Search in sources :

Example 1 with ComputeEnumerateResourceRequest

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

the class AWSEnumerationAdapterService method handlePatch.

@Override
public void handlePatch(Operation op) {
    setOperationHandlerInvokeTimeStat(op);
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    op.complete();
    ComputeEnumerateResourceRequest request = op.getBody(ComputeEnumerateResourceRequest.class);
    AdapterUtils.validateEnumRequest(request);
    EnumerationContext context = new EnumerationContext(this, request, op);
    if (request.isMockRequest) {
        // patch status to parent task
        context.taskManager.finishTask();
        return;
    }
    context.populateBaseContext(BaseAdapterStage.PARENTDESC).whenComplete((ignoreCtx, t) -> {
        // NOTE: In case of error 'ignoreCtx' is null so use passed context!
        if (t != null) {
            context.error = t;
            context.stage = AWSEnumerationStages.ERROR;
        }
        handleEnumerationRequest(context);
    });
}
Also used : ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)

Example 2 with ComputeEnumerateResourceRequest

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

the class AzureEnumerationAdapterService method handlePatch.

@Override
public void handlePatch(Operation op) {
    setOperationHandlerInvokeTimeStat(op);
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    ComputeEnumerateResourceRequest request = op.getBody(ComputeEnumerateResourceRequest.class);
    try {
        AdapterUtils.validateEnumRequest(request);
        op.complete();
    } catch (Exception e) {
        op.fail(e);
    }
    EnumerationContext context = new EnumerationContext(this, request, op);
    if (request.isMockRequest) {
        // patch status to parent task
        context.taskManager.finishTask();
        return;
    }
    context.populateBaseContext(BaseAdapterStage.PARENTDESC).whenComplete((ignoreCtx, t) -> {
        // NOTE: In case of error 'ignoreCtx' is null so use passed context!
        if (t != null) {
            context.error = t;
            context.stage = AzureEnumerationStages.ERROR;
        }
        handleEnumerationRequest(context);
    });
}
Also used : ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)

Example 3 with ComputeEnumerateResourceRequest

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

the class ResourceEnumerationTaskService method sendEnumRequest.

private void sendEnumRequest(Operation start, ResourceEnumerationTaskState state) {
    ComputeEnumerateResourceRequest req = new ComputeEnumerateResourceRequest();
    req.resourcePoolLink = state.resourcePoolLink;
    req.adapterManagementReference = state.adapterManagementReference;
    req.resourceReference = createInventoryUri(this.getHost(), state.parentComputeLink);
    req.endpointLinkReference = createInventoryUri(this.getHost(), state.endpointLink);
    req.enumerationAction = state.enumerationAction;
    req.taskReference = UriUtils.buildUri(getHost(), state.documentSelfLink);
    req.isMockRequest = state.options.contains(TaskOption.IS_MOCK);
    req.preserveMissing = state.options.contains(TaskOption.PRESERVE_MISSING_RESOUCES);
    req.endpointLink = state.endpointLink;
    req.deletedResourceExpirationMicros = getResourceExpirationMicros(state.expirationPolicy == null ? ResourceExpirationPolicy.EXPIRE_AFTER_ONE_MONTH : state.expirationPolicy);
    // Patch the enumerate service URI from the CHD
    CompletionHandler descriptionCompletion = (o, ex) -> {
        if (ex != null) {
            TaskUtils.sendFailurePatch(this, state, ex);
            start.fail(ex);
            return;
        }
        ComputeStateWithDescription csd = o.getBody(ComputeStateWithDescription.class);
        if (csd.description.enumerationAdapterReference == null) {
            // no enumeration adapter associated with this resource, just patch completion
            sendSelfFinishedPatch(state);
            return;
        }
        sendRequest(Operation.createPatch(csd.description.enumerationAdapterReference).setBody(req));
    };
    URI computeUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(this.getHost(), state.parentComputeLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
    sendRequest(Operation.createGet(computeUri).setCompletion(descriptionCompletion));
}
Also used : Service(com.vmware.xenon.common.Service) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) HashMap(java.util.HashMap) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) HashSet(java.util.HashSet) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) Map(java.util.Map) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) URI(java.net.URI) LinkedList(java.util.LinkedList) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TaskUtils.getResourceExpirationMicros(com.vmware.photon.controller.model.tasks.TaskUtils.getResourceExpirationMicros) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ReleaseConstants(com.vmware.photon.controller.model.constants.ReleaseConstants) TaskState(com.vmware.xenon.common.TaskState) FactoryService(com.vmware.xenon.common.FactoryService) ServiceStateMapUpdateRequest(com.vmware.xenon.common.ServiceStateMapUpdateRequest) TaskService(com.vmware.xenon.services.common.TaskService) Collections(java.util.Collections) Since(com.esotericsoftware.kryo.serializers.VersionFieldSerializer.Since) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) URI(java.net.URI)

Example 4 with ComputeEnumerateResourceRequest

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

the class AzureDiskEnumerationServiceTest method kickOffEnumeration.

private ComputeEnumerateResourceRequest kickOffEnumeration() throws Throwable {
    ComputeEnumerateResourceRequest resourceRequest = new ComputeEnumerateResourceRequest();
    resourceRequest.endpointLink = this.endpointState.documentSelfLink;
    resourceRequest.enumerationAction = EnumerationAction.START;
    resourceRequest.adapterManagementReference = UriUtils.buildUri(AzureEnumerationAdapterService.SELF_LINK);
    resourceRequest.resourcePoolLink = this.resourcePool.documentSelfLink;
    resourceRequest.resourceReference = UriUtils.buildUri(getHost(), "");
    resourceRequest.isMockRequest = this.isMock;
    return resourceRequest;
}
Also used : ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)

Example 5 with ComputeEnumerateResourceRequest

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

the class VSphereIncrementalEnumerationService method garbageCollectUntouchedComputeResources.

private void garbageCollectUntouchedComputeResources(ComputeEnumerateResourceRequest request, Set<String> untouchedResources, TaskManager mgr) {
    if (untouchedResources.isEmpty()) {
        mgr.patchTask(TaskStage.FINISHED);
        return;
    }
    if (!request.preserveMissing) {
        // delete dependent resources without waiting for response
        for (String resourceLink : untouchedResources) {
            Operation.createDelete(PhotonModelUriUtils.createInventoryUri(getHost(), resourceLink)).sendWith(this);
        }
        mgr.patchTask(TaskStage.FINISHED);
        return;
    }
    List<Operation> deleteOps = new ArrayList<>();
    for (String resourceLink : untouchedResources) {
        if (resourceLink.startsWith(ComputeService.FACTORY_LINK)) {
            ResourceCleanRequest patch = new ResourceCleanRequest();
            patch.resourceLink = resourceLink;
            deleteOps.add(Operation.createPatch(this, VSphereUriPaths.RESOURCE_CLEANER).setBody(patch));
        } else {
            deleteOps.add(Operation.createDelete(PhotonModelUriUtils.createInventoryUri(getHost(), resourceLink)));
        }
    }
    OperationJoin.create(deleteOps).setCompletion((os, es) -> mgr.patchTask(TaskStage.FINISHED)).sendWith(this);
}
Also used : Arrays(java.util.Arrays) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) TagCache(com.vmware.photon.controller.model.adapters.vsphere.tagging.TagCache) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) UpdateSet(com.vmware.vim25.UpdateSet) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) Utils(com.vmware.xenon.common.Utils) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) Map(java.util.Map) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) URI(java.net.URI) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) StatelessService(com.vmware.xenon.common.StatelessService) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) Collectors(java.util.stream.Collectors) List(java.util.List) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) DeferredResult(com.vmware.xenon.common.DeferredResult) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) AboutInfo(com.vmware.vim25.AboutInfo) DiskService(com.vmware.photon.controller.model.resources.DiskService) MoRefKeyedMap(com.vmware.photon.controller.model.adapters.vsphere.util.MoRefKeyedMap) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceCleanRequest(com.vmware.photon.controller.model.adapters.vsphere.VsphereResourceCleanerService.ResourceCleanRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) HashMap(java.util.HashMap) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) RpcException(com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) TYPE_SERVER_DISK(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames.TYPE_SERVER_DISK) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) Operation(com.vmware.xenon.common.Operation) ObjectUpdateIterator(com.vmware.photon.controller.model.adapters.vsphere.EnumerationClient.ObjectUpdateIterator) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) PropertyFilterUpdate(com.vmware.vim25.PropertyFilterUpdate) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ObjectUpdate(com.vmware.vim25.ObjectUpdate) OperationJoin(com.vmware.xenon.common.OperationJoin) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) ResourceCleanRequest(com.vmware.photon.controller.model.adapters.vsphere.VsphereResourceCleanerService.ResourceCleanRequest)

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