use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.
the class VsphereFolderEnumerationHelper method handleFolderChanges.
public static void handleFolderChanges(VSphereIncrementalEnumerationService service, List<FolderOverlay> folderOverlays, EnumerationProgress enumerationProgress, EnumerationClient client) {
enumerationProgress.expectFolderCount(folderOverlays.size());
for (FolderOverlay folderOverlay : folderOverlays) {
try {
if (ObjectUpdateKind.ENTER == folderOverlay.getObjectUpdateKind()) {
createFolder(service, enumerationProgress, folderOverlay, Collections.emptyList(), client);
} else {
QueryTask task = queryForFolder(enumerationProgress, folderOverlay);
withTaskResults(service, task, result -> {
if (!result.documentLinks.isEmpty()) {
ResourceGroupState oldDocument = convertOnlyResultToDocument(result, ResourceGroupState.class);
if (ObjectUpdateKind.MODIFY.equals(folderOverlay.getObjectUpdateKind())) {
try {
updateFolder(service, enumerationProgress, folderOverlay, oldDocument, Collections.emptyList(), client, false);
} catch (Exception e) {
service.logSevere("Error occurred while processing folder!", e);
enumerationProgress.getFolderTracker().track(folderOverlay.getId(), ResourceTracker.ERROR);
}
} else {
Operation.createDelete(PhotonModelUriUtils.createInventoryUri(service.getHost(), oldDocument.documentSelfLink)).setCompletion((o, e) -> {
enumerationProgress.getFolderTracker().track();
}).sendWith(service);
}
} else {
enumerationProgress.getFolderTracker().track();
}
});
}
} catch (Exception e) {
service.logSevere("Error occurred while processing folder!", e);
enumerationProgress.getFolderTracker().track(folderOverlay.getId(), ResourceTracker.ERROR);
}
}
}
use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.
the class VsphereFolderEnumerationHelper method processFoundFolder.
static void processFoundFolder(VSphereIncrementalEnumerationService service, EnumerationProgress ctx, FolderOverlay folder, List<FolderOverlay> rootFolders, EnumerationClient client) {
QueryTask task = queryForFolder(ctx, folder);
withTaskResults(service, task, (ServiceDocumentQueryResult result) -> {
try {
if (result.documentLinks.isEmpty()) {
createFolder(service, ctx, folder, rootFolders, client);
} else {
ResourceGroupState oldDocument = convertOnlyResultToDocument(result, ResourceGroupState.class);
updateFolder(service, ctx, folder, oldDocument, rootFolders, client, true);
}
} catch (Exception e) {
service.logSevere("Error occurred while processing folder!", e);
ctx.getFolderTracker().track(folder.getId(), ResourceTracker.ERROR);
}
});
}
use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.
the class VsphereFolderEnumerationHelper method makeFolderFromResults.
private static ResourceGroupState makeFolderFromResults(EnumerationProgress ctx, FolderOverlay folder, List<FolderOverlay> rootFolders, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
ResourceGroupState state = new ResourceGroupState();
state.name = state.id = folder.getName();
state.endpointLink = ctx.getRequest().endpointLink;
AdapterUtils.addToEndpointLinks(state, ctx.getRequest().endpointLink);
state.tenantLinks = ctx.getTenantLinks();
// Get the parent of the folder.
// If the parent is one of the root folder, set the parent as root folders parent
String parent = null;
if (!rootFolders.isEmpty()) {
for (FolderOverlay rootFolderOverlay : rootFolders) {
if (rootFolderOverlay.getMoRefValue().equals(folder.getParent().getValue())) {
parent = VimUtils.convertMoRefToString(rootFolderOverlay.getParent());
break;
}
}
} else {
// retrieve parent folder Moref
ManagedObjectReference parentFolder = folder.getParent();
// retrieve parent of parent folder
ManagedObjectReference parentOfParentFolder = client.getParentOfFolder(parentFolder);
if (parentOfParentFolder.getType().equals(VimNames.TYPE_DATACENTER)) {
parent = VimUtils.convertMoRefToString(parentOfParentFolder);
} else {
parent = VimUtils.convertMoRefToString(parentFolder);
}
}
CustomProperties.of(state).put(CustomProperties.MOREF, folder.getId()).put(CustomProperties.TYPE, folder.getId().getType()).put(CustomProperties.DATACENTER_SELF_LINK, ctx.getDcLink()).put(ComputeProperties.ENDPOINT_LINK_PROP_NAME, ctx.getRequest().endpointLink).put(CustomProperties.DATACENTER, ctx.getRegionId()).put(CustomProperties.PARENT_ID, parent).put(CustomProperties.VC_VIEW, folder.getView()).put(CustomProperties.FOLDER_TYPE, folder.getFolderType());
VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(state, ctx.getVcUuid());
return state;
}
use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.
the class VsphereStoragePolicyEnumerationHelper method processFoundStoragePolicy.
/**
* Process the found storage policy by creating a new resource group if not found already. If
* it already present, then update its properties. Process the updates on its compatible
* datastores.
*/
static void processFoundStoragePolicy(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, StoragePolicyOverlay sp) {
QueryTask task = queryForStoragePolicy(enumerationProgress, sp.getProfileId(), sp.getName());
VsphereEnumerationHelper.withTaskResults(service, task, result -> {
if (result.documentLinks.isEmpty()) {
createNewStoragePolicy(service, enumerationProgress, sp);
} else {
ResourceGroupState oldDocument = VsphereEnumerationHelper.convertOnlyResultToDocument(result, ResourceGroupState.class);
updateStoragePolicy(service, oldDocument, enumerationProgress, sp);
}
});
}
use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.
the class VsphereStoragePolicyEnumerationHelper method createNewStoragePolicy.
static void createNewStoragePolicy(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, StoragePolicyOverlay sp) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
ResourceGroupState rgState = makeStoragePolicyFromResults(request, sp, enumerationProgress.getDcLink());
rgState.tenantLinks = enumerationProgress.getTenantLinks();
service.logFine(() -> String.format("Found new Storage Policy %s", sp.getName()));
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ResourceGroupService.FACTORY_LINK)).setBody(rgState).setCompletion((o, e) -> {
trackStoragePolicy(service, enumerationProgress, sp).handle(o, e);
// Update all compatible datastores group link with the self link of this
// storage policy
updateDataStoreWithStoragePolicyGroup(service, enumerationProgress, sp, o.getBody(ResourceGroupState.class).documentSelfLink);
}).sendWith(service);
}
Aggregations