Search in sources :

Example 26 with ResourceGroupState

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);
        }
    }
}
Also used : AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) Operation(com.vmware.xenon.common.Operation) QueryTask(com.vmware.xenon.services.common.QueryTask) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VsphereEnumerationHelper.getSelfLinkFromOperation(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.getSelfLinkFromOperation) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)

Example 27 with ResourceGroupState

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);
        }
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 28 with ResourceGroupState

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;
}
Also used : ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 29 with ResourceGroupState

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);
        }
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)

Example 30 with ResourceGroupState

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);
}
Also used : ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) MatchType(com.vmware.xenon.services.common.QueryTask.QueryTerm.MatchType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Utils(com.vmware.xenon.common.Utils) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) PbmProfile(com.vmware.pbm.PbmProfile) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) Stream(java.util.stream.Stream) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)

Aggregations

ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)31 Operation (com.vmware.xenon.common.Operation)10 QueryTask (com.vmware.xenon.services.common.QueryTask)10 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)9 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)9 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)9 List (java.util.List)9 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)8 ResourceGroupService (com.vmware.photon.controller.model.resources.ResourceGroupService)8 StorageDescription (com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)8 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)8 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)8 Collections (java.util.Collections)8 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)7 Utils (com.vmware.xenon.common.Utils)7 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Builder (com.vmware.xenon.services.common.QueryTask.Query.Builder)6 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)5