use of com.emc.storageos.storagedriver.BlockStorageDriver in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method deleteVolumeSnapshot.
private void deleteVolumeSnapshot(StorageSystem storageSystem, URI snapshot, TaskCompleter taskCompleter) {
BlockSnapshot blockSnapshot = dbClient.queryObject(BlockSnapshot.class, snapshot);
if (blockSnapshot != null && !blockSnapshot.getInactive() && // state against the BlockSnapshot object can be set.
!Strings.isNullOrEmpty(blockSnapshot.getNativeId())) {
_log.info("Deleting snapshot of a volume. Snapshot: {}", snapshot);
Volume parent = dbClient.queryObject(Volume.class, blockSnapshot.getParent().getURI());
VolumeSnapshot driverSnapshot = new VolumeSnapshot();
driverSnapshot.setStorageSystemId(storageSystem.getNativeId());
driverSnapshot.setNativeId(blockSnapshot.getNativeId());
driverSnapshot.setParentId(parent.getNativeId());
driverSnapshot.setConsistencyGroup(blockSnapshot.getReplicationGroupInstance());
// call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
DriverTask task = driver.deleteVolumeSnapshot(driverSnapshot);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
// update snapshots
blockSnapshot.setInactive(true);
dbClient.updateObject(blockSnapshot);
String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", task.getMessage());
_log.info(msg);
taskCompleter.ready(dbClient);
} else {
String errorMsg = String.format("doDeleteSnapshot -- Failed to delete snapshot: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.deleteSnapshotFailed("doDeleteSnapshot", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} else if (blockSnapshot != null) {
blockSnapshot.setInactive(true);
dbClient.updateObject(blockSnapshot);
String msg = String.format("deleteVolumeSnapshot -- Deleted snapshot: %s .", blockSnapshot.getId());
_log.info(msg);
taskCompleter.ready(dbClient);
}
}
use of com.emc.storageos.storagedriver.BlockStorageDriver in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doCreateClone.
@Override
public void doCreateClone(StorageSystem storageSystem, URI volume, URI clone, Boolean createInactive, TaskCompleter taskCompleter) {
Volume cloneObject = null;
DriverTask task = null;
try {
cloneObject = dbClient.queryObject(Volume.class, clone);
BlockObject sourceVolume = BlockObject.fetch(dbClient, volume);
VolumeClone driverClone = new VolumeClone();
if (sourceVolume instanceof Volume) {
driverClone.setSourceType(VolumeClone.SourceType.VOLUME);
} else if (sourceVolume instanceof BlockSnapshot) {
driverClone.setSourceType(VolumeClone.SourceType.SNAPSHOT);
} else {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
String errorMsg = String.format("doCreateClone -- Failed to create volume clone: unexpected source type %s .", sourceVolume.getClass().getSimpleName());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
return;
}
// Prepare driver clone
driverClone.setParentId(sourceVolume.getNativeId());
driverClone.setStorageSystemId(storageSystem.getNativeId());
driverClone.setDisplayName(cloneObject.getLabel());
driverClone.setRequestedCapacity(cloneObject.getCapacity());
driverClone.setThinlyProvisioned(cloneObject.getThinlyProvisioned());
// Call driver
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
List<VolumeClone> driverClones = new ArrayList<>();
driverClones.add(driverClone);
task = driver.createVolumeClone(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.
CreateVolumeCloneExternalDeviceJob job = new CreateVolumeCloneExternalDeviceJob(storageSystem.getId(), clone, task.getTaskId(), taskCompleter);
ControllerServiceImpl.enqueueJob(new QueueJob(job));
} else if (task.getStatus() == DriverTask.TaskStatus.READY) {
// Update clone
String msg = String.format("doCreateClone -- Created volume clone: %s .", task.getMessage());
_log.info(msg);
VolumeClone driverCloneResult = driverClones.get(0);
ExternalDeviceUtils.updateNewlyCreatedClone(cloneObject, driverCloneResult, dbClient);
taskCompleter.ready(dbClient);
} else {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
String errorMsg = String.format("doCreateClone -- Failed to create volume clone: %s .", task.getMessage());
_log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception e) {
if (cloneObject != null) {
cloneObject.setInactive(true);
dbClient.updateObject(cloneObject);
}
_log.error("Failed to create volume clone. ", e);
ServiceError serviceError = ExternalDeviceException.errors.createVolumeCloneFailed("doCreateClone", e.getMessage());
taskCompleter.error(dbClient, serviceError);
} finally {
try {
if (task == null || isTaskInTerminalState(task.getStatus())) {
StoragePool dbPool = dbClient.queryObject(StoragePool.class, cloneObject.getPool());
updateStoragePoolCapacity(dbPool, storageSystem, Collections.singletonList(clone), dbClient);
}
} catch (Exception ex) {
_log.error("Failed to update storage pool {} after create clone operation completion.", cloneObject.getPool(), ex);
}
}
}
use of com.emc.storageos.storagedriver.BlockStorageDriver in project coprhd-controller by CoprHD.
the class ExternalBlockStorageDevice method doConnect.
@Override
public void doConnect(StorageSystem storageSystem) {
BlockStorageDriver driver = getDriver(storageSystem.getSystemType());
if (driver == null) {
throw DeviceControllerException.exceptions.connectStorageFailedNoDevice(storageSystem.getSystemType());
}
_log.info("doConnect to external device {} - start", storageSystem.getId());
_log.info("doConnect to external device {} - end", storageSystem.getId());
}
use of com.emc.storageos.storagedriver.BlockStorageDriver 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()));
}
}
use of com.emc.storageos.storagedriver.BlockStorageDriver 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);
}
}
}
Aggregations