package com.onaro.sanscreen.client.view.common.data; import java.util.Map; import com.onaro.sanscreen.client.Messages; import com.onaro.sanscreen.client.view.common.functions.PortNameRetriever; import com.onaro.sanscreen.client.view.common.functions.ProxyConnection; import com.onaro.sanscreen.server.interfaces.data.AbstractDataObjectDescription; import com.onaro.sanscreen.server.interfaces.data.inventory.Port; import com.onaro.sanscreen.server.interfaces.data.inventory.PortContainerType; /** * A class that collects information about the device directly or indirectly connected to a port. */ public class PortConnectionInfo { private static final PortNameRetriever PORT_NAME_RETRIEVER = new PortNameRetriever(); private static final Messages MESSAGES = Messages.INSTANCE; public static final String PROP_DIRECT_CONNECTION = "directConnection"; //$NON-NLS-1$ public static final String PROP_CONNECTED_TO_DESC = "connectedToDescription"; //$NON-NLS-1$ public static final String PROP_CONNECTED_DEVICE = "connectedDevice"; //$NON-NLS-1$ public static final String PROP_CONNECTED_DEVICE_NAME = "connectedDeviceName"; //$NON-NLS-1$ public static final String PROP_CONNECTED_DEVICE_TYPE = "connectedDeviceType"; //$NON-NLS-1$ public static final String PROP_CONNECTED_DEVICE_TYPE_AND_NAME = "connectedDeviceTypeAndName"; //$NON-NLS-1$ public static final String PROP_CONNECTED_NODE_WWN = "connectedNodeWwn"; //$NON-NLS-1$ public static final String PROP_CONNECTED_PORT_WWN = "connectedPortWwn"; //$NON-NLS-1$ public static final String PROP_CONNECTED_PORT_NAME = "connectedPortName"; //$NON-NLS-1$ private final boolean isDirectConnection; private final Port connectedPort; private final String connectedPortWwn; private final String connectedPortName; private final Container connectedContainer; private final String connectedDeviceTypeAndName; private final String connectedToDescription; /** * Immutable class that provides a display description of the port container. */ public static final class Container extends AbstractDataObjectDescription { private final String type; private final String name; private final String wwn; private final String description; /** * Creates a {@link Container}. * @param typeName * @param objectName * @param WWN */ public Container (String typeName, String objectName, String wwn) { this.type = typeName; this.name = objectName; this.wwn = wwn; this.description = Messages.INSTANCE.getTypedName (typeName, objectName); } @Override public String getName() { return name; } @Override public String getShortDescription() { return description; } @Override public String getLongDescription() { return description; } /** * Gets the display name for the container device type. * @return the type name */ public String getType() { return type; } /** * Gets the WWN for the port container device (adapter, switch, controller, or generic device). * @return the WWN */ public String getWwn() { return wwn; } } /** * Creates a {@link PortConnectionInfo}. * @param connectedPort directly connected port * @param proxyConnection FC name server information if the fabric connection is through a proxy * @param portContainers information about port containers (connection node devices) */ public PortConnectionInfo(Port connectedPort, ProxyConnection proxyConnection, Map portContainers) { this.connectedPort = connectedPort; // connected strings: if (connectedPort == null) { // No connection. isDirectConnection = false; connectedPortWwn = null; connectedPortName = null; connectedContainer = null; connectedDeviceTypeAndName = null; connectedToDescription = null; } else if (proxyConnection == null) { // Connected directly to switch or connected via generated port. isDirectConnection = ! connectedPort.isGenerated(); connectedPortWwn = connectedPort.getWwn(); connectedPortName = PORT_NAME_RETRIEVER.getValue(connectedPort).toString(); connectedContainer = portContainers.get (connectedPort); connectedDeviceTypeAndName = Messages.INSTANCE.getDeviceGroup (connectedContainer.getType(), connectedContainer.getName()); connectedToDescription = MESSAGES.getConnectedToString(connectedContainer.getShortDescription(), connectedPortName); } else { // Connected via proxy device (NPV switch or access gateway). Show connection to fabric switch port. isDirectConnection = false; Port fabricPort = proxyConnection.getFabricSwitchPort(); connectedPortWwn = fabricPort.getWwn(); connectedPortName = PORT_NAME_RETRIEVER.getValue(fabricPort).toString(); connectedContainer = portContainers.get (fabricPort); connectedDeviceTypeAndName = Messages.INSTANCE.getDeviceGroup (connectedContainer.getType(), connectedContainer.getName()); // Show connection via proxy node port. Port proxyPort = proxyConnection.getProxyNodePort(); Container proxyDevice = portContainers.get (proxyPort); String proxyPortName = PORT_NAME_RETRIEVER.getValue(proxyPort).toString(); connectedToDescription = MESSAGES.getConnectedToProxyString(connectedContainer.getShortDescription(), connectedPortName, proxyDevice.getName(), proxyPortName); } } public String getConnectedToDescription() { return connectedToDescription; } public String getConnectedDevice() { return connectedContainer == null? null : connectedContainer.getShortDescription(); } public String getConnectedDeviceName() { return connectedContainer == null? null : connectedContainer.getName(); } public String getConnectedDeviceType() { return connectedContainer == null? null : connectedContainer.getType(); } public String getConnectedDeviceTypeAndName() { return connectedDeviceTypeAndName; } public String getConnectedNodeWwn() { return connectedContainer == null? null : connectedContainer.getWwn(); } public String getConnectedPortWwn() { return connectedPortWwn; } public String getConnectedPortName() { return connectedPortName; } public Port getConnectedPort() { return connectedPort; } /** * Indicates if the connection is a direct connection to a fabric port. * * @return {@code false} if there is no connected port or if the connected port is a generated port * or if the connection is via a proxy device; {@code true} otherwise * */ public boolean isDirectConnection() { return isDirectConnection; } /** * Gets the switch port of a port pair. This is typically an F-port or G-port. * * @param leftPort of pair * @param rightPort of pair * @return leftPort or rightPort, whichever is a switch port; if neither is definitely a switch port, * rightPort is returned; if both are switch ports, leftPort is returned */ public static Port getSwitchPort(Port leftPort, Port rightPort) { return isSwitchPort(leftPort)? leftPort : rightPort; } /** * Gets the node (non-switch) port of a port pair. This is typically an N-port or NP-port. * * @param leftPort of pair * @param rightPort of pair * @return leftPort or rightPort, whichever is a node port; if neither is definitely a node port, * leftPort is returned; if both are node ports, rightPort is returned */ public static Port getNodePort(Port leftPort, Port rightPort) { return isNodePort(rightPort)? rightPort : leftPort; } private static boolean isSwitchPort (Port port) { return port != null && port.getDeviceType() == PortContainerType.SWITCH; } private static boolean isNodePort (Port port) { return port != null && port.isNodePort(); } }