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);
}
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);
}
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);
}
Aggregations