use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class NetworkDeviceController method getExistingZonesMap.
/**
* This function wraps the logic for getting zones from the network system. The zones may have already
* been read in previous workflow steps during port assignment. To avoid another call into the network
* systems, these zones are stored in the workflow. In the case of "add initiators" workflow, only the
* new initiators's zones are read by port allocation. In this case, the new initiators zones are loaded
* from the workflow while the old initiators zones are retrieved from the network system.
*
* @param exportMaskUris -- the URI of the export mask being zones
* @param token -- the workflow step id
* @return a map of initiatorPort to the list if zones that already exist on the network system
*/
private Map<String, List<Zone>> getExistingZonesMap(Collection<URI> exportMaskUris, String token) {
// get existing zones from the switch, first check if the zones were retrieved by previous steps and cached in the workflow
Map<String, List<Zone>> zonesMap = (Map<String, List<Zone>>) WorkflowService.getInstance().loadWorkflowData(token, "zonemap");
// if the existing zones were not already retrieved and cached by other steps, retrieve them now
if (zonesMap == null) {
zonesMap = new HashMap<String, List<Zone>>();
} else {
_log.info("Existing zones were found in the workflow for initiators {}", zonesMap.keySet());
}
List<Initiator> exportInitiators = ExportUtils.getExportMasksInitiators(exportMaskUris, _dbClient);
Iterator<Initiator> itr = exportInitiators.iterator();
Initiator ini = null;
List<String> otherInitiators = new ArrayList<String>();
while (itr.hasNext()) {
ini = itr.next();
if (zonesMap.containsKey(ini.getInitiatorPort())) {
itr.remove();
} else {
otherInitiators.add(ini.getInitiatorPort());
}
}
if (!exportInitiators.isEmpty()) {
_log.info("Getting existing zones from network system for {} ", otherInitiators);
zonesMap.putAll(getInitiatorsZones(exportInitiators));
}
return zonesMap;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class NetworkDeviceController method updateZoningMap.
/**
* This method updates zoning map. This will mostly be called when volume(s) is/are removed
* from the ExportMask which is shared across two/more varrays and varrays do not have same
* storage ports which results in creating zoning based on the ports in the varray.
*
* lastReferenceZoneInfo contains the zones that were removed from the device,
* according to this if there is initiator in the zoningMap with just one storage port
* for which zone is removed then that entry is removed from the zoningMap.
* If initiator has more than one storage port in the zoningMap for the initiator then
* only storage port for which zone is removed is removed from the zoning map.
* ExportMasks with ImmutableZoningMap set are skipped.
*
* @param lastReferenceZoneInfo list of NetworkFCZoneInfo for the zones that are removed.
* @param exportGroupURI reference to exportGroup
* @param exportMaskURIs list of reference to exportMask
*/
private void updateZoningMap(List<NetworkFCZoneInfo> lastReferenceZoneInfo, URI exportGroupURI, List<URI> exportMaskURIs) {
List<URI> emURIs = new ArrayList<URI>();
if (exportMaskURIs == null || exportMaskURIs.isEmpty()) {
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup);
if (exportGroup != null && !exportMasks.isEmpty()) {
for (ExportMask mask : exportMasks) {
emURIs.add(mask.getId());
}
}
} else {
emURIs.addAll(exportMaskURIs);
}
for (URI emURI : emURIs) {
ExportMask exportMask = _dbClient.queryObject(ExportMask.class, emURI);
if (exportMask != null && !exportMask.getInactive() && !exportMask.fetchDeviceDataMapEntry(ExportMask.DeviceDataMapKeys.ImmutableZoningMap.name()).contains(Boolean.TRUE.toString())) {
for (NetworkFCZoneInfo zoneInfo : lastReferenceZoneInfo) {
StringSetMap existingZoningMap = exportMask.getZoningMap();
if (exportMask.getVolumes() == null) {
continue;
}
Set<String> exportMaskVolumes = exportMask.getVolumes().keySet();
if (existingZoningMap != null && zoneInfo.getVolumeId() != null && exportMaskVolumes.contains(zoneInfo.getVolumeId().toString()) && zoneInfo.getEndPoints().size() == 2) {
Initiator initiator = NetworkUtil.findInitiatorInDB(zoneInfo.getEndPoints().get(0), _dbClient);
List<StoragePort> storagePorts = NetworkUtil.findStoragePortsInDB(zoneInfo.getEndPoints().get(1), _dbClient);
for (StoragePort storagePort : storagePorts) {
if (initiator != null && storagePort != null) {
for (String initiatorId : existingZoningMap.keySet()) {
if (initiator.getId().toString().equals(initiatorId)) {
StringSet ports = existingZoningMap.get(initiatorId);
if (ports != null) {
if (ports.contains(storagePort.getId().toString())) {
ports.remove(storagePort.getId().toString());
if (ports.isEmpty()) {
exportMask.removeZoningMapEntry(initiatorId);
_log.info("Removing zoning map entry for initiator {}, in exportmask {}", initiatorId, emURI);
} else {
exportMask.addZoningMapEntry(initiatorId, ports);
_log.info("Removing storagePort " + storagePort.getId() + " from zoning map for initiator " + initiatorId + " in export mask " + emURI);
}
}
}
}
}
}
}
}
_dbClient.persistObject(exportMask);
}
}
}
}
use of com.emc.storageos.db.client.model.Initiator 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.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class NetworkScheduler method generateFullZoningMap.
/**
* Generates a zoning map that maps all initiators to all ports on the same Network.
*
* @param varrayURI - the ExportGroup varray
* @param mask - the Export Mask
* @param initiators - List of Initiators to be zoned
*/
public static void generateFullZoningMap(DbClient dbClient, URI varrayURI, ExportMask mask, Collection<Initiator> initiators) {
boolean changed = false;
Set<StoragePort> storagePorts = ExportMaskUtils.getPortsForExportMask(dbClient, mask, Transport.FC);
for (Initiator initiator : initiators) {
if (mask.getZoningMap() == null || mask.getZoningMap().get(initiator.getId().toString()) == null) {
_log.info(String.format("No zoning map entry for initiator %s (%s), will zone to all ports", initiator.getInitiatorPort(), initiator.getId()));
List<URI> targetPorts = findInitiatorTargetsInVarray(dbClient, varrayURI, initiator, storagePorts);
if (!targetPorts.isEmpty()) {
changed = true;
mask.addZoningMapEntry(initiator.getId().toString(), StringSetUtil.uriListToStringSet(targetPorts));
}
}
}
if (changed) {
// Update the mask to save the zoningMap entries.
dbClient.updateObject(mask);
}
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class ExportUtils method createVplexExportGroup.
/**
* Create an ExportGroup.
*
* @param vplex -- VPLEX StorageSystem
* @param array -- Array StorageSystem
* @param initiators -- Collection<Initiator> representing VPLEX back-end ports.
* @param virtualArrayURI
* @param projectURI
* @param tenantURI
* @param numPaths Value of maxPaths to be put in ExportGroup
* @param exportMask IFF non-null, will add the exportMask to the Export Group.
* @return newly created ExportGroup persisted in DB.
*/
public static ExportGroup createVplexExportGroup(DbClient dbClient, StorageSystem vplex, StorageSystem array, Collection<Initiator> initiators, URI virtualArrayURI, URI projectURI, URI tenantURI, int numPaths, ExportMask exportMask) {
String groupName = getExportGroupName(vplex, array) + "_" + UUID.randomUUID().toString().substring(28);
if (exportMask != null) {
String arrayName = array.getSystemType().replace("block", "") + array.getSerialNumber().substring(array.getSerialNumber().length() - 4);
groupName = exportMask.getMaskName() + "_" + arrayName;
}
// No existing group has the mask, let's create one.
ExportGroup exportGroup = new ExportGroup();
exportGroup.setId(URIUtil.createId(ExportGroup.class));
exportGroup.setLabel(groupName);
exportGroup.setProject(new NamedURI(projectURI, exportGroup.getLabel()));
exportGroup.setVirtualArray(vplex.getVirtualArray());
exportGroup.setTenant(new NamedURI(tenantURI, exportGroup.getLabel()));
exportGroup.setGeneratedName(groupName);
exportGroup.setVolumes(new StringMap());
exportGroup.setOpStatus(new OpStatusMap());
exportGroup.setVirtualArray(virtualArrayURI);
exportGroup.setNumPaths(numPaths);
// Add the initiators into the ExportGroup.
for (Initiator initiator : initiators) {
exportGroup.addInitiator(initiator);
}
// If we have an Export Mask, add it into the Export Group.
if (exportMask != null) {
exportGroup.addExportMask(exportMask.getId());
}
// Persist the ExportGroup
dbClient.createObject(exportGroup);
_log.info(String.format("Returning new ExportGroup %s", exportGroup.getLabel()));
return exportGroup;
}
Aggregations