Search in sources :

Example 11 with Zone

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

the class NetworkSystemService method addSanZones.

/**
 * Adds one or more SAN zones to the active zoneset of the VSAN or fabric specified on a network system.
 * This is an asynchronous call.
 *
 * @param sanZones A parameter structure listing the zone(s) to be added and their 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 Add SAN zones to 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")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep addSanZones(SanZoneCreateParam 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);
    List<Zone> zones = new ArrayList<Zone>();
    for (SanZone sz : sanZones.getZones()) {
        Zone zone = new Zone(sz.getName());
        validateZoneName(sz.getName(), device.getSystemType());
        zones.add(zone);
        for (String szm : sz.getMembers()) {
            ZoneMember member = createZoneMember(szm);
            zone.getMembers().add(member);
        }
        ArgValidator.checkFieldNotEmpty(zone.getMembers(), "zone members");
        auditOp(OperationTypeEnum.ADD_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");
    Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, device.getId(), task, ResourceOperationTypeEnum.ADD_SAN_ZONE);
    NetworkController controller = getNetworkController(device.getSystemType());
    controller.addSanZones(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)

Example 12 with Zone

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

the class NetworkDeviceController method getZoningMap.

/**
 * Finds all the zone paths that exists between a list of initiators and storage ports.
 *
 * @param initiators the list of initiators
 * @param portsMap a map of storage port keyed by the port WWN
 * @param initiatorWwnToZonesMap an OUT parameter used to store the zones retrieved mapped by initiator
 * @param networkSystemURI - an OUT parameter indicating the NetworkSystem's URI that found the zones
 *
 * @return a zoning map of zones that exists on the network systems
 */
public StringSetMap getZoningMap(NetworkLite network, List<Initiator> initiators, Map<String, StoragePort> portsMap, Map<String, List<Zone>> initiatorWwnToZonesMap, URI[] networkSystemURI) {
    StringSetMap map = new StringSetMap();
    StringSet initiatorWwns = new StringSet();
    for (Initiator initiator : initiators) {
        initiatorWwns.add(initiator.getInitiatorPort());
    }
    _log.info(String.format("Looking for zones from iniiators %s to targets %s", initiatorWwns, portsMap.keySet()));
    // find all the zones for the initiators as a map of initiator WWN to zones
    if (initiatorWwnToZonesMap == null) {
        initiatorWwnToZonesMap = new HashMap<String, List<Zone>>();
    }
    // of the zones retrieved from the network system, select the once
    NetworkSystem networkSystem = fetchInitiatorsZones(network, initiators, initiatorWwnToZonesMap);
    if (networkSystem != null && networkSystemURI != null) {
        networkSystemURI[0] = networkSystem.getId();
    }
    initiatorWwnToZonesMap = selectZonesForInitiatorsAndPorts(network, initiatorWwnToZonesMap, portsMap);
    // build the map object
    for (Initiator initiator : initiators) {
        StringSet set = new StringSet();
        List<Zone> zones = initiatorWwnToZonesMap.get(initiator.getInitiatorPort());
        if (zones != null) {
            for (Zone zone : zones) {
                _log.info(zone.getLogString());
                for (ZoneMember member : zone.getMembers()) {
                    if (portsMap.containsKey(member.getAddress())) {
                        // There can be multiple zones with the same initiator and port
                        // for this function, we're just finding all the mappings
                        set.add(portsMap.get(member.getAddress()).getId().toString());
                    }
                }
            }
        }
        if (set != null && !set.isEmpty()) {
            map.put(initiator.getId().toString(), set);
        }
    }
    _log.info("Found the following zone mappings {} for initiators {} and ports {}", new Object[] { map, initiatorWwnToZonesMap.keySet(), portsMap.keySet() });
    return map;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) Initiator(com.emc.storageos.db.client.model.Initiator) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) StringSet(com.emc.storageos.db.client.model.StringSet) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember)

Example 13 with Zone

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

the class NetworkDeviceController method fetchInitiatorsInNetworkZoneInfoMap.

/**
 * For the given network and initiators, which are in the network,
 * and a given list of storage ports, find all the zones on the network
 * system for the initiators. Search the zones to find ones that have
 * one or more of the ports and create the zoning map between the
 * initiators and ports. Returns the results as {@link ZoneInfoMap} which is map
 * of initiator port WWN and storage port WWN keyed by zone-key, where zone-key
 * is the concatenation of the initiator port WWN and the storage port WWN.
 * <p>
 * Note that the map returned contains only the zones that were selected for use by ViPR. In the case of duplicate zones between an
 * initiator-port pair, ViPR applies a selection criteria to choose one. See {@link #selectZonesForInitiatorsAndPorts}
 * <p>
 * Note that a zone in the network system can have more than one initiator and one storage port. For such zone, there can be multiple
 * entries in the map, one for each initiator/port pairs.
 * <p>
 * If the initiator is not in a network or no zones could be found for the initiator, there will be no entries for this initiator in the
 * map. An empty map will be returned if no zones could be found for any initiator.
 *
 * @param network the network of the initiators
 * @param map an OUT parameter where ZoneInfoMap is stored
 * @param initiators the initiators for which the zones will be read
 * @param initiatorPortsMap the storage ports of interest in the networks.
 * @return the network system used to read the zones
 */
private NetworkSystem fetchInitiatorsInNetworkZoneInfoMap(NetworkLite network, ZoneInfoMap map, List<Initiator> initiators, Map<String, StoragePort> initiatorPortsMap) {
    Map<String, Initiator> wwnToInitiatorMap = wwnToInitiatorMap(initiators);
    // retrieve the zones
    Map<String, List<Zone>> wwnToZones = new HashMap<String, List<Zone>>();
    NetworkSystem networkSystem = fetchInitiatorsZones(network, initiators, wwnToZones);
    wwnToZones = selectZonesForInitiatorsAndPorts(network, wwnToZones, initiatorPortsMap);
    // if we successfully retrieved the zones
    if (networkSystem != null && !wwnToZones.isEmpty()) {
        ZoneInfo info = null;
        Initiator initiator = null;
        for (Map.Entry<String, List<Zone>> entry : wwnToZones.entrySet()) {
            initiator = wwnToInitiatorMap.get(entry.getKey());
            for (Zone zone : entry.getValue()) {
                // I need some logic here to make sure I select the best zone
                for (ZoneMember member : zone.getMembers()) {
                    if (initiatorPortsMap.containsKey(member.getAddress())) {
                        // double check WWN formatting
                        StoragePort port = initiatorPortsMap.get(member.getAddress());
                        info = new ZoneInfo();
                        info.setZoneName(zone.getName());
                        info.setInitiatorWwn(initiator.getInitiatorPort());
                        info.setInitiatorId(initiator.getId().toString());
                        info.setPortWwn(port.getPortNetworkId());
                        info.setPortId(port.getId().toString());
                        info.setNetworkId(network.getId().toString());
                        info.setNetworkWwn(NetworkUtil.getNetworkWwn(network));
                        info.setFabricId(network.getNativeId());
                        info.setNetworkSystemId(networkSystem.getId().toString());
                        info.setMemberCount(zone.getMembers().size());
                        map.put(info.getZoneReferenceKey(), info);
                    }
                }
            }
        }
    }
    return networkSystem;
}
Also used : HashMap(java.util.HashMap) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) StoragePort(com.emc.storageos.db.client.model.StoragePort) Initiator(com.emc.storageos.db.client.model.Initiator) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) 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) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo)

Example 14 with Zone

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

the class NetworkDeviceController method createZoneReferences.

/**
 * Create zone references when we discover zones off the switch.
 * Normally this routine will not do anything, because the ExportMask is freshly created, and
 * will therefore have no volumes in it.
 * @param network -- Network Lite
 * @param networkSystem -- URI of network system
 * @param exportGroup -- ExportGroup
 * @param exportMask -- ExportMask
 * @param initiatorWwntoZonesMap -- Map of initiator WWN string to a list of corresponding Zones
 */
void createZoneReferences(NetworkLite network, URI networkSystem, ExportGroup exportGroup, ExportMask exportMask, Map<String, List<Zone>> initiatorWwntoZonesMap) {
    StringMap maskVolumes = exportMask.getVolumes();
    if (maskVolumes == null || maskVolumes.isEmpty()) {
        _log.info(String.format("No volumes in ExportMask %s %s so no zone references created", exportMask.getMaskName(), exportMask.getId()));
        return;
    }
    // create a separate zone reference for each initiator - target pair.
    for (String maskVolume : maskVolumes.keySet()) {
        for (List<Zone> zones : initiatorWwntoZonesMap.values()) {
            for (Zone zone : zones) {
                // Find the initiatorWwn
                String initiatorWwn = null;
                for (ZoneMember member : zone.getMembers()) {
                    if (initiatorWwntoZonesMap.containsKey(member.getAddress())) {
                        initiatorWwn = member.getAddress();
                        break;
                    }
                }
                if (initiatorWwn == null) {
                    // Could not locate the initiator
                    _log.info("Could not locat the initiator: " + zone.getName());
                    continue;
                }
                for (ZoneMember member : zone.getMembers()) {
                    if (initiatorWwn.equals(member.getAddress())) {
                        continue;
                    }
                    String key = FCZoneReference.makeEndpointsKey(initiatorWwn, member.getAddress());
                    String[] newOrExisting = new String[1];
                    FCZoneReference ref = addZoneReference(exportGroup.getId(), URI.create(maskVolume), key, network.getNativeId(), networkSystem, zone.getName(), true, newOrExisting);
                    _log.info(String.format("Created FCZoneReference for existing zone %s %s %s %s", ref.getZoneName(), ref.getPwwnKey(), ref.getVolumeUri(), ref.getGroupUri()));
                }
            }
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 15 with Zone

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

the class NetworkDeviceController method updateZoningMapForInitiators.

/**
 * Update the zoning map for a newly "accepted" export mask. This applies to
 * brown field scenarios where a export mask was found on the storage array.
 * This function finds the zones of the export mask initiators and
 * existing ports and creates the zoning map between the two sets.
 *
 * @param exportGroup the masking view export group
 * @param exportMask the export mask being updated.
 * @param doPersist a boolean that indicates if the changes should be persisted in the db
 */
public void updateZoningMapForInitiators(ExportGroup exportGroup, ExportMask exportMask, boolean doPersist) {
    if (exportMask.getZoningMap() == null || exportMask.getZoningMap().isEmpty()) {
        Long start = System.currentTimeMillis();
        // possibly the first time this export mask is processed, populate from existing zones
        List<StoragePort> storagePorts = ExportUtils.getStoragePorts(exportMask, _dbClient);
        Set<Initiator> initiators = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, exportMask, Transport.FC);
        Map<NetworkLite, List<Initiator>> initiatorsByNetworkMap = NetworkUtil.getInitiatorsByNetwork(initiators, _dbClient);
        StringSetMap zoningMap = new StringSetMap();
        for (NetworkLite network : initiatorsByNetworkMap.keySet()) {
            if (!Transport.FC.toString().equals(network.getTransportType())) {
                continue;
            }
            Map<String, StoragePort> initiatorPortsMap = NetworkUtil.getPortsInNetworkMap(network, storagePorts);
            if (!initiatorPortsMap.isEmpty()) {
                Map<String, List<Zone>> initiatorWwnToZonesMap = new HashMap<String, List<Zone>>();
                URI[] networkSystemURIUsed = new URI[1];
                zoningMap.putAll(getZoningMap(network, initiatorsByNetworkMap.get(network), initiatorPortsMap, initiatorWwnToZonesMap, networkSystemURIUsed));
                createZoneReferences(network, networkSystemURIUsed[0], exportGroup, exportMask, initiatorWwnToZonesMap);
            }
        }
        _log.info(String.format("Elapsed time to updateZoningMap %d seconds", ((System.currentTimeMillis() - start) / 1000L)));
        exportMask.setZoningMap(zoningMap);
        if (doPersist) {
            _dbClient.updateAndReindexObject(exportMask);
        }
    } else {
        _log.info((String.format("Export mask %s (%s, args) already has a zoning map, not importing zones", exportMask.getMaskName(), exportMask.getId())));
    }
}
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)

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