Search in sources :

Example 81 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class ComputeSystemControllerImpl method waitForAsyncFileExportTask.

/**
 * Waits for the file export or unexport task to complete.
 * This is required because FileDeviceController does not use a workflow.
 *
 * @param fileShareId
 *            id of the FileShare being exported
 * @param stepId
 *            id of the workflow step
 */
private void waitForAsyncFileExportTask(URI fileShareId, String stepId) {
    boolean done = false;
    try {
        while (!done) {
            Thread.sleep(1000);
            FileShare fsObj = _dbClient.queryObject(FileShare.class, fileShareId);
            if (fsObj.getOpStatus().containsKey(stepId)) {
                Operation op = fsObj.getOpStatus().get(stepId);
                if (op.getStatus().equalsIgnoreCase("ready")) {
                    WorkflowStepCompleter.stepSucceded(stepId);
                    done = true;
                } else if (op.getStatus().equalsIgnoreCase("error")) {
                    WorkflowStepCompleter.stepFailed(stepId, op.getServiceError());
                    done = true;
                }
            }
        }
    } catch (InterruptedException ex) {
        WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
    }
}
Also used : InitiatorOperation(com.emc.storageos.computesystemcontroller.impl.InitiatorCompleter.InitiatorOperation) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare)

Example 82 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class ComputeSystemControllerImpl method updateExportGroup.

public void updateExportGroup(URI exportGroup, Map<URI, Integer> newVolumesMap, Set<URI> addedClusters, Set<URI> removedClusters, Set<URI> adedHosts, Set<URI> removedHosts, Set<URI> addedInitiators, Set<URI> removedInitiators, String stepId) throws Exception {
    Map<URI, Integer> addedBlockObjects = new HashMap<URI, Integer>();
    Map<URI, Integer> removedBlockObjects = new HashMap<URI, Integer>();
    try {
        ExportGroup exportGroupObject = _dbClient.queryObject(ExportGroup.class, exportGroup);
        ExportUtils.getAddedAndRemovedBlockObjects(newVolumesMap, exportGroupObject, addedBlockObjects, removedBlockObjects);
        BlockExportController blockController = getController(BlockExportController.class, BlockExportController.EXPORT);
        Operation op = _dbClient.createTaskOpStatus(ExportGroup.class, exportGroup, stepId, ResourceOperationTypeEnum.UPDATE_EXPORT_GROUP);
        exportGroupObject.getOpStatus().put(stepId, op);
        _dbClient.updateObject(exportGroupObject);
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_026);
        blockController.exportGroupUpdate(exportGroup, addedBlockObjects, removedBlockObjects, addedClusters, removedClusters, adedHosts, removedHosts, addedInitiators, removedInitiators, stepId);
    // No code should be added following the call to the block controller to preserve rollback integrity
    } catch (Exception ex) {
        _log.error("Exception occured while updating export group {}", exportGroup, ex);
        // Clean up any pending tasks
        ExportTaskCompleter taskCompleter = new ExportUpdateCompleter(exportGroup, addedBlockObjects, removedBlockObjects, addedInitiators, removedInitiators, adedHosts, removedHosts, addedClusters, removedClusters, stepId);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(ex);
        taskCompleter.error(_dbClient, serviceError);
        // Fail the step
        WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockExportController(com.emc.storageos.volumecontroller.BlockExportController) ExportTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter) ExportUpdateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportUpdateCompleter) HashMap(java.util.HashMap) InitiatorOperation(com.emc.storageos.computesystemcontroller.impl.InitiatorCompleter.InitiatorOperation) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

Example 83 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method deleteBlockBootVolume.

/**
 * Deactivates or deletes the boot volume
 *
 * @param hostId
 *            {@link URI} hostId URI
 * @param volumeDescriptors
 *            {@link List<VolumeDescriptor>} list of boot volumes to delete
 * @param stepId
 *            {@link String} step id
 */
public void deleteBlockBootVolume(URI hostId, List<VolumeDescriptor> volumeDescriptors, String stepId) {
    log.info("deleteBlockBootVolume");
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null) {
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        String task = stepId;
        URI bootVolumeId = getBootVolumeIdFromDescriptors(volumeDescriptors, host);
        Volume bootVolume = _dbClient.queryObject(Volume.class, bootVolumeId);
        if (bootVolume == null) {
            // No boot volume found, so it was already deleted.
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        Operation op = _dbClient.createTaskOpStatus(Volume.class, bootVolume.getId(), task, ResourceOperationTypeEnum.DELETE_BLOCK_VOLUME);
        bootVolume.getOpStatus().put(task, op);
        _dbClient.updateObject(bootVolume);
        final String workflowKey = "deleteVolumes";
        if (!WorkflowService.getInstance().hasWorkflowBeenCreated(task, workflowKey)) {
            blockOrchestrationController.deleteVolumes(volumeDescriptors, task);
            // Mark this workflow as created/executed so we don't do it
            // again on retry/resume
            WorkflowService.getInstance().markWorkflowBeenCreated(task, workflowKey);
        }
    } catch (Exception exception) {
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToDeactivateHost(host != null ? host.getHostName() : hostId.toString(), exception);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 84 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class WorkflowService method resumeWorkflow.

/**
 * Resumes a suspended workflow.
 * @preq none
 * @brief Resumes a suspended workflow
 * @param uri - URI of the suspended workflow.
 * @return - No data returned in response body
 */
@PUT
@Path("/{id}/resume")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public TaskResourceRep resumeWorkflow(@PathParam("id") URI uri) {
    Workflow workflow = queryResource(uri);
    if (userIsOnlyTenantAdmin()) {
        // User is only tenant admin so only allow resume on workflows for that tenant.
        if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
            throw APIException.badRequests.userNotAuthorizedForWorkflow();
        }
    }
    verifySuspendedWorkflow(workflow);
    String taskId = UUID.randomUUID().toString();
    Operation op = initTaskStatus(_dbClient, workflow, taskId, Operation.Status.pending, ResourceOperationTypeEnum.WORKFLOW_RESUME);
    getController().resumeWorkflow(uri, taskId);
    return toTask(workflow, taskId, op);
}
Also used : Workflow(com.emc.storageos.db.client.model.Workflow) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 85 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class WorkflowService method initTaskStatus.

/**
 * Convenience method for initializing a task object with a status
 *
 * @param workflow export group
 * @param task task ID
 * @param status status to initialize with
 * @param opType operation type
 * @return operation object
 */
protected static Operation initTaskStatus(DbClient dbClient, Workflow workflow, String task, Operation.Status status, ResourceOperationTypeEnum opType) {
    if (workflow.getOpStatus() == null) {
        workflow.setOpStatus(new OpStatusMap());
    }
    Operation op = new Operation();
    op.setResourceType(opType);
    if (status == Operation.Status.ready) {
        op.ready();
    }
    dbClient.createTaskOpStatus(Workflow.class, workflow.getId(), task, op);
    return op;
}
Also used : OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation)

Aggregations

Operation (com.emc.storageos.db.client.model.Operation)272 URI (java.net.URI)114 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)105 Path (javax.ws.rs.Path)105 Produces (javax.ws.rs.Produces)103 Volume (com.emc.storageos.db.client.model.Volume)93 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)92 ArrayList (java.util.ArrayList)83 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)70 Consumes (javax.ws.rs.Consumes)70 NamedURI (com.emc.storageos.db.client.model.NamedURI)68 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)68 POST (javax.ws.rs.POST)67 TaskList (com.emc.storageos.model.TaskList)59 FileShare (com.emc.storageos.db.client.model.FileShare)56 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)49 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)40 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)36 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)35 ControllerException (com.emc.storageos.volumecontroller.ControllerException)35