use of com.emc.storageos.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class CinderExportOperations method storeITLMappingInVolume.
/**
* Create Initiator Target LUN Mapping as an extension in volume object
*
* @param volume
* - volume in which ITL to be added
* @param exportMask
* - exportMask in which the volume is to be added
* @param targetLunId
* - integer value of host LUN id on which volume is accessible.
*/
private void storeITLMappingInVolume(Map<URI, Integer> volumeToTargetLunMap, ExportMask exportMask) {
log.debug("START - createITLMappingInVolume");
for (URI volumeURI : volumeToTargetLunMap.keySet()) {
Integer targetLunId = volumeToTargetLunMap.get(volumeURI);
Volume volume = dbClient.queryObject(Volume.class, volumeURI);
StringSetMap zoningMap = exportMask.getZoningMap();
Set<String> zoningMapKeys = zoningMap.keySet();
int initiatorIndex = 0;
for (String initiator : zoningMapKeys) {
Initiator initiatorObj = dbClient.queryObject(Initiator.class, URI.create(initiator));
String initiatorWWPN = initiatorObj.getInitiatorPort().replaceAll(CinderConstants.COLON, "");
StringSet targetPorts = zoningMap.get(initiator);
int targetIndex = 0;
for (String target : targetPorts) {
StoragePort targetPort = dbClient.queryObject(StoragePort.class, URI.create(target));
String targetPortWWN = targetPort.getPortNetworkId().replaceAll(CinderConstants.COLON, "");
// Format is - <InitiatorWWPN>-<TargetWWPN>-<LunId>
String itl = initiatorWWPN + "-" + targetPortWWN + "-" + String.valueOf(targetLunId);
// ITL keys will be formed as ITL-00, ITL-01, ITL-10, ITL-11 so on
String itlKey = CinderConstants.PREFIX_ITL + String.valueOf(initiatorIndex) + String.valueOf(targetIndex);
log.info(String.format("Adding ITL %s with key %s", itl, itlKey));
StringMap extensionsMap = volume.getExtensions();
if (null == extensionsMap) {
extensionsMap = new StringMap();
extensionsMap.put(itlKey, itl);
volume.setExtensions(extensionsMap);
} else {
volume.getExtensions().put(itlKey, itl);
}
targetIndex++;
}
initiatorIndex++;
}
dbClient.updateAndReindexObject(volume);
}
log.debug("END - createITLMappingInVolume");
}
use of com.emc.storageos.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class VPlexBackEndOrchestratorUtil method configureZoning.
public static StringSetMap configureZoning(Map<URI, List<List<StoragePort>>> portGroup, Map<String, Map<URI, Set<Initiator>>> initiatorGroup, Map<URI, NetworkLite> networkMap, StoragePortsAssigner assigner, Map<URI, String> initiatorSwitchMap, Map<URI, Map<String, List<StoragePort>>> switchStoragePortsMap, Map<URI, String> portSwitchMap) {
StringSetMap zoningMap = new StringSetMap();
// Set up a map to track port usage so that we can use all ports more or less equally.
Map<StoragePort, Integer> portUsage = new HashMap<StoragePort, Integer>();
// check if switch affinity is on
boolean isSwitchAffinity = false;
if (initiatorSwitchMap != null && !initiatorSwitchMap.isEmpty() && switchStoragePortsMap != null && !switchStoragePortsMap.isEmpty()) {
isSwitchAffinity = true;
}
// with one port. This will ensure not to violate four paths per director.
for (String director : initiatorGroup.keySet()) {
for (URI networkURI : initiatorGroup.get(director).keySet()) {
NetworkLite net = networkMap.get(networkURI);
for (Initiator initiator : initiatorGroup.get(director).get(networkURI)) {
// If there are no ports on the initiators network, too bad...
if (portGroup.get(networkURI) == null) {
_log.info(String.format("%s -> no ports in network", initiator.getInitiatorPort()));
continue;
}
// find a port for the initiator
List<StoragePort> assignablePorts = portGroup.get(networkURI).iterator().next();
if (isSwitchAffinity) {
// find the ports with the same switch as the initiator
String switchName = initiatorSwitchMap.get(initiator.getId());
if (!switchName.equals(NullColumnValueGetter.getNullStr())) {
Map<String, List<StoragePort>> switchMap = switchStoragePortsMap.get(networkURI);
if (switchMap != null) {
List<StoragePort> switchPorts = switchMap.get(switchName);
if (switchPorts != null && !switchPorts.isEmpty()) {
_log.info(String.format("Found the same switch ports, switch is %s", switchName));
assignablePorts = switchPorts;
} else {
_log.info(String.format("Switch affinity is not honored, because no storage port from the switch %s for the initiator %s", switchName, initiator.getInitiatorPort()));
}
}
}
}
StoragePort storagePort = assignPortToInitiator(assigner, assignablePorts, net, initiator, portUsage, null);
if (storagePort != null) {
_log.info(String.format("%s %s %s %s -> %s %s %s", director, net.getLabel(), initiator.getInitiatorPort(), initiatorSwitchMap.get(initiator.getId()), storagePort.getPortNetworkId(), storagePort.getPortName(), portSwitchMap.get(storagePort.getId())));
StringSet ports = new StringSet();
ports.add(storagePort.getId().toString());
zoningMap.put(initiator.getId().toString(), ports);
} else {
_log.info(String.format("A port could not be assigned for %s %s %s", director, net.getLabel(), initiator.getInitiatorPort()));
}
}
}
}
return zoningMap;
}
use of com.emc.storageos.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class VPlexVnxMaskingOrchestrator method configureZoning.
@Override
public StringSetMap configureZoning(Map<URI, List<List<StoragePort>>> portGroup, Map<String, Map<URI, Set<Initiator>>> initiatorGroup, Map<URI, NetworkLite> networkMap, StoragePortsAssigner assigner, Map<URI, String> initiatorSwitchMap, Map<URI, Map<String, List<StoragePort>>> switchStoragePortsMap, Map<URI, String> portSwitchMap) {
StringSetMap zoningMap = new StringSetMap();
// Set up a map to track port usage so that we can use all ports more or less equally.
Map<StoragePort, Integer> portAUsage = new HashMap<StoragePort, Integer>();
Map<StoragePort, Integer> portBUsage = new HashMap<StoragePort, Integer>();
// check if switch affinity is on
boolean isSwitchAffinity = false;
if (initiatorSwitchMap != null && !initiatorSwitchMap.isEmpty() && switchStoragePortsMap != null && !switchStoragePortsMap.isEmpty()) {
isSwitchAffinity = true;
}
// with one port.
for (String director : initiatorGroup.keySet()) {
for (URI networkURI : initiatorGroup.get(director).keySet()) {
NetworkLite net = networkMap.get(networkURI);
for (Initiator initiator : initiatorGroup.get(director).get(networkURI)) {
// If there are no ports on the initiators network, too bad...
if (portGroup.get(networkURI) == null) {
_log.info(String.format("%s -> no ports in network", initiator.getInitiatorPort()));
continue;
}
List<StoragePort> assignablePortsA = new ArrayList<StoragePort>();
List<StoragePort> assignablePortsB = new ArrayList<StoragePort>();
if (isSwitchAffinity) {
// find the ports with the same switch as the initiator
String switchName = initiatorSwitchMap.get(initiator.getId());
if (!switchName.equals(NullColumnValueGetter.getNullStr())) {
Map<String, List<StoragePort>> switchMap = switchStoragePortsMap.get(networkURI);
if (switchMap != null) {
List<StoragePort> switchPorts = switchMap.get(switchName);
if (switchPorts != null && !switchPorts.isEmpty()) {
_log.info(String.format("Found the same switch ports, switch is %s", switchName));
for (StoragePort port : switchPorts) {
String groupId = port.getPortGroup();
if (groupId != null && groupId.equals(SPA)) {
assignablePortsA.add(port);
} else if (groupId != null && groupId.equals(SPB)) {
assignablePortsB.add(port);
}
}
}
}
}
}
StringSet ports = new StringSet();
// Get an A Port
String aPortName = " ", bPortName = " ";
if (assignablePortsA.isEmpty()) {
assignablePortsA = portGroup.get(networkURI).iterator().next();
}
StoragePort portA = VPlexBackEndOrchestratorUtil.assignPortToInitiator(assigner, assignablePortsA, net, initiator, portAUsage, SPA);
if (portA != null) {
aPortName = portA.getPortName();
ports.add(portA.getId().toString());
}
// Get a B Port
if (assignablePortsB.isEmpty()) {
assignablePortsB = portGroup.get(networkURI).iterator().next();
}
StoragePort portB = VPlexBackEndOrchestratorUtil.assignPortToInitiator(assigner, portGroup.get(networkURI).iterator().next(), net, initiator, portBUsage, SPB);
if (portB != null) {
bPortName = portB.getPortName();
ports.add(portB.getId().toString());
}
_log.info(String.format("%s %s %s %s -> %s %s %s %s", director, net.getLabel(), initiator.getInitiatorPort(), initiatorSwitchMap.get(initiator.getId()), aPortName, portSwitchMap.get(portA.getId()), bPortName, portSwitchMap.get(portB.getId())));
zoningMap.put(initiator.getId().toString(), ports);
}
}
}
return zoningMap;
}
use of com.emc.storageos.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class VolumeVpoolChangeTaskCompleter method rollbackMaskZoningMap.
/**
* Restores the zonemaps of the export masks impacted by change vpool operation
*
* @param dbClient the DB client
*/
private void rollbackMaskZoningMap(DbClient dbClient) {
if (maskToZoningMap == null || maskToZoningMap.isEmpty()) {
_log.info("There are no masks' zonemaps to be restore.");
return;
}
List<ExportMask> masks = dbClient.queryObject(ExportMask.class, maskToZoningMap.keySet());
for (ExportMask mask : masks) {
StringSetMap zoningMap = maskToZoningMap.get(mask.getId());
mask.getZoningMap().clear();
mask.addZoningMap(zoningMap);
}
dbClient.updateObject(masks);
}
use of com.emc.storageos.db.client.model.StringSetMap in project coprhd-controller by CoprHD.
the class ZoningAddPathsCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
if (status == Operation.Status.ready && !exportMaskAdjustedPathMap.isEmpty()) {
log.info("Updating export mask zoning map in DB");
for (Map.Entry<URI, Map<URI, List<URI>>> maskPathEntry : exportMaskAdjustedPathMap.entrySet()) {
URI maskURI = maskPathEntry.getKey();
Map<URI, List<URI>> newPaths = maskPathEntry.getValue();
ExportMask exportMask = dbClient.queryObject(ExportMask.class, maskURI);
// update zoning map
StringSetMap zoningMap = exportMask.getZoningMap();
if (zoningMap != null && !zoningMap.isEmpty()) {
for (Map.Entry<URI, List<URI>> entry : newPaths.entrySet()) {
URI initiator = entry.getKey();
List<URI> ports = entry.getValue();
StringSet existingPorts = zoningMap.get(initiator.toString());
Set<String> newPorts = StringSetUtil.uriListToSet(ports);
if (existingPorts != null) {
existingPorts.addAll(newPorts);
} else {
existingPorts = new StringSet(newPorts);
}
zoningMap.put(initiator.toString(), existingPorts);
}
} else {
for (Map.Entry<URI, List<URI>> entry : newPaths.entrySet()) {
zoningMap.put(entry.getKey().toString(), StringSetUtil.uriListToStringSet(entry.getValue()));
}
}
dbClient.updateObject(exportMask);
}
}
} catch (Exception e) {
log.error(String.format("Failed updating status for ExportMaskAddPaths - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
Aggregations