Search in sources :

Example 6 with OperationSequence

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

the class VSphereDiskService method finishDiskDeleteOperation.

/**
 * Finish the disk delete operation by cleaning up the disk reference in the system.
 */
private void finishDiskDeleteOperation(DiskContext ctx) {
    // Clean up disk description link if it is present.
    String diskDescLink = CustomProperties.of(ctx.diskState).getString(PhotonModelConstants.TEMPLATE_DISK_LINK);
    OperationSequence seq = null;
    if (diskDescLink != null && !diskDescLink.isEmpty()) {
        seq = OperationSequence.create(deleteDisk(diskDescLink));
    }
    List<Operation> nextOps = new ArrayList<>(2);
    if (seq == null) {
        seq = OperationSequence.create(deleteDisk(ctx.diskState.documentSelfLink));
    } else {
        nextOps.add(deleteDisk(ctx.diskState.documentSelfLink));
    }
    nextOps.add(ctx.mgr.createTaskPatch(TaskState.TaskStage.FINISHED));
    seq.next(nextOps.toArray(new Operation[nextOps.size()])).setCompletion(ctx.failTaskOnError()).sendWith(this);
}
Also used : OperationSequence(com.vmware.xenon.common.OperationSequence) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation)

Example 7 with OperationSequence

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

the class SingleResourceStatsAggregationTaskService method batchPublishMetrics.

public void batchPublishMetrics(SingleResourceStatsAggregationTaskState currentState, List<Operation> operations, int batchIndex) {
    OperationSequence opSequence = null;
    Integer nextBatchIndex = null;
    for (int i = batchIndex; i < operations.size(); i++) {
        final Operation operation = operations.get(i);
        if (opSequence == null) {
            opSequence = OperationSequence.create(operation);
            continue;
        }
        opSequence = opSequence.next(operation);
        // Batch size of 100
        int batchSize = 100;
        int opSequenceSize = i + 1;
        if ((opSequenceSize % batchSize) == 0) {
            nextBatchIndex = opSequenceSize;
            break;
        }
    }
    Integer finalNextBatchIndex = nextBatchIndex;
    opSequence.setCompletion((ops, exc) -> {
        if (exc != null) {
            sendSelfFailurePatch(currentState, exc.values().iterator().next().getMessage());
            return;
        }
        if (finalNextBatchIndex == null || finalNextBatchIndex == operations.size()) {
            sendSelfPatch(currentState, TaskStage.FINISHED, null);
            return;
        }
        batchPublishMetrics(currentState, operations, finalNextBatchIndex);
    });
    opSequence.sendWith(this);
}
Also used : OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation)

Example 8 with OperationSequence

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

the class EndpointAllocationTaskService method rollbackEndpoint.

private void rollbackEndpoint(EndpointAllocationTaskState currentState) {
    Runnable completionHandler = () -> {
        sendSelfPatch(createUpdateSubStageTask(TaskStage.FAILED, SubStage.FAILED));
    };
    if (currentState.createdDocumentLinks == null || currentState.createdDocumentLinks.isEmpty()) {
        completionHandler.run();
    } else {
        List<Operation> deleteOps = currentState.createdDocumentLinks.stream().map(link -> Operation.createDelete(this, link)).collect(Collectors.toList());
        // execute the delete ops in a reverse order because of possible dependencies
        OperationSequence opSequence = OperationSequence.create(deleteOps.get(deleteOps.size() - 1));
        for (int i = deleteOps.size() - 2; i >= 0; i--) {
            opSequence = opSequence.next(deleteOps.get(i));
        }
        opSequence.setCompletion((ops, exs) -> {
            if (exs != null) {
                logWarning(() -> "Error during rollback of created endpoint documents: " + Utils.toString(exs));
            }
            completionHandler.run();
        }).sendWith(this);
    }
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation)

Aggregations

Operation (com.vmware.xenon.common.Operation)8 OperationSequence (com.vmware.xenon.common.OperationSequence)8 ArrayList (java.util.ArrayList)5 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)3 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 OperationJoin (com.vmware.xenon.common.OperationJoin)3 ENDPOINT_LINK_PROP_NAME (com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME)2 UriPaths (com.vmware.photon.controller.model.UriPaths)2 AdapterTypePath (com.vmware.photon.controller.model.UriPaths.AdapterTypePath)2 EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)2 RequestType (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType)2 PhotonModelAdaptersConfigAccessService (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService)2 PhotonModelAdapterConfig (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)2 CUSTOM_PROP_ENDPOINT_LINK (com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK)2 SOURCE_TASK_LINK (com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK)2 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)2 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)2 EndpointService (com.vmware.photon.controller.model.resources.EndpointService)2 ResourcePoolService (com.vmware.photon.controller.model.resources.ResourcePoolService)2