use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VSphereIncrementalEnumerationService method handlePatch.
@Override
public void handlePatch(Operation patch) {
// complete the patch immediately.
patch.complete();
logInfo("Received PATCH for incremental enumeration!");
VSphereIncrementalEnumerationRequest enumerationRequest = patch.getBody(VSphereIncrementalEnumerationRequest.class);
ComputeEnumerateResourceRequest request = enumerationRequest.request;
URI parentUri = ComputeService.ComputeStateWithDescription.buildUri(PhotonModelUriUtils.createInventoryUri(getHost(), request.resourceReference));
logInfo("Creating task manager!");
TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());
logInfo(" Requesting GET on compute state with description!.");
Operation.createGet(parentUri).setCompletion(o -> {
logInfo("Submitting job to threadpool!");
VsphereEnumerationHelper.submitWorkToVSpherePool(this, () -> {
logInfo("Incremental enumeration job started for endpoint %s", enumerationRequest.request.endpointLink);
ComputeStateWithDescription computeStateWithDesc = o.getBody(ComputeStateWithDescription.class);
VapiConnection vapiConnection = VapiConnection.createFromVimConnection(this.connection);
logInfo("Establishing VAPI connection for endpoint %s", enumerationRequest.request.endpointLink);
try {
vapiConnection.login();
} catch (IOException | RpcException rpce) {
logWarning(() -> String.format("Cannot login into vAPI endpoint: %s", Utils.toString(rpce)));
mgr.patchTaskToFailure(rpce);
// self delete service so that full enumeration kicks in next invocation.
selfDeleteService();
return;
}
try {
// Get instanceUuid of the vCenter
AboutInfo vCenter = this.connection.getServiceContent().getAbout();
for (CollectorDetails collectorDetails : this.collectors) {
logInfo("Retrieving resources incremental data for data center: %s", collectorDetails.datacenter);
EnumerationProgress enumerationProgress = new EnumerationProgress(new HashSet<>(), request, computeStateWithDesc, vapiConnection, collectorDetails.datacenter, vCenter.getInstanceUuid());
EnumerationClient client = new EnumerationClient(this.connection, computeStateWithDesc, VimUtils.convertStringToMoRef(collectorDetails.datacenter));
List<ObjectUpdate> resourcesUpdates = collectResourcesData(collectorDetails);
List<ObjectUpdate> vmUpdates = collectVMData(collectorDetails);
logInfo("Received resources updates for datacenter: %s : %s", collectorDetails.datacenter, resourcesUpdates.size());
logInfo("Received vm updates for datacenter: %s : %s", collectorDetails.datacenter, vmUpdates.size());
logInfo("Resources Updates: %s", Utils.toJson(resourcesUpdates));
logInfo("VM Updates: %s", Utils.toJson(vmUpdates));
if (!resourcesUpdates.isEmpty()) {
SegregatedOverlays segregatedOverlays = segregateObjectUpdates(enumerationProgress, resourcesUpdates);
this.logInfo("Processing incremental changes for folders for datacenter [%s]!", collectorDetails.datacenter);
VsphereFolderEnumerationHelper.handleFolderChanges(this, segregatedOverlays.folders, enumerationProgress, client);
logInfo("Processing incremental changes for networks for datacenter [%s]!", collectorDetails.datacenter);
VSphereNetworkEnumerationHelper.handleNetworkChanges(this, segregatedOverlays.networks, enumerationProgress, client);
logInfo("Processing incremental changes for Datastores for datacenter [%s]!", collectorDetails.datacenter);
VsphereDatastoreEnumerationHelper.handleDatastoreChanges(this, segregatedOverlays.datastores, enumerationProgress);
logInfo("Processing incremental changes for compute resource for datacenter [%s]!", collectorDetails.datacenter);
VsphereComputeResourceEnumerationHelper.handleComputeResourceChanges(this, segregatedOverlays.clusters, enumerationProgress, client);
logInfo("Processing incremental changes for host system for datacenter [%s]!", collectorDetails.datacenter);
VSphereHostSystemEnumerationHelper.handleHostSystemChanges(this, segregatedOverlays.hosts, enumerationProgress, client);
logInfo("Processing incremental changes for resource pool for datacenter [%s]!", collectorDetails.datacenter);
VSphereResourcePoolEnumerationHelper.handleResourcePoolChanges(this, segregatedOverlays.resourcePools, enumerationProgress, client);
}
if (!vmUpdates.isEmpty()) {
logInfo("Processing incremental changes for virtual machines for datacenter [%s]!", collectorDetails.datacenter);
VSphereVirtualMachineEnumerationHelper.handleVMChanges(this, vmUpdates, enumerationProgress, client);
}
// sync storage profiles
logInfo("Syncing storage profiles for datacenter [%s]!", collectorDetails.datacenter);
VsphereStoragePolicyEnumerationHelper.syncStorageProfiles(this, client, enumerationProgress);
}
mgr.patchTask(TaskStage.FINISHED);
} catch (Exception exception) {
String msg = "Error processing PropertyCollector results during incremental retrieval";
logWarning(() -> msg + ": " + exception.toString());
mgr.patchTaskToFailure(exception);
// self delete service so that full enumeration kicks in next invocation.
// TODO: This is not complete. We need to enable owner selection on this service.
selfDeleteService();
return;
} finally {
vapiConnection.close();
}
});
}, mgr).sendWith(this);
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VSphereNetworkEnumerationHelper method makeSubnetStateFromResults.
private static SubnetState makeSubnetStateFromResults(EnumerationProgress enumerationProgress, NetworkOverlay net) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
SubnetState state = new SubnetState();
state.id = state.name = net.getName();
state.endpointLink = enumerationProgress.getRequest().endpointLink;
AdapterUtils.addToEndpointLinks(state, enumerationProgress.getRequest().endpointLink);
ManagedObjectReference parentSwitch = net.getParentSwitch();
state.networkLink = buildStableDvsLink(parentSwitch, request.endpointLink);
state.regionId = enumerationProgress.getRegionId();
CustomProperties customProperties = CustomProperties.of(state).put(CustomProperties.MOREF, net.getId()).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink()).put(CustomProperties.TYPE, net.getId().getType());
customProperties.put(DvsProperties.PORT_GROUP_KEY, net.getPortgroupKey());
return state;
}
use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest 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.adapterapi.ComputeEnumerateResourceRequest 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.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.
the class VSphereVMSnapshotEnumerationHelper method enumerateSnapshots.
static void enumerateSnapshots(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, List<VmOverlay> vms) {
if (CollectionUtils.isEmpty(vms)) {
return;
}
vms.forEach(vm -> {
// process only those VMs that have snapshots attached.
if (vm.getRootSnapshotList() != null) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
QueryTask task = VSphereVirtualMachineEnumerationHelper.queryForVm(enumerationProgress, request.resourceLink(), vm.getInstanceUuid(), null);
VsphereEnumerationHelper.withTaskResults(service, task, result -> {
ComputeState computeState = VsphereEnumerationHelper.convertOnlyResultToDocument(result, ComputeState.class);
processSnapshots(service, enumerationProgress, vm, computeState.documentSelfLink);
});
}
});
enumerationProgress.getSnapshotTracker().arriveAndDeregister();
}
Aggregations