use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class VplexDBCkr 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 VPlexBlockServiceApiImpl method stopNativeContinuousCopies.
/**
* {@inheritDoc}
*/
@Override
public TaskList stopNativeContinuousCopies(StorageSystem vplexStorageSystem, Volume sourceVolume, List<URI> mirrors, String taskId) throws ControllerException {
TaskList taskList = new TaskList();
List<VplexMirror> vplexMirrors = null;
if (mirrors != null) {
vplexMirrors = new ArrayList<VplexMirror>();
for (URI mirrorURI : mirrors) {
VplexMirror vplexMirror = _dbClient.queryObject(VplexMirror.class, mirrorURI);
if (vplexMirror.getDeviceLabel() == null) {
s_logger.error("This Vplex Mirror {} was not created successfully.", vplexMirror.getId());
throw APIException.badRequests.invalidVplexMirror(vplexMirror.getLabel(), vplexMirror.getId().toString());
}
vplexMirrors.add(vplexMirror);
}
}
// If mirrors is null then this will return all mirrors for the source volume.
// This will be mostly case through python script that will just make a call
// to stop mirrors without specifying mirror ID.
// Note : There will be only one mirror for the vplex volume though
List<URI> copiesToStop = getVplexCopiesToStop(vplexMirrors, sourceVolume);
// Removes inactive mirrors
removeIf(copiesToStop, isVplexMirrorInactivePredicate());
String mirrorTargetCommaDelimList = Joiner.on(',').join(copiesToStop);
Operation op = _dbClient.createTaskOpStatus(Volume.class, sourceVolume.getId(), taskId, ResourceOperationTypeEnum.DETACH_VPLEX_LOCAL_MIRROR, mirrorTargetCommaDelimList);
List<VplexMirror> copies = _dbClient.queryObject(VplexMirror.class, copiesToStop);
// Stopped copies will be promoted to vplex volumes.
// Creates volume objects for the mirrors that will be promoted
List<URI> promotees = preparePromotedVolumes(copies, taskList, taskId);
// Add task to the task list
taskList.getTaskList().add(toTask(sourceVolume, copies, taskId, op));
try {
VPlexController controller = getController();
controller.detachContinuousCopies(vplexStorageSystem.getId(), sourceVolume.getId(), copiesToStop, promotees, taskId);
} catch (InternalException e) {
String errorMsg = format("Failed to stop continuous copies for volume %s: %s", sourceVolume.getId(), e.getMessage());
for (TaskResourceRep taskResourceRep : taskList.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
_dbClient.error(Volume.class, taskResourceRep.getResource().getId(), taskId, e);
}
throw e;
}
return taskList;
}
use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method startNativeContinuousCopies.
/**
* {@inheritDoc}
*/
@Override
public TaskList startNativeContinuousCopies(StorageSystem vplexStorageSystem, Volume vplexVolume, VirtualPool sourceVirtualPool, VirtualPoolCapabilityValuesWrapper capabilities, NativeContinuousCopyCreate param, String taskId) throws ControllerException {
// using the target volume of a block snapshot.
if (VPlexUtil.isVolumeBuiltOnBlockSnapshot(_dbClient, vplexVolume)) {
throw APIException.badRequests.mirrorNotAllowedVolumeIsExposedSnapshot(vplexVolume.getId().toString());
}
validateNotAConsistencyGroupVolume(vplexVolume, sourceVirtualPool);
TaskList taskList = new TaskList();
// Currently, For Vplex Local Volume this will create a single mirror and add it
// to the vplex volume. For Vplex Distributed Volume this will create single mirror
// on source and/or HA side and add it to the vplex volume. Two steps: first place
// the mirror and then prepare the mirror.
URI vplexStorageSystemURI = vplexVolume.getStorageController();
// For VPLEX Local volume there will be only one associated volume entry in this set.
StringSet associatedVolumeIds = vplexVolume.getAssociatedVolumes();
if (associatedVolumeIds == null) {
throw InternalServerErrorException.internalServerErrors.noAssociatedVolumesForVPLEXVolume(vplexVolume.forDisplay());
}
VirtualPool sourceMirrorVPool = null;
// Set source mirror vpool
if (!isNullOrEmpty(sourceVirtualPool.getMirrorVirtualPool()) && !NullColumnValueGetter.isNullURI(URI.create(sourceVirtualPool.getMirrorVirtualPool()))) {
sourceMirrorVPool = _dbClient.queryObject(VirtualPool.class, URI.create(sourceVirtualPool.getMirrorVirtualPool()));
}
// Check if volume is distributed and if HA Mirror Vpool is also set
VirtualPool haMirrorVPool = VPlexUtil.getHAMirrorVpool(sourceVirtualPool, associatedVolumeIds, _dbClient);
// Map of backend volume and the mirror pool to target backend volume for the mirror
Map<Volume, VirtualPool> backendVolumeToMirrorVpoolMap = new HashMap<Volume, VirtualPool>();
if (associatedVolumeIds.size() > 1) {
// If associatedVolumeIds size is greater than 1 then its a VPLEX Distributed Volume
updateBackendVolumeToMirrorVpoolMap(vplexVolume, associatedVolumeIds, sourceVirtualPool, sourceMirrorVPool, haMirrorVPool, backendVolumeToMirrorVpoolMap);
} else {
// If we are here that means we need to create mirror for the VPLEX local volume
for (String associatedVolumeId : associatedVolumeIds) {
Volume associatedVolume = _dbClient.queryObject(Volume.class, URI.create(associatedVolumeId));
if (associatedVolume != null) {
backendVolumeToMirrorVpoolMap.put(associatedVolume, sourceMirrorVPool);
}
}
}
// Project is not passed in continuous copies call.
// Implicit assumption to use same project as the source volume.
Project project = _permissionsHelper.getObjectById(vplexVolume.getProject(), Project.class);
Map<Volume, List<Recommendation>> backendvolumeToMirrorRecommendationMap = new HashMap<Volume, List<Recommendation>>();
Map<Volume, VirtualArray> backendvolumeToMirrorVarrayMap = new HashMap<Volume, VirtualArray>();
for (Volume backendVolume : backendVolumeToMirrorVpoolMap.keySet()) {
URI backendVolumeVarrayURI = backendVolume.getVirtualArray();
// Get the VPLEX cluster value from the varray
String cluster = ConnectivityUtil.getVplexClusterForVarray(backendVolumeVarrayURI, vplexStorageSystemURI, _dbClient);
if (cluster.equals(ConnectivityUtil.CLUSTER_UNKNOWN)) {
throw InternalServerErrorException.internalServerErrors.noVplexClusterInfoForVarray(backendVolumeVarrayURI.toString(), vplexStorageSystemURI.toString());
}
VirtualPool backendVolumeVpool = _dbClient.queryObject(VirtualPool.class, backendVolume.getVirtualPool());
VirtualPool mirrorVpool = backendVolumeToMirrorVpoolMap.get(backendVolume);
// Get recommendations for the mirror placement
List<Recommendation> volumeRecommendations = null;
VirtualArray varray = null;
if (mirrorVpool != null) {
// If mirror vpool is provided try to get recommendations using the provided mirror vpool
// Check if any of the varray for mirror vpool is same as that of the source volume varray.
// If yes then get recommendations using that varray.
StringSet mirrorVPoolVarrays = mirrorVpool.getVirtualArrays();
boolean foundMatch = false;
for (String mirrorVPoolVarrayId : mirrorVPoolVarrays) {
if (mirrorVPoolVarrayId.equals(backendVolumeVarrayURI.toString())) {
varray = _dbClient.queryObject(VirtualArray.class, backendVolumeVarrayURI);
volumeRecommendations = _scheduler.getRecommendationsForMirrors(varray, project, backendVolumeVpool, mirrorVpool, capabilities, vplexStorageSystemURI, backendVolume.getStorageController(), cluster);
foundMatch = true;
break;
}
}
if (!foundMatch) {
s_logger.info("Mirror Vpool varray is different than the source vpool varray");
// with the source volume VPLEX system.
for (String mirrorVPoolVarrayId : mirrorVPoolVarrays) {
if (VPlexUtil.checkIfVarrayContainsSpecifiedVplexSystem(mirrorVPoolVarrayId, cluster, vplexStorageSystemURI, _dbClient)) {
varray = _dbClient.queryObject(VirtualArray.class, URI.create(mirrorVPoolVarrayId));
volumeRecommendations = _scheduler.getRecommendationsForMirrors(varray, project, backendVolumeVpool, mirrorVpool, capabilities, vplexStorageSystemURI, backendVolume.getStorageController(), cluster);
if (!volumeRecommendations.isEmpty()) {
foundMatch = true;
break;
} else {
s_logger.info("Tried to get recommemdations using varray {} {}. ", varray.getId(), varray.getLabel());
}
}
}
}
} else {
if (sourceVirtualPool.getHighAvailability().equals(VirtualPool.HighAvailabilityType.vplex_local.name())) {
s_logger.info("Mirror vpool is not specified, use the source volume virtual pool and virtual array");
// In case of Vplex local if mirror pool is not provided then we can use source vpool as mirror vpool.
sourceMirrorVPool = backendVolumeVpool;
mirrorVpool = backendVolumeVpool;
backendVolumeToMirrorVpoolMap.put(backendVolume, sourceMirrorVPool);
// Separate Mirror vpool is not provided so use the source volume vpool and varray for
// getting recommendations.Here sourceVirtualPool and mirrorVPool will be same.
varray = _dbClient.queryObject(VirtualArray.class, backendVolumeVarrayURI);
volumeRecommendations = _scheduler.getRecommendationsForMirrors(varray, project, backendVolumeVpool, mirrorVpool, capabilities, vplexStorageSystemURI, backendVolume.getStorageController(), cluster);
}
}
if (mirrorVpool == null) {
throw APIException.badRequests.noMirrorVpoolForVplexVolume(vplexVolume.getLabel());
}
if (varray == null) {
throw APIException.badRequests.noVarrayForMirrorVpoolWithExpectedVplex(mirrorVpool.getLabel(), vplexStorageSystem.getLabel(), cluster);
}
if (volumeRecommendations == null || volumeRecommendations.isEmpty()) {
if (volumeRecommendations.isEmpty()) {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, backendVolume.getStorageController());
throw APIException.badRequests.noMatchingStoragePoolsForContinuousCopiesVpoolForVplex(varray.getLabel(), sourceMirrorVPool.getLabel(), storageSystem.getLabel());
}
}
// Add mirror recommendations for the backend volume to the map
backendvolumeToMirrorRecommendationMap.put(backendVolume, volumeRecommendations);
backendvolumeToMirrorVarrayMap.put(backendVolume, varray);
}
// Prepare mirror.
int varrayCount = 0;
int volumeCounter = 1;
// volumeCount will be always 1 for now
int volumeCount = capabilities.getResourceCount();
String volumeLabel = param.getName();
List<URI> allVolumes = new ArrayList<URI>();
List<URI> allMirrors = new ArrayList<URI>();
List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
// Currently only one local mirror is supported for the VPLEX local virtual volume
List<VplexMirror> preparedMirrors = new ArrayList<VplexMirror>();
for (Volume backendVolume : backendvolumeToMirrorRecommendationMap.keySet()) {
List<Recommendation> volumeRecommendations = backendvolumeToMirrorRecommendationMap.get(backendVolume);
VirtualArray varray = backendvolumeToMirrorVarrayMap.get(backendVolume);
VirtualPool mirrorVpool = backendVolumeToMirrorVpoolMap.get(backendVolume);
long thinVolumePreAllocationSize = 0;
if (null != mirrorVpool.getThinVolumePreAllocationPercentage()) {
thinVolumePreAllocationSize = VirtualPoolUtil.getThinVolumePreAllocationSize(mirrorVpool.getThinVolumePreAllocationPercentage(), vplexVolume.getCapacity());
}
for (Recommendation volumeRecommendation : volumeRecommendations) {
VPlexRecommendation vplexRecommendation = (VPlexRecommendation) volumeRecommendation;
StringBuilder mirrorLabelBuilder = new StringBuilder(volumeLabel);
if (backendVolume.getVirtualArray().equals(vplexVolume.getVirtualArray())) {
varrayCount = 0;
} else {
varrayCount = 1;
}
mirrorLabelBuilder.append('-').append(varrayCount);
if (volumeCount > 1) {
mirrorLabelBuilder.append('-').append(volumeCounter++);
}
// Create mirror object
VplexMirror createdMirror = initializeMirror(vplexVolume, mirrorVpool, varray, mirrorLabelBuilder.toString(), thinVolumePreAllocationSize, _dbClient);
preparedMirrors.add(createdMirror);
Operation op = _dbClient.createTaskOpStatus(VplexMirror.class, createdMirror.getId(), taskId, ResourceOperationTypeEnum.ATTACH_VPLEX_LOCAL_MIRROR);
s_logger.info("Prepared mirror {}", createdMirror.getId());
allMirrors.add(createdMirror.getId());
// Add descriptor for the mirror.
VolumeDescriptor descriptor = new VolumeDescriptor(VolumeDescriptor.Type.VPLEX_LOCAL_MIRROR, vplexStorageSystemURI, createdMirror.getId(), null, capabilities);
descriptors.add(descriptor);
// Create backend volume object and add it to the VplexMirror created above.
Volume volume = prepareVolume(createdMirror, backendVolume, mirrorVpool, varray, vplexRecommendation.getSourceStorageSystem(), vplexRecommendation.getSourceStoragePool(), mirrorLabelBuilder.toString(), thinVolumePreAllocationSize, capabilities, _dbClient);
op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
_dbClient.createTaskOpStatus(Volume.class, volume.getId(), taskId, op);
URI volumeId = volume.getId();
allVolumes.add(volumeId);
s_logger.info("Prepared volume {}", volumeId);
// Add descriptor for the backend volume
descriptor = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, vplexRecommendation.getSourceStorageSystem(), volumeId, vplexRecommendation.getSourceStoragePool(), capabilities);
descriptors.add(descriptor);
}
}
Collection<URI> mirrorTargetIds = Collections2.transform(preparedMirrors, FCTN_VPLEX_MIRROR_TO_URI);
String mirrorTargetCommaDelimList = Joiner.on(',').join(mirrorTargetIds);
Operation op = _dbClient.createTaskOpStatus(Volume.class, vplexVolume.getId(), taskId, ResourceOperationTypeEnum.ATTACH_VPLEX_LOCAL_MIRROR, mirrorTargetCommaDelimList);
taskList.getTaskList().add(toTask(vplexVolume, preparedMirrors, taskId, op));
try {
VPlexController controller = getController();
controller.attachContinuousCopies(vplexStorageSystem.getId(), descriptors, vplexVolume.getId(), taskId);
} catch (InternalException e) {
if (s_logger.isErrorEnabled()) {
s_logger.error("Controller error", e);
}
String errMsg = String.format("Controller error: %s", e.getMessage());
for (URI volumeURI : allVolumes) {
_dbClient.error(Volume.class, volumeURI, taskId, e);
}
for (URI mirrorURI : allMirrors) {
_dbClient.error(VplexMirror.class, mirrorURI, taskId, e);
}
for (TaskResourceRep volumeTask : taskList.getTaskList()) {
volumeTask.setState(Operation.Status.error.name());
volumeTask.setMessage(errMsg);
}
throw e;
}
return taskList;
}
use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method cleanupForViPROnlyMirrorDelete.
/**
* {@inheritDoc}
*/
@Override
protected void cleanupForViPROnlyMirrorDelete(List<URI> mirrorURIs) {
// We need to mark the associated volume inactive.
List<Volume> associatedVolumes = new ArrayList<Volume>();
for (URI mirrorURI : mirrorURIs) {
VplexMirror mirror = _dbClient.queryObject(VplexMirror.class, mirrorURI);
if (mirror.getAssociatedVolumes() != null) {
for (String assocVolumeId : mirror.getAssociatedVolumes()) {
URI assocVolumeURI = URI.create(assocVolumeId);
// Get the associated volume and add it to the list of associated
// volumes to be marked inactive.
Volume assocVolume = _dbClient.queryObject(Volume.class, assocVolumeURI);
associatedVolumes.add(assocVolume);
// Remove the associated volume form any export groups/masks.
ExportUtils.cleanBlockObjectFromExports(assocVolumeURI, true, _dbClient);
}
}
}
// Now mark all the associated volumes for deletion.
_dbClient.markForDeletion(associatedVolumes);
}
use of com.emc.storageos.db.client.model.VplexMirror in project coprhd-controller by CoprHD.
the class VPlexBlockServiceApiImpl method initializeMirror.
/**
* Adds a VplexMirror structure for a Volume. It also calls addMirrorToVolume to
* link the mirror into the volume's mirror set.
*
* @param vplexVolume The volume for which mirror needs to be created
* @param vPool The virtual pool for the mirror
* @param varray The virtual array for the mirror
* @param mirrorLabel The label for the new vplex mirror
* @param thinPreAllocationSize preallocation size for thin provisioning or 0.
* @param dbClient
*/
private static VplexMirror initializeMirror(Volume vplexVolume, VirtualPool vPool, VirtualArray varray, String mirrorLabel, long thinPreAllocationSize, DbClient dbClient) {
// Check if there is already vplex mirror with the same name
List<VplexMirror> mirrorList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, VplexMirror.class, ContainmentPrefixConstraint.Factory.getFullMatchConstraint(VplexMirror.class, "project", vplexVolume.getProject().getURI(), mirrorLabel));
if (!mirrorList.isEmpty()) {
throw APIException.badRequests.duplicateLabel(mirrorLabel);
}
VplexMirror createdMirror = new VplexMirror();
createdMirror.setSource(new NamedURI(vplexVolume.getId(), vplexVolume.getLabel()));
createdMirror.setId(URIUtil.createId(VplexMirror.class));
createdMirror.setLabel(mirrorLabel);
createdMirror.setStorageController(vplexVolume.getStorageController());
createdMirror.setVirtualArray(varray.getId());
createdMirror.setCapacity(vplexVolume.getCapacity());
createdMirror.setProject(new NamedURI(vplexVolume.getProject().getURI(), createdMirror.getLabel()));
createdMirror.setTenant(new NamedURI(vplexVolume.getTenant().getURI(), createdMirror.getLabel()));
createdMirror.setVirtualPool(vPool.getId());
createdMirror.setThinPreAllocationSize(thinPreAllocationSize);
createdMirror.setThinlyProvisioned(VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vPool.getSupportedProvisioningType()));
dbClient.createObject(createdMirror);
addVplexMirrorToVolume(vplexVolume, createdMirror, dbClient);
return createdMirror;
}
Aggregations