Search in sources :

Example 1 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class RPDeviceController method getInitiatorNetwork.

/**
 * Check if initiator being added to export-group is good.
 *
 * @param exportGroup
 * @param initiator
 * @throws InternalException
 */
private URI getInitiatorNetwork(ExportGroup exportGroup, Initiator initiator) throws InternalException {
    _log.info(String.format("Export(%s), Initiator: p(%s), port(%s)", exportGroup.getLabel(), initiator.getProtocol(), initiator.getInitiatorPort()));
    NetworkLite net = BlockStorageScheduler.lookupNetworkLite(_dbClient, StorageProtocol.block2Transport(initiator.getProtocol()), initiator.getInitiatorPort());
    // can't use it.
    if (net == null || RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(net.getRegistrationStatus())) {
        return null;
    }
    return net.getId();
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite)

Example 2 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class NetworkAssociationHelper method getNetworkConnectedStoragePorts.

public static List<StoragePort> getNetworkConnectedStoragePorts(String networkUri, DbClient dbClient) {
    List<StoragePort> ports = getNetworkStoragePorts(networkUri, null, dbClient);
    NetworkLite lite = NetworkUtil.getNetworkLite(URI.create(networkUri), dbClient);
    if (lite.getRoutedNetworks() != null) {
        for (String str : lite.getRoutedNetworks()) {
            ports.addAll(getNetworkStoragePorts(str, null, dbClient));
        }
    }
    return ports;
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort)

Example 3 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class NetworkDeviceController method addRemoveZones.

/**
 * Adds/removes a bunch of zones based on their NetworkFCZoneInfo structures.
 * They are split into groups and subgroups, first by the device/networkSystem used for zoning, and then by the fabricId to be zoned.
 * Then each subgroup is processed separately.
 *
 * @param exportGroupUri
 * @param fabricInfos
 * @return BiosCommandResult
 * @throws ControllerException
 */
public BiosCommandResult addRemoveZones(URI exportGroupUri, List<NetworkFCZoneInfo> fabricInfos, boolean doRemove) throws ControllerException {
    // Group the fabric infos together based on which devices should zone them.
    Map<URI, NetworkSystem> networkSystemId2NetworkSystem = new HashMap<URI, NetworkSystem>();
    Map<URI, List<NetworkFCZoneInfo>> networkSystemId2NetworkFabricInfos = new HashMap<>();
    for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
        URI networkSystemId = fabricInfo.getNetworkDeviceId();
        URI altNetworkSystemId = fabricInfo.getAltNetworkDeviceId();
        NetworkSystem networkSystem = null;
        // Determine network system. The network system structures are cached in networkSystemId2NetworkSystem
        networkSystem = networkSystemId2NetworkSystem.get(networkSystemId);
        if (networkSystem == null) {
            networkSystem = getNetworkSystemObject(networkSystemId);
            if (networkSystem != null && networkSystem.getInactive() == false) {
                networkSystemId2NetworkSystem.put(networkSystemId, networkSystem);
            } else if (altNetworkSystemId != null) {
                networkSystem = networkSystemId2NetworkSystem.get(altNetworkSystemId);
                if (networkSystem == null) {
                    networkSystem = getNetworkSystemObject(altNetworkSystemId);
                    if (networkSystem != null && networkSystem.getInactive() == false) {
                        networkSystemId2NetworkSystem.put(altNetworkSystemId, networkSystem);
                    }
                }
            }
        }
        if (networkSystem == null) {
            throw NetworkDeviceControllerException.exceptions.addRemoveZonesFailedNoDev(networkSystemId.toString());
        }
        List<NetworkFCZoneInfo> finfos = networkSystemId2NetworkFabricInfos.get(networkSystem.getId());
        if (finfos == null) {
            finfos = new ArrayList<NetworkFCZoneInfo>();
            networkSystemId2NetworkFabricInfos.put(networkSystem.getId(), finfos);
        }
        finfos.add(fabricInfo);
    }
    // Now loop through each network system, splitting the collection of fabric infos by fabric ID/WWN.
    StringBuilder messageBuffer = new StringBuilder();
    for (URI deviceId : networkSystemId2NetworkFabricInfos.keySet()) {
        NetworkSystem device = networkSystemId2NetworkSystem.get(deviceId);
        Map<String, List<NetworkFCZoneInfo>> fabric2FabricInfos = new HashMap<String, List<NetworkFCZoneInfo>>();
        Map<String, NetworkLite> fabricId2Network = new HashMap<String, NetworkLite>();
        List<NetworkFCZoneInfo> finfos = networkSystemId2NetworkFabricInfos.get(deviceId);
        for (NetworkFCZoneInfo fabricInfo : finfos) {
            String fabricId = fabricInfo.getFabricId();
            String fabricWwn = fabricInfo.getFabricWwn();
            String key = (fabricWwn != null) ? fabricWwn : fabricId;
            updateAltDeviceid(fabricInfo, fabricId, fabricWwn, key, fabricId2Network);
            List<NetworkFCZoneInfo> singleFabricInfos = fabric2FabricInfos.get(key);
            if (singleFabricInfos == null) {
                singleFabricInfos = new ArrayList<NetworkFCZoneInfo>();
                fabric2FabricInfos.put(key, singleFabricInfos);
            }
            singleFabricInfos.add(fabricInfo);
        }
        // Now for each fabric, do the zoning.
        for (String key : fabric2FabricInfos.keySet()) {
            List<NetworkFCZoneInfo> singleFabricInfos = fabric2FabricInfos.get(key);
            String fabricId = singleFabricInfos.get(0).getFabricId();
            String fabricWwn = singleFabricInfos.get(0).getFabricWwn();
            BiosCommandResult rslt = addRemoveZones(device, fabricId, fabricWwn, exportGroupUri, singleFabricInfos, doRemove, true);
            if (messageBuffer.length() > 0) {
                messageBuffer.append("; ");
            }
            messageBuffer.append(rslt.getMessage());
        }
    }
    BiosCommandResult result = BiosCommandResult.createSuccessfulResult();
    return result;
}
Also used : HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) URI(java.net.URI) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 4 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class NetworkScheduler method placeZones.

/**
 * Select the network device and VSAN or Brocade Fabric for the host/volume zoning.
 *
 * The selection is based on the end points (initiator and storage port) and
 * the availability of a network device that has ports connections to both
 * end points. If a fabric can't be identified with both endpoints, we fall back to
 * looking for a fabric with at least the storagePort discovered.
 *
 * @param exportGroupUri Export Group URI
 * @param varrayUri Virtual Array URI
 * @param protocol String (FC for this to do anything)
 * @param initiatorPort The WWN of the initiator
 * @param storagePort The StoragePort object
 * @param hostName Used for generating the zone name.
 * @param existingZones a list of existing zones for the initiator
 * @param checkZones Flag to enable or disable zoning check on a Network System
 *
 * @return NetworkFabricInfo configured for adding zones
 */
private NetworkFCZoneInfo placeZones(URI exportGroupUri, URI varrayUri, String protocol, String initiatorPort, StoragePort storagePort, String hostName, List<Zone> existingZones, boolean checkZones) throws DeviceControllerException {
    initiatorPort = formatWWN(initiatorPort);
    String storagePortWwn = formatWWN(storagePort.getPortNetworkId());
    if (Transport.FC != StorageProtocol.block2Transport(protocol)) {
        return null;
    }
    _log.info("Placing a zone for initiator {} and port {}", initiatorPort, storagePortWwn);
    // do some validation
    NetworkLite iniNet = NetworkUtil.getEndpointNetworkLite(initiatorPort, _dbClient);
    NetworkLite portNet = getStoragePortNetwork(storagePort);
    if (iniNet == null || portNet == null || !NetworkUtil.checkInitiatorAndPortConnected(iniNet, portNet)) {
        _log.debug(String.format("Initiator %s could not be paired with port %s", initiatorPort, storagePortWwn));
        return null;
    }
    // False we will use the existing FCZoneReference info
    if (!checkZones) {
        _log.debug("Check Zones flag is false. Finding FCZoneReference for initiator {} and port {}", initiatorPort, storagePortWwn);
        // Find the FCZoneReference in ViPR for the port-initiator key and the network
        String key = FCZoneReference.makeEndpointsKey(initiatorPort, storagePortWwn);
        List<FCZoneReference> fcZoneRefs = getFCZoneReferencesForKey(key);
        FCZoneReference refTemplate = DataObjectUtils.findByProperty(fcZoneRefs, "groupUri", exportGroupUri);
        if (refTemplate != null) {
            _log.info("Already existing FCZoneReferences for initiator {} and port {} will be replicated for new volumes.", initiatorPort, storagePortWwn);
            return createZoneInfoForRef(refTemplate, null, initiatorPort, storagePortWwn, NetworkUtil.getEndpointNetworkLite(initiatorPort, _dbClient), exportGroupUri);
        } else {
            _log.info("FCZoneReferences doesnt exist for initiator {} and port {} for replication.", initiatorPort, storagePortWwn);
            return null;
        }
    } else {
        _log.debug("Check Zones flag is false. Placing a zone for initiator {} and port {}", initiatorPort, storagePortWwn);
        // If the zone already exists, just return its reference
        NetworkFCZoneInfo zoneInfo = getZoneInfoForExistingZone(iniNet, initiatorPort, storagePort.getPortNetworkId(), existingZones);
        if (zoneInfo != null) {
            zoneInfo.setExportGroup(exportGroupUri);
            _log.info("Already existing zone {} for initiator {} and port {} will be used.", new Object[] { zoneInfo.getZoneName(), initiatorPort, storagePortWwn });
            return zoneInfo;
        }
        _log.debug("Could not find an existing zone for initiator {} and port {} to use." + "A new zone will be created.", new Object[] { initiatorPort, storagePortWwn });
        // Create a the list of end points -
        List<String> endPoints = Arrays.asList(new String[] { initiatorPort, storagePortWwn });
        List<NetworkSystem> networkSystems = getZoningNetworkSystems(iniNet, portNet);
        if (networkSystems.isEmpty()) {
            _log.info(String.format("Could not find a network system with connection to storage port %s", storagePortWwn));
            throw DeviceControllerException.exceptions.cannotFindSwitchConnectionToStoragePort(storagePortWwn);
        }
        // 2. Select the network system to use
        NetworkSystem networkSystem = networkSystems.get(0);
        // 3. identify an alternate network device, if any
        _log.debug("Network system {} was selected to be the primary network system. " + "Trying to select an alternate network system.", networkSystem.getNativeGuid());
        NetworkSystem altNetworkSystem = networkSystem;
        for (NetworkSystem system : networkSystems) {
            if (altNetworkSystem != system) {
                altNetworkSystem = system;
                _log.debug("Network system {} was selected to be the alternate network system.", altNetworkSystem.getNativeGuid());
                break;
            }
        }
        // 4. create the response
        NetworkFCZoneInfo networkFabricInfo = null;
        if (networkSystem != null) {
            networkFabricInfo = new NetworkFCZoneInfo(networkSystem.getId(), iniNet.getNativeId(), NetworkUtil.getNetworkWwn(iniNet));
            networkFabricInfo.getEndPoints().addAll(endPoints);
            networkFabricInfo.setAltNetworkDeviceId(URI.create(altNetworkSystem.getId().toString()));
            networkFabricInfo.setExportGroup(exportGroupUri);
            networkFabricInfo.setCanBeRolledBack(false);
            nameZone(networkFabricInfo, networkSystem.getSystemType(), hostName, initiatorPort, storagePort, !portNet.equals(iniNet));
        }
        return networkFabricInfo;
    }
}
Also used : NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) NetworkLite(com.emc.storageos.util.NetworkLite) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 5 with NetworkLite

use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.

the class StoragePortAssociationHelper method runUpdatePortAssociationsProcess.

/**
 * This method is responsible for
 * 1. Update pools to virtual arrays & system to virtual arrays in vplex case
 * 2. Run implicit Pool Matcher
 * 3. Run RP Connectivity Process
 *
 * @param ports
 * @param remPorts
 * @param dbClient
 * @param coordinator
 * @throws IOException
 */
public static void runUpdatePortAssociationsProcess(Collection<StoragePort> ports, Collection<StoragePort> remPorts, DbClient dbClient, CoordinatorClient coordinator, List<StoragePool> pools) {
    try {
        if (null == pools) {
            pools = new ArrayList<StoragePool>();
        }
        if (null == ports) {
            ports = new ArrayList<StoragePort>();
        }
        if (null != remPorts) {
            ports.addAll(remPorts);
        }
        // for better reading, added a method to group Ports by Network
        Map<NetworkLite, List<StoragePort>> portsByNetwork = groupPortsByNetwork(ports, dbClient);
        if (!portsByNetwork.isEmpty()) {
            updatePortAssociations(ports, portsByNetwork, dbClient);
            // if any ports are associated with network, then add pools to existing list and run matching pools
            Set<URI> poolUris = getStoragePoolIds(pools);
            List<StoragePool> modifiedPools = StoragePoolAssociationHelper.getStoragePoolsFromPorts(dbClient, ports, remPorts);
            for (StoragePool pool : modifiedPools) {
                if (!poolUris.contains(pool.getId())) {
                    pools.add(pool);
                }
            }
        }
        StringBuffer errorMessage = new StringBuffer();
        // Match the VPools to the StoragePools
        ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVirtualPool(pools, dbClient, coordinator, errorMessage);
        // get all the system that were affected and update their virtual
        // arrays
        HashSet<URI> systemsToProcess = StoragePoolAssociationHelper.getStorageSytemsFromPorts(ports, remPorts);
        // Now that pools have changed varrays, we need to update RP systems
        ConnectivityUtil.updateRpSystemsConnectivity(systemsToProcess, dbClient);
    } catch (Exception e) {
        _log.error("Update Port Association process failed", e);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

NetworkLite (com.emc.storageos.util.NetworkLite)130 StoragePort (com.emc.storageos.db.client.model.StoragePort)110 URI (java.net.URI)86 ArrayList (java.util.ArrayList)85 PortAllocationContext (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)82 HashMap (java.util.HashMap)48 List (java.util.List)44 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)25 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)22 Map (java.util.Map)22 HashSet (java.util.HashSet)20 Initiator (com.emc.storageos.db.client.model.Initiator)19 StringSet (com.emc.storageos.db.client.model.StringSet)19 TreeMap (java.util.TreeMap)10 Set (java.util.Set)9 SortedMap (java.util.SortedMap)9 StringMap (com.emc.storageos.db.client.model.StringMap)7 StoragePortsAllocator (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator)6 DummyDbClient (com.emc.storageos.util.DummyDbClient)4 PortAllocatorTestContext (com.emc.storageos.volumecontroller.placement.PortAllocatorTestContext)4