Search in sources :

Example 51 with Parameter

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);
}
Also used : AmazonCloudFormation(com.amazonaws.services.cloudformation.AmazonCloudFormation) ArgumentCaptor(org.mockito.ArgumentCaptor) UpdateStackSetResult(com.amazonaws.services.cloudformation.model.UpdateStackSetResult) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TaskListener(hudson.model.TaskListener) Parameter(com.amazonaws.services.cloudformation.model.Parameter) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) PrintWriter(java.io.PrintWriter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 52 with Parameter

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());
}
Also used : JSONParameterFileParser(de.taimos.pipeline.aws.cloudformation.parser.JSONParameterFileParser) Parameter(com.amazonaws.services.cloudformation.model.Parameter) Test(org.junit.Test)

Example 53 with Parameter

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;
}
Also used : ArrayList(java.util.ArrayList) Parameter(com.amazonaws.services.cloudformation.model.Parameter)

Example 54 with Parameter

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;
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsNetworkView) ArrayList(java.util.ArrayList) Parameter(com.amazonaws.services.cloudformation.model.Parameter) AwsInstanceProfileView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsInstanceProfileView)

Example 55 with Parameter

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;
}
Also used : Parameter(com.amazonaws.services.cloudformation.model.Parameter) CreateStackRequest(com.amazonaws.services.cloudformation.model.CreateStackRequest)

Aggregations

Parameter (com.amazonaws.services.cloudformation.model.Parameter)85 Test (org.junit.Test)79 Context (de.widdix.awscftemplates.Context)66 ACloudFormationTest (de.widdix.awscftemplates.ACloudFormationTest)60 HttpResponse (org.apache.http.HttpResponse)19 KeyPair (com.amazonaws.services.ec2.model.KeyPair)5 StringInputStream (com.amazonaws.util.StringInputStream)4 ArrayList (java.util.ArrayList)4 DescribeContainerInstancesRequest (com.amazonaws.services.ecs.model.DescribeContainerInstancesRequest)3 DescribeContainerInstancesResult (com.amazonaws.services.ecs.model.DescribeContainerInstancesResult)3 ListContainerInstancesRequest (com.amazonaws.services.ecs.model.ListContainerInstancesRequest)3 ListContainerInstancesResult (com.amazonaws.services.ecs.model.ListContainerInstancesResult)3 ParameterProvider (de.taimos.pipeline.aws.cloudformation.ParameterProvider)3 FilePath (hudson.FilePath)3 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)2 TaskListener (hudson.model.TaskListener)2 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)2 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Change (com.amazonaws.services.cloudformation.model.Change)1