fix(aws/lambda): add atomic operations for updating lambda function concurrency
ADD
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/converters/PutLambdaProvisionedConcurrencyAtomicOperationConverter.java
+/*
+ * Copyright 2018 Amazon.com, Inc. or its affiliates.
+ *
+ * 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.clouddriver.lambda.deploy.converters;
+
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.PutLambdaProvisionedConcurrencyDescription;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.ops.PutLambdaProvisionedConcurrencyAtomicOperation;
+import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
+import com.netflix.spinnaker.clouddriver.security.AbstractAtomicOperationsCredentialsSupport;
+import java.util.Map;
+import org.springframework.stereotype.Component;
+
+@Component("putLambdaProvisionedConcurrency")
+public class PutLambdaProvisionedConcurrencyAtomicOperationConverter
+ extends AbstractAtomicOperationsCredentialsSupport {
+
+ @Override
+ public AtomicOperation convertOperation(Map input) {
+ return new PutLambdaProvisionedConcurrencyAtomicOperation(convertDescription(input));
+ }
+
+ @Override
+ public PutLambdaProvisionedConcurrencyDescription convertDescription(Map input) {
+ PutLambdaProvisionedConcurrencyDescription converted =
+ getObjectMapper().convertValue(input, PutLambdaProvisionedConcurrencyDescription.class);
+ converted.setCredentials(getCredentialsObject(input.get("credentials").toString()));
+
+ return converted;
+ }
+}

ADD
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/converters/PutLambdaReservedConcurrencyAtomicOperationConverter.java
+/*
+ * Copyright 2018 Amazon.com, Inc. or its affiliates.
+ *
+ * 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.clouddriver.lambda.deploy.converters;
+
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.PutLambdaReservedConcurrencyDescription;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.ops.PutLambdaReservedConcurrencyAtomicOperation;
+import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
+import com.netflix.spinnaker.clouddriver.security.AbstractAtomicOperationsCredentialsSupport;
+import java.util.Map;
+import org.springframework.stereotype.Component;
+
+@Component("putLambdaReservedConcurrency")
+public class PutLambdaReservedConcurrencyAtomicOperationConverter
+ extends AbstractAtomicOperationsCredentialsSupport {
+
+ @Override
+ public AtomicOperation convertOperation(Map input) {
+ return new PutLambdaReservedConcurrencyAtomicOperation(convertDescription(input));
+ }
+
+ @Override
+ public PutLambdaReservedConcurrencyDescription convertDescription(Map input) {
+ PutLambdaReservedConcurrencyDescription converted =
+ getObjectMapper().convertValue(input, PutLambdaReservedConcurrencyDescription.class);
+ converted.setCredentials(getCredentialsObject(input.get("credentials").toString()));
+
+ return converted;
+ }
+}

ADD
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/description/PutLambdaProvisionedConcurrencyDescription.java
+/*
+ * Copyright 2018 Amazon.com, Inc. or its affiliates.
+ *
+ * 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.clouddriver.lambda.deploy.description;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class PutLambdaProvisionedConcurrencyDescription extends AbstractLambdaFunctionDescription {
+ String functionName;
+ String qualifier;
+ int provisionedConcurrentExecutions;
+}

ADD
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/description/PutLambdaReservedConcurrencyDescription.java
+/*
+ * Copyright 2018 Amazon.com, Inc. or its affiliates.
+ *
+ * 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.clouddriver.lambda.deploy.description;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class PutLambdaReservedConcurrencyDescription extends AbstractLambdaFunctionDescription {
+ String functionName;
+ int reservedConcurrentExecutions;
+}

ADD
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/PutLambdaProvisionedConcurrencyAtomicOperation.java
+/*
+ * Copyright 2018 Amazon.com, Inc. or its affiliates.
+ *
+ * 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.clouddriver.lambda.deploy.ops;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.PutProvisionedConcurrencyConfigRequest;
+import com.amazonaws.services.lambda.model.PutProvisionedConcurrencyConfigResult;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.PutLambdaProvisionedConcurrencyDescription;
+import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
+import java.util.List;
+
+public class PutLambdaProvisionedConcurrencyAtomicOperation
+ extends AbstractLambdaAtomicOperation<
+ PutLambdaProvisionedConcurrencyDescription, PutProvisionedConcurrencyConfigResult>
+ implements AtomicOperation<PutProvisionedConcurrencyConfigResult> {
+
+ public PutLambdaProvisionedConcurrencyAtomicOperation(
+ PutLambdaProvisionedConcurrencyDescription description) {
+ super(description, "PUT_LAMBDA_FUNCTION_PROVISIONED_CONCURRENCY");
+ }
+
+ @Override
+ public PutProvisionedConcurrencyConfigResult operate(List priorOutputs) {
+ updateTaskStatus("Initializing Atomic Operation AWS Lambda for PutProvisionedConcurrency...");
+ return putProvisionedFunctionConcurrency(
+ description.getFunctionName(),
+ description.getQualifier(),
+ description.getProvisionedConcurrentExecutions());
+ }
+
+ private PutProvisionedConcurrencyConfigResult putProvisionedFunctionConcurrency(
+ String functionName, String qualifier, int provisionedConcurrentExecutions) {
+ AWSLambda client = getLambdaClient();
+ PutProvisionedConcurrencyConfigRequest req =
+ new PutProvisionedConcurrencyConfigRequest()
+ .withFunctionName(functionName)
+ .withQualifier(qualifier)
+ .withProvisionedConcurrentExecutions(provisionedConcurrentExecutions);
+
+ PutProvisionedConcurrencyConfigResult result = client.putProvisionedConcurrencyConfig(req);
+ updateTaskStatus("Finished Atomic Operation AWS Lambda for PutProvisionedConcurrency...");
+ return result;
+ }
+}

ADD
clouddriver-lambda/src/main/java/com/netflix/spinnaker/clouddriver/lambda/deploy/ops/PutLambdaReservedConcurrencyAtomicOperation.java
+/*
+ * Copyright 2018 Amazon.com, Inc. or its affiliates.
+ *
+ * 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.clouddriver.lambda.deploy.ops;
+
+import com.amazonaws.services.lambda.AWSLambda;
+import com.amazonaws.services.lambda.model.PutFunctionConcurrencyRequest;
+import com.amazonaws.services.lambda.model.PutFunctionConcurrencyResult;
+import com.netflix.spinnaker.clouddriver.lambda.deploy.description.PutLambdaReservedConcurrencyDescription;
+import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation;
+import java.util.List;
+
+public class PutLambdaReservedConcurrencyAtomicOperation
+ extends AbstractLambdaAtomicOperation<
+ PutLambdaReservedConcurrencyDescription, PutFunctionConcurrencyResult>
+ implements AtomicOperation<PutFunctionConcurrencyResult> {
+
+ public PutLambdaReservedConcurrencyAtomicOperation(
+ PutLambdaReservedConcurrencyDescription description) {
+ super(description, "PUT_LAMBDA_FUNCTION_RESERVED_CONCURRENCY");
+ }
+
+ @Override
+ public PutFunctionConcurrencyResult operate(List priorOutputs) {
+ updateTaskStatus("Initializing Atomic Operation AWS Lambda for PutReservedConcurrency...");
+ return putReservedFunctionConcurrency(
+ description.getFunctionName(), description.getReservedConcurrentExecutions());
+ }
+
+ private PutFunctionConcurrencyResult putReservedFunctionConcurrency(
+ String functionName, int reservedConcurrentExecutions) {
+ AWSLambda client = getLambdaClient();
+ PutFunctionConcurrencyRequest req =
+ new PutFunctionConcurrencyRequest()
+ .withFunctionName(functionName)
+ .withReservedConcurrentExecutions(reservedConcurrentExecutions);
+
+ PutFunctionConcurrencyResult result = client.putFunctionConcurrency(req);
+ updateTaskStatus("Finished Atomic Operation AWS Lambda for PutReservedConcurrency...");
+ return result;
+ }
+}

fix(aws/lambda): add atomic operations for updating lambda function concurrency (#4950)

Co-authored-by: smaniyedath <shyam_maniyedath@intuit.com>