use of com.emc.storageos.workflow.Workflow in project coprhd-controller by CoprHD.
the class RPDeviceController method updateApplication.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.protectioncontroller.RPController#updateApplication(java.net.URI,
* com.emc.storageos.volumecontroller.ApplicationAddVolumeList, java.util.List, java.net.URI, java.lang.String)
*/
@Override
public void updateApplication(URI systemURI, ApplicationAddVolumeList addVolList, List<URI> removeVolumeURIs, URI applicationId, String taskId) {
// get all source and target devices
// for remove volumes source and targets can be processed in the same step
// for add volumes, split up volumes into source and target
// assign a different replication group name for target volumes so they don't end up in the same group as source
// volumes
// create one step for remove volumes and add source volumes and a separate step for add target volumes
TaskCompleter completer = null;
try {
Set<URI> impactedCGs = new HashSet<URI>();
List<URI> allRemoveVolumes = new ArrayList<URI>();
Set<URI> removeVolumeSet = new HashSet<URI>();
if (removeVolumeURIs != null && !removeVolumeURIs.isEmpty()) {
// get source and target volumes to be removed from the application
removeVolumeSet = RPHelper.getReplicationSetVolumes(removeVolumeURIs, _dbClient);
for (URI removeUri : removeVolumeSet) {
Volume removeVol = _dbClient.queryObject(Volume.class, removeUri);
URI cguri = removeVol.getConsistencyGroup();
impactedCGs.add(cguri);
addBackendVolumes(removeVol, false, allRemoveVolumes, null);
}
}
Set<URI> vplexVolumes = new HashSet<URI>();
Set<URI> addVolumeSet = new HashSet<URI>();
ApplicationAddVolumeList addSourceVols = new ApplicationAddVolumeList();
ApplicationAddVolumeList addTargetVols = new ApplicationAddVolumeList();
boolean existingSnapOrClone = false;
URI protectionSystemId = null;
ProtectionSystem protectionSystem = null;
Set<String> volumeWWNs = new HashSet<String>();
Volume aSrcVolume = null;
if (addVolList != null && addVolList.getVolumes() != null && !addVolList.getVolumes().isEmpty()) {
URI addVolCg = null;
// get source and target volumes to be added the application
addVolumeSet = RPHelper.getReplicationSetVolumes(addVolList.getVolumes(), _dbClient);
// split up add volumes list by source and target
List<URI> allAddSourceVolumes = new ArrayList<URI>();
List<URI> allAddTargetVolumes = new ArrayList<URI>();
for (URI volUri : addVolumeSet) {
Volume vol = _dbClient.queryObject(Volume.class, volUri);
if (protectionSystemId == null) {
protectionSystemId = vol.getProtectionController();
}
URI cguri = vol.getConsistencyGroup();
if (addVolCg == null && cguri != null) {
addVolCg = cguri;
}
impactedCGs.add(cguri);
if (vol.checkPersonality(Volume.PersonalityTypes.SOURCE.name())) {
addBackendVolumes(vol, true, allAddSourceVolumes, vplexVolumes);
aSrcVolume = vol;
} else if (vol.checkPersonality(Volume.PersonalityTypes.TARGET.name())) {
addBackendVolumes(vol, true, allAddTargetVolumes, vplexVolumes);
volumeWWNs.add(RPHelper.getRPWWn(vol.getId(), _dbClient));
}
}
if (protectionSystemId != null) {
protectionSystem = _dbClient.queryObject(ProtectionSystem.class, protectionSystemId);
}
addSourceVols.setConsistencyGroup(addVolCg);
addSourceVols.setReplicationGroupName(addVolList.getReplicationGroupName());
addSourceVols.setVolumes(allAddSourceVolumes);
String targetReplicationGroupName = addVolList.getReplicationGroupName() + REPLICATION_GROUP_RPTARGET_SUFFIX;
addTargetVols.setConsistencyGroup(addVolCg);
addTargetVols.setReplicationGroupName(targetReplicationGroupName);
addTargetVols.setVolumes(allAddTargetVolumes);
// if there are any target clones or snapshots, need to create a bookmark and enable image access
List<Volume> existingVols = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, AlternateIdConstraint.Factory.getVolumeByReplicationGroupInstance(targetReplicationGroupName));
for (Volume existingVol : existingVols) {
if (existingVol.getFullCopies() != null && !existingVol.getFullCopies().isEmpty()) {
existingSnapOrClone = true;
break;
} else if (ControllerUtils.checkIfVolumeHasSnapshotSession(existingVol.getId(), _dbClient)) {
existingSnapOrClone = true;
break;
} else if (ControllerUtils.checkIfVolumeHasSnapshot(existingVol, _dbClient)) {
existingSnapOrClone = true;
break;
}
}
}
// Get a new workflow to execute the volume group update.
Workflow workflow = _workflowService.getNewWorkflow(this, BlockDeviceController.UPDATE_VOLUMES_FOR_APPLICATION_WS_NAME, false, taskId);
// create the completer add the steps and execute the plan.
completer = new VolumeGroupUpdateTaskCompleter(applicationId, addVolumeSet, removeVolumeSet, impactedCGs, taskId);
String waitFor = null;
if (existingSnapOrClone) {
// A temporary date/time stamp for the bookmark name
String bookmarkName = VIPR_SNAPSHOT_PREFIX + (new Random()).nextInt();
// Step 1 - Create a RP bookmark
String rpWaitFor = addCreateBookmarkStep(workflow, new ArrayList<URI>(), protectionSystem, bookmarkName, volumeWWNs, false, waitFor);
// Lock CG for the duration of the workflow so enable and disable can complete before another workflow
// tries to enable image
// access
List<String> locks = new ArrayList<String>();
String lockName = ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, aSrcVolume.getConsistencyGroup(), protectionSystem.getId());
if (null != lockName) {
locks.add(lockName);
acquireWorkflowLockOrThrow(workflow, locks);
}
// Step 2 - Enable image access
waitFor = addEnableImageAccessForCreateReplicaStep(workflow, protectionSystem, null, new ArrayList<URI>(), bookmarkName, volumeWWNs, rpWaitFor);
}
// add steps for add source and remove vols
waitFor = _blockDeviceController.addStepsForUpdateApplication(workflow, addSourceVols, allRemoveVolumes, waitFor, taskId);
// add steps for add target vols
waitFor = _blockDeviceController.addStepsForUpdateApplication(workflow, addTargetVols, null, waitFor, taskId);
if (existingSnapOrClone) {
waitFor = addDisableImageAccessForCreateReplicaStep(workflow, protectionSystem, null, new ArrayList<URI>(), volumeWWNs, waitFor);
}
if (!vplexVolumes.isEmpty()) {
_vplexDeviceController.addStepsForImportClonesOfApplicationVolumes(workflow, waitFor, new ArrayList<URI>(vplexVolumes), taskId);
}
_log.info("Executing workflow plan {}", BlockDeviceController.UPDATE_VOLUMES_FOR_APPLICATION_WS_NAME);
String successMessage = String.format("Update application successful for %s", applicationId.toString());
workflow.executePlan(completer, successMessage);
} catch (Exception e) {
_log.error("Exception while updating the application", e);
if (completer != null) {
completer.error(_dbClient, DeviceControllerException.exceptions.failedToUpdateVolumesFromAppication(applicationId.toString(), e.getMessage()));
}
throw e;
}
}
use of com.emc.storageos.workflow.Workflow in project coprhd-controller by CoprHD.
the class RPDeviceController method addStepsForRestoreVolume.
@Override
public String addStepsForRestoreVolume(Workflow workflow, String waitFor, URI storage, URI pool, URI volume, URI snapshot, Boolean updateOpStatus, String syncDirection, String taskId, BlockSnapshotRestoreCompleter completer) throws InternalException {
BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshot);
if (snap != null && NullColumnValueGetter.isNotNullValue(snap.getTechnologyType())) {
Volume vol = _dbClient.queryObject(Volume.class, volume);
if (vol != null) {
if (snap.getTechnologyType().equals(TechnologyType.RP.toString())) {
// Perform an RP controller restore operation only if restoring from an RP BlockSnapshot.
ProtectionSystem rpSystem = null;
rpSystem = _dbClient.queryObject(ProtectionSystem.class, vol.getProtectionController());
if (rpSystem == null) {
// Verify non-null storage device returned from the database client.
throw DeviceControllerExceptions.recoverpoint.failedConnectingForMonitoring(vol.getProtectionController());
}
String stepId = workflow.createStepId();
Workflow.Method restoreVolumeFromSnapshotMethod = new Workflow.Method(METHOD_RESTORE_VOLUME_STEP, rpSystem.getId(), storage, snapshot, completer);
waitFor = workflow.createStep(null, "Restore volume from RP snapshot: " + volume.toString(), waitFor, rpSystem.getId(), rpSystem.getSystemType(), this.getClass(), restoreVolumeFromSnapshotMethod, rollbackMethodNullMethod(), stepId);
_log.info(String.format("Created workflow step to restore RP volume %s from snapshot %s.", volume, snapshot));
}
}
}
return waitFor;
}
use of com.emc.storageos.workflow.Workflow in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method installOperatingSystem.
/**
* Install OS
* @param task {@link AsyncTask}
* @param computeImageJob {@link URI} compute imageJob id
* @throws InternalException
*/
@Override
public void installOperatingSystem(AsyncTask task, URI computeImageJob) throws InternalException {
log.info("installOperatingSystem");
Host host = dbClient.queryObject(Host.class, task._id);
ComputeElement ce = dbClient.queryObject(ComputeElement.class, host.getComputeElement());
ComputeSystem cs = dbClient.queryObject(ComputeSystem.class, ce.getComputeSystem());
ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, computeImageJob);
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
ComputeImage img = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
TaskCompleter completer = null;
try {
completer = new OsInstallCompleter(host.getId(), task._opId, job.getId(), EVENT_SERVICE_TYPE);
boolean imageServerVerified = verifyImageServer(imageServer);
if (!imageServerVerified) {
throw ImageServerControllerException.exceptions.imageServerNotSetup("Can't install operating system: " + imageServerErrorMsg);
}
Workflow workflow = workflowService.getNewWorkflow(this, OS_INSTALL_WF, true, task._opId);
String waitFor = null;
waitFor = workflow.createStep(OS_INSTALL_IMAGE_SERVER_CHECK_STEP, "image server check pre os install", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("preOsInstallImageServerCheck", job.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
waitFor = workflow.createStep(OS_INSTALL_PREPARE_PXE_STEP, "prepare pxe boot", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("preparePxeBootMethod", job.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
String prepStepId = workflow.createStepId();
waitFor = computeDeviceController.addStepsPreOsInstall(workflow, waitFor, cs.getId(), host.getId(), prepStepId);
waitFor = workflow.createStep(OS_INSTALL_WAIT_FOR_FINISH_STEP, "wait for os install to finish", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("waitForFinishMethod", job.getId(), host.getHostName()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
waitFor = computeDeviceController.addStepsPostOsInstall(workflow, waitFor, cs.getId(), ce.getId(), host.getId(), prepStepId, job.getVolumeId());
workflow.executePlan(completer, SUCCESS);
} catch (Exception e) {
log.error("installOperatingSystem caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
use of com.emc.storageos.workflow.Workflow 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.workflow.Workflow 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);
}
}
Aggregations