use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method updateFailedImages.
/**
* Updates the imageServer with the image that failed import, this method updates
* it as failed only after making sure that the image was not previously successful.
* @param imageServerURI {@link URI} imageServerURI instance to which import was made.
* @param image {@link ComputeImage} instance that failed the import.
*/
private void updateFailedImages(URI imageServerURI, ComputeImage image) {
if (null != imageServerURI && null != image) {
String imageURIStr = image.getId().toString();
log.info("updateFailedImages : update failed image import details.");
// first fetch updated imageServer details from DB and
// verify if image was previously loaded successfully on to
// the imageServer, if so then skip updating it as failed else
// update it as failed.
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerURI);
if (imageServer.getComputeImages() == null || !imageServer.getComputeImages().contains(imageURIStr)) {
// update the imageServer with the failed image.
if (imageServer.getFailedComputeImages() == null) {
imageServer.setFailedComputeImages(new StringSet());
}
log.info("Image - {} failed to import on imageServer - {}", image.getLabel(), imageServer.getLabel());
imageServer.getFailedComputeImages().add(imageURIStr);
dbClient.updateObject(imageServer);
}
}
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class NetworkDeviceController method generateExistingZoneWarningMessages.
/**
* Generating warning messages if there are any zoneInfos that won't be deleted because
* their existingZone value is true (and we are removing the last reference.)
* @param zoneInfos -- list of NetworkFCZoneInfo representingzones to be delete.
* @return -- Warning message text (may include information about multiple zones)
*/
private String generateExistingZoneWarningMessages(List<NetworkFCZoneInfo> zoneInfos) {
StringBuilder buf = new StringBuilder();
StringSet zoneNames = new StringSet();
;
// Issue warning for zones that are lastRef but existing, as they won't be removed.
for (NetworkFCZoneInfo zoneInfo : zoneInfos) {
if (zoneInfo.isLastReference() && zoneInfo.isExistingZone()) {
zoneNames.add(zoneInfo.getZoneName());
}
}
if (!zoneNames.isEmpty()) {
buf.append("Zones which will not be deleted because they may be used externally: ");
buf.append(com.google.common.base.Joiner.on(' ').join(zoneNames));
}
return buf.toString();
}
use of com.emc.storageos.db.client.model.StringSet in project coprhd-controller by CoprHD.
the class NetworkDeviceController method refreshZoningMap.
/**
* Update the zoning map for as export mask previously "accepted". This applies to
* brown field scenarios where a export mask was found on the storage array. For
* those export masks, changes outside of the application are expected and the
* application should get the latest state before making any changes. This
* function is called from ExportMaskOperations#refreshZoneMap after all
* updates to the initiators, ports and volumes were made into the export mask and
* the export group. The update steps are as follow:
* <ol>
* <li>Get the current zones for those initiators that were not added by ViPR and the storage ports that exist in the mask.</li>
* <li>Diff the current zones with those in the export mask and update the zoning map</li>
* <li>Update the FCZoneReferences to match the zone updates</li>
* </ol>
* Note that ViPR does not keep FCZoneReferences only for volumes created by ViPR. As those
* volumes are not updated by ExportMaskOperations#refreshZoneMap, no additional code
* is needed to remove FCZoneReferences for removed volumes.
*
* @param exportMask the export mask being updated.
* @param removedInitiators the list of initiators that were removed. This is needed because
* these were removed from the zoingMap by {@link ExportMask#removeInitiators(Collection)}
* @param removedPorts the set of storage ports that were removed
* @param maskUpdated a flag that indicates if an update was made to the mask that requires
* a zoning refresh
* @param persist a boolean that indicates if the changes should be persisted in the db
*/
public void refreshZoningMap(ExportMask exportMask, Collection<String> removedInitiators, Collection<String> removedPorts, boolean maskUpdated, boolean persist) {
try {
// check if zoning is enabled for the mask
if (!zoningEnabled(exportMask)) {
_log.info("Zoning not enabled for export mask {}. Zoning refresh will not be done", exportMask.getMaskName());
return;
}
if (!(maskUpdated || alwaysRefreshZone())) {
_log.info("The mask ports and initiators were not modified and alwaysRefreshZones is false" + " Zoning refresh will not be done for mask {}", exportMask.getMaskName());
return;
}
List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
_log.info("Refreshing zones for export mask {}. \n\tCurrent initiators " + "in this mask are: {}. \n\tStorage ports in the mask are : {}. \n\tZoningMap is : {}. " + "\n\tRemoved initiators: {}. \n\tRemoved ports: {}", new Object[] { exportMask.getMaskName(), exportMask.getInitiators(), exportMask.getStoragePorts(), exportMask.getZoningMap(), removedInitiators, removedPorts });
Long start = System.currentTimeMillis();
// get the current zones in the network system for initiators and ports
List<StoragePort> storagePorts = ExportUtils.getStoragePorts(exportMask, _dbClient);
ZoneInfoMap zoneInfoMap = getInitiatorsZoneInfoMap(initiators, storagePorts);
// Get the full sets of initiators and ports affected. They will be used to find the FCZoneReferences to refresh
// These sets include new initiators and ports, existing ones that did not change, as well as removed ones
List<StoragePort> allStoragePorts = DataObjectUtils.iteratorToList(_dbClient.queryIterativeObjects(StoragePort.class, StringSetUtil.stringSetToUriList(removedPorts)));
allStoragePorts.addAll(storagePorts);
List<Initiator> allInitiators = DataObjectUtils.iteratorToList(_dbClient.queryIterativeObjects(Initiator.class, StringSetUtil.stringSetToUriList(removedInitiators)));
allInitiators.addAll(initiators);
// Make a copy of the zoning mask - Zones have already been removed for removed initiators, put them back
// This zoning map will be used to do diff between old and new and to get zone references
StringSetMap allZonesMap = new StringSetMap();
StringSetMap tempMap = exportMask.getZoningMap() == null ? new StringSetMap() : exportMask.getZoningMap();
for (String key : tempMap.keySet()) {
// when the zoning map is removed prematurely, this ports set is empty but not null
if (removedInitiators.contains(key) && (tempMap.get(key) == null || tempMap.get(key).isEmpty())) {
// this was prematurely cleared, we will assume all ports
// were zoned to make sure we clean up all FCZoneReferences
allZonesMap.put(key, new StringSet(removedPorts));
if (exportMask.getStoragePorts() != null) {
allZonesMap.get(key).addAll(exportMask.getStoragePorts());
}
} else {
allZonesMap.put(key, new StringSet(tempMap.get(key)));
}
}
// get all the zone references that exist in the database for this export mask.
Map<String, List<FCZoneReference>> existingRefs = getZoneReferences(allZonesMap, allInitiators, allStoragePorts);
// initialize results collections
List<ZoneInfo> addedZoneInfos = new ArrayList<ZoneInfo>();
List<ZoneInfo> updatedZoneInfos = new ArrayList<ZoneInfo>();
List<String> removedZonesKeys = new ArrayList<String>();
// Compare old and new zones. Initialize some loop variables.
ZoneInfo zoneInfo = null;
String initId = null;
String portId = null;
if (exportMask.getZoningMap() == null) {
exportMask.setZoningMap(new StringSetMap());
}
for (Entry<String, ZoneInfo> entry : zoneInfoMap.entrySet()) {
zoneInfo = entry.getValue();
initId = zoneInfo.getInitiatorId();
portId = zoneInfo.getPortId();
if (exportMask.getZoningMap().containsKey(initId) && exportMask.getZoningMap().get(initId).contains(portId)) {
_log.debug("Zoning between initiator {} and port {} did not change", zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn());
// This is accounted for, let's remove it from our diff map
allZonesMap.remove(initId, portId);
// add the zone info so that it can be updated for changes like zone name change
updatedZoneInfos.add(zoneInfo);
} else {
_log.info("New zone was found between initiator {} and port {} and will be added", zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn());
// sometimes zones have more than one initiator or port
if (exportMask.hasExistingInitiator(zoneInfo.getInitiatorWwn())) {
// This is a new entry, add it to the zoning map
exportMask.getZoningMap().put(initId, portId);
// add it to the results so that the appropriate FCZoneReferences are added
addedZoneInfos.add(zoneInfo);
}
// This zone is not expected to be in the diff map, but try anyway
allZonesMap.remove(initId, portId);
}
}
// If anything is remaining zones in the diff zoning map, these were removed in the network system
Initiator initiator = null;
StoragePort port = null;
for (String key : allZonesMap.keySet()) {
initiator = DataObjectUtils.findInCollection(allInitiators, key);
if (allZonesMap.get(key) != null && !allZonesMap.get(key).isEmpty()) {
for (String val : allZonesMap.get(key)) {
port = DataObjectUtils.findInCollection(allStoragePorts, val);
_log.info("Zone between initiator {} and port {} was removed from the network system" + " or no longer belongs to this mask.", key, val);
if (port == null || initiator == null) {
// the port or initiator were removed at some point
exportMask.getZoningMap().remove(key, val);
_log.info("Removed zoningMap entry between initiator {} and port {} because " + "the port and/or the initiator were removed from the mask", key, val);
} else if (removedInitiators.contains(key) || removedPorts.contains(val)) {
// the port or initiator were removed, remove the zone map entry
exportMask.getZoningMap().remove(key, val);
_log.info("Removed zoningMap entry between initiator {} and port {} because " + "the port and/or the initiator were removed from the mask", initiator.getInitiatorPort(), port.getPortNetworkId());
} else if (exportMask.hasExistingInitiator(WWNUtility.getUpperWWNWithNoColons(initiator.getInitiatorPort()))) {
exportMask.getZoningMap().remove(key, val);
_log.info("Removed zoningMap entry between initiator {} and port {} because " + "this was a brownfield zone for a brownfield initiator", initiator.getInitiatorPort(), port.getPortNetworkId());
} else {
_log.info("The zone between initiator {} and port {} was removed from " + " the network system but the zoningMap entry will be kept because it was" + " a ViPR initiator-port assignment", initiator.getInitiatorPort(), port.getPortNetworkId());
}
if (port != null && initiator != null) {
removedZonesKeys.add(FCZoneReference.makeEndpointsKey(initiator.getInitiatorPort(), port.getPortNetworkId()));
}
}
}
}
// get all the existing zone references from the database, these are
refreshFCZoneReferences(exportMask, existingRefs, addedZoneInfos, updatedZoneInfos, removedZonesKeys);
if (persist) {
_dbClient.updateAndReindexObject(exportMask);
}
_log.info("Changed zones for export mask {} to {}. \nRefreshing zones took {} ms", new Object[] { exportMask.getMaskName(), exportMask.getZoningMap(), (System.currentTimeMillis() - start) });
} catch (Exception ex) {
_log.error("An exception occurred while updating zoning map for export mask {} with message {}", new Object[] { exportMask.getMaskName(), ex.getMessage() }, ex);
}
}
use of com.emc.storageos.db.client.model.StringSet 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.StringSet 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;
}
Aggregations