use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class NetworkDiscoveryWorker method reconcileFCEndpoints.
/**
* Reconciles the current set of a Device's endpoints with what is persisted.
* Updates the database accordingly.
*
* @param dev
* @param currentConnections
* @throws IOException
*/
private void reconcileFCEndpoints(NetworkSystem dev, List<FCEndpoint> currentConnections) throws IOException {
// First, read all the existing connections from the device, and put them into a map
// keyed by remote wwpn.
URIQueryResultList uriList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(dev.getId()), uriList);
Map<String, FCEndpoint> existingEndpoints = new HashMap<String, FCEndpoint>();
for (URI uriold : uriList) {
FCEndpoint connection = dbClient.queryObject(FCEndpoint.class, uriold);
if (connection != null) {
existingEndpoints.put(connection.getRemotePortName().toUpperCase(), connection);
}
}
// Now, scan the new endpoints, looking for added or updated records by
// comparing them with the existing endpoints. Keep track of what was processed
// so can do deletions on anything not seen in the currentConnections.
List<FCEndpoint> updated = new ArrayList<FCEndpoint>();
List<FCEndpoint> created = new ArrayList<FCEndpoint>();
Set<String> processedWwpns = new HashSet<String>();
int conflictingEndpoints = 0;
for (FCEndpoint current : currentConnections) {
String key = current.getRemotePortName().toUpperCase();
processedWwpns.add(key);
FCEndpoint existing = existingEndpoints.get(key);
if (existing == null) {
current.setNetworkDevice(dev.getId());
current.setId(URIUtil.createId(FCEndpoint.class));
if (WWNUtility.isValidWWN(current.getRemotePortName())) {
created.add(current);
} else {
_log.info("Invalid new FCEndpoint {}, Hence not adding it to DB", current.getRemotePortName());
}
conflictingEndpoints += removeConflictingEndpoints(key, current.getFabricWwn(), dev.getId());
} else {
boolean modified = checkUpdated(existing, current);
if (existing.getAwolCount() > 0) {
modified = true;
existing.setAwolCount(0);
existing.setAwolTime(null);
}
if (modified) {
if (WWNUtility.isValidWWN(existing.getRemotePortName())) {
updated.add(existing);
} else {
_log.info("Invalid existing FCEndpoint {}, Hence not updating it to DB", existing.getRemotePortName());
}
conflictingEndpoints += removeConflictingEndpoints(key, current.getFabricWwn(), dev.getId());
}
}
}
// What was left were not seen this time.
for (String key : processedWwpns) {
existingEndpoints.remove(key);
}
// The remaining existingEndpoints can be processed for removal.
// They are removed after a minimum number of samples and minimum amount of time has transpired.
Integer removedCount = 0;
for (FCEndpoint entry : existingEndpoints.values()) {
int count = entry.getAwolCount();
if (count == 0) {
entry.setAwolTime(System.currentTimeMillis());
}
entry.setAwolCount(++count);
if (count >= _minAwolSamples && (System.currentTimeMillis() - entry.getAwolTime()) > _minAwolTime) {
removedCount++;
dbClient.removeObject(entry);
} else {
// update counters
updated.add(entry);
}
}
// Persist created, modified.
dbClient.createObject(created);
dbClient.updateObject(updated);
_log.info(MessageFormat.format("{0} new connections persisted", created.size()).toString());
_log.info(MessageFormat.format("{0} updated connections persisted", updated.size()).toString());
_log.info(MessageFormat.format("{0} missing connections", existingEndpoints.values().size()).toString());
_log.info(MessageFormat.format("{0} removed connections", removedCount.toString()));
_log.info(MessageFormat.format("{0} conflicting connections (removed)", conflictingEndpoints));
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class NetworkDiscoveryWorker method getNetworkSystemEndPoints.
private Iterator<FCEndpoint> getNetworkSystemEndPoints(NetworkSystem networkSystem) throws IOException {
URIQueryResultList uriList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(networkSystem.getId()), uriList);
List<URI> uris = new ArrayList<URI>();
while (uriList.iterator().hasNext()) {
uris.add(uriList.iterator().next());
}
return dbClient.queryIterativeObjects(FCEndpoint.class, uris);
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class RegistryImpl method clearDriverAttributes.
@Override
public void clearDriverAttributes(String driverName) {
URIQueryResultList registryEntriesUris = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getDriverRegistryEntriesByDriverName(driverName), registryEntriesUris);
while (registryEntriesUris.iterator().hasNext()) {
URI registryEntryUri = registryEntriesUris.iterator().next();
DriverRegistryRecord registryEntry = dbClient.queryObject(DriverRegistryRecord.class, registryEntryUri);
dbClient.markForDeletion(registryEntry);
}
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class RegistryImpl method clearDriverAttributeForKey.
@Override
public void clearDriverAttributeForKey(String driverName, String key, String attribute) {
validateRegistryRequest(driverName, key);
URIQueryResultList registryEntriesUris = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getDriverRegistryEntriesByDriverName(driverName), registryEntriesUris);
while (registryEntriesUris.iterator().hasNext()) {
URI registryEntryUri = registryEntriesUris.iterator().next();
DriverRegistryRecord registryEntry = dbClient.queryObject(DriverRegistryRecord.class, registryEntryUri);
if (registryEntry.getRegistryKey().equals(key)) {
// remove attribute from registry entry attribute map
registryEntry.getAttributes().remove(attribute);
if (registryEntry.getAttributes().isEmpty()) {
dbClient.markForDeletion(registryEntry);
} else {
dbClient.updateObject(registryEntry);
}
break;
}
}
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class RegistryImpl method getDriverAttributesForKey.
@Override
public Map<String, List<String>> getDriverAttributesForKey(String driverName, String key) {
validateRegistryRequest(driverName, key);
Map<String, List<String>> attributesMap = new HashMap<>();
// find existing entry for driver name and a given key
URIQueryResultList registryEntriesUris = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getDriverRegistryEntriesByDriverName(driverName), registryEntriesUris);
while (registryEntriesUris.iterator().hasNext()) {
URI registryEntryUri = registryEntriesUris.iterator().next();
DriverRegistryRecord registryEntry = dbClient.queryObject(DriverRegistryRecord.class, registryEntryUri);
if (registryEntry.getRegistryKey().equals(key)) {
StringSetMap attributes = registryEntry.getAttributes();
for (Map.Entry<String, AbstractChangeTrackingSet<String>> entry : attributes.entrySet()) {
attributesMap.put(entry.getKey(), new ArrayList<>(entry.getValue()));
}
break;
}
}
return attributesMap;
}
Aggregations