Search in sources :

Example 6 with DriverRegistryRecord

use of com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord in project coprhd-controller by CoprHD.

the class RegistryImpl method addDriverAttributeForKey.

@Override
public void addDriverAttributeForKey(String driverName, String key, String attribute, List<String> value) {
    validateRegistryRequest(driverName, key);
    DriverRegistryRecord registryEntryForKey = null;
    // find existing entry for a driver name and a given key
    boolean existingKey = false;
    URIQueryResultList registryEntriesUris = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getDriverRegistryEntriesByDriverName(driverName), registryEntriesUris);
    while (registryEntriesUris.iterator().hasNext()) {
        URI registryEntryUri = registryEntriesUris.iterator().next();
        registryEntryForKey = dbClient.queryObject(DriverRegistryRecord.class, registryEntryUri);
        if (registryEntryForKey.getRegistryKey().equals(key)) {
            existingKey = true;
            StringSetMap attributes = registryEntryForKey.getAttributes();
            StringSet attributeValue = new StringSet(value);
            updateAttributeInMap(attributes, attribute, attributeValue);
            break;
        }
    }
    if (existingKey == false) {
        // no entry for this key in the registry, create a new entry
        registryEntryForKey = new DriverRegistryRecord();
        registryEntryForKey.setId(URIUtil.createId(DriverRegistryRecord.class));
        registryEntryForKey.setDriverName(driverName);
        registryEntryForKey.setRegistryKey(key);
        StringSetMap attributesMap = new StringSetMap();
        StringSet values = new StringSet(value);
        updateAttributeInMap(attributesMap, attribute, values);
        registryEntryForKey.setAttributes(attributesMap);
    }
    // update db
    if (existingKey) {
        dbClient.updateObject(registryEntryForKey);
    } else {
        dbClient.createObject(registryEntryForKey);
    }
}
Also used : DriverRegistryRecord(com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 7 with DriverRegistryRecord

use of com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord in project coprhd-controller by CoprHD.

the class RegistryImpl method setDriverAttributesForKey.

@Override
public void setDriverAttributesForKey(String driverName, String key, Map<String, List<String>> attributes) {
    validateRegistryRequest(driverName, key);
    DriverRegistryRecord registryEntryForKey = null;
    // find existing entry for driver name and a given key
    boolean existingEntry = false;
    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)) {
            registryEntryForKey = registryEntry;
            existingEntry = true;
            break;
        }
    }
    // have not find existing driver registry entry for a key, create a new entry for this key
    if (registryEntryForKey == null) {
        registryEntryForKey = new DriverRegistryRecord();
        registryEntryForKey.setId(URIUtil.createId(DriverRegistryRecord.class));
        registryEntryForKey.setDriverName(driverName);
        registryEntryForKey.setRegistryKey(key);
    }
    // update/add attribute map for the key entry
    StringSetMap attributesMap = new StringSetMap();
    for (Map.Entry<String, List<String>> entry : attributes.entrySet()) {
        StringSet values = new StringSet(entry.getValue());
        updateAttributeInMap(attributesMap, entry.getKey(), values);
    }
    registryEntryForKey.setAttributes(attributesMap);
    if (existingEntry) {
        dbClient.updateObject(registryEntryForKey);
    } else {
        dbClient.createObject(registryEntryForKey);
    }
}
Also used : DriverRegistryRecord(com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringSet(com.emc.storageos.db.client.model.StringSet) 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)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 DriverRegistryRecord (com.emc.storageos.db.client.model.storagedriver.DriverRegistryRecord)7 URI (java.net.URI)7 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)2 StringSet (com.emc.storageos.db.client.model.StringSet)2