use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class CinderCloneOperations method createSingleClone.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.CloneOperations#createSingleClone(
* com.emc.storageos.db.client.model.StorageSystem, java.net.URI, java.net.URI,
* java.lang.Boolean,
* com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void createSingleClone(StorageSystem storageSystem, URI sourceObject, URI cloneVolume, Boolean createInactive, TaskCompleter taskCompleter) {
log.info("START createSingleClone operation");
boolean isVolumeClone = true;
try {
BlockObject sourceObj = BlockObject.fetch(dbClient, sourceObject);
URI tenantUri = null;
if (sourceObj instanceof BlockSnapshot) {
// In case of snapshot, get the tenant from its parent volume
NamedURI parentVolUri = ((BlockSnapshot) sourceObj).getParent();
Volume parentVolume = dbClient.queryObject(Volume.class, parentVolUri);
tenantUri = parentVolume.getTenant().getURI();
isVolumeClone = false;
} else {
// This is a default flow
tenantUri = ((Volume) sourceObj).getTenant().getURI();
isVolumeClone = true;
}
Volume cloneObj = dbClient.queryObject(Volume.class, cloneVolume);
StoragePool targetPool = dbClient.queryObject(StoragePool.class, cloneObj.getPool());
TenantOrg tenantOrg = dbClient.queryObject(TenantOrg.class, tenantUri);
// String cloneLabel = generateLabel(tenantOrg, cloneObj);
CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storageSystem.getActiveProviderURI(), dbClient);
log.info("Getting the cinder APi for the provider with id " + storageSystem.getActiveProviderURI());
CinderApi cinderApi = cinderApiFactory.getApi(storageSystem.getActiveProviderURI(), ep);
String volumeId = "";
if (isVolumeClone) {
volumeId = cinderApi.cloneVolume(cloneObj.getLabel(), (cloneObj.getCapacity() / (1024 * 1024 * 1024)), targetPool.getNativeId(), sourceObj.getNativeId());
} else {
volumeId = cinderApi.createVolumeFromSnapshot(cloneObj.getLabel(), (cloneObj.getCapacity() / (1024 * 1024 * 1024)), targetPool.getNativeId(), sourceObj.getNativeId());
}
log.debug("Creating volume with the id " + volumeId + " on Openstack cinder node");
if (volumeId != null) {
// Cinder volume/snapshot clones are not sync with source, so
// set the replication state as DETACHED
cloneObj.setReplicaState(ReplicationState.DETACHED.name());
dbClient.persistObject(cloneObj);
Map<String, URI> volumeIds = new HashMap<String, URI>();
volumeIds.put(volumeId, cloneObj.getId());
ControllerServiceImpl.enqueueJob(new QueueJob(new CinderSingleVolumeCreateJob(volumeId, cloneObj.getLabel(), storageSystem.getId(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter, targetPool.getId(), volumeIds)));
}
} catch (InternalException e) {
String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceObject, cloneVolume);
log.error(errorMsg, e);
taskCompleter.error(dbClient, e);
} catch (Exception e) {
String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, sourceObject, cloneVolume);
log.error(errorMsg, e);
ServiceError serviceError = DeviceControllerErrors.cinder.operationFailed("createSingleClone", e.getMessage());
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class ReplicaDeviceController method prepareClone.
private Volume prepareClone(Volume volume, String repGroupName, String cloneSetName) {
// create clone for the source
Volume clone = new Volume();
clone.setId(URIUtil.createId(Volume.class));
clone.setLabel(volume.getLabel() + "-" + repGroupName);
clone.setPool(volume.getPool());
clone.setStorageController(volume.getStorageController());
clone.setSystemType(volume.getSystemType());
clone.setProject(new NamedURI(volume.getProject().getURI(), clone.getLabel()));
clone.setTenant(new NamedURI(volume.getTenant().getURI(), clone.getLabel()));
clone.setVirtualPool(volume.getVirtualPool());
clone.setVirtualArray(volume.getVirtualArray());
clone.setProtocol(new StringSet());
clone.getProtocol().addAll(volume.getProtocol());
clone.setThinlyProvisioned(volume.getThinlyProvisioned());
clone.setOpStatus(new OpStatusMap());
clone.setAssociatedSourceVolume(volume.getId());
clone.setReplicationGroupInstance(repGroupName);
// For clones of new volumes added to Application, get the clone set name and set it
if (cloneSetName != null) {
clone.setFullCopySetName(cloneSetName);
}
StringSet fullCopies = volume.getFullCopies();
if (fullCopies == null) {
fullCopies = new StringSet();
volume.setFullCopies(fullCopies);
}
fullCopies.add(clone.getId().toString());
_dbClient.createObject(clone);
_dbClient.updateObject(volume);
return clone;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class ReplicaDeviceController method prepareSnapshot.
private BlockSnapshot prepareSnapshot(Volume volume, String repGroupName) {
BlockSnapshot snapshot = new BlockSnapshot();
snapshot.setId(URIUtil.createId(BlockSnapshot.class));
URI cgUri = volume.getConsistencyGroup();
if (cgUri != null) {
snapshot.setConsistencyGroup(cgUri);
}
snapshot.setSourceNativeId(volume.getNativeId());
snapshot.setParent(new NamedURI(volume.getId(), volume.getLabel()));
snapshot.setReplicationGroupInstance(repGroupName);
snapshot.setStorageController(volume.getStorageController());
snapshot.setSystemType(volume.getSystemType());
snapshot.setVirtualArray(volume.getVirtualArray());
snapshot.setProtocol(new StringSet());
snapshot.getProtocol().addAll(volume.getProtocol());
NamedURI project = volume.getProject();
// get the project from VPLEX volume as backend volume have different project set with internal flag.
if (Volume.checkForVplexBackEndVolume(_dbClient, volume)) {
Volume vplexVolume = Volume.fetchVplexVolume(_dbClient, volume);
project = vplexVolume.getProject();
}
snapshot.setProject(new NamedURI(project.getURI(), project.getName()));
String existingSnapSnapSetLabel = ControllerUtils.getSnapSetLabelFromExistingSnaps(repGroupName, volume.getStorageController(), _dbClient);
if (null == existingSnapSnapSetLabel) {
log.warn("Not able to find any snapshots with group {}", repGroupName);
existingSnapSnapSetLabel = repGroupName;
}
snapshot.setSnapsetLabel(existingSnapSnapSetLabel);
Set<String> existingLabels = ControllerUtils.getSnapshotLabelsFromExistingSnaps(repGroupName, volume, _dbClient);
LabelFormatFactory labelFormatFactory = new LabelFormatFactory();
LabelFormat labelFormat = labelFormatFactory.getLabelFormat(existingLabels);
snapshot.setLabel(labelFormat.next());
snapshot.setTechnologyType(BlockSnapshot.TechnologyType.NATIVE.name());
_dbClient.createObject(snapshot);
return snapshot;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class ReplicaDeviceController method createMirror.
/**
* Adds a BlockMirror structure for a Volume. It also calls addMirrorToVolume to
* link the mirror into the volume's mirror set.
*
* @param volume Volume
* @param vPoolURI
* @param recommendedPoolURI Pool that should be used to create the mirror
* @param volumeLabel
* @param repGroupName
* @return BlockMirror (persisted)
*/
private BlockMirror createMirror(Volume volume, URI vPoolURI, URI recommendedPoolURI, String volumeLabel, String repGroupName) {
BlockMirror createdMirror = new BlockMirror();
createdMirror.setSource(new NamedURI(volume.getId(), volume.getLabel()));
createdMirror.setId(URIUtil.createId(BlockMirror.class));
URI cgUri = volume.getConsistencyGroup();
if (!NullColumnValueGetter.isNullURI(cgUri)) {
createdMirror.setConsistencyGroup(cgUri);
}
createdMirror.setLabel(volumeLabel);
createdMirror.setStorageController(volume.getStorageController());
createdMirror.setSystemType(volume.getSystemType());
createdMirror.setVirtualArray(volume.getVirtualArray());
createdMirror.setProtocol(new StringSet());
createdMirror.getProtocol().addAll(volume.getProtocol());
createdMirror.setCapacity(volume.getCapacity());
createdMirror.setProject(new NamedURI(volume.getProject().getURI(), createdMirror.getLabel()));
createdMirror.setTenant(new NamedURI(volume.getTenant().getURI(), createdMirror.getLabel()));
createdMirror.setPool(recommendedPoolURI);
createdMirror.setVirtualPool(vPoolURI);
createdMirror.setSyncState(SynchronizationState.UNKNOWN.toString());
createdMirror.setSyncType(BlockMirror.MIRROR_SYNC_TYPE);
createdMirror.setThinlyProvisioned(volume.getThinlyProvisioned());
createdMirror.setReplicationGroupInstance(repGroupName);
_dbClient.createObject(createdMirror);
addMirrorToVolume(volume, createdMirror);
return createdMirror;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class StorageScheduler method prepareFullCopyVolumeFromVolume.
private static Volume prepareFullCopyVolumeFromVolume(DbClient dbClient, String name, Volume sourceVolume, VolumeRecommendation recommendation, int volumeCounter, VirtualPoolCapabilityValuesWrapper capabilities, Boolean createInactive) {
long size = sourceVolume.getCapacity();
long preAllocateSize = 0;
if (null != sourceVolume.getThinVolumePreAllocationSize()) {
preAllocateSize = sourceVolume.getThinVolumePreAllocationSize();
}
NamedURI projectUri = sourceVolume.getProject();
Project project = dbClient.queryObject(Project.class, projectUri);
URI vArrayUri = sourceVolume.getVirtualArray();
VirtualArray vArray = dbClient.queryObject(VirtualArray.class, vArrayUri);
URI vPoolUri = sourceVolume.getVirtualPool();
VirtualPool vPool = dbClient.queryObject(VirtualPool.class, vPoolUri);
String label = name + (volumeCounter > 0 ? ("-" + volumeCounter) : "");
Volume volume = prepareVolume(dbClient, null, size, preAllocateSize, project, vArray, vPool, recommendation, label, null, capabilities, createInactive);
// Since this is a full copy, update it with URI of the source volume
volume.setAssociatedSourceVolume(sourceVolume.getId());
StringSet associatedFullCopies = sourceVolume.getFullCopies();
if (associatedFullCopies == null) {
associatedFullCopies = new StringSet();
sourceVolume.setFullCopies(associatedFullCopies);
}
associatedFullCopies.add(volume.getId().toString());
dbClient.persistObject(volume);
dbClient.persistObject(sourceVolume);
addVolumeCapacityToReservedCapacityMap(dbClient, volume);
return volume;
}
Aggregations