use of com.emc.storageos.volumecontroller.impl.smis.job.SmisCreateListReplicaJob in project coprhd-controller by CoprHD.
the class AbstractReplicaOperations method createListReplica.
@Override
public void createListReplica(StorageSystem storage, List<URI> replicaList, Boolean createInactive, TaskCompleter taskCompleter) {
_log.info("createListReplica operation START");
List<String> targetDeviceIds = new ArrayList<String>();
try {
List<String> sourceIds = new ArrayList<String>();
List<String> labels = new ArrayList<String>();
Map<String, URI> srcNativeIdToReplicaUriMap = new HashMap<String, URI>();
Map<String, String> tgtToSrcMap = new HashMap<String, String>();
String replicaGroupName = null;
String sessionName = null;
Volume source = null;
boolean isThinlyProvisioned = false;
for (URI replicaURI : replicaList) {
BlockObject replica = BlockObject.fetch(_dbClient, replicaURI);
source = (Volume) _helper.getSource(replica);
// Use the existing replica group instance name for the new snaps to add.
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, source.getTenant().getURI());
int maxLength = SmisConstants.MAX_VOLUME_NAME_LENGTH;
if (storage.getUsingSmis80() && URIUtil.isType(replicaURI, BlockSnapshot.class)) {
maxLength = SmisConstants.MAX_SMI80_SNAPSHOT_NAME_LENGTH;
}
String label = _nameGenerator.generate(tenant.getLabel(), replica.getLabel(), replicaURI.toString(), '-', maxLength);
labels.add(label);
replicaGroupName = replica.getReplicationGroupInstance();
if (sessionName == null) {
sessionName = getSnapshotSessionNameFromReplicaGroupName(replicaGroupName, storage.getId());
}
String sourceNativeId = source.getNativeId();
isThinlyProvisioned = source.getThinlyProvisioned();
sourceIds.add(sourceNativeId);
srcNativeIdToReplicaUriMap.put(sourceNativeId, replica.getId());
if (storage.deviceIsType(Type.vnxblock)) {
// need to create target devices first
final URI poolId = source.getPool();
final List<String> newDeviceIds = ReplicationUtils.createTargetDevices(storage, replicaGroupName, label, createInactive, 1, poolId, source.getCapacity(), isThinlyProvisioned, null, taskCompleter, _dbClient, _helper, _cimPath);
targetDeviceIds.addAll(newDeviceIds);
tgtToSrcMap.put(newDeviceIds.get(0), source.getNativeId());
}
}
int syncType = getSyncType(replicaList.get(0));
CIMObjectPath[] sourceVolumePaths = _cimPath.getVolumePaths(storage, sourceIds.toArray(new String[sourceIds.size()]));
CIMObjectPath[] targetDevicePaths = _cimPath.getVolumePaths(storage, targetDeviceIds.toArray(new String[targetDeviceIds.size()]));
CIMObjectPath targetVPSnapPoolPath = null;
if (syncType == SmisConstants.SNAPSHOT_VALUE && !volumeHasSnapshot(source)) {
targetVPSnapPoolPath = ReplicationUtils.getTargetPoolForVPSnapCreation(storage, null, replicaGroupName, isThinlyProvisioned, _dbClient, _helper, _cimPath);
}
CIMArgument[] inArgs = _helper.getCreateListReplicaInputArguments(storage, sourceVolumePaths, targetDevicePaths, labels, syncType, replicaGroupName, sessionName, createInactive, targetVPSnapPoolPath);
CIMArgument[] outArgs = new CIMArgument[5];
CIMObjectPath replicationSvc = _cimPath.getControllerReplicationSvcPath(storage);
_helper.invokeMethod(storage, replicationSvc, CREATE_LIST_REPLICA, inArgs, outArgs);
CIMObjectPath job = _cimPath.getCimObjectPathFromOutputArgs(outArgs, JOB);
ControllerServiceImpl.enqueueJob(new QueueJob(new SmisCreateListReplicaJob(job, storage.getId(), srcNativeIdToReplicaUriMap, tgtToSrcMap, syncType, !createInactive, taskCompleter)));
} catch (Exception e) {
final String errMsg = format("An exception occurred when trying to create list replica on storage system {0}", storage.getId());
_log.error(errMsg, e);
// Roll back changes
ReplicationUtils.rollbackCreateReplica(storage, null, targetDeviceIds, taskCompleter, _dbClient, _helper, _cimPath);
List<? extends BlockObject> replicas = BlockObject.fetch(_dbClient, replicaList);
for (BlockObject replica : replicas) {
replica.setInactive(true);
}
_dbClient.updateObject(replicas);
ServiceError error = DeviceControllerErrors.smis.methodFailed("createListReplica", e.getMessage());
taskCompleter.error(_dbClient, error);
}
_log.info("createListReplica operation END");
}
Aggregations