Search in sources :

Example 1 with InstanceType

use of com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType in project photon-model by vmware.

the class AWSInstanceContext method getInstanceTypeInfo.

private DeferredResult<AWSInstanceContext> getInstanceTypeInfo(AWSInstanceContext context) {
    String instanceType = context.child.description.instanceType;
    if (instanceType == null) {
        instanceType = context.child.description.name;
    }
    if (instanceType == null) {
        String msg = String.format("AWS Instance type not specified for [%s] VM.", context.child.name);
        return DeferredResult.failed(new IllegalStateException(msg));
    }
    URI instanceTypeServiceURI = UriUtils.buildUri(context.service.getHost(), AWSInstanceTypeService.SELF_LINK);
    instanceTypeServiceURI = UriUtils.appendQueryParam(instanceTypeServiceURI, URI_PARAM_ENDPOINT, context.child.endpointLink);
    instanceTypeServiceURI = UriUtils.appendQueryParam(instanceTypeServiceURI, URI_PARAM_INSTANCE_TYPE, instanceType);
    Operation op = Operation.createGet(instanceTypeServiceURI).setReferer(context.service.getHost().getUri());
    DeferredResult<InstanceType> dr = context.service.sendWithDeferredResult(op, InstanceType.class);
    return dr.thenAccept(type -> {
        context.instanceTypeInfo = type;
    }).handle((all, err) -> {
        if (err != null) {
            String msg = String.format("Error getting instance-type info for [%s] VM. Reason [%s]", context.child.name, err.getMessage());
            throw new IllegalStateException(msg, err);
        }
        return context;
    });
}
Also used : InstanceNetworkInterfaceSpecification(com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) CREATE_CONTEXT_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.CREATE_CONTEXT_PROP_NAME) Function(java.util.function.Function) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) AWSSecurityGroupClient(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSSecurityGroupClient) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) URI_PARAM_INSTANCE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_INSTANCE_TYPE) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Filter(com.amazonaws.services.ec2.model.Filter) Collections.singletonMap(java.util.Collections.singletonMap) URI(java.net.URI) Subnet(com.amazonaws.services.ec2.model.Subnet) StatelessService(com.vmware.xenon.common.StatelessService) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) Vpc(com.amazonaws.services.ec2.model.Vpc) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Collectors(java.util.stream.Collectors) AWS_VPC_ID_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VPC_ID_FILTER) URI_PARAM_ENDPOINT(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_ENDPOINT) InstanceType(com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType) List(java.util.List) BaseComputeInstanceContext(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext) AWS_SUBNET_ID_FILTER(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_SUBNET_ID_FILTER) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) DiskService(com.vmware.photon.controller.model.resources.DiskService) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) Operation(com.vmware.xenon.common.Operation) InstanceType(com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType) URI(java.net.URI)

Example 2 with InstanceType

use of com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType in project photon-model by vmware.

the class AzureInstanceTypeServiceTest method testGetInstanceTypes.

@Test
public void testGetInstanceTypes() throws Throwable {
    Assume.assumeFalse(this.isMock);
    TestContext ctx = getHost().testCreate(1);
    URI uri = buildUri(getHost(), AzureInstanceTypeService.SELF_LINK, buildUriQuery("endpoint", this.endpointState.documentSelfLink));
    send(Operation.createGet(uri).setCompletion((op, t) -> {
        try {
            if (t != null) {
                ctx.failIteration(t);
                return;
            }
            assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
            InstanceTypeList instanceTypesList = op.getBody(InstanceTypeList.class);
            assertNotNull("Tenant links should ne set.", instanceTypesList.tenantLinks);
            assertEquals("Tenant links size equal to endpoint tenant links size is " + "expected.", this.endpointState.tenantLinks.size(), instanceTypesList.tenantLinks.size());
            assertNotNull("Instance types should not be null.", instanceTypesList.instanceTypes);
            InstanceType instanceTypeBasicA0 = instanceTypesList.instanceTypes.stream().filter(instanceType -> VirtualMachineSizeTypes.BASIC_A0.toString().equals(instanceType.name)).findFirst().get();
            assertNotNull("BASIC_A0 Instance type should not be null.", instanceTypeBasicA0);
            final String regionId = this.endpointState.endpointProperties.get(EndpointConfigRequest.REGION_KEY);
            final List<VirtualMachineSizeInner> azureSizes = getAzureSdkClients().getComputeManager().inner().virtualMachineSizes().list(regionId);
            assertEquals(azureSizes.size(), instanceTypesList.instanceTypes.size());
            VirtualMachineSizeInner azureSizeBasicA0 = azureSizes.stream().filter(azureSize -> VirtualMachineSizeTypes.BASIC_A0.toString().equals(azureSize.name())).findFirst().get();
            assertEquals("Invalid cpuCount", azureSizeBasicA0.numberOfCores(), instanceTypeBasicA0.cpuCount);
            assertEquals("Invalid dataDiskMaxCount", azureSizeBasicA0.maxDataDiskCount(), instanceTypeBasicA0.dataDiskMaxCount);
            assertEquals("Invalid dataDiskSizeInMB", azureSizeBasicA0.resourceDiskSizeInMB(), instanceTypeBasicA0.dataDiskSizeInMB);
            assertEquals("Invalid bootDiskSizeInMB", azureSizeBasicA0.osDiskSizeInMB(), instanceTypeBasicA0.bootDiskSizeInMB);
            assertEquals("Invalid memoryInMB", azureSizeBasicA0.memoryInMB(), instanceTypeBasicA0.memoryInMB);
            ctx.completeIteration();
        } catch (AssertionError err) {
            ctx.failIteration(err);
        }
    }));
    testWait(ctx);
}
Also used : Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Test(org.junit.Test) VirtualMachineSizeTypes(com.microsoft.azure.management.compute.VirtualMachineSizeTypes) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) VirtualMachineSizeInner(com.microsoft.azure.management.compute.implementation.VirtualMachineSizeInner) InstanceType(com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType) List(java.util.List) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) TestContext(com.vmware.xenon.common.test.TestContext) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) UriUtils(com.vmware.xenon.common.UriUtils) UriUtils.buildUri(com.vmware.xenon.common.UriUtils.buildUri) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) Assume(org.junit.Assume) URI(java.net.URI) UriUtils.buildUriQuery(com.vmware.xenon.common.UriUtils.buildUriQuery) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TestContext(com.vmware.xenon.common.test.TestContext) List(java.util.List) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) InstanceType(com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType) URI(java.net.URI) VirtualMachineSizeInner(com.microsoft.azure.management.compute.implementation.VirtualMachineSizeInner) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) Test(org.junit.Test) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)

Aggregations

InstanceType (com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType)2 Operation (com.vmware.xenon.common.Operation)2 UriUtils (com.vmware.xenon.common.UriUtils)2 URI (java.net.URI)2 List (java.util.List)2 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 CreateSubnetRequest (com.amazonaws.services.ec2.model.CreateSubnetRequest)1 CreateSubnetResult (com.amazonaws.services.ec2.model.CreateSubnetResult)1 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)1 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)1 DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)1 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1 InstanceNetworkInterfaceSpecification (com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification)1 Subnet (com.amazonaws.services.ec2.model.Subnet)1 Tag (com.amazonaws.services.ec2.model.Tag)1 Vpc (com.amazonaws.services.ec2.model.Vpc)1 VirtualMachineSizeTypes (com.microsoft.azure.management.compute.VirtualMachineSizeTypes)1 VirtualMachineSizeInner (com.microsoft.azure.management.compute.implementation.VirtualMachineSizeInner)1 CREATE_CONTEXT_PROP_NAME (com.vmware.photon.controller.model.ComputeProperties.CREATE_CONTEXT_PROP_NAME)1