use of com.emc.storageos.volumecontroller.BlockController 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;
}
use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.
the class BlockSnapshotService method activate.
/**
* Call will activate this snapshot, essentially establishing the synchronization
* between the source and target. The "heavy lifting" of getting the snapshot
* to the point where it can be activated should have been done by the create.
*
* @prereq Create snapshot as inactive
* @param id [required] - the URN of a ViPR block snapshot to restore from
* @brief Activate snapshot
* @return TaskResourceRep - Task resource object for tracking this operation
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
@Path("/{id}/activate")
public TaskResourceRep activate(@PathParam("id") URI id) {
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT);
ArgValidator.checkFieldUriType(id, BlockSnapshot.class, "id");
BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
// Get the block service API implementation for the snapshot parent volume.
Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Make sure that we don't have some pending
// operation against the parent volume
checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), Arrays.asList(parentVolume));
StorageSystem device = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
BlockController controller = getController(BlockController.class, device.getSystemType());
String task = UUID.randomUUID().toString();
// another request to activate it again.
if (snapshot.getIsSyncActive()) {
op.ready("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);
List<URI> snapshotList = new ArrayList<URI>();
if (!NullColumnValueGetter.isNullURI(snapshot.getConsistencyGroup())) {
List<BlockSnapshot> snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
for (BlockSnapshot snap : snapshots) {
snapshotList.add(snap.getId());
}
} else {
snapshotList.add(id);
}
// If the volume is under protection
if (snapshot.getEmName() != null) {
// RP snapshots cannot be activated so throw exception
throw new ServiceCodeException(API_BAD_REQUEST, "RecoverPoint snapshots cannot be activated.", null);
} else {
controller.activateSnapshot(device.getId(), snapshotList, task);
}
auditOp(OperationTypeEnum.ACTIVATE_VOLUME_SNAPSHOT, true, 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 AbstractBlockServiceApiImpl method resynchronizeSnapshot.
/**
* Resynchronize the passed snapshot from its parent volume.
*
* @param snapshot
* The snapshot to be resynchronized
* @param parentVolume
* The volume to be resynchronized from.
* @param taskId
* The unique task identifier.
*/
@Override
public void resynchronizeSnapshot(BlockSnapshot snapshot, Volume parentVolume, String taskId) {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
controller.resyncSnapshot(storageSystem.getId(), parentVolume.getId(), snapshot.getId(), Boolean.TRUE, taskId);
}
Aggregations