Skip to content

Commit

Permalink
feat(provider/kubernetes): scale manifest (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander authored Nov 15, 2017
1 parent 30977fb commit 3e953ac
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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.ScaleManifestTask;
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 ScaleManifestStage implements StageDefinitionBuilder {
public static final String PIPELINE_CONFIG_TYPE = "scaleManifest";

@Override
public void taskGraph(Stage stage, TaskNode.Builder builder) {
builder.withTask(ScaleManifestTask.TASK_NAME, ScaleManifestTask.class)
.withTask("monitorScale", MonitorKatoTask.class)
.withTask(UpdateManifestForceCacheRefreshTask.TASK_NAME, UpdateManifestForceCacheRefreshTask.class);
}
}
Original file line number Diff line number Diff line change
@@ -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 abstract class GenericUpdateManifestTask extends AbstractCloudProviderAwareTask implements Task {
@Autowired
KatoService kato;

protected abstract String taskName();

@Nonnull
@Override
public TaskResult execute(@Nonnull Stage stage) {
String credentials = getCredentials(stage);
String cloudProvider = getCloudProvider(stage);
Map<String, Map> operation = new ImmutableMap.Builder<String, Map>()
.put(taskName(), stage.getContext())
.build();

TaskId taskId = kato.requestOperations(cloudProvider, Collections.singletonList(operation)).toBlocking().first();

Map<String, Object> outputs = new ImmutableMap.Builder<String, Object>()
.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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 org.springframework.stereotype.Component;

@Component
public class ScaleManifestTask extends GenericUpdateManifestTask {
public static final String TASK_NAME = "scaleManifest";

@Override
protected String taskName() {
return TASK_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,14 @@

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 class UndoRolloutManifestTask extends GenericUpdateManifestTask {
public static final String TASK_NAME = "undoRolloutManifest";

@Nonnull
@Override
public TaskResult execute(@Nonnull Stage stage) {
String credentials = getCredentials(stage);
String cloudProvider = getCloudProvider(stage);
Map<String, Map> operation = new ImmutableMap.Builder<String, Map>()
.put(TASK_NAME, stage.getContext())
.build();

TaskId taskId = kato.requestOperations(cloudProvider, Collections.singletonList(operation)).toBlocking().first();

Map<String, Object> outputs = new ImmutableMap.Builder<String, Object>()
.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);
protected String taskName() {
return TASK_NAME;
}
}

0 comments on commit 3e953ac

Please sign in to comment.