Search in sources :

Example 76 with BlockSnapshotSession

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

the class BlockSnapshotSessionDeleteCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    URI snapSessionURI = getId();
    try {
        BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, snapSessionURI);
        switch(status) {
            case ready:
                // access to snapshot session after it has been marked inactive.
                if ((_markInactive) && (snapSession != null) && (!snapSession.getInactive())) {
                    snapSession.setInactive(true);
                    dbClient.updateObject(snapSession);
                }
                break;
            default:
                break;
        }
        s_logger.info("Done delete snapshot session step {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for delete snapshot session step {}", getOpId(), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 77 with BlockSnapshotSession

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

the class BlockSnapshotSessionLinkTargetCompleter method complete.

/**
 * {@inheritDoc}
 */
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    try {
        switch(status) {
            case error:
                break;
            case ready:
                List<BlockSnapshotSession> sessionsToUpdate = newArrayList();
                BlockSnapshotSession snapSession = dbClient.queryObject(BlockSnapshotSession.class, _snapshotSessionURI);
                StringSet linkedTargets = snapSession.getLinkedTargets();
                if (linkedTargets == null) {
                    linkedTargets = new StringSet();
                    snapSession.setLinkedTargets(linkedTargets);
                }
                linkedTargets.addAll(transform(_snapshotURIs, FCTN_URI_TO_STRING));
                sessionsToUpdate.add(snapSession);
                dbClient.updateObject(sessionsToUpdate);
                break;
            default:
                String errMsg = String.format("Unexpected status %s for completer for step %s", status.name(), getOpId());
                s_logger.info(errMsg);
                throw DeviceControllerException.exceptions.unexpectedCondition(errMsg);
        }
        s_logger.info("Done link snapshot session target step {} with status: {}", getOpId(), status.name());
    } catch (Exception e) {
        s_logger.error("Failed updating status for link snapshot session target step {}", getOpId(), e);
    } finally {
        super.complete(dbClient, status, coded);
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) StringSet(com.emc.storageos.db.client.model.StringSet) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 78 with BlockSnapshotSession

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

the class RPDeviceController method addStepsForPreOrPostCreateReplica.

/**
 * adds steps for either pre-create copy or post-create copy for recoverpoint protected volumes
 *
 * @param workflow
 * @param waitFor
 * @param volumeDescriptors
 * @param preCreate
 *            true if this is a pre-create copy steps or false for post create copy steps
 * @param taskId
 * @return
 * @throws InternalException
 */
private String addStepsForPreOrPostCreateReplica(Workflow workflow, String waitFor, List<VolumeDescriptor> volumeDescriptors, boolean preCreate, String taskId) throws InternalException {
    List<VolumeDescriptor> blockVolmeDescriptors = VolumeDescriptor.filterByType(volumeDescriptors, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.BLOCK_DATA, VolumeDescriptor.Type.BLOCK_SNAPSHOT, VolumeDescriptor.Type.VPLEX_IMPORT_VOLUME, VolumeDescriptor.Type.BLOCK_SNAPSHOT_SESSION }, new VolumeDescriptor.Type[] {});
    // If no volumes to create, just return
    if (blockVolmeDescriptors.isEmpty()) {
        _log.warn("Skipping RP create steps for create replica because no block volume descriptors were found");
        return waitFor;
    }
    // get the list of parent volumes that are to be copied
    Map<VolumeDescriptor, List<URI>> descriptorToParentIds = new HashMap<VolumeDescriptor, List<URI>>();
    Class<? extends DataObject> clazz = Volume.class;
    for (VolumeDescriptor descriptor : blockVolmeDescriptors) {
        List<URI> parentIds = new ArrayList<>();
        if (URIUtil.isType(descriptor.getVolumeURI(), BlockSnapshotSession.class)) {
            // for snapshot sessions, if its a single volume snapshot session, parent will be filled in
            // for CG snapshot sessions, get all the parents in the group from the replication group name
            BlockSnapshotSession snapshotSession = _dbClient.queryObject(BlockSnapshotSession.class, descriptor.getVolumeURI());
            if (snapshotSession != null && !snapshotSession.getInactive()) {
                if (!NullColumnValueGetter.isNullNamedURI(snapshotSession.getParent())) {
                    parentIds.add(snapshotSession.getParent().getURI());
                } else if (!NullColumnValueGetter.isNullValue(snapshotSession.getReplicationGroupInstance())) {
                    List<Volume> volsInRG = ControllerUtils.getVolumesPartOfRG(snapshotSession.getStorageController(), snapshotSession.getReplicationGroupInstance(), _dbClient);
                    for (Volume vol : volsInRG) {
                        parentIds.add(vol.getId());
                    }
                } else {
                    _log.warn(String.format("Skipping BlockSnapshotSession object with null parent and null replicationGroupInstance: %s", snapshotSession.getId().toString()));
                }
                clazz = BlockSnapshotSession.class;
            }
        } else if (URIUtil.isType(descriptor.getVolumeURI(), BlockSnapshot.class)) {
            BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, descriptor.getVolumeURI());
            if (snapshot != null && !snapshot.getInactive() && !NullColumnValueGetter.isNullNamedURI(snapshot.getParent())) {
                parentIds.add(snapshot.getParent().getURI());
                clazz = BlockSnapshot.class;
            } else {
                _log.warn(String.format("Skipping snapshot with null parent: %s", descriptor.getVolumeURI().toString()));
            }
        } else if (URIUtil.isType(descriptor.getVolumeURI(), Volume.class)) {
            Volume volume = _dbClient.queryObject(Volume.class, descriptor.getVolumeURI());
            if (volume != null && !volume.getInactive() && !NullColumnValueGetter.isNullURI(volume.getAssociatedSourceVolume())) {
                parentIds.add(volume.getAssociatedSourceVolume());
            } else {
                _log.warn(String.format("Skipping full copy with null parent: %s", descriptor.getVolumeURI().toString()));
            }
        } else {
            _log.warn(String.format("Skipping unsupported copy type: %s", descriptor.getVolumeURI().toString()));
        }
        if (!parentIds.isEmpty()) {
            descriptorToParentIds.put(descriptor, parentIds);
        }
    }
    // get the descriptor and wwn of each target volume being copied
    // also get the protection system and one source volume to be used for locking
    ProtectionSystem protectionSystem = null;
    Volume aSrcVolume = null;
    Set<String> volumeWWNs = new HashSet<String>();
    Set<URI> copyList = new HashSet<URI>();
    for (Entry<VolumeDescriptor, List<URI>> entry : descriptorToParentIds.entrySet()) {
        VolumeDescriptor descriptor = entry.getKey();
        List<URI> parentIds = entry.getValue();
        for (URI parentId : parentIds) {
            if (URIUtil.isType(parentId, Volume.class)) {
                Volume parentVolume = _dbClient.queryObject(Volume.class, parentId);
                if (parentVolume != null && !parentVolume.getInactive()) {
                    if (Volume.checkForVplexBackEndVolume(_dbClient, parentVolume)) {
                        parentVolume = Volume.fetchVplexVolume(_dbClient, parentVolume);
                    }
                    // the target volumes are RP volumes.
                    if (StringUtils.equals(parentVolume.getPersonality(), Volume.PersonalityTypes.TARGET.toString()) && Volume.checkForRP(_dbClient, parentVolume.getId())) {
                        volumeWWNs.add(RPHelper.getRPWWn(parentVolume.getId(), _dbClient));
                        copyList.add(descriptor.getVolumeURI());
                        if (protectionSystem == null) {
                            if (!NullColumnValueGetter.isNullURI(parentVolume.getProtectionController())) {
                                aSrcVolume = RPHelper.getRPSourceVolumeFromTarget(_dbClient, parentVolume);
                                protectionSystem = _dbClient.queryObject(ProtectionSystem.class, aSrcVolume.getProtectionController());
                            }
                        }
                    }
                }
            }
        }
    }
    if (!volumeWWNs.isEmpty()) {
        if (preCreate) {
            // 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
            return addEnableImageAccessForCreateReplicaStep(workflow, protectionSystem, clazz, new ArrayList<URI>(copyList), bookmarkName, volumeWWNs, rpWaitFor);
        } else {
            return addDisableImageAccessForCreateReplicaStep(workflow, protectionSystem, clazz, new ArrayList<URI>(copyList), volumeWWNs, waitFor);
        }
    } else {
        _log.warn("Skipping RP create steps for create replica. No qualifying volume WWNs found.");
    }
    return waitFor;
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) Random(java.util.Random) Volume(com.emc.storageos.db.client.model.Volume) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) HashSet(java.util.HashSet)

Example 79 with BlockSnapshotSession

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

the class VmaxSnapshotOperations method relinkSnapshotSessionTarget.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("rawtypes")
@Override
public void relinkSnapshotSessionTarget(StorageSystem system, URI tgtSnapSessionURI, URI snapshotURI, TaskCompleter completer) throws DeviceControllerException {
    // Only supported for VMAX3 storage systems.
    if (!system.checkIfVmax3()) {
        throw DeviceControllerException.exceptions.blockDeviceOperationNotSupported();
    }
    try {
        _log.info("Re-link target {} to snapshot session {} START", snapshotURI, tgtSnapSessionURI);
        BlockSnapshotSession tgtSnapSession = _dbClient.queryObject(BlockSnapshotSession.class, tgtSnapSessionURI);
        BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotURI);
        URI sourceURI = tgtSnapSession.getParent().getURI();
        BlockObject sourceObj = BlockObject.fetch(_dbClient, sourceURI);
        CIMObjectPath sourcePath = _cimPath.getVolumePath(system, sourceObj.getNativeId());
        CIMObjectPath syncObjPath = getSyncObject(system, snapshot, sourceObj);
        boolean targetLinkedInCopyMode = isTargetOrGroupCopyMode(system, syncObjPath);
        CIMObjectPath replicationSvcPath = _cimPath.getControllerReplicationSvcPath(system);
        String syncAspectPath = tgtSnapSession.getSessionInstance();
        CIMObjectPath settingsStatePath = _cimPath.getSyncSettingsPath(system, sourcePath, syncAspectPath);
        CIMObjectPath targetDevicePath = _cimPath.getBlockObjectPath(system, snapshot);
        CIMArgument[] inArgs = null;
        CIMArgument[] outArgs = new CIMArgument[5];
        inArgs = _helper.getModifySettingsDefinedStateForRelinkTargets(system, settingsStatePath, targetDevicePath, targetLinkedInCopyMode);
        _helper.invokeMethod(system, replicationSvcPath, SmisConstants.MODIFY_SETTINGS_DEFINE_STATE, inArgs, outArgs);
        CIMObjectPath jobPath = _cimPath.getCimObjectPathFromOutputArgs(outArgs, SmisConstants.JOB);
        ControllerServiceImpl.enqueueJob(new QueueJob(new SmisBlockSnapshotSessionRelinkTargetJob(jobPath, system.getId(), completer)));
    } catch (Exception e) {
        _log.error("Exception re-linking snapshot session", e);
        ServiceError error = DeviceControllerErrors.smis.unableToCallStorageProvider(e.getMessage());
        completer.error(_dbClient, error);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SmisBlockSnapshotSessionRelinkTargetJob(com.emc.storageos.volumecontroller.impl.smis.job.SmisBlockSnapshotSessionRelinkTargetJob) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CIMObjectPath(javax.cim.CIMObjectPath) URI(java.net.URI) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) BlockObject(com.emc.storageos.db.client.model.BlockObject) CIMArgument(javax.cim.CIMArgument)

Example 80 with BlockSnapshotSession

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

the class VmaxSnapshotOperations method linkSnapshotSessionTargetGroup.

@Override
public void linkSnapshotSessionTargetGroup(StorageSystem system, URI snapshotSessionURI, List<URI> snapSessionSnapshotURIs, String copyMode, Boolean targetsExist, TaskCompleter completer) throws DeviceControllerException {
    _log.info("Link new target group to snapshot session group START");
    CIMObjectPath targetGroupPath = null;
    List<String> targetDeviceIds = new ArrayList<>();
    // Gather all snapshots to be created
    List<URI> snapshotUris = snapSessionSnapshotURIs;
    List<BlockSnapshot> snapshots = newArrayList(_dbClient.queryIterativeObjects(BlockSnapshot.class, snapshotUris));
    final Map<URI, BlockSnapshot> uriToSnapshot = new HashMap<>();
    BlockSnapshot sampleSnapshot = snapshots.get(0);
    BlockObject sampleParent = BlockObject.fetch(_dbClient, sampleSnapshot.getParent().getURI());
    try {
        String sourceGroupName;
        String targetGroupName;
        if (!targetsExist) {
            // This is the normal scenario for linking group targets to a group snapshot session.
            sourceGroupName = ConsistencyGroupUtils.getSourceConsistencyGroupName(sampleParent, _dbClient);
            // Group snapshots parent volumes by their pool and size
            Map<String, List<Volume>> volumesBySizeMap = new HashMap<>();
            for (BlockSnapshot target : snapshots) {
                uriToSnapshot.put(target.getId(), target);
                Volume parent = _dbClient.queryObject(Volume.class, target.getParent().getURI());
                String key = parent.getPool() + "-" + parent.getCapacity();
                if (volumesBySizeMap.containsKey(key)) {
                    volumesBySizeMap.get(key).add(parent);
                } else {
                    volumesBySizeMap.put(key, newArrayList(parent));
                }
            }
            // Create snapshot target volumes
            for (Entry<String, List<Volume>> entry : volumesBySizeMap.entrySet()) {
                final List<Volume> volumes = entry.getValue();
                final Volume volume = volumes.get(0);
                final URI poolId = volume.getPool();
                // get respective group path for volume storage pool
                CIMObjectPath volumeGroupPath = _helper.getVolumeGroupPath(system, system, volume, null);
                // Create target devices based on the array model
                final List<String> newDeviceIds = kickOffTargetDevicesCreation(system, volumeGroupPath, sourceGroupName, null, false, true, volumes.size(), poolId, volume.getCapacity(), completer);
                targetDeviceIds.addAll(newDeviceIds);
            }
            // Create target device group
            targetGroupPath = ReplicationUtils.createTargetDeviceGroup(system, sourceGroupName, targetDeviceIds, completer, _dbClient, _helper, _cimPath, SYNC_TYPE.SNAPSHOT);
            _log.info("Created target device group: {}", targetGroupPath);
            targetGroupName = (String) targetGroupPath.getKeyValue(CP_INSTANCE_ID);
            // Update the snapshots with the ReplicationGroup InstanceID
            for (BlockSnapshot snapshot : snapshots) {
                snapshot.setReplicationGroupInstance(targetGroupName);
            }
            _dbClient.updateObject(snapshots);
        } else {
            // already exist. First we setup of the snapshot map.
            for (BlockSnapshot target : snapshots) {
                uriToSnapshot.put(target.getId(), target);
            }
            // The parent in this case is a BlockSnapshot and the source group is the
            // replication group for the snapshot. We eliminate the system prefix and
            // serial number from the replication group, to get simply the group name
            // as in the case above.
            sourceGroupName = ((BlockSnapshot) sampleParent).getReplicationGroupInstance();
            int groupNameStartIndex = sourceGroupName.indexOf("+") + 1;
            sourceGroupName = sourceGroupName.substring(groupNameStartIndex);
            // The target in this case is actually a source volume and the target group
            // is the source volume group, which we can get from the parent's replication group instance.
            // Note that we can use the sample parent because it references the same
            // repliaction group as the source volume.
            targetGroupName = ConsistencyGroupUtils.getSourceConsistencyGroupName(sampleParent, _dbClient);
            // Get the CIM object path for the target group.
            targetGroupPath = _cimPath.getReplicationGroupPath(system, targetGroupName);
        }
        // Now link the target group to the array snapshots represented by the session.
        CIMObjectPath replicationSvcPath = _cimPath.getControllerReplicationSvcPath(system);
        BlockSnapshotSession snapSession = _dbClient.queryObject(BlockSnapshotSession.class, snapshotSessionURI);
        String syncAspectPath = snapSession.getSessionInstance();
        CIMObjectPath settingsStatePath = _cimPath.getGroupSynchronizedSettingsPath(system, sourceGroupName, syncAspectPath);
        CIMArgument[] inArgs = null;
        CIMArgument[] outArgs = new CIMArgument[5];
        inArgs = _helper.getModifySettingsDefinedStateForLinkTargetGroup(system, settingsStatePath, targetGroupPath, copyMode);
        _helper.invokeMethod(system, replicationSvcPath, SmisConstants.MODIFY_SETTINGS_DEFINE_STATE, inArgs, outArgs);
        CIMObjectPath jobPath = _cimPath.getCimObjectPathFromOutputArgs(outArgs, SmisConstants.JOB);
        SmisBlockSnapshotSessionLinkTargetGroupJob job = new SmisBlockSnapshotSessionLinkTargetGroupJob(jobPath, system.getId(), completer);
        job.setSourceGroupName(sourceGroupName);
        job.setTargetGroupName(targetGroupName);
        job.setSnapSessionInstance(snapSession.getSessionInstance());
        Map<String, URI> srcNativeIdToSnapshot = Maps.uniqueIndex(snapshotUris, new Function<URI, String>() {

            @Override
            public String apply(URI input) {
                return uriToSnapshot.get(input).getSourceNativeId();
            }
        });
        job.setSrcNativeIdToSnapshotMap(srcNativeIdToSnapshot);
        ControllerServiceImpl.enqueueJob(new QueueJob(job));
        _log.info("Link new target group to snapshot session group FINISH");
    } catch (Exception e) {
        _log.error("Exception creating and linking snapshot session targets", e);
        ServiceError error = DeviceControllerErrors.smis.unableToCallStorageProvider(e.getMessage());
        completer.error(_dbClient, error);
    }
}
Also used : HashMap(java.util.HashMap) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) URI(java.net.URI) SmisBlockSnapshotSessionLinkTargetGroupJob(com.emc.storageos.volumecontroller.impl.smis.job.SmisBlockSnapshotSessionLinkTargetGroupJob) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) ArrayList(java.util.ArrayList) List(java.util.List) BlockObject(com.emc.storageos.db.client.model.BlockObject) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) CIMObjectPath(javax.cim.CIMObjectPath) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) CustomQueryUtility.queryActiveResourcesByConstraint(com.emc.storageos.db.client.util.CustomQueryUtility.queryActiveResourcesByConstraint) Factory.getLinkedTargetSnapshotSessionConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) Volume(com.emc.storageos.db.client.model.Volume) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) CIMArgument(javax.cim.CIMArgument)

Aggregations

BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)112 URI (java.net.URI)64 Volume (com.emc.storageos.db.client.model.Volume)43 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)41 NamedURI (com.emc.storageos.db.client.model.NamedURI)38 ArrayList (java.util.ArrayList)33 BlockObject (com.emc.storageos.db.client.model.BlockObject)29 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)27 StringSet (com.emc.storageos.db.client.model.StringSet)25 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 HashMap (java.util.HashMap)17 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)16 CIMObjectPath (javax.cim.CIMObjectPath)13 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)12 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)11 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)11 ServiceCoded (com.emc.storageos.svcs.errorhandling.model.ServiceCoded)11 DataObject (com.emc.storageos.db.client.model.DataObject)10 Project (com.emc.storageos.db.client.model.Project)10 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)10