use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsNativeInstanceResourceBuilderTest method testBuildWhenInstanceExistAndNotRunningButNotTerminated.
@Test
public void testBuildWhenInstanceExistAndNotRunningButNotTerminated() throws Exception {
CloudResource cloudResource = CloudResource.builder().name("name").type(ResourceType.AWS_INSTANCE).status(CommonStatus.CREATED).params(emptyMap()).build();
long privateId = 0;
Instance instance = new Instance().withInstanceId("instanceId").withState(new InstanceState().withCode(0));
when(awsMethodExecutor.execute(any(), eq(Optional.empty()))).thenReturn(Optional.of(instance));
when(awsContext.getAmazonEc2Client()).thenReturn(amazonEc2Client);
List<CloudResource> actual = underTest.build(awsContext, cloudInstance, privateId, ac, group, Collections.singletonList(cloudResource), cloudStack);
Assertions.assertEquals(actual.get(0).getInstanceId(), "instanceId");
verify(amazonEc2Client, times(1)).startInstances(any());
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsTaggingServiceTest method tesTagRootVolumesForInstancesMoreThanSingleRequestLimitAndNotAllVolumesFound.
@Test
public void tesTagRootVolumesForInstancesMoreThanSingleRequestLimitAndNotAllVolumesFound() {
int instanceCount = 1200;
CloudResource instance = CloudResource.builder().type(ResourceType.AWS_INSTANCE).instanceId(INSTANCE_ID).name(INSTANCE_ID).status(CommonStatus.CREATED).build();
Instance awsInstance = new Instance().withInstanceId(INSTANCE_ID).withBlockDeviceMappings(new InstanceBlockDeviceMapping().withDeviceName("/dev/sda1").withEbs(new EbsInstanceBlockDevice().withVolumeId(VOLUME_ID))).withRootDeviceName("/dev/sda1");
Instance awsInstanceWithInvalidRootDisk = new Instance().withInstanceId(INSTANCE_ID).withBlockDeviceMappings(new InstanceBlockDeviceMapping().withDeviceName("/dev/sdb1").withEbs(new EbsInstanceBlockDevice().withVolumeId(VOLUME_ID))).withRootDeviceName("/dev/sda1");
List<CloudResource> instanceList = new ArrayList<>(instanceCount);
for (int i = 0; i < instanceCount; i++) {
instanceList.add(instance);
}
List<Instance> awsInstances = new ArrayList<>(instanceCount);
for (int i = 0; i < 1100; i++) {
awsInstances.add(awsInstance);
}
for (int i = 0; i < 100; i++) {
awsInstances.add(awsInstanceWithInvalidRootDisk);
}
DescribeInstancesResult describeResult = new DescribeInstancesResult().withReservations(new Reservation().withInstances(awsInstances));
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
when(ec2Client.describeInstances(any())).thenReturn(describeResult);
awsTaggingService.tagRootVolumes(authenticatedContext(), ec2Client, instanceList, Map.of());
verify(ec2Client, times(2)).createTags(tagRequestCaptor.capture());
List<CreateTagsRequest> requests = tagRequestCaptor.getAllValues();
assertEquals(1000, requests.get(0).getResources().size());
assertEquals(100, requests.get(1).getResources().size());
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsNativeMetadataCollectorTest method collectInstanceMetadataWhenOneOrMoreOfSpecifiedInstanceIdsDoNotExist.
@Test
void collectInstanceMetadataWhenOneOrMoreOfSpecifiedInstanceIdsDoNotExist() {
List<CloudInstance> allInstances = List.of();
String anInstanceId = "anInstanceId";
CloudResource cloudResource = getCloudResource(String.valueOf(1L), "instanceName", anInstanceId, AWS_INSTANCE);
String secondInstanceId = "secondInstanceId";
CloudResource secondCloudResource = getCloudResource(String.valueOf(2L), "secondInstanceName", secondInstanceId, AWS_INSTANCE);
List<CloudResource> resources = List.of(cloudResource, secondCloudResource);
InstanceTemplate instanceTemplate = new InstanceTemplate("flavor", "alma", 1L, Set.of(), CREATED, Map.of(), 1L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L);
CloudInstance cloudInstance = new CloudInstance(anInstanceId, instanceTemplate, null, "subnet-123", "az1");
InstanceTemplate secondInstanceTemplate = new InstanceTemplate("flavor", "alma", 2L, Set.of(), CREATED, Map.of(), 1L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L);
CloudInstance secondCloudInstance = new CloudInstance(secondInstanceId, secondInstanceTemplate, null, "subnet-123", "az1");
List<CloudInstance> cloudInstances = List.of(cloudInstance, secondCloudInstance);
when(awsClient.createEc2Client(any(), anyString())).thenReturn(ec2Client);
Instance anInstance = getAnInstance(anInstanceId);
Reservation reservation = new Reservation().withInstances(anInstance);
List<Reservation> reservations = List.of(reservation);
DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult().withReservations(reservations);
String instancesNotFoundMessage = String.format("Instance with ID could not be found: '%s'", secondInstanceId);
AmazonServiceException amazonServiceException = new AmazonServiceException(instancesNotFoundMessage);
amazonServiceException.setErrorCode(INSTANCE_NOT_FOUND_ERROR_CODE);
when(ec2Client.describeInstances(any())).thenThrow(amazonServiceException).thenReturn(describeInstancesResult);
List<CloudVmMetaDataStatus> metaDataStatuses = underTest.collect(authenticatedContext, resources, cloudInstances, allInstances);
verify(ec2Client, times(2)).describeInstances(any());
assertFalse(metaDataStatuses.isEmpty());
assertEquals(2, metaDataStatuses.size());
assertTrue(metaDataStatuses.stream().anyMatch(metaDataStatus -> InstanceStatus.TERMINATED.equals(metaDataStatus.getCloudVmInstanceStatus().getStatus())));
assertTrue(metaDataStatuses.stream().allMatch(vmMetaDataStatus -> isNotEmpty(vmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance().getInstanceId())));
verifyCloudInstance(metaDataStatuses, anInstanceId, "subnet-123", "az1");
verifyCloudInstance(metaDataStatuses, String.valueOf(2L), "subnet-123", "az1");
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsNativeMetadataCollectorTest method collectInstanceMetadataWhenTheSpecifiedInstanceIdsExist.
@Test
void collectInstanceMetadataWhenTheSpecifiedInstanceIdsExist() {
List<CloudInstance> allInstances = List.of();
String anInstanceId = "anInstanceId";
CloudResource cloudResource = getCloudResource(String.valueOf(1L), "instanceName", anInstanceId, AWS_INSTANCE);
String secondInstanceId = "secondInstanceId";
CloudResource secondCloudResource = getCloudResource(String.valueOf(2L), "secondInstanceName", secondInstanceId, AWS_INSTANCE);
List<CloudResource> resources = List.of(cloudResource, secondCloudResource);
InstanceTemplate instanceTemplate = new InstanceTemplate("flavor", "alma", 1L, Set.of(), CREATED, Map.of(), 1L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L);
InstanceTemplate otherInstanceTemplate = new InstanceTemplate("flavor", "alma", 2L, Set.of(), CREATED, Map.of(), 1L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L);
CloudInstance cloudInstance = new CloudInstance(anInstanceId, instanceTemplate, null, "subnet-123", "az1");
CloudInstance secondCloudInstance = new CloudInstance(secondInstanceId, otherInstanceTemplate, null, "subnet-123", "az1");
List<CloudInstance> cloudInstances = List.of(cloudInstance, secondCloudInstance);
when(awsClient.createEc2Client(any(), anyString())).thenReturn(ec2Client);
Instance anInstance = getAnInstance(anInstanceId);
Instance secondInstance = getAnInstance(secondInstanceId);
Reservation reservation = new Reservation().withInstances(anInstance, secondInstance);
List<Reservation> reservations = List.of(reservation);
DescribeInstancesResult describeInstancesResult = new DescribeInstancesResult().withReservations(reservations);
when(ec2Client.describeInstances(any())).thenReturn(describeInstancesResult);
List<CloudVmMetaDataStatus> metaDataStatuses = underTest.collect(authenticatedContext, resources, cloudInstances, allInstances);
verify(ec2Client, times(1)).describeInstances(any());
assertFalse(metaDataStatuses.isEmpty());
assertEquals(resources.size(), metaDataStatuses.size());
assertTrue(metaDataStatuses.stream().allMatch(vmMetaDataStatus -> isNotEmpty(vmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance().getInstanceId())));
verifyCloudInstance(metaDataStatuses, anInstanceId, "subnet-123", "az1");
verifyCloudInstance(metaDataStatuses, secondInstanceId, "subnet-123", "az1");
}
use of com.google.api.services.notebooks.v1.model.Instance in project cloudbreak by hortonworks.
the class AwsNativeMetadataCollectorTest method collectInstanceMetadataWhenOneOrMoreOfSpecifiedInstanceIdsDoNotExistAndMultipleBatchRequestsAreNecessary.
@Test
void collectInstanceMetadataWhenOneOrMoreOfSpecifiedInstanceIdsDoNotExistAndMultipleBatchRequestsAreNecessary() {
List<CloudInstance> allInstances = List.of();
List<CloudResource> resources = new ArrayList<>();
List<CloudInstance> cloudInstances = new ArrayList<>();
List<Instance> ec2Instances = new ArrayList<>();
for (int i = 0; i < 15; i++) {
String anInstanceId = "anInstanceId" + i;
InstanceTemplate instanceTemplate = new InstanceTemplate("flavor", "alma", (long) i, Set.of(), CREATED, Map.of(), 1L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L);
resources.add(getCloudResource(String.valueOf(i), "instanceName" + i, anInstanceId, AWS_INSTANCE));
cloudInstances.add(new CloudInstance(anInstanceId, instanceTemplate, null, "subnet-123", "az1"));
ec2Instances.add(getAnInstance(anInstanceId));
}
when(awsClient.createEc2Client(any(), anyString())).thenReturn(ec2Client);
AmazonServiceException amazonServiceException = new AmazonServiceException("Instance with id could not be found: 'anInstanceId0'");
amazonServiceException.setErrorCode(INSTANCE_NOT_FOUND_ERROR_CODE);
DescribeInstancesResult describeInstancesResult1 = new DescribeInstancesResult().withReservations(List.of(new Reservation().withInstances(ec2Instances.subList(1, 5))));
AmazonServiceException amazonServiceException2 = new AmazonServiceException("Instance with id could not be found: 'anInstanceId5'");
amazonServiceException2.setErrorCode(INSTANCE_NOT_FOUND_ERROR_CODE);
DescribeInstancesResult describeInstancesResult2 = new DescribeInstancesResult().withReservations(List.of(new Reservation().withInstances(ec2Instances.subList(6, 10))));
DescribeInstancesResult describeInstancesResult3 = new DescribeInstancesResult().withReservations(List.of(new Reservation().withInstances(ec2Instances.subList(10, ec2Instances.size()))));
when(ec2Client.describeInstances(any())).thenThrow(amazonServiceException).thenReturn(describeInstancesResult1).thenThrow(amazonServiceException2).thenReturn(describeInstancesResult2).thenReturn(describeInstancesResult3);
List<CloudVmMetaDataStatus> metaDataStatuses = underTest.collect(authenticatedContext, resources, cloudInstances, allInstances);
verify(ec2Client, times(5)).describeInstances(any());
assertFalse(metaDataStatuses.isEmpty());
assertEquals(cloudInstances.size(), metaDataStatuses.size());
for (int i = 0; i < 15; i++) {
String instanceId = i == 0 || i == 5 ? String.valueOf(i) : "anInstanceId" + i;
verifyCloudInstance(metaDataStatuses, instanceId, "subnet-123", "az1");
}
}
Aggregations