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));
}
}
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));
}
}
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);
}
}
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);
}
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;
}
Aggregations