use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class XIVExportOperations method refreshSMISExportMask.
private ExportMask refreshSMISExportMask(StorageSystem storage, ExportMask mask) {
try {
CIMInstance instance = _helper.getSCSIProtocolController(storage, mask);
if (instance != null) {
StringBuilder builder = new StringBuilder();
String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_NAME);
// Get volumes and initiators for the masking instance
CIMObjectPath controllerPath = instance.getObjectPath();
Map<String, Integer> discoveredVolumes = _helper.getVolumesFromScsiProtocolController(storage, controllerPath);
Map<String, CIMObjectPath> discoveredPortPaths = _helper.getInitiatorsFromScsiProtocolController(storage, instance.getObjectPath());
Set<String> discoveredPorts = discoveredPortPaths.keySet();
Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
builder.append(String.format("%nXM object: %s I{%s} V:{%s}%n", name, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
builder.append(String.format("XM discovered: %s I:{%s} V:{%s}%n", name, Joiner.on(',').join(discoveredPorts), Joiner.on(',').join(discoveredVolumes.keySet())));
// Check the initiators and update the lists as necessary
boolean addInitiators = false;
List<String> initiatorsToAdd = new ArrayList<String>();
for (String port : discoveredPorts) {
String normalizedPort = Initiator.normalizePort(port);
if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
initiatorsToAdd.add(normalizedPort);
addInitiators = true;
}
}
boolean removeInitiators = false;
List<String> initiatorsToRemove = new ArrayList<String>();
if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
initiatorsToRemove.addAll(mask.getExistingInitiators());
initiatorsToRemove.removeAll(discoveredPorts);
removeInitiators = !initiatorsToRemove.isEmpty();
}
// Check the volumes and update the lists as necessary
Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
boolean addVolumes = !volumesToAdd.isEmpty();
boolean removeVolumes = false;
List<String> volumesToRemove = new ArrayList<String>();
if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
volumesToRemove.addAll(mask.getExistingVolumes().keySet());
volumesToRemove.removeAll(discoveredVolumes.keySet());
removeVolumes = !volumesToRemove.isEmpty();
}
boolean changeName = false;
if (!mask.getMaskName().equals(name)) {
changeName = true;
mask.setLabel(name);
mask.setMaskName(name);
// update host label
StringSet initiators = mask.getInitiators();
if (initiators != null) {
Iterator<String> itr = initiators.iterator();
if (itr.hasNext()) {
Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(itr.next()));
Host host = _dbClient.queryObject(Host.class, initiator.getHost());
String label = host.getLabel();
if (label.equals(name)) {
_helper.unsetTag(host, storage.getSerialNumber());
} else {
_helper.setTag(host, storage.getSerialNumber(), name);
}
}
}
}
builder.append(String.format("XM refresh: %s initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAdd), Joiner.on(',').join(initiatorsToRemove)));
builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
// Any changes indicated, then update the mask and persist it
if (addInitiators || removeInitiators || addVolumes || removeVolumes || changeName) {
builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
mask.removeFromExistingInitiators(initiatorsToRemove);
mask.addToExistingInitiatorsIfAbsent(initiatorsToAdd);
mask.removeFromExistingVolumes(volumesToRemove);
mask.addToExistingVolumesIfAbsent(volumesToAdd);
ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
_dbClient.updateAndReindexObject(mask);
} else {
builder.append("XM refresh: There are no changes to the mask\n");
}
_networkDeviceController.refreshZoningMap(mask, initiatorsToRemove, Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
_log.info(builder.toString());
}
} catch (Exception e) {
boolean throwException = true;
if (e instanceof WBEMException) {
WBEMException we = (WBEMException) e;
// Only throw exception if code is not CIM_ERROR_NOT_FOUND
throwException = (we.getID() != WBEMException.CIM_ERR_NOT_FOUND);
}
if (throwException) {
String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
_log.error(MessageFormat.format("Encountered an SMIS error when attempting to refresh existing exports: {0}", msg), e);
throw SmisException.exceptions.refreshExistingMaskFailure(msg, e);
}
}
return mask;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method getInitiatorsFromScsiProtocolController.
/**
* Returns a map of normalized port name to port path for the masking.
*
* @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 port name to port path for the container.
*/
public Map<String, CIMObjectPath> getInitiatorsFromScsiProtocolController(StorageSystem storage, CIMObjectPath controllerPath) {
Map<String, CIMObjectPath> initiatorPortPaths = new HashMap<String, CIMObjectPath>();
CloseableIterator<CIMInstance> iterator = null;
try {
WBEMClient client = getConnection(storage).getCimClient();
iterator = client.associatorInstances(controllerPath, CP_SHWID_TO_SPC, CP_STORAGE_HARDWARE_ID, null, null, false, PS_STORAGE_ID);
while (iterator.hasNext()) {
CIMInstance cimInstance = iterator.next();
String initiator = CIMPropertyFactory.getPropertyValue(cimInstance, CP_STORAGE_ID);
initiatorPortPaths.put(Initiator.normalizePort(initiator), cimInstance.getObjectPath());
}
} catch (WBEMException we) {
_log.error("Caught an error while attempting to get initiator list from " + "masking instance", we);
} finally {
if (iterator != null) {
iterator.close();
}
}
return initiatorPortPaths;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method checkExists.
/**
* This method is a 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]
* @return CIMInstance object that represents the existing object
* @throws Exception
*/
public CIMInstance checkExists(StorageSystem storage, Volume volume, boolean propagated, boolean includeClassOrigin) throws Exception {
CIMInstance instance = null;
CIMObjectPath objectPath = _cimPath.getBlockObjectPath(storage, volume);
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, null);
}
} 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 getStoragePortsFromScsiProtocolController.
/**
* Given a CIMInstance of a IBMTSDS_SCSIProtocolController return a list of storage ports that
* it references.
*
* @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 List of port name String values. The WWNs will have colons separating the hex digits.
*/
public List<String> getStoragePortsFromScsiProtocolController(StorageSystem storage, CIMObjectPath controllerPath) {
List<String> storagePorts = new ArrayList<String>();
CloseableIterator<CIMObjectPath> iterator = null;
try {
WBEMClient client = getConnection(storage).getCimClient();
iterator = client.associatorNames(controllerPath, null, CIM_PROTOCOL_ENDPOINT, null, null);
while (iterator.hasNext()) {
CIMObjectPath endpointPath = iterator.next();
String portName = endpointPath.getKeyValue(CP_NAME).toString();
String fixedName = Initiator.toPortNetworkId(portName);
storagePorts.add(fixedName);
}
} catch (WBEMException we) {
_log.error("Caught an error while attempting to get storage ports from " + "masking instance", we);
} finally {
if (iterator != null) {
iterator.close();
}
}
return storagePorts;
}
use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method invokeMethod.
/**
* Invoke CIM method.
*/
@SuppressWarnings("rawtypes")
public void invokeMethod(StorageSystem storageDevice, CIMObjectPath objectPath, String methodName, CIMArgument[] inArgs, CIMArgument[] outArgs) throws Exception {
CimConnection connection = getConnection(storageDevice);
WBEMClient client = connection.getCimClient();
int index = 0;
StringBuilder inputInfoBuffer = new StringBuilder();
inputInfoBuffer.append("\nSMI-S Provider: ").append(connection.getHost()).append(" -- Attempting invokeMethod ").append(methodName).append(" on\n").append(" objectPath=").append(objectPath.toString()).append(" with arguments: \n");
for (CIMArgument arg : inArgs) {
inputInfoBuffer.append(" inArg[").append(index++).append("]=").append(arg.toString()).append('\n');
}
_log.info(inputInfoBuffer.toString());
long start = System.nanoTime();
// workaround for CTRL-8024 (CIMError: "request-not-well-formed" ...)
// retry CIM_MAX_RETRY_COUNT times if encounter the error
// the invoke method will return quickly with the error, so extensive retry (e.g., 25 times), won't be a big overhead
Object obj = null;
int retryCount = 0;
while (true) {
try {
_log.info("Invoke method {}, attempt {}", methodName, retryCount);
obj = client.invokeMethod(objectPath, methodName, inArgs, outArgs);
} 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;
}
String total = String.format("%2.6f", ((System.nanoTime() - start) / 1000000000.0));
StringBuilder outputInfoBuffer = new StringBuilder();
outputInfoBuffer.append("\nSMI-S Provider: ").append(connection.getHost()).append(" -- Completed invokeMethod ").append(methodName).append(" on\n").append(" objectPath=").append(objectPath.toString()).append("\n Returned: ").append(obj.toString()).append(" with output arguments: \n");
int returnCode = NumberUtils.toInt(obj.toString(), INVALID_RETURN_CODE);
for (CIMArgument arg : outArgs) {
if (arg != null) {
if (returnCode == CIM_SUCCESS_CODE) {
outputInfoBuffer.append(" outArg=").append(arg.toString()).append('\n');
} else {
outputInfoBuffer.append(" outArg=").append(arg.getName()).append("=").append(arg.getValue()).append(" (Type ").append(arg.getDataType()).append(")\n");
}
}
}
outputInfoBuffer.append(" Execution time: ").append(total).append(" seconds.\n");
_log.info(outputInfoBuffer.toString());
if (returnCode == CIM_MAPPING_NOT_DEFINED && methodName.equals(HIDE_PATHS)) {
// ignore the error
} else if (returnCode == this.CIM_DUPLICATED_HOST_NAME && methodName.equals(CREATE_HARDWARE_ID_COLLECTION)) {
outArgs[0] = null;
} else if (returnCode == this.CIM_OPERATION_PARTIALLY_SUCCEEDED && methodName.equals(ADD_HARDWARE_IDS_TO_COLLECTION)) {
outArgs[0] = null;
} else if (returnCode == CIM_DUPLICATED_CG_NAME_CODE) {
throw new Exception(DUPLICATED_CG_NAME_ERROR);
} else if (returnCode == CIM_ONLY_ALLOWED_ON_EMPTY_CG_CODE && methodName.equals(REMOVE_MEMBERS)) {
// after this call
throw new Exception("Failed with return code: " + obj);
} else if (returnCode != CIM_SUCCESS_CODE && methodName.equals(CREATE_OR_MODIFY_ELEMENTS_FROM_STORAGE_POOL) && checkIfVolumeSizeExceedingPoolSize(inArgs, outArgs)) {
throw DeviceControllerException.exceptions.volumeSizeExceedingPoolSize(getVolumeName(inArgs));
} else if (returnCode != CIM_SUCCESS_CODE) {
throw new Exception("Failed with return code: " + obj);
}
}
Aggregations