use of com.emc.storageos.networkcontroller.impl.mds.Zone in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getZoneFromZoneInstance.
/**
* Creates an instance of {@link #_Zone}
*
* @param client an instance of WBEMClient
* @param zoneIns an instance of CIMInstance
* @param includeMembers if true, the members are retrieved and populated in the zone.
* @param includeAliases if true, the aliases are retrieved and populated in the zone.
* @return and instance of {@link #_Zone}.
* @throws WBEMException
*/
private Zone getZoneFromZoneInstance(WBEMClient client, CIMInstance zoneIns, boolean includeMembers, boolean includeAliases) throws WBEMException {
Zone zone = new Zone(cimStringProperty(zoneIns, _element_name));
zone.setActive(cimBooleanProperty(zoneIns, _active));
zone.setCimObjectPath(zoneIns.getObjectPath());
if (includeMembers) {
zone.setMembers(getZoneMembers(client, zoneIns.getObjectPath(), includeAliases));
}
return zone;
}
use of com.emc.storageos.networkcontroller.impl.mds.Zone in project coprhd-controller by CoprHD.
the class BrocadeNetworkSMIS method getZonesetZones.
@SuppressWarnings("unchecked")
public List<Zone> getZonesetZones(WBEMClient client, CIMObjectPath zonesetPath, boolean includeMembers, boolean includeAliases, String filter) throws WBEMException {
List<Zone> zones = new ArrayList<Zone>();
if (zonesetPath != null) {
CloseableIterator<CIMInstance> zoneItr = null;
try {
zoneItr = client.associatorInstances(zonesetPath, _Brocade_ZoneInZoneSet, _Brocade_Zone, null, null, false, null);
String filterCriteria = null;
if (!StringUtils.isEmpty(filter)) {
filterCriteria = filter.substring(NetworkDeviceController.ZONESET_QUERY_FILTER.length());
}
while (zoneItr.hasNext()) {
CIMInstance zoneIns = zoneItr.next();
boolean getZone = true;
if (!StringUtils.isEmpty(filter)) {
String zoneName = cimStringProperty(zoneIns, _element_name);
if (!zoneName.contains(filterCriteria)) {
getZone = false;
}
}
if (getZone) {
Zone zone = getZoneFromZoneInstance(client, zoneIns, includeMembers, includeAliases);
zones.add(zone);
}
}
} finally {
if (zoneItr != null) {
zoneItr.close();
}
}
}
return zones;
}
use of com.emc.storageos.networkcontroller.impl.mds.Zone in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method removeZonesStrategy.
/**
* This function removed one or more zones from the active zoneset. This function will not
* error if a zone to be removed was not found.
* <p>
* Removing zones typical flow is:
* <ol>
* <li>find the zones that can be deleted</li>
* <li>get the session lock</li>
* <li>delete the zones</li>
* <li>commit which releases the lock</li>
* <li>activate if requested</li>
* </ol>
* This flow is different when we're removing the last zones in a zoneset. If the zoneset becomes empty, it needs to be removed too or
* commit would fail. In order to remove the zoneset, it has to first be deactivated. The flow for removing the last zones in a zoneset
* is
* <ol>
* <li>find the zones that can be deleted</li>
* <li>deactivate the zoneset</li>
* <li>get the session lock</li>
* <li>delete the zones</li>
* <li>delete the zoneset</li>
* <li>commit which releases the lock</li>
* </ol>
*
* @param client an instance of the SMI client
* @param zones the list if zones to be deleted.
* @param fabricId the id of the fabric where the zones will be removed
* @param activateZones a boolean that indicates if immediate activation is requested.
* @return a map that contains the outcome for each zone keyed by zone name
* @throws NetworkDeviceControllerException
*/
public Map<String, String> removeZonesStrategy(WBEMClient client, List<Zone> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
long start = System.currentTimeMillis();
// a zone-name-to-result map to hold the results for each zone
Map<String, String> removedZoneResults = new HashMap<String, String>();
CIMInstance zoneServiceIns = null;
boolean wasDeactivated = false;
CIMObjectPath shadowZonsetPath = null;
boolean empty = false;
try {
_log.info("Remove zones started.");
zoneServiceIns = _smisHelper.getZoneServiceInstance(client, fabricId, fabricWwn);
if (zoneServiceIns == null) {
_log.info("Failed to get zoning service.");
throw NetworkDeviceControllerException.exceptions.removeZonesStrategyFailedSvc();
}
// get active zoneset.
CIMInstance activeZonesetIns = _smisHelper.getActiveZonesetInstance(client, fabricId, fabricWwn);
if (activeZonesetIns == null) {
String defaultZonesetName = getDefaultZonesetName(fabricId);
// if no active zone set, get pending default active zone set
activeZonesetIns = _smisHelper.getZoneset(client, fabricId, fabricWwn, defaultZonesetName);
if (activeZonesetIns == null) {
_log.warn("No active/default zoneset found: " + defaultZonesetName);
throw NetworkDeviceControllerException.exceptions.noActiveZonesetForFabric(fabricId);
}
}
// The actual work should be done on an inactive
shadowZonsetPath = _smisHelper.getShadowZonesetPath(client, fabricId, fabricWwn, activeZonesetIns);
Map<String, Zone> zonesInFabric = _smisHelper.getZones(client, getZoneNames(zones), fabricWwn, false, true, true);
// Find the set of zones to be actually deleted.
// We don't attempt to delete zones that are already gone.
// And we don't delete zones that Bourne didn't create.
List<Zone> zonesToBeDeleted = getZonesToBeDeleted(zones, zonesInFabric.values(), new Integer[1], removedZoneResults);
// check if we need to deactivate
if (!zonesToBeDeleted.isEmpty()) {
empty = !_smisHelper.zonesetHasMore(client, shadowZonsetPath, zonesToBeDeleted.size());
if (empty) {
_log.info("All zones will be removed so deactivate the zoneset");
_log.info("Attempting to deactivate the zoneset.");
wasDeactivated = _smisHelper.activateZoneSet(client, zoneServiceIns, activeZonesetIns.getObjectPath(), false);
}
// now start removing zones
_log.info("Attempting to start a zoning session");
zoneServiceIns = _smisHelper.startSession(client, fabricId, fabricWwn);
for (Zone curZone : zonesToBeDeleted) {
try {
_log.info("Removing zone: " + curZone.getName() + " fabric: " + fabricId);
_smisHelper.removeZone(client, curZone);
removedZoneResults.put(curZone.getName(), SUCCESS);
} catch (Exception ex) {
removedZoneResults.put(curZone.getName(), ERROR + " : " + ex.getMessage());
handleZonesStrategyException(ex, activateZones);
}
}
// get the current state of the zoneset to make sure it is indeed empty
empty = _smisHelper.isEmptyZoneset(client, shadowZonsetPath);
if (empty) {
client.deleteInstance(shadowZonsetPath);
}
}
// first close the session, commit if we have successful deletes, otherwise rollback
_log.info("Attempting to close zoning session.");
if (_smisHelper.endSession(client, zoneServiceIns, hasResult(removedZoneResults, SUCCESS))) {
// last activate/deactivate as needed
// we want to activate if the zoneset is not empty and we either has deactivated it or
// we actually deleted some zones and the caller requested re-activation.
boolean shouldActivate = ((activateZones && hasResult(removedZoneResults, SUCCESS)) || wasDeactivated) && !empty;
if (shouldActivate) {
_log.info("Attempting to activate the zoneset.");
_smisHelper.activateZoneSet(client, zoneServiceIns, shadowZonsetPath, true);
}
} else {
if (hasResult(removedZoneResults, SUCCESS)) {
// only throw an exception if we were trying to commit changes
throw NetworkDeviceControllerException.exceptions.removeZonesStrategyFailedCommit();
} else {
_log.info("Failed to terminate zoning session. Ignoring as the session may have expired.");
}
}
_log.info("Remove zone completed successfully and took " + (System.currentTimeMillis() - start));
return removedZoneResults;
} catch (Exception e1) {
try {
if (zoneServiceIns != null) {
_log.info("Attempting to terminate zoning session.");
_smisHelper.endSession(client, zoneServiceIns, false);
if (shadowZonsetPath != null && wasDeactivated) {
_log.info("Attempting to re-activate the zoneset because it was deactivated earlier.");
_smisHelper.activateZoneSet(client, zoneServiceIns, shadowZonsetPath, true);
}
}
} catch (Exception ex) {
_log.error("Failed terminate the zoning session and to reactivate the zoneset.");
}
_log.error("Failed to remove zones " + e1.getMessage());
throw NetworkDeviceControllerException.exceptions.removeZonesStrategyFailed(e1);
}
}
use of com.emc.storageos.networkcontroller.impl.mds.Zone in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method getEndpointsZones.
@Override
public Map<String, List<Zone>> getEndpointsZones(NetworkSystem networkSystem, String fabricWwn, String nativeId, Collection<String> endpointsWwn) {
Map<String, List<Zone>> zones = new HashMap<String, List<Zone>>();
Map<CIMObjectPath, Zone> cachedZones = new HashMap<CIMObjectPath, Zone>();
try {
WBEMClient client = getNetworkDeviceClient(networkSystem);
for (String endpointWwn : endpointsWwn) {
_log.info("getting zones for endpoint {} in network {} ", endpointWwn, nativeId == null ? fabricWwn : nativeId);
zones.put(endpointWwn, _smisHelper.getEndpointZones(client, fabricWwn, endpointWwn, cachedZones));
}
} catch (Exception ex) {
_log.info("Failed to get zones for endpoints {} : ", endpointsWwn, ex.getMessage());
throw NetworkDeviceControllerException.exceptions.failedToGetEndpointZones(endpointsWwn, networkSystem.getLabel(), ex.getMessage());
}
return zones;
}
use of com.emc.storageos.networkcontroller.impl.mds.Zone in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method addZonesStrategy.
/**
* This function creates one or more zones in the active zoneset.
*
* @param client
* - the WBEMClient of the SMI-S provider
* @param zones
* - Zones to be created
* @param fabricId
* - the fabric where the zones will be created
* @return a map that contains the outcome for each zone keyed by zone name
* @throws NetworkDeviceControllerException
*/
public Map<String, String> addZonesStrategy(WBEMClient client, List<Zone> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
// a zone-name-to-result map to hold the results for each zone
Map<String, String> addedZonesResult = new HashMap<String, String>();
if (zones.isEmpty()) {
throw DeviceControllerException.exceptions.entityNullOrEmpty("zones");
}
CIMInstance zoneServiceIns = null;
try {
_log.info("add zones started.");
_log.info("Attempting to start a zoning session");
zoneServiceIns = _smisHelper.startSession(client, fabricId, fabricWwn);
if (zoneServiceIns == null) {
_log.info("Failed to start a zoning session.");
throw NetworkDeviceControllerException.exceptions.startZoningSessionFailed();
}
// First determine if there is an active zoneset.
CIMObjectPath zonesetPath = null;
CIMInstance activeZonesetIns = _smisHelper.getActiveZonesetInstance(client, fabricId, fabricWwn);
// There is no active zoneset. So we'll throw an exception.
if (activeZonesetIns == null) {
_log.info("No active zoneset fabrics: " + fabricId);
throw NetworkDeviceControllerException.exceptions.noActiveZonesetForFabric(fabricId);
} else {
// For Brocade, the active zoneset is a copy of a configuration zoneset. To make a change, we
// need to modify the configuration zoneset and activate it. Get the configuration zoneset.
zonesetPath = _smisHelper.getShadowZonesetPath(client, fabricId, fabricWwn, activeZonesetIns);
}
for (Zone zone : zones) {
try {
if (checkAndCreateZone(client, zoneServiceIns, fabricId, fabricWwn, zonesetPath, zone, activateZones)) {
addedZonesResult.put(zone.getName(), SUCCESS);
} else {
addedZonesResult.put(zone.getName(), NO_CHANGE);
}
} catch (Exception ex) {
addedZonesResult.put(zone.getName(), ERROR + ": " + ex.getMessage());
handleZonesStrategyException(ex, activateZones);
}
}
_log.info("Attempting to close zoning session.");
// If there are no zones that need to be added, just close the session without commit and return.
if (!hasResult(addedZonesResult, SUCCESS)) {
_log.info("No zones were added. Closing the session with no commit");
if (!_smisHelper.endSession(client, zoneServiceIns, false)) {
_log.info("Failed to terminate zoning session. Ignoring as session may have expired.");
}
return addedZonesResult;
} else {
// if zones were added, commit them before ending the session
if (_smisHelper.endSession(client, zoneServiceIns, true)) {
if (activateZones) {
_log.info("Attempting to activate the zoneset.");
if (_smisHelper.activateZoneSet(client, zoneServiceIns, zonesetPath, true)) {
_log.info("The zoneset was activated succcessfully.");
} else {
_log.info("Failed to activate the zoneset");
}
}
} else {
throw NetworkDeviceControllerException.exceptions.addZonesStrategyFailedZoneCommit();
}
}
_log.info("Add zone completed successfully.");
} catch (Exception e1) {
try {
if (zoneServiceIns != null) {
_log.info("Attempting to terminate zoning session.");
_smisHelper.endSession(client, zoneServiceIns, false);
}
} catch (WBEMException e) {
_log.error("Failed to terminate zoning session." + e.getLocalizedMessage(), e);
}
_log.error("Failed to create zones: " + e1.getLocalizedMessage(), e1);
throw NetworkDeviceControllerException.exceptions.addZonesStrategyFailed(e1);
}
return addedZonesResult;
}
Aggregations