use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class AbstractDefaultMaskingOrchestrator method maskAppliesToMultipleHosts.
/**
* Check to see if this mask applies to multiple hosts already.
* Helps us to determine if this is a qualifying mask for brownfield
*
* @param mask
* export mask
* @return true if the mask has initiators from multiple hosts
*/
protected boolean maskAppliesToMultipleHosts(ExportMask mask) {
Set<URI> existingMaskHosts = new HashSet<URI>();
Set<URI> initiatorIds = ExportMaskUtils.getAllInitiatorsForExportMask(_dbClient, mask);
for (URI initiatorId : initiatorIds) {
// We should have a non-null initiator URI at this point
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorId);
if (initiator == null) {
_log.info(String.format("maskAppliesToMultipleHosts - Initiator %s does not exist in DB", initiatorId.toString()));
continue;
}
existingMaskHosts.add(initiator.getHost());
}
return existingMaskHosts.size() > 1;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class AbstractDefaultMaskingOrchestrator method processInitiators.
/**
* A utility for processing initiators and updating data structures. The data
* structures are for mapping an initiator reference on the array, which is
* in terms of a WWN/IQN, to an initiator reference in ViPR, which is in terms of
* URI. There's an optional parameter to return a list of host URIs referenced by
* the list of initiators. There's an optional parameter to return a Multimap of
* compute resource to a list of array port WWNs.
*
* @param exportGroup
* [in] - ExportGroup object
* @param initiators
* [in] - Initiator objects to process
* @param portNames
* [out] - Port names/WWNs of the initiators
* @param portNameToInitiatorURI
* [out] - Map of port name/WWN to initiator URI
* @param hostURIs
* [out] - Optional. List of URIs of the hosts that list of
* initiators point to.
* @param computeResourceToPortNames
* [out] - Optional. Multimap of compute String
* name to List of portNames.
*/
protected void processInitiators(ExportGroup exportGroup, Collection<Initiator> initiators, Collection<String> portNames, Map<String, URI> portNameToInitiatorURI, Collection<URI> hostURIs, ListMultimap<String, String> computeResourceToPortNames) {
for (Initiator initiator : initiators) {
String normalizedName = Initiator.normalizePort(initiator.getInitiatorPort());
portNames.add(normalizedName);
portNameToInitiatorURI.put(normalizedName, initiator.getId());
if (hostURIs != null) {
if (!NullColumnValueGetter.isNullURI(initiator.getHost()) && !hostURIs.contains(initiator.getHost())) {
hostURIs.add(initiator.getHost());
}
}
if (computeResourceToPortNames != null) {
String computeResourceId;
if (exportGroup != null && exportGroup.forCluster()) {
computeResourceId = initiator.getClusterName();
} else {
URI hostURI = initiator.getHost();
if (hostURI == null) {
// Bogus URI for those initiators without a host object,
// helps maintain a good map. We want to put bunch up the non-host
// initiators together.
hostURI = NullColumnValueGetter.getNullURI();
}
computeResourceId = hostURI.toString();
}
computeResourceToPortNames.put(computeResourceId, normalizedName);
}
}
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class AbstractDefaultMaskingOrchestrator method determineInitiatorToExportMaskPlacements.
/**
* Routine will examine the ExportGroup object's ExportMask and the passed in map of
* compute-resource-to-initiators map to produce a mapping of the ExportMasks'
* initiator port name to a list of ExportMask URIs.
*
* @param exportGroup
* [in] - ExportGroup object to examine
* @param storage
* @param computeResourceToInitiators
* [in] - Mapping of compute resource string key to
* list of Initiator URIs. @return Map of String to set of URIs. The key will be
* Initiator.normalizePort(initiator.portName).
* @param partialMasks
* [out] - list of masks that were found to be "partial" masks, where there are multiple masks that make
* up one
* compute resource
* Value will be set of ExportMask URIs.
*/
protected Map<String, Set<URI>> determineInitiatorToExportMaskPlacements(ExportGroup exportGroup, URI storage, Map<String, List<URI>> computeResourceToInitiators, Map<String, Set<URI>> initiatorToExportMapOnArray, Map<String, URI> portNameToInitiatorURI, Set<URI> partialMasks) {
Map<String, Set<URI>> initiatorToExportMaskURIMap = new HashMap<String, Set<URI>>();
Map<String, Set<URI>> computeResourceToExportMaskMap = ExportMaskUtils.mapComputeResourceToExportMask(_dbClient, exportGroup, storage);
Set<URI> allExportMaskURIs = new HashSet<>();
// associated with the ExportGroup
for (Map.Entry<String, List<URI>> entry : computeResourceToInitiators.entrySet()) {
String computeResource = entry.getKey();
List<URI> initiatorSet = entry.getValue();
if (computeResourceToExportMaskMap.get(computeResource) != null) {
for (URI exportMaskURI : computeResourceToExportMaskMap.get(computeResource)) {
if (exportMaskURI == null) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - No ExportMask for compute resource %s in ExportGroup %s", computeResource, exportGroup.getLabel()));
continue;
}
for (URI initiatorURI : initiatorSet) {
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
if (initiator == null) {
continue;
}
String normalizedName = Initiator.normalizePort(initiator.getInitiatorPort());
Set<URI> exportMaskURIs = initiatorToExportMaskURIMap.get(normalizedName);
if (exportMaskURIs == null) {
exportMaskURIs = new TreeSet<URI>();
initiatorToExportMaskURIMap.put(normalizedName, exportMaskURIs);
}
exportMaskURIs.add(exportMaskURI);
}
}
}
}
// when combined, make up a cluster masking view
for (Map.Entry<String, Set<URI>> entry : initiatorToExportMapOnArray.entrySet()) {
allExportMaskURIs.addAll(entry.getValue());
}
Collection<URI> volumes = new HashSet<URI>();
if (exportGroup.getVolumes() != null) {
volumes = Collections2.transform(exportGroup.getVolumes().keySet(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
}
ExportPathParams exportPathParams = _blockScheduler.calculateExportPathParamForVolumes(volumes, 0, storage, exportGroup.getId());
_log.info(String.format("determineInitiatorToExportMaskPlacements - ExportGroup=%s, exportPathParams=%s", exportGroup.getId().toString(), exportPathParams));
URI portGroup = exportPathParams.getPortGroup();
_log.info(String.format("Port group: %s", portGroup));
// Update mapping based on what is seen on the array
for (Map.Entry<String, Set<URI>> entry : initiatorToExportMapOnArray.entrySet()) {
String portName = entry.getKey();
// Validate this initiator and determine if it exists in the database
URI initiatorURI = portNameToInitiatorURI.get(portName);
if (initiatorURI == null) {
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(portName), uris);
if (!uris.iterator().hasNext()) {
// There is no such initiator
_log.info(String.format("determineInitiatorToExportMaskPlacements - Could not find initiator port %s in DB", portName));
continue;
}
initiatorURI = uris.iterator().next();
}
// We should have a non-null initiator URI at this point
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorURI);
if (initiator == null) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Initiator %s does not exist in DB", initiatorURI.toString()));
continue;
}
_log.info(String.format("determineInitiatorToExportMaskPlacements - Scanning masks that contain initiator %s to see if those masks qualify for consideration for re-use", initiator.getInitiatorPort()));
// This container is for capturing those ExportMasks that we find to
// be matching based on the initiators, but unusable based on the
// StoragePorts that the mask has. Basically, in order for a mask to
// be considered a match, the initiators have to match, but the
// StoragePorts have to be in the same Network as the ExportGroup's
// VArray Network.
Map<URI, Map<String, String>> masksWithUnmatchedStoragePorts = new HashMap<URI, Map<String, String>>();
// Take a look at the ExportMask's initiators to see what compute resource that they support.
String computeResource = ExportUtils.computeResourceForInitiator(exportGroup, initiator);
List<URI> uriList = computeResourceToInitiators.get(computeResource);
List<String> portsForComputeResource = new ArrayList<String>();
Iterator<Initiator> iterator = _dbClient.queryIterativeObjects(Initiator.class, uriList);
while (iterator.hasNext()) {
portsForComputeResource.add(iterator.next().getInitiatorPort());
}
// At this point we have a non-null initiator object that we can use in the mapping
Map<URI, Integer> maskToTotalMatchingPorts = new HashMap<URI, Integer>();
int totalPorts = 0;
Set<URI> candidateExportMaskURIs = new HashSet<URI>();
Set<URI> exportMaskURIs = entry.getValue();
for (URI exportMaskURI : exportMaskURIs) {
ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
if (mask == null || mask.getInactive()) {
continue;
}
_log.info(String.format("determineInitiatorToExportMaskPlacements - Checking to see if we can consider mask %s, given its initiators, storage ports, and volumes", mask.getMaskName()));
// Check for NO_VIPR. If found, avoid this mask.
if (mask.getMaskName() != null && mask.getMaskName().toUpperCase().contains(ExportUtils.NO_VIPR)) {
_log.info(String.format("ExportMask %s disqualified because the name contains %s (in upper or lower case) to exclude it", mask.getMaskName(), ExportUtils.NO_VIPR));
continue;
}
Map<String, String> storagePortToNetworkName = new HashMap<String, String>();
if (mask.getCreatedBySystem()) {
if (mask.getResource().equals(computeResource)) {
if (maskHasPortGroup(mask, portGroup) && maskHasStoragePortsInExportVarray(exportGroup, mask, initiator, storagePortToNetworkName)) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - ViPR-created mask %s qualifies for consideration for re-use", mask.getMaskName()));
candidateExportMaskURIs.add(exportMaskURI);
totalPorts += storagePortToNetworkName.keySet().size();
maskToTotalMatchingPorts.put(exportMaskURI, totalPorts);
// Ingest Fix : In ingest case, more than 1 export mask with createdBySystem flag set to
// true is possible
// remove the break statement
// break; First ViPR-created ExportMask associated with the resource, we will use
} else {
masksWithUnmatchedStoragePorts.put(exportMaskURI, storagePortToNetworkName);
_log.info(String.format("determineInitiatorToExportMaskPlacements - ViPR-created mask %s does not qualify for consideration for re-use due to storage ports mismatch with varray.", mask.getMaskName()));
}
} else {
_log.info(String.format("determineInitiatorToExportMaskPlacements - ViPR-created mask %s does not qualify for consideration for re-use due to compute resource mismatch.", mask.getMaskName()));
}
} else if (maskHasInitiatorsBasedOnExportType(exportGroup, mask, initiator, portsForComputeResource) || maskHasInitiatorsBasedOnExportType(exportGroup, mask, allExportMaskURIs, portsForComputeResource, partialMasks)) {
if (maskHasPortGroup(mask, portGroup) && maskHasStoragePortsInExportVarray(exportGroup, mask, initiator, storagePortToNetworkName)) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Pre-existing mask %s qualifies for consideration for re-use", mask.getMaskName()));
// This is a non-ViPR create ExportMask and it has the initiator
// as an existing initiator. Add it this as a matching candidate
candidateExportMaskURIs.add(exportMaskURI);
// We don't have zone ingest information for pre-existing masks, so for the purpose of
// matching more coexistence masks, we assume there are zones from every port to every
// initiator in the mask.
// Existing Initiators - initiators which are not userAdded.
int existingInitiators = mask.getExistingInitiators() == null ? 0 : mask.getExistingInitiators().size();
int userAddedInitators = mask.getUserAddedInitiators() == null ? 0 : mask.getUserAddedInitiators().size();
int totalInitiators = existingInitiators + userAddedInitators;
totalPorts += storagePortToNetworkName.keySet().size() * totalInitiators;
maskToTotalMatchingPorts.put(exportMaskURI, totalPorts);
} else {
masksWithUnmatchedStoragePorts.put(exportMaskURI, storagePortToNetworkName);
_log.info(String.format("determineInitiatorToExportMaskPlacements - Pre-existing mask %s does not qualify for consideration for re-use due to storage ports mismatch with varray.", mask.getMaskName()));
}
} else {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Pre-existing mask %s does not qualify for consideration for re-use due to initiators not suitable for export group type.", mask.getMaskName()));
}
}
if (!candidateExportMaskURIs.isEmpty()) {
if (validateCandidateMasksAgainstExportPathParams(exportPathParams, maskToTotalMatchingPorts)) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Initiator %s (%s) will be mapped to these ExportMask URIs: %s", portName, initiatorURI.toString(), Joiner.on(',').join(exportMaskURIs)));
initiatorToExportMaskURIMap.put(portName, candidateExportMaskURIs);
}
} else {
if (masksWithUnmatchedStoragePorts.isEmpty()) {
_log.info(String.format("determineInitiatorToExportMaskPlacements - Could not find ExportMask to which %s can be associated", portName));
} else {
// We found matching exports on the array, but they were not viable due to
// the StoragePorts used (they were pointing to a different VArray), so we should
// warn the user in this case. We will likely still attempt to make a new mask,
// so if the user doesn't prefer that, this message will tell them why we took that
// path.
StringBuilder exportMaskInfo = new StringBuilder();
for (Map.Entry<URI, Map<String, String>> maskToStoragePortsEntry : masksWithUnmatchedStoragePorts.entrySet()) {
URI exportMaskURI = maskToStoragePortsEntry.getKey();
Map<String, String> storagePortToNetworks = maskToStoragePortsEntry.getValue();
ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
exportMaskInfo.append(String.format("MaskingView=%s StoragePorts [ %s ]%n", mask.getMaskName(), Joiner.on(',').join(storagePortToNetworks.entrySet())));
}
VirtualArray virtualArray = _dbClient.queryObject(VirtualArray.class, exportGroup.getVirtualArray());
Exception e = DeviceControllerException.exceptions.existingExportFoundButWithSPsInDifferentNetwork(virtualArray.getLabel(), exportMaskInfo.toString());
_log.warn(e.getMessage());
}
}
}
_log.info(String.format("determineInitiatorToExportMaskPlacements - initiatorToExportMaskURIMap: %s", Joiner.on(',').join(initiatorToExportMaskURIMap.entrySet())));
return initiatorToExportMaskURIMap;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class AbstractDefaultMaskingOrchestrator method getInitiatorToExportMaskMap.
/**
* Routine will examine the ExportGroup object's ExportMask and produce a mapping of the ExportMasks'
* initiator port name to a list of ExportMask URIs.
*
* @param exportGroup
* [in] - ExportGroup object to examine
* @return Map of String to set of URIs. The key will be Initiator.normalizePort(initiator.portName).
* Value will be set of ExportMask URIs.
*/
protected Map<String, Set<URI>> getInitiatorToExportMaskMap(ExportGroup exportGroup) {
Map<String, Set<URI>> mapping = new HashMap<String, Set<URI>>();
for (ExportMask exportMask : ExportMaskUtils.getExportMasks(_dbClient, exportGroup)) {
if (ExportMaskUtils.isUsable(exportMask)) {
Set<Initiator> initiators = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, exportMask, null);
for (Initiator initiator : initiators) {
String name = Initiator.normalizePort(initiator.getInitiatorPort());
Set<URI> maskURIs = mapping.get(name);
if (maskURIs == null) {
maskURIs = new HashSet<URI>();
mapping.put(name, maskURIs);
}
maskURIs.add(exportMask.getId());
}
}
}
return mapping;
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class NetworkScheduler method getInitiators.
/**
* Returns a list of initiators from a list of Initiator URIs
*
* @param initiatorURIs -- a List of Initiator URIs
* @return List<Initiator> where each Initiator is active and type FC
*/
private List<Initiator> getInitiators(Collection<URI> initiatorURIs) {
List<Initiator> initiators = new ArrayList<Initiator>();
Iterator<Initiator> queryIterativeInitiators = _dbClient.queryIterativeObjects(Initiator.class, initiatorURIs);
while (queryIterativeInitiators.hasNext()) {
Initiator initiator = queryIterativeInitiators.next();
if (initiator == null || initiator.getInactive() == true) {
continue;
}
if (StorageProtocol.block2Transport(initiator.getProtocol()) != Transport.FC) {
continue;
}
initiators.add(initiator);
}
return initiators;
}
Aggregations