Search in sources :

Example 91 with Operation

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

the class EndpointRemovalTaskService method doInstanceDelete.

/**
 * Delete endpoint
 */
private void doInstanceDelete(EndpointRemovalTaskState currentState, SubStage next) {
    EndpointState endpoint = currentState.endpoint;
    Operation crdOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.authCredentialsLink));
    Operation epOp = Operation.createDelete(createInventoryUri(this.getHost(), endpoint.documentSelfLink));
    // custom header identifier for endpoint service to validate before deleting endpoint
    epOp.addRequestHeader(ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME, ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE);
    OperationJoin.create(crdOp, epOp).setCompletion((ops, exc) -> {
        if (exc != null) {
            // failing to delete the endpoint itself is considered a critical error
            Throwable endpointRemovalException = exc.get(epOp.getId());
            if (endpointRemovalException != null) {
                sendFailureSelfPatch(endpointRemovalException);
                return;
            }
            // other removal exceptions are just warnings
            logFine(() -> String.format("Failed delete some of the associated resources," + " reason %s", Utils.toString(exc)));
        }
        // Endpoint and AuthCredentials are deleted; mark the operation as complete
        sendSelfPatch(TaskStage.STARTED, next);
    }).sendWith(this);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) LINK(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.LINK) Service(com.vmware.xenon.common.Service) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) QueryTask(com.vmware.xenon.services.common.QueryTask) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Utils(com.vmware.xenon.common.Utils) RouterState(com.vmware.photon.controller.model.resources.RouterService.RouterState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) SEPARATOR(com.vmware.photon.controller.model.tasks.monitoring.StatsUtil.SEPARATOR) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Collection(java.util.Collection) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) ServiceHost(com.vmware.xenon.common.ServiceHost) ENDPOINT_LINK_EXPLICIT_SUPPORT(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.ENDPOINT_LINK_EXPLICIT_SUPPORT) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) UriUtils(com.vmware.xenon.common.UriUtils) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) ArrayList(java.util.ArrayList) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) HashSet(java.util.HashSet) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE(com.vmware.photon.controller.model.resources.EndpointService.ENDPOINT_REMOVAL_REQUEST_REFERRER_VALUE) ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME(com.vmware.photon.controller.model.resources.EndpointService.ENDPOINT_REMOVAL_REQUEST_REFERRER_NAME) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) Operation(com.vmware.xenon.common.Operation)

Example 92 with Operation

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

the class IPAddressReleaseTaskService method markIPAddressesAsAvailable.

/**
 * Releases IP Addresses and marks them as available.
 * @param ipAddressStates IP Address states
 */
private DeferredResult<List<Operation>> markIPAddressesAsAvailable(List<IPAddressService.IPAddressState> ipAddressStates) {
    IPAddressService.IPAddressState addressState = new IPAddressService.IPAddressState();
    addressState.ipAddressStatus = IPAddressService.IPAddressState.IPAddressStatus.AVAILABLE;
    List<DeferredResult<Operation>> ipAddressOperations = new ArrayList<>();
    for (IPAddressService.IPAddressState ipAddressState : ipAddressStates) {
        Operation patchOp = Operation.createPatch(this, ipAddressState.documentSelfLink).setBody(addressState).setCompletion((o, e) -> {
            if (e != null) {
                logWarning("Failed to mark IP address resource %s as available due to failure %s", ipAddressState.ipAddress, e.getMessage());
            } else {
                logInfo("The IP address %s is made available", ipAddressState.ipAddress);
            }
        });
        ipAddressOperations.add(this.sendWithDeferredResult(patchOp));
    }
    return DeferredResult.allOf(ipAddressOperations);
}
Also used : IPAddressService(com.vmware.photon.controller.model.resources.IPAddressService) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 93 with Operation

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

the class ProvisionComputeTaskService method sendSelfPatch.

private void sendSelfPatch(TaskStage newStage, ProvisionComputeTaskState.SubStage newSubStage, Throwable ex) {
    ProvisionComputeTaskState patchBody = new ProvisionComputeTaskState();
    patchBody.taskInfo = new TaskState();
    patchBody.taskInfo.stage = newStage;
    patchBody.taskSubStage = newSubStage;
    if (ex != null) {
        patchBody.taskInfo.failure = Utils.toServiceErrorResponse(ex);
    }
    Operation patch = Operation.createPatch(getUri()).setBody(patchBody).setCompletion((o, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Self patch failed: %s", com.vmware.xenon.common.Utils.toString(e)));
        }
    });
    sendRequest(patch);
}
Also used : Operation(com.vmware.xenon.common.Operation) TaskState(com.vmware.xenon.common.TaskState)

Example 94 with Operation

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

the class ProvisionComputeTaskService method handleStart.

@Override
public void handleStart(Operation startPost) {
    try {
        ProvisionComputeTaskState state = startPost.getBody(ProvisionComputeTaskState.class);
        validateState(state);
        // we need to retrieve and cache the power and boot services we need
        // to actuate
        URI computeHost = buildComputeHostUri(state);
        sendRequest(Operation.createGet(computeHost).addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY).setCompletion((o, e) -> validateComputeHostAndStart(startPost, o, e, state)));
    } catch (Throwable e) {
        logSevere(e);
        startPost.fail(e);
    }
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ComputeBootRequest(com.vmware.photon.controller.model.adapterapi.ComputeBootRequest) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) Operation(com.vmware.xenon.common.Operation) ServiceDocument(com.vmware.xenon.common.ServiceDocument) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType) BootDevice(com.vmware.photon.controller.model.resources.ComputeService.BootDevice) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) InetAddressValidator(org.apache.commons.validator.routines.InetAddressValidator) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) URI(java.net.URI) TaskService(com.vmware.xenon.services.common.TaskService) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) SubStage(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState.SubStage) URI(java.net.URI)

Example 95 with Operation

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

the class SingleResourceStatsCollectionTaskService method batchPersistStats.

private void batchPersistStats(List<Operation> operations, int batchIndex, boolean isFinalBatch) {
    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) {
            logWarning(() -> String.format("Failed stats collection: %s", exc.values().iterator().next().getMessage()));
            TaskUtils.sendFailurePatch(this, new SingleResourceStatsCollectionTaskState(), exc.values());
            return;
        }
        if (finalNextBatchIndex == null || finalNextBatchIndex == operations.size()) {
            if (isFinalBatch) {
                SingleResourceStatsCollectionTaskState nextStatePatch = new SingleResourceStatsCollectionTaskState();
                nextStatePatch.taskInfo = TaskUtils.createTaskState(TaskStage.FINISHED);
                TaskUtils.sendPatch(this, nextStatePatch);
            }
            return;
        }
        batchPersistStats(operations, finalNextBatchIndex, isFinalBatch);
    });
    opSequence.sendWith(this);
}
Also used : OperationSequence(com.vmware.xenon.common.OperationSequence) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) 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