Search in sources :

Example 16 with ResourceOperationResponse

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

the class ProvisionSecurityGroupTaskService method patchAdapter.

private void patchAdapter(ProvisionSecurityGroupTaskState taskState, String subTaskLink) {
    if (subTaskLink == null) {
        createSubTask(taskState, link -> patchAdapter(taskState, link));
        return;
    }
    taskState.securityGroupDescriptionLinks.forEach(sgLink -> sendRequest(Operation.createGet(UriUtils.buildUri(this.getHost(), sgLink)).setCompletion((o, e) -> {
        if (e != null) {
            // don't fail the task; just update the subtask, which will
            // handle the failure if necessary
            ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(sgLink, e);
            updateSubTask(subTaskLink, subTaskPatchBody);
            return;
        }
        SecurityGroupState securityGroupState = o.getBody(SecurityGroupState.class);
        SecurityGroupInstanceRequest req = toReq(securityGroupState, taskState, sgLink, subTaskLink);
        sendRequest(Operation.createPatch(securityGroupState.instanceAdapterReference).setBody(req).setCompletion((oo, ee) -> {
            if (ee != null) {
                ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(sgLink, ee);
                updateSubTask(subTaskLink, subTaskPatchBody);
            }
        }));
    })));
}
Also used : SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest) Operation(com.vmware.xenon.common.Operation) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) Set(java.util.Set) ProvisionSecurityGroupTaskState(com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Consumer(java.util.function.Consumer) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) Map(java.util.Map) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) EXPAND(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.EXPAND) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest.InstanceRequestType) TaskService(com.vmware.xenon.services.common.TaskService) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) FIXED_ITEM_NAME(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.FIXED_ITEM_NAME) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)

Example 17 with ResourceOperationResponse

use of com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse 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)

Aggregations

ResourceOperationResponse (com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse)17 Operation (com.vmware.xenon.common.Operation)14 TestContext (com.vmware.xenon.common.test.TestContext)10 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)9 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)8 ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)8 UriPaths (com.vmware.photon.controller.model.UriPaths)4 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)4 PropertyUsageOption (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption)4 TaskState (com.vmware.xenon.common.TaskState)4 UriUtils (com.vmware.xenon.common.UriUtils)4 Utils (com.vmware.xenon.common.Utils)4 TaskService (com.vmware.xenon.services.common.TaskService)4 List (java.util.List)4 Consumer (java.util.function.Consumer)4 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)3 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)3 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)3 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)3 SnapshotService (com.vmware.photon.controller.model.resources.SnapshotService)3