use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getFCEndpointsByFabric.
/**
* Get FCEndpoints instances by getting TopologyView instances by fabric. This method
* of getting TopologyView instances can be slow in some environments thus the need
* for the alternate function {@link #getFCEndpointsByFabric(WBEMClient, Map, Map, Map, Map)} which is faster but requires more
* memory. The user can select the function best suitable
* using config item controller_ns_brocade_discovery_by_fabric_association
*
* @param client
* WBEMClient
* @param routedConnections
* IN/OUT - A map where routed endpoints will be stored
* @param fabricsByIds
* a map of fabric name to fabric WWN
* @param deviceNameCache
* a map to cache switch names
* @param logicalToPhysicalSwitchMap
* a map to cache logical switches and their container physical switch
* @return a map of endpoint Wwn to its FCEndpoint instance
* @throws WBEMException
*/
private Map<String, FCEndpoint> getFCEndpointsByFabric(WBEMClient client, Map<String, Set<String>> routedConnections, Map<String, String> fabricsByIds, Map<String, String> deviceNameCache, Map<String, String> logicalToPhysicalSwitchMap) throws WBEMException {
long start = System.currentTimeMillis();
_log.info("Getting topology by fabric");
Map<String, FCEndpoint> portConnections = new HashMap<String, FCEndpoint>();
CIMObjectPath path = CimObjectPathCreator.createInstance(_fabric_path, _namespace);
CloseableIterator<CIMInstance> it = null;
try {
it = client.enumerateInstances(path, false, true, true, null);
while (it.hasNext()) {
CIMInstance ins = it.next();
String fabricWwn = formatWWN(cimStringProperty(ins, _name));
String fabricName = cimStringProperty(ins, _element_name);
_log.info("Fabric: " + fabricName + " (" + fabricWwn + ")");
CloseableIterator<CIMInstance> topit = client.associatorInstances(ins.getObjectPath(), _Brocade_TopologyViewInFabric, _Brocade_TopologyView, null, null, false, null);
try {
CIMInstance topins = null;
while (topit.hasNext()) {
topins = topit.next();
_log.debug(topins.toString());
processTopologyViewInstance(client, topins, portConnections, routedConnections, fabricsByIds.get(fabricWwn), fabricWwn, deviceNameCache, logicalToPhysicalSwitchMap);
}
} finally {
if (topit != null) {
topit.close();
}
}
}
} finally {
if (it != null) {
it.close();
}
}
_log.info("Getting topology by fabric took " + (System.currentTimeMillis() - start));
return portConnections;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getEndpointZones.
/**
* Given an initiator WWN, find all the zones this initiator is in.
*
* @param client an instance of WBEMClient with an open session to SMI provider
* @param fabricWwn the WWN of the fabric
* @param endpointWwn the WWN of the initiator
* @param cachedZones A cache of zones already retrieved from the network system.
* @return a list of zones in the initiator is in any zones, otherwise, an empty list
* @throws WBEMException
*/
public List<Zone> getEndpointZones(WBEMClient client, String fabricWwn, String endpointWwn, Map<CIMObjectPath, Zone> cachedZones) throws WBEMException {
List<Zone> zones = new ArrayList<Zone>();
CIMInstance memberIns = getZoneMemberInstance(client, endpointWwn, _ZMType_Wwn, fabricWwn, true);
// if we find an instance, this means the initiator is in some zones
if (memberIns != null) {
// get the zones
CloseableIterator<CIMInstance> zoneItr = null;
Zone zone = null;
try {
zoneItr = client.associatorInstances(memberIns.getObjectPath(), _Brocade_ZoneMembershipSettingDataInZone, _Brocade_Zone, null, null, false, null);
while (zoneItr.hasNext()) {
CIMInstance zoneIns = zoneItr.next();
zone = cachedZones.get(zoneIns.getObjectPath());
if (zone == null) {
zone = getZoneFromZoneInstance(client, zoneIns, true, false);
cachedZones.put(zoneIns.getObjectPath(), zone);
}
zones.add(zone);
_log.info("Found zone " + zone.getName());
}
} catch (WBEMException ex) {
_log.error("Encountered an exception while trying to get zones for initiator." + ex.getMessage(), ex);
throw ex;
} finally {
if (zoneItr != null) {
zoneItr.close();
}
}
}
return zones;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getZoneSets.
@SuppressWarnings("unchecked")
public List<Zoneset> getZoneSets(WBEMClient client, String fabricId, String fabricWwn, String zoneName, boolean excludeMembers, boolean excludeAliases) throws WBEMException {
List<Zoneset> zonesets = new ArrayList<Zoneset>();
fabricWwn = StringUtils.isEmpty(fabricWwn) ? getFabricWwn(client, fabricId) : fabricWwn;
CIMInstance fabricIns = getFabricInstance(client, fabricId, fabricWwn);
if (fabricIns != null) {
CloseableIterator<CIMInstance> zonesetItr = null;
try {
CIMInstance activeZonesetIns = getActiveZonesetInstance(client, fabricId, fabricWwn);
if (activeZonesetIns != null) {
Zoneset activeZoneset = new Zoneset(cimStringProperty(activeZonesetIns, _element_name));
activeZoneset.setActive(cimBooleanProperty(activeZonesetIns, _active));
// if zoneName not specified, get all zones in the zoneset.
if (StringUtils.isEmpty(zoneName) || (zoneName != null && zoneName.startsWith(NetworkDeviceController.ZONESET_QUERY_FILTER))) {
activeZoneset.setZones(getZonesetZones(client, activeZonesetIns.getObjectPath(), !excludeMembers, !excludeAliases, zoneName));
} else {
// looking for a zone with given zoneName
Zone zone = getZone(client, zoneName, fabricWwn, true, !excludeMembers, !excludeAliases);
if (zone != null) {
activeZoneset.getZones().add(zone);
}
}
// get pending active zoneset and consolidate with active zoneset
zonesetItr = client.associatorInstances(fabricIns.getObjectPath(), _zoneset_fabric_path, _zoneset_name, null, null, false, null);
while (zonesetItr.hasNext()) {
CIMInstance zonesetIns = zonesetItr.next();
Zoneset zoneset = new Zoneset(cimStringProperty(zonesetIns, _element_name));
zoneset.setActive(cimBooleanProperty(zonesetIns, _active));
if (!zoneset.getActive() && StringUtils.equals(zoneset.getName(), activeZoneset.getName())) {
// found a pending active zoneset, consolidate its zones into active zoneset
if (StringUtils.isEmpty(zoneName)) {
zoneset.setZones(getZonesetZones(client, zonesetIns.getObjectPath(), !excludeMembers, !excludeAliases, null));
// consolidate active and pending zones in the zoneset
List<String> activeZoneNames = new ArrayList<String>();
for (Zone zone : activeZoneset.getZones()) {
activeZoneNames.add(zone.getName());
}
// get zones that are not yet active in zoneset, then
// append to zoneset
List<Zone> inactiveZones = new ArrayList<Zone>();
for (Zone zone : zoneset.getZones()) {
if (!activeZoneNames.contains(zone.getName())) {
inactiveZones.add(zone);
}
}
activeZoneset.getZones().addAll(inactiveZones);
} else if (activeZoneset.getZones().isEmpty()) {
// if specified zone was not found in active zone set, look into pending zoneset
Zone zone = getZone(client, zoneName, fabricWwn, true, !excludeMembers, !excludeAliases);
if (zone != null) {
zoneset.getZones().add(zone);
}
}
break;
}
}
if (activeZoneset != null) {
zonesets.add(activeZoneset);
}
}
} finally {
if (zonesetItr != null) {
zonesetItr.close();
}
}
}
return zonesets;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getLogicalToPhysicalSwitcheMap.
/**
* get Logical switches to physical switch map
* @param client an instance of WBEMClient
* @return a map of logical to physical switch name
* @throws WBEMException
*/
public HashMap<String, String> getLogicalToPhysicalSwitcheMap(WBEMClient client) throws WBEMException {
HashMap<String, String> switchMap = new HashMap<>();
CIMObjectPath path = new CIMObjectPath(null, null, null, _namespace, _Brocade_SwitchPCS, null);
CloseableIterator<CIMInstance> it = null;
try {
it = client.enumerateInstances(path, false, true, true, null);
while (it.hasNext()) {
CIMInstance ins = it.next();
String parentName = cimStringProperty(ins, _Parent);
String childName = cimStringProperty(ins, _Child);
_log.debug("Brocade Switch: Parent : {} - Child : {} )", parentName, childName);
CIMProperty[] props = ins.getProperties();
for (int i = 0; i < props.length; i++) {
_log.debug("Switch property : " + props[i].getName() + ": value : " + props[i].getValue());
}
CIMInstance parentObject = client.getInstance(new CIMObjectPath(parentName), true, true, null);
CIMInstance childObject = client.getInstance(new CIMObjectPath(childName), true, true, null);
parentName = cimStringProperty(parentObject, _element_name);
childName = cimStringProperty(childObject, _element_name);
switchMap.put(childName, parentName);
_log.info("Brocade Switch: Logical Switch : " + childName + " In (" + parentName + ")");
}
} finally {
if (it != null) {
it.close();
}
}
return switchMap;
}
use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method activateZones.
@Override
public BiosCommandResult activateZones(NetworkSystem networkSystem, String fabricId, String fabricWwn) throws NetworkDeviceControllerException {
BiosCommandResult result = null;
NetworkDeviceControllerException exception = null;
try {
WBEMClient client = getNetworkDeviceClient(networkSystem);
CIMInstance zonesetIns = _smisHelper.getActiveZonesetInstance(client, fabricId, fabricWwn);
if (zonesetIns != null) {
CIMObjectPath shadowZonesetPath = _smisHelper.getShadowZonesetPath(client, fabricId, fabricWwn, zonesetIns);
CIMInstance zoneServiceIns = _smisHelper.getZoneServiceInstance(client, fabricId, fabricWwn);
boolean activate = !_smisHelper.isEmptyZoneset(client, shadowZonesetPath);
if (_smisHelper.activateZoneSet(client, zoneServiceIns, zonesetIns.getObjectPath(), activate)) {
_log.info("The active zoneset for fabric " + fabricId + " was " + (activate ? "re-activated" : "deactivated"));
} else {
_log.error("Failed to re-activate zoneset");
exception = NetworkDeviceControllerException.exceptions.zonesetActivationFailed(fabricId, new Throwable());
}
} else {
exception = NetworkDeviceControllerException.exceptions.noActiveZonesetForFabric(fabricId);
}
result = BiosCommandResult.createSuccessfulResult();
} catch (Exception ex) {
_log.error("Cannot re-activate zoneset: " + ex.getLocalizedMessage());
exception = NetworkDeviceControllerException.exceptions.zonesetActivationFailed(fabricId, ex);
}
if (exception != null) {
throw exception;
}
return result;
}
Aggregations