Search in sources :

Example 1 with ExportGroup

use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.

the class RPDeviceController method addExportRemoveVolumesSteps.

/**
 * Add the steps that will remove the volumes from the export group
 * TODO: This could stand to be refactored to be simpler.
 *
 * @param workflow
 *            workflow object
 * @param waitFor
 *            step that these steps are dependent on
 * @param filteredSourceVolumeDescriptors
 *            volumes to act on
 * @return "waitFor" step that future steps should wait on
 * @throws InternalException
 */
private String addExportRemoveVolumesSteps(Workflow workflow, String waitFor, List<VolumeDescriptor> filteredSourceVolumeDescriptors) throws InternalException {
    _log.info("Adding steps to remove volumes from export groups.");
    String returnStep = waitFor;
    Set<URI> volumeURIs = RPHelper.getVolumesToDelete(VolumeDescriptor.getVolumeURIs(filteredSourceVolumeDescriptors), _dbClient);
    _log.info(String.format("Following volume(s) will be unexported from their RP export groups :  [%s]", Joiner.on("--").join(volumeURIs)));
    Map<URI, RPExport> rpExports = new HashMap<URI, RPExport>();
    for (URI volumeURI : volumeURIs) {
        Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
        if (volume == null) {
            _log.warn("Could not load volume with given URI: " + volumeURI);
            continue;
        }
        // get the protection system for this volume
        URI rpSystemId = volume.getProtectionController();
        ProtectionSystem rpSystem = null;
        if (rpSystemId != null) {
            rpSystem = _dbClient.queryObject(ProtectionSystem.class, rpSystemId);
            if (rpSystem == null || rpSystem.getInactive()) {
                _log.warn("No protection system information found for volume {}. Volume cannot be removed from RP export groups.", volume.getLabel());
                continue;
            }
        }
        // Get the storage controller URI of the volume
        URI storageURI = volume.getStorageController();
        // Get the vpool of the volume
        VirtualPool virtualPool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
        if (VirtualPool.isRPVPlexProtectHASide(virtualPool)) {
            _log.info(String.format("RP+VPLEX protect HA Source Volume [%s] to be removed from RP export group.", volume.getLabel()));
            // the HA side export group only.
            if (volume.getAssociatedVolumes() != null && volume.getAssociatedVolumes().size() == 2) {
                for (String associatedVolURI : volume.getAssociatedVolumes()) {
                    Volume associatedVolume = _dbClient.queryObject(Volume.class, URI.create(associatedVolURI));
                    if (associatedVolume.getVirtualArray().toString().equals(virtualPool.getHaVarrayConnectedToRp())) {
                        ExportGroup exportGroup = getExportGroup(rpSystem, volume.getId(), associatedVolume.getVirtualArray(), associatedVolume.getInternalSiteName());
                        if (exportGroup != null) {
                            _log.info(String.format("Removing volume [%s] from RP export group [%s].", volume.getLabel(), exportGroup.getGeneratedName()));
                        }
                        // Assuming we've found the correct Export Group for this volume, let's
                        // then add the information we need to the rpExports map.
                        addExportGroup(rpExports, exportGroup, volumeURI, storageURI);
                        break;
                    }
                }
            }
        } else if (volume.getAssociatedVolumes() != null && volume.getAssociatedVolumes().size() == 2) {
            for (String associatedVolURI : volume.getAssociatedVolumes()) {
                _log.info(String.format("VPLEX %s Volume [%s] to be removed from RP export group.", volume.getPersonality(), associatedVolURI));
                Volume associatedVolume = _dbClient.queryObject(Volume.class, URI.create(associatedVolURI));
                String internalSiteName = associatedVolume.getInternalSiteName();
                URI virtualArray = associatedVolume.getVirtualArray();
                if (!VirtualPool.vPoolSpecifiesMetroPoint(virtualPool)) {
                    // Only MetroPoint associated volumes will have the internalSiteName set. For VPlex distributed volumes
                    // the parent (virtual volume) internal site name should be used.
                    internalSiteName = volume.getInternalSiteName();
                    // If we are using the parent volume's internal site name, we also need to use the parent volume's virtual array.
                    // Again, only in the case of MetroPoint volumes would we want to use the associated volume's virtual array.
                    virtualArray = volume.getVirtualArray();
                }
                ExportGroup exportGroup = getExportGroup(rpSystem, volume.getId(), virtualArray, internalSiteName);
                if (exportGroup != null) {
                    _log.info(String.format("Removing volume [%s] from RP export group [%s].", volume.getLabel(), exportGroup.getGeneratedName()));
                }
                // Assuming we've found the correct Export Group for this volume, let's
                // then add the information we need to the rpExports map.
                addExportGroup(rpExports, exportGroup, volumeURI, storageURI);
            }
        } else {
            _log.info(String.format("Volume [%s] to be removed from RP export group.", volume.getLabel()));
            // Find the Export Group for this regular RP volume
            ExportGroup exportGroup = getExportGroup(rpSystem, volume.getId(), volume.getVirtualArray(), volume.getInternalSiteName());
            if (exportGroup != null) {
                _log.info(String.format("Removing volume [%s] from RP export group [%s].", volume.getLabel(), exportGroup.getGeneratedName()));
            }
            // Assuming we've found the correct Export Group for this volume, let's
            // then add the information we need to the rpExports map.
            addExportGroup(rpExports, exportGroup, volumeURI, storageURI);
        }
    }
    // Generate the workflow steps for export volume removal and volume deletion
    for (URI exportURI : rpExports.keySet()) {
        _log.info(String.format("RP export group will have these volumes removed: [%s]", Joiner.on(',').join(rpExports.get(exportURI).getVolumes())));
        RPExport rpExport = rpExports.get(exportURI);
        if (!rpExport.getVolumes().isEmpty()) {
            _exportWfUtils.generateExportGroupRemoveVolumes(workflow, STEP_DV_REMOVE_VOLUME_EXPORT, waitFor, rpExport.getStorageSystem(), exportURI, rpExport.getVolumes());
            returnStep = STEP_DV_REMOVE_VOLUME_EXPORT;
        }
    }
    _log.info("Completed adding steps to remove volumes from RP export groups.");
    return returnStep;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) HashMap(java.util.HashMap) Volume(com.emc.storageos.db.client.model.Volume) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem)

Example 2 with ExportGroup

use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.

the class RPDeviceController method exportOrchestrationSteps.

/**
 * @param volumeDescriptors
 *            - Volume descriptors
 * @param rpSystemId
 *            - RP system
 * @param taskId
 *            - task ID
 * @return - True on success, false otherwise
 * @throws InternalException
 */
public boolean exportOrchestrationSteps(List<VolumeDescriptor> volumeDescriptors, URI rpSystemId, String taskId) throws InternalException {
    List<URI> volUris = VolumeDescriptor.getVolumeURIs(volumeDescriptors);
    RPCGExportOrchestrationCompleter completer = new RPCGExportOrchestrationCompleter(volUris, taskId);
    Workflow workflow = null;
    boolean lockException = false;
    Map<URI, Set<URI>> exportGroupVolumesAdded = new HashMap<URI, Set<URI>>();
    exportGroupsCreated = new ArrayList<URI>();
    final String COMPUTE_RESOURCE_CLUSTER = "cluster";
    try {
        final String workflowKey = "rpExportOrchestration";
        if (!WorkflowService.getInstance().hasWorkflowBeenCreated(taskId, workflowKey)) {
            // Generate the Workflow.
            workflow = _workflowService.getNewWorkflow(this, EXPORT_ORCHESTRATOR_WF_NAME, true, taskId);
            // the wait for key returned by previous call
            String waitFor = null;
            ProtectionSystem rpSystem = _dbClient.queryObject(ProtectionSystem.class, rpSystemId);
            // Get the CG Params based on the volume descriptors
            CGRequestParams params = this.getCGRequestParams(volumeDescriptors, rpSystem);
            updateCGParams(params);
            _log.info("Start adding RP Export Volumes steps....");
            // Get the RP Exports from the CGRequestParams object
            Collection<RPExport> rpExports = generateStorageSystemExportMaps(params, volumeDescriptors);
            Map<String, Set<URI>> rpSiteInitiatorsMap = getRPSiteInitiators(rpSystem, rpExports);
            // Acquire all the RP lock keys needed for export before we start assembling the export groups.
            acquireRPLockKeysForExport(taskId, rpExports, rpSiteInitiatorsMap);
            // or create a new one.
            for (RPExport rpExport : rpExports) {
                URI storageSystemURI = rpExport.getStorageSystem();
                String internalSiteName = rpExport.getRpSite();
                URI varrayURI = rpExport.getVarray();
                List<URI> volumes = rpExport.getVolumes();
                List<URI> initiatorSet = new ArrayList<URI>();
                String rpSiteName = (rpSystem.getRpSiteNames() != null) ? rpSystem.getRpSiteNames().get(internalSiteName) : internalSiteName;
                StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
                VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayURI);
                _log.info("--------------------");
                _log.info(String.format("RP Export: StorageSystem = [%s] RPSite = [%s] VirtualArray = [%s]", storageSystem.getLabel(), rpSiteName, varray.getLabel()));
                boolean isJournalExport = rpExport.getIsJournalExport();
                String exportGroupGeneratedName = RPHelper.generateExportGroupName(rpSystem, storageSystem, internalSiteName, varray, isJournalExport);
                // Setup the export group - we may or may not need to create it, but we need to have everything ready in case we do
                ExportGroup exportGroup = RPHelper.createRPExportGroup(exportGroupGeneratedName, varray, _dbClient.queryObject(Project.class, params.getProject()), 0, isJournalExport);
                // Get the initiators of the RP Cluster (all of the RPAs on one side of a configuration)
                Map<String, Map<String, String>> rpaWWNs = RPHelper.getRecoverPointClient(rpSystem).getInitiatorWWNs(internalSiteName);
                if (rpaWWNs == null || rpaWWNs.isEmpty()) {
                    throw DeviceControllerExceptions.recoverpoint.noInitiatorsFoundOnRPAs();
                }
                // Convert to initiator object
                List<Initiator> initiators = new ArrayList<Initiator>();
                for (String rpaId : rpaWWNs.keySet()) {
                    for (Map.Entry<String, String> rpaWWN : rpaWWNs.get(rpaId).entrySet()) {
                        Initiator initiator = ExportUtils.getInitiator(rpaWWN.getKey(), _dbClient);
                        initiators.add(initiator);
                    }
                }
                // We need to find and distill only those RP initiators that correspond to the network of the
                // storage
                // system and
                // that network has front end port from the storage system.
                // In certain lab environments, its quite possible that there are 2 networks one for the storage
                // system
                // FE ports and one for
                // the BE ports.
                // In such configs, RP initiators will be spread across those 2 networks. RP controller does not
                // care
                // about storage system
                // back-end ports, so
                // we will ignore those initiators that are connected to a network that has only storage system back
                // end
                // port connectivity.
                Map<URI, Set<Initiator>> rpNetworkToInitiatorsMap = new HashMap<URI, Set<Initiator>>();
                Set<URI> rpSiteInitiatorUris = rpSiteInitiatorsMap.get(internalSiteName);
                if (rpSiteInitiatorUris != null) {
                    for (URI rpSiteInitiatorUri : rpSiteInitiatorUris) {
                        Initiator rpSiteInitiator = _dbClient.queryObject(Initiator.class, rpSiteInitiatorUri);
                        URI rpInitiatorNetworkURI = getInitiatorNetwork(exportGroup, rpSiteInitiator);
                        if (rpInitiatorNetworkURI != null) {
                            if (rpNetworkToInitiatorsMap.get(rpInitiatorNetworkURI) == null) {
                                rpNetworkToInitiatorsMap.put(rpInitiatorNetworkURI, new HashSet<Initiator>());
                            }
                            rpNetworkToInitiatorsMap.get(rpInitiatorNetworkURI).add(rpSiteInitiator);
                            _log.info(String.format("RP Initiator [%s] found on network: [%s]", rpSiteInitiator.getInitiatorPort(), rpInitiatorNetworkURI.toASCIIString()));
                        } else {
                            _log.info(String.format("RP Initiator [%s] was not found on any network. Excluding from automated exports", rpSiteInitiator.getInitiatorPort()));
                        }
                    }
                }
                // Compute numPaths. This is how its done:
                // We know the RP site and the Network/TransportZone it is on.
                // Determine all the storage ports for the storage array for all the networks they are on.
                // Next, if we find the network for the RP site in the above list, return all the storage ports
                // corresponding to that.
                // For RP we will try and use as many Storage ports as possible.
                Map<URI, List<StoragePort>> initiatorPortMap = getInitiatorPortsForArray(rpNetworkToInitiatorsMap, storageSystemURI, varrayURI, rpSiteName);
                for (URI networkURI : initiatorPortMap.keySet()) {
                    for (StoragePort storagePort : initiatorPortMap.get(networkURI)) {
                        _log.info(String.format("Network : [%s] - Port : [%s]", networkURI.toString(), storagePort.getLabel()));
                    }
                }
                int numPaths = computeNumPaths(initiatorPortMap, varrayURI, storageSystem);
                _log.info("Total paths = " + numPaths);
                // Stems from above comment where we distill the RP network and the initiators in that network.
                List<Initiator> initiatorList = new ArrayList<Initiator>();
                for (URI rpNetworkURI : rpNetworkToInitiatorsMap.keySet()) {
                    if (initiatorPortMap.containsKey(rpNetworkURI)) {
                        initiatorList.addAll(rpNetworkToInitiatorsMap.get(rpNetworkURI));
                    }
                }
                for (Initiator initiator : initiatorList) {
                    initiatorSet.add(initiator.getId());
                }
                // See if the export group already exists
                ExportGroup exportGroupInDB = exportGroupExistsInDB(exportGroup);
                boolean addExportGroupToDB = false;
                if (exportGroupInDB != null) {
                    exportGroup = exportGroupInDB;
                    // If the export already exists, check to see if any of the volumes have already been exported.
                    // No
                    // need to
                    // re-export volumes.
                    List<URI> volumesToRemove = new ArrayList<URI>();
                    for (URI volumeURI : volumes) {
                        if (exportGroup.getVolumes() != null && !exportGroup.getVolumes().isEmpty() && exportGroup.getVolumes().containsKey(volumeURI.toString())) {
                            _log.info(String.format("Volume [%s] already exported to export group [%s], " + "it will be not be re-exported", volumeURI.toString(), exportGroup.getGeneratedName()));
                            volumesToRemove.add(volumeURI);
                        }
                    }
                    // Remove volumes if they have already been exported
                    if (!volumesToRemove.isEmpty()) {
                        volumes.removeAll(volumesToRemove);
                    }
                    // nothing else needs to be done here.
                    if (volumes.isEmpty()) {
                        _log.info(String.format("No volumes needed to be exported to export group [%s], continue", exportGroup.getGeneratedName()));
                        continue;
                    }
                } else {
                    addExportGroupToDB = true;
                }
                // Add volumes to the export group
                Map<URI, Integer> volumesToAdd = new HashMap<URI, Integer>();
                for (URI volumeID : volumes) {
                    exportGroup.addVolume(volumeID, ExportGroup.LUN_UNASSIGNED);
                    volumesToAdd.put(volumeID, ExportGroup.LUN_UNASSIGNED);
                }
                // Keep track of volumes added to export group
                if (!volumesToAdd.isEmpty()) {
                    exportGroupVolumesAdded.put(exportGroup.getId(), volumesToAdd.keySet());
                }
                // volume
                if (rpExport.getComputeResource() != null) {
                    URI computeResource = rpExport.getComputeResource();
                    _log.info(String.format("RP Export: ComputeResource : %s", computeResource.toString()));
                    if (computeResource.toString().toLowerCase().contains(COMPUTE_RESOURCE_CLUSTER)) {
                        Cluster cluster = _dbClient.queryObject(Cluster.class, computeResource);
                        exportGroup.addCluster(cluster);
                    } else {
                        Host host = _dbClient.queryObject(Host.class, rpExport.getComputeResource());
                        exportGroup.addHost(host);
                    }
                }
                // Persist the export group
                if (addExportGroupToDB) {
                    exportGroup.addInitiators(initiatorSet);
                    exportGroup.setNumPaths(numPaths);
                    _dbClient.createObject(exportGroup);
                    // Keep track of newly created EGs in case of rollback
                    exportGroupsCreated.add(exportGroup.getId());
                } else {
                    _dbClient.updateObject(exportGroup);
                }
                // If the export group already exists, add the volumes to it, otherwise create a brand new
                // export group.
                StringBuilder buffer = new StringBuilder();
                buffer.append(String.format(DASHED_NEWLINE));
                if (!addExportGroupToDB) {
                    buffer.append(String.format("Adding volumes to existing Export Group for Storage System [%s], RP Site [%s], Virtual Array [%s]%n", storageSystem.getLabel(), rpSiteName, varray.getLabel()));
                    buffer.append(String.format("Export Group name is : [%s]%n", exportGroup.getGeneratedName()));
                    buffer.append(String.format("Export Group will have these volumes added: [%s]%n", Joiner.on(',').join(volumes)));
                    buffer.append(String.format(DASHED_NEWLINE));
                    _log.info(buffer.toString());
                    waitFor = _exportWfUtils.generateExportGroupAddVolumes(workflow, STEP_EXPORT_GROUP, waitFor, storageSystemURI, exportGroup.getId(), volumesToAdd);
                    _log.info("Added Export Group add volumes step in workflow");
                } else {
                    buffer.append(String.format("Creating new Export Group for Storage System [%s], RP Site [%s], Virtual Array [%s]%n", storageSystem.getLabel(), rpSiteName, varray.getLabel()));
                    buffer.append(String.format("Export Group name is: [%s]%n", exportGroup.getGeneratedName()));
                    buffer.append(String.format("Export Group will have these initiators: [%s]%n", Joiner.on(',').join(initiatorSet)));
                    buffer.append(String.format("Export Group will have these volumes added: [%s]%n", Joiner.on(',').join(volumes)));
                    buffer.append(String.format(DASHED_NEWLINE));
                    _log.info(buffer.toString());
                    String exportStep = workflow.createStepId();
                    initTaskStatus(exportGroup, exportStep, Operation.Status.pending, "create export");
                    waitFor = _exportWfUtils.generateExportGroupCreateWorkflow(workflow, STEP_EXPORT_GROUP, waitFor, storageSystemURI, exportGroup.getId(), volumesToAdd, initiatorSet);
                    _log.info("Added Export Group create step in workflow. New Export Group Id: " + exportGroup.getId());
                }
            }
            String successMessage = "Export orchestration completed successfully";
            // Finish up and execute the plan.
            // The Workflow will handle the TaskCompleter
            Object[] callbackArgs = new Object[] { volUris };
            workflow.executePlan(completer, successMessage, new WorkflowCallback(), callbackArgs, null, null);
            // Mark this workflow as created/executed so we don't do it again on retry/resume
            WorkflowService.getInstance().markWorkflowBeenCreated(taskId, workflowKey);
        }
    } catch (LockRetryException ex) {
        /**
         * Added this catch block to mark the current workflow as completed so that lock retry will not get exception while creating new
         * workflow using the same taskid.
         */
        _log.warn(String.format("Lock retry exception key: %s remaining time %d", ex.getLockIdentifier(), ex.getRemainingWaitTimeSeconds()));
        if (workflow != null && !NullColumnValueGetter.isNullURI(workflow.getWorkflowURI()) && workflow.getWorkflowState() == WorkflowState.CREATED) {
            com.emc.storageos.db.client.model.Workflow wf = _dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
            if (!wf.getCompleted()) {
                _log.error("Marking the status to completed for the newly created workflow {}", wf.getId());
                wf.setCompleted(true);
                _dbClient.updateObject(wf);
            }
        }
        throw ex;
    } catch (Exception ex) {
        _log.error("Could not create volumes: " + volUris, ex);
        // Rollback ViPR level RP export group changes
        rpExportGroupRollback();
        if (workflow != null) {
            _workflowService.releaseAllWorkflowLocks(workflow);
        }
        String opName = ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME.getName();
        ServiceError serviceError = null;
        if (lockException) {
            serviceError = DeviceControllerException.errors.createVolumesAborted(volUris.toString(), ex);
        } else {
            serviceError = DeviceControllerException.errors.createVolumesFailed(volUris.toString(), opName, ex);
        }
        completer.error(_dbClient, _locker, serviceError);
        return false;
    }
    _log.info("End adding RP Export Volumes steps.");
    return true;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) RPCGExportOrchestrationCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.RPCGExportOrchestrationCompleter) Initiator(com.emc.storageos.db.client.model.Initiator) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePort(com.emc.storageos.db.client.model.StoragePort) Workflow(com.emc.storageos.workflow.Workflow) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) LockRetryException(com.emc.storageos.locking.LockRetryException) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) 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) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Project(com.emc.storageos.db.client.model.Project) CGRequestParams(com.emc.storageos.recoverpoint.requests.CGRequestParams) BlockObject(com.emc.storageos.db.client.model.BlockObject) DataObject(com.emc.storageos.db.client.model.DataObject) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap)

Example 3 with ExportGroup

use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.

the class RPDeviceController method disableImageAccessStep.

/**
 * Workflow step method for disabling an image access of all snapshots in an export group
 *
 * @param rpSystem
 *            RP system
 * @param token
 *            the task
 * @return true if successful
 * @param exportGroupID
 *            export group ID
 * @throws ControllerException
 */
public boolean disableImageAccessStep(URI rpSystemId, URI exportGroupURI, String token) throws ControllerException {
    try {
        WorkflowStepCompleter.stepExecuting(token);
        List<URI> snapshots = new ArrayList<URI>();
        // In order to find all of the snapshots to deactivate, go through the devices, find the RP snapshots, and
        // deactivate any active
        // ones
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
        for (String exportVolumeIDStr : exportGroup.getVolumes().keySet()) {
            URI blockID;
            blockID = new URI(exportVolumeIDStr);
            BlockObject block = BlockObject.fetch(_dbClient, blockID);
            if (block.getProtectionController() != null) {
                if (block.getId().toString().contains("BlockSnapshot")) {
                    // Collect this snapshot; it needs to be disabled
                    snapshots.add(block.getId());
                }
            }
        }
        disableImageForSnapshots(rpSystemId, new ArrayList<URI>(snapshots), false, token);
        // Update the workflow state.
        WorkflowStepCompleter.stepSucceded(token);
    } catch (Exception e) {
        _log.error(String.format("disableImageAccessStep Failed - Protection System: %s, export group: %s", String.valueOf(rpSystemId), String.valueOf(exportGroupURI)));
        return stepFailed(token, e, "disableImageAccessStep");
    }
    return true;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) 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)

Example 4 with ExportGroup

use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.

the class RPDeviceController method addExportRemoveVolumeSteps.

/**
 * Add the export remove volume step to the workflow
 *
 * @param workflow
 *            workflow object
 * @param rpSystem
 *            protection system
 * @param exportGroupID
 *            export group
 * @param boIDs
 *            volume/snapshot IDs
 * @throws InternalException
 */
private void addExportRemoveVolumeSteps(Workflow workflow, ProtectionSystem rpSystem, URI exportGroupID, List<URI> boIDs) throws InternalException {
    ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupID);
    String exportStep = workflow.createStepId();
    initTaskStatus(exportGroup, exportStep, Operation.Status.pending, "export remove volumes (that contain RP snapshots)");
    Map<URI, List<URI>> deviceToBlockObjects = new HashMap<URI, List<URI>>();
    for (URI snapshotID : boIDs) {
        BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
        // Get the export objects corresponding to this snapshot
        List<BlockObject> objectsToRemove = getExportObjectsForBookmark(snapshot);
        for (BlockObject blockObject : objectsToRemove) {
            List<URI> blockObjects = deviceToBlockObjects.get(blockObject.getStorageController());
            if (blockObjects == null) {
                blockObjects = new ArrayList<URI>();
                deviceToBlockObjects.put(blockObject.getStorageController(), blockObjects);
            }
            blockObjects.add(blockObject.getId());
        }
    }
    for (Map.Entry<URI, List<URI>> deviceEntry : deviceToBlockObjects.entrySet()) {
        _log.info(String.format("Adding workflow step to remove RP bookmarks and associated target volumes from export.  ExportGroup: %s, Storage System: %s, BlockObjects: %s", exportGroup.getId(), deviceEntry.getKey(), deviceEntry.getValue()));
        _exportWfUtils.generateExportGroupRemoveVolumes(workflow, STEP_EXPORT_REMOVE_SNAPSHOT, STEP_EXPORT_GROUP_DISABLE, deviceEntry.getKey(), exportGroupID, deviceEntry.getValue());
    }
    _log.info(String.format("Created export group remove snapshot steps in workflow: %s", exportGroup.getId()));
}
Also used : HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 5 with ExportGroup

use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.

the class RPDeviceController method rpExportGroupRollback.

/**
 * ViPR level deletion/update of any RP Export Groups that are newly created. If they are pre-existing,
 * then we simply want to remove any volume references that had been added to those Export Groups.
 */
private void rpExportGroupRollback() {
    // Rollback any newly created export groups
    if (exportGroupsCreated != null && !exportGroupsCreated.isEmpty()) {
        for (URI exportGroupURI : exportGroupsCreated) {
            ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
            if (exportGroup != null && !exportGroup.getInactive()) {
                _log.info(String.format("Marking ExportGroup [%s](%s) for deletion.", exportGroup.getLabel(), exportGroup.getId()));
                _dbClient.markForDeletion(exportGroup);
            }
        }
    }
    // Rollback any volumes that have been added/persisted to existing export groups
    if (exportGroupVolumesAdded != null && !exportGroupVolumesAdded.isEmpty()) {
        for (Entry<URI, Set<URI>> entry : exportGroupVolumesAdded.entrySet()) {
            if (entry.getValue() != null && !entry.getValue().isEmpty()) {
                if (exportGroupsCreated != null && !exportGroupsCreated.isEmpty()) {
                    if (exportGroupsCreated.contains(entry.getKey())) {
                        // We already marked this EG for deletion, so keep going.
                        continue;
                    }
                }
                ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, entry.getKey());
                _log.info(String.format("Removing volumes (%s) from ExportGroup (%s).", entry.getValue(), entry.getKey()));
                exportGroup.removeVolumes(new ArrayList<URI>(entry.getValue()));
                _dbClient.updateObject(exportGroup);
            }
        }
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

ExportGroup (com.emc.storageos.db.client.model.ExportGroup)274 URI (java.net.URI)202 ExportMask (com.emc.storageos.db.client.model.ExportMask)137 ArrayList (java.util.ArrayList)135 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)111 HashMap (java.util.HashMap)94 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)84 Initiator (com.emc.storageos.db.client.model.Initiator)83 NamedURI (com.emc.storageos.db.client.model.NamedURI)79 HashSet (java.util.HashSet)69 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)63 Workflow (com.emc.storageos.workflow.Workflow)61 List (java.util.List)56 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)54 BlockObject (com.emc.storageos.db.client.model.BlockObject)49 Map (java.util.Map)47 ExportOrchestrationTask (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)44 ControllerException (com.emc.storageos.volumecontroller.ControllerException)41 StringSet (com.emc.storageos.db.client.model.StringSet)38 StringMap (com.emc.storageos.db.client.model.StringMap)32