Search in sources :

Example 26 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VsphereDatastoreEnumerationHelper method updateStorageDescription.

private static void updateStorageDescription(VSphereIncrementalEnumerationService service, StorageDescription oldDocument, EnumerationProgress enumerationProgress, DatastoreOverlay ds, boolean fullUpdate) {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    String regionId = enumerationProgress.getRegionId();
    StorageDescription desc;
    if (fullUpdate) {
        desc = makeStorageFromResults(request, ds, regionId, enumerationProgress);
    } else {
        desc = makeStorageFromChanges(ds, oldDocument);
    }
    desc.documentSelfLink = oldDocument.documentSelfLink;
    desc.resourcePoolLink = null;
    if (oldDocument.tenantLinks == null) {
        desc.tenantLinks = enumerationProgress.getTenantLinks();
    }
    service.logFine(() -> String.format("Syncing Storage %s", ds.getName()));
    Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), desc.documentSelfLink)).setBody(desc).setCompletion((o, e) -> {
        trackDatastore(enumerationProgress, ds).handle(o, e);
        if (e == null) {
            VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
                VsphereEnumerationHelper.updateLocalTags(service, enumerationProgress, ds, o.getBody(ResourceState.class));
                updateStorageStats(service, ds, o.getBody(ServiceDocument.class).documentSelfLink);
            });
        }
    }).sendWith(service);
}
Also used : STORAGE_USED_BYTES(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_USED_BYTES) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) ServiceDocument(com.vmware.xenon.common.ServiceDocument) HashMap(java.util.HashMap) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) CUSTOM_PROP_STORAGE_SHARED(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_PROP_STORAGE_SHARED) Utils(com.vmware.xenon.common.Utils) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) StatsUtil(com.vmware.photon.controller.model.tasks.monitoring.StatsUtil) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) TimeUnit(java.util.concurrent.TimeUnit) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) STORAGE_AVAILABLE_BYTES(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_AVAILABLE_BYTES) List(java.util.List) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceDocument(com.vmware.xenon.common.ServiceDocument) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Example 27 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest 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)

Example 28 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VSphereNetworkEnumerationHelper method makeNetworkStateFromResults.

private static NetworkState makeNetworkStateFromResults(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, NetworkOverlay net) {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    ComputeStateWithDescription parent = enumerationProgress.getParent();
    NetworkState state = new NetworkState();
    state.documentSelfLink = NetworkService.FACTORY_LINK + "/" + service.getHost().nextUUID();
    state.id = state.name = net.getName();
    state.endpointLink = enumerationProgress.getRequest().endpointLink;
    AdapterUtils.addToEndpointLinks(state, enumerationProgress.getRequest().endpointLink);
    state.regionId = enumerationProgress.getRegionId();
    state.resourcePoolLink = request.resourcePoolLink;
    state.adapterManagementReference = request.adapterManagementReference;
    state.authCredentialsLink = parent.description.authCredentialsLink;
    URI ref = parent.description.instanceAdapterReference;
    state.instanceAdapterReference = AdapterUriUtil.buildAdapterUri(ref.getPort(), VSphereUriPaths.DVS_NETWORK_SERVICE);
    CustomProperties custProp = CustomProperties.of(state).put(CustomProperties.MOREF, net.getId()).put(CustomProperties.DATACENTER_SELF_LINK, enumerationProgress.getDcLink()).put(CustomProperties.TYPE, net.getId().getType());
    if (net.getSummary() instanceof OpaqueNetworkSummary) {
        OpaqueNetworkSummary ons = (OpaqueNetworkSummary) net.getSummary();
        custProp.put(NsxProperties.OPAQUE_NET_ID, ons.getOpaqueNetworkId());
        custProp.put(NsxProperties.OPAQUE_NET_TYPE, ons.getOpaqueNetworkType());
    }
    if (net.getId().getType().equals(VimNames.TYPE_DVS)) {
        // dvs'es have a stable link
        state.documentSelfLink = buildStableDvsLink(net.getId(), request.endpointLink);
        custProp.put(DvsProperties.DVS_UUID, net.getDvsUuid());
    }
    VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(state, enumerationProgress.getVcUuid());
    return state;
}
Also used : OpaqueNetworkSummary(com.vmware.vim25.OpaqueNetworkSummary) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) URI(java.net.URI)

Example 29 with ComputeEnumerateResourceRequest

use of com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest in project photon-model by vmware.

the class VSphereResourcePoolEnumerationHelper method processFoundResourcePool.

public static void processFoundResourcePool(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, ResourcePoolOverlay rp, String ownerName, EnumerationClient client) {
    ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
    String selfLink = buildStableResourcePoolLink(rp.getId(), request.endpointLink);
    Operation.createGet(PhotonModelUriUtils.createInventoryUri(service.getHost(), selfLink)).setCompletion((o, e) -> {
        try {
            if (e == null) {
                updateResourcePool(service, enumerationProgress, ownerName, selfLink, rp, true, client);
            } else if (e instanceof ServiceNotFoundException || o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) {
                createNewResourcePool(service, enumerationProgress, ownerName, selfLink, rp, client);
            } else {
                enumerationProgress.getResourcePoolTracker().track();
            }
        } catch (Exception ex) {
            enumerationProgress.getResourcePoolTracker().track(rp.getId(), ResourceTracker.ERROR);
        }
    }).sendWith(service);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) List(java.util.List) UriUtils.buildUriPath(com.vmware.xenon.common.UriUtils.buildUriPath) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) Collections(java.util.Collections) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)

Aggregations

ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)29 QueryTask (com.vmware.xenon.services.common.QueryTask)16 Operation (com.vmware.xenon.common.Operation)12 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)11 List (java.util.List)11 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)10 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)10 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)10 Utils (com.vmware.xenon.common.Utils)10 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)9 VsphereEnumerationHelper.convertOnlyResultToDocument (com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument)8 VsphereEnumerationHelper.withTaskResults (com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults)8 ObjectUpdateKind (com.vmware.vim25.ObjectUpdateKind)8 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)8 UriUtils (com.vmware.xenon.common.UriUtils)8 Map (java.util.Map)8 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)7 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)7 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)7 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)7