Search in sources :

Example 1 with SmisBlockSnapshotSessionLinkTargetGroupJob

use of com.emc.storageos.volumecontroller.impl.smis.job.SmisBlockSnapshotSessionLinkTargetGroupJob 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

ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 Factory.getLinkedTargetSnapshotSessionConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint.Factory.getLinkedTargetSnapshotSessionConstraint)1 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)1 BlockObject (com.emc.storageos.db.client.model.BlockObject)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)1 Volume (com.emc.storageos.db.client.model.Volume)1 CustomQueryUtility.queryActiveResourcesByConstraint (com.emc.storageos.db.client.util.CustomQueryUtility.queryActiveResourcesByConstraint)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)1 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)1 SmisBlockSnapshotSessionLinkTargetGroupJob (com.emc.storageos.volumecontroller.impl.smis.job.SmisBlockSnapshotSessionLinkTargetGroupJob)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CIMArgument (javax.cim.CIMArgument)1 CIMObjectPath (javax.cim.CIMObjectPath)1