use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class BlockDeviceController method rollBackCreateVolumes.
/**
* {@inheritDoc} NOTE: The signature here MUST match the Workflow.Method rollbackCreateVolumesMethod just above
* (except opId).
*/
@Override
public void rollBackCreateVolumes(URI systemURI, List<URI> volumeURIs, String opId) throws ControllerException {
MultiVolumeTaskCompleter completer = new MultiVolumeTaskCompleter(volumeURIs, opId);
List<Volume> volumes = new ArrayList<>(volumeURIs.size());
completer.setRollingBack(true);
try {
String logMsg = String.format("rollbackCreateVolume start - Array:%s, Volume:%s", systemURI.toString(), Joiner.on(',').join(volumeURIs));
_log.info(logMsg.toString());
WorkflowStepCompleter.stepExecuting(opId);
volumes.addAll(_dbClient.queryObject(Volume.class, volumeURIs));
for (Volume volume : volumes) {
// CTRL-5597 clean volumes which have failed only in a multi-volume request
if (null != volume.getNativeGuid()) {
StorageSystem system = _dbClient.queryObject(StorageSystem.class, volume.getStorageController());
if (Type.xtremio.toString().equalsIgnoreCase(system.getSystemType())) {
continue;
}
}
// then we need to clear srdfTargets and personality fields for source
if (null != volume.getSrdfTargets()) {
_log.info("Clearing targets for existing source");
volume.getSrdfTargets().clear();
_dbClient.updateObject(volume);
// Clearing Source CG
URI sourceCgUri = volume.getConsistencyGroup();
if (null != sourceCgUri) {
BlockConsistencyGroup sourceCG = _dbClient.queryObject(BlockConsistencyGroup.class, sourceCgUri);
if (null != sourceCG && (null == sourceCG.getTypes() || NullColumnValueGetter.isNullURI(sourceCG.getStorageController()))) {
sourceCG.getRequestedTypes().remove(Types.SRDF.name());
_dbClient.updateObject(sourceCG);
}
}
}
// for change Virtual Pool, if failed, clear targets and personality field for source and also
if (!NullColumnValueGetter.isNullNamedURI(volume.getSrdfParent())) {
URI sourceUri = volume.getSrdfParent().getURI();
Volume sourceVolume = _dbClient.queryObject(Volume.class, sourceUri);
sourceVolume.setPersonality(NullColumnValueGetter.getNullStr());
if (null != sourceVolume.getSrdfTargets()) {
sourceVolume.getSrdfTargets().clear();
_dbClient.updateObject(sourceVolume);
}
// Clearing target CG
URI cgUri = volume.getConsistencyGroup();
if (null != cgUri) {
BlockConsistencyGroup targetCG = _dbClient.queryObject(BlockConsistencyGroup.class, cgUri);
if (null != targetCG && (null == targetCG.getTypes() || NullColumnValueGetter.isNullURI(targetCG.getStorageController()))) {
_log.info("Set target CG {} inactive", targetCG.getLabel());
targetCG.setInactive(true);
_dbClient.updateObject(targetCG);
}
// clear association between target volume and target cg
volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
_dbClient.updateAndReindexObject(volume);
}
}
// Check for loose export groups associated with this rolled-back volume
URIQueryResultList exportGroupURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeExportGroupConstraint(volume.getId()), exportGroupURIs);
while (exportGroupURIs.iterator().hasNext()) {
URI exportGroupURI = exportGroupURIs.iterator().next();
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
if (!exportGroup.getInactive()) {
exportGroup.removeVolume(volume.getId());
boolean canRemoveGroup = false;
List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup);
// Make sure the volume is not in an export mask
for (ExportMask exportMask : exportMasks) {
exportMask.removeVolume(volume.getId());
exportMask.removeFromUserCreatedVolumes(volume);
exportMask.removeFromExistingVolumes(volume);
if (!exportMask.getCreatedBySystem() && !exportMask.hasAnyVolumes() && exportMask.emptyVolumes()) {
canRemoveGroup = true;
_dbClient.removeObject(exportMask);
} else {
_dbClient.updateObject(exportMask);
}
}
// If we didn't find that volume in a mask, it's OK to remove it.
if (canRemoveGroup && exportMasks.size() == 1 && exportGroup.getVolumes().isEmpty()) {
_dbClient.removeObject(exportGroup);
} else {
_dbClient.updateObject(exportGroup);
}
}
}
}
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_013);
deleteVolumesWithCompleter(systemURI, volumeURIs, completer);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_014);
logMsg = String.format("rollbackCreateVolume end - Array:%s, Volume:%s", systemURI.toString(), Joiner.on(',').join(volumeURIs));
_log.info(logMsg.toString());
} catch (Exception e) {
_log.error(String.format("rollbackCreateVolume Failed - Array:%s, Volume:%s", systemURI.toString(), Joiner.on(',').join(volumeURIs)));
handleException(e, completer);
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class BlockDeviceController method createConsistencyGroup.
@Override
public void createConsistencyGroup(URI storage, URI consistencyGroup, String opId) throws ControllerException {
TaskCompleter completer = new BlockConsistencyGroupCreateCompleter(consistencyGroup, opId);
try {
WorkflowStepCompleter.stepExecuting(opId);
// Lock the CG for the step duration.
List<String> lockKeys = new ArrayList<String>();
lockKeys.add(ControllerLockingUtil.getConsistencyGroupStorageKey(_dbClient, consistencyGroup, storage));
_workflowService.acquireWorkflowStepLocks(opId, lockKeys, LockTimeoutValue.get(LockType.ARRAY_CG));
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
// Check if already created, if not create, if so just complete.
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroup);
String groupName = ControllerUtils.generateReplicationGroupName(storageObj, cg, null, _dbClient);
if (!cg.created(storage, groupName)) {
getDevice(storageObj.getSystemType()).doCreateConsistencyGroup(storageObj, consistencyGroup, groupName, completer);
} else {
_log.info(String.format("Consistency group %s (%s) already created", cg.getLabel(), cg.getId()));
completer.ready(_dbClient);
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(_dbClient, serviceError);
throw DeviceControllerException.exceptions.createConsistencyGroupFailed(e);
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class BlockDeviceController method deleteConsistencyGroup.
@Override
public void deleteConsistencyGroup(URI storage, URI consistencyGroup, Boolean markInactive, String opId) throws ControllerException {
_log.info("START delete consistency group");
TaskCompleter wfCompleter = null;
try {
Workflow workflow = _workflowService.getNewWorkflow(this, "deleteReplicationGroupInConsistencyGroup", true, opId);
wfCompleter = new SimpleTaskCompleter(BlockConsistencyGroup.class, consistencyGroup, opId);
StorageSystem system = _dbClient.queryObject(StorageSystem.class, storage);
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, consistencyGroup);
Set<String> groupNames = BlockConsistencyGroupUtils.getGroupNamesForSystemCG(cg, system);
String stepId = null;
for (String groupName : groupNames) {
Workflow.Method deleteStep = new Workflow.Method("deleteReplicationGroupInConsistencyGroup", storage, consistencyGroup, groupName, false, markInactive, true);
stepId = workflow.createStep("DeleteReplicationGroup", "Deleting replication group", stepId, storage, system.getSystemType(), this.getClass(), deleteStep, rollbackMethodNullMethod(), null);
}
String successMsg = String.format("Successfully deleted replication groups %s", Joiner.on(',').join(groupNames));
workflow.executePlan(wfCompleter, successMsg);
} catch (Exception e) {
if (wfCompleter != null) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
wfCompleter.error(_dbClient, serviceError);
}
throw DeviceControllerException.exceptions.deleteConsistencyGroupFailed(e);
}
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup 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.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class ExternalDeviceExportOperations method createDriverVolume.
/**
* Create driver block object
*
* @param storage
* @param volume
* @return
*/
private StorageVolume createDriverVolume(StorageSystem storage, BlockObject volume) {
StorageVolume driverVolume = new StorageVolume();
driverVolume.setStorageSystemId(storage.getNativeId());
driverVolume.setNativeId(volume.getNativeId());
driverVolume.setDeviceLabel(volume.getDeviceLabel());
if (!NullColumnValueGetter.isNullURI(volume.getConsistencyGroup())) {
BlockConsistencyGroup cg = dbClient.queryObject(BlockConsistencyGroup.class, volume.getConsistencyGroup());
driverVolume.setConsistencyGroup(cg.getLabel());
}
return driverVolume;
}
Aggregations