Search in sources :

Example 1 with ZoneMember

use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.

the class NetworkDeviceController method getZonesets.

@Override
public List<Zoneset> getZonesets(URI uri, String fabricId, String fabricWwn, String zoneName, boolean excludeMembers, boolean excludeAliases) 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.getZonesetsFailedNull(device.getSystemType());
    }
    try {
        List<Zoneset> zonesets = networkDevice.getZonesets(device, fabricId, fabricWwn, zoneName, excludeMembers, excludeAliases);
        // Object pointers, so remove them here!
        for (Zoneset zs : zonesets) {
            zs.setCimObjectPath(null);
            for (Zone zo : zs.getZones()) {
                zo.setCimObjectPath(null);
                for (ZoneMember zm : zo.getMembers()) {
                    zm.setCimObjectPath(null);
                }
            }
        }
        return zonesets;
    } catch (Exception ex) {
        Date date = new Date();
        throw NetworkDeviceControllerException.exceptions.getZonesetsFailedExc(uri.toString(), date.toString(), ex);
    }
}
Also used : Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) Zoneset(com.emc.storageos.networkcontroller.impl.mds.Zoneset) 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 2 with ZoneMember

use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.

the class NetworkDeviceController method addRemoveZones.

/**
 * Add/remove a group of zones as given by their NetworkFabricInfo structures.
 * ALL fabricInfos must be using the same NetworkDevice, and the same fabricId. There is a higher level
 * subroutine to split complex requests into sets of requests with the same NetworkDevice and fabricId.
 *
 * @param networkSystem NetworkDevice
 * @param fabricId String
 * @param exportGroupUri The ExportGroup URI. Used for reference counting.
 * @param fabricInfos - Describe each zone.
 * @param activateZones - activate active zoneset after zones change
 * @param retryAltNetworkDevice - a boolean to indicate if re-try to be done.
 *            This is to stop this function from running again after the alternate
 *            system is retried once.
 * @return BiosCommandResult
 * @throws ControllerException
 */
private BiosCommandResult addRemoveZones(NetworkSystem networkSystem, String fabricId, String fabricWwn, URI exportGroupUri, List<NetworkFCZoneInfo> fabricInfos, boolean doRemove, boolean retryAltNetworkDevice) throws ControllerException {
    BiosCommandResult result = null;
    String taskId = UUID.randomUUID().toString();
    List<Zone> zones = new ArrayList<Zone>();
    // Make the zone operations. Don't make the same zone more than once,
    // as determined by its key. The same zone shows up multiple times because it
    // must be recorded for each volume in the FCZoneReference table.
    HashSet<String> keySet = new HashSet<String>();
    for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
        String key = fabricInfo.makeEndpointsKey();
        if (false == keySet.contains(key)) {
            keySet.add(key);
            // neither create nor delete zones found on the switch
            if (fabricInfo.isExistingZone()) {
                _log.info("Zone {} will not be created or removed on {}, as it is not vipr created. ", fabricInfo.getZoneName(), fabricInfo.toString());
                // neither create nor delete zones found on the switch
                continue;
            }
            // Don't actually remove the zone if it's not the last reference
            if (doRemove && !fabricInfo._isLastReference) {
                _log.info("Zone {} will not be removed on {}, as still the zone is used to expose other volumes in export groups ", fabricInfo.getZoneName(), fabricInfo.toString());
                continue;
            }
            Zone zone = new Zone(fabricInfo.getZoneName());
            for (String address : fabricInfo.getEndPoints()) {
                ZoneMember member = new ZoneMember(address, ConnectivityMemberType.WWPN);
                zone.getMembers().add(member);
            }
            zones.add(zone);
        }
    }
    // Get the network device reference for the type of network device managed
    // by the controller.
    NetworkSystemDevice networkDevice = getDevice(networkSystem.getSystemType());
    if (networkDevice == null) {
        throw NetworkDeviceControllerException.exceptions.addRemoveZonesFailedNull(networkSystem.getSystemType());
    }
    // Lock to prevent concurrent operations on the same VSAN / FABRIC.
    InterProcessLock fabricLock = NetworkFabricLocker.lockFabric(fabricId, _coordinator);
    try {
        if (doRemove) {
            /* Removing zones */
            result = networkDevice.removeZones(networkSystem, zones, fabricId, fabricWwn, true);
            if (result.isCommandSuccess()) {
                for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
                    String refKey = fabricInfo.getZoneName() + " " + fabricInfo.getFcZoneReferenceId().toString();
                    try {
                        FCZoneReference ref = deleteFCZoneReference(fabricInfo);
                        if (ref != null && !zones.isEmpty()) {
                            recordZoneEvent(ref, OperationTypeEnum.REMOVE_SAN_ZONE.name(), OperationTypeEnum.REMOVE_SAN_ZONE.getDescription());
                        }
                    } catch (DatabaseException ex) {
                        _log.error("Could not delete FCZoneReference: " + refKey);
                    }
                }
            }
        } else {
            /* Adding zones */
            _log.debug("Adding zones on network system {} ", networkSystem.getNativeGuid());
            result = networkDevice.addZones(networkSystem, zones, fabricId, fabricWwn, true);
            if (result.isCommandSuccess()) {
                for (NetworkFCZoneInfo fabricInfo : fabricInfos) {
                    String refKey = fabricInfo.getZoneName() + " " + fabricInfo.getVolumeId().toString();
                    try {
                        String[] newOrExisting = new String[1];
                        FCZoneReference ref = addZoneReference(exportGroupUri, fabricInfo, newOrExisting);
                        // this is needed for rollback
                        fabricInfo.setFcZoneReferenceId(ref.getId());
                        _log.info(String.format("%s FCZoneReference key: %s volume %s group %s", newOrExisting[0], ref.getPwwnKey(), ref.getVolumeUri(), exportGroupUri));
                        if (!zones.isEmpty()) {
                            recordZoneEvent(ref, OperationTypeEnum.ADD_SAN_ZONE.name(), OperationTypeEnum.ADD_SAN_ZONE.getDescription());
                        }
                    } catch (DatabaseException ex) {
                        _log.error("Could not persist FCZoneReference: " + refKey);
                    }
                }
            }
        }
        // Update the FCZoneInfo structures if we changed device state for rollback.
        Map<String, String> map = (Map<String, String>) result.getObjectList().get(0);
        for (NetworkFCZoneInfo info : fabricInfos) {
            if (NetworkSystemDevice.SUCCESS.equals(map.get(info.getZoneName()))) {
                info.setCanBeRolledBack(true);
            } else {
                info.setCanBeRolledBack(false);
            }
        }
        if (!result.isCommandSuccess()) {
            ServiceError serviceError = NetworkDeviceControllerException.errors.addRemoveZonesFailed(networkSystem.getSystemType());
            setStatus(ExportGroup.class, exportGroupUri, taskId, false, serviceError);
        } else {
            setStatus(ExportGroup.class, exportGroupUri, taskId, true, null);
        }
        return result;
    } catch (ControllerException ex) {
        String operation = doRemove ? "Remove Zones" : "Add Zones";
        _log.info(String.format("waiting for 2 min before retrying %s with alternate device", operation));
        try {
            Thread.sleep(1000 * 120);
        } catch (InterruptedException e) {
            _log.warn("Thread sleep interrupted.  Allowing to continue without sleep");
        }
        NetworkFCZoneInfo fabricInfo = fabricInfos.get(0);
        URI primaryUri = fabricInfo.getNetworkDeviceId();
        URI altUri = fabricInfo.getAltNetworkDeviceId();
        // If we took an error, attempt a retry with an alternate device if possible.
        if (altUri != null && retryAltNetworkDevice) {
            NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
            fabricLock = null;
            _log.error("Zone operation failed using device: " + primaryUri + " retrying with alternate device: " + altUri);
            fabricInfo.setNetworkDeviceId(altUri);
            networkSystem = getNetworkSystemObject(altUri);
            return addRemoveZones(networkSystem, fabricId, fabricWwn, exportGroupUri, fabricInfos, doRemove, false);
        } else {
            if (result != null) {
                if (!result.isCommandSuccess()) {
                    ServiceError serviceError = NetworkDeviceControllerException.errors.addRemoveZonesFailed(networkSystem.getSystemType());
                    setStatus(ExportGroup.class, exportGroupUri, taskId, false, serviceError);
                } else {
                    setStatus(ExportGroup.class, exportGroupUri, taskId, true, null);
                }
            }
            throw ex;
        }
    } finally {
        NetworkFabricLocker.unlockFabric(fabricId, fabricLock);
    }
}
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) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) 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) HashSet(java.util.HashSet)

Example 3 with ZoneMember

use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember 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 4 with ZoneMember

use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.

the class NetworkSystemDeviceImpl method sameMembers.

/**
 * Check if 2 zones has the same members
 *
 * @param zoneInFabric
 * @param zone
 * @return true if both zone has the same wwn and alias members
 */
protected boolean sameMembers(Zone zoneInFabric, Zone zone) {
    boolean same = true;
    if (zoneInFabric.getMembers().size() == zone.getMembers().size()) {
        Collection<String> wwnsInFabric = getWwnsInZone(zoneInFabric);
        Collection<String> aliasesInFabric = getAliasesInZone(zoneInFabric);
        for (ZoneMember member : zone.getMembers()) {
            if (!StringUtils.isEmpty(member.getAddress()) && !wwnsInFabric.contains(member.getAddress())) {
                _log.info("Zone member WWN {} not found in active zone {}", member.getAddress(), zone.getName());
                same = false;
                break;
            } else if (!StringUtils.isEmpty(member.getAlias()) && !aliasesInFabric.contains(member.getAlias())) {
                _log.info("Zone member alias {} not found in active zone {}", member.getAlias(), zone.getName());
                same = false;
                break;
            }
        }
    } else {
        same = false;
    }
    // if zones do not have same info, log their info for debugging.
    if (!same) {
        _log.info("Zones {} and {} do not have the same info", zoneInFabric.getName(), zone.getName());
        _log.info("Zone {} has {} members in fabric.", zoneInFabric.getName(), zoneInFabric.getMembers().size());
        _log.info("and intended zone {} has {} members.", zone.getName(), zone.getMembers().size());
        zoneInFabric.print();
        zone.print();
    }
    return same;
}
Also used : ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember)

Example 5 with ZoneMember

use of com.emc.storageos.networkcontroller.impl.mds.ZoneMember in project coprhd-controller by CoprHD.

the class NetworkSystemDeviceImpl method getZonesToBeAdded.

/**
 * Given a list of zones requested to be added, and a list of existing zones on
 * the device, return a list of zones that should really be added.
 * Zones which already exist will not be added again (if they match by content and
 * name). Zones with match members but have a different name (and are therefore
 * assumed to be externally created) are ignored.
 *
 * @param zones -- Zones requested to be created.
 * @param existingZones -- Existing zones on the device.
 * @return -- Zones to be added
 * @throws NetworkDeviceControllerException
 */
protected List<Zone> getZonesToBeAdded(List<Zone> zones, List<Zone> existingZones) throws NetworkDeviceControllerException {
    // Now, we want to add only new zones.
    // Zones that have members completely in a zone in the active zoneset already are
    // ignored, if they match the zoneset name we have.
    // Make an array of sets containing the members of the active zones.
    // The next paragraph below checks each zone to be created against each existing zone and looks for matches.
    // key is an existing zone name
    Map<String, Set<String>> memberSetMap = new HashMap<String, Set<String>>();
    for (Zone azone : existingZones) {
        Set<String> memberAddressSet = new HashSet<String>();
        for (ZoneMember amember : azone.getMembers()) {
            if (amember.getAddress() != null) {
                memberAddressSet.add(amember.getAddress());
            }
            if (amember.getAlias() != null) {
                memberAddressSet.add(amember.getAlias());
            }
        }
        memberSetMap.put(azone.getName(), memberAddressSet);
    }
    // Check each zone to be added to see if it's matched by an active set.
    List<Zone> zonesToBeAdded = new ArrayList<Zone>();
    for (Zone zone : zones) {
        boolean addIt = true;
        for (String azoneName : memberSetMap.keySet()) {
            Set<String> activeSet = memberSetMap.get(azoneName);
            boolean match = true;
            for (ZoneMember member : zone.getMembers()) {
                if ((member.getAddress() != null && !WWNUtility.isValidWWN(member.getAddress())) || (member.getAlias() != null && !WWNUtility.isValidWWNAlias(member.getAlias()))) {
                    throw NetworkDeviceControllerException.exceptions.getZonesToBeAddedFailedIllegalAddress(member.getAddress());
                }
                if ((member.getAddress() != null && !activeSet.contains(member.getAddress())) || (member.getAlias() != null && !activeSet.contains(member.getAlias()))) {
                    match = false;
                }
            }
            if (match == true) {
                // Check to see if it's the same zone name that we wanted. Otherwise, log a duplicate zone.
                if (azoneName.equals(zone.getName())) {
                    addIt = false;
                } else {
                    _log.info("Found duplicate zone: " + azoneName + " for: " + zone.getName() + " ... ignoring");
                }
            }
        }
        if (addIt) {
            zonesToBeAdded.add(zone);
        }
    }
    return zonesToBeAdded;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) ArrayList(java.util.ArrayList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) HashSet(java.util.HashSet)

Aggregations

ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)21 Zone (com.emc.storageos.networkcontroller.impl.mds.Zone)13 ArrayList (java.util.ArrayList)11 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)8 HashMap (java.util.HashMap)5 MapNetworkSystem (com.emc.storageos.api.mapper.functions.MapNetworkSystem)4 FCZoneReference (com.emc.storageos.db.client.model.FCZoneReference)4 NetworkController (com.emc.storageos.networkcontroller.NetworkController)4 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Operation (com.emc.storageos.db.client.model.Operation)3 StringMap (com.emc.storageos.db.client.model.StringMap)3 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 SanZone (com.emc.storageos.model.network.SanZone)3 ControllerException (com.emc.storageos.volumecontroller.ControllerException)3 HashSet (java.util.HashSet)3