use of com.emc.storageos.db.client.model.Operation 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.model.Operation in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method startNativeContinuousCopies.
@Override
public TaskList startNativeContinuousCopies(StorageSystem storageSystem, Volume sourceVolume, VirtualPool sourceVirtualPool, VirtualPoolCapabilityValuesWrapper capabilities, NativeContinuousCopyCreate param, String taskId) throws ControllerException {
if (!((storageSystem.getUsingSmis80() && storageSystem.deviceIsType(Type.vmax)) || storageSystem.deviceIsType(Type.vnxblock))) {
validateNotAConsistencyGroupVolume(sourceVolume, sourceVirtualPool);
}
TaskList taskList = new TaskList();
// Currently, this will create a single mirror and add it to the source volume
// Two steps: first place the mirror and then prepare the mirror.
List<Recommendation> volumeRecommendations = new ArrayList<Recommendation>();
// Prepare mirror.
int volumeCounter = 1;
int volumeCount = capabilities.getResourceCount();
String volumeLabel = param.getName();
List<Volume> preparedVolumes = new ArrayList<Volume>();
// If the requested volume is part of CG
if (sourceVolume.isInCG()) {
if (volumeCount > 1) {
throw APIException.badRequests.invalidMirrorCountForVolumesInConsistencyGroup();
}
URIQueryResultList cgVolumeList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumesByConsistencyGroup(sourceVolume.getConsistencyGroup()), cgVolumeList);
// recommendation
while (cgVolumeList.iterator().hasNext()) {
Volume cgSourceVolume = _dbClient.queryObject(Volume.class, cgVolumeList.iterator().next());
_log.info("Processing volume {} in CG {}", cgSourceVolume.getId(), sourceVolume.getConsistencyGroup());
VirtualPool cgVolumeVPool = _dbClient.queryObject(VirtualPool.class, cgSourceVolume.getVirtualPool());
populateVolumeRecommendations(capabilities, cgVolumeVPool, cgSourceVolume, taskId, taskList, volumeCount, volumeCounter, volumeLabel, preparedVolumes, volumeRecommendations);
}
} else {
// Source Volume without CG
populateVolumeRecommendations(capabilities, sourceVirtualPool, sourceVolume, taskId, taskList, volumeCount, volumeCounter, volumeLabel, preparedVolumes, volumeRecommendations);
}
List<URI> mirrorList = new ArrayList<URI>(preparedVolumes.size());
for (Volume volume : preparedVolumes) {
Operation op = _dbClient.createTaskOpStatus(BlockMirror.class, volume.getId(), taskId, ResourceOperationTypeEnum.ATTACH_BLOCK_MIRROR);
volume.getOpStatus().put(taskId, op);
TaskResourceRep volumeTask = toTask(volume, taskId, op);
taskList.getTaskList().add(volumeTask);
mirrorList.add(volume.getId());
}
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
try {
controller.attachNativeContinuousCopies(storageSystem.getId(), sourceVolume.getId(), mirrorList, taskId);
} catch (ControllerException ce) {
String errorMsg = format("Failed to start continuous copies on volume %s: %s", sourceVolume.getId(), ce.getMessage());
_log.error(errorMsg, ce);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
Operation statusUpdate = new Operation(Operation.Status.error.name(), errorMsg);
_dbClient.updateTaskOpStatus(Volume.class, taskResourceRep.getResource().getId(), taskId, statusUpdate);
}
throw ce;
}
return taskList;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method establishVolumeAndNativeContinuousCopyGroupRelation.
/**
* {@inheritDoc}
*/
@Override
public TaskResourceRep establishVolumeAndNativeContinuousCopyGroupRelation(StorageSystem storageSystem, Volume sourceVolume, BlockMirror blockMirror, String taskId) throws ControllerException {
_log.info("START establish Volume and Mirror group relation");
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.ESTABLISH_VOLUME_MIRROR, blockMirror.getId().toString());
try {
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
controller.establishVolumeAndNativeContinuousCopyGroupRelation(storageSystem.getId(), sourceVolume.getId(), blockMirror.getId(), taskId);
} catch (ControllerException e) {
String errorMsg = format("Failed to establish group relation between volume group and mirror group." + "Source volume: %s, Mirror: %s", sourceVolume.getId(), blockMirror.getId());
_log.error(errorMsg, e);
_dbClient.error(Volume.class, sourceVolume.getId(), taskId, e);
}
return toTask(sourceVolume, Arrays.asList(blockMirror), taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockMirrorServiceApiImpl method addTask.
private void addTask(TaskList taskList, DataObject object, String taskId, ResourceOperationTypeEnum opType) {
Operation op = _dbClient.createTaskOpStatus(object.getClass(), object.getId(), taskId, opType);
taskList.addTask(toTask(object, taskId, op));
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockService method performProtectionAction.
/**
* Since all of the protection operations are very similar, this method does all of the work.
* We keep the actual REST methods separate mostly for the purpose of documentation generators.
*
* @param id
* the URN of a ViPR source volume
* @param copyID
* id of the target volume
* @param pointInTime
* any point in time used for failover, specified in UTC.
* Allowed values: "yyyy-MM-dd_HH:mm:ss" formatted date or datetime in milliseconds. Can be
* null.
* @param op
* operation to perform (pause, stop, failover, etc)
* @return task resource rep
* @throws InternalException
*/
private TaskResourceRep performProtectionAction(URI id, Copy copy, String op) throws InternalException {
ArgValidator.checkFieldUriType(copy.getCopyID(), Volume.class, "copyID");
// Get the volume associated with the URI
Volume volume = queryVolumeResource(id);
Volume copyVolume = queryVolumeResource(copy.getCopyID());
ArgValidator.checkEntity(volume, id, true);
ArgValidator.checkEntity(copyVolume, copy.getCopyID(), true);
if (op.equalsIgnoreCase(ProtectionOp.SWAP.getRestOp()) && !NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
ExportUtils.validateConsistencyGroupBookmarksExported(_dbClient, volume.getConsistencyGroup());
}
// cancel operations)
if ((op.equalsIgnoreCase(ProtectionOp.CHANGE_ACCESS_MODE.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER.getRestOp()) || op.equalsIgnoreCase(ProtectionOp.FAILOVER_CANCEL.getRestOp())) && !NullColumnValueGetter.isNullURI(volume.getConsistencyGroup()) && !volume.getConsistencyGroup().equals(copyVolume.getConsistencyGroup())) {
throw APIException.badRequests.invalidConsistencyGroupsForProtectionOperation();
}
// Catch any attempts to use an invalid access mode
if (op.equalsIgnoreCase(ProtectionOp.CHANGE_ACCESS_MODE.getRestOp()) && !Copy.ImageAccessMode.DIRECT_ACCESS.name().equalsIgnoreCase(copy.getAccessMode())) {
throw APIException.badRequests.unsupportedAccessMode(copy.getAccessMode());
}
if (isNullURI(volume.getProtectionController())) {
throw new ServiceCodeException(ServiceCode.IO_ERROR, "Attempt to do protection link management on unprotected volume: {0}", new Object[] { volume.getWWN() });
}
// Make sure that we don't have some pending
// operation against the volume
checkForPendingTasks(Arrays.asList(volume.getTenant().getURI()), Arrays.asList(volume));
String task = UUID.randomUUID().toString();
Operation status = new Operation();
status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
_dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, status);
_log.info(String.format("Protection %s --- VolumeId id: %s on Protection Appliance: %s", task, id, volume.getProtectionController()));
ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, volume.getProtectionController());
String deviceType = system.getSystemType();
if (!deviceType.equals(DiscoveredDataObject.Type.rp.name())) {
throw APIException.badRequests.protectionForRpClusters();
}
RPController controller = getController(RPController.class, system.getSystemType());
controller.performProtectionOperation(system.getId(), id, copy.getCopyID(), copy.getPointInTime(), copy.getAccessMode(), op, task);
/*
* auditOp(OperationTypeEnum.PERFORM_PROTECTION_ACTION, true, AuditLogManager.AUDITOP_BEGIN,
* op, copyID.toString(), id.toString(), system.getId().toString());
*/
return toTask(volume, task, status);
}
Aggregations