use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class IBMCIMObjectPathFactory method getSyncObject.
/**
* Return IBMTSDS_StorageSynchronized instance referenced by the given
* BlockObject.
*
* @param storage
* @param subject
* @return CIMObjectPath
*/
public CIMObjectPath getSyncObject(StorageSystem storage, BlockObject subject) {
CloseableIterator<CIMObjectPath> syncReference = null;
CIMObjectPath syncObjectPath = NULL_IBM_CIM_OBJECT_PATH;
try {
CIMObjectPath subjectPath = getBlockObjectPath(storage, subject);
syncReference = _cimConnection.getConnection(storage).getCimClient().referenceNames(subjectPath, CP_STORAGE_SYNCHRONIZED, null);
if (syncReference != null) {
while (syncReference.hasNext()) {
syncObjectPath = syncReference.next();
if (syncObjectPath != null) {
break;
}
}
}
} catch (WBEMException e) {
_log.warn(String.format("Trying to find syncObject for %s failed", subject.getId()));
} finally {
if (syncReference != null) {
syncReference.close();
}
}
return syncObjectPath;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class IBMCIMObjectPathFactory method executeQuery.
/**
* Executes query
*
* @param storageSystem
* @param query
* @param queryLanguage
* @return list of matched instances
*/
public List<CIMInstance> executeQuery(StorageSystem storageSystem, CIMObjectPath objectPath, String query, String queryLanguage) {
CloseableIterator<CIMInstance> iterator = null;
CimConnection connection = _cimConnection.getConnection(storageSystem);
WBEMClient client = connection.getCimClient();
_log.info(String.format("Executing query: %s, objectPath: %s, query language: %s", query, objectPath, queryLanguage));
List<CIMInstance> instanceList = new ArrayList<CIMInstance>();
try {
iterator = client.execQuery(objectPath, query, queryLanguage);
while (iterator.hasNext()) {
CIMInstance instance = iterator.next();
instanceList.add(instance);
}
} catch (WBEMException we) {
_log.error("Caught an error while attempting to execute query and process query result. Query: " + query, we);
} finally {
if (iterator != null) {
iterator.close();
}
}
return instanceList;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method checkExists.
/**
* Wrapper for the getInstance. If the object is not found, it returns a null
* value instead of throwing an exception.
*
* @param storage
* [required] - StorageSystem object to which an SMI-S connection would be made
* @param objectPath
* [required]
* @param propagated
* [required]
* @param includeClassOrigin
* [required]
* @param propertyList
* - An array of property names used to filter what is contained in the instances
* returned.
* @return CIMInstance object that represents the existing object
* @throws Exception
*/
private CIMInstance checkExists(StorageSystem storage, CIMObjectPath objectPath, boolean propagated, boolean includeClassOrigin, String[] propertyList) throws Exception {
CIMInstance instance = null;
try {
if (objectPath != null) {
_log.debug(String.format("checkExists(storage=%s, objectPath=%s, propagated=%s, includeClassOrigin=%s)", storage.getSerialNumber(), objectPath.toString(), String.valueOf(propagated), String.valueOf(includeClassOrigin)));
instance = getInstance(storage, objectPath, propagated, includeClassOrigin, propertyList);
}
} catch (WBEMException e) {
// it's okay, we want to return null for this method
if (e.getID() != WBEMException.CIM_ERR_NOT_FOUND) {
throw e;
}
} catch (Exception e) {
_log.error("checkExists call encountered an exception", e);
throw e;
}
return instance;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method getInstance.
/*
* Return CIM instance of the given object path.
*/
public CIMInstance getInstance(StorageSystem storage, CIMObjectPath objectPath, boolean propagated, boolean includeClassOrigin, String[] propertyList) throws Exception {
CimConnection connection = _cimConnection.getConnection(storage);
WBEMClient client = connection.getCimClient();
// CTRL-9069 workaround CIM_BAD_REQUEST error
CIMInstance instance = null;
int retryCount = 0;
while (true) {
try {
_log.info("Calling getInstance, attempt {}", retryCount);
instance = client.getInstance(objectPath, propagated, includeClassOrigin, propertyList);
} catch (WBEMException e) {
if (CIM_BAD_REQUEST.equals(e.getMessage())) {
if (retryCount < CIM_MAX_RETRY_COUNT) {
_log.warn("Encountered 'request-not-well-formed' error. Retry...");
retryCount++;
try {
Thread.sleep(CIM_RETRY_WAIT_INTERVAL);
} catch (InterruptedException ie) {
_log.warn("Thread: " + Thread.currentThread().getName() + " interrupted.");
throw e;
}
continue;
}
_log.warn("Exhausted {} retries", CIM_MAX_RETRY_COUNT);
}
// other WBEMException, or reach the max retry count
throw e;
}
// no exception
break;
}
return instance;
}
use of javax.wbem.WBEMException 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;
}
Aggregations