From: Tony Tkacik Date: Tue, 15 Apr 2014 07:46:03 +0000 (+0000) Subject: Merge "Cleanup utility classes" X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~232 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=6932c15f119da55b17ce4ad39236566bfed96ab3;hp=207dfa6ea38ed9847bb48aa052ebf70d68d0a37d Merge "Cleanup utility classes" --- diff --git a/.gitignore b/.gitignore index 175ab5f0a0..6fc003be27 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,8 @@ opendaylight/northbound/integrationtest/logs/* *.iws .idea xtend-gen +yang-gen-config +yang-gen-sal classes out/ .externalToolBuilders diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index 1e8d3d26b5..d5d7e8e5c4 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -115,7 +115,9 @@ 1.3.1 2.4.3 - ${project.build.directory}/generated-sources/xtend-gen + src/main/xtend-gen + src/main/yang-gen-config + src/main/yang-gen-sal @@ -1717,7 +1719,7 @@ true ${project.basedir} **\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat - **\/target\/,**\/bin\/,**\/target-ide\/ + **\/target\/,**\/bin\/,**\/target-ide\/,**\/${jmxGeneratorPath}\/,**\/${salGeneratorPath}\/ @@ -1784,6 +1786,10 @@ + + org.codehaus.mojo + build-helper-maven-plugin + @@ -2005,6 +2011,52 @@ + + maven-clean-plugin + + + + ${xtend.dstdir} + + ** + + + + ${jmxGeneratorPath} + + ** + + + + ${salGeneratorPath} + + ** + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + add-source + generate-sources + + add-source + + + + ${jmxGeneratorPath} + ${salGeneratorPath} + ${xtend.dstdir} + + + + + diff --git a/opendaylight/commons/protocol-framework/pom.xml b/opendaylight/commons/protocol-framework/pom.xml index 650d2dd35b..1a1a2561cc 100644 --- a/opendaylight/commons/protocol-framework/pom.xml +++ b/opendaylight/commons/protocol-framework/pom.xml @@ -25,11 +25,6 @@ 3.0.4 - - ${project.build.directory}/generated-sources/config - ${project.build.directory}/generated-sources/sal - - io.netty diff --git a/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml index 21b1a5590b..80abd87262 100644 --- a/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml +++ b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml @@ -8,8 +8,6 @@ bundle - ${project.build.directory}/generated-sources/config - ${project.build.directory}/generated-sources/sal ${config-api-version} ${yang-maven-plugin-version} ${maven-bundle-plugin-version} @@ -78,26 +76,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${jmxGeneratorPath} - - - - - - org.apache.felix maven-bundle-plugin diff --git a/opendaylight/config/config-plugin-parent/pom.xml b/opendaylight/config/config-plugin-parent/pom.xml index e382c33871..2c607f81d0 100644 --- a/opendaylight/config/config-plugin-parent/pom.xml +++ b/opendaylight/config/config-plugin-parent/pom.xml @@ -14,10 +14,6 @@ 3.0.4 - - ${project.build.directory}/generated-sources/config - - @@ -56,28 +52,6 @@ - - - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${jmxGeneratorPath} - ${salGeneratorPath} - - - - - diff --git a/opendaylight/config/logback-config/pom.xml b/opendaylight/config/logback-config/pom.xml index fbebda526a..2fe515c312 100644 --- a/opendaylight/config/logback-config/pom.xml +++ b/opendaylight/config/logback-config/pom.xml @@ -89,6 +89,7 @@ org.opendaylight.yangtools yang-maven-plugin + diff --git a/opendaylight/config/netty-threadgroup-config/pom.xml b/opendaylight/config/netty-threadgroup-config/pom.xml index 54143355f4..332426faa5 100644 --- a/opendaylight/config/netty-threadgroup-config/pom.xml +++ b/opendaylight/config/netty-threadgroup-config/pom.xml @@ -68,8 +68,6 @@ org.opendaylight.yangtools yang-maven-plugin - - org.apache.felix maven-bundle-plugin diff --git a/opendaylight/config/pom.xml b/opendaylight/config/pom.xml index d700075e95..8efed2d9f6 100644 --- a/opendaylight/config/pom.xml +++ b/opendaylight/config/pom.xml @@ -62,7 +62,6 @@ 5.0.0 0.6.2.201302030002 1.7.2 - ${project.build.directory}/generated-sources/sal @@ -305,26 +304,6 @@ - - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${salGeneratorPath} - - - - - org.apache.maven.plugins maven-jar-plugin diff --git a/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml b/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml index fc0ef32954..f3fd230d5b 100644 --- a/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml +++ b/opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml @@ -30,9 +30,6 @@ org.eclipse.xtend xtend-maven-plugin - - maven-clean-plugin - diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/pom.xml b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/pom.xml index b7e193b59d..aef489ec83 100644 --- a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/pom.xml +++ b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/pom.xml @@ -31,9 +31,6 @@ org.eclipse.xtend xtend-maven-plugin - - maven-clean-plugin - diff --git a/opendaylight/md-sal/forwardingrules-manager/pom.xml b/opendaylight/md-sal/forwardingrules-manager/pom.xml index 00cbc18e7e..68eaa96871 100644 --- a/opendaylight/md-sal/forwardingrules-manager/pom.xml +++ b/opendaylight/md-sal/forwardingrules-manager/pom.xml @@ -31,9 +31,6 @@ org.eclipse.xtend xtend-maven-plugin - - maven-clean-plugin - diff --git a/opendaylight/md-sal/inventory-manager/pom.xml b/opendaylight/md-sal/inventory-manager/pom.xml index 362a349657..31621deeea 100644 --- a/opendaylight/md-sal/inventory-manager/pom.xml +++ b/opendaylight/md-sal/inventory-manager/pom.xml @@ -59,9 +59,6 @@ org.eclipse.xtend xtend-maven-plugin - - maven-clean-plugin - diff --git a/opendaylight/md-sal/model/pom.xml b/opendaylight/md-sal/model/pom.xml index 4c8a74c62b..a2a526426e 100644 --- a/opendaylight/md-sal/model/pom.xml +++ b/opendaylight/md-sal/model/pom.xml @@ -91,24 +91,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - generate-sources - - add-source - - - - target/generated-sources/sal - - - - - diff --git a/opendaylight/md-sal/pom.xml b/opendaylight/md-sal/pom.xml index a45cadab7c..631f1118c5 100644 --- a/opendaylight/md-sal/pom.xml +++ b/opendaylight/md-sal/pom.xml @@ -86,23 +86,9 @@ - - IDE - - - m2e.version - - - - - target-ide - - - ${project.build.directory}/generated-sources/sal UTF-8 @@ -220,30 +206,6 @@ org.eclipse.xtend xtend-maven-plugin ${xtend.version} - - - - compile - - - ${basedir}/src/main/xtend-gen - - - - - - maven-clean-plugin - ${maven.clean.plugin.version} - - - - ${basedir}/src/main/xtend-gen - - ** - - - - org.jacoco @@ -311,27 +273,6 @@ org.apache.felix maven-bundle-plugin - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/config - ${project.build.directory}/generated-sources/sal - src/main/xtend-gen - - - - - org.apache.maven.plugins maven-jar-plugin diff --git a/opendaylight/md-sal/sal-binding-broker/pom.xml b/opendaylight/md-sal/sal-binding-broker/pom.xml index dafb3ef634..9976f48114 100644 --- a/opendaylight/md-sal/sal-binding-broker/pom.xml +++ b/opendaylight/md-sal/sal-binding-broker/pom.xml @@ -30,7 +30,7 @@ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${project.build.directory}/generated-sources/config + ${jmxGeneratorPath} urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang @@ -72,28 +72,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - - - ${project.build.directory}/generated-sources/config - src/main/xtend-gen - - - - - org.apache.felix maven-bundle-plugin @@ -122,9 +100,6 @@ org.eclipse.xtend xtend-maven-plugin - - maven-clean-plugin - org.jacoco jacoco-maven-plugin diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java index 4f9c429e50..6334457fd4 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java @@ -21,6 +21,7 @@ import org.eclipse.xtext.xbase.lib.Exceptions; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException; import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; @@ -108,27 +109,34 @@ public class AbstractForwardedTransaction currentArguments = new ArrayList<>(); - DataNormalizationOperation currentOp = codec.getDataNormalizer().getRootOperation(); - Iterator iterator = normalizedPath.getPath().iterator(); - while (iterator.hasNext()) { - PathArgument currentArg = iterator.next(); + List currentArguments = new ArrayList<>(); + DataNormalizationOperation currentOp = codec.getDataNormalizer().getRootOperation(); + Iterator iterator = normalizedPath.getPath().iterator(); + while (iterator.hasNext()) { + PathArgument currentArg = iterator.next(); + try { currentOp = currentOp.getChild(currentArg); - currentArguments.add(currentArg); - org.opendaylight.yangtools.yang.data.api.InstanceIdentifier currentPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier( - currentArguments); - boolean isPresent = writeTransaction.read(store, currentPath).get().isPresent(); - if (isPresent == false && iterator.hasNext()) { - writeTransaction.put(store, currentPath, currentOp.createDefault(currentArg)); - } + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", path), e); + } + currentArguments.add(currentArg); + org.opendaylight.yangtools.yang.data.api.InstanceIdentifier currentPath = new org.opendaylight.yangtools.yang.data.api.InstanceIdentifier( + currentArguments); + + final Optional> d; + try { + d = writeTransaction.read(store, currentPath).get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Failed to read pre-existing data from store {} path {}", store, currentPath, e); + throw new IllegalStateException("Failed to read pre-existing data", e); + } + + if (!d.isPresent() && iterator.hasNext()) { + writeTransaction.put(store, currentPath, currentOp.createDefault(currentArg)); } - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); } //LOG .info("Tx: {} : Putting data {}",getDelegate().getIdentifier(),normalized.getKey()); writeTransaction.put(store, normalized.getKey(), normalized.getValue()); - } protected void doMerge(final DOMDataWriteTransaction writeTransaction, final LogicalDatastoreType store, diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend index fe2681f1f7..6d675b4b5e 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend @@ -60,7 +60,7 @@ class NotificationBrokerImpl implements NotificationProviderService, AutoCloseab override publish(Notification notification, ExecutorService service) { val allTypes = notification.notificationTypes - var Iterable> listenerToNotify = Collections.emptySet(); + var Iterable> listenerToNotify = Collections.emptySet(); for (type : allTypes) { listenerToNotify = listenerToNotify + listeners.get(type as Class) } diff --git a/opendaylight/md-sal/sal-binding-config/pom.xml b/opendaylight/md-sal/sal-binding-config/pom.xml index 145dc37552..f75995dc22 100644 --- a/opendaylight/md-sal/sal-binding-config/pom.xml +++ b/opendaylight/md-sal/sal-binding-config/pom.xml @@ -43,7 +43,7 @@ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${project.build.directory}/generated-sources/config + ${jmxGeneratorPath} urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang @@ -73,25 +73,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/config - - - - - diff --git a/opendaylight/md-sal/sal-binding-dom-it/pom.xml b/opendaylight/md-sal/sal-binding-dom-it/pom.xml index 82e3d97572..94832c14b6 100644 --- a/opendaylight/md-sal/sal-binding-dom-it/pom.xml +++ b/opendaylight/md-sal/sal-binding-dom-it/pom.xml @@ -19,9 +19,6 @@ org.eclipse.xtend xtend-maven-plugin - - maven-clean-plugin - org.jacoco jacoco-maven-plugin diff --git a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationException.java b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationException.java new file mode 100644 index 0000000000..f7a15b614e --- /dev/null +++ b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationException.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.md.sal.common.impl.util.compat; + +public class DataNormalizationException extends Exception { + private static final long serialVersionUID = 1L; + + public DataNormalizationException(String message) { + super(message); + } + + public DataNormalizationException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java index 941f2fdb39..1055fa81fd 100644 --- a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java +++ b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.md.sal.common.impl.util.compat; import static com.google.common.base.Preconditions.checkArgument; @@ -70,9 +77,9 @@ public abstract class DataNormalizationOperation impleme return Collections.singleton(identifier.getNodeType()); } - public abstract DataNormalizationOperation getChild(final PathArgument child); + public abstract DataNormalizationOperation getChild(final PathArgument child) throws DataNormalizationException; - public abstract DataNormalizationOperation getChild(QName child); + public abstract DataNormalizationOperation getChild(QName child) throws DataNormalizationException; public abstract NormalizedNode normalize(Node legacyData); @@ -162,7 +169,13 @@ public abstract class DataNormalizationOperation impleme Set> usedMixins = new HashSet<>(); for (Node childLegacy : compositeNode.getValue()) { - DataNormalizationOperation childOp = getChild(childLegacy.getNodeType()); + final DataNormalizationOperation childOp; + + try { + childOp = getChild(childLegacy.getNodeType()); + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Failed to normalize data %s", compositeNode.getValue()), e); + } // We skip unknown nodes if this node is mixin since // it's nodes and parent nodes are interleaved @@ -175,8 +188,7 @@ public abstract class DataNormalizationOperation impleme if (childOp.isMixin()) { if (usedMixins.contains(childOp)) { // We already run / processed that mixin, so to avoid - // dupliciry we are - // skiping next nodes. + // duplicity we are skipping next nodes. continue; } builder.addChild(childOp.normalize(compositeNode)); @@ -208,7 +220,7 @@ public abstract class DataNormalizationOperation impleme } @Override - public DataNormalizationOperation getChild(final PathArgument child) { + public DataNormalizationOperation getChild(final PathArgument child) throws DataNormalizationException { DataNormalizationOperation potential = byArg.get(child); if (potential != null) { return potential; @@ -218,7 +230,7 @@ public abstract class DataNormalizationOperation impleme } @Override - public DataNormalizationOperation getChild(final QName child) { + public DataNormalizationOperation getChild(final QName child) throws DataNormalizationException { DataNormalizationOperation potential = byQName.get(child); if (potential != null) { return potential; @@ -486,15 +498,19 @@ public abstract class DataNormalizationOperation impleme } } - public static DataNormalizationOperation fromSchemaAndPathArgument(final DataNodeContainer schema, - final QName child) { + private static DataNormalizationOperation fromSchemaAndPathArgument(final DataNodeContainer schema, + final QName child) throws DataNormalizationException { DataSchemaNode potential = schema.getDataChildByName(child); if (potential == null) { Iterable choices = FluentIterable.from( schema.getChildNodes()).filter(org.opendaylight.yangtools.yang.model.api.ChoiceNode.class); potential = findChoice(choices, child); } - checkArgument(potential != null, "Supplied QName %s is not valid according to schema %s", child, schema); + + if (potential == null) { + throw new DataNormalizationException(String.format("Supplied QName %s is not valid according to schema %s", child, schema)); + } + if ((schema instanceof DataSchemaNode) && !((DataSchemaNode) schema).isAugmenting() && potential.isAugmenting()) { return fromAugmentation(schema, (AugmentationTarget) schema, potential); } @@ -541,7 +557,7 @@ public abstract class DataNormalizationOperation impleme } } - private static DataNormalizationOperation fromSchema(final DataNodeContainer schema, final PathArgument child) { + private static DataNormalizationOperation fromSchema(final DataNodeContainer schema, final PathArgument child) throws DataNormalizationException { if (child instanceof AugmentationIdentifier) { return fromSchemaAndPathArgument(schema, ((AugmentationIdentifier) child).getPossibleChildNames() .iterator().next()); diff --git a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java index 28b2bde26d..e1fc3c3cdb 100644 --- a/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java +++ b/opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.md.sal.common.impl.util.compat; import static com.google.common.base.Preconditions.checkArgument; @@ -7,6 +14,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Map; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier; @@ -44,18 +52,24 @@ public class DataNormalizer { DataNormalizationOperation currentOp = operation; Iterator arguments = legacy.getPath().iterator(); - while ( arguments.hasNext() ) { - PathArgument legacyArg = arguments.next(); - currentOp = currentOp.getChild(legacyArg); - checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s",legacy,normalizedArgs.build()); - while (currentOp.isMixin()) { - normalizedArgs.add(currentOp.getIdentifier()); - currentOp = currentOp.getChild(legacyArg.getNodeType()); - } - if(arguments.hasNext() || (!currentOp.isKeyedEntry() || legacyArg instanceof NodeIdentifierWithPredicates || legacyArg instanceof NodeWithValue)) { - normalizedArgs.add(legacyArg); + + try { + while ( arguments.hasNext() ) { + PathArgument legacyArg = arguments.next(); + currentOp = currentOp.getChild(legacyArg); + checkArgument(currentOp != null, "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s",legacy,normalizedArgs.build()); + while (currentOp.isMixin()) { + normalizedArgs.add(currentOp.getIdentifier()); + currentOp = currentOp.getChild(legacyArg.getNodeType()); + } + if(arguments.hasNext() || (!currentOp.isKeyedEntry() || legacyArg instanceof NodeIdentifierWithPredicates || legacyArg instanceof NodeWithValue)) { + normalizedArgs.add(legacyArg); + } } + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e); } + return new InstanceIdentifier(normalizedArgs.build()); } @@ -69,12 +83,24 @@ public class DataNormalizer { DataNormalizationOperation currentOp = operation; for (PathArgument arg : normalizedPath.getPath()) { - currentOp = currentOp.getChild(arg); + try { + currentOp = currentOp.getChild(arg); + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Failed to validate normalized path %s", normalizedPath), e); + } } - // Write Augmentaiton data resolution + + // Write Augmentation data resolution if (legacyData.getChildren().size() == 1) { - DataNormalizationOperation potentialOp = currentOp.getChild(legacyData.getChildren().get(0) - .getNodeType()); + final DataNormalizationOperation potentialOp; + + try { + final QName childType = legacyData.getChildren().get(0).getNodeType(); + potentialOp = currentOp.getChild(childType); + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Failed to get child operation for %s", legacyData), e); + } + if(potentialOp.getIdentifier() instanceof AugmentationIdentifier) { currentOp = potentialOp; ArrayList reworkedArgs = new ArrayList<>(normalizedPath.getPath()); diff --git a/opendaylight/md-sal/sal-dom-api/pom.xml b/opendaylight/md-sal/sal-dom-api/pom.xml index 15932d56ce..181fc5c0c5 100644 --- a/opendaylight/md-sal/sal-dom-api/pom.xml +++ b/opendaylight/md-sal/sal-dom-api/pom.xml @@ -33,7 +33,7 @@ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${project.build.directory}/generated-sources/config + ${jmxGeneratorPath} urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang @@ -79,25 +79,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/config - - - - - diff --git a/opendaylight/md-sal/sal-dom-broker/pom.xml b/opendaylight/md-sal/sal-dom-broker/pom.xml index 5063e4339b..360988fbb2 100644 --- a/opendaylight/md-sal/sal-dom-broker/pom.xml +++ b/opendaylight/md-sal/sal-dom-broker/pom.xml @@ -84,7 +84,7 @@ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${project.build.directory}/generated-sources/config + ${jmxGeneratorPath} urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang @@ -156,26 +156,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/config - src/main/xtend-gen - - - - - org.eclipse.xtend xtend-maven-plugin diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java index fce2494554..b905d2f673 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.md.sal.dom.broker.impl.compat; import static com.google.common.base.Preconditions.checkNotNull; @@ -14,6 +21,7 @@ import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException; import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation; import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction; @@ -232,7 +240,11 @@ public abstract class BackwardsCompatibleTransaction iterator = normalizedPath.getPath().iterator(); while(iterator.hasNext()) { PathArgument currentArg = iterator.next(); - currentOp = currentOp.getChild(currentArg); + try { + currentOp = currentOp.getChild(currentArg); + } catch (DataNormalizationException e) { + throw new IllegalArgumentException(String.format("Invalid child encountered in path %s", normalizedPath), e); + } currentArguments.add(currentArg); InstanceIdentifier currentPath = new InstanceIdentifier(currentArguments); boolean isPresent = getDelegate().read(store, currentPath).get().isPresent(); diff --git a/opendaylight/md-sal/sal-netconf-connector/pom.xml b/opendaylight/md-sal/sal-netconf-connector/pom.xml index 182441d3f5..ae819b0f78 100644 --- a/opendaylight/md-sal/sal-netconf-connector/pom.xml +++ b/opendaylight/md-sal/sal-netconf-connector/pom.xml @@ -204,7 +204,7 @@ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${project.build.directory}/generated-sources/config + ${jmxGeneratorPath} urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang @@ -235,27 +235,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/config - src/main/xtend-gen - - - - - - org.eclipse.xtend xtend-maven-plugin diff --git a/opendaylight/md-sal/sal-remote/pom.xml b/opendaylight/md-sal/sal-remote/pom.xml index 15bd2e7a30..0c06b4490d 100644 --- a/opendaylight/md-sal/sal-remote/pom.xml +++ b/opendaylight/md-sal/sal-remote/pom.xml @@ -64,25 +64,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/ - - - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml index 415ae5aa05..0c817d26f6 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml +++ b/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml @@ -157,7 +157,7 @@ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${project.build.directory}/generated-sources/config + ${jmxGeneratorPath} urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java index 722ca06879..d256b998d4 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java @@ -254,7 +254,6 @@ public class ServerImpl implements RemoteRpcServer { e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { _logger.error("Failed to get list of interfaces", e1); - //throw new RuntimeException("Failed to acquire list of interfaces", e1); return null; } while (e.hasMoreElements()) { @@ -265,7 +264,7 @@ public class ServerImpl implements RemoteRpcServer { while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); _logger.debug("Trying address {}", i); - if ((i instanceof Inet4Address) && (i.isSiteLocalAddress())) { + if ((i instanceof Inet4Address) && (!i.isLoopbackAddress())) { String hostAddress = i.getHostAddress(); _logger.debug("Settled on host address {}", hostAddress); return hostAddress; diff --git a/opendaylight/md-sal/sal-restconf-broker/pom.xml b/opendaylight/md-sal/sal-restconf-broker/pom.xml index 2fe625ffb3..c086db7ba4 100644 --- a/opendaylight/md-sal/sal-restconf-broker/pom.xml +++ b/opendaylight/md-sal/sal-restconf-broker/pom.xml @@ -66,25 +66,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${project.build.directory}/generated-sources/ - - - - - diff --git a/opendaylight/md-sal/samples/l2switch/model/pom.xml b/opendaylight/md-sal/samples/l2switch/model/pom.xml index d0ef2e0c65..7c54309fa1 100644 --- a/opendaylight/md-sal/samples/l2switch/model/pom.xml +++ b/opendaylight/md-sal/samples/l2switch/model/pom.xml @@ -41,7 +41,7 @@ org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl - target/generated-sources/sal + ${salGeneratorPath} diff --git a/opendaylight/md-sal/samples/toaster-consumer/pom.xml b/opendaylight/md-sal/samples/toaster-consumer/pom.xml index 67fc824a7b..0c16a92586 100644 --- a/opendaylight/md-sal/samples/toaster-consumer/pom.xml +++ b/opendaylight/md-sal/samples/toaster-consumer/pom.xml @@ -16,8 +16,6 @@ 1.1-SNAPSHOT - ${project.build.directory}/generated-sources/config - @@ -84,25 +82,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${jmxGeneratorPath} - - - - - diff --git a/opendaylight/md-sal/samples/toaster-provider/pom.xml b/opendaylight/md-sal/samples/toaster-provider/pom.xml index 4e4cfeda2a..11ee47b8c7 100644 --- a/opendaylight/md-sal/samples/toaster-provider/pom.xml +++ b/opendaylight/md-sal/samples/toaster-provider/pom.xml @@ -16,7 +16,6 @@ - ${project.build.directory}/generated-sources/config 1.1-SNAPSHOT @@ -82,25 +81,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-source - generate-sources - - add-source - - - - ${jmxGeneratorPath} - - - - - diff --git a/opendaylight/md-sal/samples/toaster/pom.xml b/opendaylight/md-sal/samples/toaster/pom.xml index 59f8955d4b..eb13e64adc 100644 --- a/opendaylight/md-sal/samples/toaster/pom.xml +++ b/opendaylight/md-sal/samples/toaster/pom.xml @@ -49,24 +49,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - generate-sources - - add-source - - - - target/generated-sources/sal - - - - - diff --git a/opendaylight/md-sal/statistics-manager/pom.xml b/opendaylight/md-sal/statistics-manager/pom.xml index b829990bd3..9ace8a119f 100644 --- a/opendaylight/md-sal/statistics-manager/pom.xml +++ b/opendaylight/md-sal/statistics-manager/pom.xml @@ -66,9 +66,6 @@ - - maven-clean-plugin - diff --git a/opendaylight/md-sal/topology-lldp-discovery/pom.xml b/opendaylight/md-sal/topology-lldp-discovery/pom.xml index 590e8ea91a..627934eb67 100644 --- a/opendaylight/md-sal/topology-lldp-discovery/pom.xml +++ b/opendaylight/md-sal/topology-lldp-discovery/pom.xml @@ -92,29 +92,6 @@ org.eclipse.xtend xtend-maven-plugin - - - - compile - - - ${basedir}/src/main/xtend-gen - - - - - - maven-clean-plugin - - - - ${basedir}/src/main/xtend-gen - - ** - - - - diff --git a/opendaylight/md-sal/topology-manager/pom.xml b/opendaylight/md-sal/topology-manager/pom.xml index 8035f420fb..8503864f62 100644 --- a/opendaylight/md-sal/topology-manager/pom.xml +++ b/opendaylight/md-sal/topology-manager/pom.xml @@ -68,9 +68,6 @@ org.eclipse.xtend xtend-maven-plugin - - maven-clean-plugin - diff --git a/opendaylight/netconf/ietf-netconf-monitoring-extension/pom.xml b/opendaylight/netconf/ietf-netconf-monitoring-extension/pom.xml index 7b872db9a6..2590ad8b11 100644 --- a/opendaylight/netconf/ietf-netconf-monitoring-extension/pom.xml +++ b/opendaylight/netconf/ietf-netconf-monitoring-extension/pom.xml @@ -31,10 +31,6 @@ org.opendaylight.yangtools yang-maven-plugin - - org.codehaus.mojo - build-helper-maven-plugin - org.apache.felix diff --git a/opendaylight/netconf/ietf-netconf-monitoring/pom.xml b/opendaylight/netconf/ietf-netconf-monitoring/pom.xml index f1e5764ca6..bd2f1cc807 100644 --- a/opendaylight/netconf/ietf-netconf-monitoring/pom.xml +++ b/opendaylight/netconf/ietf-netconf-monitoring/pom.xml @@ -38,10 +38,6 @@ org.opendaylight.yangtools yang-maven-plugin - - org.codehaus.mojo - build-helper-maven-plugin - org.apache.felix diff --git a/opendaylight/netconf/netconf-client/pom.xml b/opendaylight/netconf/netconf-client/pom.xml index b0f5f74810..25ed0e7ab1 100644 --- a/opendaylight/netconf/netconf-client/pom.xml +++ b/opendaylight/netconf/netconf-client/pom.xml @@ -68,6 +68,19 @@ + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + package + + test-jar + + + + diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java deleted file mode 100644 index 6ae966d1f7..0000000000 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.netconf.client; - -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; - -/** - * Class extending {@link NetconfClientSessionListener} to provide notification capability. - */ -public abstract class AbstractNetconfClientNotifySessionListener extends SimpleNetconfClientSessionListener { - /* - * Maybe some capabilities could be expressed as internal NetconfClientSessionListener handlers. - * It would enable NetconfClient functionality to be extended by using namespace handlers. - * So far let just enable notification capability by extending and let parent class intact. - */ - - /** - * As class purpose is to provide notification capability to session listener - * onMessage method is not allowed to be further overridden. - * {@see #onNotification(NetconfClientSession, NetconfMessage)} - * - * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - */ - @Override - public final void onMessage(NetconfClientSession session, NetconfMessage message) { - if (isNotification(message)) { - onNotification(session, message); - } else { - super.onMessage(session, message); - } - } - - /** - * Method intended to customize notification processing. - * - * @param session {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - * @param message {@see NetconfClientSessionListener#onMessage(NetconfClientSession, NetconfMessage)} - */ - public abstract void onNotification(NetconfClientSession session, NetconfMessage message); - - private boolean isNotification(NetconfMessage message) { - XmlElement xmle = XmlElement.fromDomDocument(message.getDocument()); - return XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME.equals(xmle.getName()) ; - } -} diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java deleted file mode 100644 index 4cdca208bc..0000000000 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.netconf.client; - -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GlobalEventExecutor; - -import java.io.Closeable; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Set; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; -import org.opendaylight.protocol.framework.ReconnectStrategy; -import org.opendaylight.protocol.framework.TimedReconnectStrategy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Preconditions; -import com.google.common.base.Stopwatch; -import com.google.common.collect.Sets; - -/** - * @deprecated Use {@link NetconfClientDispatcher.createClient()} or {@link NetconfClientDispatcher.createReconnectingClient()} instead. - */ -@Deprecated -public class NetconfClient implements Closeable { - - private static final Logger logger = LoggerFactory.getLogger(NetconfClient.class); - - public static final int DEFAULT_CONNECT_TIMEOUT = 5000; - private final NetconfClientDispatcher dispatch; - private final String label; - private final NetconfClientSession clientSession; - private final NetconfClientSessionListener sessionListener; - private final long sessionId; - private final InetSocketAddress address; - - // TODO test reconnecting constructor - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectionAttempts, - int attemptMsTimeout, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this(clientLabelForLogging, address, getReconnectStrategy(connectionAttempts, attemptMsTimeout), - netconfClientDispatcher); - } - - private NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this.label = clientLabelForLogging; - dispatch = netconfClientDispatcher; - sessionListener = new SimpleNetconfClientSessionListener(); - Future clientFuture = dispatch.createClient(address, sessionListener, strat); - this.address = address; - clientSession = get(clientFuture); - this.sessionId = clientSession.getSessionId(); - } - - private NetconfClientSession get(Future clientFuture) throws InterruptedException { - try { - return clientFuture.get(); - } catch (CancellationException e) { - throw new RuntimeException("Cancelling " + this, e); - } catch (ExecutionException e) { - throw new IllegalStateException("Unable to create " + this, e); - } - } - - public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher); - } - - public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, - ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException { - return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher,listener); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs, - NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this(clientLabelForLogging, address, - new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), netconfClientDispatcher); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, - NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { - this(clientLabelForLogging, address, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, - DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher); - } - - public NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, - NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException{ - this.label = clientLabelForLogging; - dispatch = netconfClientDispatcher; - sessionListener = listener; - Future clientFuture = dispatch.createClient(address, sessionListener, strategy); - this.address = address; - clientSession = get(clientFuture); - this.sessionId = clientSession.getSessionId(); - } - - public Future sendRequest(NetconfMessage message) { - return ((SimpleNetconfClientSessionListener)sessionListener).sendRequest(message); - } - - /** - * @deprecated Use {@link sendRequest} instead - */ - @Deprecated - public NetconfMessage sendMessage(NetconfMessage message) throws ExecutionException, InterruptedException, TimeoutException { - return sendMessage(message, 5, 1000); - } - - /** - * @deprecated Use {@link sendRequest} instead - */ - @Deprecated - public NetconfMessage sendMessage(NetconfMessage message, int attempts, int attemptMsDelay) throws ExecutionException, InterruptedException, TimeoutException { - //logger.debug("Sending message: {}",XmlUtil.toString(message.getDocument())); - final Stopwatch stopwatch = new Stopwatch().start(); - - try { - return sendRequest(message).get(attempts * attemptMsDelay, TimeUnit.MILLISECONDS); - } finally { - stopwatch.stop(); - logger.debug("Total time spent waiting for response from {}: {} ms", address, stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - } - - @Override - public void close() throws IOException { - clientSession.close(); - } - - public NetconfClientDispatcher getNetconfClientDispatcher() { - return dispatch; - } - - private static ReconnectStrategy getReconnectStrategy(int connectionAttempts, int attemptMsTimeout) { - return new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, attemptMsTimeout, 1000, 1.0, null, - Long.valueOf(connectionAttempts), null); - } - - @Override - public String toString() { - final StringBuffer sb = new StringBuffer("NetconfClient{"); - sb.append("label=").append(label); - sb.append(", sessionId=").append(sessionId); - sb.append('}'); - return sb.toString(); - } - - public long getSessionId() { - return sessionId; - } - - public Set getCapabilities() { - Preconditions.checkState(clientSession != null, "Client was not initialized successfully"); - return Sets.newHashSet(clientSession.getServerCapabilities()); - } - - public NetconfClientSession getClientSession() { - return clientSession; - } -} diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java index bb372b3aff..cff214401c 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java @@ -58,8 +58,9 @@ public class NetconfClientSessionNegotiatorFactory implements SessionNegotiatorF if(this.additionalHeader.isPresent()) { helloMessage = new NetconfHelloMessage(helloMessage.getDocument(), additionalHeader.get()); - } else + } else { helloMessage = new NetconfHelloMessage(helloMessage.getDocument()); + } NetconfSessionPreferences proposal = new NetconfSessionPreferences(helloMessage); return new NetconfClientSessionNegotiator(proposal, promise, channel, timer, diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java index e96161c29a..504e4c9949 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java @@ -101,7 +101,7 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL } } - final synchronized Future sendRequest(NetconfMessage message) { + public final synchronized Future sendRequest(NetconfMessage message) { final RequestEntry req = new RequestEntry(GlobalEventExecutor.INSTANCE.newPromise(), message); requests.add(req); diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java deleted file mode 100644 index 1357201f57..0000000000 --- a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.netconf.client; - -import io.netty.channel.nio.NioEventLoopGroup; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -@Ignore -public class SSHNetconfClientLiveTest { - private static final Logger logger = LoggerFactory.getLogger(SSHNetconfClientLiveTest.class); - - NioEventLoopGroup nettyThreadgroup; - NetconfSshClientDispatcher netconfClientDispatcher; - InetSocketAddress address; - final int connectionAttempts = 10, attemptMsTimeout = 1000; - final int connectionTimeoutMillis = 20000; - - @Before - public void setUp() { - nettyThreadgroup = new NioEventLoopGroup(); - - netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword( - System.getProperty("username"), System.getProperty("password")), - nettyThreadgroup, nettyThreadgroup, connectionTimeoutMillis); - - address = new InetSocketAddress(System.getProperty("host"), Integer.parseInt(System.getProperty("port"))); - } - - @Ignore - @Test - public void test() throws Exception { - //runnable.run(); - } - - @Test - public void testInExecutor() throws Exception { - int threads = 4; - ExecutorService executorService = Executors.newFixedThreadPool(threads); - try { - for (int i= 0;i< threads;i++) { - InetSocketAddress address = new InetSocketAddress(System.getProperty("host"), - Integer.parseInt(System.getProperty("port"))); - NetconfRunnable runnable = new NetconfRunnable(address); - executorService.execute(runnable); - } - executorService.shutdown(); - executorService.awaitTermination(1, TimeUnit.MINUTES); - - - } finally { - executorService.shutdownNow(); - } - } - - class NetconfRunnable implements Runnable { - private final InetSocketAddress address; - - NetconfRunnable(InetSocketAddress address) { - this.address = address; - } - - @Override - public void run() { - try (NetconfClient netconfClient = new NetconfClient(address.toString(), address, connectionAttempts, - attemptMsTimeout, netconfClientDispatcher);) { - logger.info("OK {}", address); - } catch (InterruptedException | IOException e) { - logger.error("Failed {}", address, e); - } - } - }; -} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java new file mode 100644 index 0000000000..32c6ea85d6 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.netconf.client.test; + +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GlobalEventExecutor; + +import java.io.Closeable; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.Set; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.NetconfClientSession; +import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; +import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategy; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; + + +/** + * Synchronous netconf client suitable for testing + */ +public class TestingNetconfClient implements Closeable { + + public static final int DEFAULT_CONNECT_TIMEOUT = 5000; + + private final String label; + private final NetconfClientSession clientSession; + private final NetconfClientSessionListener sessionListener; + private final long sessionId; + + private TestingNetconfClient(String clientLabel, InetSocketAddress address, ReconnectStrategy strat, + NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { + this.label = clientLabel; + sessionListener = new SimpleNetconfClientSessionListener(); + Future clientFuture = netconfClientDispatcher.createClient(address, sessionListener, strat); + clientSession = get(clientFuture); + this.sessionId = clientSession.getSessionId(); + } + + private NetconfClientSession get(Future clientFuture) throws InterruptedException { + try { + return clientFuture.get(); + } catch (CancellationException e) { + throw new RuntimeException("Cancelling " + this, e); + } catch (ExecutionException e) { + throw new IllegalStateException("Unable to create " + this, e); + } + } + + public TestingNetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs, + NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { + this(clientLabelForLogging, address, + new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, connectTimeoutMs), netconfClientDispatcher); + } + + public TestingNetconfClient(String clientLabelForLogging, InetSocketAddress address, + NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException { + this(clientLabelForLogging, address, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, + DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher); + } + + public Future sendRequest(NetconfMessage message) { + return ((SimpleNetconfClientSessionListener)sessionListener).sendRequest(message); + } + + public NetconfMessage sendMessage(NetconfMessage message, int attemptMsDelay) throws ExecutionException, + InterruptedException, TimeoutException { + return sendRequest(message).get(attemptMsDelay, TimeUnit.MILLISECONDS); + } + + public NetconfMessage sendMessage(NetconfMessage message) throws ExecutionException, + InterruptedException, TimeoutException { + return sendMessage(message, DEFAULT_CONNECT_TIMEOUT); + } + + @Override + public void close() throws IOException { + clientSession.close(); + } + + @Override + public String toString() { + final StringBuffer sb = new StringBuffer("TestingNetconfClient{"); + sb.append("label=").append(label); + sb.append(", sessionId=").append(sessionId); + sb.append('}'); + return sb.toString(); + } + + public long getSessionId() { + return sessionId; + } + + public Set getCapabilities() { + Preconditions.checkState(clientSession != null, "Client was not initialized successfully"); + return Sets.newHashSet(clientSession.getServerCapabilities()); + } +} \ No newline at end of file diff --git a/opendaylight/netconf/netconf-impl/pom.xml b/opendaylight/netconf/netconf-impl/pom.xml index 76a0bd9908..b8b3028708 100644 --- a/opendaylight/netconf/netconf-impl/pom.xml +++ b/opendaylight/netconf/netconf-impl/pom.xml @@ -88,6 +88,13 @@ netconf-client test + + ${project.groupId} + netconf-client + ${project.version} + test-jar + test + org.opendaylight.controller commons.logback_settings diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index c1a7b1478b..82e8caef3a 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.mockito.Mock; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.client.NetconfClient; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; @@ -259,13 +259,13 @@ public class ConcurrentClientsTest { @Override public void run() { try { - final NetconfClient netconfClient = new NetconfClient(clientId, netconfAddress, netconfClientDispatcher); + final TestingNetconfClient netconfClient = new TestingNetconfClient(clientId, netconfAddress, netconfClientDispatcher); long sessionId = netconfClient.getSessionId(); logger.info("Client with sessionid {} hello exchanged", sessionId); final NetconfMessage getMessage = XmlFileLoader .xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); - NetconfMessage result = netconfClient.sendMessage(getMessage); + NetconfMessage result = netconfClient.sendRequest(getMessage).get(); logger.info("Client with sessionid {} got result {}", sessionId, result); netconfClient.close(); logger.info("Client with session id {} ended", sessionId); diff --git a/opendaylight/netconf/netconf-it/pom.xml b/opendaylight/netconf/netconf-it/pom.xml index aab939e8d9..68fd34e135 100644 --- a/opendaylight/netconf/netconf-it/pom.xml +++ b/opendaylight/netconf/netconf-it/pom.xml @@ -1,6 +1,9 @@ 4.0.0 + + 2.0.0 + netconf-subsystem @@ -33,11 +36,23 @@ netconf-client test + + ${project.groupId} + netconf-client + ${project.version} + test-jar + test + ${project.groupId} config-netconf-connector test + + ${project.groupId} + netty-config-api + test + ${project.groupId} config-manager @@ -114,6 +129,12 @@ org.opendaylight.controller commons.logback_settings + + org.ops4j.pax.tinybundles + tinybundles + ${tinybundles.version} + test + diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java index 997cae0f7c..78933e4b0b 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java @@ -25,8 +25,8 @@ import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification; import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; -import org.opendaylight.controller.netconf.client.NetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; @@ -121,12 +121,12 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { VerifyingNotificationListener notificationVerifier = createCommitNotificationListener(); VerifyingPersister mockedAggregator = mockAggregator(); - try (NetconfClient persisterClient = new NetconfClient("persister", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient persisterClient = new TestingNetconfClient("persister", tcpAddress, 4000, clientDispatcher)) { try (ConfigPersisterNotificationHandler configPersisterNotificationHandler = new ConfigPersisterNotificationHandler( platformMBeanServer, mockedAggregator)) { - try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", tcpAddress, 4000, clientDispatcher)) { NetconfMessage response = netconfClient.sendMessage(loadGetConfigMessage()); assertResponse(response, " capabilitiesFromNetconfServer = netconfClient.getCapabilities(); long sessionId = netconfClient.getSessionId(); @@ -191,8 +191,8 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testTwoSessions() throws Exception { - try (NetconfClient netconfClient = new NetconfClient("1", tcpAddress, 10000, clientDispatcher)) { - try (NetconfClient netconfClient2 = new NetconfClient("2", tcpAddress, 10000, clientDispatcher)) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("1", tcpAddress, 10000, clientDispatcher)) { + try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("2", tcpAddress, 10000, clientDispatcher)) { } } } @@ -208,7 +208,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void rpcReplyContainsAllAttributesTest() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { final String rpc = "" + "" + ""; final Document doc = XmlUtil.readXmlToDocument(rpc); @@ -236,7 +236,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void rpcReplyErrorContainsAllAttributesTest() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { final String rpc = "" + "" + ""; final Document doc = XmlUtil.readXmlToDocument(rpc); @@ -260,7 +260,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { transaction.commit(); - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { final String expectedNamespace = "urn:opendaylight:params:xml:ns:yang:controller:test:impl"; final String rpc = "" @@ -284,7 +284,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { /* @Test public void testStartExi() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { Document rpcReply = netconfClient.sendMessage(this.startExi) @@ -311,7 +311,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testCloseSession() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { // edit config Document rpcReply = netconfClient.sendMessage(this.editConfig) @@ -327,7 +327,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testEditConfig() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { // send edit_config.xml final Document rpcReply = netconfClient.sendMessage(this.editConfig).getDocument(); assertIsOK(rpcReply); @@ -336,7 +336,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testValidate() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { // begin transaction Document rpcReply = netconfClient.sendMessage(getConfigCandidate).getDocument(); assertEquals("data", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName()); @@ -353,11 +353,11 @@ public class NetconfITTest extends AbstractNetconfConfigTest { assertEquals("ok", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName()); } - private Document assertGetConfigWorks(final NetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException { + private Document assertGetConfigWorks(final TestingNetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException { return assertGetConfigWorks(netconfClient, this.getConfig); } - private Document assertGetConfigWorks(final NetconfClient netconfClient, final NetconfMessage getConfigMessage) + private Document assertGetConfigWorks(final TestingNetconfClient netconfClient, final NetconfMessage getConfigMessage) throws InterruptedException, ExecutionException, TimeoutException { final NetconfMessage rpcReply = netconfClient.sendMessage(getConfigMessage); assertNotNull(rpcReply); @@ -367,14 +367,14 @@ public class NetconfITTest extends AbstractNetconfConfigTest { @Test public void testGetConfig() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { assertGetConfigWorks(netconfClient); } } @Test public void createYangTestBasedOnYuma() throws Exception { - try (NetconfClient netconfClient = createSession(tcpAddress, "1")) { + try (TestingNetconfClient netconfClient = createSession(tcpAddress, "1")) { Document rpcReply = netconfClient.sendMessage( XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_yang-test.xml")) .getDocument(); @@ -392,8 +392,8 @@ public class NetconfITTest extends AbstractNetconfConfigTest { } } - private NetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception { - final NetconfClient netconfClient = new NetconfClient("test " + address.toString(), address, 5000, clientDispatcher); + private TestingNetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception { + final TestingNetconfClient netconfClient = new TestingNetconfClient("test " + address.toString(), address, 5000, clientDispatcher); assertEquals(expected, Long.toString(netconfClient.getSessionId())); return netconfClient; } diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java index 4af66532a1..01b66ab0cf 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java @@ -33,7 +33,7 @@ import org.opendaylight.controller.config.spi.ModuleFactory; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; -import org.opendaylight.controller.netconf.client.NetconfClient; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; @@ -120,8 +120,8 @@ public class NetconfMonitoringITTest extends AbstractNetconfConfigTest { @Test public void testGetResponseFromMonitoring() throws Exception { - try (NetconfClient netconfClient = new NetconfClient("client-monitoring", tcpAddress, 4000, clientDispatcher)) { - try (NetconfClient netconfClient2 = new NetconfClient("client-monitoring2", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient netconfClient = new TestingNetconfClient("client-monitoring", tcpAddress, 4000, clientDispatcher)) { + try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("client-monitoring2", tcpAddress, 4000, clientDispatcher)) { NetconfMessage response = netconfClient.sendMessage(loadGetMessage()); assertSessionElementsInResponse(response.getDocument(), 2); } diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java index c75adbba8d..18275ad78b 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java @@ -7,6 +7,22 @@ */ package org.opendaylight.controller.netconf.it.pax; +import static org.junit.Assert.fail; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.streamBundle; +import static org.ops4j.pax.exam.CoreOptions.systemPackages; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; + +import javax.inject.Inject; +import javax.xml.parsers.ParserConfigurationException; + import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import io.netty.channel.nio.NioEventLoopGroup; @@ -16,8 +32,9 @@ import org.junit.Test; import org.junit.matchers.JUnitMatchers; import org.junit.runner.RunWith; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.client.NetconfClient; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; +import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.ops4j.pax.exam.Configuration; @@ -25,29 +42,15 @@ import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.options.DefaultCompositeOption; import org.ops4j.pax.exam.util.Filter; -import org.w3c.dom.Document; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.osgi.framework.Constants; import org.xml.sax.SAXException; -import javax.inject.Inject; -import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; -import java.io.InputStream; import java.net.InetSocketAddress; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import static org.junit.Assert.fail; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import static org.ops4j.pax.exam.CoreOptions.options; -import static org.ops4j.pax.exam.CoreOptions.systemPackages; -import static org.ops4j.pax.exam.CoreOptions.systemProperty; - @Ignore @RunWith(PaxExam.class) public class IdentityRefNetconfTest { @@ -71,7 +74,24 @@ public class IdentityRefNetconfTest { loggingModules(), mdSalCoreBundles(), bindingAwareSalBundles(), configMinumumBundles(), baseModelBundles(), flowCapableModelBundles(), - junitAndMockitoBundles()); + junitAndMockitoBundles(), + + // Classes from test-jars bundled for pax-exam test + streamBundle(TinyBundles.bundle() + .add(TestingNetconfClient.class) + .add(XmlFileLoader.class) + + .add("/netconfMessages/editConfig_identities.xml", + XmlFileLoader.class.getResource("/netconfMessages/editConfig_identities.xml")) + .add("/netconfMessages/commit.xml", + XmlFileLoader.class.getResource("/netconfMessages/commit.xml")) + .add("/netconfMessages/getConfig.xml", + XmlFileLoader.class.getResource("/netconfMessages/getConfig.xml")) + + .set(Constants.BUNDLE_SYMBOLICNAME, "TestingClient_bundle") + .set(Constants.EXPORT_PACKAGE, "org.opendaylight.controller.netconf.client.test, " + + "org.opendaylight.controller.netconf.util.test") + .build(TinyBundles.withBnd()))); } private Option loggingModules() { @@ -89,29 +109,26 @@ public class IdentityRefNetconfTest { private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 18383); - @Test public void testIdRef() throws Exception { - try { - Preconditions.checkNotNull(broker, "Controller not initialized"); - - NioEventLoopGroup nettyThreadgroup = new NioEventLoopGroup(); - NetconfClientDispatcher clientDispatcher = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup, - CLIENT_CONNECTION_TIMEOUT_MILLIS); - - NetconfMessage edit = xmlFileToNetconfMessage("netconfMessages/editConfig_identities.xml"); - NetconfMessage commit = xmlFileToNetconfMessage("netconfMessages/commit.xml"); - NetconfMessage getConfig = xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); - - try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, CLIENT_CONNECTION_TIMEOUT_MILLIS, clientDispatcher)) { - sendMessage(edit, netconfClient); - sendMessage(commit, netconfClient); - sendMessage(getConfig, netconfClient, "id-test", - "prefix:test-identity1", - "prefix:test-identity2", - "prefix:test-identity2", - "prefix:test-identity1"); - } + Preconditions.checkNotNull(broker, "Controller not initialized"); + + NioEventLoopGroup nettyThreadgroup = new NioEventLoopGroup(); + NetconfClientDispatcher clientDispatcher = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup, + CLIENT_CONNECTION_TIMEOUT_MILLIS); + + NetconfMessage edit = xmlFileToNetconfMessage("netconfMessages/editConfig_identities.xml"); + NetconfMessage commit = xmlFileToNetconfMessage("netconfMessages/commit.xml"); + NetconfMessage getConfig = xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); + + try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", tcpAddress, CLIENT_CONNECTION_TIMEOUT_MILLIS, clientDispatcher)) { + sendMessage(edit, netconfClient); + sendMessage(commit, netconfClient); + sendMessage(getConfig, netconfClient, "id-test", + "prefix:test-identity1", + "prefix:test-identity2", + "prefix:test-identity2", + "prefix:test-identity1"); clientDispatcher.close(); } catch (Exception e) { @@ -119,8 +136,7 @@ public class IdentityRefNetconfTest { } } - - private void sendMessage(NetconfMessage edit, NetconfClient netconfClient, String... containingResponse) + private void sendMessage(NetconfMessage edit, TestingNetconfClient netconfClient, String... containingResponse) throws ExecutionException, InterruptedException, TimeoutException { NetconfMessage response = netconfClient.sendRequest(edit).get(); if (containingResponse == null) { @@ -134,16 +150,6 @@ public class IdentityRefNetconfTest { public static NetconfMessage xmlFileToNetconfMessage(final String fileName) throws IOException, SAXException, ParserConfigurationException { - return new NetconfMessage(xmlFileToDocument(fileName)); - } - - public static Document xmlFileToDocument(final String fileName) throws IOException, SAXException, - ParserConfigurationException { - // TODO xml messages from netconf-util test-jar cannot be loaded here(in OSGi), since test jar is not a bundle - try (InputStream resourceAsStream = IdentityRefNetconfTest.class.getClassLoader().getResourceAsStream(fileName)) { - Preconditions.checkNotNull(resourceAsStream); - final Document doc = XmlUtil.readXmlToDocument(resourceAsStream); - return doc; - } + return XmlFileLoader.xmlFileToNetconfMessage(fileName); } } diff --git a/opendaylight/netconf/pom.xml b/opendaylight/netconf/pom.xml index 2be64a8a98..9a71c47193 100644 --- a/opendaylight/netconf/pom.xml +++ b/opendaylight/netconf/pom.xml @@ -47,7 +47,6 @@ 5.0.0 2.4.0 1.7.2 - ${project.build.directory}/generated-sources/sal @@ -239,24 +238,6 @@ - - org.codehaus.mojo - build-helper-maven-plugin - 1.7 - - - generate-sources - - add-source - - - - ${salGeneratorPath} - - - - - diff --git a/opendaylight/northbound/java-client/pom.xml b/opendaylight/northbound/java-client/pom.xml index 4aa4e0328b..6de347fdde 100644 --- a/opendaylight/northbound/java-client/pom.xml +++ b/opendaylight/northbound/java-client/pom.xml @@ -127,7 +127,6 @@ org.codehaus.mojo build-helper-maven-plugin - 1.8 attach-artifacts