diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/manifest/UndoRolloutManifestStage.java b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/manifest/UndoRolloutManifestStage.java new file mode 100644 index 0000000000..a30e218df3 --- /dev/null +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/manifest/UndoRolloutManifestStage.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Google, 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.manifest; + +import com.netflix.spinnaker.orca.clouddriver.tasks.MonitorKatoTask; +import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.UndoRolloutManifestTask; +import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.UpdateManifestForceCacheRefreshTask; +import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; +import com.netflix.spinnaker.orca.pipeline.TaskNode; +import com.netflix.spinnaker.orca.pipeline.model.Stage; +import org.springframework.stereotype.Component; + +@Component +public class UndoRolloutManifestStage implements StageDefinitionBuilder { + public static final String PIPELINE_CONFIG_TYPE = "undoRolloutManifest"; + + @Override + public void taskGraph(Stage stage, TaskNode.Builder builder) { + builder.withTask(UndoRolloutManifestTask.TASK_NAME, UndoRolloutManifestTask.class) + .withTask("monitorUndoRollout", MonitorKatoTask.class) + .withTask(UpdateManifestForceCacheRefreshTask.TASK_NAME, UpdateManifestForceCacheRefreshTask.class); + } +} diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/UndoRolloutManifestTask.java b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/UndoRolloutManifestTask.java new file mode 100644 index 0000000000..cb58321258 --- /dev/null +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/UndoRolloutManifestTask.java @@ -0,0 +1,63 @@ +/* + * Copyright 2017 Google, 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.tasks.manifest; + +import com.google.common.collect.ImmutableMap; +import com.netflix.spinnaker.orca.ExecutionStatus; +import com.netflix.spinnaker.orca.Task; +import com.netflix.spinnaker.orca.TaskResult; +import com.netflix.spinnaker.orca.clouddriver.KatoService; +import com.netflix.spinnaker.orca.clouddriver.model.TaskId; +import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask; +import com.netflix.spinnaker.orca.pipeline.model.Stage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.Map; + +@Component +public class UndoRolloutManifestTask extends AbstractCloudProviderAwareTask implements Task { + @Autowired + KatoService kato; + + public static final String TASK_NAME = "undoRolloutManifest"; + + @Nonnull + @Override + public TaskResult execute(@Nonnull Stage stage) { + String credentials = getCredentials(stage); + String cloudProvider = getCloudProvider(stage); + Map operation = new ImmutableMap.Builder() + .put(TASK_NAME, stage.getContext()) + .build(); + + TaskId taskId = kato.requestOperations(cloudProvider, Collections.singletonList(operation)).toBlocking().first(); + + Map outputs = new ImmutableMap.Builder() + .put("kato.result.expected", false) + .put("kato.last.task.id", taskId) + .put("manifest.account.name", credentials) + .put("manifest.name", stage.getContext().get("name")) + .put("manifest.location", stage.getContext().get("location")) + .build(); + + return new TaskResult(ExecutionStatus.SUCCEEDED, outputs); + } +} diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/UpdateManifestForceCacheRefreshTask.java b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/UpdateManifestForceCacheRefreshTask.java new file mode 100644 index 0000000000..af26572eeb --- /dev/null +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/UpdateManifestForceCacheRefreshTask.java @@ -0,0 +1,57 @@ +/* + * Copyright 2017 Google, 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.tasks.manifest; + +import com.google.common.collect.ImmutableMap; +import com.netflix.spinnaker.orca.ExecutionStatus; +import com.netflix.spinnaker.orca.Task; +import com.netflix.spinnaker.orca.TaskResult; +import com.netflix.spinnaker.orca.clouddriver.CloudDriverCacheService; +import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask; +import com.netflix.spinnaker.orca.pipeline.model.Stage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Map; + +@Component +public class UpdateManifestForceCacheRefreshTask extends AbstractCloudProviderAwareTask implements Task { + private final static String REFRESH_TYPE = "Manifest"; + public final static String TASK_NAME = "forceCacheRefresh"; + + @Autowired + CloudDriverCacheService cacheService; + + @Override + public TaskResult execute(Stage stage) { + String cloudProvider = getCloudProvider(stage); + String account = getCredentials(stage); + String name = (String) stage.getContext().get("manifest.name"); + String location = (String) stage.getContext().get("manifest.location"); + + Map request = new ImmutableMap.Builder() + .put("account", account) + .put("name", name) + .put("location", location) + .build(); + + cacheService.forceCacheUpdate(cloudProvider, REFRESH_TYPE, request); + + return new TaskResult(ExecutionStatus.SUCCEEDED); + } +}