Search in sources :

Example 1 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class SSHDialog method sendWaitFor.

/**
 * Send string and then wait for a prompt in the supplied set.
 * All data received is in buf.
 *
 * @param send
 * @param timeout
 * @param prompts - An array of MDS prompts. The first one encountered will be returned.
 * @param buf - Output: StringBuilder containing characters received (including prompt)
 * @return
 */
public SSHPrompt sendWaitFor(String send, Integer timeout, SSHPrompt[] prompts, StringBuilder buf) throws NetworkDeviceControllerException {
    _log.debug(MessageFormat.format("Host: {0}, Port: {1} - sendWaitFor: {2}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), send }));
    SSHPrompt prompt = null;
    try {
        oswr.append(send);
        oswr.flush();
        prompt = waitFor(prompts, timeout, buf, false);
    } catch (Exception ex) {
        _log.error("Exception sending string: {},  recevied: {}", send, buf);
        throw new NetworkDeviceControllerException(ex);
    }
    _log.debug(MessageFormat.format("Host: {0}, Port: {1} - sendWaitFor: {2} - Received data: {3}", new Object[] { getSession().getSession().getHost(), getSession().getSession().getPort(), send, buf }));
    return prompt;
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) IOException(java.io.IOException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 2 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class BrocadeNetworkSMIS method addZoneAlias.

/**
 * Create an instance of an alias object on the switch. The alias object can have
 * a single member that has to be of type WWN.
 * <p>
 * This function will retry if the alias creation fails because the session is lost or timed out. The total number of tries is set to 2.
 *
 * @param client an instance of WBEMClient with an open session to SMI provider
 * @param zoneServiceIns an instance of zone service for the fabric
 * @param fabricId the fabric name
 * @param fabricWwn the fabric WWN
 * @param alias the object containing the attributes of the alias to be created
 * @throws WBEMException
 */
@SuppressWarnings("rawtypes")
public CIMObjectPath addZoneAlias(WBEMClient client, CIMInstance zoneServiceIns, String fabricId, String fabricWwn, ZoneWwnAlias alias) throws WBEMException {
    CIMObjectPath aliasPath = null;
    CIMArgument[] outargs = new CIMArgument[1];
    CIMArgument[] inargs = new CIMArgument[1];
    inargs[0] = _cimArgumentFactory.string(_CollectionAlias, alias.getName());
    _log.info("Creating alias: " + alias.getName());
    UnsignedInteger32 result = new UnsignedInteger32(Integer.MAX_VALUE);
    int count = 0;
    while (result.intValue() != 0 && count < 2) {
        result = (UnsignedInteger32) client.invokeMethod(zoneServiceIns.getObjectPath(), _CreateZoneAlias, inargs, outargs);
        if (result.intValue() == 0 && outargs[0].getValue() != null) {
            aliasPath = (CIMObjectPath) outargs[0].getValue();
            _log.info("Created alias: " + alias.getName() + " with path " + aliasPath);
            break;
        } else if (result.intValue() == 32770) {
            // session timed out or was stolen
            _log.info("Created alias: " + alias.getName() + " failed with result.intvalue() 32770: " + "Transaction Not Started. Retry to get a new session lock.");
            endSession(client, zoneServiceIns, false);
            zoneServiceIns = startSession(client, fabricId, fabricWwn);
            count++;
        } else {
            throw new NetworkDeviceControllerException("Created alias failed: " + alias.getName() + " with result.intValue() " + result.intValue());
        }
    }
    if (aliasPath == null) {
        if (count >= 2) {
            _log.info("Failed to create alias " + alias.getName() + ". The maximum number of retries (" + (count + 1) + ") was reached without successfully starting a transaction.");
        }
    } else {
        // add WWN as alias member to alias
        addZoneOrAliasMember(client, zoneServiceIns, fabricWwn, aliasPath, alias.getAddress());
    }
    return aliasPath;
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) CIMObjectPath(javax.cim.CIMObjectPath) UnsignedInteger32(javax.cim.UnsignedInteger32) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) CIMArgument(javax.cim.CIMArgument)

Example 3 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException 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;
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) CIMObjectPath(javax.cim.CIMObjectPath) WBEMClient(javax.wbem.client.WBEMClient) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 4 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class BrocadeNetworkSystemDevice method executeInSession.

/**
 * Common code for opening sessions and executing alias-type commands
 *
 * @param networkSystem the network system when the commands will execute
 * @param aliases a list of aliases to be created/updated/deleted
 * @param fabricId the name of fabric where the aliases will be changed
 * @param fabricWwn the WWN of fabric where the aliases will be changed
 * @param methodName the method to be executed
 * @param methodLogName the method name to be used for logging
 * @return the command that contains a map of results-per-alias keyed
 *         by alias name
 * @throws NetworkDeviceControllerException
 */
private BiosCommandResult executeInSession(NetworkSystem networkSystem, List<ZoneWwnAlias> aliases, String fabricId, String fabricWwn, String methodName, String methodLogName) throws NetworkDeviceControllerException {
    // a alias-name-to-result map to hold the results for each alias
    Map<String, String> aliasUpdateResults = new HashMap<String, String>();
    if (aliases.isEmpty()) {
        throw DeviceControllerException.exceptions.entityNullOrEmpty("aliases");
    }
    WBEMClient client = getNetworkDeviceClient(networkSystem);
    CIMInstance zoneServiceIns = null;
    try {
        if (fabricWwn == null) {
            fabricWwn = _smisHelper.getFabricWwn(client, fabricId);
        } else {
            validateFabric(networkSystem, fabricWwn, fabricId);
        }
        _log.info("{} started.", methodLogName);
        _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();
        }
        Method method = getClass().getMethod(methodName, new Class[] { WBEMClient.class, CIMInstance.class, String.class, String.class, ZoneWwnAlias.class });
        for (ZoneWwnAlias alias : aliases) {
            try {
                if ((Boolean) method.invoke(this, client, zoneServiceIns, fabricId, fabricWwn, alias)) {
                    aliasUpdateResults.put(alias.getName(), SUCCESS);
                } else {
                    aliasUpdateResults.put(alias.getName(), NO_CHANGE);
                }
            } catch (Exception ex) {
                aliasUpdateResults.put(alias.getName(), ERROR + " : " + ex.getMessage());
                _log.info("Exception was encountered but will try the rest of the batch. Error message: ", ex);
            }
        }
        _log.info("Attempting to close zoning session.");
        // If no aliases were changed, just close the session without commit and return.
        if (!hasResult(aliasUpdateResults, SUCCESS)) {
            _log.info("{} was not successful for any entity. Closing the session with no commit", methodLogName);
            if (!_smisHelper.endSession(client, zoneServiceIns, false)) {
                _log.info("Failed to terminate zoning session. Ignoring as session may have expired.");
            }
        } else {
            // if aliases were changed, commit them before ending the session
            if (!_smisHelper.endSession(client, zoneServiceIns, true)) {
                throw NetworkDeviceControllerException.exceptions.zoneSessionCommitFailed(fabricId);
            }
        }
        _log.info("{} completed successfully.", methodLogName);
    } 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 " + methodLogName + ": " + e1.getLocalizedMessage(), e1);
        throw NetworkDeviceControllerException.exceptions.operationFailed(methodLogName, e1);
    }
    _log.info(methodLogName + " results: " + toMessage(aliasUpdateResults));
    return getBiosCommandResult(aliasUpdateResults);
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 5 with NetworkDeviceControllerException

use of com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException in project coprhd-controller by CoprHD.

the class BrocadeNetworkSystemDevice method removeZones.

public BiosCommandResult removeZones(NetworkSystem networkSystem, List<Zone> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
    BiosCommandResult result = null;
    Map<String, String> removedZoneResults = new HashMap<String, String>();
    try {
        validateFabric(networkSystem, fabricWwn, fabricId);
        Map<NetworkLite, List<Zone>> zonesPerFabric = getAllZonesForZones(zones, true, fabricId, fabricWwn);
        for (NetworkLite network : zonesPerFabric.keySet()) {
            WBEMClient client = getNetworkDeviceClient(networkSystem);
            removedZoneResults.putAll(removeZonesStrategy(client, zonesPerFabric.get(network), network.getNativeId(), NetworkUtil.getNetworkWwn(network), activateZones));
        }
        result = getBiosCommandResult(removedZoneResults);
        _log.info("Remove zone results {}", toMessage(removedZoneResults));
    } catch (NetworkDeviceControllerException ex) {
        _log.error("Cannot remove zones: " + ex.getLocalizedMessage());
        throw ex;
    }
    return result;
}
Also used : NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) HashMap(java.util.HashMap) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkLite(com.emc.storageos.util.NetworkLite) ArrayList(java.util.ArrayList) List(java.util.List) WBEMClient(javax.wbem.client.WBEMClient)

Aggregations

NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)26 HashMap (java.util.HashMap)12 FCEndpoint (com.emc.storageos.db.client.model.FCEndpoint)10 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)10 SSHPrompt (com.emc.storageos.networkcontroller.SSHPrompt)7 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 ArrayList (java.util.ArrayList)7 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 CIMInstance (javax.cim.CIMInstance)5 CIMObjectPath (javax.cim.CIMObjectPath)5 WBEMException (javax.wbem.WBEMException)5 WBEMClient (javax.wbem.client.WBEMClient)5 Zone (com.emc.storageos.networkcontroller.impl.mds.Zone)3 NetworkLite (com.emc.storageos.util.NetworkLite)2 List (java.util.List)2 IntRange (org.apache.commons.lang.math.IntRange)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 Network (com.emc.storageos.db.client.model.Network)1 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)1