use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method deleteSnapshot.
/**
* {@inheritDoc}
*/
@Override
public void deleteSnapshot(BlockSnapshot requestedSnapshot, List<BlockSnapshot> allSnapshots, String taskId, String deleteType) {
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
s_logger.info("Executing ViPR-only snapshot deletion");
// Do any cleanup necessary for the ViPR only delete.
cleanupForViPROnlySnapshotDelete(allSnapshots);
// Mark them inactive.
_dbClient.markForDeletion(allSnapshots);
// Note that we must go back to the database to get the latest snapshot status map.
for (BlockSnapshot snapshot : allSnapshots) {
BlockSnapshot updatedSnapshot = _dbClient.queryObject(BlockSnapshot.class, snapshot.getId());
Operation op = updatedSnapshot.getOpStatus().get(taskId);
op.ready("Snapshot succesfully deleted from ViPR");
updatedSnapshot.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.updateObject(updatedSnapshot);
}
} else {
StorageSystem device = _dbClient.queryObject(StorageSystem.class, requestedSnapshot.getStorageController());
BlockController controller = getController(BlockController.class, device.getSystemType());
controller.deleteSnapshot(device.getId(), requestedSnapshot.getId(), taskId);
}
}
use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method activateConsistencyGroupSnapshot.
/**
* Activate the specified Consistency Group Snapshot
*
* @prereq Create consistency group snapshot as inactive
*
* @param consistencyGroupId
* - Consistency group URI
* @param snapshotId
* - Consistency group snapshot URI
*
* @brief Activate consistency group snapshot
* @return TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/activate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep activateConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.ACTIVATE_CONSISTENCY_GROUP_SNAPSHOT);
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
// check for backend CG
if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
_log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
throw APIException.badRequests.cannotCreateSnapshotOfCG();
}
final StorageSystem device = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
final BlockController controller = getController(BlockController.class, device.getSystemType());
final String task = UUID.randomUUID().toString();
// activate it again.
if (snapshot.getIsSyncActive()) {
op.ready();
op.setMessage("The consistency group snapshot is already active.");
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
return toTask(snapshot, task, op);
}
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
try {
final List<URI> snapshotList = new ArrayList<URI>();
// Query all the snapshots by snapshot label
final List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
// Build a URI list with all the snapshots ids
for (BlockSnapshot snap : snaps) {
snapshotList.add(snap.getId());
}
// Activate snapshots
controller.activateSnapshot(device.getId(), snapshotList, task);
} catch (final ControllerException e) {
throw new ServiceCodeException(CONTROLLER_ERROR, e, "An exception occurred when activating consistency group snapshot {0}. Caused by: {1}", new Object[] { snapshotId, e.getMessage() });
}
auditBlockConsistencyGroup(OperationTypeEnum.ACTIVATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
return toTask(snapshot, task, op);
}
use of com.emc.storageos.volumecontroller.BlockController 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.volumecontroller.BlockController 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.volumecontroller.BlockController 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;
}
Aggregations