Skip to content

Commit

Permalink
feat(core): Force cache refresh manifest task
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Wander committed Oct 13, 2017
1 parent dd9b7e0 commit 5dc44c4
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@ public class DeployManifestStage implements StageDefinitionBuilder {
@Override
public <T extends Execution<T>> void taskGraph(Stage<T> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" && deployed)) {
outputs["deploy.outputs"] = deployed
}
}
if (status == ExecutionStatus.SUCCEEDED || status == ExecutionStatus.TERMINAL || status == ExecutionStatus.RUNNING) {
List<Map<String, Object>> katoTasks = []
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, List<String>> deployedManifests = (Map<String, List<String>>) stage.getContext().get("deploy.outputs");

for (Map.Entry<String, List<String>> entry : deployedManifests.entrySet()) {
String location = entry.getKey();
entry.getValue().forEach(name -> {
Map<String, String> request = new ImmutableMap.Builder<String, String>()
.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);
}
}

0 comments on commit 5dc44c4

Please sign in to comment.