Search in sources :

Example 96 with Operation

use of com.vmware.xenon.common.Operation in project photon-model by vmware.

the class StatsCollectionTaskService method createSubTask.

private void createSubTask(List<String> computeResources, String nextPageLink, StatsCollectionTaskState currentState) {
    ServiceTaskCallback<StatsCollectionStage> callback = ServiceTaskCallback.create(UriUtils.buildPublicUri(getHost(), getSelfLink()));
    if (nextPageLink != null) {
        callback.onSuccessTo(StatsCollectionStage.GET_RESOURCES).addProperty(PROP_NEXT_PAGE_LINK, nextPageLink);
    } else {
        callback.onSuccessFinishTask();
    }
    SubTaskState<StatsCollectionStage> subTaskInitState = new SubTaskState<>();
    subTaskInitState.errorThreshold = 0;
    subTaskInitState.completionsRemaining = computeResources.size();
    subTaskInitState.serviceTaskCallback = callback;
    Operation startPost = Operation.createPost(this, SubTaskService.FACTORY_LINK).setBody(subTaskInitState).setCompletion((postOp, postEx) -> {
        if (postEx != null) {
            TaskUtils.sendFailurePatch(this, new StatsCollectionTaskState(), postEx);
            return;
        }
        SubTaskState<?> body = postOp.getBody(SubTaskState.class);
        // via the compute subtask
        for (String computeLink : computeResources) {
            createSingleResourceComputeTask(computeLink, body.documentSelfLink, currentState);
        }
    });
    sendRequest(startPost);
}
Also used : SubTaskState(com.vmware.photon.controller.model.tasks.SubTaskService.SubTaskState) Operation(com.vmware.xenon.common.Operation) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

Example 97 with Operation

use of com.vmware.xenon.common.Operation 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 98 with Operation

use of com.vmware.xenon.common.Operation in project photon-model by vmware.

the class ResourceIPDeallocationTaskService method getComputeResource.

private DeferredResult<ResourceIPDeallocationContext> getComputeResource(ResourceIPDeallocationContext ctx) {
    Operation op = Operation.createGet(ComputeService.ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), ctx.resourceLink)));
    return sendWithDeferredResult(op, ComputeState.class).thenApply(computeState -> {
        ctx.computeResource = computeState;
        logFine("Retrieved resource [%s]", ctx.resourceLink);
        return ctx;
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Operation(com.vmware.xenon.common.Operation)

Example 99 with Operation

use of com.vmware.xenon.common.Operation in project photon-model by vmware.

the class TagGroomerTaskServiceTest method executeTagsGroomerTask.

/**
 * Run groomer task and wait for completion
 */
private void executeTagsGroomerTask() {
    TagDeletionRequest state = new TagDeletionRequest();
    state.documentSelfLink = UriUtils.buildUriPath(TagGroomerTaskService.FACTORY_LINK, UUID.randomUUID().toString());
    Operation postOp = Operation.createPost(UriUtils.buildUri(this.host, TagGroomerTaskService.FACTORY_LINK)).setBody(state);
    this.host.waitForResponse(postOp);
    this.host.waitForFinishedTask(TagDeletionRequest.class, state.documentSelfLink);
}
Also used : TagDeletionRequest(com.vmware.photon.controller.model.tasks.TagGroomerTaskService.TagDeletionRequest) Operation(com.vmware.xenon.common.Operation)

Example 100 with Operation

use of com.vmware.xenon.common.Operation in project photon-model by vmware.

the class TagGroomerTaskServiceTest method createComputesWithTags.

/**
 * Create n computes associated with specific tags
 */
private void createComputesWithTags(int count, List<String> tagLinks) {
    ComputeState computeState = new ComputeState();
    computeState.descriptionLink = "description-link";
    computeState.id = UUID.randomUUID().toString();
    computeState.name = computeState.id;
    computeState.tagLinks = new HashSet<>();
    for (int i = 0; i < count; i++) {
        computeState.tagLinks.add(tagLinks.get(i));
        Operation op = Operation.createPost(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)).setBody(computeState);
        this.host.waitForResponse(op);
        // clear tagLinks and assign new one on the next round
        computeState.tagLinks.clear();
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Operation(com.vmware.xenon.common.Operation)

Aggregations

Operation (com.vmware.xenon.common.Operation)391 URI (java.net.URI)142 ArrayList (java.util.ArrayList)132 QueryTask (com.vmware.xenon.services.common.QueryTask)118 List (java.util.List)118 Utils (com.vmware.xenon.common.Utils)111 StatelessService (com.vmware.xenon.common.StatelessService)108 UriUtils (com.vmware.xenon.common.UriUtils)106 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)98 Map (java.util.Map)92 HashMap (java.util.HashMap)90 OperationJoin (com.vmware.xenon.common.OperationJoin)86 Query (com.vmware.xenon.services.common.QueryTask.Query)86 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)82 Collectors (java.util.stream.Collectors)79 HashSet (java.util.HashSet)78 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)73 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)70 DeferredResult (com.vmware.xenon.common.DeferredResult)69 Consumer (java.util.function.Consumer)69