Search in sources :

Example 31 with NetworkSystem

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

the class NetworkDeviceController method getZoningMap.

/**
 * Finds all the zone paths that exists between a list of initiators and storage ports.
 *
 * @param initiators the list of initiators
 * @param portsMap a map of storage port keyed by the port WWN
 * @param initiatorWwnToZonesMap an OUT parameter used to store the zones retrieved mapped by initiator
 * @param networkSystemURI - an OUT parameter indicating the NetworkSystem's URI that found the zones
 *
 * @return a zoning map of zones that exists on the network systems
 */
public StringSetMap getZoningMap(NetworkLite network, List<Initiator> initiators, Map<String, StoragePort> portsMap, Map<String, List<Zone>> initiatorWwnToZonesMap, URI[] networkSystemURI) {
    StringSetMap map = new StringSetMap();
    StringSet initiatorWwns = new StringSet();
    for (Initiator initiator : initiators) {
        initiatorWwns.add(initiator.getInitiatorPort());
    }
    _log.info(String.format("Looking for zones from iniiators %s to targets %s", initiatorWwns, portsMap.keySet()));
    // find all the zones for the initiators as a map of initiator WWN to zones
    if (initiatorWwnToZonesMap == null) {
        initiatorWwnToZonesMap = new HashMap<String, List<Zone>>();
    }
    // of the zones retrieved from the network system, select the once
    NetworkSystem networkSystem = fetchInitiatorsZones(network, initiators, initiatorWwnToZonesMap);
    if (networkSystem != null && networkSystemURI != null) {
        networkSystemURI[0] = networkSystem.getId();
    }
    initiatorWwnToZonesMap = selectZonesForInitiatorsAndPorts(network, initiatorWwnToZonesMap, portsMap);
    // build the map object
    for (Initiator initiator : initiators) {
        StringSet set = new StringSet();
        List<Zone> zones = initiatorWwnToZonesMap.get(initiator.getInitiatorPort());
        if (zones != null) {
            for (Zone zone : zones) {
                _log.info(zone.getLogString());
                for (ZoneMember member : zone.getMembers()) {
                    if (portsMap.containsKey(member.getAddress())) {
                        // There can be multiple zones with the same initiator and port
                        // for this function, we're just finding all the mappings
                        set.add(portsMap.get(member.getAddress()).getId().toString());
                    }
                }
            }
        }
        if (set != null && !set.isEmpty()) {
            map.put(initiator.getId().toString(), set);
        }
    }
    _log.info("Found the following zone mappings {} for initiators {} and ports {}", new Object[] { map, initiatorWwnToZonesMap.keySet(), portsMap.keySet() });
    return map;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) Initiator(com.emc.storageos.db.client.model.Initiator) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) StringSet(com.emc.storageos.db.client.model.StringSet) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember)

Example 32 with NetworkSystem

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

the class NetworkDeviceController method activateSanZones.

@Override
public void activateSanZones(URI uri, String fabricId, String fabricWwn, String taskId) throws ControllerException {
    NetworkSystem device = getNetworkSystemObject(uri);
    // Lock to prevent concurrent operations on the same VSAN / FABRIC.
    InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
    try {
        // Get the file device reference for the type of file device managed
        // by the controller.
        NetworkSystemDevice networkDevice = getDevice(device.getSystemType());
        if (networkDevice == null) {
            throw NetworkDeviceControllerException.exceptions.updateSanZonesFailedNull(device.getSystemType());
        }
        BiosCommandResult result = networkDevice.activateZones(device, fabricId, fabricWwn);
        ServiceError serviceError = NetworkDeviceControllerException.errors.activateSanZonesFailed(uri.toString(), device.getSystemType());
        setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), serviceError);
        _auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.ACTIVATE_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL());
    } catch (Exception ex) {
        ServiceError serviceError = NetworkDeviceControllerException.errors.activateSanZonesFailedExc(device.getSystemType(), ex);
        _dbClient.error(NetworkSystem.class, device.getId(), taskId, serviceError);
    } finally {
        NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 33 with NetworkSystem

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

the class NetworkDeviceController method fetchInitiatorsInNetworkZoneInfoMap.

/**
 * For the given network and initiators, which are in the network,
 * and a given list of storage ports, find all the zones on the network
 * system for the initiators. Search the zones to find ones that have
 * one or more of the ports and create the zoning map between the
 * initiators and ports. Returns the results as {@link ZoneInfoMap} which is map
 * of initiator port WWN and storage port WWN keyed by zone-key, where zone-key
 * is the concatenation of the initiator port WWN and the storage port WWN.
 * <p>
 * Note that the map returned contains only the zones that were selected for use by ViPR. In the case of duplicate zones between an
 * initiator-port pair, ViPR applies a selection criteria to choose one. See {@link #selectZonesForInitiatorsAndPorts}
 * <p>
 * Note that a zone in the network system can have more than one initiator and one storage port. For such zone, there can be multiple
 * entries in the map, one for each initiator/port pairs.
 * <p>
 * If the initiator is not in a network or no zones could be found for the initiator, there will be no entries for this initiator in the
 * map. An empty map will be returned if no zones could be found for any initiator.
 *
 * @param network the network of the initiators
 * @param map an OUT parameter where ZoneInfoMap is stored
 * @param initiators the initiators for which the zones will be read
 * @param initiatorPortsMap the storage ports of interest in the networks.
 * @return the network system used to read the zones
 */
private NetworkSystem fetchInitiatorsInNetworkZoneInfoMap(NetworkLite network, ZoneInfoMap map, List<Initiator> initiators, Map<String, StoragePort> initiatorPortsMap) {
    Map<String, Initiator> wwnToInitiatorMap = wwnToInitiatorMap(initiators);
    // retrieve the zones
    Map<String, List<Zone>> wwnToZones = new HashMap<String, List<Zone>>();
    NetworkSystem networkSystem = fetchInitiatorsZones(network, initiators, wwnToZones);
    wwnToZones = selectZonesForInitiatorsAndPorts(network, wwnToZones, initiatorPortsMap);
    // if we successfully retrieved the zones
    if (networkSystem != null && !wwnToZones.isEmpty()) {
        ZoneInfo info = null;
        Initiator initiator = null;
        for (Map.Entry<String, List<Zone>> entry : wwnToZones.entrySet()) {
            initiator = wwnToInitiatorMap.get(entry.getKey());
            for (Zone zone : entry.getValue()) {
                // I need some logic here to make sure I select the best zone
                for (ZoneMember member : zone.getMembers()) {
                    if (initiatorPortsMap.containsKey(member.getAddress())) {
                        // double check WWN formatting
                        StoragePort port = initiatorPortsMap.get(member.getAddress());
                        info = new ZoneInfo();
                        info.setZoneName(zone.getName());
                        info.setInitiatorWwn(initiator.getInitiatorPort());
                        info.setInitiatorId(initiator.getId().toString());
                        info.setPortWwn(port.getPortNetworkId());
                        info.setPortId(port.getId().toString());
                        info.setNetworkId(network.getId().toString());
                        info.setNetworkWwn(NetworkUtil.getNetworkWwn(network));
                        info.setFabricId(network.getNativeId());
                        info.setNetworkSystemId(networkSystem.getId().toString());
                        info.setMemberCount(zone.getMembers().size());
                        map.put(info.getZoneReferenceKey(), info);
                    }
                }
            }
        }
    }
    return networkSystem;
}
Also used : HashMap(java.util.HashMap) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) StoragePort(com.emc.storageos.db.client.model.StoragePort) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo)

Example 34 with NetworkSystem

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

the class NetworkDeviceController method deleteNetworkSystem.

@Override
public void deleteNetworkSystem(URI network, String taskId) throws ControllerException {
    try {
        NetworkSystem networkDevice = getNetworkSystemObject(network);
        URIQueryResultList epUriList = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(network), epUriList);
        while (epUriList.iterator().hasNext()) {
            FCEndpoint connection = _dbClient.queryObject(FCEndpoint.class, epUriList.iterator().next());
            if (connection != null) {
                _dbClient.removeObject(connection);
            }
        }
        List<URI> tzUriList = _dbClient.queryByType(Network.class, true);
        NetworkDiscoveryWorker worker = new NetworkDiscoveryWorker(getDevice(networkDevice.getSystemType()), _dbClient);
        worker.setCoordinator(_coordinator);
        for (URI tzUri : tzUriList) {
            Network tz = _dbClient.queryObject(Network.class, tzUri);
            if (tz != null && (tz.getNetworkSystems() != null && tz.getNetworkSystems().contains(network.toString()))) {
                worker.removeNetworkSystemTransportZone(tz, network.toString());
            }
        }
        if (taskId != null) {
            _dbClient.ready(NetworkSystem.class, network, taskId);
            _auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.DELETE_NETWORK_SYSTEM, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, networkDevice.getId().toString(), networkDevice.getLabel(), networkDevice.getPortNumber(), networkDevice.getUsername(), networkDevice.getSmisProviderIP(), networkDevice.getSmisPortNumber(), networkDevice.getSmisUserName(), networkDevice.getSmisUseSSL());
        }
    } catch (Exception ex) {
        String msg = MessageFormat.format("Exception encountered while removing FC Port Connection for {0} because: {1}", network, ex.getLocalizedMessage());
        _log.error(msg);
        if (taskId != null) {
            try {
                ServiceError serviceError = NetworkDeviceControllerException.errors.deleteNetworkSystemFailed(network.toString(), ex);
                _dbClient.error(NetworkSystem.class, network, taskId, serviceError);
            } catch (DatabaseException e) {
                _log.error(e.getMessage());
            }
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Network(com.emc.storageos.db.client.model.Network) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 35 with NetworkSystem

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

the class NetworkDeviceController method doConnect.

private BiosCommandResult doConnect(URI network) throws ControllerException {
    // Retrieve the storage device info from the database.
    NetworkSystem networkObj = getNetworkSystemObject(network);
    // Verify non-null network device returned from the database client.
    // Will not return null
    // Get the file device reference for the type of file device managed
    // by the controller.
    NetworkSystemDevice networkDevice = getDevice(networkObj.getSystemType());
    if (networkDevice == null) {
        throw NetworkDeviceControllerException.exceptions.doConnectFailed(network.toString(), networkObj.getSystemType());
    }
    return networkDevice.doConnect(networkObj);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem)

Aggregations

NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)54 MapNetworkSystem (com.emc.storageos.api.mapper.functions.MapNetworkSystem)21 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)20 Produces (javax.ws.rs.Produces)20 ArrayList (java.util.ArrayList)19 Path (javax.ws.rs.Path)18 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)16 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)16 ControllerException (com.emc.storageos.volumecontroller.ControllerException)16 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)13 URI (java.net.URI)13 NetworkController (com.emc.storageos.networkcontroller.NetworkController)11 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)10 Consumes (javax.ws.rs.Consumes)10 POST (javax.ws.rs.POST)10 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 Operation (com.emc.storageos.db.client.model.Operation)8 ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)8 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7