Search in sources :

Example 6 with Zone

use of com.emc.storageos.networkcontroller.impl.mds.Zone 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)

Example 7 with Zone

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

the class BrocadeNetworkSMIS method getEndpointZones.

/**
 * Given an initiator WWN, find all the zones this initiator is in.
 *
 * @param client an instance of WBEMClient with an open session to SMI provider
 * @param fabricWwn the WWN of the fabric
 * @param endpointWwn the WWN of the initiator
 * @param cachedZones A cache of zones already retrieved from the network system.
 * @return a list of zones in the initiator is in any zones, otherwise, an empty list
 * @throws WBEMException
 */
public List<Zone> getEndpointZones(WBEMClient client, String fabricWwn, String endpointWwn, Map<CIMObjectPath, Zone> cachedZones) throws WBEMException {
    List<Zone> zones = new ArrayList<Zone>();
    CIMInstance memberIns = getZoneMemberInstance(client, endpointWwn, _ZMType_Wwn, fabricWwn, true);
    // if we find an instance, this means the initiator is in some zones
    if (memberIns != null) {
        // get the zones
        CloseableIterator<CIMInstance> zoneItr = null;
        Zone zone = null;
        try {
            zoneItr = client.associatorInstances(memberIns.getObjectPath(), _Brocade_ZoneMembershipSettingDataInZone, _Brocade_Zone, null, null, false, null);
            while (zoneItr.hasNext()) {
                CIMInstance zoneIns = zoneItr.next();
                zone = cachedZones.get(zoneIns.getObjectPath());
                if (zone == null) {
                    zone = getZoneFromZoneInstance(client, zoneIns, true, false);
                    cachedZones.put(zoneIns.getObjectPath(), zone);
                }
                zones.add(zone);
                _log.info("Found zone " + zone.getName());
            }
        } catch (WBEMException ex) {
            _log.error("Encountered an exception while trying to get zones for initiator." + ex.getMessage(), ex);
            throw ex;
        } finally {
            if (zoneItr != null) {
                zoneItr.close();
            }
        }
    }
    return zones;
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) TimeZone(java.util.TimeZone) ArrayList(java.util.ArrayList) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance)

Example 8 with Zone

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

the class BrocadeNetworkSMIS method getZoneSets.

@SuppressWarnings("unchecked")
public List<Zoneset> getZoneSets(WBEMClient client, String fabricId, String fabricWwn, String zoneName, boolean excludeMembers, boolean excludeAliases) throws WBEMException {
    List<Zoneset> zonesets = new ArrayList<Zoneset>();
    fabricWwn = StringUtils.isEmpty(fabricWwn) ? getFabricWwn(client, fabricId) : fabricWwn;
    CIMInstance fabricIns = getFabricInstance(client, fabricId, fabricWwn);
    if (fabricIns != null) {
        CloseableIterator<CIMInstance> zonesetItr = null;
        try {
            CIMInstance activeZonesetIns = getActiveZonesetInstance(client, fabricId, fabricWwn);
            if (activeZonesetIns != null) {
                Zoneset activeZoneset = new Zoneset(cimStringProperty(activeZonesetIns, _element_name));
                activeZoneset.setActive(cimBooleanProperty(activeZonesetIns, _active));
                // if zoneName not specified, get all zones in the zoneset.
                if (StringUtils.isEmpty(zoneName) || (zoneName != null && zoneName.startsWith(NetworkDeviceController.ZONESET_QUERY_FILTER))) {
                    activeZoneset.setZones(getZonesetZones(client, activeZonesetIns.getObjectPath(), !excludeMembers, !excludeAliases, zoneName));
                } else {
                    // looking for a zone with given zoneName
                    Zone zone = getZone(client, zoneName, fabricWwn, true, !excludeMembers, !excludeAliases);
                    if (zone != null) {
                        activeZoneset.getZones().add(zone);
                    }
                }
                // get pending active zoneset and consolidate with active zoneset
                zonesetItr = client.associatorInstances(fabricIns.getObjectPath(), _zoneset_fabric_path, _zoneset_name, null, null, false, null);
                while (zonesetItr.hasNext()) {
                    CIMInstance zonesetIns = zonesetItr.next();
                    Zoneset zoneset = new Zoneset(cimStringProperty(zonesetIns, _element_name));
                    zoneset.setActive(cimBooleanProperty(zonesetIns, _active));
                    if (!zoneset.getActive() && StringUtils.equals(zoneset.getName(), activeZoneset.getName())) {
                        // found a pending active zoneset, consolidate its zones into active zoneset
                        if (StringUtils.isEmpty(zoneName)) {
                            zoneset.setZones(getZonesetZones(client, zonesetIns.getObjectPath(), !excludeMembers, !excludeAliases, null));
                            // consolidate active and pending zones in the zoneset
                            List<String> activeZoneNames = new ArrayList<String>();
                            for (Zone zone : activeZoneset.getZones()) {
                                activeZoneNames.add(zone.getName());
                            }
                            // get zones that are not yet active in zoneset, then
                            // append to zoneset
                            List<Zone> inactiveZones = new ArrayList<Zone>();
                            for (Zone zone : zoneset.getZones()) {
                                if (!activeZoneNames.contains(zone.getName())) {
                                    inactiveZones.add(zone);
                                }
                            }
                            activeZoneset.getZones().addAll(inactiveZones);
                        } else if (activeZoneset.getZones().isEmpty()) {
                            // if specified zone was not found in active zone set, look into pending zoneset
                            Zone zone = getZone(client, zoneName, fabricWwn, true, !excludeMembers, !excludeAliases);
                            if (zone != null) {
                                zoneset.getZones().add(zone);
                            }
                        }
                        break;
                    }
                }
                if (activeZoneset != null) {
                    zonesets.add(activeZoneset);
                }
            }
        } finally {
            if (zonesetItr != null) {
                zonesetItr.close();
            }
        }
    }
    return zonesets;
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) TimeZone(java.util.TimeZone) ArrayList(java.util.ArrayList) Zoneset(com.emc.storageos.networkcontroller.impl.mds.Zoneset) CIMInstance(javax.cim.CIMInstance)

Example 9 with Zone

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

the class BrocadeNetworkSystemDevice method checkAndCreateZone.

/**
 * Checks if a zone with the same name already exists before the zone is created. The
 * rules for creating a zone are:
 * <ul>
 * <li>If an active zone with the same name exists, ensure that all the desired members are in the zone. If this is true, consider the
 * zone created. If not, error because the application is not going to modify an existing zone.</li>
 * <li>If an inactive zone with the same name exists, delete the inactive zone and then create the new one.</li>
 * </ul>
 * This function assumes the zoning session is already acquired.
 *
 * @param client an instance of the SMI client
 * @param zoneServiceIns the instance of SMI zoneServices
 * @param fabricId the fabric id where the zone should created
 * @param fabricWwn the fabric WWN where the zone should created
 * @param zonesetPath the SMI path of the active zoneset for the fabric
 * @param zone the zone to be created
 * @return a boolean to indicated if a zone was created or not.
 * @throws WBEMException
 */
private boolean checkAndCreateZone(WBEMClient client, CIMInstance zoneServiceIns, String fabricId, String fabricWwn, CIMObjectPath zonesetPath, Zone zone, boolean activateZones) throws WBEMException {
    boolean added = false;
    _log.info("Starting create zone with name " + zone.getName());
    // check if an active zone with the same name exists
    Zone zoneInFabric = _smisHelper.getZone(client, zone.getName(), fabricWwn, true, true, true);
    if (zoneInFabric != null) {
        _log.info("Found an active zone with the name " + zone.getName());
        // and this one cannot be used without adding the missing members, so error
        if (!sameMembers(zoneInFabric, zone)) {
            throw NetworkDeviceControllerException.exceptions.activeZoneWithSameNameExists(zone.getName());
        }
    } else {
        // check if an inactive zone with the same name exists
        zoneInFabric = _smisHelper.getZone(client, zone.getName(), fabricWwn, false, true, true);
        if (zoneInFabric != null) {
            _log.info("Found an inactive zone with the name " + zone.getName());
            if (activateZones) {
                // This is the export path - delete the zone we will create the new one
                removeZone(client, fabricId, fabricWwn, zoneInFabric);
                // create the new zone
                createZone(client, zoneServiceIns, fabricId, fabricWwn, zonesetPath, zone);
                added = true;
            } else {
                // This is the API path - Error and let the caller provide the right input
                throw NetworkDeviceControllerException.exceptions.inactiveZoneWithSameNameExists(zone.getName());
            }
        } else {
            // create the new zone
            added = createZone(client, zoneServiceIns, fabricId, fabricWwn, zonesetPath, zone);
        }
    }
    return added;
}
Also used : Zone(com.emc.storageos.networkcontroller.impl.mds.Zone)

Example 10 with Zone

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

the class NetworkSystemService method removeSanZones.

/**
 * Deletes one or more zone(s) from the active zoneset of the VSAN or fabric specified in
 * the network system. This is an asynchronous call.
 *
 * @param sanZones A list of Zones and their zone members that should be deleted from
 *            the active zoneset. Note: the zone members must be included (deletion of a zone is based
 *            on matching both the name and the zone members).
 * @param id the URN of a ViPR Network System
 * @param fabricId The name of the VSAN or fabric as returned by
 *            /vdc/network-systems/{id}/san-fabrics or the VSAN or fabric WWN
 * @prereq none
 * @brief Delete zones from network system VSAN or fabric
 * @return A task description structure.
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/san-fabrics/{fabricId}/san-zones/remove")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep removeSanZones(SanZonesDeleteParam sanZones, @PathParam("id") URI id, @PathParam("fabricId") String fabricId) throws InternalException {
    String task = UUID.randomUUID().toString();
    String fabricWwn = null;
    if (WWNUtility.isValidWWN(fabricId)) {
        fabricWwn = fabricId;
        fabricId = fabricId.replaceAll(":", "");
    }
    ArgValidator.checkFieldUriType(id, NetworkSystem.class, "id");
    NetworkSystem device = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.REMOVE_SAN_ZONE);
    List<Zone> zones = new ArrayList<Zone>();
    for (SanZone sz : sanZones.getZones()) {
        Zone zone = new Zone(sz.getName());
        zones.add(zone);
        for (String szm : sz.getMembers()) {
            ZoneMember member = createZoneMember(szm);
            zone.getMembers().add(member);
        }
        auditOp(OperationTypeEnum.REMOVE_SAN_ZONE, true, AuditLogManager.AUDITOP_BEGIN, zone.getName(), device.getId().toString(), device.getLabel(), device.getPortNumber(), device.getUsername(), device.getSmisProviderIP(), device.getSmisPortNumber(), device.getSmisUserName(), device.getSmisUseSSL(), device.getVersion(), device.getUptime());
    }
    ArgValidator.checkFieldNotEmpty(zones, "zones");
    NetworkController controller = getNetworkController(device.getSystemType());
    controller.removeSanZones(device.getId(), fabricId, fabricWwn, zones, false, task);
    return toTask(device, task, op);
}
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) ArrayList(java.util.ArrayList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) Operation(com.emc.storageos.db.client.model.Operation) SanZone(com.emc.storageos.model.network.SanZone) NetworkController(com.emc.storageos.networkcontroller.NetworkController) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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