use of com.emc.storageos.storagedriver.model.VolumeConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method createGroupSnapshots.
private void createGroupSnapshots(StorageSystem storageSystem, List<BlockSnapshot> snapshots, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) {
_log.info("Creating snapshot of consistency group .....");
List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
Map<VolumeSnapshot, BlockSnapshot> driverSnapshotToSnapshotMap = new HashMap<>();
URI cgUri = snapshots.get(0).getConsistencyGroup();
BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
// Prepare driver snapshots
String storageSystemNativeId = storageSystem.getNativeId();
for (BlockSnapshot snapshot : snapshots) {
Volume parent = dbClient.queryObject(Volume.class, snapshot.getParent().getURI());
VolumeSnapshot driverSnapshot = new VolumeSnapshot();
driverSnapshot.setParentId(parent.getNativeId());
driverSnapshot.setStorageSystemId(storageSystemNativeId);
driverSnapshot.setDisplayName(snapshot.getLabel());
if (readOnly) {
driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_ONLY);
} else {
driverSnapshot.setAccessStatus(StorageObject.AccessStatus.READ_WRITE);
}
driverSnapshotToSnapshotMap.put(driverSnapshot, snapshot);
driverSnapshots.add(driverSnapshot);
}
// Prepare driver consistency group of the parent volume
VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
driverCG.setNativeId(consistencyGroup.getNativeId());
driverCG.setDisplayName(consistencyGroup.getLabel());
driverCG.setStorageSystemId(storageSystem.getNativeId());
// call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.createConsistencyGroupSnapshot(driverCG, Collections.unmodifiableList(driverSnapshots), null);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// update snapshots
for (VolumeSnapshot driverSnapshot : driverSnapshotToSnapshotMap.keySet()) {
BlockSnapshot snapshot = driverSnapshotToSnapshotMap.get(driverSnapshot);
snapshot.setNativeId(driverSnapshot.getNativeId());
snapshot.setDeviceLabel(driverSnapshot.getDeviceLabel());
snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
snapshot.setIsSyncActive(true);
// we use driver snapshot consistency group id as replication group label for group snapshots
snapshot.setReplicationGroupInstance(driverSnapshot.getConsistencyGroup());
if (driverSnapshot.getProvisionedCapacity() > 0) {
snapshot.setProvisionedCapacity(driverSnapshot.getProvisionedCapacity());
}
if (driverSnapshot.getAllocatedCapacity() > 0) {
snapshot.setAllocatedCapacity(driverSnapshot.getAllocatedCapacity());
}
}
dbClient.updateObject(driverSnapshotToSnapshotMap.values());
String msg = String.format("createGroupSnapshots -- Created snapshots: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
for (BlockSnapshot snapshot : snapshots) {
snapshot.setInactive(true);
}
dbClient.updateObject(snapshots);
String errorMsg = String.format("doCreateSnapshot -- Failed to create snapshots: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createSnapshotsFailed("doCreateSnapshot", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.storagedriver.model.VolumeConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doDeleteConsistencyGroup.
@Override
public void doDeleteConsistencyGroup(StorageSystem storageSystem, URI consistencyGroupId, String replicationGroupName, Boolean keepRGName, Boolean markInactive, TaskCompleter taskCompleter) throws DeviceControllerException {
_log.info("Delete consistency group: STARTED...");
BlockConsistencyGroup consistencyGroup = null;
String groupNativeId = null;
String groupDisplayName = null;
boolean isDeleteForBlockCG = true;
try {
if (!NullColumnValueGetter.isNullURI(consistencyGroupId)) {
consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
groupDisplayName = consistencyGroup != null ? consistencyGroup.getLabel() : replicationGroupName;
groupNativeId = consistencyGroup != null ? consistencyGroup.getNativeId() : replicationGroupName;
if (consistencyGroup == null) {
isDeleteForBlockCG = false;
}
} else {
groupDisplayName = replicationGroupName;
groupNativeId = replicationGroupName;
isDeleteForBlockCG = false;
}
if (groupNativeId == null || groupNativeId.isEmpty()) {
String msg = String.format("doDeleteConsistencyGroup -- There is no consistency group or replication group to delete.");
_log.info(msg);
taskCompleter.ready(dbClient);
return;
}
if (isDeleteForBlockCG) {
_log.info("Deleting consistency group: storage system {}, group {}", storageSystem.getNativeId(), groupDisplayName);
} else {
_log.info("Deleting system replication group: storage system {}, group {}", storageSystem.getNativeId(), groupDisplayName);
_log.info("Replication groups are not supported for external devices. Do not call driver.");
taskCompleter.ready(dbClient);
return;
}
// prepare driver consistency group
VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
driverCG.setDisplayName(groupDisplayName);
driverCG.setNativeId(groupNativeId);
driverCG.setStorageSystemId(storageSystem.getNativeId());
// call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.deleteConsistencyGroup(driverCG);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
if (consistencyGroup != null) {
// I followed xtremio pattern to implement this logic.
consistencyGroup.removeSystemConsistencyGroup(URIUtil.asString(storageSystem.getId()), groupDisplayName);
dbClient.updateObject(consistencyGroup);
// have to read again to get updated systemConsistencyGroup map
consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
/*
* Verify if the BlockConsistencyGroup references any LOCAL arrays.
* If we no longer have any references we can remove the 'LOCAL' type from the BlockConsistencyGroup.
*/
List<URI> referencedArrays = BlockConsistencyGroupUtils.getLocalSystems(consistencyGroup, dbClient);
boolean cgReferenced = referencedArrays != null && !referencedArrays.isEmpty();
if (!cgReferenced) {
// Remove the LOCAL type
StringSet cgTypes = consistencyGroup.getTypes();
cgTypes.remove(BlockConsistencyGroup.Types.LOCAL.name());
consistencyGroup.setTypes(cgTypes);
// of storage systems associated with the CG.
if (!BlockConsistencyGroupUtils.referencesNonLocalCgs(consistencyGroup, dbClient)) {
consistencyGroup.setStorageController(NullColumnValueGetter.getNullURI());
// Update the consistency group model
consistencyGroup.setInactive(markInactive);
}
} else {
_log.info("*** Referenced arrays {}", referencedArrays.toString());
}
dbClient.updateObject(consistencyGroup);
}
String msg = String.format("doDeleteConsistencyGroup -- Delete consistency group: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
String errorMsg = String.format("doDeleteConsistencyGroup -- Failed to delete Consistency Group: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.deleteConsistencyGroupFailed("doDeleteConsistencyGroup", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
String errorMsg = String.format("doDeleteConsistencyGroup -- Failed to delete Consistency Group: %s .", e.getMessage());
_log.error(errorMsg, e);
ServiceError serviceError = ExternalDeviceException.errors.deleteConsistencyGroupFailed("doDeleteConsistencyGroup", errorMsg);
taskCompleter.error(dbClient, serviceError);
} finally {
_log.info("Delete consistency group: END...");
}
}
use of com.emc.storageos.storagedriver.model.VolumeConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doCreateGroupClone.
@Override
public void doCreateGroupClone(StorageSystem storageSystem, List<URI> cloneURIs, Boolean createInactive, TaskCompleter taskCompleter) {
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
List<VolumeClone> driverClones = new ArrayList<>();
Map<VolumeClone, Volume> driverCloneToCloneMap = new HashMap<>();
Set<URI> consistencyGroups = new HashSet<>();
List<Volume> clones = null;
DriverTask task = null;
try {
clones = dbClient.queryObject(Volume.class, cloneURIs);
// We assume here that all volumes belong to the same consistency group
URI parentUri = clones.get(0).getAssociatedSourceVolume();
Volume parentVolume = dbClient.queryObject(Volume.class, parentUri);
BlockConsistencyGroup cg = null;
if (!NullColumnValueGetter.isNullURI(parentVolume.getConsistencyGroup())) {
cg = dbClient.queryObject(BlockConsistencyGroup.class, parentVolume.getConsistencyGroup());
} else {
String errorMsg = String.format("doCreateGroupClone -- Failed to create group clone, parent volumes do not belong to consistency group." + " Clones: %s .", cloneURIs);
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
return;
}
// Prepare driver consistency group of parent volume
VolumeConsistencyGroup driverCG = new VolumeConsistencyGroup();
driverCG.setDisplayName(cg.getLabel());
driverCG.setNativeId(cg.getNativeId());
driverCG.setStorageSystemId(storageSystem.getNativeId());
// Prepare driver clones
for (Volume clone : clones) {
URI sourceVolumeUri = clone.getAssociatedSourceVolume();
Volume sourceVolume = dbClient.queryObject(Volume.class, sourceVolumeUri);
VolumeClone driverClone = new VolumeClone();
driverClone.setParentId(sourceVolume.getNativeId());
driverClone.setStorageSystemId(storageSystem.getNativeId());
driverClone.setDisplayName(clone.getLabel());
driverClone.setRequestedCapacity(clone.getCapacity());
driverClone.setThinlyProvisioned(clone.getThinlyProvisioned());
driverClones.add(driverClone);
driverCloneToCloneMap.put(driverClone, clone);
}
// Call driver to create group snapshot
task = driver.createConsistencyGroupClone(driverCG, Collections.unmodifiableList(driverClones), null);
if (!isTaskInTerminalState(task.getStatus())) {
// If the task is not in a terminal state and will be completed asynchronously
// create a job to monitor the progress of the request and update the clone
// volume and call the completer as appropriate based on the result of the request.
CreateGroupCloneExternalDeviceJob job = new CreateGroupCloneExternalDeviceJob(storageSystem.getId(), cloneURIs, parentVolume.getConsistencyGroup(), task.getTaskId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(job));
} else if (task.getStatus() == DriverTask.TaskStatus.READY) {
// Update clone object with driver data
String msg = String.format("doCreateGroupClone -- Created group clone: %s .", task.getMessage());
_log.info(msg);
List<Volume> cloneObjects = new ArrayList<>();
for (VolumeClone driverCloneResult : driverClones) {
Volume cloneObject = driverCloneToCloneMap.get(driverCloneResult);
ExternalDeviceUtils.updateNewlyCreatedGroupClone(cloneObject, driverCloneResult, parentVolume.getConsistencyGroup(), dbClient);
cloneObjects.add(cloneObject);
}
dbClient.updateObject(cloneObjects);
taskCompleter.ready(dbClient);
} else {
// Process failure
for (Volume cloneObject : clones) {
cloneObject.setInactive(true);
}
dbClient.updateObject(clones);
String errorMsg = String.format("doCreateGroupClone -- Failed to create group clone: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
if (clones != null) {
// Process failure
for (Volume cloneObject : clones) {
cloneObject.setInactive(true);
}
dbClient.updateObject(clones);
}
_log.error("Failed to create group clone. ", e);
ServiceError serviceError = ExternalDeviceException.errors.createGroupCloneFailed("doCreateGroupClone", e.getMessage());
taskCompleter.error(dbClient, serviceError);
} finally {
try {
if (task == null || isTaskInTerminalState(task.getStatus())) {
// post process storage pool capacity for clone's pools
// map clones to their storage pool
Map<URI, List<URI>> dbPoolToClone = new HashMap<>();
for (Volume clone : clones) {
URI dbPoolUri = clone.getPool();
List<URI> poolClones = dbPoolToClone.get(dbPoolUri);
if (poolClones == null) {
poolClones = new ArrayList<>();
dbPoolToClone.put(dbPoolUri, poolClones);
}
poolClones.add(clone.getId());
}
for (URI dbPoolUri : dbPoolToClone.keySet()) {
StoragePool dbPool = dbClient.queryObject(StoragePool.class, dbPoolUri);
updateStoragePoolCapacity(dbPool, storageSystem, dbPoolToClone.get(dbPoolUri), dbClient);
}
}
} catch (Exception ex) {
_log.error("Failed to update storage pool after create group clone operation completion.", ex);
}
}
}
use of com.emc.storageos.storagedriver.model.VolumeConsistencyGroup in project coprhd-controller by CoprHD.
the class HP3PARStorageDriver method getStorageObject.
/*
* objectid is nothing but the native id of the storage object. For
* consistency group it would be the native id of consistency group, which
* on the HP3PAR array is nothing but the name of the volume set.
*/
@Override
public <T extends StorageObject> T getStorageObject(String storageSystemId, String objectId, Class<T> type) {
// TODO Auto-generated method stub
_log.info("3PARDriver: getStorageObject enter ");
try {
HP3PARApi hp3parApi = hp3parUtil.getHP3PARDeviceFromNativeId(storageSystemId, this.driverRegistry);
ConsistencyGroupResult cgResult = null;
if (VolumeConsistencyGroup.class.getSimpleName().equals(type.getSimpleName())) {
cgResult = hp3parApi.getVVsetDetails(objectId);
VolumeConsistencyGroup cg = new VolumeConsistencyGroup();
cg.setStorageSystemId(storageSystemId);
cg.setNativeId(cgResult.getName());
cg.setDeviceLabel(objectId);
_log.info("3PARDriver: getStorageObject leaving ");
return (T) cg;
} else if (StoragePool.class.getSimpleName().equals(type.getSimpleName())) {
CPGMember cpgResult = null;
cpgResult = hp3parApi.getCPGDetails(objectId);
StoragePool sp = new StoragePool();
String cpgName = cpgResult.getName();
sp.setNativeId(cpgName);
CPGSpaceCommandResult cpgSpaceResult = hp3parApi.getCPGSpaceDetails(cpgName);
// CPG common space is space available to the CPG from the common pool
Long cpgCommonSpace = cpgSpaceResult.getUsableFreeMiB().longValue();
// CPG allocated capacity is what is currently allocated to the CPG
Long cpgAllocatedCapacity = cpgResult.getUsrUsage().getTotalMiB().longValue() + cpgResult.getSAUsage().getTotalMiB().longValue() + cpgResult.getSDUsage().getTotalMiB().longValue();
// CPG used capacity is what is currently used within the CPG
Long cpgUsedCapacity = cpgResult.getUsrUsage().getUsedMiB().longValue() + cpgResult.getSAUsage().getUsedMiB().longValue() + cpgResult.getSDUsage().getUsedMiB().longValue();
// CPG Free capacity is what is currently free within the CPG
Long cpgFreeCapacity = cpgAllocatedCapacity - cpgUsedCapacity;
// CPG total potentially usable capacity is the sum of these two
// Here we are assuming that the CPG can potentially use all of the common capacity
// Although in practice this is shared with all CPGs of the same type
Long cpgTotalCapacity = cpgAllocatedCapacity + cpgCommonSpace;
// We add the common space to the free capacity because it can also be used by the CPG
cpgFreeCapacity += cpgCommonSpace;
sp.setTotalCapacity(cpgTotalCapacity * HP3PARConstants.KILO_BYTE);
sp.setFreeCapacity(cpgFreeCapacity * HP3PARConstants.KILO_BYTE);
VolumesCommandResult volumesOfCpg = hp3parApi.getVolumesofCPG(cpgName);
Long cpgSubscribedCapacity = (long) 0;
Iterator<VolumeDetailsCommandResult> volIter = volumesOfCpg.getMembers().iterator();
while (volIter.hasNext()) {
cpgSubscribedCapacity += volIter.next().getSizeMiB();
}
sp.setSubscribedCapacity(cpgSubscribedCapacity * HP3PARConstants.KILO_BYTE);
_log.info("3PARDriver: For CPG {}:", cpgName);
_log.info("Number of volumes in CPG = {}", volumesOfCpg.getTotal());
_log.info("Total Capacity = {} MB, Subscribed Capacity = {} MB, Free Capacity = {} MB", cpgTotalCapacity, cpgSubscribedCapacity, cpgFreeCapacity);
// Note that subscribed capacity need not be equal to (total - free capacity) for thin pools
_log.info("3PARDriver: StoragePool getStorageObject leaving ");
return (T) sp;
}
} catch (Exception e) {
String msg = String.format("3PARDriver: Unable to get Stroage Object for id %s; Error: %s.\n", objectId, e.getMessage());
_log.error(msg);
e.printStackTrace();
_log.error(CompleteError.getStackTrace(e));
return (T) null;
}
return null;
}
use of com.emc.storageos.storagedriver.model.VolumeConsistencyGroup in project coprhd-controller by CoprHD.
the class StorageDriverSimulator method getStorageObject.
@Override
public <T extends StorageObject> T getStorageObject(String storageSystemId, String objectId, Class<T> type) {
if (StorageVolume.class.getSimpleName().equals(type.getSimpleName())) {
StorageVolume obj = new StorageVolume();
obj.setAllocatedCapacity(200L);
_log.info("getStorageObject: storage volume allocated capacity: {}", obj.getAllocatedCapacity());
return (T) obj;
} else if (VolumeConsistencyGroup.class.getSimpleName().equals(type.getSimpleName())) {
VolumeConsistencyGroup cg = new VolumeConsistencyGroup();
cg.setStorageSystemId(storageSystemId);
cg.setNativeId(objectId);
cg.setDeviceLabel(objectId);
_log.info("Return volume cg {} from array {}", objectId, storageSystemId);
return (T) cg;
} else if (StoragePool.class.getSimpleName().equals(type.getSimpleName())) {
StoragePool pool = new StoragePool();
// 40 GB
pool.setFreeCapacity(40000000L);
// 10 GB
pool.setSubscribedCapacity(10000000L);
pool.setNativeId(objectId);
pool.setStorageSystemId(storageSystemId);
_log.info("getStorageObject: storage pool free capacity: {}, subscribed capacity: {}", pool.getFreeCapacity(), pool.getSubscribedCapacity());
return (T) pool;
} else {
_log.error("getStorageObject: not supported for type: {}", type.getSimpleName());
return null;
}
}
Aggregations