use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class NetworkDeviceController method addZoneReference.
/**
* A base function for creating an FCZoneReference from the parameters. This function
* ensures that duplicate FCZoneReference for the same refKey, volume and export group
* is not created.
*
* @param exportGroupURI -- the export group URI
* @param volumeURI -- the volume URI
* @param refKey -- the FCZoneReference key which is the concatenation of the initiator
* and storage port WWNs. Note that this key is formed by sorting the WWNs
* @param fabricId -- the name of the fabric or the is of the vsan
* @param NetworkSystemURI -- the network system used to add the zone
* @param zoneName -- the zone name
* @param existingZone -- an flag that indicates if the zone is created by the aplication
* or by the user, true means it was created by the user.
* @param newOrExisting - OUT param in String[0] puts "New" or "Existing" indicating
* whether a New FCZoneReference was persisted.
* @return The zone reference instance
*/
private FCZoneReference addZoneReference(URI exportGroupURI, URI volumeURI, String refKey, String fabricId, URI NetworkSystemURI, String zoneName, boolean existingZone, String[] newOrExisting) {
// Check to see that we don't add multiple references for same Volume/Export Group combination
FCZoneReference ref = findFCZoneReferenceForVolGroupKey(exportGroupURI, volumeURI, refKey, newOrExisting);
if (ref == null) {
ref = new FCZoneReference();
ref.setPwwnKey(refKey);
ref.setFabricId(fabricId);
ref.setNetworkSystemUri(NetworkSystemURI);
ref.setVolumeUri(volumeURI);
ref.setGroupUri(exportGroupURI);
ref.setZoneName(zoneName);
ref.setId(URIUtil.createId(FCZoneReference.class));
ref.setInactive(false);
ref.setLabel(FCZoneReference.makeLabel(ref.getPwwnKey(), volumeURI.toString()));
ref.setExistingZone(existingZone);
_dbClient.createObject(ref);
newOrExisting[0] = "New";
}
return ref;
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class NetworkDeviceController method getZoneReferences.
/**
* Given the zoning map, find all the instances of FCZoneReference for each initiator-port pair.
*
* @param refreshMap the zoning map
* @param initiators the initiators
* @param ports the storage ports
* @return a map of zone key to a list of zone reference objects for the key.
*/
private Map<String, List<FCZoneReference>> getZoneReferences(StringSetMap refreshMap, Collection<Initiator> initiators, Collection<StoragePort> ports) {
Map<String, List<FCZoneReference>> map = new HashMap<String, List<FCZoneReference>>();
Initiator initiator = null;
StoragePort port = null;
Set<String> portsKey = null;
for (String initKey : refreshMap.keySet()) {
portsKey = refreshMap.get(initKey);
initiator = DataObjectUtils.findInCollection(initiators, initKey);
if (initiator == null) {
continue;
}
if (portsKey == null || portsKey.isEmpty()) {
continue;
}
for (String portkey : portsKey) {
port = DataObjectUtils.findInCollection(ports, portkey);
if (port == null) {
continue;
}
String key = FCZoneReference.makeEndpointsKey(initiator.getInitiatorPort(), port.getPortNetworkId());
Joiner joiner = dbModelClient.join(FCZoneReference.class, "refs", "pwwnKey", key).go();
List<FCZoneReference> list = joiner.list("refs");
if (list != null && !list.isEmpty()) {
map.put(key, list);
}
}
}
return map;
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class NetworkDeviceController method deleteFCZoneReference.
/**
* Remove an FCZoneReference from database from the corresponding FCZoneInfo
* @param info -- FCZoneReference
* @param ref -- Returns FCZoneReference that has been marked for deletioni or null
*/
private FCZoneReference deleteFCZoneReference(NetworkFCZoneInfo info) {
URI fcZoneReferenceId = info.getFcZoneReferenceId();
if (NullColumnValueGetter.isNullURI(fcZoneReferenceId)) {
_log.info("fcZoneReferenceId corresponding to zone info {} is null. Nothing to remove.", info.toString());
return null;
}
FCZoneReference ref = _dbClient.queryObject(FCZoneReference.class, fcZoneReferenceId);
if (ref != null) {
_dbClient.markForDeletion(ref);
_log.info(String.format("Remove FCZoneReference key: %s volume %s id %s", ref.getPwwnKey(), ref.getVolumeUri(), ref.getId().toString()));
}
return ref;
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class NetworkDeviceController method refreshFCZoneReferences.
/**
* Given the list of zone changes, the list of existing zone references for the initiators and ports,
* update the FCZoneReference instances in the database. This function ensures that the zone
* references updated are those of the export mask volumes.
*
* @param exportMask the export mask being refreshed
* @param existingRefs a map of zone-reference-key-to-zone-references for each initiator-port pair
* of the mask, including those that were removed. This list may contain zone references for
* volumes not in the export mask.
* @param addedZoneInfos the ZoneInfo instances of zones that were added in this refresh operation
* @param updatedZoneInfos the ZoneInfo instances of zones that were updated in this refresh operation
* @param removedZonesKeys the keys of the zones that were removed.
*/
private void refreshFCZoneReferences(ExportMask exportMask, Map<String, List<FCZoneReference>> existingRefs, List<ZoneInfo> addedZoneInfos, List<ZoneInfo> updatedZoneInfos, List<String> removedZonesKeys) {
// get the export mask volumes and export groups because FCZoneReference are kept for each
Map<URI, Integer> exportMaskVolumes = StringMapUtil.stringMapToVolumeMap(exportMask.getVolumes());
List<ExportGroup> exportGroups = ExportUtils.getExportGroupsForMask(exportMask.getId(), _dbClient);
// start with removing references
List<FCZoneReference> temp = null;
List<FCZoneReference> refs = new ArrayList<FCZoneReference>();
for (String refKey : removedZonesKeys) {
temp = existingRefs.get(refKey);
if (temp == null) {
continue;
}
for (FCZoneReference ref : temp) {
for (ExportGroup exportGroup : exportGroups) {
if (exportGroup.getId().equals(ref.getGroupUri()) && exportGroup.hasBlockObject(ref.getVolumeUri()) && exportMaskVolumes.containsKey(ref.getVolumeUri())) /*
* &&
* ref.getExistingZone()
*/
{
_log.info("FCZoneReference {} for volume {} and exportGroup {} will be deleted", new Object[] { ref.getPwwnKey(), ref.getVolumeUri(), ref.getGroupUri() });
refs.add(ref);
}
}
}
}
_dbClient.markForDeletion(refs);
refs.clear();
// update zone references with new zone info in case the zone was renamed
for (ZoneInfo zoneInfo : updatedZoneInfos) {
String refKey = zoneInfo.getZoneReferenceKey();
temp = existingRefs.get(refKey);
if (temp == null) {
continue;
}
for (FCZoneReference ref : temp) {
for (ExportGroup exportGroup : exportGroups) {
if (exportGroup.getId().equals(ref.getGroupUri()) && exportGroup.hasBlockObject(ref.getVolumeUri()) && exportMaskVolumes.containsKey(ref.getVolumeUri())) {
// only update when there are changes to avoid unnecessary create/delete of indexes
if (zoneInfo.getZoneName() != null && !zoneInfo.getZoneName().equals(ref.getZoneName())) {
ref.setZoneName(zoneInfo.getZoneName());
ref.setExistingZone(true);
}
if (zoneInfo.getNetworkSystemId() != null && (ref.getNetworkSystemUri() == null || !zoneInfo.getNetworkSystemId().equals(ref.getNetworkSystemUri().toString()))) {
ref.setNetworkSystemUri(URI.create(zoneInfo.getNetworkSystemId()));
}
if (zoneInfo.getFabricId() != null && !zoneInfo.getFabricId().equals(ref.getFabricId())) {
ref.setFabricId(zoneInfo.getFabricId());
}
refs.add(ref);
}
}
}
}
_dbClient.updateAndReindexObject(refs);
refs.clear();
// Create zone references as needed, one per volume and export group
for (ZoneInfo zoneInfo : addedZoneInfos) {
for (URI volUri : exportMaskVolumes.keySet()) {
for (ExportGroup exportGroup : exportGroups) {
if (exportGroup.hasBlockObject(volUri)) {
// do I need to check duplicates?
refs.add(createFCZoneReference(zoneInfo, volUri, exportGroup));
_log.info("FCZoneReference {} for volume {} and exportGroup {} will be added", new Object[] { zoneInfo.getZoneReferenceKey(), volUri, exportGroup.getId() });
}
}
}
}
_dbClient.createObject(refs);
}
use of com.emc.storageos.db.client.model.FCZoneReference in project coprhd-controller by CoprHD.
the class NetworkDeviceController method addZoneReference.
/**
* Add a zone reference for an ExportGroup-Zone combination.
* This method is careful not to duplicate existing FCZoneReferences matching the same
* ExportGroup and Volume. Whether a new reference is persisted or not,
* it returns the reference.
*
* @param exportGroupURI -- the URI of the export group
* @param zoneInfo -- the zoneInfo for which the FCZoneReference is being created
* @param newOrExisting - OUT param in String[0] puts "New" or "Existing" indicating
* whether a New FCZoneReference was persisted.
* @return an FCZoneReference for the zoneInfo-exportGroup combination
*/
private FCZoneReference addZoneReference(URI exportGroupURI, NetworkFCZoneInfo zoneInfo, String[] newOrExisting) {
String refKey = zoneInfo.makeEndpointsKey();
URI egURI = exportGroupURI;
// If ExportGroup specified in zone info, use it instead of the default of the order
if (zoneInfo.getExportGroup() != null) {
egURI = zoneInfo.getExportGroup();
}
FCZoneReference ref = addZoneReference(egURI, zoneInfo.getVolumeId(), refKey, zoneInfo.getFabricId(), zoneInfo.getNetworkDeviceId(), zoneInfo.getZoneName(), zoneInfo.isExistingZone(), newOrExisting);
return ref;
}
Aggregations