Search in sources :

Example 11 with Workflow

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;
    }
}
Also used : ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException) FunctionalAPIActionFailedException_Exception(com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FunctionalAPIInternalError_Exception(com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RecoverPointException(com.emc.storageos.recoverpoint.exceptions.RecoverPointException) Random(java.util.Random) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) VolumeVpoolChangeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeVpoolChangeTaskCompleter) RPCGProtectionTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGProtectionTaskCompleter) HashSet(java.util.HashSet)

Example 12 with Workflow

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;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Workflow(com.emc.storageos.workflow.Workflow) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 13 with Workflow

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) OsInstallCompleter(com.emc.storageos.imageservercontroller.OsInstallCompleter) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 14 with Workflow

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);
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) URI(java.net.URI) ComputeImageServerCompleter(com.emc.storageos.imageservercontroller.ComputeImageServerCompleter) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 15 with Workflow

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ComputeImageCompleter(com.emc.storageos.imageservercontroller.ComputeImageCompleter) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) Workflow(com.emc.storageos.workflow.Workflow) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)

Aggregations

Workflow (com.emc.storageos.workflow.Workflow)285 URI (java.net.URI)204 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)171 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)127 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)126 ControllerException (com.emc.storageos.volumecontroller.ControllerException)126 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)124 ArrayList (java.util.ArrayList)123 WorkflowException (com.emc.storageos.workflow.WorkflowException)119 NamedURI (com.emc.storageos.db.client.model.NamedURI)102 Volume (com.emc.storageos.db.client.model.Volume)76 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)72 HashMap (java.util.HashMap)66 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)65 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)61 ExportMask (com.emc.storageos.db.client.model.ExportMask)54 ExportTaskCompleter (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter)54 List (java.util.List)54 BlockObject (com.emc.storageos.db.client.model.BlockObject)41 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)41