use of javax.wbem.client.WBEMClient 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 javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class XIVSmisStorageDevicePostProcessor method processVolumeExpansion.
/**
* Update DB with SMI-S output.
*/
public void processVolumeExpansion(StorageSystem storageSystem, URI storagePoolURI, URI volumeId, CIMArgument[] outArgs) throws Exception {
StringBuilder logMsgBuilder = new StringBuilder(String.format("Processing volume expansion - "));
CimConnection connection = _cimConnection.getConnection(storageSystem);
WBEMClient client = connection.getCimClient();
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolURI);
StringMap reservationMap = storagePool.getReservedCapacityMap();
reservationMap.remove(volumeId.toString());
updateStoragePoolCapacity(client, storagePool);
_dbClient.persistObject(storagePool);
Volume volume = _dbClient.queryObject(Volume.class, volumeId);
CIMObjectPath volumePath = (CIMObjectPath) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_THE_ELEMENT);
boolean isSuccess = false;
if (volumePath != null) {
CIMInstance volumeInstance = client.getInstance(volumePath, true, false, null);
if (volumeInstance != null) {
isSuccess = true;
volume.setProvisionedCapacity(getProvisionedCapacityInformation(volumeInstance));
volume.setAllocatedCapacity(getAllocatedCapacityInformation(client, volumeInstance));
_dbClient.persistObject(volume);
logMsgBuilder.append(String.format("%n Capacity: %s, Provisioned capacity: %s, Allocated Capacity: %s", volume.getCapacity(), volume.getProvisionedCapacity(), volume.getAllocatedCapacity()));
}
}
if (!isSuccess) {
UnsignedInteger32 returnCoede = (UnsignedInteger32) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_RETURN_CODE);
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Failed to expand volume: %s with return code: %s", volume.getId(), returnCoede.toString()));
}
_log.info(logMsgBuilder.toString());
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisAbstractCreateVolumeJob method updateStatus.
/**
* Called to update the job status when the volume create job completes.
* <p/>
* This is common update code for volume create operations.
*
* @param jobContext The job context.
*/
@Override
public void updateStatus(JobContext jobContext) throws Exception {
CloseableIterator<CIMObjectPath> iterator = null;
DbClient dbClient = jobContext.getDbClient();
JobStatus jobStatus = getJobStatus();
try {
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
int volumeCount = 0;
String opId = getTaskCompleter().getOpId();
StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, jobStatus.name()));
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
iterator = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
Calendar now = Calendar.getInstance();
// from pool's reserved capacity map.
if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
SmisUtils.updateStoragePoolCapacity(dbClient, client, _storagePool);
StoragePool pool = dbClient.queryObject(StoragePool.class, _storagePool);
StringMap reservationMap = pool.getReservedCapacityMap();
for (URI volumeId : getTaskCompleter().getIds()) {
// remove from reservation map
reservationMap.remove(volumeId.toString());
}
dbClient.persistObject(pool);
}
if (jobStatus == JobStatus.SUCCESS) {
List<URI> volumes = new ArrayList<URI>();
while (iterator.hasNext()) {
CIMObjectPath volumePath = iterator.next();
CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
String nativeID = deviceID.getValue();
URI volumeId = getTaskCompleter().getId(volumeCount++);
volumes.add(volumeId);
persistVolumeNativeID(dbClient, volumeId, nativeID, now);
processVolume(jobContext, volumePath, nativeID, volumeId, client, dbClient, logMsgBuilder, now);
}
// Add Volumes to Consistency Group (if needed)
addVolumesToConsistencyGroup(jobContext, volumes);
} else if (jobStatus == JobStatus.FAILED) {
if (iterator.hasNext()) {
while (iterator.hasNext()) {
CIMObjectPath volumePath = iterator.next();
CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(SmisConstants.CP_DEVICE_ID);
String nativeID = deviceID.getValue();
URI volumeId = getTaskCompleter().getId(volumeCount++);
if ((nativeID != null) && (nativeID.length() != 0)) {
persistVolumeNativeID(dbClient, volumeId, nativeID, now);
processVolume(jobContext, volumePath, nativeID, volumeId, client, dbClient, logMsgBuilder, now);
} else {
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, volumeId));
Volume volume = dbClient.queryObject(Volume.class, volumeId);
volume.setInactive(true);
dbClient.persistObject(volume);
}
}
} else {
for (URI id : getTaskCompleter().getIds()) {
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, id.toString()));
Volume volume = dbClient.queryObject(Volume.class, id);
volume.setInactive(true);
dbClient.persistObject(volume);
}
}
}
_log.info(logMsgBuilder.toString());
} catch (Exception e) {
_log.error("Caught an exception while trying to updateStatus for SmisCreateVolumeJob", e);
setPostProcessingErrorStatus("Encountered an internal error during volume create job status processing : " + e.getMessage());
} finally {
super.updateStatus(jobContext);
if (iterator != null) {
iterator.close();
}
}
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisBlockCreateCGMirrorJob method updateStatus.
public void updateStatus(JobContext jobContext) throws Exception {
CloseableIterator<CIMInstance> syncVolumeIter = null;
CloseableIterator<CIMObjectPath> repGroupPathIter = null;
DbClient dbClient = jobContext.getDbClient();
BlockMirrorCreateCompleter completer = (BlockMirrorCreateCompleter) getTaskCompleter();
;
JobStatus jobStatus = getJobStatus();
try {
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
List<BlockMirror> mirrors = dbClient.queryObject(BlockMirror.class, completer.getIds());
if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
updatePools(client, dbClient, mirrors);
}
if (jobStatus == JobStatus.SUCCESS) {
_log.info("Group mirror creation success");
repGroupPathIter = client.associatorNames(getCimJob(), null, SmisConstants.SE_REPLICATION_GROUP, null, null);
CIMObjectPath repGroupPath = repGroupPathIter.next();
StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
String repGroupID = (String) repGroupPath.getKey(SmisConstants.CP_INSTANCE_ID).getValue();
repGroupID = SmisUtils.getTargetGroupName(repGroupID, storage.getUsingSmis80());
CIMInstance syncInst = getSynchronizedInstance(client, repGroupPath);
String syncType = CIMPropertyFactory.getPropertyValue(syncInst, SmisConstants.CP_SYNC_TYPE);
syncVolumeIter = client.associatorInstances(repGroupPath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null, false, _volumeProps);
processCGMirrors(syncVolumeIter, client, dbClient, jobContext.getSmisCommandHelper(), storage, mirrors, repGroupID, syncInst.getObjectPath().toString(), syncType);
} else if (isJobInTerminalFailedState()) {
_log.info("Failed to create group mirrors");
completer.error(dbClient, DeviceControllerException.exceptions.attachVolumeMirrorFailed(getMessage()));
for (BlockMirror mirror : mirrors) {
mirror.setInactive(true);
}
dbClient.persistObject(mirrors);
}
} catch (Exception e) {
setPostProcessingErrorStatus("Encountered an internal error during block create CG mirror job status processing: " + e.getMessage());
_log.error("Caught an exception while trying to updateStatus for SmisBlockCreateCGMirrorJob", e);
} finally {
if (syncVolumeIter != null) {
syncVolumeIter.close();
}
if (repGroupPathIter != null) {
repGroupPathIter.close();
}
super.updateStatus(jobContext);
}
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class ValidateVolumeIdentity method validate.
@Override
public boolean validate() throws Exception {
getLogger().setLog(log);
for (Volume volume : volumes) {
CIMObjectPath volumePath = getCimPath().getBlockObjectPath(system, volume);
CimConnection connection = getHelper().getConnection(system);
WBEMClient cimClient = connection.getCimClient();
CIMInstance instance = cimClient.getInstance(volumePath, false, false, PROP_KEYS);
checkForDifferences(instance, volume);
}
return getLogger().hasErrors();
}
Aggregations