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);
}
}
Aggregations