use of com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException 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.adapters.vsphere.vapi.RpcException in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService method processAllLibraries.
private void processAllLibraries(Set<String> oldImages, String endpointLink, String taskLink, LibraryClient libraryClient, List<String> tenantLinks) throws IOException, RpcException {
Phaser phaser = new Phaser(1);
for (String libId : libraryClient.listLibs()) {
ObjectNode libModel = libraryClient.loadLib(libId);
for (String itemId : libraryClient.listItemsInLib(libId)) {
ObjectNode itemModel = libraryClient.loadItem(itemId);
String type = VapiClient.getString(itemModel, "type", VapiClient.K_OPTIONAL);
if (!"ovf".equals(type)) {
// only ovfs can be deployed
continue;
}
ImageState state = makeImageFromItem(libModel, itemModel);
state.documentSelfLink = buildStableImageLink(endpointLink, state.id);
state.endpointLink = endpointLink;
state.tenantLinks = tenantLinks;
state.regionId = "";
oldImages.remove(state.documentSelfLink);
phaser.register();
Operation.createPost(PhotonModelUriUtils.createInventoryUri(getHost(), ImageService.FACTORY_LINK)).setBody(state).setCompletion((o, e) -> phaser.arrive()).sendWith(this);
}
}
phaser.arriveAndAwaitAdvance();
}
use of com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException in project photon-model by vmware.
the class VSphereIncrementalEnumerationService method refreshResourcesOnce.
/**
* This method executes in a thread managed by {@link VSphereIOThreadPoolAllocator}
*/
private void refreshResourcesOnce(Set<String> resourceLinks, ComputeEnumerateResourceRequest request, Connection connection, ComputeService.ComputeStateWithDescription parent, TaskManager mgr) {
VapiConnection vapiConnection = VapiConnection.createFromVimConnection(connection);
try {
vapiConnection.login();
} catch (IOException | RpcException e) {
logWarning(() -> String.format("Cannot login into vAPI endpoint: %s", Utils.toString(e)));
mgr.patchTaskToFailure(e);
return;
}
DatacenterLister lister = new DatacenterLister(connection);
try {
// Get instanceUuid of the vCenter
AboutInfo vCenter = this.connection.getServiceContent().getAbout();
for (Element element : lister.listAllDatacenters()) {
ManagedObjectReference datacenter = element.object;
log(Level.INFO, "Processing datacenter %s (%s)", element.path, VimUtils.convertMoRefToString(element.object));
EnumerationClient client = new EnumerationClient(connection, parent, datacenter);
EnumerationProgress enumerationProgress = new EnumerationProgress(resourceLinks, request, parent, vapiConnection, VimUtils.convertMoRefToString(datacenter), vCenter.getInstanceUuid());
// since we are processing DC sequentially one at a time
enumerationProgress.expectDatacenterCount(1);
VsphereDatacenterEnumerationHelper.processDatacenterInfo(this, element, enumerationProgress);
enumerationProgress.getDcTracker().await();
logInfo("Proceeding to refresh resources on datacenter: %s", enumerationProgress.getDcLink());
refreshResourcesOnDatacenter(client, enumerationProgress, mgr);
}
} catch (Exception e) {
logWarning(String.format("Error during enumeration: %s", Utils.toString(e)));
mgr.patchTaskToFailure(e);
}
try {
vapiConnection.close();
} catch (Exception e) {
logWarning(() -> String.format("Error occurred when closing vAPI connection: %s", Utils.toString(e)));
}
// after all dc's are enumerated untouched resource links are the only ones left
// in resourceLinks
garbageCollectUntouchedComputeResources(request, resourceLinks, mgr);
// cleanup the connection if the enumeration action is REFRESH.
if (EnumerationAction.REFRESH.equals(request.enumerationAction)) {
cleanupConnection();
}
}
use of com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException in project photon-model by vmware.
the class VsphereEnumerationHelper method updateLocalTags.
static void updateLocalTags(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, AbstractOverlay obj, ResourceState patchResponse) {
List<TagState> tags;
try {
tags = retrieveAttachedTags(service, enumerationProgress.getEndpoint(), obj.getId(), enumerationProgress.getTenantLinks());
} catch (IOException | RpcException e) {
service.logWarning("Error updating local tags for %s", patchResponse.documentSelfLink);
return;
}
Map<String, String> remoteTagMap = new HashMap<>();
for (TagState ts : tags) {
remoteTagMap.put(ts.key, ts.value);
}
TagsUtil.updateLocalTagStates(service, patchResponse, remoteTagMap, null);
}
Aggregations