Search in sources :

Example 1 with Service

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

the class BaseTestCase method createHost.

protected VerificationHost createHost() throws Throwable {
    ServiceHost.Arguments args = new ServiceHost.Arguments();
    // ask runtime to pick a random storage location
    args.sandbox = null;
    // ask runtime to pick a random port
    args.port = 0;
    Map<Class<? extends Service>, Class<? extends OperationProcessingChain>> chains = new HashMap<>();
    customizeChains(chains);
    VerificationHost h = VerificationHost.initialize(new CustomizationVerificationHost(chains), args);
    h.setMaintenanceIntervalMicros(this.getMaintenanceIntervalMillis() * 1000);
    h.setTimeoutSeconds(HOST_TIMEOUT_SECONDS);
    h.setPeerSynchronizationEnabled(this.getPeerSynchronizationEnabled());
    h.start();
    return h;
}
Also used : HashMap(java.util.HashMap) Service(com.vmware.xenon.common.Service) StatefulService(com.vmware.xenon.common.StatefulService) FactoryService(com.vmware.xenon.common.FactoryService) ServiceHost(com.vmware.xenon.common.ServiceHost) OperationProcessingChain(com.vmware.xenon.common.OperationProcessingChain) VerificationHost(com.vmware.xenon.common.test.VerificationHost)

Example 2 with Service

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

the class ResourceRemovalTaskService method doInstanceDeletes.

private void doInstanceDeletes(ResourceRemovalTaskState currentState, QueryTask queryTask, String subTaskLink) {
    // handle empty pages
    if (queryTask.results.documentCount == 0) {
        sendSelfPatch(currentState.taskInfo.stage, SubStage.DEALLOCATE_IP_ADDRESSES, s -> {
            s.nextPageLink = null;
        });
        return;
    }
    if (subTaskLink == null) {
        createSubTaskForDeleteCallbacks(currentState, queryTask, link -> doInstanceDeletes(currentState, queryTask, link));
        return;
    }
    logFine(() -> String.format("Starting delete of %d compute resources using sub task %s", queryTask.results.documentLinks.size(), subTaskLink));
    // a DELETE request to its associated instance service.
    for (String resourceLink : queryTask.results.documentLinks) {
        URI u = ComputeStateWithDescription.buildUri(UriUtils.buildUri(getHost(), resourceLink));
        sendRequest(Operation.createGet(u).setCompletion((o, e) -> {
            if (e != null) {
                // we do not fail task if one delete failed ...
                // send a FINISHED patch which is what a sub task
                // would do. Since the
                // current state
                // is still at REMOVING_RESOURCES, we will just
                // increment a counter
                ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(resourceLink, e);
                sendPatch(subTaskLink, subTaskPatchBody);
                return;
            }
            sendInstanceDelete(resourceLink, subTaskLink, o, currentState);
        }));
    }
}
Also used : Service(com.vmware.xenon.common.Service) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) URI(java.net.URI) EnumSet(java.util.EnumSet) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) Operation(com.vmware.xenon.common.Operation) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ResourceIPDeallocationTaskState(com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState) List(java.util.List) Stream(java.util.stream.Stream) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ServiceTaskCallbackResponse(com.vmware.photon.controller.model.tasks.ServiceTaskCallback.ServiceTaskCallbackResponse) DeferredResult(com.vmware.xenon.common.DeferredResult) 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) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) URI(java.net.URI)

Example 3 with Service

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

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

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

the class AdapterUtils method getServiceState.

/**
 * Method will be responsible for getting the service state for the
 * requested resource and invoke Consumer callback for success and
 * failure
 */
public static void getServiceState(Service service, URI computeUri, String contentType, Consumer<Operation> success, Consumer<Throwable> failure) {
    Operation getOp = Operation.createGet(computeUri);
    if (contentType != null) {
        getOp.setContentType(contentType);
    }
    service.sendRequest(getOp.setCompletion((o, e) -> {
        if (e != null) {
            failure.accept(e);
            return;
        }
        success.accept(o);
    }));
}
Also used : Service(com.vmware.xenon.common.Service) Arrays(java.util.Arrays) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ServiceHost(com.vmware.xenon.common.ServiceHost) Level(java.util.logging.Level) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Utils(com.vmware.xenon.common.Utils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) UriUtils(com.vmware.xenon.common.UriUtils) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) URI(java.net.URI) ExecutorService(java.util.concurrent.ExecutorService) Operation(com.vmware.xenon.common.Operation)

Aggregations

Service (com.vmware.xenon.common.Service)12 Operation (com.vmware.xenon.common.Operation)10 UriUtils (com.vmware.xenon.common.UriUtils)9 Utils (com.vmware.xenon.common.Utils)9 URI (java.net.URI)9 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)7 List (java.util.List)7 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)6 OperationJoin (com.vmware.xenon.common.OperationJoin)6 EnumSet (java.util.EnumSet)6 Consumer (java.util.function.Consumer)6 Query (com.vmware.xenon.services.common.QueryTask.Query)5 UriPaths (com.vmware.photon.controller.model.UriPaths)4 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)4 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)4 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)4 Collections (java.util.Collections)4 TimeUnit (java.util.concurrent.TimeUnit)4 IAAS_API_ENABLED (com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED)3 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)3