Search in sources :

Example 26 with Zone

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

the class BrocadeNetworkSystemDevice method getAllZonesForZones.

/**
 * For a list of zones requested by clients, check is routing is needed and created
 * the required zone to support both use cases: switched and routed endpoints. For
 * switched endpoints the same list of zone is returned. For routed endpoints,
 * for each zone in the primary fabrics, an identical zone in the target fabrics
 * will also be created.
 *
 * @param zones the zones to be created or deleted.
 *
 * @return a map of zones to be created grouped by fabric. When the zone members
 *         are in different fabrics (i.e. routed), there will be a zone to create in each
 *         member's fabric
 */
private Map<NetworkLite, List<Zone>> getAllZonesForZones(List<Zone> zones, boolean delete, String fabricId, String fabricWwn) {
    Map<NetworkLite, List<Zone>> allZones = new HashMap<NetworkLite, List<Zone>>();
    // or two networks that are routed to each other
    for (Zone zone : zones) {
        Map<ZoneMember, NetworkLite> epNetworks = getEndpointNetworks(zone, fabricId, fabricWwn);
        if (!epNetworks.isEmpty()) {
            Set<NetworkLite> networks = new HashSet<NetworkLite>(epNetworks.values());
            if (networks.size() == 2) {
                // need to create zone for
                // ensure the other members can be routed as well
                NetworkLite network = networks.iterator().next();
                for (ZoneMember member : epNetworks.keySet()) {
                    if (network.getId().equals(epNetworks.get(member).getId()) || (network.hasRoutedNetworks(epNetworks.get(member).getId()))) {
                        _log.info("Verified zone {} endpoints are connected", zone.getName());
                    } else {
                        if (!delete) {
                            // only error on create. For delete, always try.
                            _log.info("Cannot create zone {} because the member are found to be not connected", zone.getName());
                            throw NetworkDeviceControllerException.exceptions.zoneEndpointsNotConnected(zone.getName());
                        }
                    }
                }
                // zones, the zone may not be properly named.
                if (!delete) {
                    if (zone.getName() != null && !zone.getName().toLowerCase().startsWith("lsan_")) {
                        String name = "lsan_" + (zone.getName() == null ? "" : zone.getName());
                        if (name.length() > ZONE_NAME_MAX_LENGTH) {
                            name = name.substring(0, ZONE_NAME_MAX_LENGTH - 1);
                        }
                        zone.setName(name);
                    }
                }
            }
            for (NetworkLite network : networks) {
                List<Zone> netZones = allZones.get(network);
                if (netZones == null) {
                    netZones = new ArrayList<Zone>();
                    allZones.put(network, netZones);
                }
                netZones.add(zone);
            }
        } else if (delete) {
            // if delete zone does not have member or member that are not in end point list
            // include them anyway for deletion
            NetworkLite networkLite = NetworkUtil.getNetworkLiteByFabricId(fabricId, fabricWwn, _dbClient);
            if (networkLite != null) {
                List<Zone> zoneList = allZones.get(networkLite);
                if (zoneList == null) {
                    zoneList = new ArrayList<Zone>();
                    allZones.put(networkLite, zoneList);
                }
                zoneList.add(zone);
            }
        }
    }
    return allZones;
}
Also used : HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) HashSet(java.util.HashSet)

Example 27 with Zone

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

the class BrocadeNetworkSystemDevice method checkAndUpdateZone.

/**
 * Add and remove members from/to a zone. This function will not fail if
 * a member to be removed is not in the zone or if a member that will be
 * added is already in the zone.
 * <p>
 * A member of type alias can be remove using its alias or its WWN.
 * <p>
 * If the zone already has the WWN of an alias and now the user is trying to add the alias into the zone, the alias will not be added.
 * The WWN has to be removed first.
 * <p>
 * Replacing a WWN with its alias should be possible in a single call by specifying the WWN in the remove list and alias in the add
 * list.
 * <p>
 * Note this function will delete the zone if the zone has no remaining members.
 *
 * @param client an instance of WBEMClient
 * @param zoneServiceIns an instance of ZoneService
 * @param fabricId the fabric name or vsan id
 * @param fabricWwn the fabric WWN
 * @param zonesetPath CIM path of the zoneset
 * @param zonesInFabric a map of all zones in the zoneset
 * @param zoneUpdate the changes to be made to the zone
 * @return true if the update completed successfully.
 */
private boolean checkAndUpdateZone(WBEMClient client, CIMInstance zoneServiceIns, String fabricId, String fabricWwn, CIMObjectPath zonesetPath, Map<String, Zone> zonesInFabric, ZoneUpdate zoneUpdate) {
    boolean success = false;
    ZoneMember curMember = null;
    try {
        if (zonesInFabric.containsKey(zoneUpdate.getName())) {
            _log.info("Start update zone {}", zoneUpdate.getName());
            Zone zone = zonesInFabric.get(zoneUpdate.getName());
            Map<String, ZoneMember> members = getZoneMembersMap(client, zone.getName(), (CIMObjectPath) zone.getCimObjectPath());
            // handle removed members
            if (zoneUpdate.getRemoveZones() != null) {
                for (ZoneMember remMember : zoneUpdate.getRemoveZones()) {
                    curMember = members.containsKey(remMember.getAlias()) ? members.get(remMember.getAlias()) : members.get(remMember.getAddress());
                    if (curMember != null && curMember.isAliasType() && !StringUtils.isEmpty(remMember.getAlias())) {
                        _log.info("Removing alia smember {}", remMember.getAlias());
                        _smisHelper.removeZoneOrAliasMember(client, (CIMObjectPath) curMember.getCimAliasPath(), (CIMObjectPath) zone.getCimObjectPath(), true);
                        members.remove(curMember.getAlias());
                        members.remove(curMember.getAddress());
                        success = true;
                    } else if (curMember != null && !curMember.isAliasType() && !StringUtils.isEmpty(remMember.getAddress())) {
                        _log.info("Removing WWN member {}", remMember.getAddress());
                        _smisHelper.removeZoneOrAliasMember(client, (CIMObjectPath) curMember.getCimObjectPath(), (CIMObjectPath) zone.getCimObjectPath(), false);
                        members.remove(curMember.getAlias());
                        members.remove(curMember.getAddress());
                        success = true;
                    } else {
                        _log.warn("Did not remove zone member with alias " + remMember.getAlias() + " and WWN " + remMember.getAddress() + " because it was not found.");
                    }
                }
            }
            // handle added members
            if (zoneUpdate.getAddZones() != null) {
                for (ZoneMember addMember : zoneUpdate.getAddZones()) {
                    curMember = members.containsKey(addMember.getAlias()) ? members.get(addMember.getAlias()) : members.get(addMember.getAddress());
                    if (curMember == null) {
                        String name = addMember.hasAlias() ? addMember.getAlias() : addMember.getAddress();
                        _log.info("Adding zone member {} ", name);
                        _smisHelper.addZoneOrAliasMember(client, zoneServiceIns, fabricWwn, (CIMObjectPath) zone.getCimObjectPath(), name);
                        members.put(name, addMember);
                        success = true;
                    } else {
                        _log.warn("Did not add zone member with alias " + addMember.getAlias() + " and WWN " + addMember.getAddress() + " because it already exists.");
                    }
                }
            }
            // check to see if the zone is now empty
            if (members.isEmpty()) {
                _log.error("Deleting Zone " + zoneUpdate.getName() + " because it is now empty.");
                _smisHelper.removeZone(client, zone);
            }
        } else {
            _log.error("Failed to update zones: " + zoneUpdate.getName() + ". The zone was not found in the active zoneset");
            throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailedNotFound(zoneUpdate.getName());
        }
    } catch (WBEMException ex) {
        _log.error("Failed to update zone: " + zoneUpdate.getName() + ". Error message" + ex.getLocalizedMessage(), ex);
        throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailed(ex);
    }
    return success;
}
Also used : Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) CIMObjectPath(javax.cim.CIMObjectPath) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) WBEMException(javax.wbem.WBEMException)

Example 28 with Zone

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

the class BrocadeNetworkSystemDevice method updateZonesStrategy.

/**
 * Updates one or more zones by adding/removing members as requested for each zone.
 *
 * @param client and instance of {@link WBEMClient} connected to the provider
 * @param zones the list of zone update requests
 * @param fabricId the name of the fabric where the zones exist
 * @param fabricWwn the WWN of the fabric where the zones exist
 * @param activateZones a boolean to indicate if the zoneset should be activated
 *            following successful updates
 * @return a map of the update results by zone keyed by zone name
 * @throws NetworkDeviceControllerException
 */
public Map<String, String> updateZonesStrategy(WBEMClient client, List<ZoneUpdate> zones, String fabricId, String fabricWwn, boolean activateZones) throws NetworkDeviceControllerException {
    // to do - Make sure fabric
    // id and fabric wwn are not
    // null or only request
    // needed params
    // a zone-name-to-result map to hold the results for each zone
    Map<String, String> zoneUpdateResults = new HashMap<String, String>();
    if (zones.isEmpty()) {
        throw DeviceControllerException.exceptions.entityNullOrEmpty("zones");
    }
    CIMInstance zoneServiceIns = null;
    try {
        _log.info("Update zones started.");
        _log.info("Attempting to start a zoning session");
        if (fabricWwn == null) {
            fabricWwn = _smisHelper.getFabricWwn(client, fabricId);
        }
        zoneServiceIns = _smisHelper.startSession(client, fabricId, fabricWwn);
        if (zoneServiceIns == null) {
            _log.info("Failed to start a zoning session.");
            throw NetworkDeviceControllerException.exceptions.startZoningSessionFailed();
        }
        // First determine if there is an active zoneset.
        CIMObjectPath zonesetPath = null;
        CIMInstance activeZonesetIns = _smisHelper.getActiveZonesetInstance(client, fabricId, fabricWwn);
        // There is no active zoneset, error
        if (activeZonesetIns == null) {
            _log.info("Cannot find active zoneset.");
            throw NetworkDeviceControllerException.exceptions.noActiveZonesetForFabric(fabricId);
        } else {
            // For Brocade, the active zoneset is a copy of a configuration zoneset. To make a change, we
            // need to modify the configuration zoneset and activate it. Get the configuration zoneset.
            zonesetPath = _smisHelper.getShadowZonesetPath(client, fabricId, fabricWwn, activeZonesetIns);
        }
        Map<String, Zone> zonesInFabric = _smisHelper.getZones(client, getZoneNames(zones), fabricWwn, false, true, true);
        for (ZoneUpdate zone : zones) {
            try {
                if (checkAndUpdateZone(client, zoneServiceIns, fabricId, fabricWwn, zonesetPath, zonesInFabric, zone)) {
                    zoneUpdateResults.put(zone.getName(), SUCCESS);
                } else {
                    zoneUpdateResults.put(zone.getName(), NO_CHANGE);
                }
            } catch (Exception ex) {
                zoneUpdateResults.put(zone.getName(), ERROR + " : " + ex.getMessage());
                handleZonesStrategyException(ex, activateZones);
            }
        }
        _log.info("Attempting to close zoning session.");
        // If there were no zones updated, just close the session without commit and return.
        if (!hasResult(zoneUpdateResults, SUCCESS)) {
            _log.info("No zones were updates. Closing the session with no commit");
            if (!_smisHelper.endSession(client, zoneServiceIns, false)) {
                _log.info("Failed to terminate zoning session. Ignoring as session may have expired.");
            }
        } else {
            // if zones were updated, commit them before ending the session
            if (_smisHelper.endSession(client, zoneServiceIns, true)) {
                if (activateZones) {
                    _log.info("Attempting to activate the zoneset.");
                    if (_smisHelper.activateZoneSet(client, zoneServiceIns, zonesetPath, true)) {
                        _log.info("The zoneset was activated succcessfully.");
                    } else {
                        _log.info("Failed to activate the zoneset");
                    }
                }
            } else {
                throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailedCommit();
            }
        }
        _log.info("Update zones strategy completed successfully.");
    } catch (Exception e1) {
        try {
            if (zoneServiceIns != null) {
                _log.info("Attempting to terminate zoning session.");
                _smisHelper.endSession(client, zoneServiceIns, false);
            }
        } catch (WBEMException e) {
            _log.error("Failed to terminate zoning session." + e.getLocalizedMessage(), e);
        }
        _log.error("Failed to update zones: " + e1.getLocalizedMessage(), e1);
        throw NetworkDeviceControllerException.exceptions.updateZonesStrategyFailed(e1);
    }
    return zoneUpdateResults;
}
Also used : HashMap(java.util.HashMap) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) CIMObjectPath(javax.cim.CIMObjectPath) ZoneUpdate(com.emc.storageos.networkcontroller.impl.mds.ZoneUpdate) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance) WBEMException(javax.wbem.WBEMException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 29 with Zone

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

the class NetworkSystemService method getSanZones.

/**
 * Returns a list of the active zones (and their zone members) for the specified
 * fabric or VSAN in a network system. E.g., ../san-fabrics/{fabric-id}/san-zones?zone-name="abc-zone"&exclude-members=true
 * Note: This is a synchronous call to the device and may take a while to receive a response.
 *
 * @param id the URN of a ViPR network system.
 * @param fabricId The name of the VSAN or fabric as returned by
 * @param zoneName - only returns zone with zone name matched the given name. Return all zones, if not specified.
 * @param excludeMembers - true, do not include members with zone. Include members, if not specified.
 * @param excludeAliases - true, do not include aliases with zone. Include aliases, if not specified.
 * @prereq none
 * @brief List active zones in a network system fabric or VSAN
 * @return A list of the active zones and their members. If zone name is specified, and there is a match, then only one zone is
 *         returned.
 *         If excludeMembers is true, then only zone name is present.
 * @throws InternalException
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-fabrics/{fabricId}/san-zones")
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public SanZonesRestRep getSanZones(@PathParam("id") URI id, @PathParam("fabricId") String fabricId, @QueryParam("zone-name") String zoneName, @QueryParam("exclude-members") boolean excludeMembers, @QueryParam("exclude-aliases") boolean excludeAliases) throws InternalException {
    SanZonesRestRep szones = new SanZonesRestRep();
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    NetworkSystem device = queryResource(id);
    String fabricWwn = null;
    if (WWNUtility.isValidWWN(fabricId)) {
        fabricWwn = fabricId;
        fabricId = fabricId.replaceAll(":", "");
    }
    NetworkController controller = getNetworkController(device.getSystemType());
    List<Zoneset> zonesets = controller.getZonesets(device.getId(), fabricId, fabricWwn, zoneName, excludeMembers, excludeAliases);
    for (Zoneset zoneset : zonesets) {
        for (Zone zone : zoneset.getZones()) {
            SanZoneRestRep sz = new SanZoneRestRep();
            sz.setName(zone.getName());
            for (ZoneMember member : zone.getMembers()) {
                // convert zone member to xml aware. Only fill in alias if member is an alias type
                sz.getMembers().add(new SanZoneMemberRestRep(member.getAddress(), member.isAliasType() ? member.getAlias() : null));
            }
            szones.getZones().add(sz);
        }
    }
    return szones;
}
Also used : Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) SanZone(com.emc.storageos.model.network.SanZone) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) SanZoneMemberRestRep(com.emc.storageos.model.network.SanZoneMemberRestRep) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) SanZonesRestRep(com.emc.storageos.model.network.SanZonesRestRep) Zoneset(com.emc.storageos.networkcontroller.impl.mds.Zoneset) SanZoneRestRep(com.emc.storageos.model.network.SanZoneRestRep) NetworkController(com.emc.storageos.networkcontroller.NetworkController) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 30 with Zone

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

the class BlockStorageScheduler method getPrezonedPortsForInitiators.

/**
 * Reads the existing zones for the initiators from the network system and finds all ports that are
 * already prezoned to one or more of the initiators.
 *
 * @param networkDeviceController an instance of networkDeviceController
 * @param portByNetwork the ports in the export mask grouped by network
 * @param initiatorsByNetwork the initiators of interest grouped by network
 * @param zonesByNetwork an OUT param to collect the zones found grouped by network
 * @param token the workflow step id
 * @return a map of ports in networks that are already zoned to one or more of the initiators
 */
public Map<NetworkLite, List<StoragePort>> getPrezonedPortsForInitiators(NetworkDeviceController networkDeviceController, Map<NetworkLite, List<StoragePort>> portByNetwork, Map<NetworkLite, List<Initiator>> initiatorsByNetwork, Map<NetworkLite, StringSetMap> zonesByNetwork, String token) {
    // so now we have a a collection of initiators and ports, let's get the zones
    Map<NetworkLite, List<StoragePort>> preZonedPortsByNetwork = new HashMap<NetworkLite, List<StoragePort>>();
    StringSetMap zonesInNetwork = null;
    Map<String, List<Zone>> initiatorWwnToZonesMap = new HashMap<String, List<Zone>>();
    for (NetworkLite network : portByNetwork.keySet()) {
        if (!Transport.FC.toString().equals(network.getTransportType())) {
            continue;
        }
        List<Initiator> networkInitiators = initiatorsByNetwork.get(network);
        if (networkInitiators == null || networkInitiators.isEmpty()) {
            continue;
        }
        Map<String, StoragePort> portByWwn = DataObjectUtils.mapByProperty(portByNetwork.get(network), "portNetworkId");
        URI[] networkSystemURIUsed = new URI[1];
        zonesInNetwork = networkDeviceController.getZoningMap(network, networkInitiators, portByWwn, initiatorWwnToZonesMap, networkSystemURIUsed);
        _log.info("Existing zones in network {} are {}", network.getNativeGuid(), zonesInNetwork);
        // if the OUT parameter is not null, fill in the discovered zones
        if (zonesByNetwork != null && !zonesInNetwork.isEmpty()) {
            zonesByNetwork.put(network, zonesInNetwork);
        }
        for (String iniId : zonesInNetwork.keySet()) {
            for (String portId : zonesInNetwork.get(iniId)) {
                StringMapUtil.addToListMap(preZonedPortsByNetwork, network, DataObjectUtils.findInCollection(portByNetwork.get(network), URI.create(portId)));
            }
        }
    }
    // now store the retrieved zones in ZK
    if (!initiatorWwnToZonesMap.isEmpty()) {
        Map<String, List<Zone>> zonesMap = (Map<String, List<Zone>>) WorkflowService.getInstance().loadWorkflowData(token, "zonemap");
        // some workflows call port allocation more than one time, rather than overriding, add to these zones to already stored zones.
        if (zonesMap == null) {
            zonesMap = initiatorWwnToZonesMap;
        } else {
            zonesMap.putAll(initiatorWwnToZonesMap);
        }
        WorkflowService.getInstance().storeWorkflowData(token, "zonemap", zonesMap);
    }
    return preZonedPortsByNetwork;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) TreeMap(java.util.TreeMap)

Aggregations

Zone (com.emc.storageos.networkcontroller.impl.mds.Zone)30 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)14 ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)13 List (java.util.List)9 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)8 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)7 CIMInstance (javax.cim.CIMInstance)7 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)6 Initiator (com.emc.storageos.db.client.model.Initiator)5 TimeZone (java.util.TimeZone)5 CIMObjectPath (javax.cim.CIMObjectPath)5 WBEMException (javax.wbem.WBEMException)5 DateTimeZone (org.joda.time.DateTimeZone)5 FCZoneReference (com.emc.storageos.db.client.model.FCZoneReference)4 StringMap (com.emc.storageos.db.client.model.StringMap)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 NetworkFCZoneInfo (com.emc.storageos.networkcontroller.NetworkFCZoneInfo)4