forked from spinnaker/orca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jobs): preconfigured run job stage (spinnaker#2540)
- Loading branch information
Showing
12 changed files
with
341 additions
and
16 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ain/groovy/com/netflix/spinnaker/orca/clouddriver/config/ClouddriverJobConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2018 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.config; | ||
|
||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
|
||
@EnableConfigurationProperties(JobConfigurationProperties.class) | ||
public class ClouddriverJobConfiguration {} |
28 changes: 28 additions & 0 deletions
28
...main/groovy/com/netflix/spinnaker/orca/clouddriver/config/JobConfigurationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2018 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.config; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import java.util.List; | ||
|
||
@ConfigurationProperties("job") | ||
@Data | ||
public class JobConfigurationProperties { | ||
List<PreconfiguredJobStageProperties> preconfigured; | ||
} |
27 changes: 27 additions & 0 deletions
27
.../groovy/com/netflix/spinnaker/orca/clouddriver/config/PreconfiguredJobStageParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2018 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.config; | ||
|
||
import com.netflix.spinnaker.orca.config.PreconfiguredStageParameter; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class PreconfiguredJobStageParameter extends PreconfiguredStageParameter { | ||
|
||
String mapping; | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...groovy/com/netflix/spinnaker/orca/clouddriver/config/PreconfiguredJobStageProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2018 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.config; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Data | ||
|
||
public class PreconfiguredJobStageProperties { | ||
|
||
// Fields are public as job stages use reflection to access these directly from outside the class | ||
public boolean enabled = true; | ||
public String label; | ||
public String description; | ||
public String type; | ||
public List<PreconfiguredJobStageParameter> parameters; | ||
public boolean waitForCompletion = true; | ||
public String cloudProvider; | ||
public String credentials; | ||
public String region; | ||
public String propertyFile; | ||
public Map<String, Object> cluster = new HashMap<>(); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...com/netflix/spinnaker/orca/clouddriver/exception/PreconfiguredJobNotFoundException.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2017 Schibsted ASA. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.exception | ||
|
||
class PreconfiguredJobNotFoundException extends RuntimeException { | ||
PreconfiguredJobNotFoundException(String jobKey) { | ||
super("Could not find a stage named '$jobKey'") | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...n/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/job/PreconfiguredJobStage.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2018 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.pipeline.job | ||
|
||
|
||
import com.netflix.spinnaker.orca.clouddriver.config.PreconfiguredJobStageProperties | ||
import com.netflix.spinnaker.orca.clouddriver.exception.PreconfiguredJobNotFoundException | ||
import com.netflix.spinnaker.orca.clouddriver.service.JobService | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
@ConditionalOnProperty("job.preconfigured") | ||
class PreconfiguredJobStage extends RunJobStage { | ||
|
||
@Autowired | ||
private JobService jobService | ||
|
||
def fields = PreconfiguredJobStageProperties.declaredFields.findAll { | ||
!it.synthetic && !['props', 'enabled', 'label', 'description', 'type', 'parameters'].contains(it.name) | ||
}.collect { it.name } | ||
|
||
@Override | ||
void taskGraph(Stage stage, TaskNode.Builder builder) { | ||
def preconfiguredJob = jobService.getPreconfiguredStages().find { stage.type == it.type } | ||
|
||
if (!preconfiguredJob) { | ||
throw new PreconfiguredJobNotFoundException((String) stage.type) | ||
} | ||
|
||
stage.setContext(overrideIfNotSetInContextAndOverrideDefault(stage.context, preconfiguredJob)) | ||
super.taskGraph(stage, builder) | ||
} | ||
|
||
private Map<String, Object> overrideIfNotSetInContextAndOverrideDefault(Map<String, Object> context, PreconfiguredJobStageProperties preconfiguredWebhook) { | ||
fields.each { | ||
if (context[it] == null || preconfiguredWebhook[it] != null) { | ||
context[it] = preconfiguredWebhook[it] | ||
} | ||
} | ||
preconfiguredWebhook.parameters.each { defaults -> | ||
if (defaults.defaultValue != null) { | ||
Eval.xy(context, defaults.defaultValue, "x.${defaults.mapping} = y.toString()") | ||
} | ||
} | ||
if (context.parameters) { | ||
context.parameters.each { k, v -> | ||
def parameterDefinition = preconfiguredWebhook.parameters.find { it.name == k } | ||
if (parameterDefinition) { | ||
Eval.xy(context, v, "x.${parameterDefinition.mapping} = y.toString()") | ||
} | ||
} | ||
context.remove("parameters") | ||
} | ||
return context | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...louddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/service/JobService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2018 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.clouddriver.service; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.config.JobConfigurationProperties; | ||
import com.netflix.spinnaker.orca.clouddriver.config.PreconfiguredJobStageProperties; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@ConditionalOnProperty("job.preconfigured") | ||
public class JobService { | ||
|
||
@Autowired JobConfigurationProperties jobConfigurationProperties; | ||
|
||
@Autowired | ||
List<PreconfiguredJobStageProperties> getPreconfiguredStages() { | ||
return jobConfigurationProperties.getPreconfigured().stream().filter(it -> it.enabled == true).collect(Collectors.toList()); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
orca-core/src/main/java/com/netflix/spinnaker/orca/config/PreconfiguredStageParameter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2017 Schibsted ASA. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.config; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class PreconfiguredStageParameter { | ||
private String name; | ||
private String label; | ||
private String defaultValue; | ||
private String description; | ||
private ParameterType type = ParameterType.string; | ||
private int order; | ||
|
||
public | ||
enum ParameterType { | ||
string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.