Search in sources :

Example 6 with URIQueryResultList

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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) HashSet(java.util.HashSet)

Example 7 with URIQueryResultList

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);
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 8 with URIQueryResultList

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);
    }
}
Also used : DriverRegistryRecord(com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 9 with URIQueryResultList

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;
        }
    }
}
Also used : DriverRegistryRecord(com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 10 with URIQueryResultList

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;
}
Also used : DriverRegistryRecord(com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URI(java.net.URI) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) Map(java.util.Map) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)664 URI (java.net.URI)497 ArrayList (java.util.ArrayList)258 HashMap (java.util.HashMap)107 Volume (com.emc.storageos.db.client.model.Volume)97 NamedURI (com.emc.storageos.db.client.model.NamedURI)96 HashSet (java.util.HashSet)92 StoragePort (com.emc.storageos.db.client.model.StoragePort)91 StringSet (com.emc.storageos.db.client.model.StringSet)83 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)64 Produces (javax.ws.rs.Produces)55 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)54 Path (javax.ws.rs.Path)54 List (java.util.List)53 StoragePool (com.emc.storageos.db.client.model.StoragePool)49 Initiator (com.emc.storageos.db.client.model.Initiator)47 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)45 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)39 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)38