use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.
the class MdsNetworkSystemDevice method removeAliases.
@Override
public BiosCommandResult removeAliases(NetworkSystem network, List<ZoneWwnAlias> removingAliases, String fabricId, String fabricWwn) throws NetworkDeviceControllerException {
BiosCommandResult result = null;
MDSDialog dialog = null;
Map<String, String> removedAliasesName = new HashMap<String, String>();
try {
dialog = setUpDialog(network);
if (!removingAliases.isEmpty()) {
removedAliasesName.putAll(removeAliasesStrategy(dialog, removingAliases));
}
String msg = "Successfully removed aliases: " + removedAliasesName.toString();
if (!hasResult(removedAliasesName, SUCCESS)) {
msg = "Network System: " + network.getLabel() + ": No aliases were removed";
}
_log.info(msg);
result = getBiosCommandResult(removedAliasesName);
} catch (Exception ex) {
_log.error("Cannot remove aliases: " + (ex.getCause() != null ? ex.getCause().getMessage() : ex.getLocalizedMessage()));
throw ex;
} finally {
disconnect(dialog);
}
return result;
}
use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException 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.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method addZones.
@Override
public BiosCommandResult addZones(NetworkSystem networkSystem, List<Zone> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
BiosCommandResult result = null;
// a zone-name-to-result map to hold the results for each zone
Map<String, String> addZonesResults = new HashMap<String, String>();
try {
validateFabric(networkSystem, fabricWwn, fabricId);
Map<NetworkLite, List<Zone>> zonesPerFabric = getAllZonesForZones(zones, false, fabricId, fabricWwn);
WBEMClient client = getNetworkDeviceClient(networkSystem);
for (NetworkLite network : zonesPerFabric.keySet()) {
addZonesResults.putAll(addZonesStrategy(client, zonesPerFabric.get(network), network.getNativeId(), NetworkUtil.getNetworkWwn(network), activateZones));
}
_log.info(toMessage(addZonesResults));
result = getBiosCommandResult(addZonesResults);
} catch (NetworkDeviceControllerException ex) {
_log.error("Cannot add zones: " + ex.getLocalizedMessage());
throw ex;
}
return result;
}
use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException 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;
}
use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.
the class BrocadeNetworkSystemDevice method updateZonesStrategy.
/**
* Updates one or more zones by adding/removing members as requested for each zone.
*
* @param client and instance of {@link WBEMClient} connected to the provider
* @param zones the list of zone update requests
* @param fabricId the name of the fabric where the zones exist
* @param fabricWwn the WWN of the fabric where the zones exist
* @param activateZones a boolean to indicate if the zoneset should be activated
* following successful updates
* @return a map of the update results by zone keyed by zone name
* @throws NetworkDeviceControllerException
*/
public Map<String, String> updateZonesStrategy(WBEMClient client, List<ZoneUpdate> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
// to do - Make sure fabric
// id and fabric wwn are not
// null or only request
// needed params
// a zone-name-to-result map to hold the results for each zone
Map<String, String> zoneUpdateResults = new HashMap<String, String>();
if (zones.isEmpty()) {
throw DeviceControllerException.exceptions.entityNullOrEmpty("zones");
}
CIMInstance zoneServiceIns = null;
try {
_log.info("Update zones started.");
_log.info("Attempting to start a zoning session");
if (fabricWwn == null) {
fabricWwn = _smisHelper.getFabricWwn(client, fabricId);
}
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, error
if (activeZonesetIns == null) {
_log.info("Cannot find active zoneset.");
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);
}
Map<String, Zone> zonesInFabric = _smisHelper.getZones(client, getZoneNames(zones), fabricWwn, false, true, true);
for (ZoneUpdate zone : zones) {
try {
if (checkAndUpdateZone(client, zoneServiceIns, fabricId, fabricWwn, zonesetPath, zonesInFabric, zone)) {
zoneUpdateResults.put(zone.getName(), SUCCESS);
} else {
zoneUpdateResults.put(zone.getName(), NO_CHANGE);
}
} catch (Exception ex) {
zoneUpdateResults.put(zone.getName(), ERROR + " : " + ex.getMessage());
handleZonesStrategyException(ex, activateZones);
}
}
_log.info("Attempting to close zoning session.");
// If there were no zones updated, just close the session without commit and return.
if (!hasResult(zoneUpdateResults, SUCCESS)) {
_log.info("No zones were updates. 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.");
}
} else {
// if zones were updated, 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.updateZonesStrategyFailedCommit();
}
}
_log.info("Update zones strategy 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 update zones: " + e1.getLocalizedMessage(), e1);
throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailed(e1);
}
return zoneUpdateResults;
}
Aggregations