From: Moiz Raja
Date: Wed, 28 Jan 2015 15:29:00 +0000 (+0000)
Subject: Merge "Bug 2265: Use streaming for DeleteData message"
X-Git-Tag: release/lithium~657
X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=4ed6793fcad89fcb4a3c0f7ec230753cb7ed31a9;hp=e0e940ce65e9ae8845b94da03fa559c5980a2876
Merge "Bug 2265: Use streaming for DeleteData message"
---
diff --git a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/pom.xml b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/pom.xml
index 880e2dc9d5..1ee28b8d5a 100644
--- a/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/pom.xml
+++ b/opendaylight/archetypes/opendaylight-startup/src/main/resources/archetype-resources/__artifactId__-features/pom.xml
@@ -39,6 +39,30 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
+
+ org.opendaylight.yangtools
+ features-yangtools
+ features
+ ${yangtools.version}
+ xml
+ runtime
+
+
+ org.opendaylight.controller
+ features-mdsal
+ features
+ ${mdsal.version}
+ xml
+ runtime
+
+
+ org.opendaylight.controller
+ features-restconf
+ features
+ ${mdsal.version}
+ xml
+ runtime
+
${symbol_dollar}{groupId}
${artifactId}-impl
diff --git a/opendaylight/config/config-parent/pom.xml b/opendaylight/config/config-parent/pom.xml
index 10c1824ebe..af39b63447 100644
--- a/opendaylight/config/config-parent/pom.xml
+++ b/opendaylight/config/config-parent/pom.xml
@@ -24,6 +24,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
0.3.0-SNAPSHOT
1.2.0-SNAPSHOT
+ 0.7.0-SNAPSHOT
src/main/yang-gen-config
src/main/config/default-config.xml
@@ -45,10 +46,21 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
pom
import
+
+ org.opendaylight.yangtools
+ yangtools-artifacts
+ ${yangtools.version}
+ pom
+ import
+
+
+ org.opendaylight.yangtools
+ yang-common
+
org.opendaylight.controller
config-api
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java
index 677b6aa65e..6c02001fec 100644
--- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java
+++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java
@@ -9,24 +9,23 @@ package org.opendaylight.controller.sal.binding.codegen.impl;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
+import java.util.Map;
+import java.util.WeakHashMap;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.NotFoundException;
+import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter;
import org.opendaylight.controller.sal.binding.codegen.RpcIsNotRoutedException;
import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
+import org.opendaylight.yangtools.util.ClassLoaderUtils;
import org.opendaylight.yangtools.yang.binding.BindingMapping;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.NotificationListener;
import org.opendaylight.yangtools.yang.binding.RpcService;
import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
-import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils;
-
-import javax.annotation.concurrent.GuardedBy;
-import java.util.Map;
-import java.util.WeakHashMap;
abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator, NotificationInvokerFactory {
@GuardedBy("this")
@@ -79,7 +78,7 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll
*/
Thread.currentThread().getContextClassLoader().loadClass(routingPair.getInputType().getName());
} else {
- throw new RpcIsNotRoutedException("RPC " + method.getName() + " from "+ iface.getName() +" is not routed");
+ throw new RpcIsNotRoutedException(String.format("RPC %s from %s is not routed", method.getName(), iface.getName()));
}
}
}
@@ -164,7 +163,7 @@ abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controll
try {
return getRpcMetadata(utils.asCtClass(serviceType));
} catch (ClassNotFoundException | NotFoundException e) {
- throw new IllegalStateException(String.format("Failed to load metadata for class {}", serviceType), e);
+ throw new IllegalStateException(String.format("Failed to load metadata for class %s", serviceType), e);
}
}
});
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/AugmentationIdentifierGenerator.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/AugmentationIdentifierGenerator.java
index 7f7cdc650e..56ef8ea6fc 100644
--- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/AugmentationIdentifierGenerator.java
+++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/AugmentationIdentifierGenerator.java
@@ -10,40 +10,38 @@
package org.opendaylight.controller.cluster.datastore.node.utils;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
+import com.google.common.base.Splitter;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
public class AugmentationIdentifierGenerator {
+ private static final Pattern PATTERN = Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
+ private static final Splitter COMMA_SPLITTER = Splitter.on(',').trimResults();
+
private final String id;
- private static final Pattern pattern = Pattern.compile("AugmentationIdentifier\\Q{\\EchildNames=\\Q[\\E(.*)\\Q]}\\E");
private final Matcher matcher;
private final boolean doesMatch;
- public AugmentationIdentifierGenerator(String id){
+ public AugmentationIdentifierGenerator(String id) {
this.id = id;
- matcher = pattern.matcher(this.id);
+ matcher = PATTERN.matcher(this.id);
doesMatch = matcher.matches();
}
- public boolean matches(){
+ public boolean matches() {
return doesMatch;
}
- public YangInstanceIdentifier.AugmentationIdentifier getPathArgument(){
- Set childNames = new HashSet();
+ public YangInstanceIdentifier.AugmentationIdentifier getPathArgument() {
final String childQNames = matcher.group(1);
- final String[] splitChildQNames = childQNames.split(",");
-
- for(String name : splitChildQNames){
- childNames.add(
- org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory
- .create(name.trim()));
+ final Set childNames = new HashSet<>();
+ for (String name : COMMA_SPLITTER.split(childQNames)) {
+ childNames.add(QNameFactory.create(name));
}
return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java
index 6cdddfd271..930dbceab4 100644
--- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java
+++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java
@@ -10,15 +10,16 @@
package org.opendaylight.controller.cluster.datastore.node.utils;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
+import com.google.common.base.Splitter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
public class PathUtils {
+ private static final Splitter SLASH_SPLITTER = Splitter.on('/').omitEmptyStrings();
/**
* Given a YangInstanceIdentifier return a serialized version of the same
@@ -27,17 +28,22 @@ public class PathUtils {
* @param path
* @return
*/
- public static String toString(YangInstanceIdentifier path){
- StringBuilder sb = new StringBuilder();
- Iterator iterator =
+ public static String toString(YangInstanceIdentifier path) {
+ final Iterator it =
path.getPathArguments().iterator();
+ if (!it.hasNext()) {
+ return "";
+ }
- while(iterator.hasNext()){
- sb.append(toString(iterator.next()));
- if(iterator.hasNext()){
- sb.append("/");
+ final StringBuilder sb = new StringBuilder();
+ for (;;) {
+ sb.append(toString(it.next()));
+ if (!it.hasNext()) {
+ break;
}
+ sb.append('/');
}
+
return sb.toString();
}
@@ -70,13 +76,9 @@ public class PathUtils {
* @return
*/
public static YangInstanceIdentifier toYangInstanceIdentifier(String path){
- String[] segments = path.split("/");
-
List pathArguments = new ArrayList<>();
- for (String segment : segments) {
- if (!"".equals(segment)) {
- pathArguments.add(NodeIdentifierFactory.getArgument(segment));
- }
+ for (String segment : SLASH_SPLITTER.split(path)) {
+ pathArguments.add(NodeIdentifierFactory.getArgument(segment));
}
return YangInstanceIdentifier.create(pathArguments);
}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java
index 5a8f522861..c63266ff08 100644
--- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java
+++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/QNameFactory.java
@@ -19,11 +19,12 @@ public class QNameFactory {
private static final int MAX_QNAME_CACHE_SIZE = 10000;
- private static LoadingCache cache = CacheBuilder.newBuilder()
+ private static final LoadingCache CACHE = CacheBuilder.newBuilder()
.maximumSize(MAX_QNAME_CACHE_SIZE)
.softValues()
.build(
new CacheLoader() {
+ @Override
public QName load(String key) {
return QName.create(key);
}
@@ -32,6 +33,6 @@ public class QNameFactory {
public static QName create(String name){
- return cache.getUnchecked(name);
+ return CACHE.getUnchecked(name);
}
}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java
index f562d8b35d..71946b0a7a 100644
--- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java
+++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java
@@ -9,11 +9,8 @@
package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
import com.google.protobuf.ByteString;
-import java.math.BigDecimal;
-import java.math.BigInteger;
import java.util.HashSet;
import java.util.Set;
-import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -101,35 +98,7 @@ public class ValueSerializer {
private static Object deSerializeBasicTypes(int valueType, String value) {
- switch(ValueType.values()[valueType]){
- case SHORT_TYPE: {
- return Short.valueOf(value);
- }
- case BOOL_TYPE: {
- return Boolean.valueOf(value);
- }
- case BYTE_TYPE: {
- return Byte.valueOf(value);
- }
- case INT_TYPE : {
- return Integer.valueOf(value);
- }
- case LONG_TYPE: {
- return Long.valueOf(value);
- }
- case QNAME_TYPE: {
- return QNameFactory.create(value);
- }
- case BIG_INTEGER_TYPE: {
- return new BigInteger(value);
- }
- case BIG_DECIMAL_TYPE: {
- return new BigDecimal(value);
- }
- default: {
- return value;
- }
- }
+ return ValueType.values()[valueType].deserialize(value);
}
}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueType.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueType.java
index 2007544b7e..b9e46a3a57 100644
--- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueType.java
+++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueType.java
@@ -9,53 +9,120 @@
package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
import com.google.common.base.Preconditions;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
public enum ValueType {
- SHORT_TYPE,
- BYTE_TYPE,
- INT_TYPE,
- LONG_TYPE,
- BOOL_TYPE,
- QNAME_TYPE,
- BITS_TYPE,
- YANG_IDENTIFIER_TYPE,
- STRING_TYPE,
- BIG_INTEGER_TYPE,
- BIG_DECIMAL_TYPE,
- BINARY_TYPE;
+ SHORT_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return Short.valueOf(str);
+ }
+ },
+ BYTE_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return Byte.valueOf(str);
+ }
+ },
+ INT_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return Integer.valueOf(str);
+ }
+ },
+ LONG_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return Long.valueOf(str);
+ }
+ },
+ BOOL_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return Boolean.valueOf(str);
+ }
+ },
+ QNAME_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return QNameFactory.create(str);
+ }
+ },
+ BITS_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ throw new UnsupportedOperationException("Should have been caught by caller");
+ }
+ },
+ YANG_IDENTIFIER_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ throw new UnsupportedOperationException("Should have been caught by caller");
+ }
+ },
+ STRING_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return str;
+ }
+ },
+ BIG_INTEGER_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return new BigInteger(str);
+ }
+ },
+ BIG_DECIMAL_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ return new BigDecimal(str);
+ }
+ },
+ BINARY_TYPE {
+ @Override
+ Object deserialize(final String str) {
+ throw new UnsupportedOperationException("Should have been caught by caller");
+ }
+ };
- private static Map, ValueType> types = new HashMap<>();
+ private static final Map, ValueType> TYPES;
static {
- types.put(String.class, STRING_TYPE);
- types.put(Byte.class, BYTE_TYPE);
- types.put(Integer.class, INT_TYPE);
- types.put(Long.class, LONG_TYPE);
- types.put(Boolean.class, BOOL_TYPE);
- types.put(QName.class, QNAME_TYPE);
- types.put(Set.class, BITS_TYPE);
- types.put(YangInstanceIdentifier.class, YANG_IDENTIFIER_TYPE);
- types.put(Short.class,SHORT_TYPE);
- types.put(BigInteger.class, BIG_INTEGER_TYPE);
- types.put(BigDecimal.class, BIG_DECIMAL_TYPE);
- types.put(byte[].class, BINARY_TYPE);
+ final Builder, ValueType> b = ImmutableMap.builder();
+
+ b.put(String.class, STRING_TYPE);
+ b.put(Byte.class, BYTE_TYPE);
+ b.put(Integer.class, INT_TYPE);
+ b.put(Long.class, LONG_TYPE);
+ b.put(Boolean.class, BOOL_TYPE);
+ b.put(QName.class, QNAME_TYPE);
+ b.put(YangInstanceIdentifier.class, YANG_IDENTIFIER_TYPE);
+ b.put(Short.class,SHORT_TYPE);
+ b.put(BigInteger.class, BIG_INTEGER_TYPE);
+ b.put(BigDecimal.class, BIG_DECIMAL_TYPE);
+ b.put(byte[].class, BINARY_TYPE);
+
+ TYPES = b.build();
}
- public static final ValueType getSerializableType(Object node){
+ abstract Object deserialize(String str);
+
+ public static final ValueType getSerializableType(Object node) {
Preconditions.checkNotNull(node, "node should not be null");
- ValueType type = types.get(node.getClass());
- if(type != null) {
+ final ValueType type = TYPES.get(node.getClass());
+ if (type != null) {
return type;
- } else if(node instanceof Set){
+ }
+ if (node instanceof Set) {
return BITS_TYPE;
}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java
index e75a454d39..3a2d2b49b3 100644
--- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java
+++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/ValueTypes.java
@@ -9,15 +9,16 @@
package org.opendaylight.controller.cluster.datastore.node.utils.stream;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-public class ValueTypes {
+final class ValueTypes {
public static final byte SHORT_TYPE = 1;
public static final byte BYTE_TYPE = 2;
public static final byte INT_TYPE = 3;
@@ -31,30 +32,38 @@ public class ValueTypes {
public static final byte BIG_DECIMAL_TYPE = 11;
public static final byte BINARY_TYPE = 12;
- private static Map, Byte> types = new HashMap<>();
+ private static final Map, Byte> TYPES;
static {
- types.put(String.class, Byte.valueOf(STRING_TYPE));
- types.put(Byte.class, Byte.valueOf(BYTE_TYPE));
- types.put(Integer.class, Byte.valueOf(INT_TYPE));
- types.put(Long.class, Byte.valueOf(LONG_TYPE));
- types.put(Boolean.class, Byte.valueOf(BOOL_TYPE));
- types.put(QName.class, Byte.valueOf(QNAME_TYPE));
- types.put(Set.class, Byte.valueOf(BITS_TYPE));
- types.put(YangInstanceIdentifier.class, Byte.valueOf(YANG_IDENTIFIER_TYPE));
- types.put(Short.class, Byte.valueOf(SHORT_TYPE));
- types.put(BigInteger.class, Byte.valueOf(BIG_INTEGER_TYPE));
- types.put(BigDecimal.class, Byte.valueOf(BIG_DECIMAL_TYPE));
- types.put(byte[].class, Byte.valueOf(BINARY_TYPE));
+ final Builder, Byte> b = ImmutableMap.builder();
+
+ b.put(String.class, Byte.valueOf(STRING_TYPE));
+ b.put(Byte.class, Byte.valueOf(BYTE_TYPE));
+ b.put(Integer.class, Byte.valueOf(INT_TYPE));
+ b.put(Long.class, Byte.valueOf(LONG_TYPE));
+ b.put(Boolean.class, Byte.valueOf(BOOL_TYPE));
+ b.put(QName.class, Byte.valueOf(QNAME_TYPE));
+ b.put(YangInstanceIdentifier.class, Byte.valueOf(YANG_IDENTIFIER_TYPE));
+ b.put(Short.class, Byte.valueOf(SHORT_TYPE));
+ b.put(BigInteger.class, Byte.valueOf(BIG_INTEGER_TYPE));
+ b.put(BigDecimal.class, Byte.valueOf(BIG_DECIMAL_TYPE));
+ b.put(byte[].class, Byte.valueOf(BINARY_TYPE));
+
+ TYPES = b.build();
}
- public static final byte getSerializableType(Object node){
+ private ValueTypes() {
+ throw new UnsupportedOperationException("Utility class");
+ }
+
+ public static final byte getSerializableType(Object node) {
Preconditions.checkNotNull(node, "node should not be null");
- Byte type = types.get(node.getClass());
- if(type != null) {
+ final Byte type = TYPES.get(node.getClass());
+ if (type != null) {
return type;
- } else if(node instanceof Set){
+ }
+ if (node instanceof Set) {
return BITS_TYPE;
}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java
index 061e1ab448..0541e3a48b 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ConfigurationImpl.java
@@ -10,6 +10,12 @@ package org.opendaylight.controller.cluster.datastore;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ListMultimap;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigObject;
@@ -17,7 +23,6 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -29,9 +34,9 @@ import org.slf4j.LoggerFactory;
public class ConfigurationImpl implements Configuration {
- private final List moduleShards = new ArrayList<>();
+ private final List moduleShards;
- private final List modules = new ArrayList<>();
+ private final List modules;
private static final Logger
LOG = LoggerFactory.getLogger(DistributedDataStore.class);
@@ -44,6 +49,10 @@ public class ConfigurationImpl implements Configuration {
// key = shardName, value = list of replicaNames (replicaNames are the same as memberNames)
private final Map> shardReplicaNames = new HashMap<>();
+ private final ListMultimap moduleNameToShardName;
+ private final Map moduleNameToStrategy;
+ private final Map namespaceToModuleName;
+ private final Set allShardNames;
public ConfigurationImpl(final String moduleShardsConfigPath,
@@ -74,9 +83,51 @@ public class ConfigurationImpl implements Configuration {
modulesConfig = ConfigFactory.load(modulesConfigPath);
}
- readModuleShards(moduleShardsConfig);
+ this.moduleShards = readModuleShards(moduleShardsConfig);
+ this.modules = readModules(modulesConfig);
- readModules(modulesConfig);
+ this.allShardNames = createAllShardNames(moduleShards);
+ this.moduleNameToShardName = createModuleNameToShardName(moduleShards);
+ this.moduleNameToStrategy = createModuleNameToStrategy(modules);
+ this.namespaceToModuleName = createNamespaceToModuleName(modules);
+ }
+
+ private static Set createAllShardNames(Iterable moduleShards) {
+ final com.google.common.collect.ImmutableSet.Builder b = ImmutableSet.builder();
+ for(ModuleShard ms : moduleShards){
+ for(Shard s : ms.getShards()) {
+ b.add(s.getName());
+ }
+ }
+ return b.build();
+ }
+
+ private static Map createModuleNameToStrategy(Iterable modules) {
+ final com.google.common.collect.ImmutableMap.Builder b = ImmutableMap.builder();
+ for (Module m : modules) {
+ b.put(m.getName(), m.getShardStrategy());
+ }
+ return b.build();
+ }
+
+ private static Map createNamespaceToModuleName(Iterable modules) {
+ final com.google.common.collect.ImmutableMap.Builder b = ImmutableMap.builder();
+ for (Module m : modules) {
+ b.put(m.getNameSpace(), m.getName());
+ }
+ return b.build();
+ }
+
+ private static ListMultimap createModuleNameToShardName(Iterable moduleShards) {
+ final com.google.common.collect.ImmutableListMultimap.Builder b = ImmutableListMultimap.builder();
+
+ for (ModuleShard m : moduleShards) {
+ for (Shard s : m.getShards()) {
+ b.put(m.getModuleName(), s.getName());
+ }
+ }
+
+ return b.build();
}
@Override public List getMemberShardNames(final String memberName){
@@ -104,41 +155,21 @@ public class ConfigurationImpl implements Configuration {
}
- @Override public Optional getModuleNameFromNameSpace(final String nameSpace) {
-
+ @Override
+ public Optional getModuleNameFromNameSpace(final String nameSpace) {
Preconditions.checkNotNull(nameSpace, "nameSpace should not be null");
-
- for(Module m : modules){
- if(m.getNameSpace().equals(nameSpace)){
- return Optional.of(m.getName());
- }
- }
- return Optional.absent();
+ return Optional.fromNullable(namespaceToModuleName.get(nameSpace));
}
- @Override public Map getModuleNameToShardStrategyMap() {
- Map map = new HashMap<>();
- for(Module m : modules){
- map.put(m.getName(), m.getShardStrategy());
- }
- return map;
+ @Override
+ public Map getModuleNameToShardStrategyMap() {
+ return moduleNameToStrategy;
}
- @Override public List getShardNamesFromModuleName(final String moduleName) {
-
+ @Override
+ public List getShardNamesFromModuleName(final String moduleName) {
Preconditions.checkNotNull(moduleName, "moduleName should not be null");
-
- for(ModuleShard m : moduleShards){
- if(m.getModuleName().equals(moduleName)){
- List l = new ArrayList<>();
- for(Shard s : m.getShards()){
- l.add(s.getName());
- }
- return l;
- }
- }
-
- return Collections.emptyList();
+ return moduleNameToShardName.get(moduleName);
}
@Override public List getMembersFromShardName(final String shardName) {
@@ -162,33 +193,30 @@ public class ConfigurationImpl implements Configuration {
return Collections.emptyList();
}
- @Override public Set getAllShardNames() {
- Set shardNames = new LinkedHashSet<>();
- for(ModuleShard ms : moduleShards){
- for(Shard s : ms.getShards()) {
- shardNames.add(s.getName());
- }
- }
- return shardNames;
+ @Override
+ public Set getAllShardNames() {
+ return allShardNames;
}
-
-
- private void readModules(final Config modulesConfig) {
+ private List readModules(final Config modulesConfig) {
List extends ConfigObject> modulesConfigObjectList =
modulesConfig.getObjectList("modules");
+ final Builder b = ImmutableList.builder();
for(ConfigObject o : modulesConfigObjectList){
ConfigObjectWrapper w = new ConfigObjectWrapper(o);
- modules.add(new Module(w.stringValue("name"), w.stringValue(
+ b.add(new Module(w.stringValue("name"), w.stringValue(
"namespace"), w.stringValue("shard-strategy")));
}
+
+ return b.build();
}
- private void readModuleShards(final Config moduleShardsConfig) {
+ private static List readModuleShards(final Config moduleShardsConfig) {
List extends ConfigObject> moduleShardsConfigObjectList =
moduleShardsConfig.getObjectList("module-shards");
+ final Builder b = ImmutableList.builder();
for(ConfigObject moduleShardConfigObject : moduleShardsConfigObjectList){
String moduleName = moduleShardConfigObject.get("name").unwrapped().toString();
@@ -204,12 +232,13 @@ public class ConfigurationImpl implements Configuration {
shards.add(new Shard(shardName, replicas));
}
- this.moduleShards.add(new ModuleShard(moduleName, shards));
+ b.add(new ModuleShard(moduleName, shards));
}
- }
+ return b.build();
+ }
- private class ModuleShard {
+ private static class ModuleShard {
private final String moduleName;
private final List shards;
@@ -227,7 +256,7 @@ public class ConfigurationImpl implements Configuration {
}
}
- private class Shard {
+ private static class Shard {
private final String name;
private final List replicas;
@@ -257,7 +286,7 @@ public class ConfigurationImpl implements Configuration {
if(ModuleShardStrategy.NAME.equals(shardStrategy)){
this.shardStrategy = new ModuleShardStrategy(name, ConfigurationImpl.this);
} else {
- this.shardStrategy = new DefaultShardStrategy();
+ this.shardStrategy = DefaultShardStrategy.getInstance();
}
}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransactionReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransactionReply.java
index 7db4846ef4..7e8cd436d2 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransactionReply.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransactionReply.java
@@ -17,13 +17,16 @@ public class CanCommitTransactionReply implements SerializableMessage {
public static final CanCommitTransactionReply YES = new CanCommitTransactionReply(true);
public static final CanCommitTransactionReply NO = new CanCommitTransactionReply(false);
+ private static final ThreePhaseCommitCohortMessages.CanCommitTransactionReply YES_SERIALIZED =
+ ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().setCanCommit(true).build();
+
+ private static final ThreePhaseCommitCohortMessages.CanCommitTransactionReply NO_SERIALIZED =
+ ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().setCanCommit(false).build();
+
private final boolean canCommit;
- private final Object serializedMessage;
private CanCommitTransactionReply(final boolean canCommit) {
this.canCommit = canCommit;
- this.serializedMessage = ThreePhaseCommitCohortMessages.CanCommitTransactionReply.newBuilder().
- setCanCommit(canCommit).build();
}
public boolean getCanCommit() {
@@ -32,7 +35,7 @@ public class CanCommitTransactionReply implements SerializableMessage {
@Override
public Object toSerializable() {
- return serializedMessage;
+ return canCommit ? YES_SERIALIZED : NO_SERIALIZED;
}
public static CanCommitTransactionReply fromSerializable(final Object message) {
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/MergeData.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/MergeData.java
index 9234385b35..ae0d630cf2 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/MergeData.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/MergeData.java
@@ -55,7 +55,7 @@ public class MergeData extends ModifyData implements VersionedSerializableMessag
}
public static boolean isSerializedType(Object message) {
- return SERIALIZABLE_CLASS.isAssignableFrom(message.getClass()) ||
+ return SERIALIZABLE_CLASS.isInstance(message) ||
message instanceof ShardTransactionMessages.MergeData;
}
}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/WriteData.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/WriteData.java
index c5e3a6b059..989949c88f 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/WriteData.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/WriteData.java
@@ -55,7 +55,7 @@ public class WriteData extends ModifyData implements VersionedSerializableMessag
}
public static boolean isSerializedType(Object message) {
- return SERIALIZABLE_CLASS.isAssignableFrom(message.getClass()) ||
+ return SERIALIZABLE_CLASS.isInstance(message) ||
message instanceof ShardTransactionMessages.WriteData;
}
}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategy.java
index 55c682b860..6a3de4256b 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategy.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategy.java
@@ -16,13 +16,21 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
* The default shard stores data for all modules for which a specific set of shards has not been configured
*
*/
-public class DefaultShardStrategy implements ShardStrategy{
+public final class DefaultShardStrategy implements ShardStrategy {
+ public static final String NAME = "default";
+ public static final String DEFAULT_SHARD = "default";
+ private static final DefaultShardStrategy INSTANCE = new DefaultShardStrategy();
- public static final String NAME = "default";
- public static final String DEFAULT_SHARD = "default";
+ private DefaultShardStrategy() {
+ // Hidden to force a singleton instnace
+ }
- @Override
- public String findShard(YangInstanceIdentifier path) {
- return DEFAULT_SHARD;
- }
+ public static DefaultShardStrategy getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public String findShard(YangInstanceIdentifier path) {
+ return DEFAULT_SHARD;
+ }
}
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java
index fc7ebd94dd..e9ecf7eac3 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategy.java
@@ -8,11 +8,10 @@
package org.opendaylight.controller.cluster.datastore.shardstrategy;
+import java.util.List;
import org.opendaylight.controller.cluster.datastore.Configuration;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import java.util.List;
-
public class ModuleShardStrategy implements ShardStrategy {
public static final String NAME = "module";
@@ -26,10 +25,11 @@ public class ModuleShardStrategy implements ShardStrategy {
this.configuration = configuration;
}
- @Override public String findShard(YangInstanceIdentifier path) {
+ @Override
+ public String findShard(YangInstanceIdentifier path) {
List shardNames =
configuration.getShardNamesFromModuleName(moduleName);
- if(shardNames.size() == 0){
+ if (shardNames.isEmpty()) {
return DefaultShardStrategy.DEFAULT_SHARD;
}
return shardNames.get(0);
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactory.java
index 62fb65482b..fd786c903e 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactory.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactory.java
@@ -36,7 +36,7 @@ public class ShardStrategyFactory {
String moduleName = getModuleName(path);
ShardStrategy shardStrategy = moduleNameToStrategyMap.get(moduleName);
if (shardStrategy == null) {
- return new DefaultShardStrategy();
+ return DefaultShardStrategy.getInstance();
}
return shardStrategy;
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategyTest.java
index c065782af5..5842d566ab 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategyTest.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/DefaultShardStrategyTest.java
@@ -5,10 +5,9 @@ import org.junit.Test;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
public class DefaultShardStrategyTest {
-
- @Test
- public void testFindShard() throws Exception {
- String shard = new DefaultShardStrategy().findShard(TestModel.TEST_PATH);
- Assert.assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shard);
- }
+ @Test
+ public void testFindShard() throws Exception {
+ String shard = DefaultShardStrategy.getInstance().findShard(TestModel.TEST_PATH);
+ Assert.assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shard);
+ }
}
\ No newline at end of file