X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fclustered-data-store%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fdatastore%2Finternal%2FClusteredDataStoreImpl.java;h=0809ba347ba1bf97d914208978e9c536a3e669cf;hb=4142ab5dce3021e6f6551aada26c7523cd134844;hp=f2e7773a454565e537053f72889cc0ebfb0a3f6a;hpb=0b3fe7299bbeccc10f2c1b859f95de07c168ac9f;p=controller.git diff --git a/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImpl.java b/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImpl.java index f2e7773a45..0809ba347b 100644 --- a/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImpl.java +++ b/opendaylight/md-sal/clustered-data-store/implementation/src/main/java/org/opendaylight/controller/datastore/internal/ClusteredDataStoreImpl.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.datastore.internal; import com.google.common.base.Preconditions; + import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; import org.opendaylight.controller.clustering.services.IClusterGlobalServices; @@ -17,9 +18,12 @@ import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.datastore.ClusteredDataStore; import org.opendaylight.controller.md.sal.common.api.data.DataModification; import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Collections; import java.util.EnumSet; @@ -35,54 +39,74 @@ public class ClusteredDataStoreImpl implements ClusteredDataStore { public static final String OPERATIONAL_DATA_CACHE = "clustered_data_store.operational_data_cache"; public static final String CONFIGURATION_DATA_CACHE = "clustered_data_store.configuration_data_cache"; - private ConcurrentMap operationalDataCache; - private ConcurrentMap configurationDataCache; + private final ConcurrentMap operationalDataCache; + private final ConcurrentMap configurationDataCache; - public ClusteredDataStoreImpl(IClusterGlobalServices clusterGlobalServices) throws CacheExistException, CacheConfigException { - Preconditions.checkNotNull(clusterGlobalServices, "clusterGlobalServices cannot be null"); + private Logger logger = LoggerFactory.getLogger(ClusteredDataStoreImpl.class); - operationalDataCache = clusterGlobalServices.createCache(OPERATIONAL_DATA_CACHE, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); + public ClusteredDataStoreImpl(IClusterGlobalServices clusterGlobalServices) throws CacheConfigException { + logger.trace("Constructing clustered data store"); + Preconditions.checkNotNull(clusterGlobalServices, "clusterGlobalServices cannot be null"); - if(operationalDataCache == null){ - Preconditions.checkNotNull(operationalDataCache, "operationalDataCache cannot be null"); - } + operationalDataCache = getOrCreateCache(clusterGlobalServices, OPERATIONAL_DATA_CACHE); - configurationDataCache = clusterGlobalServices.createCache(CONFIGURATION_DATA_CACHE, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); + Preconditions.checkNotNull(operationalDataCache, "operationalDataCache cannot be null"); - if(configurationDataCache == null){ - Preconditions.checkNotNull(configurationDataCache, "configurationDataCache cannot be null"); - } + configurationDataCache = getOrCreateCache(clusterGlobalServices, CONFIGURATION_DATA_CACHE); + Preconditions.checkNotNull(configurationDataCache, "configurationDataCache cannot be null"); } @Override - public DataCommitTransaction, Object> requestCommit(DataModification, Object> modification) { + public DataCommitTransaction requestCommit(DataModification modification) { return new ClusteredDataStoreTransaction(modification); } @Override - public Object readOperationalData(InstanceIdentifier path) { + public CompositeNode readOperationalData(InstanceIdentifier path) { Preconditions.checkNotNull(path, "path cannot be null"); return operationalDataCache.get(path); } @Override - public Object readConfigurationData(InstanceIdentifier path) { + public boolean containsConfigurationPath(InstanceIdentifier path) { + return configurationDataCache.containsKey(path); + } + + @Override + public boolean containsOperationalPath(InstanceIdentifier path) { + return operationalDataCache.containsKey(path); + } + + @Override + public Iterable getStoredConfigurationPaths() { + return configurationDataCache.keySet(); + } + + @Override + public Iterable getStoredOperationalPaths() { + return operationalDataCache.keySet(); + } + + + + @Override + public CompositeNode readConfigurationData(InstanceIdentifier path) { Preconditions.checkNotNull(path, "path cannot be null"); return configurationDataCache.get(path); } private RpcResult finish(final ClusteredDataStoreTransaction transaction) { - final DataModification,Object> modification = transaction.getModification(); + final DataModification modification = transaction.getModification(); this.configurationDataCache.putAll(modification.getUpdatedConfigurationData()); this.operationalDataCache.putAll(modification.getUpdatedOperationalData()); - for (final InstanceIdentifier removal : modification.getRemovedConfigurationData()) { + for (final InstanceIdentifier removal : modification.getRemovedConfigurationData()) { this.configurationDataCache.remove(removal); } - for (final InstanceIdentifier removal : modification.getRemovedOperationalData()) { + for (final InstanceIdentifier removal : modification.getRemovedOperationalData()) { this.operationalDataCache.remove(removal ); } @@ -95,17 +119,31 @@ public class ClusteredDataStoreImpl implements ClusteredDataStore { return Rpcs.getRpcResult(true, null, _emptySet); } - private class ClusteredDataStoreTransaction implements DataCommitTransaction, Object> { - private final DataModification,Object> modification; - public ClusteredDataStoreTransaction(DataModification,Object> modification){ + private ConcurrentMap getOrCreateCache(IClusterGlobalServices clusterGlobalServices, String name) throws CacheConfigException { + ConcurrentMap cache = clusterGlobalServices.getCache(name); + + if(cache == null) { + try { + cache = clusterGlobalServices.createCache(name, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); + } catch (CacheExistException e) { + cache = clusterGlobalServices.getCache(name); + } + } + return cache; + } + + private class ClusteredDataStoreTransaction implements DataCommitTransaction { + private final DataModification modification; + + public ClusteredDataStoreTransaction(DataModification modification){ Preconditions.checkNotNull(modification, "modification cannot be null"); this.modification = modification; } @Override - public DataModification, Object> getModification() { + public DataModification getModification() { return this.modification; }