use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VSphereVirtualMachineEnumerationHelper method handleVMChanges.
public static void handleVMChanges(VSphereIncrementalEnumerationService service, List<ObjectUpdate> resourcesUpdates, EnumerationProgress enumerationProgress, EnumerationClient client) {
List<VmOverlay> vmOverlays = new ArrayList<>();
for (ObjectUpdate objectUpdate : resourcesUpdates) {
if (VimUtils.isVirtualMachine(objectUpdate.getObj())) {
VmOverlay vm = new VmOverlay(objectUpdate);
if (vm.getInstanceUuid() != null || !objectUpdate.getKind().equals(ObjectUpdateKind.ENTER)) {
vmOverlays.add(vm);
}
}
}
for (VmOverlay vmOverlay : vmOverlays) {
if (ObjectUpdateKind.ENTER == vmOverlay.getObjectUpdateKind()) {
createNewVm(service, enumerationProgress, vmOverlay);
} else {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
QueryTask task = queryForVm(enumerationProgress, request.resourceLink(), null, vmOverlay.getId());
VsphereEnumerationHelper.withTaskResults(service, task, result -> {
if (!result.documentLinks.isEmpty()) {
ComputeState oldDocument = VsphereEnumerationHelper.convertOnlyResultToDocument(result, ComputeState.class);
if (ObjectUpdateKind.MODIFY == vmOverlay.getObjectUpdateKind()) {
updateVm(service, oldDocument, enumerationProgress, vmOverlay, false);
} else {
deleteVM(enumerationProgress, vmOverlay, service, oldDocument);
}
} else {
enumerationProgress.getVmTracker().arrive();
}
});
}
}
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VSphereVirtualMachineEnumerationHelper method processFoundVm.
static void processFoundVm(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, VmOverlay vm) {
long latestAcceptableModification = System.currentTimeMillis() - VM_FERMENTATION_PERIOD_MILLIS;
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
QueryTask task = queryForVm(enumerationProgress, request.resourceLink(), vm.getInstanceUuid(), vm.getId());
VsphereEnumerationHelper.withTaskResults(service, task, result -> {
if (result.documentLinks.isEmpty()) {
if (vm.getLastReconfigureMillis() < latestAcceptableModification) {
// If vm is not settled down don't create a new resource
createNewVm(service, enumerationProgress, vm);
} else {
enumerationProgress.getVmTracker().arrive();
}
} else {
// always update state of a vm even if modified recently
ComputeState oldDocument = VsphereEnumerationHelper.convertOnlyResultToDocument(result, ComputeState.class);
updateVm(service, oldDocument, enumerationProgress, vm, true);
}
});
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VsphereComputeResourceEnumerationHelper method handleComputeResourceChanges.
public static void handleComputeResourceChanges(VSphereIncrementalEnumerationService service, List<ComputeResourceOverlay> computeResourceOverlays, EnumerationProgress ctx, EnumerationClient client) {
ctx.expectComputeResourceCount(computeResourceOverlays.size());
// process compute resource changes
for (ComputeResourceOverlay cluster : computeResourceOverlays) {
try {
service.logInfo("Handling compute resource change %s", Utils.toJson(cluster));
// TODO If a host is part of cluster then the host needs to be populated with cluster link.
if (ObjectUpdateKind.ENTER == cluster.getObjectUpdateKind()) {
// create a cluster object only for DRS enabled clusters
if (cluster.isDrsEnabled()) {
service.logInfo("Creating new cluster for %s", Utils.toJson(cluster));
createNewComputeResource(service, ctx, cluster, client);
}
} else {
// If an existing compute resource is modified or removed.
ComputeEnumerateResourceRequest request = ctx.getRequest();
QueryTask task = queryForCluster(ctx, request.resourceLink(), cluster.getId().getValue());
withTaskResults(service, task, result -> {
service.logInfo("Queried for existing clusters for %s", Utils.toJson(cluster));
try {
if (!result.documentLinks.isEmpty()) {
ComputeState oldDocument = convertOnlyResultToDocument(result, ComputeState.class);
// check if the compute resource is modified.
if (ObjectUpdateKind.MODIFY.equals(cluster.getObjectUpdateKind())) {
service.logInfo("Updating existing cluster for %s", Utils.toJson(cluster));
updateCluster(service, oldDocument, ctx, cluster, client, false);
} else {
// Compute resource has been removed. remove the compute resource from photon model here
// Delete only compute state document as compute description can be shared among compute resources.
service.logInfo("Deleting existing cluster for %s", Utils.toJson(cluster));
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), oldDocument.documentSelfLink)).setCompletion((o, e) -> {
trackComputeResource(ctx, cluster).handle(o, e);
}).sendWith(service);
}
} else {
ctx.getComputeResourceTracker().track();
}
} catch (Exception ex) {
service.logSevere("Error occurred while processing update of compute resource!", ex);
ctx.getComputeResourceTracker().track(cluster.getId(), ResourceTracker.ERROR);
}
});
}
} catch (Exception e) {
service.logSevere("Error occurred while processing update of compute resource!", e);
ctx.getComputeResourceTracker().track(cluster.getId(), ResourceTracker.ERROR);
}
}
// checkpoint compute resource
try {
ctx.getComputeResourceTracker().await();
} catch (InterruptedException e) {
service.logSevere("Interrupted during incremental enumeration for networks!", e);
}
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VSphereHostSystemEnumerationHelper method processFoundHostSystem.
/**
* Process all the host system retrieved from the endpoint.
*/
public static void processFoundHostSystem(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, HostSystemOverlay hs, EnumerationClient client) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
QueryTask task = queryForHostSystem(enumerationProgress, request.resourceLink(), hs.getId().getValue());
withTaskResults(service, task, result -> {
try {
if (result.documentLinks.isEmpty()) {
createNewHostSystem(service, enumerationProgress, hs, client);
} else {
ComputeState oldDocument = convertOnlyResultToDocument(result, ComputeState.class);
updateHostSystem(service, oldDocument, enumerationProgress, hs, true, client);
}
} catch (Exception e) {
service.logSevere("Error occurred while processing host system!", e);
enumerationProgress.getHostSystemTracker().track();
}
});
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VsphereDatastoreEnumerationHelper method createNewStorageDescription.
private static void createNewStorageDescription(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, DatastoreOverlay ds) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
String regionId = enumerationProgress.getRegionId();
StorageDescription desc = makeStorageFromResults(request, ds, regionId, enumerationProgress);
desc.tenantLinks = enumerationProgress.getTenantLinks();
service.logFine(() -> String.format("Found new Datastore %s", ds.getName()));
VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
VsphereEnumerationHelper.populateTags(service, enumerationProgress, ds, desc);
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), StorageDescriptionService.FACTORY_LINK)).setBody(desc).setCompletion((o, e) -> {
trackDatastore(enumerationProgress, ds).handle(o, e);
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ResourceGroupService.FACTORY_LINK)).setBody(makeStorageGroup(ds, enumerationProgress)).sendWith(service);
updateStorageStats(service, ds, o.getBody(ServiceDocument.class).documentSelfLink);
}).sendWith(service);
});
}
Aggregations