use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method deactivateMirror.
/**
* {@inheritDoc}
*/
@Override
public TaskList deactivateMirror(StorageSystem vplexStorageSystem, URI mirrorURI, String taskId, String deleteType) {
TaskList taskList = new TaskList();
try {
VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, mirrorURI);
Volume sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
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));
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
s_logger.info("Perform ViPR-only delete for VPLEX mirrors %s", mirrorURI);
// Perform any database cleanup that is required.
cleanupForViPROnlyMirrorDelete(Arrays.asList(mirrorURI));
// Mark them inactive.
_dbClient.markForDeletion(_dbClient.queryObject(VplexMirror.class, mirrorURI));
// We must get the volume from the DB again, to properly update the status.
sourceVolume = _dbClient.queryObject(Volume.class, mirror.getSource().getURI());
op = sourceVolume.getOpStatus().get(taskId);
op.ready("VPLEX continuous copy succesfully deleted from ViPR");
sourceVolume.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.updateObject(sourceVolume);
} else {
List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
// Add a descriptor for each of the associated volumes.There will be only one associated volume
if (mirror.getAssociatedVolumes() != null) {
for (String assocVolId : mirror.getAssociatedVolumes()) {
Volume assocVolume = _dbClient.queryObject(Volume.class, URI.create(assocVolId));
if (assocVolume != null && !assocVolume.getInactive() && assocVolume.getNativeId() != null) {
// In order to add descriptor for the the backend volumes that needs to be
// deleted we are checking for volume nativeId as well, because its possible
// that we were not able to create backend volume due to SMIS communication
// and rollback didn't clean up VplexMirror and its associated volumes in
// database. So in such a case nativeId will be null and we just want to skip
// sending this volume to SMIS, else it fails with null reference when user
// attempts to cleanup this failed mirror.
VolumeDescriptor assocDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, assocVolume.getStorageController(), assocVolume.getId(), null, null);
descriptors.add(assocDesc);
}
}
}
VPlexController controller = getController();
controller.deactivateMirror(vplexStorageSystem.getId(), mirror.getId(), descriptors, taskId);
}
} catch (ControllerException e) {
String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
s_logger.error(errorMsg, e);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
_dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, e);
}
} catch (Exception e) {
String errorMsg = format("Failed to deactivate continuous copy %s: %s", mirrorURI.toString(), e.getMessage());
s_logger.error(errorMsg, e);
ServiceCoded sc = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(sc.getMessage());
_dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, sc);
}
}
return taskList;
}
use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method addDescriptorsForVplexMirrors.
public void addDescriptorsForVplexMirrors(List<VolumeDescriptor> descriptors, Volume vplexVolume) {
if (vplexVolume.getMirrors() != null && vplexVolume.getMirrors().isEmpty() == false) {
for (String mirrorId : vplexVolume.getMirrors()) {
VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, URI.create(mirrorId));
if (mirror != null && !mirror.getInactive()) {
if (null != mirror.getAssociatedVolumes()) {
for (String assocVolumeId : mirror.getAssociatedVolumes()) {
Volume volume = _dbClient.queryObject(Volume.class, URI.create(assocVolumeId));
if (volume != null && !volume.getInactive()) {
VolumeDescriptor volDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, volume.getStorageController(), URI.create(assocVolumeId), null, null);
descriptors.add(volDesc);
}
}
}
}
}
}
}
use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class BlockService method validateContinuousCopyName.
private void validateContinuousCopyName(String name, Integer count, Volume sourceVolume) {
if (sourceVolume.getMirrors() == null || sourceVolume.getMirrors().isEmpty()) {
return;
}
boolean vplexVolume = checkIfVolumeIsForVplex(sourceVolume.getId());
List<String> dupList = new ArrayList<String>();
for (String mirrorURI : sourceVolume.getMirrors()) {
if (vplexVolume) {
VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, URI.create(mirrorURI));
if (!mirror.getInactive() && ((count > 1 && mirror.getLabel().matches("^" + name + "\\-\\d+$")) || (count == 1 && name.equals(mirror.getLabel())))) {
dupList.add(mirror.getLabel());
}
} else {
BlockMirror mirror = _dbClient.queryObject(BlockMirror.class, URI.create(mirrorURI));
if (null != mirror && !mirror.getInactive() && ((count > 1 && mirror.getLabel().matches("^" + name + "\\-\\d+$")) || (count == 1 && name.equals(mirror.getLabel())))) {
dupList.add(mirror.getLabel());
}
}
}
if (!dupList.isEmpty()) {
throw APIException.badRequests.blockSourceAlreadyHasContinuousCopiesOfSameName(dupList);
}
}
use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class BlockService method stopVplexMirrors.
/**
* Stop the specified vplex mirror(s) for the source volume
*
* @param id
* the URN of a ViPR Source volume
* @param copyID
* Copy volume ID, none specified stops all copies
*
* @return TaskList
*/
private TaskList stopVplexMirrors(URI id, URI copyID) {
ArgValidator.checkFieldUriType(id, Volume.class, "id");
Volume sourceVolume = queryVolumeResource(id);
ArgValidator.checkEntity(sourceVolume, id, true);
StringSet mirrors = sourceVolume.getMirrors();
if (mirrors == null || mirrors.isEmpty()) {
throw APIException.badRequests.invalidParameterVolumeHasNoContinuousCopies(sourceVolume.getId());
}
ArrayList<URI> mirrorList = null;
if (copyID != null) {
ArgValidator.checkFieldUriType(copyID, VplexMirror.class, "copyID");
VplexMirror mirror = queryVplexMirror(copyID);
ArgValidator.checkEntity(mirror, copyID, true);
if (!mirror.getSource().getURI().equals(id)) {
throw APIException.badRequests.invalidParameterBlockCopyDoesNotBelongToVolume(copyID, id);
} else {
mirrorList = new ArrayList();
mirrorList.add(mirror.getId());
}
}
String task = UUID.randomUUID().toString();
BlockServiceApi blockServiceApi;
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, sourceVolume.getStorageController());
blockServiceApi = getBlockServiceImpl(DiscoveredDataObject.Type.vplex.name());
return blockServiceApi.stopNativeContinuousCopies(storageSystem, sourceVolume, mirrorList, task);
}
use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class BlockService method getNativeContinuousCopies.
/**
* List volume mirrors
*
* @prereq none
*
* @param id
* the URN of a ViPR Volume to list mirrors
*
* @brief List volume mirrors
* @return Volume mirror response containing a list of mirror identifiers
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public MirrorList getNativeContinuousCopies(@PathParam("id") URI id) {
MirrorList list = new MirrorList();
ArgValidator.checkFieldUriType(id, Volume.class, "id");
Volume sourceVolume = queryVolumeResource(id);
boolean vplexVolume = checkIfVolumeIsForVplex(id);
StringSet sourceVolumeMirrors = sourceVolume.getMirrors();
if (sourceVolumeMirrors == null || sourceVolumeMirrors.isEmpty()) {
return list;
}
for (String uriStr : sourceVolumeMirrors) {
if (vplexVolume) {
VplexMirror vplexMirror = _dbClient.queryObject(VplexMirror.class, URI.create(uriStr));
if (vplexMirror == null || vplexMirror.getInactive()) {
_log.warn("Stale mirror {} found for volume {}", uriStr, sourceVolume.getId());
continue;
}
list.getMirrorList().add(toNamedRelatedResource(vplexMirror));
} else {
BlockMirror blockMirror = _dbClient.queryObject(BlockMirror.class, URI.create(uriStr));
if (blockMirror == null || blockMirror.getInactive()) {
_log.warn("Stale mirror {} found for volume {}", uriStr, sourceVolume.getId());
continue;
}
list.getMirrorList().add(toNamedRelatedResource(blockMirror));
}
}
return list;
}
Aggregations