Search in sources :

Example 1 with ComputeInstanceRequest

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

the class VSphereAdapterInstanceService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();
    ComputeInstanceRequest request = op.getBody(ComputeInstanceRequest.class);
    TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());
    if (request.isMockRequest) {
        handleMockRequest(mgr);
        return;
    }
    ProvisionContext.populateContextThen(this, createInitialContext(request, op), ctx -> {
        switch(request.requestType) {
            case CREATE:
                handleCreateInstance(ctx);
                break;
            case DELETE:
                handleDeleteInstance(ctx);
                break;
            default:
                Throwable error = new IllegalStateException("Unsupported requestType " + request.requestType);
                ctx.fail(error);
        }
    });
}
Also used : TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)

Example 2 with ComputeInstanceRequest

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

the class ResourceRemovalTaskService method sendInstanceDelete.

private void sendInstanceDelete(String resourceLink, String subTaskLink, Operation o, ResourceRemovalTaskState currentState) {
    ComputeStateWithDescription chd = o.getBody(ComputeStateWithDescription.class);
    if (chd.description.instanceAdapterReference != null) {
        ComputeInstanceRequest deleteReq = new ComputeInstanceRequest();
        deleteReq.resourceReference = createInventoryUri(this.getHost(), resourceLink);
        deleteReq.taskReference = UriUtils.buildUri(getHost(), subTaskLink);
        deleteReq.requestType = ComputeInstanceRequest.InstanceRequestType.DELETE;
        deleteReq.isMockRequest = currentState.isMockRequest;
        sendRequest(Operation.createPatch(chd.description.instanceAdapterReference).setBody(deleteReq).setCompletion((deleteOp, e) -> {
            if (e != null) {
                logWarning(() -> String.format("PATCH to instance service %s, failed: %s", deleteOp.getUri(), e.toString()));
                ResourceOperationResponse fail = ResourceOperationResponse.fail(resourceLink, e);
                sendPatch(subTaskLink, fail);
                return;
            }
        }));
    } else {
        logWarning(() -> String.format("Compute instance %s doesn't not have configured" + " instanceAdapter. Only local resource will be deleted.", resourceLink));
        ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.finish(resourceLink);
        sendPatch(subTaskLink, subTaskPatchBody);
    }
}
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) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)

Example 3 with ComputeInstanceRequest

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

the class ProvisionComputeTaskService method doSubStageCreateHost.

private void doSubStageCreateHost(ProvisionComputeTaskState updatedState, ProvisionComputeTaskState.SubStage nextStage) {
    CompletionHandler c = (o, e) -> {
        if (e != null) {
            failTask(e);
            return;
        }
        ComputeInstanceRequest cr = new ComputeInstanceRequest();
        cr.resourceReference = createInventoryUri(this.getHost(), updatedState.computeLink);
        cr.endpointLinkReference = createInventoryUri(this.getHost(), updatedState.endpointLink);
        cr.requestType = InstanceRequestType.CREATE;
        // the first reboot needs to be from the network, and the bare metal
        // services
        // will provide the image reference (retrieved from the computeReference)
        ServiceDocument subTask = o.getBody(ServiceDocument.class);
        cr.taskReference = UriUtils.buildUri(this.getHost(), subTask.documentSelfLink);
        cr.isMockRequest = updatedState.isMockRequest;
        sendHostServiceRequest(cr, updatedState.instanceAdapterReference);
    };
    // after setting boot order and rebooting, we want the sub
    // task to patch us, the main task, to the "next" state
    createSubTask(c, nextStage, updatedState);
}
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) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Aggregations

ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)3 UriPaths (com.vmware.photon.controller.model.UriPaths)2 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)2 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)2 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)2 Operation (com.vmware.xenon.common.Operation)2 TaskState (com.vmware.xenon.common.TaskState)2 UriUtils (com.vmware.xenon.common.UriUtils)2 Utils (com.vmware.xenon.common.Utils)2 TaskService (com.vmware.xenon.services.common.TaskService)2 URI (java.net.URI)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 ComputeBootRequest (com.vmware.photon.controller.model.adapterapi.ComputeBootRequest)1 InstanceRequestType (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType)1 ResourceOperationResponse (com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse)1 TaskManager (com.vmware.photon.controller.model.adapters.util.TaskManager)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)1 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)1