use of com.emc.storageos.volumecontroller.impl.smis.job.SmisCloneVolumeJob in project coprhd-controller by CoprHD.
the class AbstractCloneOperations method createSingleClone.
@Override
@SuppressWarnings("rawtypes")
public void createSingleClone(StorageSystem storageSystem, URI sourceVolume, URI cloneVolume, Boolean createInactive, TaskCompleter taskCompleter) {
_log.info("START createSingleClone operation");
try {
BlockObject sourceObj = BlockObject.fetch(_dbClient, sourceVolume);
URI tenantUri = null;
Volume baseVolume = null;
boolean isSourceSnap = false;
if (sourceObj instanceof BlockSnapshot) {
// In case of snapshot, get the tenant from its parent volume
NamedURI parentVolUri = ((BlockSnapshot) sourceObj).getParent();
Volume parentVolume = _dbClient.queryObject(Volume.class, parentVolUri);
tenantUri = parentVolume.getTenant().getURI();
baseVolume = parentVolume;
isSourceSnap = true;
} else {
// This is a default flow
tenantUri = ((Volume) sourceObj).getTenant().getURI();
baseVolume = (Volume) sourceObj;
}
// CTRL-1992: Need to resync any existing snapshot restore sessions, if applicable
if (_helper.arraySupportsResync(storageSystem)) {
CloseableIterator<CIMObjectPath> syncObjectIter = _cimPath.getSyncObjects(storageSystem, sourceObj);
CIMObjectPath path = null;
while (syncObjectIter.hasNext()) {
path = syncObjectIter.next();
CIMInstance instance = _helper.getInstance(storageSystem, path, false, false, SmisConstants.PS_COPY_STATE_AND_DESC_SYNCTYPE);
String copyState = instance.getPropertyValue(SmisConstants.CP_COPY_STATE).toString();
String copyStateDesc = instance.getPropertyValue(SmisConstants.EMC_COPY_STATE_DESC).toString();
String syncType = instance.getPropertyValue(SmisConstants.CP_SYNC_TYPE).toString();
_log.info(String.format("Sync %s has copyState %s (%s) syncType %s", path.toString(), copyState, copyStateDesc, syncType));
if (copyState.equals(COPY_STATE_RESTORED_INT_VALUE) && syncType.equals(Integer.toString(SmisConstants.SNAPSHOT_VALUE))) {
// This snapshot is in the 'Restored' state, need to
// resync it, before we can create a full copy
_log.info("Sync {} is in restored state, need to resync", path);
SmisBlockResyncSnapshotJob job = new SmisBlockResyncSnapshotJob(null, storageSystem.getId(), new TaskCompleter() {
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
}
});
CIMArgument[] result = new CIMArgument[5];
_helper.invokeMethodSynchronously(storageSystem, _cimPath.getControllerReplicationSvcPath(storageSystem), SmisConstants.MODIFY_REPLICA_SYNCHRONIZATION, _helper.getResyncSnapshotInputArguments(path), result, job);
if (job.isSuccess()) {
_log.info("{} was successfully resynchronized", path.toString());
} else {
_log.error("Encountered a failure while trying to resynchronize a restored snapshot");
ServiceError error = DeviceControllerErrors.smis.resyncActiveRestoreSessionFailure(sourceObj.getLabel());
taskCompleter.error(_dbClient, error);
return;
}
}
}
}
Volume cloneObj = _dbClient.queryObject(Volume.class, cloneVolume);
StoragePool targetPool = _dbClient.queryObject(StoragePool.class, cloneObj.getPool());
TenantOrg tenantOrg = _dbClient.queryObject(TenantOrg.class, tenantUri);
String cloneLabel = generateLabel(tenantOrg, cloneObj);
CIMObjectPath volumeGroupPath = _helper.getVolumeGroupPath(storageSystem, storageSystem, baseVolume, targetPool);
CIMObjectPath sourceVolumePath = _cimPath.getBlockObjectPath(storageSystem, sourceObj);
CIMObjectPath replicationSvcPath = _cimPath.getControllerReplicationSvcPath(storageSystem);
CIMArgument[] inArgs = null;
CIMInstance repSettingData = null;
if (storageSystem.deviceIsType(Type.vmax)) {
if (createInactive && storageSystem.getUsingSmis80()) {
repSettingData = _helper.getReplicationSettingDataInstanceForDesiredCopyMethod(storageSystem, COPY_BEFORE_ACTIVATE, true);
} else if (storageSystem.checkIfVmax3() && ControllerUtils.isVmaxUsing81SMIS(storageSystem, _dbClient)) {
/**
* VMAX3 using SMI 8.1 provider needs to send DesiredCopyMethodology=32770
* to create TimeFinder differential clone.
*/
repSettingData = _helper.getReplicationSettingDataInstanceForDesiredCopyMethod(storageSystem, SMIS810_TF_DIFFERENTIAL_CLONE_VALUE, true);
} else {
repSettingData = _helper.getReplicationSettingDataInstanceForDesiredCopyMethod(storageSystem, DIFFERENTIAL_CLONE_VALUE, true);
}
inArgs = _helper.getCloneInputArguments(cloneLabel, sourceVolumePath, volumeGroupPath, storageSystem, targetPool, createInactive, repSettingData);
} else if (storageSystem.deviceIsType(Type.vnxblock)) {
if (!isSourceSnap) {
repSettingData = getReplicationSettingDataInstanceForThinProvisioningPolicy(storageSystem, PROVISIONING_TARGET_SAME_AS_SOURCE);
// don't supply target pool when using thinlyProvisioningPolicy=PROVISIONING_TARGET_SAME_AS_SOURCE
inArgs = _helper.getCreateElementReplicaMirrorInputArgumentsWithReplicationSettingData(storageSystem, sourceObj, null, false, repSettingData, cloneLabel);
cloneObj.setPool(baseVolume.getPool());
_dbClient.persistObject(cloneObj);
} else {
// when source is snapshot, create clone instead of mirror, since creating mirror from a snap is not supported.
inArgs = _helper.getCloneInputArguments(cloneLabel, sourceVolumePath, volumeGroupPath, storageSystem, targetPool, createInactive, null);
}
}
CIMArgument[] outArgs = new CIMArgument[5];
_helper.invokeMethod(storageSystem, replicationSvcPath, SmisConstants.CREATE_ELEMENT_REPLICA, inArgs, outArgs);
CIMObjectPath job = _cimPath.getCimObjectPathFromOutputArgs(outArgs, SmisConstants.JOB);
if (job != null) {
ControllerServiceImpl.enqueueJob(new QueueJob(new SmisCloneVolumeJob(job, storageSystem.getId(), taskCompleter)));
}
} catch (Exception e) {
Volume clone = _dbClient.queryObject(Volume.class, cloneVolume);
if (clone != null) {
clone.setInactive(true);
_dbClient.persistObject(clone);
}
String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceVolume, cloneVolume);
_log.error(errorMsg, e);
SmisException serviceCode = DeviceControllerExceptions.smis.createFullCopyFailure(errorMsg, e);
taskCompleter.error(_dbClient, serviceCode);
throw serviceCode;
}
}
Aggregations