Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): Add stage to set preferred plugin version (#3664)
- Loading branch information
1 parent
a3d2916
commit ca13c6b
Showing
4 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
...in/groovy/com/netflix/spinnaker/orca/front50/pipeline/SetPreferredPluginReleaseStage.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,32 @@ | ||
/* | ||
* Copyright 2020 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.front50.pipeline; | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.graph.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.api.pipeline.graph.TaskNode; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution; | ||
import com.netflix.spinnaker.orca.front50.tasks.SetPreferredPluginReleaseTask; | ||
import javax.annotation.Nonnull; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SetPreferredPluginReleaseStage implements StageDefinitionBuilder { | ||
|
||
@Override | ||
public void taskGraph(@Nonnull StageExecution stage, @Nonnull TaskNode.Builder builder) { | ||
builder.withTask("setPreferredPluginVersion", SetPreferredPluginReleaseTask.class); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...c/main/groovy/com/netflix/spinnaker/orca/front50/tasks/SetPreferredPluginReleaseTask.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,68 @@ | ||
/* | ||
* Copyright 2020 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.front50.tasks; | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.RetryableTask; | ||
import com.netflix.spinnaker.orca.api.pipeline.TaskResult; | ||
import com.netflix.spinnaker.orca.api.pipeline.models.StageExecution; | ||
import com.netflix.spinnaker.orca.front50.Front50Service; | ||
import java.time.Duration; | ||
import java.util.Objects; | ||
import javax.annotation.Nonnull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SetPreferredPluginReleaseTask implements RetryableTask { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SetPreferredPluginReleaseTask.class); | ||
|
||
private final Front50Service front50Service; | ||
|
||
public SetPreferredPluginReleaseTask(Front50Service front50Service) { | ||
this.front50Service = front50Service; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public TaskResult execute(@Nonnull StageExecution stage) { | ||
final String pluginId = (String) stage.getContext().get("pluginId"); | ||
final String version = (String) stage.getContext().get("preferredVersion"); | ||
|
||
Objects.requireNonNull(pluginId); | ||
Objects.requireNonNull(version); | ||
|
||
try { | ||
front50Service.setPreferredPluginVersion(pluginId, version); | ||
} catch (Exception e) { | ||
log.error("Failed setting preferred plugin version '{}' to '{}'", pluginId, version, e); | ||
return TaskResult.RUNNING; | ||
} | ||
|
||
return TaskResult.SUCCEEDED; | ||
} | ||
|
||
@Override | ||
public long getBackoffPeriod() { | ||
return Duration.ofSeconds(10).toMillis(); | ||
} | ||
|
||
@Override | ||
public long getTimeout() { | ||
return Duration.ofMinutes(2).toMillis(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../groovy/com/netflix/spinnaker/orca/front50/tasks/SetPreferredPluginReleaseTaskSpec.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,51 @@ | ||
/* | ||
* Copyright 2020 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.front50.tasks | ||
|
||
import com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus | ||
import com.netflix.spinnaker.orca.front50.Front50Service | ||
import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
import static com.netflix.spinnaker.orca.test.model.ExecutionBuilder.stage | ||
|
||
class SetPreferredPluginReleaseTaskSpec extends Specification { | ||
|
||
Front50Service front50Service = Mock() | ||
|
||
@Subject | ||
SetPreferredPluginReleaseTask subject = new SetPreferredPluginReleaseTask(front50Service) | ||
|
||
def "should call front50"() { | ||
given: | ||
StageExecutionImpl stageExecution = stage { | ||
type = "whatever" | ||
context = [ | ||
"pluginId": "netflix.foo", | ||
"preferredVersion": "1.0.1" | ||
] | ||
} | ||
|
||
when: | ||
def result = subject.execute(stageExecution) | ||
|
||
then: | ||
result.status == ExecutionStatus.SUCCEEDED | ||
1 * front50Service.setPreferredPluginVersion("netflix.foo", "1.0.1") | ||
} | ||
} |