Search in sources :

Example 6 with InstanceStoreMetadata

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"));
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Builder(com.sequenceiq.cloudbreak.cloud.context.CloudContext.Builder) ArrayList(java.util.ArrayList) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Test(org.junit.jupiter.api.Test)

Example 7 with InstanceStoreMetadata

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"));
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Builder(com.sequenceiq.cloudbreak.cloud.context.CloudContext.Builder) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Test(org.junit.jupiter.api.Test)

Example 8 with InstanceStoreMetadata

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"));
}
Also used : VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) Region(com.sequenceiq.cloudbreak.cloud.model.Region) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with InstanceStoreMetadata

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);
    }
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) MinimalHardwareFilter(com.sequenceiq.cloudbreak.filter.MinimalHardwareFilter) Cacheable(org.springframework.cache.annotation.Cacheable) LoggerFactory(org.slf4j.LoggerFactory) Identity(com.microsoft.azure.management.msi.Identity) AzureRegionProvider(com.sequenceiq.cloudbreak.cloud.azure.resource.AzureRegionProvider) StringUtils(org.apache.commons.lang3.StringUtils) PrivateZone(com.microsoft.azure.management.privatedns.v2018_09_01.PrivateZone) InvalidParameterException(java.security.InvalidParameterException) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudAccessConfig(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig) CloudSshKeys(com.sequenceiq.cloudbreak.cloud.model.CloudSshKeys) Map(java.util.Map) BadRequestException(javax.ws.rs.BadRequestException) EPHEMERAL(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.EPHEMERAL) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) CloudPrivateDnsZone(com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZone) Predicate(java.util.function.Predicate) Collection(java.util.Collection) CloudEncryptionKeys(com.sequenceiq.cloudbreak.cloud.model.CloudEncryptionKeys) CloudResourceGroups(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroups) Set(java.util.Set) Collectors(java.util.stream.Collectors) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) Objects(java.util.Objects) List(java.util.List) CloudPrivateDnsZones(com.sequenceiq.cloudbreak.cloud.model.dns.CloudPrivateDnsZones) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) Entry(java.util.Map.Entry) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) MAGNETIC(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.MAGNETIC) CloudSecurityGroup(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroup) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Subnet(com.microsoft.azure.management.network.Subnet) HashMap(java.util.HashMap) CloudGateWays(com.sequenceiq.cloudbreak.cloud.model.CloudGateWays) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Network(com.microsoft.azure.management.network.Network) PagedList(com.microsoft.azure.PagedList) Service(org.springframework.stereotype.Service) PlatformResourceSecurityGroupFilterView(com.sequenceiq.cloudbreak.cloud.model.view.PlatformResourceSecurityGroupFilterView) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) PlatformResources(com.sequenceiq.cloudbreak.cloud.PlatformResources) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) NetworkSecurityGroup(com.microsoft.azure.management.network.NetworkSecurityGroup) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) SSD(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType.SSD) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) CloudResourceGroup(com.sequenceiq.cloudbreak.cloud.model.resourcegroup.CloudResourceGroup) CloudSecurityGroups(com.sequenceiq.cloudbreak.cloud.model.CloudSecurityGroups) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) PermanentlyFailedException(com.sequenceiq.cloudbreak.util.PermanentlyFailedException) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) InvalidParameterException(java.security.InvalidParameterException) BadRequestException(javax.ws.rs.BadRequestException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) PermanentlyFailedException(com.sequenceiq.cloudbreak.util.PermanentlyFailedException)

Aggregations

InstanceStoreMetadata (com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Region (com.sequenceiq.cloudbreak.cloud.model.Region)4 HashSet (java.util.HashSet)4 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)2 Builder (com.sequenceiq.cloudbreak.cloud.context.CloudContext.Builder)2 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 SdkClientException (com.amazonaws.SdkClientException)1 ListTablesRequest (com.amazonaws.services.dynamodbv2.model.ListTablesRequest)1 ListTablesResult (com.amazonaws.services.dynamodbv2.model.ListTablesResult)1 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 DescribeAvailabilityZonesRequest (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)1 DescribeInstanceTypeOfferingsRequest (com.amazonaws.services.ec2.model.DescribeInstanceTypeOfferingsRequest)1 DescribeInstanceTypesRequest (com.amazonaws.services.ec2.model.DescribeInstanceTypesRequest)1 DescribeInstanceTypesResult (com.amazonaws.services.ec2.model.DescribeInstanceTypesResult)1 DescribeInternetGatewaysRequest (com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest)1