use of com.amazonaws.services.ec2.model.DescribeInstanceTypesResult in project cloudbreak by hortonworks.
the class AwsPlatformResourcesTest method setUp.
@BeforeEach
public void setUp() {
AvailabilityZone availabilityZone = new AvailabilityZone();
availabilityZone.setZoneName(AZ_NAME);
Region awsRegion = new Region();
awsRegion.setRegionName(REGION_NAME);
InstanceTypeOffering instanceTypeOffering = new InstanceTypeOffering();
instanceTypeOffering.setInstanceType("m5.2xlarge");
instanceTypeInfos = new ArrayList<>();
instanceTypeInfos.add(getInstanceTypeInfo("m5.2xlarge"));
describeInstanceTypesResult.setInstanceTypes(instanceTypeInfos);
when(awsDefaultZoneProvider.getDefaultZone(any(CloudCredential.class))).thenReturn(REGION_NAME);
when(awsClient.createEc2Client(any(AwsCredentialView.class))).thenReturn(amazonEC2Client);
when(awsClient.createEc2Client(any(AwsCredentialView.class), any())).thenReturn(amazonEC2Client);
when(amazonEC2Client.describeRegions(any(DescribeRegionsRequest.class))).thenReturn(describeRegionsResult);
when(describeRegionsResult.getRegions()).thenReturn(Collections.singletonList(awsRegion));
when(awsAvailabilityZoneProvider.describeAvailabilityZones(any(), any(), any())).thenReturn(List.of(availabilityZone));
when(amazonEC2Client.describeInstanceTypeOfferings(any(DescribeInstanceTypeOfferingsRequest.class))).thenReturn(describeInstanceTypeOfferingsResult);
when(amazonEC2Client.describeInstanceTypes(any(DescribeInstanceTypesRequest.class))).thenReturn(describeInstanceTypesResult);
when(describeInstanceTypesResult.getInstanceTypes()).thenReturn(instanceTypeInfos);
when(describeInstanceTypeOfferingsResult.getInstanceTypeOfferings()).thenReturn(Collections.singletonList(instanceTypeOffering));
ReflectionTestUtils.setField(underTest, "fetchMaxItems", 500);
region = region(REGION_NAME);
ReflectionTestUtils.setField(underTest, "enabledRegions", Set.of(region));
ReflectionTestUtils.setField(underTest, "enabledAvailabilityZones", Set.of(availabilityZone(AZ_NAME)));
cloudCredential = new ExtendedCloudCredential(new CloudCredential("crn", "aws-credential", "account"), "AWS", null, "crn", "id", new ArrayList<>());
}
use of com.amazonaws.services.ec2.model.DescribeInstanceTypesResult in project cloudbreak by hortonworks.
the class AwsPlatformResources method getVmTypesWithAwsCall.
private void getVmTypesWithAwsCall(Set<VmType> awsInstances, DescribeInstanceTypesResult describeInstanceTypesResult) {
for (InstanceTypeInfo instanceType : describeInstanceTypesResult.getInstanceTypes()) {
if (!instanceType.isBareMetal()) {
VmTypeMetaBuilder vmTypeMetaBuilder = VmTypeMetaBuilder.builder().withCpuAndMemory(instanceType.getVCpuInfo().getDefaultVCpus(), getMemory(instanceType)).withMagneticConfig(new VolumeParameterConfig(MAGNETIC, MINIMUM_MAGNETIC_SIZE, MAXIMUM_MAGNETIC_SIZE, ONE, TWENTY_FOUR)).withSsdConfig(new VolumeParameterConfig(SSD, MINIMUM_SSD_SIZE, MAXIMUM_SSD_SIZE, ONE, TWENTY_FOUR)).withSt1Config(new VolumeParameterConfig(ST1, MINIMUM_ST1_SIZE, MAXIMUM_ST1_SIZE, ONE, TWENTY_FOUR));
if (instanceType.getInstanceStorageSupported()) {
InstanceStorageInfo instanceStorageInfo = instanceType.getInstanceStorageInfo();
DiskInfo diskInfo = instanceStorageInfo.getDisks().get(0);
vmTypeMetaBuilder.withEphemeralConfig(new VolumeParameterConfig(EPHEMERAL, diskInfo.getSizeInGB().intValue(), diskInfo.getSizeInGB().intValue(), diskInfo.getCount(), diskInfo.getCount()));
}
if (getEncryptionSupported(instanceType)) {
vmTypeMetaBuilder.withVolumeEncryptionSupport(true);
}
VmType vmType = vmTypeWithMeta(instanceType.getInstanceType(), vmTypeMetaBuilder.create(), true);
awsInstances.add(vmType);
}
}
}
use of com.amazonaws.services.ec2.model.DescribeInstanceTypesResult in project cloudbreak by hortonworks.
the class AwsPlatformResourcesTest method virtualMachinesShouldBeFilteredByEnabledAvailabilityZones.
@Test
public void virtualMachinesShouldBeFilteredByEnabledAvailabilityZones() {
setUpRegions();
instanceTypeInfos.add(getInstanceTypeInfo("vm1"));
instanceTypeInfos.add(getInstanceTypeInfo("vm2"));
describeInstanceTypesResult.setInstanceTypes(instanceTypeInfos);
when(amazonEC2Client.describeInstanceTypes(any(DescribeInstanceTypesRequest.class))).thenReturn(describeInstanceTypesResult);
when(describeInstanceTypesResult.getInstanceTypes()).thenReturn(instanceTypeInfos);
ReflectionTestUtils.setField(underTest, "defaultVmTypes", Map.of(region, vmType("vm1"), region(NOT_ENABLED_REGION_NAME), vmType("vm2")));
ReflectionTestUtils.setField(underTest, "disabledInstanceTypes", List.of());
CloudVmTypes cloudVmTypes = underTest.virtualMachines(cloudCredential, region, Map.of());
assertThat(cloudVmTypes.getCloudVmResponses()).containsKey(AZ_NAME).doesNotContainKey(NOT_ENABLED_AZ_NAME);
assertThat(cloudVmTypes.getDefaultCloudVmResponses()).containsKey(AZ_NAME).doesNotContainKey(NOT_ENABLED_AZ_NAME);
}
Aggregations