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