Search in sources :

Example 1 with ResourceIPDeallocationTaskState

use of com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState in project photon-model by vmware.

the class ResourceRemovalTaskService method deallocateIpAddressesForResources.

private void deallocateIpAddressesForResources(ResourceRemovalTaskState currentState, QueryTask queryTask, String subTaskLink) {
    // handle empty pages
    if (queryTask.results.documentCount == 0) {
        sendSelfPatch(TaskState.TaskStage.FINISHED, SubStage.FINISHED, null);
        return;
    }
    if (subTaskLink == null) {
        createSubTaskForIpDeallocationCallbacks(currentState, queryTask, link -> deallocateIpAddressesForResources(currentState, queryTask, link));
        return;
    }
    logFine("Starting ip deallocation of %d compute resources using sub task", queryTask.results.documentCount);
    // for each compute resource link in the results, call ResourceIPDeallocationTaskService
    for (String resourceLink : queryTask.results.documentLinks) {
        ResourceIPDeallocationTaskState deallocateTask = new ResourceIPDeallocationTaskState();
        deallocateTask.resourceLink = resourceLink;
        deallocateTask.tenantLinks = currentState.tenantLinks;
        deallocateTask.serviceTaskCallback = ServiceTaskCallback.create(UriUtils.buildPublicUri(getHost(), subTaskLink));
        deallocateTask.serviceTaskCallback.onSuccessFinishTask();
        // Similar to instance deletes - a failure for one network interface deallocate will fail the task
        deallocateTask.serviceTaskCallback.onErrorFailTask();
        this.sendRequest(Operation.createPost(this, ResourceIPDeallocationTaskService.FACTORY_LINK).setBody(deallocateTask).setCompletion((o, ex) -> {
            if (ex != null) {
                logSevere("Failure deallocating IPs for resource: [%s]: %s", resourceLink, ex);
                ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.finish(resourceLink);
                sendPatch(subTaskLink, subTaskPatchBody);
            } else {
                logFine("Sent deallocation IPs request for resource [%s]", resourceLink);
            }
        }));
    }
}
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) ResourceIPDeallocationTaskState(com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState)

Aggregations

UriPaths (com.vmware.photon.controller.model.UriPaths)1 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)1 ResourceOperationResponse (com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse)1 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)1 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)1 SnapshotService (com.vmware.photon.controller.model.resources.SnapshotService)1 ResourceIPDeallocationTaskState (com.vmware.photon.controller.model.tasks.ResourceIPDeallocationTaskService.ResourceIPDeallocationTaskState)1 ServiceTaskCallbackResponse (com.vmware.photon.controller.model.tasks.ServiceTaskCallback.ServiceTaskCallbackResponse)1 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)1 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 Operation (com.vmware.xenon.common.Operation)1 OperationJoin (com.vmware.xenon.common.OperationJoin)1 Service (com.vmware.xenon.common.Service)1 PropertyUsageOption (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption)1 ServiceErrorResponse (com.vmware.xenon.common.ServiceErrorResponse)1 TaskState (com.vmware.xenon.common.TaskState)1