use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doCreateVolumes.
@Override
public void doCreateVolumes(StorageSystem storageSystem, StoragePool storagePool, String opId, List<Volume> volumes, VirtualPoolCapabilityValuesWrapper capabilities, TaskCompleter taskCompleter) throws DeviceControllerException {
List<StorageVolume> driverVolumes = new ArrayList<>();
Map<StorageVolume, Volume> driverVolumeToVolumeMap = new HashMap<>();
Set<URI> consistencyGroups = new HashSet<>();
StorageCapabilities storageCapabilities = null;
DriverTask task = null;
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
try {
for (Volume volume : volumes) {
if (storageCapabilities == null) {
// All volumes created in a request will have the same capabilities.
storageCapabilities = new StorageCapabilities();
addAutoTieringPolicyCapability(storageCapabilities, volume.getAutoTieringPolicyUri());
addDeduplicationCapability(storageCapabilities, volume.getIsDeduplicated());
}
StorageVolume driverVolume = new StorageVolume();
driverVolume.setStorageSystemId(storageSystem.getNativeId());
driverVolume.setStoragePoolId(storagePool.getNativeId());
driverVolume.setRequestedCapacity(volume.getCapacity());
driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
driverVolume.setDisplayName(volume.getLabel());
if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
BlockConsistencyGroup cg = dbClient.queryObject(BlockConsistencyGroup.class, volume.getConsistencyGroup());
driverVolume.setConsistencyGroup(cg.getNativeId());
}
driverVolumes.add(driverVolume);
driverVolumeToVolumeMap.put(driverVolume, volume);
}
// Call driver
task = driver.createVolumes(Collections.unmodifiableList(driverVolumes), storageCapabilities);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY || task.getStatus() == DriverTask.TaskStatus.PARTIALLY_FAILED) {
updateVolumesWithDriverVolumeInfo(dbClient, driverVolumeToVolumeMap, consistencyGroups);
dbClient.updateObject(driverVolumeToVolumeMap.values());
updateConsistencyGroupsWithStorageSystem(consistencyGroups, storageSystem);
String msg = String.format("doCreateVolumes -- Created volumes: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
// Set volumes to inactive state
for (Volume volume : volumes) {
volume.setInactive(true);
}
dbClient.updateObject(volumes);
String errorMsg = String.format("doCreateVolumes -- Failed to create volumes: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createVolumesFailed("doCreateVolumes", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
_log.error("doCreateVolumes -- Failed to create volumes. ", e);
ServiceError serviceError = ExternalDeviceException.errors.createVolumesFailed("doCreateVolumes", e.getMessage());
taskCompleter.error(dbClient, serviceError);
} finally {
try {
if (task == null || isTaskInTerminalState(task.getStatus())) {
updateStoragePoolCapacity(storagePool, storageSystem, URIUtil.toUris(volumes), dbClient);
}
} catch (Exception ex) {
_log.error("Failed to update storage pool {} after create volumes operation completion.", storagePool.getId(), ex);
}
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doRestoreFromSnapshot.
@Override
public void doRestoreFromSnapshot(StorageSystem storageSystem, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
String storageSystemNativeId = storageSystem.getNativeId();
_log.info("Snapshot Restore..... Started");
BlockConsistencyGroup parentVolumeConsistencyGroup = null;
try {
List<BlockSnapshot> snapshotsToRestore = new ArrayList<>();
BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
List<BlockSnapshot> groupSnapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(blockSnapshot, dbClient);
if (groupSnapshots.size() > 1 && ControllerUtils.checkSnapshotsInConsistencyGroup(Arrays.asList(blockSnapshot), dbClient, taskCompleter)) {
// make sure we restore only snapshots from the same consistency group
for (BlockSnapshot snap : groupSnapshots) {
if (snap.getConsistencyGroup().equals(blockSnapshot.getConsistencyGroup())) {
snapshotsToRestore.add(snap);
}
}
URI cgUri = blockSnapshot.getConsistencyGroup();
parentVolumeConsistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
_log.info("Restore group snapshot: group {}, snapshot set: {}, snapshots to restore: " + Joiner.on("\t").join(snapshotsToRestore), parentVolumeConsistencyGroup.getNativeId(), blockSnapshot.getReplicationGroupInstance());
} else {
Volume sourceVolume = getSnapshotParentVolume(blockSnapshot);
snapshotsToRestore.add(blockSnapshot);
_log.info("Restore single volume snapshot: volume {}, snapshot: {}", sourceVolume.getNativeId(), blockSnapshot.getNativeId());
}
// Prepare driver snapshots
List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
for (BlockSnapshot snap : snapshotsToRestore) {
VolumeSnapshot driverSnapshot = new VolumeSnapshot();
Volume sourceVolume = getSnapshotParentVolume(snap);
driverSnapshot.setParentId(sourceVolume.getNativeId());
driverSnapshot.setNativeId(snap.getNativeId());
driverSnapshot.setStorageSystemId(storageSystemNativeId);
driverSnapshot.setDisplayName(snap.getLabel());
if (parentVolumeConsistencyGroup != null) {
driverSnapshot.setConsistencyGroup(snap.getReplicationGroupInstance());
}
driverSnapshots.add(driverSnapshot);
}
// Call driver to execute this request
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.restoreSnapshot(driverSnapshots);
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 call the completer as
// appropriate based on the result of the request.
RestoreFromSnapshotExternalDeviceJob job = new RestoreFromSnapshotExternalDeviceJob(storageSystem.getId(), snapshot, task.getTaskId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(job));
} else if (task.getStatus() == DriverTask.TaskStatus.READY) {
String msg = String.format("doRestoreFromSnapshot -- Restored snapshots: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
String errorMsg = String.format("doRestoreFromSnapshot -- Failed to restore from snapshots: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.restoreFromSnapshotFailed("doRestoreFromSnapshot", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
String message = String.format("IO exception when trying to restore from snapshots on array %s", storageSystem.getSerialNumber());
_log.error(message, e);
ServiceError error = ExternalDeviceException.errors.restoreFromSnapshotFailed("doRestoreFromSnapshot", e.getMessage());
taskCompleter.error(dbClient, error);
}
_log.info("Snapshot Restore..... End");
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup 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.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method deleteGroupSnapshots.
private void deleteGroupSnapshots(StorageSystem storageSystem, List<BlockSnapshot> groupSnapshots, TaskCompleter taskCompleter) {
_log.info("Deleting snapshot of consistency group. Snapshots: " + Joiner.on("\t").join(groupSnapshots));
URI cgUri = groupSnapshots.get(0).getConsistencyGroup();
BlockConsistencyGroup consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
List<VolumeSnapshot> driverSnapshots = new ArrayList<>();
for (BlockSnapshot blockSnapshot : groupSnapshots) {
VolumeSnapshot driverSnapshot = new VolumeSnapshot();
driverSnapshot.setStorageSystemId(storageSystem.getNativeId());
driverSnapshot.setNativeId(blockSnapshot.getNativeId());
driverSnapshot.setConsistencyGroup(blockSnapshot.getReplicationGroupInstance());
Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
driverSnapshot.setParentId(parent.getNativeId());
driverSnapshots.add(driverSnapshot);
}
// call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.deleteConsistencyGroupSnapshot(Collections.unmodifiableList(driverSnapshots));
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// update snapshots
for (BlockSnapshot blockSnapshot : groupSnapshots) {
blockSnapshot.setInactive(true);
}
dbClient.updateObject(groupSnapshots);
String msg = String.format("deleteGroupSnapshots -- Deleted group snapshot: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
String errorMsg = String.format("doDeleteSnapshot -- Failed to delete group snapshot: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.deleteGroupSnapshotFailed("doDeleteSnapshot", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doAddToConsistencyGroup.
@Override
public void doAddToConsistencyGroup(StorageSystem storageSystem, URI consistencyGroupId, String replicationGroupName, List<URI> blockObjects, TaskCompleter taskCompleter) throws DeviceControllerException {
BlockConsistencyGroup consistencyGroup = null;
try {
_log.info("{} doAddToConsistencyGroup START ...", storageSystem.getSerialNumber());
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
List<Volume> volumes = dbClient.queryObject(Volume.class, blockObjects);
List<StorageVolume> driverVolumes = new ArrayList<>();
consistencyGroup = dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroupId);
for (Volume volume : volumes) {
StorageVolume driverVolume = new StorageVolume();
driverVolume.setStorageSystemId(storageSystem.getNativeId());
driverVolume.setNativeId(volume.getNativeId());
driverVolume.setRequestedCapacity(volume.getCapacity());
driverVolume.setThinlyProvisioned(volume.getThinlyProvisioned());
driverVolume.setConsistencyGroup(consistencyGroup.getNativeId());
driverVolume.setDisplayName(volume.getLabel());
// add them to StorageVolumes list
driverVolumes.add(driverVolume);
}
DriverTask task = driver.addVolumesToConsistencyGroup(driverVolumes, null);
_log.info("doAddToConsistencyGroup -- added volumes {} to consistency Group: {}", volumes.toString(), consistencyGroupId);
if (task.getStatus() == DriverTask.TaskStatus.READY) {
for (Volume volume : volumes) {
volume.setConsistencyGroup(consistencyGroupId);
}
dbClient.updateObject(volumes);
taskCompleter.ready(dbClient);
} else {
_log.error(String.format("Add volumes to Consistency Group operation failed %s", task.getMessage()));
taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToAddMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), task.getMessage()));
}
_log.info("{} doAddVolumesToConsistencyGroup END ...", storageSystem.getSerialNumber());
} catch (Exception e) {
_log.error(String.format("Add volumes from Consistency Group operation failed %s", e.getMessage()));
taskCompleter.error(dbClient, DeviceControllerException.exceptions.failedToAddMembersToConsistencyGroup(consistencyGroup.getLabel(), consistencyGroup.getLabel(), e.getMessage()));
}
}
Aggregations