Search in sources :

Example 1 with DescribeInstanceTypesResult

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<>());
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) DescribeInstanceTypesRequest(com.amazonaws.services.ec2.model.DescribeInstanceTypesRequest) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) InstanceTypeOffering(com.amazonaws.services.ec2.model.InstanceTypeOffering) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DescribeInstanceTypeOfferingsRequest(com.amazonaws.services.ec2.model.DescribeInstanceTypeOfferingsRequest) ArrayList(java.util.ArrayList) AvailabilityZone(com.amazonaws.services.ec2.model.AvailabilityZone) Region(com.amazonaws.services.ec2.model.Region) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with DescribeInstanceTypesResult

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);
        }
    }
}
Also used : VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) DiskInfo(com.amazonaws.services.ec2.model.DiskInfo) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) InstanceStorageInfo(com.amazonaws.services.ec2.model.InstanceStorageInfo) InstanceTypeInfo(com.amazonaws.services.ec2.model.InstanceTypeInfo) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)

Example 3 with DescribeInstanceTypesResult

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);
}
Also used : DescribeInstanceTypesRequest(com.amazonaws.services.ec2.model.DescribeInstanceTypesRequest) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Test(org.junit.jupiter.api.Test)

Aggregations

DescribeInstanceTypesRequest (com.amazonaws.services.ec2.model.DescribeInstanceTypesRequest)2 AvailabilityZone (com.amazonaws.services.ec2.model.AvailabilityZone)1 DescribeInstanceTypeOfferingsRequest (com.amazonaws.services.ec2.model.DescribeInstanceTypeOfferingsRequest)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1 DiskInfo (com.amazonaws.services.ec2.model.DiskInfo)1 InstanceStorageInfo (com.amazonaws.services.ec2.model.InstanceStorageInfo)1 InstanceTypeInfo (com.amazonaws.services.ec2.model.InstanceTypeInfo)1 InstanceTypeOffering (com.amazonaws.services.ec2.model.InstanceTypeOffering)1 Region (com.amazonaws.services.ec2.model.Region)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)1 VmTypeMetaBuilder (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder)1 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)1 ArrayList (java.util.ArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1