Search in sources :

Example 1 with VolumeGroupUpdateTaskCompleter

use of com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter 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 2 with VolumeGroupUpdateTaskCompleter

use of com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter in project coprhd-controller by CoprHD.

the class VPlexDeviceController method updateVolumeGroup.

@Override
public void updateVolumeGroup(URI vplexURI, ApplicationAddVolumeList addVolList, List<URI> removeVolumeList, URI volumeGroup, String opId) throws InternalException {
    _log.info("Update volume group {}", volumeGroup);
    TaskCompleter completer = null;
    List<URI> addVols = null;
    String waitFor = null;
    // Get a new workflow to execute the volume group update.
    Workflow workflow = _workflowService.getNewWorkflow(this, UPDATE_VOLUMEGROUP_WF_NAME, false, opId);
    Set<URI> cgs = new HashSet<URI>();
    try {
        List<URI> allRemoveBEVolumes = new ArrayList<URI>();
        if (removeVolumeList != null && !removeVolumeList.isEmpty()) {
            _log.info("Creating steps for removing volumes from the volume group");
            for (URI voluri : removeVolumeList) {
                Volume vol = getDataObject(Volume.class, voluri, _dbClient);
                if (vol == null || vol.getInactive()) {
                    _log.info(String.format("The volume: %s has been deleted. Skip it.", voluri));
                    continue;
                }
                cgs.add(vol.getConsistencyGroup());
                StringSet backends = vol.getAssociatedVolumes();
                if (backends == null) {
                    _log.info(String.format("The volume: %s do not have backend volumes. Skip it.", vol.getLabel()));
                    continue;
                }
                for (String backendId : backends) {
                    allRemoveBEVolumes.add(URI.create(backendId));
                }
            }
        }
        List<URI> allAddBEVolumes = new ArrayList<URI>();
        ApplicationAddVolumeList addBEVolList = new ApplicationAddVolumeList();
        if (addVolList != null && addVolList.getVolumes() != null && !addVolList.getVolumes().isEmpty()) {
            _log.info("Creating steps for adding volumes to the volume group");
            addVols = addVolList.getVolumes();
            for (URI addVol : addVols) {
                Volume addVplexVol = getDataObject(Volume.class, addVol, _dbClient);
                if (addVplexVol == null || addVplexVol.getInactive()) {
                    _log.info(String.format("The volume: %s has been deleted. Skip it.", addVol));
                    continue;
                }
                cgs.add(addVplexVol.getConsistencyGroup());
                StringSet backends = addVplexVol.getAssociatedVolumes();
                if (backends == null) {
                    _log.info(String.format("The volume: %s do not have backend volumes. Skip it.", addVol));
                    continue;
                }
                for (String backendId : backends) {
                    URI backUri = URI.create(backendId);
                    Volume backVol = getDataObject(Volume.class, backUri, _dbClient);
                    if (backVol != null && !backVol.getInactive()) {
                        allAddBEVolumes.add(backUri);
                    }
                }
            }
        }
        completer = new VolumeGroupUpdateTaskCompleter(volumeGroup, addVols, removeVolumeList, cgs, opId);
        addBEVolList.setVolumes(allAddBEVolumes);
        addBEVolList.setReplicationGroupName(addVolList.getReplicationGroupName());
        addBEVolList.setConsistencyGroup(addVolList.getConsistencyGroup());
        // add steps for add source and remove vols
        waitFor = _blockDeviceController.addStepsForUpdateApplication(workflow, addBEVolList, allRemoveBEVolumes, waitFor, opId);
        addStepsForImportClonesOfApplicationVolumes(workflow, waitFor, addVolList.getVolumes(), opId);
        // Finish up and execute the plan.
        _log.info("Executing workflow plan {}", UPDATE_VOLUMEGROUP_WF_NAME);
        String successMessage = String.format("Update volume group successful for %s", volumeGroup.toString());
        workflow.executePlan(completer, successMessage);
    } catch (Exception e) {
        _log.error("Exception while updating the volume group", e);
        DeviceControllerException ex = DeviceControllerException.exceptions.failedToUpdateVolumesFromAppication(volumeGroup.toString(), e.getMessage());
        if (completer != null) {
            completer.error(_dbClient, ex);
        } else {
            throw ex;
        }
    }
}
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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Volume(com.emc.storageos.db.client.model.Volume) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) StringSet(com.emc.storageos.db.client.model.StringSet) ExportTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportTaskCompleter) MigrationTaskCompleter(com.emc.storageos.vplexcontroller.completers.MigrationTaskCompleter) CloneTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.CloneTaskCompleter) MigrationOperationTaskCompleter(com.emc.storageos.vplexcontroller.completers.MigrationOperationTaskCompleter) CacheStatusTaskCompleter(com.emc.storageos.vplexcontroller.completers.CacheStatusTaskCompleter) VplexMirrorTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VplexMirrorTaskCompleter) VolumeTaskCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter) VolumeGroupUpdateTaskCompleter(com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) WorkflowTaskCompleter(com.emc.storageos.workflow.WorkflowTaskCompleter) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Aggregations

NamedURI (com.emc.storageos.db.client.model.NamedURI)2 Volume (com.emc.storageos.db.client.model.Volume)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)2 ApplicationAddVolumeList (com.emc.storageos.volumecontroller.ApplicationAddVolumeList)2 ControllerException (com.emc.storageos.volumecontroller.ControllerException)2 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)2 VolumeGroupUpdateTaskCompleter (com.emc.storageos.vplexcontroller.completers.VolumeGroupUpdateTaskCompleter)2 Workflow (com.emc.storageos.workflow.Workflow)2 WorkflowException (com.emc.storageos.workflow.WorkflowException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 FunctionalAPIActionFailedException_Exception (com.emc.fapiclient.ws.FunctionalAPIActionFailedException_Exception)1 FunctionalAPIInternalError_Exception (com.emc.fapiclient.ws.FunctionalAPIInternalError_Exception)1 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)1 ProtectionSystem (com.emc.storageos.db.client.model.ProtectionSystem)1