use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class AwsPlatformResourcesTest method collectInstanceStorageCountWhenInstanceTypeIsNotFoundTest.
@Test
void collectInstanceStorageCountWhenInstanceTypeIsNotFoundTest() {
ReflectionTestUtils.setField(underTest, "disabledInstanceTypes", Collections.emptyList());
CloudContext cloudContext = new Builder().withLocation(Location.location(region, availabilityZone(AZ_NAME))).build();
AuthenticatedContext ac = new AuthenticatedContext(cloudContext, cloudCredential);
InstanceStoreMetadata instanceStoreMetadata = underTest.collectInstanceStorageCount(ac, Collections.singletonList("unsupported"), List.of());
assertNull(instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("unsupported"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("unsupported"));
assertNull(instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("m5.2xlarge"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("m5.2xlarge"));
instanceStoreMetadata = underTest.collectInstanceStorageCount(ac, new ArrayList<>(), List.of());
assertNull(instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("m5.2xlarge"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("m5.2xlarge"));
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class AwsPlatformResourcesTest method collectInstanceStorageCountTest.
@Test
void collectInstanceStorageCountTest() {
ReflectionTestUtils.setField(underTest, "disabledInstanceTypes", Collections.emptyList());
CloudContext cloudContext = new Builder().withLocation(Location.location(region, availabilityZone(AZ_NAME))).build();
AuthenticatedContext ac = new AuthenticatedContext(cloudContext, cloudCredential);
InstanceStoreMetadata instanceStoreMetadata = underTest.collectInstanceStorageCount(ac, Collections.singletonList("m5.2xlarge"), List.of());
assertEquals(2, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("m5.2xlarge"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("unsupported"));
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class AzurePlatformResourcesTest method collectInstanceStorageCountWhenInstanceTypeIsNotFoundTest.
@Test
void collectInstanceStorageCountWhenInstanceTypeIsNotFoundTest() {
Region region = Region.region("us-west-1");
CloudContext cloudContext = new CloudContext.Builder().withLocation(Location.location(region, availabilityZone("us-west-1"))).build();
AuthenticatedContext ac = new AuthenticatedContext(cloudContext, cloudCredential);
Set<VirtualMachineSize> virtualMachineSizes = new HashSet<>();
when(azureClient.getVmTypes(region.value())).thenReturn(virtualMachineSizes);
InstanceStoreMetadata instanceStoreMetadata = underTest.collectInstanceStorageCount(ac, Collections.singletonList("unsupported"));
assertNull(instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("unsupported"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("unsupported"));
assertNull(instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("Standard_D8_v3"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("Standard_D8_v3"));
when(azureClient.getVmTypes(region.value())).thenReturn(virtualMachineSizes);
instanceStoreMetadata = underTest.collectInstanceStorageCount(ac, new ArrayList<>());
assertNull(instanceStoreMetadata.mapInstanceTypeToInstanceStoreCount("Standard_D8_v3"));
assertEquals(0, instanceStoreMetadata.mapInstanceTypeToInstanceStoreCountNullHandled("Standard_D8_v3"));
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata in project cloudbreak by hortonworks.
the class AzurePlatformResources method collectInstanceStorageCount.
public InstanceStoreMetadata collectInstanceStorageCount(AuthenticatedContext ac, List<String> instanceTypes) {
try {
AzureClient client = azureClientService.getClient(ac.getCloudCredential());
Set<VirtualMachineSize> vmTypes = client.getVmTypes(ac.getCloudContext().getLocation().getRegion().value());
Map<String, VolumeParameterConfig> instanceTypeToInstanceStorageMap = vmTypes.stream().filter(vmType -> instanceTypes.contains(vmType.name())).filter(vmType -> vmType.resourceDiskSizeInMB() != NO_RESOURCE_DISK_ATTACHED_TO_INSTANCE).collect(Collectors.toMap(VirtualMachineSize::name, vmType -> new VolumeParameterConfig(EPHEMERAL, (int) (vmType.resourceDiskSizeInMB() / NO_MB_PER_GB), (int) (vmType.resourceDiskSizeInMB() / NO_MB_PER_GB), 1, 1)));
return new InstanceStoreMetadata(instanceTypeToInstanceStorageMap);
} catch (Exception e) {
LOGGER.warn("Failed to get vm type data: {}", instanceTypes, e);
throw new CloudConnectorException(e.getMessage(), e);
}
}
Aggregations