Search in sources :

Example 11 with CIMInstance

use of javax.cim.CIMInstance 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 12 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class DCNMDialog method getFabricIds.

/**
 * Get the list of Vsan Ids.
 *
 * @return List<String>
 * @throws Exception
 */
public List<String> getFabricIds() throws Exception {
    // A set is used because in the case of a disconnected network the same Vsan can
    // show up twice. Conerted to list at end.
    Set<String> fabricIds = new HashSet<String>();
    List<Zoneset> zonesets = new ArrayList<Zoneset>();
    CIMObjectPath path = CimObjectPathCreator.createInstance("Cisco_Vsan", _namespace);
    CloseableIterator<CIMInstance> vsanIt = null;
    try {
        vsanIt = _client.enumerateInstances(path, false, true, true, null);
        while (vsanIt.hasNext()) {
            String vsanId = null;
            CIMInstance vsanIns = vsanIt.next();
            CIMProperty prop = vsanIns.getProperty("OtherIdentifyingInfo");
            String[] idinfoValue = (String[]) prop.getValue();
            if (idinfoValue.length == 2 && idinfoValue[0].equals("Fabric")) {
                vsanId = idinfoValue[1];
            }
            if (vsanId != null) {
                fabricIds.add(vsanId);
            }
        }
    } finally {
        if (vsanIt != null) {
            vsanIt.close();
        }
    }
    List<String> alist = new ArrayList<String>();
    alist.addAll(fabricIds);
    return alist;
}
Also used : CIMProperty(javax.cim.CIMProperty) ArrayList(java.util.ArrayList) CIMObjectPath(javax.cim.CIMObjectPath) CIMInstance(javax.cim.CIMInstance) HashSet(java.util.HashSet)

Example 13 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class DCNMDialog method getPortConnection.

List<FCEndpoint> getPortConnection() throws Exception {
    List<FCEndpoint> connections = new ArrayList<FCEndpoint>();
    CIMObjectPath path = CimObjectPathCreator.createInstance("CISCO_LogicalComputerSystem", _namespace);
    CloseableIterator<CIMInstance> lcsIt = null;
    CloseableIterator<CIMInstance> lportIt = null;
    CloseableIterator<CIMInstance> pepIt = null;
    try {
        lcsIt = _client.enumerateInstances(path, false, true, true, null);
        while (lcsIt.hasNext()) {
            CIMInstance lcsIns = lcsIt.next();
            // Get the VSAN of this Logical COmputer System
            String fabricId = null;
            String[] identifyingDescriptions = (String[]) lcsIns.getProperty("IdentifyingDescriptions").getValue();
            String[] otherIdentifyingInfo = (String[]) lcsIns.getProperty("OtherIdentifyingInfo").getValue();
            if (identifyingDescriptions.length >= 2 && identifyingDescriptions[1].equals("VsanId") && otherIdentifyingInfo.length >= 2) {
                fabricId = otherIdentifyingInfo[1];
            }
            // Find the associated CISCO_LogicalFCPort structures
            lportIt = _client.associatorInstances(lcsIns.getObjectPath(), "CISCO_FCPortsInLogicalComputerSystem", "CISCO_LogicalFCPort", null, null, false, null);
            // Iterate through all the ports in this Vsan, finding connections.
            while (lportIt.hasNext()) {
                CIMInstance lportIns = lportIt.next();
                _log.debug("logical port: " + cimStringProperty(lportIns, "Name") + " wwpn " + cimStringProperty(lportIns, "PermanentAddress"));
                String systemName = getSystemNameFromLogicalPort(lportIns);
                pepIt = _client.associatorInstances(lportIns.getObjectPath(), "CISCO_FCPortSAPImplementation", "CISCO_ProtocolEndPoint", null, null, false, null);
                while (pepIt.hasNext()) {
                    CIMInstance pepIns = pepIt.next();
                    _log.debug("endpoint: " + cimStringProperty(pepIns, "Name"));
                    FCProtocolEndpoint pep = new FCProtocolEndpoint(pepIns);
                    pep.findConnections(_client, _namespace);
                    for (String key : pep.connections.keySet()) {
                        _log.debug("connection: " + key);
                        FCProtocolEndpoint cep = pep.connections.get(key);
                        FCEndpoint conn = new FCEndpoint();
                        // conn.setFabricId(fabricId)
                        conn.setRemotePortName(formatWWN(cep.wwpn));
                        conn.setLabel(conn.getRemotePortName());
                        conn.setRemoteNodeName(formatWWN(cep.wwnn));
                        conn.setSwitchPortName(formatWWN(cimStringProperty(lportIns, "PermanentAddress")));
                        conn.setSwitchInterface(cimStringProperty(lportIns, "Name"));
                        conn.setFabricId(fabricId);
                        conn.setSwitchName(systemName);
                        connections.add(conn);
                    }
                }
                pepIt.close();
                pepIt = null;
            }
            lportIt.close();
            lportIt = null;
        }
    } finally {
        if (lcsIt != null) {
            lcsIt.close();
        }
        if (lportIt != null) {
            lportIt.close();
        }
        if (pepIt != null) {
            pepIt.close();
        }
    }
    return connections;
}
Also used : ArrayList(java.util.ArrayList) CIMObjectPath(javax.cim.CIMObjectPath) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) CIMInstance(javax.cim.CIMInstance)

Example 14 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class DCNMDialog method getSystemNameFromLogicalPort.

/**
 * Given an instance of a CISCO_LogicalFCPort, get the system name housing this port.
 *
 * @param lportIns
 * @return system name String
 * @throws Exception
 */
private String getSystemNameFromLogicalPort(CIMInstance lportIns) throws Exception {
    String systemName = null;
    CloseableIterator<CIMInstance> fcportIt = null;
    CloseableIterator<CIMInstance> physcomputerIt = null;
    try {
        fcportIt = _client.associatorInstances(lportIns.getObjectPath(), null, "CISCO_FCPort", null, null, false, null);
        while (fcportIt.hasNext()) {
            CIMInstance fcportIns = fcportIt.next();
            physcomputerIt = _client.associatorInstances(fcportIns.getObjectPath(), null, "CISCO_PhysicalComputerSystem", null, null, false, null);
            while (physcomputerIt.hasNext()) {
                CIMInstance physins = physcomputerIt.next();
                systemName = cimStringProperty(physins, "ElementName");
            }
            physcomputerIt.close();
            physcomputerIt = null;
        }
    } finally {
        if (fcportIt != null) {
            fcportIt.close();
        }
        if (physcomputerIt != null) {
            physcomputerIt.close();
        }
    }
    return systemName;
}
Also used : CIMInstance(javax.cim.CIMInstance)

Example 15 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class DCNMDialog method getZonesetsInVsan.

/**
 * Returns the zonesets in a VSAN as given by its CIMInstance.
 * This generates the nested objects Zone and ZoneMember in the Zonesets.
 *
 * @param vsanIns CIMInstance of vsan
 * @return List<Zoneset>
 * @throws javax.wbem.WBEMException
 */
private List<Zoneset> getZonesetsInVsan(CIMInstance vsanIns) throws WBEMException {
    List<Zoneset> inactiveZonesets = new ArrayList<Zoneset>();
    Zoneset activeZoneset = null;
    // Iterate through the zonesets.
    CloseableIterator<CIMInstance> zstIt = null;
    try {
        zstIt = _client.associatorInstances(vsanIns.getObjectPath(), "CIM_HostedCollection", "CISCO_Zoneset", null, null, false, null);
        while (zstIt.hasNext()) {
            CIMInstance zsIns = zstIt.next();
            Zoneset zs = makeZoneset(zsIns);
            _log.debug("zoneset: " + zs.name);
            if (zs.active == true) {
                activeZoneset = zs;
            } else {
                inactiveZonesets.add(zs);
            }
        }
    } catch (WBEMException ex) {
    // Problem where iterator isn't returned in associators();
    } finally {
        if (zstIt != null) {
            zstIt.close();
        }
    }
    List<Zoneset> zonesets = new ArrayList<Zoneset>();
    if (activeZoneset != null) {
        zonesets.add(activeZoneset);
    }
    zonesets.addAll(inactiveZonesets);
    return zonesets;
}
Also used : ArrayList(java.util.ArrayList) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Aggregations

CIMInstance (javax.cim.CIMInstance)370 CIMObjectPath (javax.cim.CIMObjectPath)254 WBEMException (javax.wbem.WBEMException)139 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)104 ArrayList (java.util.ArrayList)98 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)79 URI (java.net.URI)79 CIMArgument (javax.cim.CIMArgument)71 WBEMClient (javax.wbem.client.WBEMClient)69 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)62 Volume (com.emc.storageos.db.client.model.Volume)62 HashSet (java.util.HashSet)60 IOException (java.io.IOException)53 HashMap (java.util.HashMap)52 Iterator (java.util.Iterator)50 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)48 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)48 CIMProperty (javax.cim.CIMProperty)37 StringSet (com.emc.storageos.db.client.model.StringSet)31 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)29