use of com.amazonaws.services.ec2.model.LaunchTemplateVersion 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());
}
use of com.amazonaws.services.ec2.model.LaunchTemplateVersion in project cloudbreak by hortonworks.
the class AwsLaunchTemplateUpdateServiceTest method testUpdateFieldsUpdatesTheAppropriateParams.
@Test
public void testUpdateFieldsUpdatesTheAppropriateParams() 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);
Map<LaunchTemplateField, String> updatableFieldMap = Map.of(LaunchTemplateField.IMAGE_ID, stack.getImage().getImageName(), LaunchTemplateField.DESCRIPTION, DESCRIPTION, LaunchTemplateField.USER_DATA, USER_DATA);
when(ec2Client.createLaunchTemplateVersion(any(CreateLaunchTemplateVersionRequest.class))).thenReturn(new CreateLaunchTemplateVersionResult().withLaunchTemplateVersion(new LaunchTemplateVersion().withVersionNumber(1L)));
// WHEN
underTest.updateFields(ac, cfResource.getName(), updatableFieldMap);
// THEN
Mockito.verify(ec2Client).createLaunchTemplateVersion(argumentCaptor.capture());
CreateLaunchTemplateVersionRequest request = argumentCaptor.getValue();
Assertions.assertEquals(stack.getImage().getImageName(), request.getLaunchTemplateData().getImageId());
Assertions.assertEquals(USER_DATA, request.getLaunchTemplateData().getUserData());
Assertions.assertEquals(DESCRIPTION, request.getVersionDescription());
}
use of com.amazonaws.services.ec2.model.LaunchTemplateVersion in project cloudbreak by hortonworks.
the class AwsLaunchTemplateUpdateServiceTest method testUpdateFieldsUpdatesWithMissingParams.
@Test
public void testUpdateFieldsUpdatesWithMissingParams() 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);
Map<LaunchTemplateField, String> updatableFieldMap = Map.of(LaunchTemplateField.IMAGE_ID, stack.getImage().getImageName(), LaunchTemplateField.DESCRIPTION, DESCRIPTION);
when(ec2Client.createLaunchTemplateVersion(any(CreateLaunchTemplateVersionRequest.class))).thenReturn(new CreateLaunchTemplateVersionResult().withLaunchTemplateVersion(new LaunchTemplateVersion().withVersionNumber(1L)));
// WHEN
underTest.updateFields(ac, cfResource.getName(), updatableFieldMap);
// THEN
Mockito.verify(ec2Client).createLaunchTemplateVersion(argumentCaptor.capture());
CreateLaunchTemplateVersionRequest request = argumentCaptor.getValue();
Assertions.assertEquals(stack.getImage().getImageName(), request.getLaunchTemplateData().getImageId());
Assertions.assertEquals(DESCRIPTION, request.getVersionDescription());
Assertions.assertNull(request.getLaunchTemplateData().getUserData());
}
Aggregations