From: Moiz Raja Date: Mon, 26 Jan 2015 03:57:54 +0000 (+0000) Subject: Merge "Bug 2265: Use new NormalizedNode streaming in messages" X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=fcf65d723ef53f8da2dd6347f41ce19016fc36e5;hp=cad857b425b1a0072681066b2ba37b0b0dc8c111 Merge "Bug 2265: Use new NormalizedNode streaming in messages" --- diff --git a/features/pom.xml b/features/pom.xml index 4f9ff72927..ed4fa499a9 100644 --- a/features/pom.xml +++ b/features/pom.xml @@ -9,9 +9,7 @@ features-controller pom - - 3.0 - + config config-persister diff --git a/itests/pom.xml b/itests/pom.xml index c722149145..9021e634ea 100644 --- a/itests/pom.xml +++ b/itests/pom.xml @@ -9,9 +9,7 @@ itests-controller pom - - 3.0 - + base-features-it diff --git a/opendaylight/archetypes/pom.xml b/opendaylight/archetypes/pom.xml index d8ac923176..6d46aaec78 100644 --- a/opendaylight/archetypes/pom.xml +++ b/opendaylight/archetypes/pom.xml @@ -1,9 +1,6 @@ 4.0.0 - - 3.0 - org.opendaylight.controller commons.opendaylight diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index 4d95b72ce7..32aa9a3efc 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -12,9 +12,6 @@ commons.opendaylight 1.5.0-SNAPSHOT pom - - 3.0 - @@ -1720,7 +1717,7 @@ ${enforcer.version} - enforce-java + enforce-requirements enforce @@ -1729,6 +1726,9 @@ 1.7.0 + + 3.1.1 + diff --git a/opendaylight/commons/parent/pom.xml b/opendaylight/commons/parent/pom.xml index cbd6efaef8..f8364ca535 100644 --- a/opendaylight/commons/parent/pom.xml +++ b/opendaylight/commons/parent/pom.xml @@ -5,9 +5,6 @@ commons.parent 1.1.0-SNAPSHOT pom - - 3.0 - opendaylight.release diff --git a/opendaylight/commons/protocol-framework/pom.xml b/opendaylight/commons/protocol-framework/pom.xml index 00f7b3179b..38b9d175f2 100644 --- a/opendaylight/commons/protocol-framework/pom.xml +++ b/opendaylight/commons/protocol-framework/pom.xml @@ -15,9 +15,6 @@ bundle ${project.artifactId} Common protocol framework - - 3.0.4 - diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java index 9201a94de3..2aa0027e55 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeInputStreamReader.java @@ -12,6 +12,18 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream; import com.google.common.base.Preconditions; import com.google.common.base.Strings; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +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.Node; @@ -29,18 +41,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNo import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; /** * NormalizedNodeInputStreamReader reads the byte stream and constructs the normalized node including its children nodes. @@ -67,6 +67,8 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead private NormalizedNodeAttrBuilder> leafSetEntryBuilder; + private final StringBuilder reusableStringBuilder = new StringBuilder(50); + public NormalizedNodeInputStreamReader(InputStream stream) throws IOException { Preconditions.checkNotNull(stream); input = new DataInputStream(stream); @@ -147,7 +149,6 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead case NodeTypes.ANY_XML_NODE : LOG.debug("Read xml node"); - Node value = (Node) readObject(); return Builders.anyXmlBuilder().withValue((Node) readObject()).build(); case NodeTypes.MAP_NODE : @@ -196,14 +197,16 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead String namespace = readCodedString(); String revision = readCodedString(); - // Not using stringbuilder as compiler optimizes string concatenation of + String qName; if(!Strings.isNullOrEmpty(revision)) { - qName = "(" + namespace + REVISION_ARG + revision + ")" +localName; + qName = reusableStringBuilder.append('(').append(namespace).append(REVISION_ARG). + append(revision).append(')').append(localName).toString(); } else { - qName = "(" + namespace + ")" + localName; + qName = reusableStringBuilder.append('(').append(namespace).append(')'). + append(localName).toString(); } + reusableStringBuilder.delete(0, reusableStringBuilder.length()); return QNameFactory.create(qName); } @@ -213,7 +216,7 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead if(valueType == NormalizedNodeOutputStreamWriter.IS_CODE_VALUE) { return codedStringMap.get(input.readInt()); } else if(valueType == NormalizedNodeOutputStreamWriter.IS_STRING_VALUE) { - String value = input.readUTF(); + String value = input.readUTF().intern(); codedStringMap.put(Integer.valueOf(codedStringMap.size()), value); return value; } @@ -249,22 +252,22 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead return readObjSet(); case ValueTypes.BOOL_TYPE : - return input.readBoolean(); + return Boolean.valueOf(input.readBoolean()); case ValueTypes.BYTE_TYPE : - return input.readByte(); + return Byte.valueOf(input.readByte()); case ValueTypes.INT_TYPE : - return input.readInt(); + return Integer.valueOf(input.readInt()); case ValueTypes.LONG_TYPE : - return input.readLong(); + return Long.valueOf(input.readLong()); case ValueTypes.QNAME_TYPE : return readQName(); case ValueTypes.SHORT_TYPE : - return input.readShort(); + return Short.valueOf(input.readShort()); case ValueTypes.STRING_TYPE : return input.readUTF(); @@ -275,6 +278,11 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead case ValueTypes.BIG_INTEGER_TYPE : return new BigInteger(input.readUTF()); + case ValueTypes.BINARY_TYPE : + byte[] bytes = new byte[input.readInt()]; + input.readFully(bytes); + return bytes; + case ValueTypes.YANG_IDENTIFIER_TYPE : return readYangInstanceIdentifier(); @@ -313,13 +321,13 @@ public class NormalizedNodeInputStreamReader implements NormalizedNodeStreamRead return new YangInstanceIdentifier.AugmentationIdentifier(readQNameSet()); case PathArgumentTypes.NODE_IDENTIFIER : - return new NodeIdentifier(readQName()); + return new NodeIdentifier(readQName()); case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES : - return new NodeIdentifierWithPredicates(readQName(), readKeyValueMap()); + return new NodeIdentifierWithPredicates(readQName(), readKeyValueMap()); case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE : - return new NodeWithValue(readQName(), readObject()); + return new NodeWithValue(readQName(), readObject()); default : return null; diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java index 46768d5112..ddbc4f5d48 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeOutputStreamWriter.java @@ -12,11 +12,6 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream; import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.DataOutput; import java.io.DataOutputStream; import java.io.IOException; @@ -24,6 +19,11 @@ import java.io.OutputStream; 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; +import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * NormalizedNodeOutputStreamWriter will be used by distributed datastore to send normalized node in @@ -310,7 +310,6 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri } } - @SuppressWarnings("rawtypes") private void writeObject(Object value) throws IOException { byte type = ValueTypes.getSerializableType(value); @@ -339,6 +338,11 @@ public class NormalizedNodeOutputStreamWriter implements NormalizedNodeStreamWri case ValueTypes.BITS_TYPE: writeObjSet((Set) value); break; + case ValueTypes.BINARY_TYPE: + byte[] bytes = (byte[]) value; + output.writeInt(bytes.length); + output.write(bytes); + break; case ValueTypes.YANG_IDENTIFIER_TYPE: writeYangInstanceIdentifier((YangInstanceIdentifier) value); break; 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 80fa527b46..e75a454d39 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,14 +9,13 @@ package org.opendaylight.controller.cluster.datastore.node.utils.stream; import com.google.common.base.Preconditions; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; - 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 { public static final byte SHORT_TYPE = 1; @@ -30,6 +29,7 @@ public class ValueTypes { public static final byte STRING_TYPE = 9; public static final byte BIG_INTEGER_TYPE = 10; public static final byte BIG_DECIMAL_TYPE = 11; + public static final byte BINARY_TYPE = 12; private static Map, Byte> types = new HashMap<>(); @@ -45,6 +45,7 @@ public class ValueTypes { 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)); } public static final byte getSerializableType(Object node){ diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializerTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializerTest.java index 816442f885..694b467623 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializerTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializerTest.java @@ -60,7 +60,7 @@ public class NormalizedNodeSerializerTest { } ContainerNode node1 = TestModel.createBaseTestContainerBuilder() - .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATE_QNAME, binaryData)) + .withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, binaryData)) .build(); NormalizedNodeMessages.Node serializedNode1 = NormalizedNodeSerializer @@ -73,7 +73,7 @@ public class NormalizedNodeSerializerTest { // FIXME: This will not work due to BUG 2326. Once that is fixed we can uncomment this assertion // assertEquals(node1, node2); - Optional> child = node2.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.SOME_BINARY_DATE_QNAME)); + Optional> child = node2.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.SOME_BINARY_DATA_QNAME)); Object value = child.get().getValue(); diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java index 8854fc73b5..a67e887a15 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/NormalizedNodeStreamReaderWriterTest.java @@ -17,13 +17,17 @@ import org.junit.Assert; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.util.TestModel; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class NormalizedNodeStreamReaderWriterTest { @@ -31,7 +35,7 @@ public class NormalizedNodeStreamReaderWriterTest { @Test public void testNormalizedNodeStreamReaderWriter() throws IOException { - testNormalizedNodeStreamReaderWriter(TestModel.createTestContainer()); + testNormalizedNodeStreamReaderWriter(createTestContainer()); QName toaster = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","toaster"); QName darknessFactor = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","darknessFactor"); @@ -44,6 +48,29 @@ public class NormalizedNodeStreamReaderWriterTest { withChild(toasterNode).build()); } + private NormalizedNode createTestContainer() { + byte[] bytes1 = {1,2,3}; + LeafSetEntryNode entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( + new YangInstanceIdentifier.NodeWithValue(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)). + withValue(bytes1).build(); + + byte[] bytes2 = {}; + LeafSetEntryNode entry2 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier( + new YangInstanceIdentifier.NodeWithValue(TestModel.BINARY_LEAF_LIST_QNAME, bytes2)). + withValue(bytes2).build(); + + return TestModel.createBaseTestContainerBuilder(). + withChild(ImmutableLeafSetNodeBuilder.create().withNodeIdentifier( + new YangInstanceIdentifier.NodeIdentifier(TestModel.BINARY_LEAF_LIST_QNAME)). + withChild(entry1).withChild(entry2).build()). + withChild(ImmutableNodes.leafNode(TestModel.SOME_BINARY_DATA_QNAME, new byte[]{1,2,3,4})). + withChild(Builders.orderedMapBuilder(). + withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.ORDERED_LIST_QNAME)). + withChild(ImmutableNodes.mapEntry(TestModel.ORDERED_LIST_ENTRY_QNAME, + TestModel.ID_QNAME, 11)).build()). + build(); + } + private void testNormalizedNodeStreamReaderWriter(NormalizedNode input) throws IOException { byte[] byteData = null; diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java index d3abd38153..aa1cfc6cd8 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/TestModel.java @@ -10,7 +10,19 @@ package org.opendaylight.controller.cluster.datastore.util; +import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; +import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; +import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; import com.google.common.collect.ImmutableSet; +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; @@ -36,18 +48,6 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntry; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder; -import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder; - public class TestModel { public static final QName TEST_QNAME = QName.create( @@ -65,7 +65,8 @@ public class TestModel { public static final QName DESC_QNAME = QName.create(TEST_QNAME, "desc"); public static final QName POINTER_QNAME = QName.create(TEST_QNAME, "pointer"); - public static final QName SOME_BINARY_DATE_QNAME = QName.create(TEST_QNAME, "some-binary-data"); + public static final QName SOME_BINARY_DATA_QNAME = QName.create(TEST_QNAME, "some-binary-data"); + public static final QName BINARY_LEAF_LIST_QNAME = QName.create(TEST_QNAME, "binary_leaf_list"); public static final QName SOME_REF_QNAME = QName.create(TEST_QNAME, "some-ref"); public static final QName MYIDENTITY_QNAME = QName.create(TEST_QNAME, @@ -73,8 +74,8 @@ public class TestModel { public static final QName SWITCH_FEATURES_QNAME = QName.create(TEST_QNAME, "switch-features"); - public static final QName AUGMENTED_LIST_QNAME = QName.create(TEST_QNAME, - "augmented-list"); + public static final QName AUGMENTED_LIST_QNAME = QName.create(TEST_QNAME, "augmented-list"); + public static final QName AUGMENTED_LIST_ENTRY_QNAME = QName.create(TEST_QNAME, "augmented-list-entry"); public static final QName OUTER_LIST_QNAME = QName.create(TEST_QNAME, "outer-list"); @@ -85,6 +86,16 @@ public class TestModel { public static final QName ID_QNAME = QName.create(TEST_QNAME, "id"); public static final QName NAME_QNAME = QName.create(TEST_QNAME, "name"); public static final QName VALUE_QNAME = QName.create(TEST_QNAME, "value"); + public static final QName BOOLEAN_LEAF_QNAME = QName.create(TEST_QNAME, "boolean-leaf"); + public static final QName SHORT_LEAF_QNAME = QName.create(TEST_QNAME, "short-leaf"); + public static final QName BYTE_LEAF_QNAME = QName.create(TEST_QNAME, "byte-leaf"); + public static final QName BIGINTEGER_LEAF_QNAME = QName.create(TEST_QNAME, "biginteger-leaf"); + public static final QName BIGDECIMAL_LEAF_QNAME = QName.create(TEST_QNAME, "bigdecimal-leaf"); + public static final QName ORDERED_LIST_QNAME = QName.create(TEST_QNAME, "ordered-list"); + public static final QName ORDERED_LIST_ENTRY_QNAME = QName.create(TEST_QNAME, "ordered-list-entry"); + public static final QName UNKEYED_LIST_QNAME = QName.create(TEST_QNAME, "unkeyed-list"); + public static final QName UNKEYED_LIST_ENTRY_QNAME = QName.create(TEST_QNAME, "unkeyed-list-entry"); + public static final QName CHOICE_QNAME = QName.create(TEST_QNAME, "choice"); private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang"; private static final String DATASTORE_AUG_YANG = "/odl-datastore-augmentation.yang"; @@ -107,7 +118,7 @@ public class TestModel { private static final String TWO_TWO_NAME = "two"; private static final String DESC = "Hello there"; private static final Long LONG_ID = 1L; - private static final Boolean ENABLED = false; + private static final Boolean ENABLED = true; private static final Short SHORT_ID = 1; private static final Byte BYTE_ID = 1; // Family specific constants @@ -149,83 +160,6 @@ public class TestModel { private static final String SECOND_GRAND_CHILD_NAME = "second grand child"; - // first child - private static final YangInstanceIdentifier CHILDREN_1_PATH = - YangInstanceIdentifier.builder(CHILDREN_PATH) - .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, FIRST_CHILD_ID) // - .build(); - private static final YangInstanceIdentifier CHILDREN_1_NAME_PATH = - YangInstanceIdentifier.builder(CHILDREN_PATH) - .nodeWithKey(CHILDREN_QNAME, CHILD_NAME_QNAME, FIRST_CHILD_NAME) // - .build(); - - private static final YangInstanceIdentifier CHILDREN_2_PATH = - YangInstanceIdentifier.builder(CHILDREN_PATH) - .nodeWithKey(CHILDREN_QNAME, CHILD_NUMBER_QNAME, SECOND_CHILD_ID) // - .build(); - private static final YangInstanceIdentifier CHILDREN_2_NAME_PATH = - YangInstanceIdentifier.builder(CHILDREN_PATH) - .nodeWithKey(CHILDREN_QNAME, CHILD_NAME_QNAME, SECOND_CHILD_NAME) // - .build(); - - - private static final YangInstanceIdentifier GRAND_CHILD_1_PATH = - YangInstanceIdentifier - .builder(CHILDREN_1_PATH) - .node(GRAND_CHILDREN_QNAME) - // - .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME, - FIRST_GRAND_CHILD_ID) // - .build(); - - private static final YangInstanceIdentifier GRAND_CHILD_1_NAME_PATH = - YangInstanceIdentifier - .builder(CHILDREN_1_PATH) - .node(GRAND_CHILDREN_QNAME) - // - .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NAME_QNAME, - FIRST_GRAND_CHILD_NAME) // - .build(); - - private static final YangInstanceIdentifier GRAND_CHILD_2_PATH = - YangInstanceIdentifier - .builder(CHILDREN_2_PATH) - .node(GRAND_CHILDREN_QNAME) - // - .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NUMBER_QNAME, - SECOND_GRAND_CHILD_ID) // - .build(); - - private static final YangInstanceIdentifier GRAND_CHILD_2_NAME_PATH = - YangInstanceIdentifier - .builder(CHILDREN_2_PATH) - .node(GRAND_CHILDREN_QNAME) - // - .nodeWithKey(GRAND_CHILDREN_QNAME, GRAND_CHILD_NAME_QNAME, - SECOND_GRAND_CHILD_NAME) // - .build(); - - private static final YangInstanceIdentifier DESC_PATH_ID = - YangInstanceIdentifier.builder(DESC_PATH).build(); - private static final YangInstanceIdentifier OUTER_LIST_1_PATH = - YangInstanceIdentifier.builder(OUTER_LIST_PATH) - .nodeWithKey(OUTER_LIST_QNAME, ID_QNAME, ONE_ID) // - .build(); - - private static final YangInstanceIdentifier OUTER_LIST_2_PATH = - YangInstanceIdentifier.builder(OUTER_LIST_PATH) - .nodeWithKey(OUTER_LIST_QNAME, ID_QNAME, TWO_ID) // - .build(); - - private static final YangInstanceIdentifier TWO_TWO_PATH = - YangInstanceIdentifier.builder(OUTER_LIST_2_PATH).node(INNER_LIST_QNAME) // - .nodeWithKey(INNER_LIST_QNAME, NAME_QNAME, TWO_TWO_NAME) // - .build(); - - private static final YangInstanceIdentifier TWO_TWO_VALUE_PATH = - YangInstanceIdentifier.builder(TWO_TWO_PATH).node(VALUE_QNAME) // - .build(); - private static final MapEntryNode BAR_NODE = mapEntryBuilder( OUTER_LIST_QNAME, ID_QNAME, TWO_ID) // .withChild(mapNodeBuilder(INNER_LIST_QNAME) // @@ -362,7 +296,7 @@ public class TestModel { // Create augmentations - MapEntryNode mapEntry = createAugmentedListEntry(1, "First Test"); + MapEntryNode augMapEntry = createAugmentedListEntry(1, "First Test"); // Create a bits leaf NormalizedNodeAttrBuilder> @@ -371,10 +305,19 @@ public class TestModel { QName.create(TEST_QNAME, "my-bits"))).withValue( ImmutableSet.of("foo", "bar")); - // Create unkey list entry - UnkeyedListEntryNode binaryDataKey = - Builders.unkeyedListEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)). - withChild(ImmutableNodes.leafNode(SOME_BINARY_DATE_QNAME, DESC)).build(); + // Create unkeyed list entry + UnkeyedListEntryNode unkeyedListEntry = + Builders.unkeyedListEntryBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_ENTRY_QNAME)). + withChild(ImmutableNodes.leafNode(NAME_QNAME, "unkeyed-entry-name")).build(); + + // Create YangInstanceIdentifier with all path arg types. + YangInstanceIdentifier instanceID = YangInstanceIdentifier.create( + new YangInstanceIdentifier.NodeIdentifier(QName.create(TEST_QNAME, "qname")), + new YangInstanceIdentifier.NodeIdentifierWithPredicates(QName.create(TEST_QNAME, "list-entry"), + QName.create(TEST_QNAME, "key"), 10), + new YangInstanceIdentifier.AugmentationIdentifier(ImmutableSet.of( + QName.create(TEST_QNAME, "aug1"), QName.create(TEST_QNAME, "aug2"))), + new YangInstanceIdentifier.NodeWithValue(QName.create(TEST_QNAME, "leaf-list-entry"), "foo")); Map keyValues = new HashMap<>(); keyValues.put(CHILDREN_QNAME, FIRST_CHILD_NAME); @@ -383,32 +326,30 @@ public class TestModel { // Create the document return ImmutableContainerNodeBuilder .create() - .withNodeIdentifier( - new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)) + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)) .withChild(myBits.build()) .withChild(ImmutableNodes.leafNode(DESC_QNAME, DESC)) - .withChild(ImmutableNodes.leafNode(POINTER_QNAME, ENABLED)) - .withChild(ImmutableNodes.leafNode(POINTER_QNAME, SHORT_ID)) - .withChild(ImmutableNodes.leafNode(POINTER_QNAME, BYTE_ID)) - .withChild( - ImmutableNodes.leafNode(SOME_REF_QNAME, GRAND_CHILD_1_PATH)) + .withChild(ImmutableNodes.leafNode(BOOLEAN_LEAF_QNAME, ENABLED)) + .withChild(ImmutableNodes.leafNode(SHORT_LEAF_QNAME, SHORT_ID)) + .withChild(ImmutableNodes.leafNode(BYTE_LEAF_QNAME, BYTE_ID)) + .withChild(ImmutableNodes.leafNode(TestModel.BIGINTEGER_LEAF_QNAME, BigInteger.valueOf(100))) + .withChild(ImmutableNodes.leafNode(TestModel.BIGDECIMAL_LEAF_QNAME, BigDecimal.valueOf(1.2))) + .withChild(ImmutableNodes.leafNode(SOME_REF_QNAME, instanceID)) .withChild(ImmutableNodes.leafNode(MYIDENTITY_QNAME, DESC_QNAME)) - .withChild(Builders.unkeyedListBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(OUTER_LIST_QNAME)) - .withChild(binaryDataKey).build()) - .withChild(Builders.orderedMapBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(mapEntry).build()) - .withChild(Builders.choiceBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)) + .withChild(Builders.unkeyedListBuilder() + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(UNKEYED_LIST_QNAME)) + .withChild(unkeyedListEntry).build()) + .withChild(Builders.choiceBuilder() + .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_QNAME)) .withChild(ImmutableNodes.leafNode(DESC_QNAME, LONG_ID)).build()) // .withChild(augmentationNode) .withChild(shoes) .withChild(numbers) .withChild(switchFeatures) - .withChild( - mapNodeBuilder(AUGMENTED_LIST_QNAME).withChild(mapEntry).build()) - .withChild( - mapNodeBuilder(OUTER_LIST_QNAME) - .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID)) - .withChild(BAR_NODE).build() + .withChild(mapNodeBuilder(AUGMENTED_LIST_QNAME).withChild(augMapEntry).build()) + .withChild(mapNodeBuilder(OUTER_LIST_QNAME) + .withChild(mapEntry(OUTER_LIST_QNAME, ID_QNAME, ONE_ID)) + .withChild(BAR_NODE).build() ); } @@ -441,7 +382,7 @@ public class TestModel { .create() .withNodeIdentifier( new YangInstanceIdentifier.NodeIdentifierWithPredicates( - AUGMENTED_LIST_QNAME, ID_QNAME, id)) + AUGMENTED_LIST_ENTRY_QNAME, ID_QNAME, id)) .withChild(ImmutableNodes.leafNode(ID_QNAME, id)) .withChild(augmentationNode).build(); } diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/resources/odl-datastore-test.yang b/opendaylight/md-sal/sal-clustering-commons/src/test/resources/odl-datastore-test.yang index a1fbc1fdad..c720d5e0cd 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/resources/odl-datastore-test.yang +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/resources/odl-datastore-test.yang @@ -74,6 +74,10 @@ module odl-datastore-test { type uint8; } + leaf-list binary_leaf_list { + type binary; + } + leaf pointer { type leafref { path "/network-topology/topology/node/termination-point/tp-id"; diff --git a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf index 89cd033df3..96ed7f1838 100644 --- a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf +++ b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/05-clustering.xml.conf @@ -97,7 +97,7 @@ urn:opendaylight:params:xml:ns:yang:controller:config:concurrent-data-broker?module=odl-concurrent-data-broker-cfg&revision=2014-11-24 - urn:opendaylight:params:xml:ns:yang:controller:config:distributed-datastore-provider?module=distributed-datastore-privider&revision=2014-06-12 + urn:opendaylight:params:xml:ns:yang:controller:config:distributed-datastore-provider?module=distributed-datastore-provider&revision=2014-06-12 urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:config-dom-store?module=opendaylight-config-dom-datastore&revision=2014-06-17 urn:opendaylight:params:xml:ns:yang:controller:md:sal:core:spi:operational-dom-store?module=opendaylight-operational-dom-datastore&revision=2014-06-17 urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom?module=opendaylight-md-sal-dom&revision=2013-10-28 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ClusterWrapperImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ClusterWrapperImpl.java index 4edd60a33a..d7bfae1b42 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ClusterWrapperImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ClusterWrapperImpl.java @@ -32,9 +32,8 @@ public class ClusterWrapperImpl implements ClusterWrapper { "member-3 here would be the name of the member" ); - currentMemberName = (String) cluster.getSelfRoles().toArray()[0]; + currentMemberName = cluster.getSelfRoles().iterator().next(); selfAddress = cluster.selfAddress(); - } public void subscribeToMemberEvents(ActorRef actorRef){ diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java index 004faf2de1..5d63c92e88 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreFactory.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSystem; @@ -17,15 +16,11 @@ import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.osgi.framework.BundleContext; -import java.util.concurrent.atomic.AtomicReference; - public class DistributedDataStoreFactory { + private static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data"; + private static final String CONFIGURATION_NAME = "odl-cluster-data"; - public static final String ACTOR_SYSTEM_NAME = "opendaylight-cluster-data"; - - public static final String CONFIGURATION_NAME = "odl-cluster-data"; - - private static AtomicReference persistentActorSystem = new AtomicReference<>(); + private static volatile ActorSystem persistentActorSystem = null; public static DistributedDataStore createInstance(String name, SchemaService schemaService, DatastoreContext datastoreContext, BundleContext bundleContext) { @@ -41,26 +36,25 @@ public class DistributedDataStoreFactory { return dataStore; } - synchronized private static final ActorSystem getOrCreateInstance(final BundleContext bundleContext, ConfigurationReader configurationReader) { - - AtomicReference actorSystemReference = persistentActorSystem; - String configurationName = CONFIGURATION_NAME; - String actorSystemName = ACTOR_SYSTEM_NAME; - - if (actorSystemReference.get() != null){ - return actorSystemReference.get(); + private static final ActorSystem getOrCreateInstance(final BundleContext bundleContext, ConfigurationReader configurationReader) { + ActorSystem ret = persistentActorSystem; + if (ret == null) { + synchronized (DistributedDataStoreFactory.class) { + ret = persistentActorSystem; + if (ret == null) { + // Create an OSGi bundle classloader for actor system + BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(), + Thread.currentThread().getContextClassLoader()); + + ret = ActorSystem.create(ACTOR_SYSTEM_NAME, + ConfigFactory.load(configurationReader.read()).getConfig(CONFIGURATION_NAME), classLoader); + ret.actorOf(Props.create(TerminationMonitor.class), "termination-monitor"); + + persistentActorSystem = ret; + } + } } - // Create an OSGi bundle classloader for actor system - BundleDelegatingClassLoader classLoader = new BundleDelegatingClassLoader(bundleContext.getBundle(), - Thread.currentThread().getContextClassLoader()); - - ActorSystem system = ActorSystem.create(actorSystemName, - ConfigFactory.load(configurationReader.read()).getConfig(configurationName), classLoader); - system.actorOf(Props.create(TerminationMonitor.class), "termination-monitor"); - - actorSystemReference.set(system); - return system; + return ret; } - } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index 1661bb4b5d..a3ef0339b7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -97,7 +97,8 @@ public class Shard extends RaftActor { private static final Object TX_COMMIT_TIMEOUT_CHECK_MESSAGE = "txCommitTimeoutCheck"; - public static final String DEFAULT_NAME = "default"; + @VisibleForTesting + static final String DEFAULT_NAME = "default"; // The state of this Shard private final InMemoryDOMDataStore store; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java index 88f818f0fa..10876045ae 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardManager.java @@ -25,6 +25,7 @@ import akka.persistence.RecoveryFailure; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import org.opendaylight.controller.cluster.DataPersistenceProvider; import org.opendaylight.controller.cluster.common.actor.AbstractUntypedPersistentActorWithMetering; @@ -45,10 +46,10 @@ import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContex import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import scala.concurrent.duration.Duration; - import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -91,7 +92,7 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering { private final DatastoreContext datastoreContext; - private final Collection knownModules = new HashSet<>(128); + private Collection knownModules = Collections.emptySet(); private final DataPersistenceProvider dataPersistenceProvider; @@ -182,8 +183,7 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering { if(dataPersistenceProvider.isRecoveryApplicable()) { if (message instanceof SchemaContextModules) { SchemaContextModules msg = (SchemaContextModules) message; - knownModules.clear(); - knownModules.addAll(msg.getModules()); + knownModules = ImmutableSet.copyOf(msg.getModules()); } else if (message instanceof RecoveryFailure) { RecoveryFailure failure = (RecoveryFailure) message; LOG.error(failure.cause(), "Recovery failed"); @@ -277,8 +277,7 @@ public class ShardManager extends AbstractUntypedPersistentActorWithMetering { LOG.info("New SchemaContext has a super set of current knownModules - persisting info"); - knownModules.clear(); - knownModules.addAll(newModules); + knownModules = ImmutableSet.copyOf(newModules); dataPersistenceProvider.persist(new SchemaContextModules(newModules), new Procedure() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java index f81c2a87cd..f217d05bb2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java @@ -279,7 +279,7 @@ public class ActorContext { Preconditions.checkArgument(actor != null, "actor must not be null"); Preconditions.checkArgument(message != null, "message must not be null"); - LOG.debug("Sending message {} to {}", message.getClass().toString(), actor.toString()); + LOG.debug("Sending message {} to {}", message.getClass(), actor); return ask(actor, message, timeout); } @@ -314,7 +314,7 @@ public class ActorContext { Preconditions.checkArgument(actor != null, "actor must not be null"); Preconditions.checkArgument(message != null, "message must not be null"); - LOG.debug("Sending message {} to {}", message.getClass().toString(), actor.toString()); + LOG.debug("Sending message {} to {}", message.getClass(), actor); return ask(actor, message, timeout); } @@ -341,7 +341,7 @@ public class ActorContext { Preconditions.checkArgument(actor != null, "actor must not be null"); Preconditions.checkArgument(message != null, "message must not be null"); - LOG.debug("Sending message {} to {}", message.getClass().toString(), actor.toString()); + LOG.debug("Sending message {} to {}", message.getClass(), actor); actor.tell(message, ActorRef.noSender()); } @@ -386,14 +386,14 @@ public class ActorContext { return false; } - int pathAtIndex = path.indexOf("@"); + int pathAtIndex = path.indexOf('@'); if (pathAtIndex == -1) { //if the path is of local format, then its local and is co-located return true; } else if (selfAddressHostPort != null) { // self-address and tx actor path, both are of remote path format - int slashIndex = path.indexOf("/", pathAtIndex); + int slashIndex = path.indexOf('/', pathAtIndex); if (slashIndex == -1) { return false;