use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AWSPowerServiceTest method test.
@Test
public void test() throws Throwable {
EndpointState endpoint = configureEndpoint();
assertNotNull(endpoint.resourcePoolLink);
ComputeState computeHost = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, endpoint.computeLink));
assertNotNull(computeHost);
ComputeDescription computeHostDesc = this.host.getServiceState(null, ComputeDescription.class, UriUtils.buildUri(this.host, endpoint.computeDescriptionLink));
assertNotNull(computeHostDesc);
assertNotNull("Power addpter must be configured", computeHostDesc.powerAdapterReference);
boolean addNonExistingSecurityGroup = false;
ComputeState cs = TestAWSSetupUtils.createAWSVMResource(this.host, computeHost, endpoint, getClass(), "trainingVM", zoneId, this.regionId, null, this.singleNicSpec, addNonExistingSecurityGroup, this.awsTestContext);
this.computesToRemove.add(cs.documentSelfLink);
assertEquals(PowerState.UNKNOWN, cs.powerState);
ProvisionComputeTaskState state = new ProvisionComputeTaskState();
state.computeLink = cs.documentSelfLink;
state.isMockRequest = this.isMock;
state.taskSubStage = ProvisionComputeTaskState.SubStage.CREATING_HOST;
state = TestUtils.doPost(this.host, state, ProvisionComputeTaskState.class, UriUtils.buildUri(this.host, ProvisionComputeTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(ProvisionComputeTaskState.class, state.documentSelfLink);
ComputeState compute = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, cs.documentSelfLink));
changePowerState(computeHostDesc, compute.documentSelfLink, PowerState.OFF);
if (!this.isMock) {
waitForInstancesToBeStopped(this.client, this.host, Arrays.asList(compute.id));
}
changePowerState(computeHostDesc, compute.documentSelfLink, PowerState.ON);
if (!this.isMock) {
final int errorRate = 0;
waitForProvisioningToComplete(Arrays.asList(compute.id), this.host, this.client, errorRate);
}
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AWSComputeDescriptionEnumerationAdapterService method createComputeDescriptionOperation.
/**
* Creates a compute description based on the VM instance information received from AWS. Futher creates an operation
* that will post to the compute description service for the creation of the compute description.
*/
private Operation createComputeDescriptionOperation(InstanceDescKey cd, AWSComputeDescriptionCreationState cdState) {
// Create a compute description for the AWS instance at hand
ComputeDescriptionService.ComputeDescription computeDescription = new ComputeDescriptionService.ComputeDescription();
computeDescription.instanceAdapterReference = AdapterUriUtil.buildAdapterUri(getHost(), AWSUriPaths.AWS_INSTANCE_ADAPTER);
computeDescription.enumerationAdapterReference = AdapterUriUtil.buildAdapterUri(getHost(), AWSUriPaths.AWS_ENUMERATION_CREATION_ADAPTER);
computeDescription.statsAdapterReference = AdapterUriUtil.buildAdapterUri(getHost(), AWSUriPaths.AWS_STATS_ADAPTER);
computeDescription.diskAdapterReference = AdapterUriUtil.buildAdapterUri(getHost(), AWSUriPaths.AWS_DISK_ADAPTER);
// We don't want cost adapter to run for each instance. Remove it from the list of stats adapter.
if (cdState.parentDescription.statsAdapterReferences != null) {
computeDescription.statsAdapterReferences = cdState.parentDescription.statsAdapterReferences.stream().filter(uri -> !uri.getPath().endsWith(AWSCostStatsService.SELF_LINK)).collect(Collectors.toSet());
}
computeDescription.environmentName = ComputeDescription.ENVIRONMENT_NAME_AWS;
computeDescription.zoneId = cd.zoneId;
computeDescription.regionId = cd.regionId;
computeDescription.id = cd.instanceType;
computeDescription.instanceType = cd.instanceType;
computeDescription.name = cd.instanceType;
computeDescription.endpointLink = cdState.endpointLink;
if (computeDescription.endpointLinks == null) {
computeDescription.endpointLinks = new HashSet<String>();
}
computeDescription.endpointLinks.add(cdState.endpointLink);
computeDescription.tenantLinks = cdState.tenantLinks;
// Book keeping information about the creation of the compute description in the system.
computeDescription.customProperties = new HashMap<>();
computeDescription.customProperties.put(SOURCE_TASK_LINK, ResourceEnumerationTaskService.FACTORY_LINK);
computeDescription.computeHostLink = cdState.parentComputeLink;
return Operation.createPost(this, ComputeDescriptionService.FACTORY_LINK).setBody(computeDescription).setReferer(getHost().getUri());
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class AWSMissingResourcesEnumerationService method populateComputeDescription.
/**
* creates a compute description for the identified linked accounts
* @return
*/
private ComputeDescription populateComputeDescription(AwsMissingResourcesEnumContext context, String linkedAccountId) {
ComputeDescription cd = new ComputeDescription();
ComputeStateWithDescription primaryAccountCompute = context.request.primaryAccountCompute;
cd.regionId = primaryAccountCompute.regionId;
cd.environmentName = primaryAccountCompute.environmentName;
cd.tenantLinks = primaryAccountCompute.tenantLinks;
cd.id = generateUuidFromStr(linkedAccountId + context.request.primaryAccountCompute.endpointLink);
cd.documentSelfLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, cd.id);
cd.name = primaryAccountCompute.name + "_" + linkedAccountId;
cd.endpointLink = primaryAccountCompute.endpointLink;
if (cd.endpointLinks == null) {
cd.endpointLinks = new HashSet<>();
}
cd.endpointLinks.add(primaryAccountCompute.endpointLink);
cd.computeHostLink = primaryAccountCompute.computeHostLink;
return cd;
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class BaseVSphereAdapterTest method createEndpoint.
protected EndpointState createEndpoint(Consumer<ComputeState> cs, Consumer<ComputeDescription> desc) throws Throwable {
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
EndpointState endpoint = new EndpointState();
validateEndpoint.endpointState = endpoint;
endpoint.endpointType = PhotonModelConstants.EndpointType.vsphere.name();
endpoint.name = PhotonModelConstants.EndpointType.vsphere.name();
endpoint.regionId = this.datacenterId;
endpoint.endpointProperties = new HashMap<>();
endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.vcUsername != null ? this.vcUsername : "username");
endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.vcPassword != null ? this.vcPassword : "password");
endpoint.endpointProperties.put(HOST_NAME_KEY, this.vcUrl != null ? URI.create(this.vcUrl).toURL().getHost() : "hostname");
validateEndpoint.options = isMock() ? EnumSet.of(TaskOption.IS_MOCK) : null;
configureEndpoint(endpoint);
EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
EndpointAllocationTaskState taskState = this.host.getServiceState(EnumSet.noneOf(TestProperty.class), EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, outTask.documentSelfLink));
if (cs != null) {
cs.accept(this.host.getServiceState(EnumSet.noneOf(TestProperty.class), ComputeState.class, UriUtils.buildUri(this.host, taskState.endpointState.computeLink)));
}
if (desc != null) {
desc.accept(this.host.getServiceState(EnumSet.noneOf(TestProperty.class), ComputeDescription.class, UriUtils.buildUri(this.host, taskState.endpointState.computeDescriptionLink)));
}
this.resourcePool = this.host.getServiceState(EnumSet.noneOf(TestProperty.class), ResourcePoolState.class, UriUtils.buildUri(this.host, taskState.endpointState.resourcePoolLink));
this.auth = this.host.getServiceState(EnumSet.noneOf(TestProperty.class), AuthCredentialsServiceState.class, UriUtils.buildUri(this.host, taskState.endpointState.authCredentialsLink));
return taskState.endpointState;
}
use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.
the class TestVSphereProvisionFromImageLink method createVmDescription.
private ComputeDescription createVmDescription() throws Throwable {
ComputeDescription computeDesc = new ComputeDescription();
computeDesc.id = nextName("vm");
computeDesc.regionId = this.datacenterId;
computeDesc.documentSelfLink = computeDesc.id;
computeDesc.supportedChildren = new ArrayList<>();
computeDesc.instanceAdapterReference = UriUtils.buildUri(this.host, VSphereUriPaths.INSTANCE_SERVICE);
computeDesc.authCredentialsLink = this.auth.documentSelfLink;
computeDesc.name = computeDesc.id;
computeDesc.dataStoreId = this.dataStoreId;
computeDesc.cpuCount = 2;
// 1G
computeDesc.totalMemoryBytes = 1024 * 1024 * 1024;
computeDesc.dataStoreId = dataStoreId;
if (this.endpoint != null) {
computeDesc.endpointLink = this.endpoint.documentSelfLink;
computeDesc.endpointLinks = new HashSet<>(1);
computeDesc.endpointLinks.add(this.endpoint.documentSelfLink);
}
return TestUtils.doPost(this.host, computeDesc, ComputeDescription.class, UriUtils.buildUri(this.host, ComputeDescriptionService.FACTORY_LINK));
}
Aggregations