use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class CIMConnectionFactory method checkConnectionliveness.
/**
* To-Do: check for Connection liveness 1. if null, add a new Connection. 2.
* if connection present, then check for liveness.
*
* @return boolean
*/
public boolean checkConnectionliveness(CimConnection connection) {
boolean isLive = false;
if (null == connection) {
return isLive;
}
WBEMClient wbemClient = connection.getCimClient();
_log.debug("copPath:{}", _cop);
try {
// Call the provider to get computer systems.
wbemClient.enumerateInstanceNames(_cop);
isLive = true;
} catch (WBEMException wbemEx) {
_log.error("Invalid connection found for ipAddress: {}", connection.getHost());
}
return isLive;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class ExportProcessor method processResult.
/*
* (non-Javadoc)
*
* @see com.emc.storageos.plugins.common.Processor#processResult(com.emc.storageos.plugins.common.domainmodel.Operation,
* java.lang.Object, java.util.Map)
*/
@SuppressWarnings("unchecked")
@Override
public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap) throws BaseCollectionException {
initialize(operation, resultObj, keyMap);
CloseableIterator<CIMInstance> it = null;
EnumerateResponse<CIMInstance> response = null;
List<Initiator> matchedInitiators = new ArrayList<Initiator>();
List<StoragePort> matchedPorts = new ArrayList<StoragePort>();
WBEMClient client = SMICommunicationInterface.getCIMClient(keyMap);
StringSet knownIniSet = new StringSet();
StringSet knownNetworkIdSet = new StringSet();
StringSet knownPortSet = new StringSet();
StringSet knownVolumeSet = new StringSet();
try {
// set lun masking view CIM path
CIMObjectPath path = this.getObjectPathfromCIMArgument(_args, keyMap);
UnManagedExportMask mask = this.getUnManagedExportMask(path);
mask.setMaskingViewPath(path.toString());
_logger.info("looking at lun masking view: " + path.toString());
CIMInstance lunMaskingView = client.getInstance(path, false, false, null);
if (lunMaskingView != null) {
String maskName = CIMPropertyFactory.getPropertyValue(lunMaskingView, SmisConstants.CP_NAME);
if (maskName != null) {
mask.setMaskName(maskName);
}
_logger.info("set UnManagedExportMask maskName to " + mask.getMaskName());
} else {
_logger.info("lunMaskingView was null");
}
CIMProperty<String> deviceIdProperty = (CIMProperty<String>) path.getKey(SmisConstants.CP_DEVICE_ID);
if (deviceIdProperty != null) {
mask.setNativeId(deviceIdProperty.getValue());
}
_logger.info("set UnManagedExportMask nativeId to " + mask.getNativeId());
// set storage system id
URI systemId = (URI) keyMap.get(Constants.SYSTEMID);
mask.setStorageSystemUri(systemId);
response = (EnumerateResponse<CIMInstance>) resultObj;
processVolumesAndInitiatorsPaths(response.getResponses(), mask, matchedInitiators, matchedPorts, knownIniSet, knownNetworkIdSet, knownPortSet, knownVolumeSet);
while (!response.isEnd()) {
_logger.info("Processing next Chunk");
response = client.getInstancesWithPath(Constants.MASKING_PATH, response.getContext(), new UnsignedInteger32(BATCH_SIZE));
processVolumesAndInitiatorsPaths(response.getResponses(), mask, matchedInitiators, matchedPorts, knownIniSet, knownNetworkIdSet, knownPortSet, knownVolumeSet);
}
// CTRL - 8918 - always update the mask with new initiators and volumes.
mask.replaceNewWithOldResources(knownIniSet, knownNetworkIdSet, knownVolumeSet, knownPortSet);
// get zones and store them?
updateZoningMap(mask, matchedInitiators, matchedPorts);
updateVplexBackendVolumes(mask, matchedInitiators);
updateRecoverPointVolumes(mask, matchedInitiators);
} catch (Exception e) {
_logger.error("something failed", e);
} finally {
if (it != null) {
it.close();
}
wrapUp();
if (response != null) {
try {
client.closeEnumeration(Constants.MASKING_PATH, response.getContext());
} catch (Exception e) {
_logger.debug("Exception occurred while closing enumeration", e);
}
}
}
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class VnxExportOperations method getExportMaskHLUs.
@Override
public Map<URI, Integer> getExportMaskHLUs(StorageSystem storage, ExportMask exportMask) {
Map<URI, Integer> hlus = Collections.emptyMap();
try {
CIMInstance instance = _helper.getLunMaskingProtocolController(storage, exportMask);
// There's a StorageGroup on the array for the ExportMask and it has userAddedVolumes.
if (instance != null && exportMask.getUserAddedVolumes() != null) {
hlus = new HashMap<>();
WBEMClient client = _helper.getConnection(storage).getCimClient();
// Get the volume WWN to HLU mapping from the StorageGroup
Map<String, Integer> discoveredVolumes = _helper.getVolumesFromLunMaskingInstance(client, instance);
for (String wwn : discoveredVolumes.keySet()) {
Integer hlu = discoveredVolumes.get(wwn);
if (hlu != null && exportMask.getUserAddedVolumes().containsKey(wwn)) {
// Look up the volume URI given the WWN
String uriString = exportMask.getUserAddedVolumes().get(wwn);
// We have a proper HLU
hlus.put(URI.create(uriString), hlu);
}
}
}
_log.info(String.format("Retrieved these volumes from ExportMask %s (%s): %s", exportMask.getMaskName(), exportMask.getId(), CommonTransformerFunctions.collectionString(hlus.entrySet())));
} catch (Exception e) {
// Log an error, but return an empty list
_log.error(String.format("Encountered an exception when attempting to get volume to HLU mapping from ExportMask %s", exportMask.getMaskName()), e);
// We encountered an exception, so let's not return partial data ...
if (!hlus.isEmpty()) {
hlus.clear();
}
}
return hlus;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class VnxExportOperations method findHLUsForInitiators.
@Override
public Set<Integer> findHLUsForInitiators(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) {
long startTime = System.currentTimeMillis();
Set<Integer> usedHLUs = new HashSet<Integer>();
CloseableIterator<CIMInstance> lunMaskingIter = null;
try {
// Get a mapping of the initiator port names to their CIMObjectPaths on the provider
WBEMClient client = _helper.getConnection(storage).getCimClient();
HashMap<String, CIMObjectPath> initiatorPathsMap = _cimPath.getInitiatorToInitiatorPath(storage, initiatorNames);
List<String> maskNames = new ArrayList<String>();
// Iterate through each initiator port name ...
for (String initiatorName : initiatorPathsMap.keySet()) {
CIMObjectPath initiatorPath = initiatorPathsMap.get(initiatorName);
// Find out if there is a Lun Masking Instance associated with the initiator...
lunMaskingIter = _helper.getAssociatorInstances(storage, initiatorPath, null, SmisConstants.CLAR_LUN_MASKING_SCSI_PROTOCOL_CONTROLLER, null, null, SmisConstants.PS_LUN_MASKING_CNTRL_NAME_AND_ROLE);
while (lunMaskingIter.hasNext()) {
// Found a Lun Masking Instance...
CIMInstance instance = lunMaskingIter.next();
String systemName = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_SYSTEM_NAME);
if (!systemName.contains(storage.getSerialNumber())) {
// SMISProvider pointed to by 'storage' system.
continue;
}
String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
if (!maskNames.contains(name)) {
_log.info("Found matching mask {}", name);
maskNames.add(name);
// Find all the initiators associated with the Masking instance
List<String> initiatorPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
// Get volumes for the Masking instance
Map<String, Integer> volumeWWNs = _helper.getVolumesFromLunMaskingInstance(client, instance);
// add HLUs to set
usedHLUs.addAll(volumeWWNs.values());
_log.info(String.format("%nXM:%s I:{%s} V:{%s} HLU:{%s}%n", name, Joiner.on(',').join(initiatorPorts), Joiner.on(',').join(volumeWWNs.keySet()), volumeWWNs.values()));
}
}
}
_log.info(String.format("HLUs found for Initiators { %s }: %s", Joiner.on(',').join(initiatorNames), usedHLUs));
} catch (Exception e) {
String errMsg = "Encountered an SMIS error when attempting to query used HLUs for initiators: " + e.getMessage();
_log.error(errMsg, e);
throw SmisException.exceptions.hluRetrievalFailed(errMsg, e);
} finally {
if (lunMaskingIter != null) {
lunMaskingIter.close();
}
long totalTime = System.currentTimeMillis() - startTime;
_log.info(String.format("find used HLUs for Initiators took %f seconds", (double) totalTime / (double) 1000));
}
return usedHLUs;
}
use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.
the class VnxExportOperations method refreshExportMask.
@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
try {
CIMInstance instance = _helper.getLunMaskingProtocolController(storage, mask);
if (instance != null) {
StringBuilder builder = new StringBuilder();
WBEMClient client = _helper.getConnection(storage).getCimClient();
String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
// Get volumes and initiators for the masking instance
Map<String, Integer> discoveredVolumes = _helper.getVolumesFromLunMaskingInstance(client, instance);
// Update user added volume's HLU information in ExportMask and ExportGroup
ExportMaskUtils.updateHLUsInExportMask(mask, discoveredVolumes, _dbClient);
List<String> discoveredPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
builder.append(String.format("%nXM existing objects: %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())));
List<String> initiatorsToAddToExisting = new ArrayList<String>();
List<Initiator> initiatorsToAddToUserAddedAndInitiatorList = new ArrayList<Initiator>();
/**
* For the newly discovered initiators, if they are ViPR discovered ports and belong to same resource
* add them to user added and initiators list, otherwise add to existing list.
*/
for (String port : discoveredPorts) {
String normalizedPort = Initiator.normalizePort(port);
if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
// Don't add additional initiator to initiators list if it belongs to different host/cluster
if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
_log.info("Initiator {}->{} belonging to same compute, adding to userAdded and initiator list.", normalizedPort, existingInitiator.getId());
initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
} else {
initiatorsToAddToExisting.add(normalizedPort);
}
}
}
/**
* Get the existing initiators from the mask and remove the non-discovered ports because
* they are not discovered and are stale.
*
* If the mask has existing initiators but if they are discovered and belongs to same compute resource, then the
* initiators has to get added to user Added and initiators list, and removed from existing list.
*/
List<String> initiatorsToRemoveFromExistingList = new ArrayList<String>();
if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
for (String existingInitiatorStr : mask.getExistingInitiators()) {
if (!discoveredPorts.contains(existingInitiatorStr)) {
initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
} else {
Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(existingInitiatorStr), _dbClient);
if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
_log.info("Initiator {}->{} belonging to same compute, removing from existing," + " and adding to userAdded and initiator list", existingInitiatorStr, existingInitiator.getId());
initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
}
}
}
}
/**
* Get all the initiators from the mask and remove all the ViPR discovered ports.
* The remaining list has to be removed from user Added and initiator list, because they are not available in ViPR
* but has to be moved to existing list.
*/
List<URI> initiatorsToRemoveFromUserAddedAndInitiatorList = new ArrayList<URI>();
if (mask.getInitiators() != null && !mask.getInitiators().isEmpty()) {
initiatorsToRemoveFromUserAddedAndInitiatorList.addAll(transform(mask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI));
for (String port : discoveredPorts) {
String normalizedPort = Initiator.normalizePort(port);
Initiator initiatorDiscoveredInViPR = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
if (initiatorDiscoveredInViPR != null) {
initiatorsToRemoveFromUserAddedAndInitiatorList.remove(initiatorDiscoveredInViPR.getId());
} else if (!mask.hasExistingInitiator(normalizedPort)) {
_log.info("Initiator {} not found in database, removing from user Added and initiator list," + " and adding to existing list.", port);
initiatorsToAddToExisting.add(normalizedPort);
}
}
}
boolean removeInitiators = !initiatorsToRemoveFromExistingList.isEmpty() || !initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty();
boolean addInitiators = !initiatorsToAddToUserAddedAndInitiatorList.isEmpty() || !initiatorsToAddToExisting.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());
}
// if the volume is in export mask's user added volumes and also in the existing volumes, remove from existing volumes
for (String wwn : discoveredVolumes.keySet()) {
if (mask.hasExistingVolume(wwn)) {
URIQueryResultList volumeList = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn), volumeList);
if (volumeList.iterator().hasNext()) {
URI volumeURI = volumeList.iterator().next();
if (mask.hasUserCreatedVolume(volumeURI)) {
builder.append(String.format("\texisting volumes contain wwn %s, but it is also in the " + "export mask's user added volumes, so removing from existing volumes", wwn));
volumesToRemove.add(wwn);
}
}
}
}
removeVolumes = !volumesToRemove.isEmpty();
// NOTE/TODO: We are not modifying the storage ports upon refresh like we do for VMAX.
// Refer to CTRL-6982.
builder.append(String.format("XM refresh: %s existing initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToExisting), Joiner.on(',').join(initiatorsToRemoveFromExistingList)));
builder.append(String.format("XM refresh: %s user added and initiator list; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToUserAddedAndInitiatorList), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
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) {
builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
mask.removeInitiatorURIs(initiatorsToRemoveFromUserAddedAndInitiatorList);
mask.removeFromUserAddedInitiatorsByURI(initiatorsToRemoveFromUserAddedAndInitiatorList);
mask.addInitiators(initiatorsToAddToUserAddedAndInitiatorList);
mask.addToUserCreatedInitiators(initiatorsToAddToUserAddedAndInitiatorList);
mask.addToExistingInitiatorsIfAbsent(initiatorsToAddToExisting);
mask.removeFromExistingVolumes(volumesToRemove);
mask.addToExistingVolumesIfAbsent(volumesToAdd);
// Update the volume list to include existing volumes if know about them.
if (addVolumes) {
for (String wwn : volumesToAdd.keySet()) {
URIQueryResultList results = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn.toUpperCase()), results);
if (results != null) {
Iterator<URI> resultsIter = results.iterator();
if (resultsIter.hasNext()) {
Volume volume = _dbClient.queryObject(Volume.class, resultsIter.next());
if (null != volume) {
mask.addVolume(volume.getId(), volumesToAdd.get(wwn));
}
}
}
}
}
ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
_dbClient.updateObject(mask);
} else {
builder.append("XM refresh: There are no changes to the mask\n");
}
_networkDeviceController.refreshZoningMap(mask, transform(initiatorsToRemoveFromUserAddedAndInitiatorList, CommonTransformerFunctions.FCTN_URI_TO_STRING), Collections.<String>emptyList(), (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;
}
Aggregations