Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aws/lambda): add atomic operations for updating lambda function c…
…oncurrency (#4950) Co-authored-by: smaniyedath <shyam_maniyedath@intuit.com>
- Loading branch information
Showing
6 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ver/lambda/deploy/converters/PutLambdaProvisionedConcurrencyAtomicOperationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...driver/lambda/deploy/converters/PutLambdaReservedConcurrencyAtomicOperationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ker/clouddriver/lambda/deploy/description/PutLambdaProvisionedConcurrencyDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
27 changes: 27 additions & 0 deletions
27
...nnaker/clouddriver/lambda/deploy/description/PutLambdaReservedConcurrencyDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
58 changes: 58 additions & 0 deletions
58
...innaker/clouddriver/lambda/deploy/ops/PutLambdaProvisionedConcurrencyAtomicOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
.../spinnaker/clouddriver/lambda/deploy/ops/PutLambdaReservedConcurrencyAtomicOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |