use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter in project coprhd-controller by CoprHD.
the class BlockDeviceController method createMetaVolumes.
/**
* {@inheritDoc} NOTE NOTE: The signature here MUST match the Workflow.Method createMetaVolumesMethod just above
* (except opId).
*/
@Override
public void createMetaVolumes(URI systemURI, URI poolURI, List<URI> volumeURIs, VirtualPoolCapabilityValuesWrapper capabilities, String opId) throws ControllerException {
boolean opCreateFailed = false;
List<Volume> volumes = new ArrayList<Volume>();
try {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, systemURI);
List<VolumeTaskCompleter> volumeCompleters = new ArrayList<VolumeTaskCompleter>();
Iterator<URI> volumeURIsIter = volumeURIs.iterator();
StringBuilder logMsgBuilder = new StringBuilder(String.format("createMetaVolumes start - Array:%s Pool:%s", systemURI.toString(), poolURI.toString()));
while (volumeURIsIter.hasNext()) {
URI volumeURI = volumeURIsIter.next();
logMsgBuilder.append(String.format("%nVolume:%s", volumeURI.toString()));
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
volumes.add(volume);
VolumeCreateCompleter volumeCompleter = new VolumeCreateCompleter(volumeURI, opId);
volumeCompleters.add(volumeCompleter);
}
_log.info(logMsgBuilder.toString());
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, poolURI);
MultiVolumeTaskCompleter completer = new MultiVolumeTaskCompleter(volumeURIs, volumeCompleters, opId);
Volume volume = volumes.get(0);
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
// All volumes are in the same storage pool with the same capacity. Get recommendation for the first volume.
MetaVolumeRecommendation recommendation = MetaVolumeUtils.getCreateRecommendation(storageSystem, storagePool, volume.getCapacity(), volume.getThinlyProvisioned(), vpool.getFastExpansion(), capabilities);
for (Volume metaVolume : volumes) {
MetaVolumeUtils.prepareMetaVolume(metaVolume, recommendation.getMetaMemberSize(), recommendation.getMetaMemberCount(), recommendation.getMetaVolumeType().toString(), _dbClient);
}
WorkflowStepCompleter.stepExecuting(completer.getOpId());
getDevice(storageSystem.getSystemType()).doCreateMetaVolumes(storageSystem, storagePool, volumes, capabilities, recommendation, completer);
logMsgBuilder = new StringBuilder(String.format("createMetaVolumes end - Array:%s Pool:%s", systemURI.toString(), poolURI.toString()));
volumeURIsIter = volumeURIs.iterator();
while (volumeURIsIter.hasNext()) {
logMsgBuilder.append(String.format("%nVolume:%s", volumeURIsIter.next().toString()));
}
_log.info(logMsgBuilder.toString());
} catch (InternalException e) {
_log.error(String.format("createMetaVolumes Failed - Array: %s Pool:%s Volume:%s", systemURI.toString(), poolURI.toString(), Joiner.on("\t").join(volumeURIs)));
doFailTask(Volume.class, volumeURIs, opId, e);
WorkflowStepCompleter.stepFailed(opId, e);
opCreateFailed = true;
} catch (Exception e) {
_log.error(String.format("createMetaVolumes Failed - Array: %s Pool:%s Volume:%s", systemURI.toString(), poolURI.toString(), Joiner.on("\t").join(volumeURIs)));
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
doFailTask(Volume.class, volumeURIs, opId, serviceError);
WorkflowStepCompleter.stepFailed(opId, serviceError);
opCreateFailed = true;
}
if (opCreateFailed) {
for (Volume volume : volumes) {
volume.setInactive(true);
_dbClient.updateObject(volume);
}
}
}
use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter in project coprhd-controller by CoprHD.
the class CinderStorageDevice method doDeleteVolumes.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doDeleteVolumes
* (com.emc.storageos.db.client.model.StorageSystem,
* java.lang.String,
* java.util.List,
* com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
List<String> volumeNativeIdsToDelete = new ArrayList<String>(volumes.size());
List<String> volumeLabels = new ArrayList<String>(volumes.size());
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume Start - Array:%s", storageSystem.getSerialNumber()));
log.info(logMsgBuilder.toString());
MultiVolumeTaskCompleter multiVolumeTaskCompleter = (MultiVolumeTaskCompleter) taskCompleter;
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);
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
try {
// Check if the volume is present on the back-end device
cinderApi.showVolume(volume.getNativeId());
} catch (CinderException ce) {
// This means, the volume is not present on the back-end device
log.info(String.format("Volume %s already deleted: ", volume.getNativeId()));
volume.setInactive(true);
dbClient.persistObject(volume);
VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
deleteTaskCompleter.ready(dbClient);
continue;
}
volumeNativeIdsToDelete.add(volume.getNativeId());
volumeLabels.add(volume.getLabel());
// cleanup if there are any snapshots created for a volume
cleanupAnyBackupSnapshots(volume, cinderApi);
}
// Now - trigger the delete
if (!multiVolumeTaskCompleter.isVolumeTaskCompletersEmpty()) {
cinderApi.deleteVolumes(volumeNativeIdsToDelete.toArray(new String[] {}));
ControllerServiceImpl.enqueueJob(new QueueJob(new CinderDeleteVolumeJob(volumeNativeIdsToDelete.get(0), volumeLabels.get(0), volumes.get(0).getStorageController(), CinderConstants.ComponentType.volume.name(), ep, taskCompleter)));
} else {
// If we are here, there are no volumes to delete, we have
// invoked ready() for the VolumeDeleteCompleter, and told
// the multiVolumeTaskCompleter to skip these completers.
// In this case, the multiVolumeTaskCompleter complete()
// method will not be invoked and the result is that the
// workflow that initiated this delete request will never
// be updated. So, here we just call complete() on the
// multiVolumeTaskCompleter to ensure the workflow status is
// updated.
multiVolumeTaskCompleter.ready(dbClient);
}
} catch (Exception e) {
log.error("Problem in doDeleteVolume: ", e);
ServiceError error = DeviceControllerErrors.cinder.operationFailed("doDeleteVolume", e.getMessage());
taskCompleter.error(dbClient, error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume End - Array: %s", storageSystem.getSerialNumber()));
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
}
log.info(logMsgBuilder.toString());
}
use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter in project coprhd-controller by CoprHD.
the class XIVSmisStorageDevicePostProcessor method processVolumeDeletion.
/**
* Update DB with SMI-S output, also set task completer status.
*/
public List<Volume> processVolumeDeletion(StorageSystem storageSystem, List<Volume> volumes, CIMArgument[] outArgs, MultiVolumeTaskCompleter multiVolumeTaskCompleter) throws Exception {
CimConnection connection = _cimConnection.getConnection(storageSystem);
WBEMClient client = connection.getCimClient();
List<Volume> volumesToProcess = new ArrayList<Volume>();
for (Volume vol : volumes) {
Volume volume = _dbClient.queryObject(Volume.class, vol.getId());
volumesToProcess.add(volume);
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, volume.getPool());
updateStoragePoolCapacity(client, storagePool);
}
StringBuilder logMsgBuilder = new StringBuilder();
UnsignedInteger32[] returnCoedes = (UnsignedInteger32[]) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_RETURN_CODES);
List<Volume> volumesToSave = new ArrayList<Volume>(returnCoedes.length);
for (int i = 0; i < returnCoedes.length; i++) {
Volume volume = volumesToProcess.get(i);
VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
if (returnCoedes[i].longValue() == 0L) {
volume.setInactive(true);
volume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
_dbClient.updateAndReindexObject(volume);
deleteTaskCompleter.ready(_dbClient);
if (logMsgBuilder.length() != 0) {
logMsgBuilder.append("\n");
}
logMsgBuilder.append(String.format("Successfully deleted volume %s", volume.getId()));
} else {
// cannot delete volume
String errorMessage = String.format("Failed to delete volume: %s , nativeId: %s with return code: %s", volume.getId(), volume.getNativeId(), returnCoedes[i].toString());
ServiceError error = DeviceControllerErrors.smis.methodFailed("doDeleteVolume", errorMessage);
deleteTaskCompleter.error(_dbClient, error);
if (logMsgBuilder.length() != 0) {
logMsgBuilder.append("\n");
}
logMsgBuilder.append(errorMessage);
}
}
if (logMsgBuilder.length() > 0) {
_log.info(logMsgBuilder.toString());
}
return volumesToSave;
}
use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter in project coprhd-controller by CoprHD.
the class HDSStorageDevice method doDeleteVolumes.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.volumecontroller.BlockStorageDevice#doDeleteVolumes(com.emc.storageos.db.client.model.StorageSystem,
* java.lang.String, java.util.List, com.emc.storageos.volumecontroller.TaskCompleter)
*/
@Override
public void doDeleteVolumes(StorageSystem storageSystem, String opId, List<Volume> volumes, TaskCompleter taskCompleter) throws DeviceControllerException {
try {
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume Start - Array:%s", storageSystem.getSerialNumber()));
MultiVolumeTaskCompleter multiVolumeTaskCompleter = (MultiVolumeTaskCompleter) taskCompleter;
Set<String> thickLogicalUnitIdList = new HashSet<String>();
Set<String> thinLogicalUnitIdList = new HashSet<String>();
HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
String systemObjectId = HDSUtils.getSystemObjectID(storageSystem);
log.info("volumes size: {}", volumes.size());
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
String logicalUnitObjectId = HDSUtils.getLogicalUnitObjectId(volume.getNativeId(), storageSystem);
LogicalUnit logicalUnit = hdsApiClient.getLogicalUnitInfo(systemObjectId, logicalUnitObjectId);
if (logicalUnit == null) {
// related volume state (if any) has been deleted. skip
// processing, if already deleted from array.
log.info(String.format("Volume %s already deleted: ", volume.getNativeId()));
volume.setInactive(true);
dbClient.persistObject(volume);
VolumeTaskCompleter deleteTaskCompleter = multiVolumeTaskCompleter.skipTaskCompleter(volume.getId());
deleteTaskCompleter.ready(dbClient);
continue;
}
if (volume.getThinlyProvisioned()) {
thinLogicalUnitIdList.add(logicalUnitObjectId);
} else {
thickLogicalUnitIdList.add(logicalUnitObjectId);
}
}
log.info(logMsgBuilder.toString());
if (!multiVolumeTaskCompleter.isVolumeTaskCompletersEmpty()) {
if (null != thickLogicalUnitIdList && !thickLogicalUnitIdList.isEmpty()) {
String asyncThickLUsJobId = hdsApiClient.deleteThickLogicalUnits(systemObjectId, thickLogicalUnitIdList, storageSystem.getModel());
if (null != asyncThickLUsJobId) {
ControllerServiceImpl.enqueueJob(new QueueJob(new HDSDeleteVolumeJob(asyncThickLUsJobId, volumes.get(0).getStorageController(), taskCompleter)));
} else {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete volume call");
}
}
if (null != thinLogicalUnitIdList && !thinLogicalUnitIdList.isEmpty()) {
String asyncThinHDSJobId = hdsApiClient.deleteThinLogicalUnits(systemObjectId, thinLogicalUnitIdList, storageSystem.getModel());
// in single operation.
if (null != asyncThinHDSJobId) {
ControllerServiceImpl.enqueueJob(new QueueJob(new HDSDeleteVolumeJob(asyncThinHDSJobId, volumes.get(0).getStorageController(), taskCompleter)));
} else {
throw HDSException.exceptions.asyncTaskFailed("Unable to get async taskId from HiCommand Device Manager for the delete volume call");
}
}
} else {
// If we are here, there are no volumes to delete, we have
// invoked ready() for the VolumeDeleteCompleter, and told
// the multiVolumeTaskCompleter to skip these completers.
// In this case, the multiVolumeTaskCompleter complete()
// method will not be invoked and the result is that the
// workflow that initiated this delete request will never
// be updated. So, here we just call complete() on the
// multiVolumeTaskCompleter to ensure the workflow status is
// updated.
multiVolumeTaskCompleter.ready(dbClient);
}
} catch (Exception e) {
log.error("Problem in doDeleteVolume: ", e);
ServiceError error = DeviceControllerErrors.hds.methodFailed("doDeleteVolume", e.getMessage());
taskCompleter.error(dbClient, error);
}
StringBuilder logMsgBuilder = new StringBuilder(String.format("Delete Volume End - Array: %s", storageSystem.getSerialNumber()));
for (Volume volume : volumes) {
logMsgBuilder.append(String.format("%nVolume:%s", volume.getLabel()));
}
log.info(logMsgBuilder.toString());
}
use of com.emc.storageos.volumecontroller.impl.block.taskcompleter.VolumeTaskCompleter in project coprhd-controller by CoprHD.
the class BlockStorageDeviceTest method performOperation.
private void performOperation(Operation operation) {
String taskId = UUID.randomUUID().toString();
if (Operation.Create.equals(operation)) {
List<Volume> volumes = createVolumes();
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
TaskCompleter taskCompleter = new VolumeCreateCompleter(volumes.get(0).getId(), taskId);
_deviceController.doCreateVolumes(_storageSystem, _storagePool, taskId, volumes, capabilities, taskCompleter);
// TODO - assert vols are created
// update vol labels with real label
} else if (Operation.Expand.equals(operation)) {
List<Volume> volumes = getVolumes(_storageSystem);
Volume volume = volumes.get(0);
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, volume.getPool());
long size = volume.getProvisionedCapacity() * 2;
TaskCompleter taskCompleter = new VolumeExpandCompleter(volume.getId(), size, taskId);
_deviceController.doExpandVolume(_storageSystem, storagePool, volume, size, taskCompleter);
// TODO - assert original vol's size (provisionedCapacity or
// capacity??) are changed
} else if (Operation.Delete.equals(operation)) {
List<Volume> volumes = getVolumes(_storageSystem);
List<URI> ids = new ArrayList<URI>(volumes.size());
List<VolumeTaskCompleter> volumeTaskCompleters = new ArrayList<>(volumes.size());
for (Volume volume : volumes) {
URI uri = volume.getId();
ids.add(uri);
volumeTaskCompleters.add(new VolumeCreateCompleter(uri, taskId));
}
MultiVolumeTaskCompleter multiTaskCompleter = new MultiVolumeTaskCompleter(ids, volumeTaskCompleters, taskId);
_deviceController.doDeleteVolumes(_storageSystem, taskId, volumes, multiTaskCompleter);
// TODO - assert vols are deleted from db
}
}
Aggregations