From f1b0acb78cb83c38134c274a373dc8859ffa004d Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Thu, 12 Oct 2017 15:51:20 -0400 Subject: [PATCH] feat(core): Force cache refresh manifest task --- .../manifest/DeployManifestStage.java | 4 +- .../clouddriver/tasks/MonitorKatoTask.groovy | 3 + .../ManifestForceCacheRefreshTask.java | 64 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestForceCacheRefreshTask.java diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/manifest/DeployManifestStage.java b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/manifest/DeployManifestStage.java index 17f6767c83e..72f18c5de15 100644 --- a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/manifest/DeployManifestStage.java +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/pipeline/manifest/DeployManifestStage.java @@ -19,6 +19,7 @@ import com.netflix.spinnaker.orca.clouddriver.tasks.MonitorKatoTask; import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.DeployManifestTask; +import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.ManifestForceCacheRefreshTask; import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; import com.netflix.spinnaker.orca.pipeline.TaskNode; import com.netflix.spinnaker.orca.pipeline.model.Execution; @@ -32,6 +33,7 @@ public class DeployManifestStage implements StageDefinitionBuilder { @Override public > void taskGraph(Stage stage, TaskNode.Builder builder) { builder.withTask(DeployManifestTask.TASK_NAME, DeployManifestTask.class) - .withTask("monitorDeploy", MonitorKatoTask.class); + .withTask("monitorDeploy", MonitorKatoTask.class) + .withTask(ManifestForceCacheRefreshTask.TASK_NAME, ManifestForceCacheRefreshTask.class); } } diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/MonitorKatoTask.groovy b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/MonitorKatoTask.groovy index b4d27a51ec0..136cbaca1f6 100644 --- a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/MonitorKatoTask.groovy +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/MonitorKatoTask.groovy @@ -120,6 +120,9 @@ class MonitorKatoTask implements RetryableTask { if (!stage.context.containsKey("deploy.jobs") && deployed) { outputs["deploy.jobs"] = deployed } + if (!stage.context.containsKey("deploy.outputs")) { + outputs["deploy.outputs"] = deployed + } } if (status == ExecutionStatus.SUCCEEDED || status == ExecutionStatus.TERMINAL || status == ExecutionStatus.RUNNING) { List> katoTasks = [] diff --git a/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestForceCacheRefreshTask.java b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestForceCacheRefreshTask.java new file mode 100644 index 00000000000..3decbdceab2 --- /dev/null +++ b/orca-clouddriver/src/main/groovy/com/netflix/spinnaker/orca/clouddriver/tasks/manifest/ManifestForceCacheRefreshTask.java @@ -0,0 +1,64 @@ +/* + * 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.List; +import java.util.Map; + +@Component +public class ManifestForceCacheRefreshTask 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); + Map> deployedManifests = (Map>) stage.getContext().get("deploy.outputs"); + + for (Map.Entry> entry : deployedManifests.entrySet()) { + String location = entry.getKey(); + entry.getValue().forEach(name -> { + Map request = new ImmutableMap.Builder() + .put("account", account) + .put("name", name) + .put("location", location) + .build(); + + cacheService.forceCacheUpdate(cloudProvider, REFRESH_TYPE, request); + }); + + // TODO(lwander): make sure cache refresh is processed + } + + return new TaskResult(ExecutionStatus.SUCCEEDED); + } +}