Search in sources :

Example 1 with InstanceTypeList

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

the class AWSInstanceTypeServiceTest method testGetInstanceTypesPositive.

@Test
public void testGetInstanceTypesPositive() throws Throwable {
    EndpointState ep = createEndpointState();
    TestContext ctx = this.host.testCreate(1);
    Operation getOperation = Operation.createGet(UriUtils.buildUri(this.host, AWSInstanceTypeService.SELF_LINK + "?endpoint=" + ep.documentSelfLink)).setCompletion((operation, throwable) -> {
        try {
            if (throwable != null) {
                ctx.failIteration(throwable);
                return;
            }
            assertEquals(Operation.STATUS_CODE_OK, operation.getStatusCode());
            InstanceTypeList instanceTypes = operation.getBody(InstanceTypeList.class);
            assertNotNull("Tenant links should ne set.", instanceTypes.tenantLinks);
            assertEquals("Tenant links size equal to endpoint tenant links size is " + "expecteed.", ep.tenantLinks.size(), instanceTypes.tenantLinks.size());
            assertNotNull("Instance types should not be null.", instanceTypes.instanceTypes);
            instanceTypes.instanceTypes.stream().filter(instanceType -> instanceType.id == null || instanceType.name == null).findFirst().ifPresent(instanceType -> fail("Found instance type without id " + "or name."));
            // Validate that all types have cpu and memory extended data set.
            instanceTypes.instanceTypes.stream().filter(instanceType -> instanceType.cpuCount == null || instanceType.memoryInMB == null).findFirst().ifPresent(instanceType -> fail("Found instance type without extended data present: " + instanceType.id));
            // Check that one of the well known type is present.
            InstanceTypeList.InstanceType t2MicroType = instanceTypes.instanceTypes.stream().filter(instanceType -> InstanceType.T2Micro.toString().equals(instanceType.id)).findFirst().orElseThrow(() -> new AssertionError("Unable to " + "find t2.micro instance type."));
            assertEquals(1, t2MicroType.cpuCount.intValue());
            assertEquals(1024, t2MicroType.memoryInMB.intValue());
            assertNotNull(t2MicroType.storageType);
            assertNotNull(t2MicroType.networkType);
            ctx.completeIteration();
        } catch (AssertionError err) {
            ctx.failIteration(err);
        }
    });
    this.send(getOperation);
    this.testWait(ctx);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TestContext(com.vmware.xenon.common.test.TestContext) Operation(com.vmware.xenon.common.Operation) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 2 with InstanceTypeList

use of com.vmware.photon.controller.model.support.InstanceTypeList 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)

Example 3 with InstanceTypeList

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

the class AWSInstanceTypeService method getInstanceTypes.

/**
 * Return the instance types by loading them from AWS SDK {@link InstanceType}.
 */
private DeferredResult<Context> getInstanceTypes(Context context) {
    AssertUtil.assertNotNull(context.endpointState, "Endpoint state was not retrieved.");
    context.instanceTypes = new InstanceTypeList();
    // Set tenant links as specified in the endpoint.
    context.instanceTypes.tenantLinks = context.endpointState.tenantLinks;
    context.instanceTypes.instanceTypes = // Use AWS SDK InstanceType enum as primary source of instance type data.
    Arrays.stream(InstanceType.values()).map(instanceType -> {
        InstanceTypeList.InstanceType result = new InstanceTypeList.InstanceType(instanceType.toString(), instanceType.toString());
        InstanceTypeList.InstanceType instanceTypeInfo = this.instanceTypeInfo.get(instanceType.toString());
        if (instanceTypeInfo != null) {
            // We have additional information -> populate additional fields.
            result.cpuCount = instanceTypeInfo.cpuCount;
            result.memoryInMB = instanceTypeInfo.memoryInMB;
            result.networkType = instanceTypeInfo.networkType;
            result.storageType = instanceTypeInfo.storageType;
            result.dataDiskMaxCount = instanceTypeInfo.dataDiskMaxCount;
            result.dataDiskSizeInMB = instanceTypeInfo.dataDiskSizeInMB;
        }
        return result;
    }).filter(instanceType -> !Integer.valueOf(-1).equals(instanceType.cpuCount)).collect(Collectors.toList());
    return DeferredResult.completed(context);
}
Also used : Arrays(java.util.Arrays) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) URI_PARAM_ENDPOINT(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_ENDPOINT) IOUtils(org.apache.commons.io.IOUtils) FileUtils(com.vmware.xenon.common.FileUtils) Utils(com.vmware.xenon.common.Utils) URI_PARAM_INSTANCE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_INSTANCE_TYPE) Map(java.util.Map) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList) InstanceType(com.amazonaws.services.ec2.model.InstanceType) AssertUtil(com.vmware.photon.controller.model.util.AssertUtil) InputStream(java.io.InputStream) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) InstanceType(com.amazonaws.services.ec2.model.InstanceType) InstanceTypeList(com.vmware.photon.controller.model.support.InstanceTypeList)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 InstanceTypeList (com.vmware.photon.controller.model.support.InstanceTypeList)3 Operation (com.vmware.xenon.common.Operation)3 UriUtils (com.vmware.xenon.common.UriUtils)2 TestContext (com.vmware.xenon.common.test.TestContext)2 Test (org.junit.Test)2 InstanceType (com.amazonaws.services.ec2.model.InstanceType)1 VirtualMachineSizeTypes (com.microsoft.azure.management.compute.VirtualMachineSizeTypes)1 VirtualMachineSizeInner (com.microsoft.azure.management.compute.implementation.VirtualMachineSizeInner)1 EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)1 URI_PARAM_ENDPOINT (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_ENDPOINT)1 URI_PARAM_INSTANCE_TYPE (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.URI_PARAM_INSTANCE_TYPE)1 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)1 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)1 EndpointService (com.vmware.photon.controller.model.resources.EndpointService)1 InstanceType (com.vmware.photon.controller.model.support.InstanceTypeList.InstanceType)1 TestUtils (com.vmware.photon.controller.model.tasks.TestUtils)1 AssertUtil (com.vmware.photon.controller.model.util.AssertUtil)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 FileUtils (com.vmware.xenon.common.FileUtils)1