use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method getVolumesFromScsiProtocolController.
/**
* Returns a map of the volume WWNs to their HLU values for a masking
* container on the array.
*
* @param storage
* [in] - StorageSystem that the masking belongs to
* @param controllerPath
* [in] - CIMObjectPath of IBMTSDS_SCSIProtocolController, holding a representation
* of an array masking container.
* @return - a map of the volume WWNs to their HLU values for an instance of
* LunMasking container on the array.
*/
public Map<String, Integer> getVolumesFromScsiProtocolController(StorageSystem storage, CIMObjectPath controllerPath) {
Map<String, Integer> wwnToHLU = new HashMap<String, Integer>();
CloseableIterator<CIMInstance> iterator = null;
CloseableIterator<CIMInstance> protocolControllerForUnitIter = null;
try {
Map<String, Integer> deviceIdToHLU = new HashMap<String, Integer>();
WBEMClient client = getConnection(storage).getCimClient();
protocolControllerForUnitIter = client.referenceInstances(controllerPath, CIM_PROTOCOL_CONTROLLER_FOR_UNIT, null, false, PS_DEVICE_NUMBER);
while (protocolControllerForUnitIter.hasNext()) {
CIMInstance pcu = protocolControllerForUnitIter.next();
CIMObjectPath pcuPath = pcu.getObjectPath();
CIMProperty<CIMObjectPath> dependentVolumePropery = (CIMProperty<CIMObjectPath>) pcuPath.getKey(CP_DEPENDENT);
CIMObjectPath dependentVolumePath = dependentVolumePropery.getValue();
String deviceId = dependentVolumePath.getKey(CP_DEVICE_ID).getValue().toString();
String deviceNumber = CIMPropertyFactory.getPropertyValue(pcu, CP_DEVICE_NUMBER);
Integer decimalHLU = (int) Long.parseLong(deviceNumber, 16);
deviceIdToHLU.put(deviceId, decimalHLU);
}
iterator = client.associatorInstances(controllerPath, null, CP_STORAGE_VOLUME, null, null, false, PS_NAME);
while (iterator.hasNext()) {
CIMInstance cimInstance = iterator.next();
String deviceId = cimInstance.getObjectPath().getKey(CP_DEVICE_ID).getValue().toString();
String wwn = CIMPropertyFactory.getPropertyValue(cimInstance, CP_NAME);
wwnToHLU.put(wwn.toUpperCase(), deviceIdToHLU.get(deviceId));
}
} catch (WBEMException we) {
_log.error("Caught an error will attempting to get volume list from " + "masking instance", we);
} finally {
if (iterator != null) {
iterator.close();
}
if (protocolControllerForUnitIter != null) {
protocolControllerForUnitIter.close();
}
}
return wwnToHLU;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class XIVSmisStorageDevicePostProcessor method processVolumeCreation.
/*
* (non-Javadoc) Update DB with volume creation output from SMI-S.
*
* @see
* com.emc.storageos.volumecontroller.impl.smis.job.SmisAbstractCreateVolumeJob
* #updateStatus
*/
public Set<URI> processVolumeCreation(StorageSystem storageSystem, URI storagePoolURI, List<Volume> volumes, CIMArgument[] outArgs) throws Exception {
Set<URI> volumeURIs = new HashSet<URI>(volumes.size());
StringBuilder logMsgBuilder = new StringBuilder(String.format("Processing volume creation"));
CimConnection connection = _cimConnection.getConnection(storageSystem);
WBEMClient client = connection.getCimClient();
Calendar now = Calendar.getInstance();
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolURI);
updateStoragePoolCapacity(client, storagePool);
StringMap reservationMap = storagePool.getReservedCapacityMap();
for (Volume volume : volumes) {
reservationMap.remove(volume.getId().toString());
}
_dbClient.persistObject(storagePool);
CIMObjectPath[] elements = (CIMObjectPath[]) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_THE_ELEMENTS);
UnsignedInteger32[] returnCoedes = (UnsignedInteger32[]) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_RETURN_CODES);
List<Volume> volumesToSave = new ArrayList<Volume>(elements.length);
if (elements != null && returnCoedes != null) {
for (int i = 0; i < elements.length; i++) {
URI volumeId = volumes.get(i).getId();
Volume volume = _dbClient.queryObject(Volume.class, volumeId);
volumesToSave.add(volume);
volumeURIs.add(volumeId);
boolean isSuccess = false;
CIMObjectPath volumePath = elements[i];
if (volumePath != null) {
CIMProperty<String> deviceID = (CIMProperty<String>) volumePath.getKey(IBMSmisConstants.CP_DEVICE_ID);
if (deviceID != null) {
String nativeID = deviceID.getValue();
if ((nativeID != null) && (nativeID.length() != 0)) {
isSuccess = true;
volume.setPool(storagePoolURI);
processVolume(volumePath, nativeID, volume, client, logMsgBuilder, now);
}
}
}
if (!isSuccess) {
logMsgBuilder.append("\n");
logMsgBuilder.append(String.format("Failed to create volume: %s with return code: %s", volumeId, returnCoedes[i].toString()));
volume.setInactive(true);
}
}
}
if (!volumesToSave.isEmpty()) {
_dbClient.persistObject(volumesToSave);
}
_log.info(logMsgBuilder.toString());
return volumeURIs;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class XIVSmisStorageDevicePostProcessor method processCloneCreation.
@SuppressWarnings("rawtypes")
public void processCloneCreation(StorageSystem storageSystem, URI volumeURI, CIMArgument[] outArgs, CloneCreateCompleter taskCompleter) throws Exception {
StringBuilder logMsgBuilder = new StringBuilder(String.format("Processing clone creation - "));
CimConnection connection = _cimConnection.getConnection(storageSystem);
WBEMClient client = connection.getCimClient();
Volume cloneVolume = _dbClient.queryObject(Volume.class, volumeURI);
URI poolURI = cloneVolume.getPool();
StoragePool pool = _dbClient.queryObject(StoragePool.class, poolURI);
updateStoragePoolCapacity(client, pool);
StringMap reservationMap = pool.getReservedCapacityMap();
// remove from reservation map
reservationMap.remove(cloneVolume.getId().toString());
_dbClient.persistObject(pool);
CIMObjectPath cloneVolumePath = (CIMObjectPath) _cimPath.getFromOutputArgs(outArgs, IBMSmisConstants.CP_TARGET_ELEMENT);
if (cloneVolumePath != null) {
// Get the sync volume native device id
CIMInstance syncVolume = client.getInstance(cloneVolumePath, false, false, null);
String deviceID = cloneVolumePath.getKey(IBMSmisConstants.CP_DEVICE_ID).getValue().toString();
String elementName = CIMPropertyFactory.getPropertyValue(syncVolume, IBMSmisConstants.CP_ELEMENT_NAME);
String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, IBMSmisConstants.CP_NAME);
cloneVolume.setNativeId(deviceID);
cloneVolume.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, cloneVolume));
cloneVolume.setLabel(elementName);
cloneVolume.setDeviceLabel(elementName);
cloneVolume.setInactive(false);
cloneVolume.setCreationTime(Calendar.getInstance());
cloneVolume.setWWN(wwn.toUpperCase());
cloneVolume.setAlternateName(wwn);
cloneVolume.setProvisionedCapacity(getProvisionedCapacityInformation(syncVolume));
cloneVolume.setAllocatedCapacity(getAllocatedCapacityInformation(client, syncVolume));
logMsgBuilder.append(String.format("For sync volume path %1$s, going to set blocksnapshot %2$s nativeId to %3$s.", cloneVolumePath.toString(), cloneVolume.getId().toString(), deviceID));
_dbClient.persistObject(cloneVolume);
taskCompleter.ready(_dbClient);
} else {
cloneVolume.setInactive(true);
_dbClient.persistObject(cloneVolume);
ServiceError error = DeviceControllerErrors.smis.unableToFindSynchPath(volumeURI.toString());
logMsgBuilder.append(error.getMessage());
_log.error(logMsgBuilder.toString());
throw new Exception(error.getMessage());
}
_log.info(logMsgBuilder.toString());
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisBlockCreateCGSnapshotJob method updateStatus.
@Override
public void updateStatus(JobContext jobContext) throws Exception {
CloseableIterator<CIMObjectPath> syncVolumeIter = null;
DbClient dbClient = jobContext.getDbClient();
JobStatus jobStatus = getJobStatus();
try {
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
BlockSnapshotCreateCompleter completer = (BlockSnapshotCreateCompleter) getTaskCompleter();
List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, completer.getSnapshotURIs());
StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
if (jobStatus == JobStatus.SUCCESS) {
// Create mapping of volume.nativeDeviceId to BlockSnapshot object
Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
for (BlockSnapshot snapshot : snapshots) {
Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
volumeToSnapMap.put(volume.getNativeId(), snapshot);
}
// Iterate through the snapshot elements that were created by the
// Job and try to match them up with the appropriate BlockSnapshot
CIMConnectionFactory cimConnectionFactory = jobContext.getCimConnectionFactory();
WBEMClient client = getWBEMClient(dbClient, cimConnectionFactory);
CIMObjectPath replicationGroupPath = client.associatorNames(getCimJob(), null, SmisConstants.SE_REPLICATION_GROUP, null, null).next();
String replicationGroupInstance = (String) replicationGroupPath.getKey(SmisConstants.CP_INSTANCE_ID).getValue();
replicationGroupInstance = SmisUtils.getTargetGroupName(replicationGroupInstance, storage.getUsingSmis80());
String relationshipName = getRelationShipName(client, replicationGroupPath, replicationGroupInstance);
syncVolumeIter = client.associatorNames(replicationGroupPath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
Calendar now = Calendar.getInstance();
while (syncVolumeIter.hasNext()) {
// Get the sync volume native device id
CIMObjectPath syncVolumePath = syncVolumeIter.next();
CIMInstance syncVolume = client.getInstance(syncVolumePath, false, false, null);
String syncDeviceID = syncVolumePath.getKey(SmisConstants.CP_DEVICE_ID).getValue().toString();
String elementName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_ELEMENT_NAME);
// Get the associated volume for this sync volume
CIMObjectPath volumePath = null;
CloseableIterator<CIMObjectPath> volumeIter = client.associatorNames(syncVolumePath, null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
volumePath = volumeIter.next();
volumeIter.close();
String volumeDeviceID = volumePath.getKey(SmisConstants.CP_DEVICE_ID).getValue().toString();
String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_WWN_NAME);
String alternativeName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_NAME);
// Lookup the associated snapshot based on the volume native device id
BlockSnapshot snapshot = volumeToSnapMap.get(volumeDeviceID);
// we need to perform this null check to avoid a NPE.
if (snapshot != null) {
snapshot.setNativeId(syncDeviceID);
snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, snapshot));
snapshot.setReplicationGroupInstance(replicationGroupInstance);
snapshot.setDeviceLabel(elementName);
snapshot.setInactive(false);
snapshot.setIsSyncActive(_wantSyncActive);
snapshot.setCreationTime(now);
snapshot.setWWN(wwn.toUpperCase());
snapshot.setAlternateName(alternativeName);
commonSnapshotUpdate(snapshot, syncVolume, client, storage, _sourceGroupId, relationshipName, true, dbClient);
_log.info(String.format("For sync volume path %1$s, going to set blocksnapshot %2$s nativeId to %3$s (%4$s). " + "Replication Group instance is %5$s. Associated volume is %6$s", syncVolumePath.toString(), snapshot.getId().toString(), syncDeviceID, elementName, replicationGroupInstance, volumePath.toString()));
dbClient.updateObject(snapshot);
}
}
} else if (jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
_log.info("Failed to create snapshot");
for (BlockSnapshot snapshot : snapshots) {
snapshot.setInactive(true);
}
dbClient.updateObject(snapshots);
}
} catch (Exception e) {
setPostProcessingErrorStatus("Encountered an internal error during create CG snapshot job status processing: " + e.getMessage());
_log.error("Caught an exception while trying to updateStatus for SmisBlockCreateCGSnapshotJob", e);
} finally {
if (syncVolumeIter != null) {
syncVolumeIter.close();
}
super.updateStatus(jobContext);
}
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class SmisBlockCreateMirrorJob method updateStatus.
@Override
public void updateStatus(JobContext jobContext) throws Exception {
CloseableIterator<CIMObjectPath> syncVolumeIter = null;
DbClient dbClient = jobContext.getDbClient();
BlockMirrorCreateCompleter completer = null;
JobStatus jobStatus = getJobStatus();
try {
if (jobStatus == JobStatus.IN_PROGRESS) {
return;
}
completer = (BlockMirrorCreateCompleter) getTaskCompleter();
BlockMirror mirror = dbClient.queryObject(BlockMirror.class, completer.getMirrorURI());
StorageSystem storage = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
CIMConnectionFactory cimConnectionFactory;
WBEMClient client = null;
// from pool's reserved capacity map.
if (jobStatus == JobStatus.SUCCESS || jobStatus == JobStatus.FAILED || jobStatus == JobStatus.FATAL_ERROR) {
cimConnectionFactory = jobContext.getCimConnectionFactory();
client = getWBEMClient(dbClient, cimConnectionFactory);
URI poolURI = mirror.getPool();
SmisUtils.updateStoragePoolCapacity(dbClient, client, poolURI);
StoragePool pool = dbClient.queryObject(StoragePool.class, poolURI);
StringMap reservationMap = pool.getReservedCapacityMap();
// remove from reservation map
reservationMap.remove(mirror.getId().toString());
dbClient.persistObject(pool);
}
if (jobStatus == JobStatus.SUCCESS) {
_log.info("Mirror creation success");
cimConnectionFactory = jobContext.getCimConnectionFactory();
client = getWBEMClient(dbClient, cimConnectionFactory);
syncVolumeIter = client.associatorNames(getCimJob(), null, SmisConstants.CIM_STORAGE_VOLUME, null, null);
if (syncVolumeIter.hasNext()) {
// Get the target mirror volume native device id
CIMObjectPath targetVolumePath = syncVolumeIter.next();
CIMInstance syncVolume = client.getInstance(targetVolumePath, false, false, null);
String syncDeviceID = targetVolumePath.getKey(SmisConstants.CP_DEVICE_ID).getValue().toString();
String elementName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_ELEMENT_NAME);
String wwn = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_WWN_NAME);
String alternateName = CIMPropertyFactory.getPropertyValue(syncVolume, SmisConstants.CP_NAME);
CIMInstance syncInstance = getStorageSyncInstanceFromVolume(client, targetVolumePath);
// Lookup the associated source volume based on the volume native device id
mirror.setProvisionedCapacity(getProvisionedCapacityInformation(client, syncVolume));
mirror.setAllocatedCapacity(getAllocatedCapacityInformation(client, syncVolume));
mirror.setWWN(wwn);
mirror.setAlternateName(alternateName);
mirror.setNativeId(syncDeviceID);
mirror.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storage, mirror));
mirror.setDeviceLabel(elementName);
mirror.setInactive(false);
mirror.setSynchronizedInstance(syncInstance.getObjectPath().toString());
updateSynchronizationAspects(client, mirror);
// mirror.setIsSyncActive(_wantSyncActive);
Volume volume = dbClient.queryObject(Volume.class, mirror.getSource().getURI());
_log.info(String.format("For target mirror volume %1$s, going to set BlockMirror %2$s nativeId to %3$s (%4$s). Associated volume is %5$s (%6$s)", targetVolumePath.toString(), mirror.getId().toString(), syncDeviceID, elementName, volume.getNativeId(), volume.getDeviceLabel()));
dbClient.persistObject(mirror);
}
} else if (isJobInTerminalFailedState()) {
_log.info("Failed to create mirror");
completer.error(dbClient, DeviceControllerException.exceptions.attachVolumeMirrorFailed(getMessage()));
mirror.setInactive(true);
dbClient.persistObject(mirror);
}
} catch (Exception e) {
setFatalErrorStatus("Encountered an internal error during block create mirror job status processing: " + e.getMessage());
_log.error("Caught an exception while trying to updateStatus for SmisBlockCreateMirrorJob", e);
if (completer != null) {
completer.error(dbClient, DeviceControllerException.errors.jobFailed(e));
}
} finally {
if (syncVolumeIter != null) {
syncVolumeIter.close();
}
super.updateStatus(jobContext);
}
}
Aggregations