use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method resumeNativeContinuousCopies.
/**
* {@inheritDoc}
*/
@Override
public TaskList resumeNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, List<BlockMirror> blockMirrors, String taskId) throws ControllerException {
_log.info("START resume native continuous copies");
TaskList taskList = new TaskList();
List<URI> resumedMirrors = new ArrayList<URI>();
List<URI> mirrorURIs = new ArrayList<URI>();
Map<BlockMirror, Volume> groupMirrorSourceMap = null;
List<BlockMirror> mirrorsToProcess = null;
boolean isCG = sourceVolume.isInCG();
if (isCG) {
if (blockMirrors == null) {
for (String uriStr : sourceVolume.getMirrors()) {
BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
if (mirrorIsResumable(mirror)) {
groupMirrorSourceMap = getGroupMirrorSourceMap(mirror, sourceVolume);
// only process one mirror group
break;
}
}
} else {
groupMirrorSourceMap = getGroupMirrorSourceMap(blockMirrors.get(0), sourceVolume);
}
if (groupMirrorSourceMap == null || groupMirrorSourceMap.isEmpty()) {
Operation op = new Operation();
op.ready();
op.setResourceType(ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR);
op.setMessage("No continuous copy can be resumed");
_dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
return taskList;
}
mirrorsToProcess = new ArrayList<BlockMirror>(groupMirrorSourceMap.keySet());
mirrorURIs = new ArrayList<URI>(transform(mirrorsToProcess, FCTN_MIRROR_TO_URI));
} else {
// Assume all continuous copies are to be resumed
mirrorsToProcess = blockMirrors;
if (mirrorsToProcess == null) {
mirrorsToProcess = new ArrayList<BlockMirror>();
for (String uriStr : sourceVolume.getMirrors()) {
BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
mirrorsToProcess.add(mirror);
}
}
for (BlockMirror mirror : mirrorsToProcess) {
if (mirrorIsPausable(mirror) || mirrorIsResynchronizing(mirror)) {
// extract mirrors that are in resume state or resynchronizing
resumedMirrors.add(mirror.getId());
} else if (!mirrorIsResumable(mirror)) {
throw APIException.badRequests.cannotResumeContinuousCopyWithSyncState(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
}
mirrorURIs.add(mirror.getId());
}
}
/*
* if all mirrors are resumed/resynchronizing, then there is no task to do.
* Return a successful task
*/
if (!resumedMirrors.isEmpty() && mirrorURIs.isEmpty()) {
// If the mirrors is already resumed or resynchronizing, there would be no need to queue another request to
// resume it again.
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR);
op.setAssociatedResourcesField(Joiner.on(',').join(resumedMirrors));
op.ready("The continuous copies are already resumed or resynchronizing");
_dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
} else {
if (!isCG) {
Collection<String> mirrorTargetIds = Collections2.transform(mirrorsToProcess, FCTN_VOLUME_URI_TO_STR);
String mirrorTargetCommaDelimList = Joiner.on(',').join(mirrorTargetIds);
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR, mirrorTargetCommaDelimList);
taskList.getTaskList().add(toTask(sourceVolume, mirrorsToProcess, taskId, op));
} else {
populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.RESUME_VOLUME_MIRROR);
}
try {
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
controller.resumeNativeContinuousCopies(storageSystem.getId(), mirrorURIs, taskId);
} catch (ControllerException e) {
String errorMsg = format("Failed to resume continuous copies for source volume %s", sourceVolume.getId());
_log.error(errorMsg, e);
_dbClient.error(Volume.class, sourceVolume.getId(), taskId, e);
}
}
return taskList;
}
Aggregations