Search in sources :

Example 1 with ModifyLaunchTemplateResult

use of com.amazonaws.services.ec2.model.ModifyLaunchTemplateResult in project cloudbreak by hortonworks.

the class AwsLaunchTemplateUpdateService method modifyLaunchTemplate.

private ModifyLaunchTemplateResult modifyLaunchTemplate(AmazonEc2Client ec2Client, LaunchTemplateSpecification launchTemplateSpecification, CreateLaunchTemplateVersionResult createLaunchTemplateVersionResult, boolean setLaunchtemplateVersionToDefault) {
    ModifyLaunchTemplateRequest modifyLaunchTemplateRequest = new ModifyLaunchTemplateRequest().withLaunchTemplateId(launchTemplateSpecification.getLaunchTemplateId());
    if (setLaunchtemplateVersionToDefault) {
        modifyLaunchTemplateRequest.withDefaultVersion(createLaunchTemplateVersionResult.getLaunchTemplateVersion().getVersionNumber().toString());
    } else {
        LOGGER.debug("In case of dryrun the default version of the used launch template remain the same: {}", launchTemplateSpecification.getVersion());
        modifyLaunchTemplateRequest.withDefaultVersion(launchTemplateSpecification.getVersion());
    }
    ModifyLaunchTemplateResult modifyLaunchTemplateResult = ec2Client.modifyLaunchTemplate(modifyLaunchTemplateRequest);
    LOGGER.debug("Modified launch template: {}", modifyLaunchTemplateResult);
    return modifyLaunchTemplateResult;
}
Also used : ModifyLaunchTemplateRequest(com.amazonaws.services.ec2.model.ModifyLaunchTemplateRequest) ModifyLaunchTemplateResult(com.amazonaws.services.ec2.model.ModifyLaunchTemplateResult)

Example 2 with ModifyLaunchTemplateResult

use of com.amazonaws.services.ec2.model.ModifyLaunchTemplateResult in project cloudbreak by hortonworks.

the class AwsLaunchTemplateUpdateServiceTest method shouldUpdateImage.

@Test
public void shouldUpdateImage() throws IOException {
    // GIVEN
    String cfStackName = "cf";
    CloudResource cfResource = CloudResource.builder().type(ResourceType.CLOUDFORMATION_STACK).name(cfStackName).build();
    String template = FileReaderUtils.readFileFromClasspath("json/aws-cf-template.json");
    String cfTemplateBody = JsonUtil.minify(String.format(template, "{\"Ref\":\"AMI\"}"));
    when(cloudFormationClient.getTemplate(any())).thenReturn(new GetTemplateResult().withTemplateBody(cfTemplateBody));
    Map<AutoScalingGroup, String> autoScalingGroupsResult = createAutoScalingGroupHandler();
    when(autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource.getName())).thenReturn(autoScalingGroupsResult);
    when(ec2Client.createLaunchTemplateVersion(any(CreateLaunchTemplateVersionRequest.class))).thenReturn(new CreateLaunchTemplateVersionResult().withLaunchTemplateVersion(new LaunchTemplateVersion().withVersionNumber(1L)));
    when(ec2Client.modifyLaunchTemplate(any(ModifyLaunchTemplateRequest.class))).thenReturn(new ModifyLaunchTemplateResult());
    when(autoScalingClient.updateAutoScalingGroup(any(UpdateAutoScalingGroupRequest.class))).thenReturn(new UpdateAutoScalingGroupResult());
    // WHEN
    underTest.updateFields(ac, cfResource.getName(), Map.of(LaunchTemplateField.IMAGE_ID, stack.getImage().getImageName()));
    // THEN
    Mockito.verify(ec2Client).createLaunchTemplateVersion(argumentCaptor.capture());
    CreateLaunchTemplateVersionRequest request = argumentCaptor.getValue();
    Assertions.assertEquals(stack.getImage().getImageName(), request.getLaunchTemplateData().getImageId());
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) UpdateAutoScalingGroupResult(com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupResult) GetTemplateResult(com.amazonaws.services.cloudformation.model.GetTemplateResult) CreateLaunchTemplateVersionResult(com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionResult) LaunchTemplateVersion(com.amazonaws.services.ec2.model.LaunchTemplateVersion) UpdateAutoScalingGroupRequest(com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest) CreateLaunchTemplateVersionRequest(com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ModifyLaunchTemplateRequest(com.amazonaws.services.ec2.model.ModifyLaunchTemplateRequest) ModifyLaunchTemplateResult(com.amazonaws.services.ec2.model.ModifyLaunchTemplateResult) Test(org.junit.Test)

Aggregations

ModifyLaunchTemplateRequest (com.amazonaws.services.ec2.model.ModifyLaunchTemplateRequest)2 ModifyLaunchTemplateResult (com.amazonaws.services.ec2.model.ModifyLaunchTemplateResult)2 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)1 UpdateAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest)1 UpdateAutoScalingGroupResult (com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupResult)1 GetTemplateResult (com.amazonaws.services.cloudformation.model.GetTemplateResult)1 CreateLaunchTemplateVersionRequest (com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionRequest)1 CreateLaunchTemplateVersionResult (com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionResult)1 LaunchTemplateVersion (com.amazonaws.services.ec2.model.LaunchTemplateVersion)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1