use of com.emc.storageos.volumecontroller.TaskCompleter in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method verifyImageServerAndImportExistingImages.
/**
* Method to verify and import images on the imageserver
*
* @param task {@link AsyncTask} instance
* @param opName operation Name
*/
@Override
public void verifyImageServerAndImportExistingImages(AsyncTask task, String opName) {
TaskCompleter completer = null;
log.info("Verifying imageServer and importing any existing images on to the server");
try {
URI computeImageServerID = task._id;
completer = new ComputeImageServerCompleter(computeImageServerID, task._opId, OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, EVENT_SERVICE_TYPE);
Workflow workflow = workflowService.getNewWorkflow(this, IMAGESERVER_VERIFY_IMPORT_IMAGE_WF, true, task._opId);
workflow.createStep(IMAGESERVER_VERIFICATION_STEP, String.format("Verfiying ImageServer %s", computeImageServerID), null, computeImageServerID, computeImageServerID.toString(), this.getClass(), new Workflow.Method("verifyComputeImageServer", computeImageServerID), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
List<ComputeImage> computeImageList = getAllComputeImages();
if (!CollectionUtils.isEmpty(computeImageList)) {
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, computeImageServerID);
for (ComputeImage computeImage : computeImageList) {
if (null == imageServer.getComputeImages() || !imageServer.getComputeImages().contains(computeImage.getId().toString())) {
StringBuilder msg = new StringBuilder("Importing image ");
msg.append(computeImage.getLabel()).append(" on to imageServer - ");
msg.append(imageServer.getImageServerIp()).append(".");
workflow.createStep(IMAGESERVER_IMPORT_IMAGES_STEP, msg.toString(), IMAGESERVER_VERIFICATION_STEP, computeImageServerID, computeImageServerID.toString(), this.getClass(), new Workflow.Method("importImageMethod", computeImage.getId(), imageServer, opName), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
}
}
workflow.executePlan(completer, SUCCESS);
} catch (Exception ex) {
log.error("Unexpected exception waiting for finish: " + ex.getMessage(), ex);
}
}
use of com.emc.storageos.volumecontroller.TaskCompleter in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method deleteImage.
/**
* Delete image from all available imageServers
*
* @param task {@link AsyncTask} instance
*/
@Override
public void deleteImage(AsyncTask task) throws InternalException {
log.info("deleteImage " + task._id);
URI ciId = task._id;
TaskCompleter completer = null;
try {
completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.DELETE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
Workflow workflow = workflowService.getNewWorkflow(this, DELETE_IMAGE_WF, true, task._opId);
List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
for (URI imageServerId : ids) {
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
if (imageServer.getComputeImages() != null && imageServer.getComputeImages().contains(ciId.toString())) {
boolean imageServerVerified = verifyImageServer(imageServer);
if (!imageServerVerified) {
throw ImageServerControllerException.exceptions.imageServerNotSetup("Can't delete image: " + imageServerErrorMsg);
}
workflow.createStep(DELETE_IMAGE_STEP, String.format("removing image %s", ciId), null, ciId, ciId.toString(), this.getClass(), new Workflow.Method("deleteImageMethod", ciId, imageServer.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
// So this cleanup needs to be performed.
if (imageServer.getFailedComputeImages() != null && imageServer.getFailedComputeImages().contains(ciId.toString())) {
imageServer.getFailedComputeImages().remove(ciId.toString());
dbClient.updateObject(imageServer);
}
}
workflow.executePlan(completer, SUCCESS);
} catch (Exception e) {
log.error("deleteImage caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
use of com.emc.storageos.volumecontroller.TaskCompleter in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method importImageToServers.
/**
* Import image to all available imageServer
*
* @param task {@link AsyncTask} instance
*/
@Override
public void importImageToServers(AsyncTask task) throws InternalException {
log.info("importImage");
URI ciId = task._id;
boolean wfHasSteps = false;
Workflow workflow = workflowService.getNewWorkflow(this, IMPORT_IMAGE_WF, true, task._opId);
TaskCompleter completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.CREATE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
try {
List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
for (URI imageServerId : ids) {
log.info("import to server:" + imageServerId.toString());
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
if (imageServer.getComputeImages() == null || !imageServer.getComputeImages().contains(ciId.toString())) {
log.info("verify Image Server");
String verifyServerStepId = workflow.createStep(IMAGESERVER_VERIFICATION_STEP, String.format("Verifying ImageServer %s", imageServerId), null, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("verifyComputeImageServer", imageServerId), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
workflow.createStep(IMPORT_IMAGE_TO_SERVER_STEP, String.format("Importing image for %s", imageServerId), verifyServerStepId, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("importImageMethod", ciId, imageServer, null), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
wfHasSteps = true;
}
}
if (wfHasSteps) {
workflow.executePlan(completer, SUCCESS);
}
} catch (Exception e) {
log.error("importImage caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
use of com.emc.storageos.volumecontroller.TaskCompleter in project coprhd-controller by CoprHD.
the class NetworkDeviceController method zoneRollback.
/**
* Rollback any of the zoning operations.
*
* @param exportGroupURI
* -- The ExportGroup URI
* @param contextKey
* -- The context which indicates what zones were configured on the device.
* @param taskId
* -- String task identifier for WorkflowTaskCompleter.
* @return
* @throws DeviceControllerException
*/
public boolean zoneRollback(URI exportGroupURI, String contextKey, String taskId) throws DeviceControllerException {
TaskCompleter taskCompleter = null;
try {
NetworkFCContext context = (NetworkFCContext) WorkflowService.getInstance().loadStepData(contextKey);
if (context == null) {
_log.warn("No zone rollback information for Step: " + contextKey + " , Export Group: " + exportGroupURI.toString() + ", and Task: " + taskId + ". The zoning step either did not complete or encountered an error.");
WorkflowStepCompleter.stepSucceded(taskId);
return true;
}
logZones(context.getZoneInfos());
WorkflowStepCompleter.stepExecuting(taskId);
_log.info("Beginning zone rollback");
_log.info("context.isAddingZones -{}", context.isAddingZones());
// Determine what needs to be rolled back.
List<NetworkFCZoneInfo> lastReferenceZoneInfo = new ArrayList<NetworkFCZoneInfo>();
List<NetworkFCZoneInfo> rollbackList = new ArrayList<NetworkFCZoneInfo>();
for (NetworkFCZoneInfo info : context.getZoneInfos()) {
if (info.canBeRolledBack()) {
// We should not blindly set last reference to true, removed code which does that earlier.
rollbackList.add(info);
} else {
// Even though we cannot rollback the zone (because we didn't create it, it previously existed,
// must remove the FCZoneReference that we created.
deleteFCZoneReference(info);
}
}
// Update the zone infos with the correct lastRef setting for those zones that can be rolled back
_networkScheduler.determineIfLastZoneReferences(rollbackList);
taskCompleter = new ZoneReferencesRemoveCompleter(NetworkUtil.getFCZoneReferences(rollbackList), context.isAddingZones(), taskId);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_020);
// Changed this parameter to true, so that the last reference validation runs all the time in placeZones()
BiosCommandResult result = addRemoveZones(exportGroupURI, rollbackList, true);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_021);
if (result.isCommandSuccess() && !lastReferenceZoneInfo.isEmpty()) {
_log.info("There seems to be last reference zones that were removed, clean those zones from the zoning map.");
updateZoningMap(lastReferenceZoneInfo, exportGroupURI, null);
}
completeWorkflowState(taskCompleter, taskId, "ZoneRollback", result, null);
return result.isCommandSuccess();
} catch (Exception ex) {
_log.error("Exception occurred while doing zone rollback", ex);
ServiceError svcError = NetworkDeviceControllerException.errors.zoneRollbackFailedExc(exportGroupURI.toString(), ex);
taskCompleter.error(_dbClient, svcError);
WorkflowStepCompleter.stepFailed(taskId, svcError);
return false;
}
}
use of com.emc.storageos.volumecontroller.TaskCompleter in project coprhd-controller by CoprHD.
the class NetworkDeviceController method zoneExportRemoveInitiators.
/**
* This will remove zones for all the initiators in the NetworkZoningParam zoneMap.
* Note: these arguments (except stepId) must match zoneExportRemoveInitiatorsMethod above.
* This routine executes as a Workflow Step.
*
* @param zoningParams -- List of NetworkZoningParam zoning parameter blocks corresponding to ExportMasks
* @param stepId -- step id in Workflow
* @return
* @throws ControllerException
*/
public boolean zoneExportRemoveInitiators(List<NetworkZoningParam> zoningParams, String stepId) throws ControllerException {
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(stepId);
boolean isOperationSuccessful = false;
TaskCompleter taskCompleter = null;
if (zoningParams.isEmpty()) {
_log.info("zoningParams is empty, returning");
WorkflowStepCompleter.stepSucceded(stepId);
return true;
}
NetworkFCContext context = new NetworkFCContext();
boolean status = false;
URI exportGroupId = zoningParams.get(0).getExportGroupId();
URI virtualArray = zoningParams.get(0).getVirtualArray();
_log.info(String.format("Entering zoneExportRemoveInitiators for ExportGroup: %s", zoningParams.get(0).getExportGroupDisplay()));
try {
if (!checkZoningRequired(stepId, virtualArray)) {
return true;
}
context.setAddingZones(false);
// Get the zoning targets to be removed.
List<NetworkFCZoneInfo> zoneInfos = _networkScheduler.getZoningRemoveTargets(zoningParams, null);
context.getZoneInfos().addAll(zoneInfos);
logZones(zoneInfos);
// If there are no zones to do, we were successful.
if (context.getZoneInfos().isEmpty()) {
isOperationSuccessful = true;
WorkflowStepCompleter.stepSucceded(stepId);
return true;
}
// Create a local completer to handle DB cleanup in the case of failure.
taskCompleter = new ZoneReferencesRemoveCompleter(NetworkUtil.getFCZoneReferences(context.getZoneInfos()), true, stepId);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_024);
// Now call removeZones to remove all the required zones.
BiosCommandResult result = addRemoveZones(exportGroupId, context.getZoneInfos(), true);
status = result.isCommandSuccess();
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_025);
// Update the workflow state.
completeWorkflowState(taskCompleter, stepId, "zoneExportRemoveInitiators", result, null);
if (result.isCommandSuccess()) {
isOperationSuccessful = true;
}
return status;
} catch (Exception ex) {
_log.error("Exception zoning remove initiators", ex);
ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportRemoveInitiatorsFailed(ex.getMessage(), ex);
taskCompleter.error(_dbClient, svcError);
WorkflowStepCompleter.stepFailed(stepId, svcError);
return status;
} finally {
// clean up the zoning map too if the result is success or a rollback
if (isOperationSuccessful || isRollback) {
removeInitiatorsFromZoningMap(zoningParams);
}
}
}
Aggregations