Search in sources :

Example 16 with FCEndpoint

use of com.emc.storageos.db.client.model.FCEndpoint in project coprhd-controller by CoprHD.

the class MDSDialog method showFcnsDatabase.

/**
 * Generates a set of FCPortConnection entries for the specified vsan id (or all
 * Vsans if vsanId is null).
 *
 * @param vsanId used to qualify command to one vsan
 * @return list of FCPortConnections
 */
public List<FCEndpoint> showFcnsDatabase(Integer vsanId) throws NetworkDeviceControllerException {
    Map<Integer, String> vsanToWwns = getVsanWwns(vsanId);
    List<FCEndpoint> connections = new ArrayList<FCEndpoint>();
    SSHPrompt[] prompts = { SSHPrompt.MDS_POUND, SSHPrompt.MDS_GREATER_THAN };
    StringBuilder buf = new StringBuilder();
    // show fcns database detail
    String cmd = MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.cmd");
    if (vsanId != null) {
        // \ vsan
        cmd = cmd + MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.vsan.cmd") + vsanId.toString() + "\n";
    } else {
        // $NON-NLS-1$
        cmd = cmd + "\n";
    }
    SSHPrompt prompt = sendWaitFor(cmd, defaultTimeout, prompts, buf);
    String[] lines = getLines(buf);
    String[] regex = { // VSAN:(\\d+)\\s+FCID:(0x[0-9a-fA-F:]+)\\s*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.VSAN.match"), // port-wwn[^:]+:([0-9a-fA-F:]+).*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.portwwn.match"), // node-wwn[^:]+:([0-9a-fA-F:]+).*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.nodewwn.match"), // fabric-port-wwn[^:]+:([0-9a-fA-F:]+).*
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.fabricportwwn.match"), // Connected Interface[^:]+:(fc\\S+)
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.ConnectedInterface.match"), // Switch Name[^:]+:(.*)
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.SwitchName.match"), // \\s*\\[(\\S+)\\]\\s*:q
    MDSDialogProperties.getString("MDSDialog.showFcnsDatabase.deviceAlias.match") };
    String[] groups = new String[10];
    FCEndpoint conn = null;
    for (String line : lines) {
        int index = match(line, regex, groups, Pattern.CASE_INSENSITIVE);
        switch(index) {
            case 0:
                conn = new FCEndpoint();
                // vsan
                conn.setFabricId(groups[0]);
                // fcid
                conn.setFcid(groups[1]);
                String fabricWwn = vsanToWwns.get(new Integer(groups[0]));
                if (fabricWwn != null) {
                    conn.setFabricWwn(fabricWwn);
                }
                connections.add(conn);
                break;
            case 1:
                // remote wwpn
                conn.setRemotePortName(groups[0]);
                break;
            case 2:
                // remote wwnn
                conn.setRemoteNodeName(groups[0]);
                break;
            case 3:
                // local wwpn
                conn.setSwitchPortName(groups[0]);
                break;
            case 4:
                // switch interface
                conn.setSwitchInterface(groups[0]);
                break;
            case 5:
                // switch name
                conn.setSwitchName(groups[0]);
                break;
            case 6:
                // pwwn alias
                conn.setRemotePortAlias(groups[0]);
        }
    }
    return connections;
}
Also used : ArrayList(java.util.ArrayList) SSHPrompt(com.emc.storageos.networkcontroller.SSHPrompt) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 17 with FCEndpoint

use of com.emc.storageos.db.client.model.FCEndpoint in project coprhd-controller by CoprHD.

the class VirtualArrayService method getComputeSystems.

/**
 * Fetches all Compute Systems that are visible in the vArray
 *
 * First determine physical connectivity to any switches in the vArrray.
 * 1. From the vArray, determine the networks. (Call this Network Set)
 * 2. From the networks, get the physical switches that are attached.
 * 3. For each physical switch, iterate through the networks and get the FC endpoints.
 * 4. Look for any of the FIC ports in any of the FC endpoints on any of the
 * networks on the physical switch. When a FIC port matches, call this FIC
 * Port.
 * 5. If found, then there is physical connectivity.
 *
 * With physical connectivity Established:
 * 1. Given the FIC Port from step (4), pull the VSAN or VSANs assigned to
 * it on UCS.
 * 2. If the set contains one of the networks from the Network
 * Set in (1), we have connectivity to that vArray.
 *
 * @param id
 *            the URN of a ViPR VirtualArray.
 * @brief List all Compute Systems that are visible in the vArray
 * @return List of Compute Systems
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/compute-systems")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public ComputeSystemBulkRep getComputeSystems(@PathParam("id") URI id) {
    _log.info("get connected CS for vArray: {}", id);
    // Get and validate the varray with the passed id.
    ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
    ArgValidator.checkEntityNotNull(varray, id, isIdEmbeddedInURL(id));
    BulkIdParam matchingCsIds = new BulkIdParam();
    // get varray networks
    List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, id, Network.class, "connectedVirtualArrays");
    // collect network vsanIds and switch ids
    Set<String> networkVsanIds = new HashSet<>();
    Set<String> nsIds = new HashSet<>();
    for (Network network : networks) {
        if (StorageProtocol.Transport.FC.name().equalsIgnoreCase(network.getTransportType()) && DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(network.getRegistrationStatus())) {
            networkVsanIds.add(network.getNativeId());
            if (network.getNetworkSystems() != null) {
                nsIds.addAll(network.getNetworkSystems());
            }
        }
    }
    _log.info("vArray has these networks: {}", networkVsanIds);
    // use only registered network systems
    Set<URI> nsUris = new HashSet<>();
    for (String nsUri : nsIds) {
        nsUris.add(URI.create(nsUri));
    }
    List<NetworkSystem> nsList = _dbClient.queryObject(NetworkSystem.class, nsUris);
    for (NetworkSystem ns : nsList) {
        if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(ns.getRegistrationStatus())) {
            nsIds.remove(ns.getId().toString());
        }
    }
    _log.info("the networks run on these network systems: {}", nsIds);
    if (networkVsanIds.isEmpty() || nsIds.isEmpty()) {
        // no networks in the array - exit early
        return new ComputeSystemBulkRep();
    }
    // for every switch get FCEndpoint.remotePortName(s)
    Set<String> connectedEndpoints = new HashSet<String>();
    for (String nsId : nsIds) {
        URIQueryResultList uriList = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(URI.create(nsId)), uriList);
        List<URI> epIds = new ArrayList<URI>();
        Iterator<URI> iter = uriList.iterator();
        while (iter.hasNext()) {
            epIds.add(iter.next());
        }
        List<FCEndpoint> eps = _dbClient.queryObjectField(FCEndpoint.class, "remotePortName", epIds);
        for (FCEndpoint ep : eps) {
            connectedEndpoints.add(ep.getRemotePortName());
        }
    }
    _log.debug("all connected endpoints: {}", connectedEndpoints);
    // get all CS
    List<URI> csIds = _dbClient.queryByType(ComputeSystem.class, true);
    List<ComputeSystem> csList = _dbClient.queryObject(ComputeSystem.class, csIds);
    for (ComputeSystem cs : csList) {
        if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(cs.getRegistrationStatus())) {
            // skip not registered CS
            continue;
        }
        boolean connected = false;
        _log.info("evaluating uplinks of cs: {}", cs.getLabel());
        // loop thru UplinkPorts to find matches
        URIQueryResultList uris = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeFabricUplinkPortConstraint(cs.getId()), uris);
        List<ComputeFabricUplinkPort> uplinkPorts = _dbClient.queryObject(ComputeFabricUplinkPort.class, uris, true);
        for (ComputeFabricUplinkPort port : uplinkPorts) {
            if (connectedEndpoints.contains(port.getWwpn())) {
                _log.info("found matching endpoint: {}", port.getWwpn());
                if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
                    _log.info("and networks overlap: {}", port.getVsans());
                    matchingCsIds.getIds().add(cs.getId());
                    connected = true;
                    break;
                }
            }
        }
        if (connected) {
            // skip uplink port channel matching as we are already connected
            continue;
        }
        // now loop thru UplinkPortChannels to find matches
        uris = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeUplinkPortChannelConstraint(cs.getId()), uris);
        List<ComputeFabricUplinkPortChannel> uplinkPortChannels = _dbClient.queryObject(ComputeFabricUplinkPortChannel.class, uris, true);
        for (ComputeFabricUplinkPortChannel port : uplinkPortChannels) {
            if (connectedEndpoints.contains(port.getWwpn())) {
                _log.info("found matching endpoint: {}", port.getWwpn());
                if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
                    _log.info("and networks overlap: {}", port.getVsans());
                    matchingCsIds.getIds().add(cs.getId());
                    connected = true;
                    break;
                }
            }
        }
    }
    _log.info("these CS are connected to the vArray: {}", matchingCsIds.getIds());
    if (matchingCsIds.getIds().isEmpty()) {
        return new ComputeSystemBulkRep();
    }
    ComputeSystemBulkRep computeSystemReps = computeSystemService.getBulkResources(matchingCsIds);
    return mapValidServiceProfileTemplatesToComputeSystem(computeSystemReps, varray.getId());
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) BulkIdParam(com.emc.storageos.model.BulkIdParam) ComputeFabricUplinkPort(com.emc.storageos.db.client.model.ComputeFabricUplinkPort) ArrayList(java.util.ArrayList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Network(com.emc.storageos.db.client.model.Network) ComputeSystemBulkRep(com.emc.storageos.model.compute.ComputeSystemBulkRep) ComputeFabricUplinkPortChannel(com.emc.storageos.db.client.model.ComputeFabricUplinkPortChannel) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) HashSet(java.util.HashSet) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 18 with FCEndpoint

use of com.emc.storageos.db.client.model.FCEndpoint in project coprhd-controller by CoprHD.

the class PlacementUtils method getSwitchName.

/**
 * Get the name of a SAN switch that is connected to the storage port or initiator with the portWWN.
 * Return null if no SAN switches are connected.
 *
 * @param portWWN portWWN of a storagePort or an initiator
 * @param dbClient
 * @return the connected switch name
 */
public static String getSwitchName(String portWWN, DbClient dbClient) {
    if (portWWN != null && !portWWN.isEmpty()) {
        URIQueryResultList uriList = new URIQueryResultList();
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFCEndpointRemotePortNameConstraint(portWWN), uriList);
        for (URI uri : uriList) {
            FCEndpoint endpoint = dbClient.queryObject(FCEndpoint.class, uri);
            if (endpoint != null) {
                if (endpoint.getSwitchName() != null) {
                    // Return the switch name if it is known.
                    if (endpoint.getAwolCount() == 0) {
                        return endpoint.getSwitchName();
                    }
                }
            }
        }
    } else {
        log.warn("The portWWN is not set");
    }
    return null;
}
Also used : URI(java.net.URI) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 19 with FCEndpoint

use of com.emc.storageos.db.client.model.FCEndpoint in project coprhd-controller by CoprHD.

the class MapStoragePort method applyAliasToStoragePortRestRep.

/**
 * Convenient method to map wwn alias to its corresponded port wwn id
 *
 * @param storagePortRestRep
 */
private void applyAliasToStoragePortRestRep(StoragePortRestRep storagePortRestRep) {
    if (dbClient == null) {
        return;
    }
    URIQueryResultList uriList = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFCEndpointRemotePortNameConstraint(storagePortRestRep.getPortNetworkId()), uriList);
    for (URI uri : uriList) {
        FCEndpoint ep = dbClient.queryObject(FCEndpoint.class, uri);
        if (ep != null && !StringUtils.isEmpty(ep.getRemotePortAlias())) {
            storagePortRestRep.setPortAlias(ep.getRemotePortAlias());
        }
    }
}
Also used : URI(java.net.URI) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

FCEndpoint (com.emc.storageos.db.client.model.FCEndpoint)19 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)6 URI (java.net.URI)6 HashMap (java.util.HashMap)6 ControllerException (com.emc.storageos.volumecontroller.ControllerException)5 ArrayList (java.util.ArrayList)5 CIMInstance (javax.cim.CIMInstance)5 CIMObjectPath (javax.cim.CIMObjectPath)5 Network (com.emc.storageos.db.client.model.Network)4 HashSet (java.util.HashSet)4 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 IOException (java.io.IOException)2 Date (java.util.Date)2 MapVirtualArray (com.emc.storageos.api.mapper.functions.MapVirtualArray)1 ComputeFabricUplinkPort (com.emc.storageos.db.client.model.ComputeFabricUplinkPort)1 ComputeFabricUplinkPortChannel (com.emc.storageos.db.client.model.ComputeFabricUplinkPortChannel)1