Search in sources :

Example 16 with ResourceGroupState

use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.

the class VsphereFolderEnumerationHelper method makeFolderFromChanges.

private static ResourceGroupState makeFolderFromChanges(FolderOverlay folder, EnumerationClient client) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ResourceGroupState state = new ResourceGroupState();
    // Folder name change
    state.name = folder.getNameOrNull();
    // Folder parent change
    if (null != folder.getParentOrNull()) {
        // retrieve parent folder Moref
        ManagedObjectReference parent = folder.getParentOrNull();
        // retrieve parent of parent folder
        ManagedObjectReference parentOfParentFolder = client.getParentOfFolder(parent);
        // if the parent of parent folder is DC, then the parent is root folder. Add parent of parent during this scenario.
        if (parentOfParentFolder.getType().equals(VimNames.TYPE_DATACENTER)) {
            CustomProperties.of(state).put(CustomProperties.PARENT_ID, VimUtils.convertMoRefToString(parentOfParentFolder));
        } else {
            CustomProperties.of(state).put(CustomProperties.PARENT_ID, VimUtils.convertMoRefToString(parent));
        }
    }
    return state;
}
Also used : ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 17 with ResourceGroupState

use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.

the class VsphereFolderEnumerationHelper method updateFolder.

private static void updateFolder(VSphereIncrementalEnumerationService service, EnumerationProgress ctx, FolderOverlay folder, ResourceGroupState oldDocument, List<FolderOverlay> rootFolders, EnumerationClient client, boolean fullUpdate) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg {
    ResourceGroupState state;
    if (fullUpdate) {
        state = makeFolderFromResults(ctx, folder, rootFolders, client);
    } else {
        state = makeFolderFromChanges(folder, client);
    }
    state.documentSelfLink = oldDocument.documentSelfLink;
    Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), state.documentSelfLink)).setBody(state).setCompletion((o, e) -> {
        trackFolder(ctx, folder).handle(o, e);
        service.logInfo("updating document for folder: %s  ", folder.getName());
    }).sendWith(service);
}
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) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)

Example 18 with ResourceGroupState

use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.

the class VsphereStoragePolicyEnumerationHelper method makeStoragePolicyFromResults.

static ResourceGroupState makeStoragePolicyFromResults(ComputeEnumerateResourceRequest request, StoragePolicyOverlay sp, final String dcLink) {
    ResourceGroupState res = new ResourceGroupState();
    res.id = sp.getProfileId();
    res.name = sp.getName();
    res.desc = sp.getDescription();
    res.endpointLink = request.endpointLink;
    AdapterUtils.addToEndpointLinks(res, request.endpointLink);
    res.customProperties = sp.getCapabilities();
    CustomProperties.of(res).put(ComputeProperties.RESOURCE_TYPE_KEY, sp.getType()).put(CustomProperties.DATACENTER_SELF_LINK, dcLink).put(ComputeProperties.ENDPOINT_LINK_PROP_NAME, request.endpointLink);
    return res;
}
Also used : ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)

Example 19 with ResourceGroupState

use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.

the class VsphereStoragePolicyEnumerationHelper method updateStoragePolicy.

static void updateStoragePolicy(VSphereIncrementalEnumerationService service, ResourceGroupState oldDocument, EnumerationProgress enumerationProgress, StoragePolicyOverlay sp) {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    ResourceGroupState rgState = makeStoragePolicyFromResults(request, sp, enumerationProgress.getDcLink());
    rgState.documentSelfLink = oldDocument.documentSelfLink;
    if (oldDocument.tenantLinks == null) {
        rgState.tenantLinks = enumerationProgress.getTenantLinks();
    }
    service.logFine(() -> String.format("Syncing Storage %s", sp.getName()));
    Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), rgState.documentSelfLink)).setBody(rgState).setCompletion((o, e) -> {
        trackStoragePolicy(service, enumerationProgress, sp).handle(o, e);
        if (e == null) {
            // 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)

Example 20 with ResourceGroupState

use of com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState in project photon-model by vmware.

the class BaseVSphereAdapterTest method createResourceGroupState.

/**
 * Creates storage policy as resource group state
 */
protected ResourceGroupState createResourceGroupState() throws Throwable {
    ResourceGroupState rg = new ResourceGroupState();
    rg.id = this.spId != null ? this.spId : "testRG";
    rg.name = this.spName != null ? this.spName : "testRG";
    rg = TestUtils.doPost(this.host, rg, ResourceGroupState.class, UriUtils.buildUri(this.host, ResourceGroupService.FACTORY_LINK));
    return rg;
}
Also used : 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