Search in sources :

Example 6 with NetworkSystem

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

the class NetworkDeviceController method removeSanZones.

@Override
public void removeSanZones(URI uri, String fabricId, String fabricWwn, List<Zone> zones, boolean activateZones, String taskId) throws ControllerException {
    NetworkSystem networkSytem = getNetworkSystemObject(uri);
    // Lock to prevent concurrent operations on the same VSAN / FABRIC.
    InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
    try {
        // Get the network system reference for the type of network system managed
        // by the controller.
        NetworkSystemDevice networkDevice = getDevice(networkSytem.getSystemType());
        if (networkDevice == null) {
            throw NetworkDeviceControllerException.exceptions.removeSanZonesFailedNull(networkSytem.getSystemType());
        }
        BiosCommandResult result = networkDevice.removeZones(networkSytem, zones, fabricId, fabricWwn, activateZones);
        setStatus(NetworkSystem.class, networkSytem.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
        _auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.REMOVE_SAN_ZONE, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, networkSytem.getId().toString(), networkSytem.getLabel(), networkSytem.getPortNumber(), networkSytem.getUsername(), networkSytem.getSmisProviderIP(), networkSytem.getSmisPortNumber(), networkSytem.getSmisUserName(), networkSytem.getSmisUseSSL());
    } catch (Exception ex) {
        ServiceError serviceError = NetworkDeviceControllerException.errors.removeSanZonesFailedExc(networkSytem.getSystemType(), ex);
        _dbClient.error(NetworkSystem.class, networkSytem.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 7 with NetworkSystem

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

the class NetworkDeviceController method getFabricIds.

@Override
public List<String> getFabricIds(URI uri) throws ControllerException {
    NetworkSystem device = getNetworkSystemObject(uri);
    // 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.getFabricIdsFailedNull(device.getSystemType());
    }
    try {
        List<String> fabricIds = networkDevice.getFabricIds(device);
        return fabricIds;
    } catch (Exception ex) {
        Date date = new Date();
        throw NetworkDeviceControllerException.exceptions.getFabricIdsFailedExc(uri.toString(), date.toString(), ex);
    }
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) 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) Date(java.util.Date)

Example 8 with NetworkSystem

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

the class NetworkDeviceController method fetchInitiatorsZones.

/**
 * For the given network and initiators, which are in the network,
 * use one of the network's network system to get the zones and populate
 * wwnToZones map with the zones found. Return the network system
 * used to get the zones.
 * <p>
 * This function is created because to create the ZoneInfoMap of {@link #getInitiatorsInNetworkZoneInfoMap(NetworkLite, List, Map)},
 * both the network system used and the zones are needed, while for {@link #getInitiatorsInNetworkZones(NetworkLite, List)} only the
 * zones are needed. This solution was to support both calling functions.
 * <p>
 * Note if a zone is found that has more than one of the initiator, the zone will be returned once for each initiator.
 *
 * @param network the network of the initiators
 * @param initiators the initiators
 * @param wwnToZones a IN/OUT parameters which is a map to be populated
 *            with the zone mappings found
 * @return the network system used to get the zones.
 */
private NetworkSystem fetchInitiatorsZones(NetworkLite network, List<Initiator> initiators, Map<String, List<Zone>> wwnToZones) {
    // Check some network systems are discovered.
    if (!NetworkUtil.areNetworkSystemDiscovered(_dbClient)) {
        return null;
    }
    if (!Transport.FC.toString().equals(network.getTransportType())) {
        return null;
    }
    if (initiators == null || initiators.isEmpty()) {
        return null;
    }
    // Select the network system to use
    NetworkSystem networkSystem = null;
    Map<String, Initiator> wwnToInitiatorMap = wwnToInitiatorMap(initiators);
    List<NetworkSystem> zoningNetworkSystems = _networkScheduler.getZoningNetworkSystems(network, null);
    Iterator<NetworkSystem> itr = zoningNetworkSystems.iterator();
    while (itr.hasNext()) {
        networkSystem = itr.next();
        try {
            if (networkSystem != null) {
                _log.info("Trying network system {} for network {} to get initiator zones.", networkSystem.getLabel(), network.getLabel());
                wwnToZones.putAll(getDevice(networkSystem.getSystemType()).getEndpointsZones(networkSystem, NetworkUtil.getNetworkWwn(network), network.getNativeId(), wwnToInitiatorMap.keySet()));
                // if we get here, we were successful at getting the zones, do not try any more network systems
                break;
            }
        } catch (Exception ex) {
            // if we hit and exception, log it and try the next network system;
            wwnToZones.clear();
            _log.error("Failed to get the zones for initiators {} in network {} " + "using network system {}. Will try the other available network systems", new Object[] { wwnToInitiatorMap.keySet(), network.getLabel(), networkSystem == null ? "null" : networkSystem.getLabel() });
        }
        networkSystem = null;
    }
    if (networkSystem == null) {
        _log.error("Failed to find a registered network system in good discovery status to discover the zones");
        throw NetworkDeviceControllerException.exceptions.failedToFindNetworkSystem(wwnToInitiatorMap.keySet(), network.getLabel());
    }
    return networkSystem;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) 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 9 with NetworkSystem

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

the class NetworkDeviceController method removeZone.

/**
 * Remove a zone.
 *
 * @param volUri URI of the Volume
 * @param fabricInfo NetworkFabricInfo generated by NetworkScheduler
 * @return BiosCommandResult
 */
public BiosCommandResult removeZone(URI volUri, NetworkFCZoneInfo fabricInfo, boolean activateZones) throws ControllerException {
    ServiceError serviceError = NetworkDeviceControllerException.errors.zoningFailedArgs(volUri.toString());
    BiosCommandResult result = BiosCommandResult.createErrorResult(serviceError);
    List<Zone> zones = new ArrayList<Zone>();
    Zone zone = new Zone(fabricInfo.getZoneName());
    zones.add(zone);
    String taskId = UUID.randomUUID().toString();
    for (String address : fabricInfo.getEndPoints()) {
        ZoneMember member = new ZoneMember(address, ConnectivityMemberType.WWPN);
        zone.getMembers().add(member);
    }
    // Lock to prevent concurrent operations on the same VSAN / FABRIC.
    InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricInfo.getFabricId(), _coordinator);
    try {
        NetworkSystem device = getNetworkSystemObject(fabricInfo.getNetworkDeviceId());
        // 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.removeZoneFailedNull(device.getSystemType());
        }
        if (fabricInfo.isLastReference() == true && !fabricInfo.isExistingZone()) {
            result = networkDevice.removeZones(device, zones, fabricInfo.getFabricId(), fabricInfo.getFabricWwn(), activateZones);
        } else {
            // This is not the last reference, just mark our FCZoneReference for deletion
            result = BiosCommandResult.createSuccessfulResult();
        }
        if (result.isCommandSuccess()) {
            if (fabricInfo.getFcZoneReferenceId() != null) {
                try {
                    // Mark our FcZoneReference object for removal
                    FCZoneReference reference = _dbClient.queryObject(FCZoneReference.class, fabricInfo.getFcZoneReferenceId());
                    if (reference != null) {
                        _dbClient.markForDeletion(reference);
                        recordZoneEvent(reference, OperationTypeEnum.REMOVE_SAN_ZONE.name(), OperationTypeEnum.REMOVE_SAN_ZONE.getDescription());
                    }
                } catch (Exception ex) {
                    _log.error("Can't mark object for removal: " + fabricInfo.getFcZoneReferenceId());
                }
            }
        }
        if (!result.isCommandSuccess()) {
            ServiceError svcError = NetworkDeviceControllerException.errors.removeZoneFailed(volUri.toString(), device.getSystemType());
            setStatus(Volume.class, volUri, taskId, false, svcError);
        } else {
            setStatus(Volume.class, volUri, taskId, true, null);
        }
    } catch (ControllerException ex) {
        _log.info("waiting for 2 min before retrying removeZone with alternate device");
        try {
            Thread.sleep(1000 * 120);
        } catch (InterruptedException e) {
            _log.warn("Thread sleep interrupted.  Allowing to continue without sleep");
        }
        URI primaryUri = fabricInfo.getNetworkDeviceId();
        URI altUri = fabricInfo.getAltNetworkDeviceId();
        if (altUri != null && altUri != primaryUri) {
            NetworkFabricLocker.unlockFabric(fabricInfo.getFabricId(), fabricLock);
            fabricLock = null;
            _log.error("Remove Zone failed using device: " + primaryUri + " retrying with alternate device: " + altUri);
            fabricInfo.setNetworkDeviceId(altUri);
            return removeZone(volUri, fabricInfo, activateZones);
        } else {
            ServiceError svcError = NetworkDeviceControllerException.errors.removeZoneFailedExc(volUri.toString());
            setStatus(Volume.class, volUri, taskId, false, svcError);
            throw ex;
        }
    } finally {
        NetworkFabricLocker.unlockFabric(fabricInfo.getFabricId(), fabricLock);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) ArrayList(java.util.ArrayList) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) URI(java.net.URI) 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) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) Volume(com.emc.storageos.db.client.model.Volume) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock)

Example 10 with NetworkSystem

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

the class NetworkDeviceController method updateSanZones.

@Override
public void updateSanZones(URI uri, String fabricId, String fabricWwn, List<ZoneUpdate> 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.updateSanZonesFailedNull(device.getSystemType());
        }
        BiosCommandResult result = networkDevice.updateZones(device, zones, fabricId, fabricWwn, activateZones);
        setStatus(NetworkSystem.class, device.getId(), taskId, result.isCommandSuccess(), result.getServiceCoded());
        _auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE, OperationTypeEnum.UPDATE_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.updateSanZonesFailedExc(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)

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