use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class CFNUpdateStackSetStepTest method updateExistantStack.
@Test
public void updateExistantStack() throws Exception {
WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "cfnTest");
Mockito.when(stackSet.exists()).thenReturn(true);
String operationId = UUID.randomUUID().toString();
Mockito.when(stackSet.update(Mockito.anyString(), Mockito.anyString(), Mockito.<Parameter>anyCollection(), Mockito.<Tag>anyCollection())).thenReturn(new UpdateStackSetResult().withOperationId(operationId));
job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " cfnUpdateStackSet(stackSet: 'foo', pollInterval: 27, params: ['foo=bar'], paramsFile: 'params.json')" + "}\n", true));
try (PrintWriter writer = new PrintWriter(jenkinsRule.jenkins.getWorkspaceFor(job).child("params.json").write())) {
writer.println("[{\"ParameterKey\": \"foo1\", \"ParameterValue\": \"25\"}]");
}
jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0));
PowerMockito.verifyNew(CloudFormationStackSet.class, Mockito.atLeastOnce()).withArguments(Mockito.any(AmazonCloudFormation.class), Mockito.eq("foo"), Mockito.any(TaskListener.class));
@SuppressWarnings("unchecked") ArgumentCaptor<List<Parameter>> parameterCapture = (ArgumentCaptor<List<Parameter>>) (Object) ArgumentCaptor.forClass(List.class);
Mockito.verify(stackSet).update(Mockito.anyString(), Mockito.anyString(), parameterCapture.capture(), Mockito.<Tag>anyCollection());
Assertions.assertThat(parameterCapture.getValue()).containsExactlyInAnyOrder(new Parameter().withParameterKey("foo").withParameterValue("bar"), new Parameter().withParameterKey("foo1").withParameterValue("25"));
Mockito.verify(stackSet).waitForOperationToComplete(operationId, 27);
}
use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class ParameterParserTest method shouldParseJSON.
@Test
public void shouldParseJSON() throws Exception {
JSONParameterFileParser parser = new JSONParameterFileParser();
Collection<Parameter> parameters = parser.parseParams(this.getClass().getResourceAsStream("/params.json"));
Parameter[] array = parameters.toArray(new Parameter[0]);
Assert.assertEquals(2, array.length);
Parameter param1 = array[0];
Assert.assertEquals("Param1", param1.getParameterKey());
Assert.assertEquals("Value1", param1.getParameterValue());
Parameter param2 = array[1];
Assert.assertEquals("Param2", param2.getParameterKey());
Assert.assertEquals("Value2", param2.getParameterValue());
}
use of com.amazonaws.services.cloudformation.model.Parameter in project pipeline-aws-plugin by jenkinsci.
the class ParameterParser method parseParams.
private static Collection<Parameter> parseParams(List<String> params) {
Collection<Parameter> parameters = new ArrayList<>();
for (String param : params) {
int i = param.indexOf('=');
if (i < 0) {
throw new IllegalArgumentException("Missing = in param " + param);
}
String key = param.substring(0, i);
String value = param.substring(i + 1);
parameters.add(new Parameter().withParameterKey(key).withParameterValue(value));
}
return parameters;
}
use of com.amazonaws.services.cloudformation.model.Parameter in project cloudbreak by hortonworks.
the class AwsResourceConnector method getStackParameters.
private Collection<Parameter> getStackParameters(AuthenticatedContext ac, CloudStack stack, String stackName, String newSubnetCidr) {
AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork());
AwsInstanceProfileView awsInstanceProfileView = new AwsInstanceProfileView(stack);
String keyPairName = awsClient.getKeyPairName(ac);
if (awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) {
keyPairName = awsClient.getExistingKeyPairName(stack.getInstanceAuthentication());
}
Collection<Parameter> parameters = new ArrayList<>(asList(new Parameter().withParameterKey("CBUserData").withParameterValue(stack.getImage().getUserDataByType(InstanceGroupType.CORE)), new Parameter().withParameterKey("CBGateWayUserData").withParameterValue(stack.getImage().getUserDataByType(InstanceGroupType.GATEWAY)), new Parameter().withParameterKey("StackName").withParameterValue(stackName), new Parameter().withParameterKey("StackOwner").withParameterValue(ac.getCloudContext().getOwner()), new Parameter().withParameterKey("KeyName").withParameterValue(keyPairName), new Parameter().withParameterKey("AMI").withParameterValue(stack.getImage().getImageName()), new Parameter().withParameterKey("RootDeviceName").withParameterValue(getRootDeviceName(ac, stack))));
if (awsInstanceProfileView.isUseExistingInstanceProfile() && awsInstanceProfileView.isEnableInstanceProfileStrategy()) {
parameters.add(new Parameter().withParameterKey("InstanceProfile").withParameterValue(awsInstanceProfileView.getInstanceProfile()));
}
if (ac.getCloudContext().getLocation().getAvailabilityZone().value() != null) {
parameters.add(new Parameter().withParameterKey("AvailabilitySet").withParameterValue(ac.getCloudContext().getLocation().getAvailabilityZone().value()));
}
if (awsNetworkView.isExistingVPC()) {
parameters.add(new Parameter().withParameterKey("VPCId").withParameterValue(awsNetworkView.getExistingVPC()));
if (awsNetworkView.isExistingIGW()) {
parameters.add(new Parameter().withParameterKey("InternetGatewayId").withParameterValue(awsNetworkView.getExistingIGW()));
}
if (awsNetworkView.isExistingSubnet()) {
parameters.add(new Parameter().withParameterKey("SubnetId").withParameterValue(awsNetworkView.getExistingSubnet()));
} else {
parameters.add(new Parameter().withParameterKey("SubnetCIDR").withParameterValue(newSubnetCidr));
}
}
return parameters;
}
use of com.amazonaws.services.cloudformation.model.Parameter in project cloudbreak by hortonworks.
the class AwsCreateVpcNetworkTest method createStackRequest.
private CreateStackRequest createStackRequest(String vpcStackName, String vpcName, String vpcCFTemplateString) {
CreateStackRequest createStackRequest = new CreateStackRequest();
Parameter vpcNameParameter = new Parameter();
vpcNameParameter.setParameterKey("VpcName");
vpcNameParameter.setParameterValue(vpcName);
createStackRequest.withParameters(vpcNameParameter);
createStackRequest.withStackName(vpcStackName);
createStackRequest.withTemplateBody(vpcCFTemplateString);
return createStackRequest;
}
Aggregations