Skip to content

Commit

Permalink
feat(aws/lambda): Add update lambda stage. (#2940)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbackes authored and asher committed May 28, 2019
1 parent 005fc41 commit 8b36fcd
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2019 Armory, 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.providers.aws;

import com.netflix.spinnaker.orca.clouddriver.tasks.MonitorKatoTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.aws.lambda.updateLambdaFunctionTask;
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder;
import com.netflix.spinnaker.orca.pipeline.TaskNode;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import javax.annotation.Nonnull;
import org.springframework.stereotype.Component;

@Component
public class UpdateLambdaFunctionStage implements StageDefinitionBuilder {
public static final String PIPELINE_CONFIG_TYPE = "updateLambdaFunction";

@Override
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) {
builder
.withTask(updateLambdaFunctionTask.TASK_NAME, updateLambdaFunctionTask.class)
.withTask("monitorLambdaFunction", MonitorKatoTask.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2019 Armory, 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.providers.aws.lambda;

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 java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class updateLambdaFunctionTask extends AbstractCloudProviderAwareTask implements Task {

@Autowired KatoService katoService;

public static final String TASK_NAME = "updateLambdaFunctionConfiguration";

@Nonnull
@Override
public TaskResult execute(@Nonnull Stage stage) {
String cloudProvider = getCloudProvider(stage);

Map<String, Object> task = new HashMap<>(stage.getContext());

Map<String, Map> operation =
new ImmutableMap.Builder<String, Map>().put(TASK_NAME, task).build();

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

Map<String, Object> context =
new ImmutableMap.Builder<String, Object>()
.put("kato.result.expected", true)
.put("kato.last.task.id", taskId)
.build();

return TaskResult.builder(ExecutionStatus.SUCCEEDED).context(context).build();
}
}

0 comments on commit 8b36fcd

Please sign in to comment.