use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class VSphereResourcePoolEnumerationHelper method makeResourcePoolFromResults.
private static ComputeState makeResourcePoolFromResults(EnumerationProgress enumerationProgress, ResourcePoolOverlay rp, String selfLink, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
ComputeState state = new ComputeState();
state.documentSelfLink = selfLink;
state.name = rp.getName();
state.id = rp.getId().getValue();
state.type = ComputeType.VM_HOST;
state.powerState = PowerState.ON;
state.endpointLink = request.endpointLink;
AdapterUtils.addToEndpointLinks(state, request.endpointLink);
state.regionId = enumerationProgress.getRegionId();
state.parentLink = enumerationProgress.getRequest().resourceLink();
state.resourcePoolLink = request.resourcePoolLink;
state.adapterManagementReference = request.adapterManagementReference;
ManagedObjectReference owner = rp.getOwner();
AbstractOverlay ov = enumerationProgress.getOverlay(owner);
if (ov instanceof ComputeResourceOverlay) {
ComputeResourceOverlay cr = (ComputeResourceOverlay) ov;
state.groupLinks = VsphereEnumerationHelper.getConnectedDatastoresAndNetworks(enumerationProgress, cr.getDatastore(), cr.getNetwork(), client);
} else if (ov instanceof HostSystemOverlay) {
HostSystemOverlay cr = (HostSystemOverlay) ov;
state.groupLinks = VsphereEnumerationHelper.getConnectedDatastoresAndNetworks(enumerationProgress, cr.getDatastore(), cr.getNetwork(), client);
}
CustomProperties.of(state).put(CustomProperties.MOREF, rp.getId()).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink()).put(CustomProperties.TYPE, VimNames.TYPE_RESOURCE_POOL);
VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(state, enumerationProgress.getVcUuid());
return state;
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class VSphereResourcePoolEnumerationHelper method updateResourcePool.
private static void updateResourcePool(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, String ownerName, String selfLink, ResourcePoolOverlay rp, boolean fullUpdate, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ComputeState state;
ComputeDescription desc;
if (fullUpdate) {
state = makeResourcePoolFromResults(enumerationProgress, rp, selfLink, client);
state.name = rp.makeUserFriendlyName(ownerName);
state.tenantLinks = enumerationProgress.getTenantLinks();
state.resourcePoolLink = null;
desc = makeDescriptionForResourcePool(enumerationProgress, rp, selfLink);
} else {
state = makeResourcePoolFromChanges(rp, selfLink, ownerName);
desc = makeDescriptionFromChanges(rp, selfLink, ownerName);
}
state.descriptionLink = desc.documentSelfLink;
service.logFine(() -> String.format("Refreshed ResourcePool %s", state.name));
Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), selfLink)).setBody(state).setCompletion(trackResourcePool(enumerationProgress, rp)).sendWith(service);
Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), desc.documentSelfLink)).setBody(desc).sendWith(service);
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class VSphereResourcePoolEnumerationHelper method handleResourcePoolChanges.
public static void handleResourcePoolChanges(VSphereIncrementalEnumerationService service, List<ResourcePoolOverlay> resourcePools, EnumerationProgress enumerationProgress, EnumerationClient client) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
enumerationProgress.expectResourcePoolCount(resourcePools.size());
for (ResourcePoolOverlay resourcePool : resourcePools) {
// no need to collect the root resource pool
if (ObjectUpdateKind.ENTER.equals(resourcePool.getObjectUpdateKind()) && VimNames.TYPE_RESOURCE_POOL.equals(resourcePool.getParent().getType())) {
String ownerMoRefId = resourcePool.getOwner().getValue();
QueryTask task = queryForRPOwner(ownerMoRefId, enumerationProgress);
String selfLink = buildStableResourcePoolLink(resourcePool.getId(), request.endpointLink);
withTaskResults(service, task, result -> {
try {
if (!result.documentLinks.isEmpty()) {
ComputeState ownerDocument = convertOnlyResultToDocument(result, ComputeState.class);
createNewResourcePool(service, enumerationProgress, ownerDocument.name, selfLink, resourcePool, client);
} else {
// This happens for the resource pools within Host. The owner is a ComputeResource and
// is not currently enumerated in photon
createNewResourcePool(service, enumerationProgress, null, selfLink, resourcePool, client);
}
} catch (Exception e) {
enumerationProgress.getResourcePoolTracker().track();
}
});
} else {
String rpSelfLink = buildStableResourcePoolLink(resourcePool.getId(), request.endpointLink);
Operation.createGet(PhotonModelUriUtils.createInventoryUri(service.getHost(), rpSelfLink)).setCompletion((o, e) -> {
try {
if (e == null) {
ComputeState oldState = o.getBody(ComputeState.class);
String existingOwnerName = getOwnerNameFromResourcePoolName(oldState.name);
if (ObjectUpdateKind.MODIFY.equals(resourcePool.getObjectUpdateKind())) {
updateResourcePool(service, enumerationProgress, existingOwnerName, oldState.documentSelfLink, resourcePool, false, client);
} else {
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), rpSelfLink)).setCompletion(trackResourcePool(enumerationProgress, resourcePool)).sendWith(service);
}
} else {
enumerationProgress.getResourcePoolTracker().track();
}
} catch (Exception ex) {
enumerationProgress.getResourcePoolTracker().track();
}
}).sendWith(service);
}
}
try {
enumerationProgress.getResourcePoolTracker().await();
} catch (InterruptedException e) {
service.logSevere("Interrupted during incremental enumeration for resource pools!", e);
}
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class BasePowerContext method updateComputeState.
/**
* Updates the compute state with the new power state
*/
private DeferredResult<CONTEXT> updateComputeState(CONTEXT context) {
ComputeState state = new ComputeState();
state.powerState = context.request.powerState;
Operation op = Operation.createPatch(context.request.resourceReference).setBody(state);
return this.service.sendWithDeferredResult(op).thenApply(ignore -> context);
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class InstanceClient method createInstanceFromTemplate.
public ComputeState createInstanceFromTemplate(ManagedObjectReference template) throws Exception {
ManagedObjectReference vm = cloneVm(template);
if (vm == null) {
// vm was created by someone else
return null;
}
// store reference to created vm for further processing
this.vm = vm;
customizeAfterClone();
ComputeState state = new ComputeState();
state.resourcePoolLink = VimUtils.firstNonNull(this.ctx.child.resourcePoolLink, this.ctx.parent.resourcePoolLink);
return state;
}
Aggregations