Skip to content

Commit

Permalink
fix(aws/lambda): add atomic operations for updating lambda function c…
Browse files Browse the repository at this point in the history
…oncurrency (#4950)

Co-authored-by: smaniyedath <shyam_maniyedath@intuit.com>
  • Loading branch information
shyamsfo and shyamsfo committed Sep 28, 2020
1 parent 8c3f482 commit 5b6f3b5
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 0 deletions.
@@ -0,0 +1,42 @@
/*
* 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;
}
}
@@ -0,0 +1,43 @@
/*
* 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;
}
}
@@ -0,0 +1,27 @@
/*
* 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;
}
@@ -0,0 +1,27 @@
/*
* 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;
}
@@ -0,0 +1,58 @@
/*
* 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;
}
}
@@ -0,0 +1,55 @@
/*
* 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;
}
}

0 comments on commit 5b6f3b5

Please sign in to comment.