Search in sources :

Example 1 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class BaseSANCIMObject method printAllAssociatedClasses.

protected void printAllAssociatedClasses(WBEMClient client, CIMObjectPath path) {
    CloseableIterator<CIMInstance> zns = null;
    try {
        zns = client.associatorInstances(path, null, null, null, null, false, null);
        while (zns.hasNext()) {
            // CIMClass cl = zns.next();
            // System.out.println("class: " + cl.getName());
            CIMInstance ins = zns.next();
            _log.info(ins.toString());
        }
    } catch (WBEMException ex) {
        _log.error("Exception: " + ex.getLocalizedMessage());
    } finally {
        if (zns != null) {
            zns.close();
        }
    }
}
Also used : WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Example 2 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class BrocadeNetworkSMIS method getAliases.

/**
 * Gets the list of aliases for a given fabric
 * This function uses the associations to improve performance and parses the
 * alias name and member address from the paths:
 * Brocade_ZoneMembershipSettingDataInZoneAlias {
 * ManagedElement =
 * "root/brocade1:Brocade_ZoneAlias.InstanceID=\"NAME=Hala_REST_API_ZONE_12;ACTIVE=false;FABRIC=10000027F858F6C0;CLASSNAME=Brocade_ZoneAlias\""
 * ;
 * SettingData =
 * "root/brocade1:Brocade_ZoneMembershipSettingData.InstanceID=\"NAME=2010101010101010;ZMTYPE=5;ACTIVE=false;FABRIC=10000027F858F6C0;CLASSNAME=Brocade_ZoneMembershipSettingData\""
 * ;
 * };
 *
 * @param client an instance of WBEMClient
 * @param fabricId the name of the fabric
 * @param fabricWwn the WWN of the fabric
 * @throws WBEMException
 */
public List<ZoneWwnAlias> getAliases(WBEMClient client, String fabricId, String fabricWwn) throws WBEMException {
    Map<String, ZoneWwnAlias> aliases = new HashMap<String, ZoneWwnAlias>();
    if (fabricWwn == null) {
        fabricWwn = getFabricWwn(client, fabricId);
    }
    fabricWwn = fabricWwn.replaceAll(":", "");
    CloseableIterator<CIMInstance> it = null;
    try {
        CIMObjectPath path = CimObjectPathCreator.createInstance(_Brocade_ZoneMembershipSettingDataInZoneAlias, _namespace);
        it = client.enumerateInstances(path, false, true, true, null);
        CIMInstance ins = null;
        String aliasPath = null;
        String memberPath = null;
        String wwn = null;
        ZoneWwnAlias alias = null;
        while (it.hasNext()) {
            ins = it.next();
            _log.debug(ins.toString());
            aliasPath = cimStringProperty(ins, _ManagedElement);
            memberPath = cimStringProperty(ins, _SettingData);
            wwn = getPropertyValueFromString(memberPath, SmisConstants.CP_FABRIC);
            if (StringUtils.equalsIgnoreCase(wwn, fabricWwn)) {
                try {
                    alias = new ZoneWwnAlias();
                    alias.setAddress(formatWWN(getPropertyValueFromString(memberPath, SmisConstants.CP_NSNAME)));
                    alias.setName(getPropertyValueFromString(aliasPath, SmisConstants.CP_NSNAME));
                    // Use a map to handle the unsupported scenario when an alias has more than one member
                    // in this code the alias will arbitrarily have the the last members discovered.
                    // this is needed to ensure code dependent on this code does not receive duplicates
                    aliases.put(alias.getName(), alias);
                    _log.debug("Retreived alias name " + alias.getName() + " and address " + alias.getAddress());
                } catch (Exception e) {
                    // if the WWN is not a valid one and setAddress will throw an error
                    // Catch it , log it , skip it it and move forward with processing the rest of the data
                    _log.warn("An exception was encountered while processing " + wwn + " may be it is malformed " + e.getMessage());
                }
            }
        }
    } catch (Exception ex) {
        _log.warn("An exception was encountered while getting the aliases for " + "fabric: " + fabricId + ". The exception is: " + ex.getMessage());
    } finally {
        if (it != null) {
            it.close();
        }
    }
    return new ArrayList<ZoneWwnAlias>(aliases.values());
}
Also used : HashMap(java.util.HashMap) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) ZoneWwnAlias(com.emc.storageos.networkcontroller.impl.mds.ZoneWwnAlias) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) NetworkControllerSessionLockedException(com.emc.storageos.networkcontroller.exceptions.NetworkControllerSessionLockedException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 3 with WBEMException

use of javax.wbem.WBEMException 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;
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) TimeZone(java.util.TimeZone) ArrayList(java.util.ArrayList) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Example 4 with WBEMException

use of javax.wbem.WBEMException in project coprhd-controller by CoprHD.

the class BrocadeNetworkSystemDevice method getWBEMClient.

private WBEMClient getWBEMClient(String ipaddress, String smisport, String username, String password, boolean useSSL) throws NetworkDeviceControllerException {
    try {
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_049);
        WBEMClient client = WBEMClientFactory.getClient(WBEMClientConstants.PROTOCOL_CIMXML);
        String protocol = useSSL ? CimConstants.SECURE_PROTOCOL : CimConstants.DEFAULT_PROTOCOL;
        CIMObjectPath path = CimObjectPathCreator.createInstance(protocol, ipaddress, smisport.toString(), BrocadeNetworkSMIS.getNamespace(), null, null);
        final Subject subject = new Subject();
        subject.getPrincipals().add(new UserPrincipal(username));
        subject.getPrivateCredentials().add(new PasswordCredential(password));
        client.initialize(path, subject, new Locale[] { Locale.US });
        return client;
    } catch (WBEMException ex) {
        _log.info("Failed to connect to Brocade at IP: " + ipaddress + " because: " + ex.getLocalizedMessage());
        throw NetworkDeviceControllerException.exceptions.getWBEMClientFailed(ipaddress, ex);
    }
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) PasswordCredential(javax.wbem.client.PasswordCredential) WBEMClient(javax.wbem.client.WBEMClient) WBEMException(javax.wbem.WBEMException) Subject(javax.security.auth.Subject) UserPrincipal(javax.wbem.client.UserPrincipal)

Example 5 with WBEMException

use of javax.wbem.WBEMException 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)

Aggregations

WBEMException (javax.wbem.WBEMException)122 CIMObjectPath (javax.cim.CIMObjectPath)90 CIMInstance (javax.cim.CIMInstance)63 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)60 CIMArgument (javax.cim.CIMArgument)52 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)38 ArrayList (java.util.ArrayList)29 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)27 Volume (com.emc.storageos.db.client.model.Volume)22 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)19 WBEMClient (javax.wbem.client.WBEMClient)19 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)16 HashSet (java.util.HashSet)15 URI (java.net.URI)13 HashMap (java.util.HashMap)13 BlockObject (com.emc.storageos.db.client.model.BlockObject)10 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)9 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)8