use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AzureCostStatsService method setCustomProperty.
private void setCustomProperty(Context context, String key, String value, Stages next) {
context.computeHostDesc.customProperties.put(key, value);
ComputeState accountState = new ComputeState();
accountState.customProperties = new HashMap<>();
accountState.customProperties.put(key, value);
sendRequest(Operation.createPatch(UriUtils.extendUri(getInventoryServiceUri(), context.computeHostDesc.documentSelfLink)).setBody(accountState).setCompletion((operation, exception) -> {
if (exception != null) {
handleError(context, null, exception, false);
return;
}
context.stage = next;
handleRequest(context);
}));
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AzureEndpointAdapterService method checkIfAccountExistsAndGetExistingDocuments.
private void checkIfAccountExistsAndGetExistingDocuments(EndpointConfigRequest req, Operation op) {
String accountId = req.endpointProperties.get(USER_LINK_KEY);
if (accountId != null && !accountId.isEmpty() && req.tenantLinks != null && !req.tenantLinks.isEmpty()) {
QueryTask queryTask = QueryUtils.createAccountQuery(accountId, PhotonModelConstants.EndpointType.azure.name(), req.tenantLinks);
queryTask.tenantLinks = req.tenantLinks;
QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((qrt, e) -> {
if (e != null) {
logSevere(() -> String.format("Failure retrieving query results for azure compute host corresponding to" + "the account ID: %s", e.toString()));
op.fail(e);
return;
}
if (qrt.results.documentCount > 0) {
req.accountAlreadyExists = true;
Object state = qrt.results.documents.values().iterator().next();
ComputeState computeHost = Utils.fromJson(state, ComputeState.class);
req.existingComputeState = computeHost;
getComputeDescription(req, computeHost.descriptionLink, op);
} else {
req.accountAlreadyExists = false;
op.setBody(req);
op.complete();
return;
}
});
} else {
req.accountAlreadyExists = false;
op.setBody(req);
op.complete();
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class TestVSphereProvisionFromImageLink method provisionVMAndGetState.
private ComputeState provisionVMAndGetState() throws Throwable {
if (isMock()) {
return null;
}
// Create a resource pool where the VM will be housed
this.resourcePool = createResourcePool();
this.auth = createAuth();
this.computeHostDescription = createComputeDescription();
this.computeHost = createComputeHost(this.computeHostDescription);
EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
enumerateComputes(this.computeHost, this.endpoint);
doRefresh();
snapshotFactoryState("images", ImageService.class);
String imageLink = findImage();
ComputeDescription desc = createVmDescription();
ComputeState vm = createVmState(desc, imageLink);
// kick off a provision task to do the actual VM creation
ProvisionComputeTaskState outTask = createProvisionTask(vm);
awaitTaskEnd(outTask);
return getComputeState(vm);
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class TestVSphereProvisionFromImageLink method deployFromLibrary.
@Test
public void deployFromLibrary() throws Throwable {
ComputeState vm = null;
try {
vm = provisionVMAndGetState();
if (vm == null) {
return;
}
snapshotFactoryState("ready", ComputeService.class);
snapshotFactoryState("ready", DiskService.class);
} finally {
if (vm != null) {
deleteVmAndWait(vm);
}
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class TestVSphereProvisionFromImageLink method createVmState.
private ComputeState createVmState(ComputeDescription vmDescription, String imageLink) throws Throwable {
ComputeState computeState = new ComputeState();
computeState.id = vmDescription.name;
computeState.documentSelfLink = computeState.id;
computeState.descriptionLink = vmDescription.documentSelfLink;
computeState.resourcePoolLink = this.resourcePool.documentSelfLink;
computeState.adapterManagementReference = getAdapterManagementReference();
computeState.name = vmDescription.name;
computeState.powerState = PowerState.ON;
computeState.parentLink = this.computeHost.documentSelfLink;
if (this.endpoint != null) {
computeState.endpointLink = this.endpoint.documentSelfLink;
computeState.endpointLinks = new HashSet<>(1);
computeState.endpointLinks.add(this.endpoint.documentSelfLink);
}
computeState.networkInterfaceLinks = new ArrayList<>(1);
computeState.diskLinks = new ArrayList<>(1);
DiskState bootDisk = createBootDisk(imageLink);
computeState.diskLinks.add(bootDisk.documentSelfLink);
CustomProperties.of(computeState).put(ComputeProperties.RESOURCE_GROUP_NAME, this.vcFolder).put(ComputeProperties.PLACEMENT_LINK, selectPlacement());
ComputeState returnState = TestUtils.doPost(this.host, computeState, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
return returnState;
}
Aggregations