use of com.emc.storageos.networkcontroller.NetworkFCZoneInfo in project coprhd-controller by CoprHD.
the class NetworkDeviceController method zoneExportRemoveInitiators.
/**
* This will remove zones for all the initiators in the NetworkZoningParam zoneMap.
* Note: these arguments (except stepId) must match zoneExportRemoveInitiatorsMethod above.
* This routine executes as a Workflow Step.
*
* @param zoningParams -- List of NetworkZoningParam zoning parameter blocks corresponding to ExportMasks
* @param stepId -- step id in Workflow
* @return
* @throws ControllerException
*/
public boolean zoneExportRemoveInitiators(List<NetworkZoningParam> zoningParams, String stepId) throws ControllerException {
boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(stepId);
boolean isOperationSuccessful = false;
TaskCompleter taskCompleter = null;
if (zoningParams.isEmpty()) {
_log.info("zoningParams is empty, returning");
WorkflowStepCompleter.stepSucceded(stepId);
return true;
}
NetworkFCContext context = new NetworkFCContext();
boolean status = false;
URI exportGroupId = zoningParams.get(0).getExportGroupId();
URI virtualArray = zoningParams.get(0).getVirtualArray();
_log.info(String.format("Entering zoneExportRemoveInitiators for ExportGroup: %s", zoningParams.get(0).getExportGroupDisplay()));
try {
if (!checkZoningRequired(stepId, virtualArray)) {
return true;
}
context.setAddingZones(false);
// Get the zoning targets to be removed.
List<NetworkFCZoneInfo> zoneInfos = _networkScheduler.getZoningRemoveTargets(zoningParams, null);
context.getZoneInfos().addAll(zoneInfos);
logZones(zoneInfos);
// If there are no zones to do, we were successful.
if (context.getZoneInfos().isEmpty()) {
isOperationSuccessful = true;
WorkflowStepCompleter.stepSucceded(stepId);
return true;
}
// Create a local completer to handle DB cleanup in the case of failure.
taskCompleter = new ZoneReferencesRemoveCompleter(NetworkUtil.getFCZoneReferences(context.getZoneInfos()), true, stepId);
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_024);
// Now call removeZones to remove all the required zones.
BiosCommandResult result = addRemoveZones(exportGroupId, context.getZoneInfos(), true);
status = result.isCommandSuccess();
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_025);
// Update the workflow state.
completeWorkflowState(taskCompleter, stepId, "zoneExportRemoveInitiators", result, null);
if (result.isCommandSuccess()) {
isOperationSuccessful = true;
}
return status;
} catch (Exception ex) {
_log.error("Exception zoning remove initiators", ex);
ServiceError svcError = NetworkDeviceControllerException.errors.zoneExportRemoveInitiatorsFailed(ex.getMessage(), ex);
taskCompleter.error(_dbClient, svcError);
WorkflowStepCompleter.stepFailed(stepId, svcError);
return status;
} finally {
// clean up the zoning map too if the result is success or a rollback
if (isOperationSuccessful || isRollback) {
removeInitiatorsFromZoningMap(zoningParams);
}
}
}
use of com.emc.storageos.networkcontroller.NetworkFCZoneInfo in project coprhd-controller by CoprHD.
the class NetworkScheduler method generateRequestedZonesForExportMask.
/**
* The ExportMask has a valid zoningMap, which identifies the zones that
* the StoragePortsAssigner wanted created. So we create specifically those zones.
*
* @param varrayURI Varray (Neighborhood) URI
* @param exportGroup ExportGroup object
* @param exportMask ExportMask object
* @param volumeURIs - List of volume URIs using this ExportMask
* @param existingZonesMap a map of initiator ports WWN to its existing zones
* @param checkZones Flag to enable or disable zoning check on a Network System
* @return List<NetworkFCZoneInfO representing zones to be created.
* @throws DeviceControllerException
*/
private List<NetworkFCZoneInfo> generateRequestedZonesForExportMask(URI varrayURI, ExportGroup exportGroup, ExportMask exportMask, Collection<URI> volumeURIs, Map<String, List<Zone>> existingZonesMap, boolean checkZones) throws DeviceControllerException {
List<NetworkFCZoneInfo> zoneInfos = new ArrayList<NetworkFCZoneInfo>();
if (exportMask.getZoningMap() == null) {
_log.info(String.format("No zone map Export Mask %s (%s) systemCreated %s", exportMask.getMaskName(), exportMask.getId(), exportMask.getCreatedBySystem()));
return zoneInfos;
}
Set<Initiator> initiators = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, exportMask, Transport.FC);
for (Initiator initiator : initiators) {
StringSet portIds = exportMask.getZoningMap().get(initiator.getId().toString());
if (portIds != null) {
for (String portId : portIds) {
StoragePort sp = _dbClient.queryObject(StoragePort.class, URI.create(portId));
if (null != sp && sp.getTaggedVirtualArrays() != null && sp.getTaggedVirtualArrays().contains(varrayURI.toString())) {
boolean placedZone = placeZone(zoneInfos, exportGroup, varrayURI, initiator, sp, volumeURIs, existingZonesMap.get(initiator.getInitiatorPort()), checkZones);
if (placedZone == false && checkZones) {
throw DeviceControllerException.exceptions.cannotMatchSanStoragePortInitiatorForVolume(sp.getPortName(), formatWWN(initiator.getInitiatorPort()), volumeURIs.toString());
}
}
}
}
}
return zoneInfos;
}
use of com.emc.storageos.networkcontroller.NetworkFCZoneInfo in project coprhd-controller by CoprHD.
the class NetworkScheduler method getZoningTargetsForPaths.
/**
* Returns a list of zoning targets for adding paths to the export mask.
*
* @param exportGroup ExportGroup
* @param exportMaskURIs export mask URIs
* @param path Map of initiator URI to List of storage port URIs
* @param zonesMap a list of existing zones mapped by the initiator port WWN
* @param dbClient
* @return List of Zones (NetworkFCZoneInfo)
* @throws DeviceControllerException
*/
public List<NetworkFCZoneInfo> getZoningTargetsForPaths(URI storageSystemURI, ExportGroup exportGroup, Collection<URI> exportMaskURIs, Map<URI, List<URI>> paths, Map<String, List<Zone>> zonesMap, DbClient dbClient) throws DeviceControllerException {
List<NetworkFCZoneInfo> zones = new ArrayList<NetworkFCZoneInfo>();
if (!isZoningRequired(dbClient, exportGroup.getVirtualArray())) {
_log.info("Zoning not required, returning empty zones list");
return zones;
}
for (URI maskURI : exportMaskURIs) {
ExportMask mask = _dbClient.queryObject(ExportMask.class, maskURI);
StringMap volumeMap = mask.getVolumes();
if (volumeMap == null || volumeMap.isEmpty()) {
_log.info(String.format("There are no volumes in the export mask %s, skipping", mask.getMaskName()));
continue;
}
List<URI> maskVolumes = StringSetUtil.stringSetToUriList(volumeMap.keySet());
List<ExportGroup> maskExportGroups = ExportMaskUtils.getExportGroups(dbClient, mask);
// Filter the paths based on the initiators in zoningMap of this ExportMask
Map<URI, List<URI>> pathsForMask = new HashMap<URI, List<URI>>();
for (String initiatorString : mask.getInitiators()) {
URI initiatorKey = URI.create(initiatorString);
if (paths.containsKey(initiatorKey)) {
pathsForMask.put(initiatorKey, paths.get(initiatorKey));
}
}
// Use the intersection of the volumes in the ExportMask and ExportGroup.
for (ExportGroup group : maskExportGroups) {
if (group.getVolumes() != null) {
List<URI> volumes = new ArrayList<URI>(maskVolumes);
volumes.retainAll(StringSetUtil.stringSetToUriList(group.getVolumes().keySet()));
zones.addAll(getZoningTargetsForPaths(group, volumes, exportGroup.getVirtualArray(), pathsForMask, zonesMap));
}
}
// Check for zones needed in alternate varray for VPLEX cross-connected
if (exportGroup.hasAltVirtualArray(storageSystemURI.toString())) {
URI altVirtualArray = URI.create(exportGroup.getAltVirtualArrays().get(storageSystemURI.toString()));
if (isZoningRequired(dbClient, altVirtualArray)) {
for (ExportGroup group : maskExportGroups) {
if (group.getVolumes() != null) {
List<URI> volumes = new ArrayList<URI>(maskVolumes);
volumes.retainAll(StringSetUtil.stringSetToUriList(group.getVolumes().keySet()));
zones.addAll(getZoningTargetsForPaths(group, volumes, altVirtualArray, pathsForMask, zonesMap));
}
}
}
}
}
return zones;
}
use of com.emc.storageos.networkcontroller.NetworkFCZoneInfo in project coprhd-controller by CoprHD.
the class NetworkScheduler method placeZones.
/**
* Select the network device and VSAN or Brocade Fabric for the host/volume zoning.
*
* The selection is based on the end points (initiator and storage port) and
* the availability of a network device that has ports connections to both
* end points. If a fabric can't be identified with both endpoints, we fall back to
* looking for a fabric with at least the storagePort discovered.
*
* @param exportGroupUri Export Group URI
* @param varrayUri Virtual Array URI
* @param protocol String (FC for this to do anything)
* @param initiatorPort The WWN of the initiator
* @param storagePort The StoragePort object
* @param hostName Used for generating the zone name.
* @param existingZones a list of existing zones for the initiator
* @param checkZones Flag to enable or disable zoning check on a Network System
*
* @return NetworkFabricInfo configured for adding zones
*/
private NetworkFCZoneInfo placeZones(URI exportGroupUri, URI varrayUri, String protocol, String initiatorPort, StoragePort storagePort, String hostName, List<Zone> existingZones, boolean checkZones) throws DeviceControllerException {
initiatorPort = formatWWN(initiatorPort);
String storagePortWwn = formatWWN(storagePort.getPortNetworkId());
if (Transport.FC != StorageProtocol.block2Transport(protocol)) {
return null;
}
_log.info("Placing a zone for initiator {} and port {}", initiatorPort, storagePortWwn);
// do some validation
NetworkLite iniNet = NetworkUtil.getEndpointNetworkLite(initiatorPort, _dbClient);
NetworkLite portNet = getStoragePortNetwork(storagePort);
if (iniNet == null || portNet == null || !NetworkUtil.checkInitiatorAndPortConnected(iniNet, portNet)) {
_log.debug(String.format("Initiator %s could not be paired with port %s", initiatorPort, storagePortWwn));
return null;
}
// False we will use the existing FCZoneReference info
if (!checkZones) {
_log.debug("Check Zones flag is false. Finding FCZoneReference for initiator {} and port {}", initiatorPort, storagePortWwn);
// Find the FCZoneReference in ViPR for the port-initiator key and the network
String key = FCZoneReference.makeEndpointsKey(initiatorPort, storagePortWwn);
List<FCZoneReference> fcZoneRefs = getFCZoneReferencesForKey(key);
FCZoneReference refTemplate = DataObjectUtils.findByProperty(fcZoneRefs, "groupUri", exportGroupUri);
if (refTemplate != null) {
_log.info("Already existing FCZoneReferences for initiator {} and port {} will be replicated for new volumes.", initiatorPort, storagePortWwn);
return createZoneInfoForRef(refTemplate, null, initiatorPort, storagePortWwn, NetworkUtil.getEndpointNetworkLite(initiatorPort, _dbClient), exportGroupUri);
} else {
_log.info("FCZoneReferences doesnt exist for initiator {} and port {} for replication.", initiatorPort, storagePortWwn);
return null;
}
} else {
_log.debug("Check Zones flag is false. Placing a zone for initiator {} and port {}", initiatorPort, storagePortWwn);
// If the zone already exists, just return its reference
NetworkFCZoneInfo zoneInfo = getZoneInfoForExistingZone(iniNet, initiatorPort, storagePort.getPortNetworkId(), existingZones);
if (zoneInfo != null) {
zoneInfo.setExportGroup(exportGroupUri);
_log.info("Already existing zone {} for initiator {} and port {} will be used.", new Object[] { zoneInfo.getZoneName(), initiatorPort, storagePortWwn });
return zoneInfo;
}
_log.debug("Could not find an existing zone for initiator {} and port {} to use." + "A new zone will be created.", new Object[] { initiatorPort, storagePortWwn });
// Create a the list of end points -
List<String> endPoints = Arrays.asList(new String[] { initiatorPort, storagePortWwn });
List<NetworkSystem> networkSystems = getZoningNetworkSystems(iniNet, portNet);
if (networkSystems.isEmpty()) {
_log.info(String.format("Could not find a network system with connection to storage port %s", storagePortWwn));
throw DeviceControllerException.exceptions.cannotFindSwitchConnectionToStoragePort(storagePortWwn);
}
// 2. Select the network system to use
NetworkSystem networkSystem = networkSystems.get(0);
// 3. identify an alternate network device, if any
_log.debug("Network system {} was selected to be the primary network system. " + "Trying to select an alternate network system.", networkSystem.getNativeGuid());
NetworkSystem altNetworkSystem = networkSystem;
for (NetworkSystem system : networkSystems) {
if (altNetworkSystem != system) {
altNetworkSystem = system;
_log.debug("Network system {} was selected to be the alternate network system.", altNetworkSystem.getNativeGuid());
break;
}
}
// 4. create the response
NetworkFCZoneInfo networkFabricInfo = null;
if (networkSystem != null) {
networkFabricInfo = new NetworkFCZoneInfo(networkSystem.getId(), iniNet.getNativeId(), NetworkUtil.getNetworkWwn(iniNet));
networkFabricInfo.getEndPoints().addAll(endPoints);
networkFabricInfo.setAltNetworkDeviceId(URI.create(altNetworkSystem.getId().toString()));
networkFabricInfo.setExportGroup(exportGroupUri);
networkFabricInfo.setCanBeRolledBack(false);
nameZone(networkFabricInfo, networkSystem.getSystemType(), hostName, initiatorPort, storagePort, !portNet.equals(iniNet));
}
return networkFabricInfo;
}
}
use of com.emc.storageos.networkcontroller.NetworkFCZoneInfo in project coprhd-controller by CoprHD.
the class NetworkScheduler method placeZone.
/**
* Place a zone described by its initiator and port, and add it to the zoneInfos list.
* ZoneReferences and zones will be added for all volumes matching the storage port's device.
*
* @param zoneInfos List<NetworkFCZoneInfo> list of zones being built
* @param exportGroup ExportGroup
* @param varrayURI VirtualArray (Neighborhood) URI
* @param initiator Initiator
* @param sp StoragePort
* @param volumeURIs
* @param existingZones zones that already exist on the network system
* @param checkZones Flag to enable or disable zoning check on a Network System
*
* @return true if could place the zone
*/
private boolean placeZone(List<NetworkFCZoneInfo> zoneInfos, ExportGroup exportGroup, URI varrayURI, Initiator initiator, StoragePort sp, Collection<URI> volumeURIs, List<Zone> existingZones, boolean checkZones) {
boolean foundMatch = false;
NetworkFCZoneInfo zoneInfo = placeZones(exportGroup.getId(), varrayURI, initiator.getProtocol(), formatWWN(initiator.getInitiatorPort()), sp, initiator.getHostName(), existingZones, checkZones);
if (zoneInfo != null) {
for (URI volumeURI : volumeURIs) {
BlockObject volume = BlockObject.fetch(_dbClient, volumeURI);
// If the volume is from a different device, don't create a reference.
if (!volume.getStorageController().equals(sp.getStorageDevice())) {
continue;
}
NetworkFCZoneInfo volZoneInfo = zoneInfo.clone();
volZoneInfo.setVolumeId(volumeURI);
zoneInfos.add(volZoneInfo);
}
foundMatch = true;
}
return foundMatch;
}
Aggregations