use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI in project coprhd-controller by CoprHD.
the class BlockDeviceController method rollbackMirror.
/**
* {@inheritDoc} NOTE NOTE: The signature here MUST match the Workflow.Method rollbackMirrorMethod just above
* (except opId).
*/
public void rollbackMirror(URI storage, List<URI> mirrorList, String taskId) {
WorkflowStepCompleter.stepExecuting(taskId);
try {
List<BlockMirror> mirrors = _dbClient.queryObject(BlockMirror.class, mirrorList);
boolean isCG = isCGMirror(mirrorList.get(0), _dbClient);
List<BlockMirror> mirrorsNoRollback = new ArrayList<BlockMirror>();
for (BlockMirror mirror : mirrors) {
// for non CG mirror, filter out mirror with no native Id
if ((isCG && NullColumnValueGetter.isNullValue(mirror.getReplicationGroupInstance()) || (!isCG && isNullOrEmpty(mirror.getNativeId())))) {
mirror.setInactive(true);
mirrorsNoRollback.add(mirror);
}
}
if (!mirrorsNoRollback.isEmpty()) {
_dbClient.updateObject(mirrorsNoRollback);
mirrors.removeAll(mirrorsNoRollback);
}
if (!mirrors.isEmpty()) {
List<URI> mirrorURIsToRollback = new ArrayList<URI>(transform(mirrors, FCTN_MIRROR_TO_URI));
String mirrorNativeIds = Joiner.on(", ").join(transform(mirrors, fctnBlockObjectToNativeID()));
if (mirrorIsPausable(mirrors)) {
_log.info("Attempting to fracture {} for rollback", mirrorNativeIds);
fractureMirror(storage, mirrorURIsToRollback, isCG, false, taskId);
}
_log.info("Attempting to detach {} for rollback", mirrorNativeIds);
detachMirror(storage, mirrorURIsToRollback, isCG, false, taskId);
_log.info("Attempting to delete {} for rollback", mirrorNativeIds);
deleteMirror(storage, mirrorURIsToRollback, isCG, taskId);
}
WorkflowStepCompleter.stepSucceded(taskId);
} catch (InternalException ie) {
_log.error(String.format("rollbackMirror Failed - Array:%s, Mirror:%s", storage, Joiner.on("\t").join(mirrorList)));
doFailTask(Volume.class, mirrorList, taskId, ie);
WorkflowStepCompleter.stepFailed(taskId, ie);
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(taskId, serviceError);
doFailTask(Volume.class, mirrorList, taskId, serviceError);
}
}
use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI in project coprhd-controller by CoprHD.
the class BlockDeviceController method rollbackListMirror.
public void rollbackListMirror(URI storage, List<URI> mirrorList, String taskId) {
WorkflowStepCompleter.stepExecuting(taskId);
try {
List<BlockMirror> mirrorsNoRollback = new ArrayList<BlockMirror>();
List<BlockMirror> mirrorsToRollback = new ArrayList<BlockMirror>();
Iterator<BlockMirror> mirrorIterator = _dbClient.queryIterativeObjects(BlockMirror.class, mirrorList);
while (mirrorIterator.hasNext()) {
BlockMirror mirror = mirrorIterator.next();
if (mirror != null && !mirror.getInactive()) {
if (isNullOrEmpty(mirror.getNativeId())) {
mirror.setInactive(true);
mirrorsNoRollback.add(mirror);
} else {
mirrorsToRollback.add(mirror);
}
}
}
if (!mirrorsNoRollback.isEmpty()) {
_dbClient.updateObject(mirrorsNoRollback);
}
if (!mirrorsToRollback.isEmpty()) {
List<URI> mirrorURIsToRollback = new ArrayList<URI>(transform(mirrorsToRollback, FCTN_MIRROR_TO_URI));
String mirrorNativeIds = Joiner.on(", ").join(transform(mirrorsToRollback, fctnBlockObjectToNativeID()));
if (mirrorIsPausable(mirrorsToRollback)) {
_log.info("Attempting to fracture {} for rollback", mirrorNativeIds);
fractureMirror(storage, mirrorURIsToRollback, false, false, generateStepIdForDependentCallDuringRollback());
}
_log.info("Attempting to detach {} for rollback", mirrorNativeIds);
detachMirror(storage, mirrorURIsToRollback, false, false, generateStepIdForDependentCallDuringRollback());
_log.info("Attempting to delete {} for rollback", mirrorNativeIds);
deleteMirror(storage, mirrorURIsToRollback, false, generateStepIdForDependentCallDuringRollback());
}
WorkflowStepCompleter.stepSucceded(taskId);
} catch (InternalException ie) {
_log.error(String.format("rollbackListMirror failed - Array:%s, Mirror:%s", storage, Joiner.on("\t").join(mirrorList)));
doFailTask(BlockMirror.class, mirrorList, taskId, ie);
WorkflowStepCompleter.stepFailed(taskId, ie);
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(taskId, serviceError);
doFailTask(BlockMirror.class, mirrorList, taskId, serviceError);
}
}
use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method deactivateMirror.
/**
* {@inheritDoc}
*
* @throws ControllerException
*/
@SuppressWarnings("unchecked")
@Override
public TaskList deactivateMirror(StorageSystem storageSystem, URI mirrorURI, String taskId, String deleteType) throws ControllerException {
_log.info("START: deactivate mirror");
TaskList taskList = new TaskList();
BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, mirrorURI);
Volume sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
List<URI> mirrorURIs = new ArrayList<URI>();
boolean isCG = sourceVolume.isInCG();
List<URI> promotees = null;
if (isCG) {
// for group mirrors, deactivate task will detach and delete the mirror that user asked to deactivate, and
// promote other mirrors
// in the group
Map<BlockMirror, Volume> groupMirrorSourceMap = getGroupMirrorSourceMap(mirror, sourceVolume);
mirrorURIs = new ArrayList<URI>(transform(new ArrayList<BlockMirror>(groupMirrorSourceMap.keySet()), FCTN_MIRROR_TO_URI));
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
// Create a task for each source/mirror pair.
for (Entry<BlockMirror, Volume> entry : groupMirrorSourceMap.entrySet()) {
Operation op = _dbClient.createTaskOpStatus(Volume.class, entry.getValue().getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, entry.getKey().getId().toString());
taskList.getTaskList().add(toTask(entry.getValue(), Arrays.asList(entry.getKey()), taskId, op));
}
} else {
// deactivate (detach and delete) mirrorURI
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, mirrorURI.toString());
taskList.getTaskList().add(toTask(sourceVolume, Arrays.asList(mirror), taskId, op));
// detach and promote other mirrors in the group
groupMirrorSourceMap.remove(mirror);
populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
// detached mirrors (except the one deleted), will be promoted to regular block volumes
promotees = preparePromotedVolumes(new ArrayList<BlockMirror>(groupMirrorSourceMap.keySet()), taskList, taskId);
}
} else {
// for single volume mirror, deactivate task will detach and delete the mirror
mirrorURIs = Arrays.asList(mirror.getId());
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_MIRROR, mirror.getId().toString());
taskList.getTaskList().add(toTask(sourceVolume, Arrays.asList(mirror), taskId, op));
}
try {
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
_log.info("Perform ViPR-only delete for mirrors %s", mirrorURIs);
// Perform any database cleanup that is required.
cleanupForViPROnlyMirrorDelete(mirrorURIs);
// Mark them inactive.
_dbClient.markForDeletion(_dbClient.queryObject(BlockMirror.class, mirrorURIs));
// Update the task status for each snapshot to successfully completed.
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
Volume taskVolume = _dbClient.queryObject(Volume.class, taskResourceRep.getResource().getId());
Operation op = taskVolume.getOpStatus().get(taskId);
op.ready("Continuous copy succesfully deleted from ViPR");
taskVolume.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.updateObject(taskVolume);
}
} else {
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
controller.deactivateMirror(storageSystem.getId(), mirrorURIs, promotees, isCG, taskId);
}
} catch (ControllerException e) {
String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirror.getId().toString(), e.getMessage());
_log.error(errorMsg);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
_dbClient.error(URIUtil.getModelClass(taskResourceRep.getResource().getId()), taskResourceRep.getResource().getId(), taskId, e);
}
// Mark the mirrors that would have been promoted inactive.
if (promotees != null && !promotees.isEmpty()) {
List<Volume> volumes = _dbClient.queryObject(Volume.class, promotees);
for (Volume volume : volumes) {
volume.setInactive(true);
}
_dbClient.updateObject(volumes);
}
} catch (Exception e) {
String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirror.getId().toString(), e.getMessage());
_log.error(errorMsg);
ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(sc.getMessage());
_dbClient.error(URIUtil.getModelClass(taskResourceRep.getResource().getId()), taskResourceRep.getResource().getId(), taskId, sc);
}
// Mark the mirrors that would have been promoted inactive.
if (promotees != null && !promotees.isEmpty()) {
List<Volume> volumes = _dbClient.queryObject(Volume.class, promotees);
for (Volume volume : volumes) {
volume.setInactive(true);
}
_dbClient.updateObject(volumes);
}
}
return taskList;
}
use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method pauseNativeContinuousCopies.
/**
* {@inheritDoc}
*
* @throws ControllerException
*/
@Override
public TaskList pauseNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, List<BlockMirror> blockMirrors, Boolean sync, String taskId) throws ControllerException {
TaskList taskList = new TaskList();
List<URI> mirrorUris = new ArrayList<>();
// Assume all continuous copies are to be paused
List<BlockMirror> pausedMirrors = new ArrayList<>();
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 (mirrorIsPausable(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.FRACTURE_VOLUME_MIRROR);
op.setMessage("No continuous copy can be paused");
_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 paused
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 (mirrorIsResumable(mirror)) {
// extract mirrors that are in "paused" state
pausedMirrors.add(mirror);
} else if (!mirrorIsPausable(mirror)) {
// if there is a mirror is not in paused state, and not pausable, throw exception
throw APIException.badRequests.cannotPauseContinuousCopyWithSyncState(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
} else if (mirrorIsResynchronizing(mirror)) {
throw APIException.badRequests.cannotPauseContinuousCopyWhileResynchronizing(mirror.getId(), mirror.getSyncState(), sourceVolume.getId());
} else {
// otherwise, place mirror a list... get ready to pause
mirrorUris.add(mirror.getId());
}
}
}
/*
* if all mirrors are paused, then there is no task to do.
* Return a successful task
*/
if (!pausedMirrors.isEmpty() && mirrorUris.isEmpty()) {
// If the mirrors is already paused, there would be no need to queue another request to activate it again.
Operation op = new Operation();
op.ready();
op.setResourceType(ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR);
op.setMessage("The continuous copies are already paused");
_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.FRACTURE_VOLUME_MIRROR, mirrorTargetCommaDelimList);
taskList.getTaskList().add(toTask(sourceVolume, mirrorsToProcess, taskId, op));
} else {
populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.FRACTURE_VOLUME_MIRROR);
}
try {
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
controller.pauseNativeContinuousCopies(storageSystem.getId(), mirrorUris, sync, taskId);
} catch (ControllerException e) {
String errorMsg = format("Failed to pause continuous copies for source volume %s", sourceVolume.getId());
_log.error(errorMsg, e);
_dbClient.error(Volume.class, sourceVolume.getId(), taskId, e);
}
}
return taskList;
}
use of com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_MIRROR_TO_URI in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method stopNativeContinuousCopies.
@Override
public TaskList stopNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, List<URI> mirrors, String taskId) throws ControllerException {
TaskList taskList = new TaskList();
List<URI> copiesToStop = null;
List<BlockMirror> copies = null;
Map<BlockMirror, Volume> groupMirrorSourceMap = null;
boolean isCG = sourceVolume.isInCG();
if (isCG) {
if (mirrors == null) {
for (String uriStr : sourceVolume.getMirrors()) {
BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
if (!mirror.getInactive()) {
groupMirrorSourceMap = getGroupMirrorSourceMap(mirror, sourceVolume);
// only process one mirror group
break;
}
}
} else {
groupMirrorSourceMap = getGroupMirrorSourceMap(mirrors.get(0), sourceVolume);
}
if (groupMirrorSourceMap == null || groupMirrorSourceMap.isEmpty()) {
Operation op = new Operation();
op.ready();
op.setResourceType(ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
op.setMessage("No continuous copy can be detached");
_dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
return taskList;
}
copiesToStop = new ArrayList<URI>(transform(groupMirrorSourceMap.keySet(), FCTN_MIRROR_TO_URI));
} else {
List<BlockMirror> blockMirrors = null;
if (mirrors != null) {
blockMirrors = new ArrayList<BlockMirror>();
for (URI mirrorURI : mirrors) {
BlockMirror blockMirror = _dbClient.queryObject(BlockMirror.class, mirrorURI);
blockMirrors.add(blockMirror);
}
}
copiesToStop = getCopiesToStop(blockMirrors, sourceVolume);
// Ensure we don't attempt to stop any lingering inactive copies
removeIf(copiesToStop, isMirrorInactivePredicate());
if (copiesToStop.size() == 0) {
Operation op = new Operation();
op.ready();
op.setResourceType(ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
op.setMessage("No continuous copy can be detached");
_dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, op);
taskList.getTaskList().add(toTask(sourceVolume, taskId, op));
return taskList;
}
}
copies = _dbClient.queryObject(BlockMirror.class, copiesToStop);
// Stopped copies will be promoted to regular block volumes
List<URI> promotees = preparePromotedVolumes(copies, taskList, taskId);
if (!isCG) {
String mirrorTargetCommaDelimList = Joiner.on(',').join(copiesToStop);
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR, mirrorTargetCommaDelimList);
taskList.getTaskList().add(toTask(sourceVolume, copies, taskId, op));
} else {
populateTaskList(sourceVolume, groupMirrorSourceMap, taskList, taskId, ResourceOperationTypeEnum.DETACH_BLOCK_MIRROR);
}
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
try {
controller.detachNativeContinuousCopies(storageSystem.getId(), copiesToStop, promotees, taskId);
} catch (ControllerException ce) {
String errorMsg = format("Failed to stop continuous copies for volume %s: %s", sourceVolume.getId(), ce.getMessage());
List<Volume> volumes = _dbClient.queryObject(Volume.class, promotees);
for (Volume volume : volumes) {
volume.setInactive(true);
}
_dbClient.persistObject(volumes);
_log.error(errorMsg, ce);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
_dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, ce);
}
throw ce;
}
return taskList;
}
Aggregations