Search in sources :

Example 16 with Zone

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

the class NetworkDeviceController method doZoneExportMasksCreate.

/**
 * Handles ExportGroup / ExportMask create, as well as add volume
 *
 * @param exportGroup
 * @param exportMaskURIs
 * @param volumeURIs
 * @param token
 * @param checkZones Flag to enable or disable zoning check on a Network System
 * @return
 */
private boolean doZoneExportMasksCreate(ExportGroup exportGroup, List<URI> exportMaskURIs, Collection<URI> volumeURIs, String token, boolean checkZones) {
    BiosCommandResult result = null;
    NetworkFCContext context = new NetworkFCContext();
    try {
        if (!checkZoningRequired(token, exportGroup.getVirtualArray())) {
            return true;
        }
        volumeURIs = removeDuplicateURIs(volumeURIs);
        // to update any at all, in which case we can success out.
        if (exportMaskURIs == null || exportMaskURIs.isEmpty()) {
            WorkflowStepCompleter.stepSucceded(token);
            return true;
        }
        // Compute the zones for the ExportGroup
        // [hala] make sure we do not rollback existing zones
        Map<String, List<Zone>> zonesMap = new HashMap<String, List<Zone>>();
        if (checkZones) {
            zonesMap = getExistingZonesMap(exportMaskURIs, token);
        }
        List<NetworkFCZoneInfo> zones = _networkScheduler.getZoningTargetsForExportMasks(exportGroup, exportMaskURIs, volumeURIs, zonesMap, checkZones, _dbClient);
        context.getZoneInfos().addAll(zones);
        logZones(zones);
        // If there are no zones to do, we were successful.
        if (!checkZones) {
            if (!context.getZoneInfos().isEmpty()) {
                String[] newOrExisting = new String[1];
                for (NetworkFCZoneInfo zoneInfo : context.getZoneInfos()) {
                    addZoneReference(exportGroup.getId(), zoneInfo, newOrExisting);
                }
            }
            result = BiosCommandResult.createSuccessfulResult();
        } else {
            // Now call addZones to add all the required zones.
            InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_047);
            result = addRemoveZones(exportGroup.getId(), context.getZoneInfos(), false);
            InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_048);
        }
        // Save our zone infos in case we want to rollback.
        WorkflowService.getInstance().storeStepData(token, context);
        // Update the workflow state.
        completeWorkflowState(null, token, "zoneExportMaskCreate", result, null);
    } catch (Exception ex) {
        _log.error("Exception zoning Export Masks", ex);
        // Save our zone infos in case we want to rollback.
        WorkflowService.getInstance().storeStepData(token, context);
        ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportGroupCreateFailed(ex.getMessage(), ex);
        WorkflowStepCompleter.stepFailed(token, svcError);
    }
    return (result != null && result.isCommandSuccess());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) HashMap(java.util.HashMap) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NetworkFCContext(com.emc.storageos.networkcontroller.NetworkFCContext) 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 17 with Zone

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

the class NetworkScheduler method selectExistingZoneForInitiatorPort.

/**
 * Search the list of existing zones for the initiator-port pair to decide which to use.
 * Preference is given to zones according to this priority:
 * <ol>
 * <li>The zone is in ViPR DB and was created by ViPR</li>
 * <li>The zone is in ViPR DB but was not created by ViPR</li>
 * <li>The zone follows the single initiator-target pair per zone</li>
 * <li>The last zone in the list</li>
 * </ol>
 * If no zone can be found for the initiator-port pair, null is returned.
 *
 * @param network the network of the initiator
 * @param initiatorWwn the initiator WWN
 * @param portWwn the target WWN
 * @param existingZones a list of zones found on the network system for the initiator
 * @return an instance of Zone if one is found, otherwise null.
 */
public Zone selectExistingZoneForInitiatorPort(NetworkLite network, String initiatorWwn, String portWwn, List<Zone> existingZones) {
    // If we did not find zones, we need to create zones even if we have FCZoneReference
    if (existingZones == null || existingZones.isEmpty()) {
        return null;
    }
    // initialize variables
    boolean existingZone = true;
    Zone foundZone = null;
    // Find the FCZoneReference in ViPR for the port-initiator key and the network
    String key = FCZoneReference.makeEndpointsKey(initiatorWwn, portWwn);
    List<FCZoneReference> fcZoneRefs = getFCZoneReferencesForKey(key);
    if (!fcZoneRefs.isEmpty()) {
        Zone matchedZone = null;
        _log.info("Found {} FCZoneReference for key {}", fcZoneRefs.size(), key);
        // try to re-use zones known to ViPR as a first preference
        for (FCZoneReference fcZoneRef : fcZoneRefs) {
            // make sure the FCZoneReference matches the network and its network system a
            if (network.getNetworkSystems().contains(fcZoneRef.getNetworkSystemUri().toString()) && network.getNativeId().equals(fcZoneRef.getFabricId())) {
                _log.debug("Found an FCZoneReference for zone {}", fcZoneRef.getZoneName());
                // do still have the zone on the network system
                matchedZone = findZoneByNameAndPort(fcZoneRef.getZoneName(), portWwn, existingZones);
                if (matchedZone != null) {
                    _log.debug("Found the zone for FCZoneReference {} in the initiator existing zones", fcZoneRef.getZoneName());
                    _log.debug(matchedZone.getLogString());
                    foundZone = matchedZone;
                    // if the zone was created by ViPR, the search ended
                    if (!fcZoneRef.getExistingZone()) {
                        existingZone = false;
                        _log.debug("Selected zone {} because it was created by ViPR", foundZone.getName());
                        break;
                    }
                }
            }
        }
    }
    if (foundZone != null) {
        _log.debug("Selected existing Zone {} as it is already used by ViPR", foundZone.getName());
    } else {
        outer: for (Zone curZone : existingZones) {
            for (ZoneMember member : curZone.getMembers()) {
                if (member.getAddress() != null && member.getAddress().equals(portWwn)) {
                    foundZone = curZone;
                    if (curZone.getMembers().size() == 2) {
                        // if the zone has only 2 members, the search ended
                        _log.debug("Selected existing Zone {} as it has only 2 members", foundZone.getName());
                        break outer;
                    }
                }
            }
        }
    }
    if (foundZone != null) {
        foundZone.setExistingZone(existingZone);
    }
    return foundZone;
}
Also used : 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 18 with Zone

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

the class NetworkScheduler method getZoneInfoForExistingZone.

/**
 * Search the list of existing zones for the initiator-port pair to decide which to use.
 * Preference is given to zones according to this priority:
 * <ol>
 * <li>The zone is in ViPR DB and was created by ViPR</li>
 * <li>The zone is in ViPR DB but was not created by ViPR</li>
 * <li>The zone follows the single initiator-target pair per zone</li>
 * <li>The last zone in the list</li>
 * </ol>
 * Create a new FCZoneInfo object from an existing zone, otherwise return a null.
 *
 * @param network the initiator network
 * @param initiatorWwn the initiator WWN
 * @param portWwn the target WWN
 * @param existingZones a list of zones found on the network system for the initiator
 * @return an instance of FCZoneInfo
 */
private NetworkFCZoneInfo getZoneInfoForExistingZone(NetworkLite network, String initiatorWwn, String portWwn, List<Zone> existingZones) {
    NetworkFCZoneInfo zoneInfo = null;
    Zone zone = selectExistingZoneForInitiatorPort(network, initiatorWwn, portWwn, existingZones);
    if (zone != null) {
        zoneInfo = new NetworkFCZoneInfo(URI.create(network.getNetworkSystems().iterator().next()), network.getNativeId(), NetworkUtil.getNetworkWwn(network));
        zoneInfo.setEndPoints(Arrays.asList(new String[] { initiatorWwn, portWwn }));
        zoneInfo.setZoneName(zone.getName());
        zoneInfo.setExistingZone(zone.getExistingZone());
        zoneInfo.setCanBeRolledBack(false);
    }
    return zoneInfo;
}
Also used : NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone)

Example 19 with Zone

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

the class NetworkSystemDeviceImpl method getZonesToBeDeleted.

/**
 * Given a list of zones requested to be deleted, and a list of existing zones on the device,
 * this returns a list of zones to actually be deleted, along with a count of the number
 * of remaining zones after they are deleted.
 *
 * @param zones -- Zones requested to be deleted
 * @param existingZones -- on the device
 * @param remainingZones -- Integer[1] array that returns number of remaining zones
 * @return collection of zones to be deleted
 * @throws NetworkDeviceControllerException
 */
protected List<Zone> getZonesToBeDeleted(List<Zone> zones, Collection<Zone> existingZones, Integer[] remainingZones, Map<String, String> removedZoneResults) throws NetworkDeviceControllerException {
    // Zones that have members completely in a zone in the active zoneset already are
    // to be deleted.
    // Make a map of zone names to zones found on the switch.
    Map<String, Zone> activeZonesMap = new HashMap<String, Zone>();
    Map<String, Object> cimObjectPaths = new HashMap<String, Object>();
    for (Zone azone : existingZones) {
        if (azone != null) {
            activeZonesMap.put(azone.getName(), azone);
            cimObjectPaths.put(azone.getName(), azone.getCimObjectPath());
        }
    }
    remainingZones[0] = new Integer(activeZonesMap.size());
    // Check each zone to be deleted to see if it's matched by a zone in the active set.
    List<Zone> zonesToBeDeleted = new ArrayList<Zone>();
    for (Zone zone : zones) {
        Zone zoneInFabric = activeZonesMap.get(zone.getName());
        if (zoneInFabric != null) {
            boolean match = true;
            if (zone.getMembers() != null && !zone.getMembers().isEmpty()) {
                match = sameMembers(zoneInFabric, zone);
            }
            if (match) {
                Object cimObjectPath = cimObjectPaths.get(zone.getName());
                zone.setCimObjectPath(cimObjectPath);
                zonesToBeDeleted.add(zone);
                remainingZones[0]--;
            } else {
                removedZoneResults.put(zone.getName(), ERROR + " : The existing zone members do not match what is in the request.");
                _log.info("Zone " + zone.getName() + " was found but the members did not match");
            }
        } else {
            _log.info("Zone " + zone.getName() + " was not found in the active zone set. Nothing to do.");
            removedZoneResults.put(zone.getName(), NO_CHANGE);
        }
    }
    return zonesToBeDeleted;
}
Also used : HashMap(java.util.HashMap) Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) ArrayList(java.util.ArrayList)

Example 20 with Zone

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

the class BrocadeNetworkSMIS method getFabricZones.

@SuppressWarnings("unchecked")
public List<Zone> getFabricZones(WBEMClient client, String fabricId, String fabricWwn) throws WBEMException {
    List<Zone> zones = new ArrayList<Zone>();
    CIMInstance fabricIns = getFabricInstance(client, fabricId, fabricWwn);
    if (fabricIns != null) {
        CloseableIterator<CIMInstance> zoneItr = null;
        try {
            zoneItr = client.associatorInstances(fabricIns.getObjectPath(), _Brocade_ZoneInFabric, _Brocade_Zone, null, null, false, null);
            while (zoneItr.hasNext()) {
                Zone zone = getZoneFromZoneInstance(client, zoneItr.next(), false, false);
                zones.add(zone);
            }
        } 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) CIMInstance(javax.cim.CIMInstance)

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