Search in sources :

Example 11 with NetworkSystem

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

the class NetworkDeviceController method addSanZones.

@Override
public void addSanZones(URI uri, String fabricId, String fabricWwn, List<Zone> zones, boolean activateZones, 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.addSanZonesFailedNull(device.getSystemType());
        }
        BiosCommandResult result = networkDevice.addZones(device, zones, fabricId, fabricWwn, activateZones);
        setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
        _auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.ADD_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.addSanZonesFailedExc(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 12 with NetworkSystem

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

the class NetworkDiscoveryWorker method updatePhysicalInventory.

/**
 * Update the network system physical inventory and creates/updates the discovered FC transport
 * zones as needed. The physical inventory is primarily the FCEndpoints (FCPortConnections),
 * which contains a record for each endpoint logged into the Fiber Channel Nameserver database.
 * The endpoints per fabric (vsan) constitute an FC transport zone which get created/updated
 * based on the FCEndpoints discovered.
 *
 * @param uri - Device URI
 */
public void updatePhysicalInventory(URI uri) throws ControllerException {
    // Retrieve the storage device info from the database.
    long start = System.currentTimeMillis();
    NetworkSystem networkDev = getDeviceObject(uri);
    String msg = "unknown status";
    NetworkSystemDevice networkDevice = getDevice();
    if (networkDevice == null) {
        throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedNull(uri.toString(), networkDev.getSystemType());
    }
    try {
        // === Reconcile the FCEndpoints of this device ===
        List<FCEndpoint> currentConnections = new ArrayList<FCEndpoint>();
        // IN/OUT parameter to get the routed endpoints map - Fabric-WWN-to-endpoints-WWN
        Map<String, Set<String>> routedEndpoints = new HashMap<String, Set<String>>();
        try {
            currentConnections = networkDevice.getPortConnections(networkDev, routedEndpoints);
            msg = MessageFormat.format("Retrieved {0} connections from device {1} at {2}", new Integer(currentConnections.size()), uri, new Date());
            _log.info(msg);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed getting port connections for Network System : {0}", uri.toString());
            throw (e);
        }
        try {
            reconcileFCEndpoints(networkDev, currentConnections);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed reconciling FC endpoints for Network System : {0}", uri.toString());
            throw (e);
        }
        // ==== Reconcile the discovered transport zones ======
        try {
            reconcileTransportZones(networkDev, routedEndpoints);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed reconciling networks for Network System : {0}", uri.toString());
            throw (e);
        }
        try {
            networkDev.setUptime(networkDevice.getUptime(networkDev));
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed setting version/uptime for Network System : {0}", uri.toString());
            throw (e);
        }
        // discovery succeeds
        msg = MessageFormat.format("Discovery completed successfully for Network System : {0}", uri.toString());
    } catch (Exception ex) {
        Date date = new Date();
        throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedExc(uri.toString(), date.toString(), ex);
    } finally {
        if (networkDev != null) {
            try {
                // set detailed message
                networkDev.setLastDiscoveryStatusMessage(msg);
                dbClient.updateObject(networkDev);
                _log.info("Discovery took {}", (System.currentTimeMillis() - start));
            } catch (DatabaseException ex) {
                _log.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) ArrayList(java.util.ArrayList) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) Date(java.util.Date) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 13 with NetworkSystem

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

the class NetworkScheduler method getZoningNetworkSystems.

/**
 * Finds all the network systems that have access to the initiators and '
 * storage port networks. When the initiators and storage port are in
 * different networks that are routed to each other, the assumption is that
 * there should exist and network system that can be used to managed both
 * networks.
 *
 * @param iniNetwork the initiator network
 * @param portNetwork the storage port network
 * @return the network systems that can be used to managed the port and initiator
 *         networks.
 */
List<NetworkSystem> getZoningNetworkSystems(NetworkLite iniNetwork, NetworkLite portNetwork) {
    List<NetworkSystem> orderedNetworkSystems = new ArrayList<NetworkSystem>();
    List<NetworkSystem> hostNetworkSystems = getOrderedNetworkSystems(iniNetwork);
    List<NetworkSystem> arrayNetworkSystems = getOrderedNetworkSystems(portNetwork);
    NetworkSystem hostSwitch = null;
    if (!hostNetworkSystems.isEmpty()) {
        orderedNetworkSystems.add(hostNetworkSystems.get(0));
        hostSwitch = hostNetworkSystems.get(0);
        _log.info("Host Network System : " + hostSwitch.getNativeGuid());
    }
    if (!arrayNetworkSystems.isEmpty()) {
        for (NetworkSystem arraySwitch : arrayNetworkSystems) {
            if (!arraySwitch.getId().equals(hostSwitch.getId())) {
                orderedNetworkSystems.add(arraySwitch);
                _log.info("Array Network System: " + arraySwitch.getNativeGuid());
                break;
            }
        }
    }
    return orderedNetworkSystems;
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) ArrayList(java.util.ArrayList)

Example 14 with NetworkSystem

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

the class NetworkScheduler method getOrderedNetworkSystems.

/**
 * Finds all the network systems that have access to the specified network.
 *
 * @param network the network
 * @return the network systems that can be used to manage the specified
 *         network.
 */
private List<NetworkSystem> getOrderedNetworkSystems(NetworkLite network) {
    List<URI> netSysIds = (network == null) ? new ArrayList<URI>() : StringSetUtil.stringSetToUriList(new StringSet(network.getNetworkSystems()));
    List<NetworkSystem> idleNetworkSystems = new ArrayList<NetworkSystem>();
    List<NetworkSystem> deRegisteredNetworkSystems = new ArrayList<NetworkSystem>();
    List<NetworkSystem> orderedNetworkSystems = new ArrayList<NetworkSystem>();
    if (!netSysIds.isEmpty()) {
        orderedNetworkSystems = _dbClient.queryObject(NetworkSystem.class, netSysIds, true);
        if (!orderedNetworkSystems.isEmpty()) {
            for (NetworkSystem networkSystem : orderedNetworkSystems) {
                if (networkSystem.getRegistrationStatus().equals(RegistrationStatus.UNREGISTERED.toString())) {
                    _log.info("Network System {} is not used as it is not registered.", networkSystem.getLabel());
                    deRegisteredNetworkSystems.add(networkSystem);
                } else if (networkSystem.getDiscoveryStatus().equals(DataCollectionJobStatus.ERROR.toString()) || networkSystem.getDiscoveryStatus().equals(DataCollectionJobStatus.CREATED.toString())) {
                    _log.info("Network System {} is moved to the end of Network System list as its discovery is not successful.", networkSystem.getLabel());
                    idleNetworkSystems.add(networkSystem);
                }
            }
            orderedNetworkSystems.removeAll(deRegisteredNetworkSystems);
            orderedNetworkSystems.removeAll(idleNetworkSystems);
            Collections.shuffle(orderedNetworkSystems);
            Collections.shuffle(idleNetworkSystems);
            orderedNetworkSystems.addAll(idleNetworkSystems);
        } else {
            _log.warn("Could not find any active network systems that can be used to zone.");
        }
    } else {
        _log.warn("Could not find any network systems that can be used to zone.");
    }
    return orderedNetworkSystems;
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 15 with NetworkSystem

use of com.emc.storageos.db.client.model.NetworkSystem 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)

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