Merge "Bug 714 - Fixed creating DOM Document's element with namespace"
authorTony Tkacik <ttkacik@cisco.com>
Tue, 15 Apr 2014 10:40:30 +0000 (10:40 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 15 Apr 2014 10:40:30 +0000 (10:40 +0000)
194 files changed:
.gitignore
opendaylight/commons/opendaylight/pom.xml
opendaylight/commons/protocol-framework/pom.xml
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java
opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml
opendaylight/config/config-plugin-parent/pom.xml
opendaylight/config/logback-config/pom.xml
opendaylight/config/netty-threadgroup-config/pom.xml
opendaylight/config/pom.xml
opendaylight/config/yang-jmx-generator-plugin/pom.xml
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/CodeWriter.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/FreeMarkerCodeWriterImpl.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGenerator.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/AbstractFactoryTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/AbstractFtlTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/AbstractModuleTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlFilePersister.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/StubFactoryTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/StubModuleTemplate.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/AnnotationsDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/ConstructorsDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/FieldsDirectiveProg.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/FieldsDirectiveTemplate.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/HeaderDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/JavadocDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/MethodsDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/ModuleFieldsDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/TypeDeclarationDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/UnimplementedExceptionDirective.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Annotation.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/AnnotationSerializer.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Constructor.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ConstructorSerializer.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Field.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/FieldSerializer.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Header.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/HeaderSerializer.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/MethodDeclaration.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/MethodDefinition.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/MethodSerializer.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleField.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleFieldSerializer.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/TypeDeclaration.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsFactoryGeneratedObjectFactory.groovy [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsModuleGeneratedObjectFactory.groovy [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/ConcreteModuleGeneratedObjectFactory.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/GenericGeneratedObjectFactory.groovy [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/FullyQualifiedName.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObject.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObjectBuilder.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/JavaFileInput.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/JavaFileInputBuilder.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/TypeName.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtil.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/copyright.txt [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/abstract_ftl_file.ftl [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/factory_abs_template.ftl [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/AbstractGeneratorTest.java
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/JMXGeneratorTest.java
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ModuleMXBeanEntryTemplatesTest.java
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/RuntimeRegistratorFtlFileTest.java
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlFilePersisterTest.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/AbstractGeneratedObjectTest.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/abs/AbsModuleGeneratedObjectFactoryTest.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/concrete/ConcreteModuleGeneratedObjectFactoryTest.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/FormattingUtil.java [deleted file]
opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtilTest.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/AbstractYangTest.java
opendaylight/config/yang-jmx-generator/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryTest.java
opendaylight/config/yang-test-plugin/pom.xml
opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/ProcessSources.java
opendaylight/config/yang-test-plugin/src/main/java/org/opendaylight/controller/config/yang/test/plugin/Util.java
opendaylight/config/yang-test/pom.xml
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/DepTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/IdentityTestModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/IdentityTestModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleFactory.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModule.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/controller/config/yang/test/impl/TestImplModuleFactory.java
opendaylight/md-sal/compatibility/flow-management-compatibility/pom.xml
opendaylight/md-sal/compatibility/inventory-topology-compatibility/pom.xml
opendaylight/md-sal/forwardingrules-manager/pom.xml
opendaylight/md-sal/inventory-manager/pom.xml
opendaylight/md-sal/model/pom.xml
opendaylight/md-sal/pom.xml
opendaylight/md-sal/sal-binding-broker/pom.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedTransaction.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/BrokerImplClassLoader.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/BrokerImplClassLoader.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/BindingAwareDataReaderRouter.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/BindingAwareDataReaderRouter.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/MapUtils.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/MapUtils.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java
opendaylight/md-sal/sal-binding-config/pom.xml
opendaylight/md-sal/sal-binding-dom-it/pom.xml
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/CrossBrokerRpcTest.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationException.java [new file with mode: 0644]
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizer.java
opendaylight/md-sal/sal-dom-api/pom.xml
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/RoutedRpcDefaultImplementation.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcImplementation.java
opendaylight/md-sal/sal-dom-broker/pom.xml
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/broker/impl/compat/BackwardsCompatibleTransaction.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareRpcBroker.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/RpcProvisionRegistryProxy.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/spi/RoutedRpcProcessor.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/spi/RpcRouter.java
opendaylight/md-sal/sal-netconf-connector/pom.xml
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/InventoryUtils.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.xtend
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceListener.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDeviceTwoPhaseCommitTransaction.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfInventoryUtils.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfMapping.xtend
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfRemoteSchemaSourceProvider.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/UncancellableFuture.java [new file with mode: 0644]
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/YangModelInputStreamAdapter.java [deleted file]
opendaylight/md-sal/sal-remote/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImpl.java
opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProvider.java
opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java
opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImplTest.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.xtend
opendaylight/md-sal/sal-restconf-broker/pom.xml
opendaylight/md-sal/samples/l2switch/model/pom.xml
opendaylight/md-sal/samples/toaster-consumer/pom.xml
opendaylight/md-sal/samples/toaster-provider/pom.xml
opendaylight/md-sal/samples/toaster/pom.xml
opendaylight/md-sal/statistics-manager/pom.xml
opendaylight/md-sal/topology-lldp-discovery/pom.xml
opendaylight/md-sal/topology-manager/pom.xml
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterActivator.java
opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java
opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/MockedBundleContext.java
opendaylight/netconf/ietf-netconf-monitoring-extension/pom.xml
opendaylight/netconf/ietf-netconf-monitoring/pom.xml
opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfOperationRouter.java
opendaylight/netconf/netconf-api/src/main/java/org/opendaylight/controller/netconf/api/NetconfTerminationReason.java
opendaylight/netconf/netconf-client/pom.xml
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/AbstractNetconfClientNotifySessionListener.java [deleted file]
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClient.java [deleted file]
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactory.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListener.java
opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SSHNetconfClientLiveTest.java [deleted file]
opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java [new file with mode: 0644]
opendaylight/netconf/netconf-impl/pom.xml
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/CapabilityProviderImpl.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerDispatcher.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListener.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionListenerFactory.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiator.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/NetconfServerSessionNegotiatorFactory.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/mapping/operations/DefaultCloseSession.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfImplActivator.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfMonitoringServiceImpl.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationRouterImpl.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListener.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceFactoryListenerImpl.java
opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceSnapshotImpl.java [moved from opendaylight/netconf/netconf-impl/src/main/java/org/opendaylight/controller/netconf/impl/osgi/NetconfOperationServiceSnapshot.java with 51% similarity]
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java
opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/NetconfDispatcherImplTest.java
opendaylight/netconf/netconf-it/pom.xml
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfMonitoringITTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/pax/IdentityRefNetconfTest.java
opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationProvider.java [new file with mode: 0644]
opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceSnapshot.java [moved from opendaylight/config/yang-test-plugin/src/main/resources/Header.txt with 54% similarity]
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/CloseableUtil.java [new file with mode: 0644]
opendaylight/netconf/pom.xml
opendaylight/northbound/java-client/pom.xml

index 175ab5f0a0c2eb35ffeff038ad72df428a93affc..6fc003be270022a4c55a2d4b2ccdb951886ccbbd 100644 (file)
@@ -19,6 +19,8 @@ opendaylight/northbound/integrationtest/logs/*
 *.iws
 .idea
 xtend-gen
+yang-gen-config
+yang-gen-sal
 classes
 out/
 .externalToolBuilders
index 1e8d3d26b584fd7b91bfbf340cdda3b3e7296e27..d5d7e8e5c468cac180549eb76248cc1a010ae3c5 100644 (file)
     <!-- enforcer version -->
     <enforcer.version>1.3.1</enforcer.version>
     <xtend.version>2.4.3</xtend.version>
-    <xtend.dstdir>${project.build.directory}/generated-sources/xtend-gen</xtend.dstdir>
+    <xtend.dstdir>src/main/xtend-gen</xtend.dstdir>
+    <jmxGeneratorPath>src/main/yang-gen-config</jmxGeneratorPath>
+    <salGeneratorPath>src/main/yang-gen-sal</salGeneratorPath>
   </properties>
 
   <dependencyManagement>
           <includeTestSourceDirectory>true</includeTestSourceDirectory>
           <sourceDirectory>${project.basedir}</sourceDirectory>
           <includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat</includes>
-          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/</excludes>
+          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/${jmxGeneratorPath}\/,**\/${salGeneratorPath}\/</excludes>
         </configuration>
       </plugin>
       <plugin>
           </execution>
         </executions>
       </plugin>
+      <plugin>
+          <groupId>org.codehaus.mojo</groupId>
+          <artifactId>build-helper-maven-plugin</artifactId>
+      </plugin>
     </plugins>
     <pluginManagement>
       <plugins>
                   </execution>
               </executions>
           </plugin>
+          <plugin>
+              <artifactId>maven-clean-plugin</artifactId>
+              <configuration>
+                  <filesets>
+                      <fileset>
+                          <directory>${xtend.dstdir}</directory>
+                          <includes>
+                              <include>**</include>
+                          </includes>
+                      </fileset>
+                      <fileset>
+                          <directory>${jmxGeneratorPath}</directory>
+                          <includes>
+                              <include>**</include>
+                          </includes>
+                      </fileset>
+                      <fileset>
+                          <directory>${salGeneratorPath}</directory>
+                          <includes>
+                              <include>**</include>
+                          </includes>
+                      </fileset>
+                  </filesets>
+              </configuration>
+            </plugin>
+          <plugin>
+             <groupId>org.codehaus.mojo</groupId>
+             <artifactId>build-helper-maven-plugin</artifactId>
+             <version>1.8</version>
+             <executions>
+                <execution>
+                   <id>add-source</id>
+                   <phase>generate-sources</phase>
+                   <goals>
+                      <goal>add-source</goal>
+                   </goals>
+                   <configuration>
+                      <sources>
+                         <source>${jmxGeneratorPath}</source>
+                         <source>${salGeneratorPath}</source>
+                         <source>${xtend.dstdir}</source>
+                      </sources>
+                   </configuration>
+                </execution>
+             </executions>
+            </plugin>
       </plugins>
     </pluginManagement>
   </build>
index 650d2dd35bb22586bcd064bc583402a90787b457..1a1a2561cc7abd55a6469f591019ab8eea7c6357 100644 (file)
         <maven>3.0.4</maven>
     </prerequisites>
 
-    <properties>
-        <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
-        <salGeneratorPath>${project.build.directory}/generated-sources/sal</salGeneratorPath>
-    </properties>
-
     <dependencies>
         <dependency>
             <groupId>io.netty</groupId>
index fb0718a721f15a6f702fdd0134acab5a5f3f3da6..e914162671e811682271d42bcbccbe4e89c47947 100644 (file)
@@ -283,6 +283,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
 
         int orderingIdx = 0;
         for (ModuleIdentifier moduleIdentifier : orderedModuleIdentifiers) {
+            logger.trace("Registering {}", moduleIdentifier);
             ModuleInternalTransactionalInfo entry = commitInfo.getCommitted()
                     .get(moduleIdentifier);
             if (entry == null) {
index 6b7251c302975911c598ccbc0dce4fd09678403e..bc4de5cc156580741caf9e5abcbfbd32e07556ce 100644 (file)
@@ -44,6 +44,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static java.lang.String.format;
 
 /**
@@ -380,7 +381,8 @@ class ConfigTransactionControllerImpl implements
             try {
                 logger.debug("About to commit {} in transaction {}",
                         name, getTransactionIdentifier());
-                module.getInstance();
+                AutoCloseable instance = module.getInstance();
+                checkNotNull(instance, "Instance is null:{} in transaction {}", name, getTransactionIdentifier());
             } catch (Exception e) {
                 logger.error("Commit failed on {} in transaction {}", name,
                         getTransactionIdentifier(), e);
index 21b1a5590bfb2470508a33ceed0a9a53a73d2f76..80abd87262c8c5affd1a7971570966412c741004 100644 (file)
@@ -8,8 +8,6 @@
   <packaging>bundle</packaging>
 
     <properties>
-        <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
-        <salGeneratorPath>${project.build.directory}/generated-sources/sal</salGeneratorPath>
         <config.version>${config-api-version}</config.version>
         <yangtools.version>${yang-maven-plugin-version}</yangtools.version>
         <maven.bundle.version>${maven-bundle-plugin-version}</maven.bundle.version>
                 </dependencies>
             </plugin>
 
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${jmxGeneratorPath}</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
index e382c338716bc47b4bf7b2657cec526b1835d7f9..2c607f81d07fb9e20661581d18704c4fbc496c1c 100644 (file)
         <maven>3.0.4</maven>
     </prerequisites>
 
-    <properties>
-        <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
-    </properties>
-
     <build>
         <pluginManagement>
             <plugins>
                         </dependency>
                     </dependencies>
                 </plugin>
-
-                <!-- tell eclipse about generated source folders -->
-                <plugin>
-                    <groupId>org.codehaus.mojo</groupId>
-                    <artifactId>build-helper-maven-plugin</artifactId>
-                    <version>1.8</version>
-                    <executions>
-                        <execution>
-                            <id>add-source</id>
-                            <phase>generate-sources</phase>
-                            <goals>
-                                <goal>add-source</goal>
-                            </goals>
-                            <configuration>
-                                <sources>
-                                    <source>${jmxGeneratorPath}</source>
-                                    <source>${salGeneratorPath}</source>
-                                </sources>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
             </plugins>
         </pluginManagement>
     </build>
index fbebda526acb82e80ef3a3fa82595dbb4390613a..2fe515c31292214dd4c8ed7158fb84e44797f909 100644 (file)
@@ -89,6 +89,7 @@
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
             </plugin>
+
         </plugins>
     </build>
 </project>
index 54143355f451c85552773492751b5643bb591a06..332426faa5bcb6d467bdb34a9b1d6138fdb41199 100644 (file)
@@ -68,8 +68,6 @@
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
             </plugin>
-
-
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
index d700075e950030e77856de1b84a2382878653055..8efed2d9f64915ed7d7a90963f33d21cbb6bcf3f 100644 (file)
@@ -62,7 +62,6 @@
         <osgi.version>5.0.0</osgi.version>
         <jacoco.version>0.6.2.201302030002</jacoco.version>
         <slf4j.version>1.7.2</slf4j.version>
-        <salGeneratorPath>${project.build.directory}/generated-sources/sal</salGeneratorPath>
     </properties>
 
     <dependencies>
                         </dependency>
                     </dependencies>
                 </plugin>
-                <!-- tell eclipse about generated source folders -->
-                <plugin>
-                    <groupId>org.codehaus.mojo</groupId>
-                    <artifactId>build-helper-maven-plugin</artifactId>
-                    <version>1.8</version>
-                    <executions>
-                        <execution>
-                            <id>add-source</id>
-                            <phase>generate-sources</phase>
-                            <goals>
-                                <goal>add-source</goal>
-                            </goals>
-                            <configuration>
-                                <sources>
-                                    <source>${salGeneratorPath}</source>
-                                </sources>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-jar-plugin</artifactId>
index a8119b81ae21361d657e845d9fb2bc8a95b5c242..c934530067f128b986787277a181e62ccfbc9fdb 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
         <artifactId>config-subsystem</artifactId>
             <artifactId>binding-type-provider</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>net.sourceforge.pmd</groupId>
+            <artifactId>pmd</artifactId>
+            <version>5.1.0</version>
+            <scope>test</scope>
+        </dependency>
+
+
         <dependency>
             <groupId>org.eclipse.jdt</groupId>
             <artifactId>core</artifactId>
         </dependency>
 
 
-        <dependency>
-            <groupId>org.freemarker</groupId>
-            <artifactId>freemarker</artifactId>
-            <version>2.3.20</version>
-        </dependency>
-
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>config-api</artifactId>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.codehaus.gmaven.runtime</groupId>
+            <artifactId>gmaven-runtime-2.0</artifactId>
+            <version>1.5</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.sonatype.gossip</groupId>
+                    <artifactId>gossip</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
     </dependencies>
 
     <build>
         <plugins>
             <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-jar-plugin</artifactId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.1</version>
+                <configuration>
+                    <compilerId>groovy-eclipse-compiler</compilerId>
+                    <verbose>false</verbose>
+                </configuration>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.codehaus.groovy</groupId>
+                        <artifactId>groovy-eclipse-compiler</artifactId>
+                        <version>2.8.0-01</version>
+                    </dependency>
+
+                    <dependency>
+                        <groupId>org.codehaus.groovy</groupId>
+                        <artifactId>groovy-eclipse-batch</artifactId>
+                        <version>2.1.8-01</version>
+                    </dependency>
+                </dependencies>
             </plugin>
+
         </plugins>
     </build>
 </project>
index 13d828a430b3a530a6c09aab7ffc7954b176f79b..dd2b504da9a03ab6807efc22adef2c1cf16c990b 100644 (file)
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
+import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
+import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralInterfaceTemplate;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.StubFactoryTemplate;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsFactoryGeneratedObjectFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.GenericGeneratedObjectFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
-import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
-import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
+final class CodeWriter {
+
+    private static final Logger logger = LoggerFactory.getLogger(CodeWriter.class);
+    private static final Optional<String> copyright = StringUtil.loadCopyright();
+
+    public File writeSie(ServiceInterfaceEntry sie, File outputBaseDir) {
+        try {
+            GeneralInterfaceTemplate generalInterfaceTemplate = TemplateFactory.serviceInterfaceFromSie(sie);
+            GeneratedObject go = new GenericGeneratedObjectFactory().toGeneratedObject(generalInterfaceTemplate, copyright);
+            return go.persist(outputBaseDir).get().getValue();
+        } catch (Exception e) {
+            String message = "An error occurred during Service interface generating, sie:"
+                    + sie.getTypeName() + ", " + sie.getFullyQualifiedName();
+            logger.error(message, e);
+            throw new RuntimeException(message, e);
+        }
+    }
+
+    public List<File> writeMbe(ModuleMXBeanEntry mbe, File targetBaseDir,
+                               File mainBaseDir) {
+        try {
+            List<File> generatedFiles = Lists.newArrayList();
+
+
+            Map<GeneratedObject, Boolean /*overwrite*/> gos = new HashMap<>();
+
+            // generate mx interface and abstract factory
+
+            // TOs
+            Map<String,GeneralClassTemplate> tosFromMbe = TemplateFactory.tOsFromMbe(mbe);
+            for(GeneralClassTemplate template: tosFromMbe.values()) {
+                gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(template, copyright), true);
+            }
+
+            // MXBean interface
+            GeneralInterfaceTemplate ifcTemplate = TemplateFactory.mXBeanInterfaceTemplateFromMbe(mbe);
+            gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(ifcTemplate, copyright), true);
+
+
+            // generate abstract factory
+            gos.put(new AbsFactoryGeneratedObjectFactory().toGeneratedObject(mbe, copyright), true);
+
+            // generate abstract module
+            gos.put(new AbsModuleGeneratedObjectFactory().toGeneratedObject(mbe, copyright), true);
+
+            // generate concrete factory
+            StubFactoryTemplate concreteFactory = TemplateFactory.stubFactoryTemplateFromMbe(mbe);
+            gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(concreteFactory, copyright), false);
+
+
+            // generate concrete module
+
+            gos.put(new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(mbe, copyright, Optional.<String>absent()), false);
+
+            // write runtime bean MXBeans and registrators
+            List<FtlTemplate> allFtlFiles = getRuntimeBeanFtlTemplates(mbe.getRuntimeBeans());
+            for(FtlTemplate template: allFtlFiles) {
+                gos.put(new GenericGeneratedObjectFactory().toGeneratedObject(template, copyright), true);
+            }
+
+            generatedFiles.addAll(persistGeneratedObjects(targetBaseDir, mainBaseDir, gos));
+
+            // purge nulls
+            for (Iterator<File> it = generatedFiles.iterator(); it.hasNext(); ) {
+                if (it.next() == null) {
+                    it.remove();
+                }
+            }
+
+            return generatedFiles;
+
+        } catch (Exception e) {
+            String message = "An error occurred during Module generating, mbe:"
+                    + mbe.getJavaNamePrefix();
+            logger.error(message, e);
+            throw new RuntimeException(message, e);
+        }
+    }
 
-public interface CodeWriter {
+    private List<File> persistGeneratedObjects(File targetBaseDir, File mainBaseDir, Map<GeneratedObject, Boolean> gos) throws IOException {
+        List<File> generatedFiles = new ArrayList<>();
+        for (Entry<GeneratedObject, Boolean> entry : gos.entrySet()) {
+            boolean overwrite = entry.getValue();
+            File dst;
+            if (overwrite) {
+                dst = targetBaseDir;
+            } else {
+                dst = mainBaseDir;
+            }
+            Optional<Entry<FullyQualifiedName, File>> maybePersistEntry = entry.getKey().persist(dst, overwrite);
 
-    File writeSie(ServiceInterfaceEntry sie, File targetBaseDir);
+            if (maybePersistEntry.isPresent()) {
+                generatedFiles.add(maybePersistEntry.get().getValue());
+            }
+        }
+        return generatedFiles;
+    }
 
-    List<File> writeMbe(ModuleMXBeanEntry mbe, File targetBaseDir,
-            File mainBaseDir, File resourceBaseDir);
+    private List<FtlTemplate> getRuntimeBeanFtlTemplates(Collection<RuntimeBeanEntry> runtimeBeans) {
+        if (runtimeBeans.isEmpty()) {
+            return Collections.emptyList();
+        }
+        List<FtlTemplate> allFtlFiles = new ArrayList<>();
+        { // registrators
+            Map<String, FtlTemplate> registratorNamesToFtls = RuntimeRegistratorFtlTemplate
+                    .create(RuntimeRegistratorFtlTemplate.findRoot(runtimeBeans));
 
+            allFtlFiles.addAll(registratorNamesToFtls.values());
+        }
+        { // TOs, MXBean interfaces
+            for (RuntimeBeanEntry runtimeBeanEntry : runtimeBeans) {
+                Collection<FtlTemplate> ftlFiles = TemplateFactory
+                        .getTOAndMXInterfaceFtlFiles(runtimeBeanEntry)
+                        .values();
+                allFtlFiles.addAll(ftlFiles);
+            }
+        }
+        return allFtlFiles;
+    }
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/FreeMarkerCodeWriterImpl.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/FreeMarkerCodeWriterImpl.java
deleted file mode 100644 (file)
index 2b84ed1..0000000
+++ /dev/null
@@ -1,108 +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.config.yangjmxgenerator.plugin;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
-import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
-import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlFilePersister;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Lists;
-
-final class FreeMarkerCodeWriterImpl implements CodeWriter {
-
-    private static final Logger logger = LoggerFactory
-            .getLogger(FreeMarkerCodeWriterImpl.class);
-
-    private final FtlFilePersister ftlFilePersister = new FtlFilePersister();
-
-    public FreeMarkerCodeWriterImpl() {
-    }
-
-    @Override
-    public File writeSie(ServiceInterfaceEntry sie, File outputBaseDir) {
-        try {
-            Collection<FtlTemplate> values = TemplateFactory.getFtlTemplates(
-                    sie).values();
-            return ftlFilePersister.persist(values, outputBaseDir, true).get(0);
-        } catch (Exception e) {
-            String message = "An error occurred during Service interface generating, sie:"
-                    + sie.getTypeName() + ", " + sie.getFullyQualifiedName();
-            logger.error(message, e);
-            throw new RuntimeException(message, e);
-        }
-    }
-
-    @Override
-    public List<File> writeMbe(ModuleMXBeanEntry mbe, File targetBaseDir,
-            File mainBaseDir, File resourceBaseDir) {
-        try {
-            List<File> generatedFiles = Lists.newArrayList();
-
-            generatedFiles.addAll(ftlFilePersister.persist(TemplateFactory
-                    .getFtlTemplates(mbe).values(), targetBaseDir, true));
-            generatedFiles.addAll(ftlFilePersister.persist(TemplateFactory
-                    .getFtlStubTemplates(mbe).values(), mainBaseDir, false));
-
-            // write runtime bean MXBeans and registrators
-            Collection<RuntimeBeanEntry> runtimeBeans = mbe.getRuntimeBeans();
-            if (runtimeBeans.size() > 0) {
-                List<FtlTemplate> allFtlFiles = new ArrayList<>();
-                { // registrators
-                    Map<String, FtlTemplate> registratorNamesToFtls = RuntimeRegistratorFtlTemplate
-                            .create(RuntimeRegistratorFtlTemplate.findRoot(runtimeBeans));
-
-                    allFtlFiles.addAll(registratorNamesToFtls.values());
-                }
-                { // TOs, MXBean interfaces
-                    for (RuntimeBeanEntry runtimeBeanEntry : runtimeBeans) {
-                        Collection<FtlTemplate> ftlFiles = TemplateFactory
-                                .getTOAndMXInterfaceFtlFiles(runtimeBeanEntry)
-                                .values();
-                        allFtlFiles.addAll(ftlFiles);
-                    }
-                }
-                boolean overwrite = true;
-
-                FtlFilePersister ftlFilePersister = new FtlFilePersister();
-                List<File> persisted = ftlFilePersister.persist(allFtlFiles,
-                        targetBaseDir, overwrite);
-                // FIXME: check for intersection
-                generatedFiles.addAll(persisted);
-            }
-
-            // purge nulls
-            for (Iterator<File> it = generatedFiles.iterator(); it.hasNext();) {
-                if (it.next() == null) {
-                    it.remove();
-                }
-            }
-
-            return generatedFiles;
-
-        } catch (Exception e) {
-            String message = "An error occurred during Module generating, mbe:"
-                    + mbe.getJavaNamePrefix();
-            logger.error(message, e);
-            throw new RuntimeException(message, e);
-        }
-    }
-
-}
index e41ac66952f889e60387b9c8adab0704432988b7..1b8905b9871c0a1334ebacbc28a1f6dd52d41492 100644 (file)
@@ -12,16 +12,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
@@ -40,6 +30,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.impl.StaticLoggerBinder;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
  * This class interfaces with yang-maven-plugin. Gets parsed yang modules in
  * {@link SchemaContext}, and parameters form the plugin configuration, and
@@ -61,7 +62,7 @@ public class JMXGenerator implements CodeGenerator {
     private boolean generateModuleFactoryFile = true;
 
     public JMXGenerator() {
-        this.codeWriter = new FreeMarkerCodeWriterImpl();
+        this.codeWriter = new CodeWriter();
     }
 
     public JMXGenerator(CodeWriter codeWriter) {
@@ -139,7 +140,7 @@ public class JMXGenerator implements CodeGenerator {
                 ModuleMXBeanEntry mbe = mbeEntry.getValue();
                 try {
                     List<File> files1 = codeWriter.writeMbe(mbe, outputBaseDir,
-                            mainBaseDir, resourceBaseDir);
+                            mainBaseDir);
                     generatedFiles.addFile(files1);
                 } catch (Exception e) {
                     throw new RuntimeException(
index 35dc7a36007c8fb31a0ecc05239b1b8986335c07..c3e51d6550e50344ed8fc1c9ad5c46f6282af7cc 100644 (file)
@@ -8,94 +8,26 @@
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
 
 import com.google.common.collect.Lists;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
-import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
-import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition;
-import org.osgi.framework.BundleContext;
 
 import java.util.Collections;
 import java.util.List;
 
-/**
- *
- */
 public class AbstractFactoryTemplate extends GeneralClassTemplate {
 
     private static final List<String> implementedIfcs = Lists
             .newArrayList(ModuleFactory.class.getCanonicalName());
 
-    private final String globallyUniqueName, moduleInstanceType;
-    private final List<String> providedServices;
-    private final ModuleMXBeanEntry mbe;
-
     public AbstractFactoryTemplate(Header header, String packageName,
-                                   String abstractFactoryName, String globallyUniqueName,
-                                   String moduleInstanceType, List<Field> fields,
-                                   List<String> providedServices, ModuleMXBeanEntry mbe) {
+                                   String abstractFactoryName,
+                                   List<Field> fields) {
         super(header, packageName, abstractFactoryName, Collections
                 .<String> emptyList(), implementedIfcs, fields, Collections
                 .<MethodDefinition> emptyList(), true, false, Collections
                 .<Constructor> emptyList());
-        this.globallyUniqueName = globallyUniqueName;
-        this.moduleInstanceType = moduleInstanceType;
-        this.providedServices = providedServices;
-        this.mbe = mbe;
-    }
-
-    public String getGloballyUniqueName() {
-        return globallyUniqueName;
-    }
-
-    public String getInstanceType() {
-        return AutoCloseable.class.getCanonicalName();
-    }
-
-    public String getModuleNameType() {
-        return ModuleIdentifier.class.getCanonicalName();
-    }
-
-    public String getModuleInstanceType() {
-        return moduleInstanceType;
-    }
-
-    public String getAbstractServiceInterfaceType() {
-        return AbstractServiceInterface.class.getCanonicalName();
-    }
-
-    public List<String> getProvidedServices() {
-        return providedServices;
-    }
-
-    public String getModuleType() {
-        return Module.class.getCanonicalName();
-    }
-
-    public String getDependencyResolverType() {
-        return DependencyResolver.class.getCanonicalName();
-    }
-
-    public String getDynamicMBeanWithInstanceType() {
-        return DynamicMBeanWithInstance.class.getCanonicalName();
-    }
-
-    public String getBundleContextType() {
-        return BundleContext.class.getCanonicalName();
-    }
-
-    @Override
-    public String getFtlTempleteLocation() {
-        return "factory_abs_template.ftl";
-    }
-
-    public ModuleMXBeanEntry getMbe() {
-        return mbe;
     }
 }
index 7f80299f009e04da625adc6cab1d4315eaf8e494..a9599783e609ad50432456ba3887768fe1581379 100644 (file)
@@ -7,17 +7,18 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
 
-import java.io.File;
-import java.util.List;
-
+import com.google.common.base.Optional;
+import com.google.common.collect.Lists;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.TypeDeclaration;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQualifiedNameHelper;
 
-import com.google.common.collect.Lists;
+import java.util.Collections;
+import java.util.List;
 
 public abstract class AbstractFtlTemplate implements FtlTemplate {
     private final String packageName;
@@ -44,6 +45,15 @@ public abstract class AbstractFtlTemplate implements FtlTemplate {
         return header;
     }
 
+    @Override
+    public Optional<String> getHeaderString() {
+        if (header == null) {
+            return Optional.absent();
+        } else {
+            return Optional.of(header.toString());
+        }
+    }
+
     @Override
     public String getFullyQualifiedName() {
         return FullyQualifiedNameHelper.getFullyQualifiedName(getPackageName(),
@@ -60,9 +70,14 @@ public abstract class AbstractFtlTemplate implements FtlTemplate {
         return typeDeclaration;
     }
 
+
     @Override
-    public String getJavadoc() {
-        return javadoc;
+    public Optional<String> getMaybeJavadoc() {
+        if (javadoc == null) {
+            return Optional.absent();
+        } else {
+            return Optional.of(javadoc);
+        }
     }
 
     public void setJavadoc(String javadoc) {
@@ -84,15 +99,10 @@ public abstract class AbstractFtlTemplate implements FtlTemplate {
         return methods;
     }
 
-    @Override
-    public File getRelativeFile() {
-        return new File(packageName.replace(".", File.separator),
-                getTypeDeclaration().getName() + ".java");
-    }
 
     @Override
-    public String getFtlTempleteLocation() {
-        return "abstract_ftl_file.ftl";
+    public List<Constructor> getConstructors() {
+        return Collections.emptyList();
     }
 
     @Override
index c40bfdfb9f2307bc233e79e578b41230c2cb22ab..92a71c2530186b014a1f085897579efe41ac8a7b 100644 (file)
@@ -7,26 +7,15 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
 
-import java.util.Collections;
-import java.util.List;
-
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
-import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator;
-import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
-/**
- *
- */
+import java.util.Collections;
+import java.util.List;
+
 public class AbstractModuleTemplate extends GeneralClassTemplate {
 
     private final List<ModuleField> moduleFields;
@@ -50,22 +39,6 @@ public class AbstractModuleTemplate extends GeneralClassTemplate {
         return moduleFields;
     }
 
-    public String getInstanceType() {
-        return AutoCloseable.class.getCanonicalName();
-    }
-
-    public String getModuleNameType() {
-        return ModuleIdentifier.class.getCanonicalName();
-    }
-
-    public String getAbstractServiceInterfaceType() {
-        return AbstractServiceInterface.class.getCanonicalName();
-    }
-
-    public String getModuleType() {
-        return Module.class.getCanonicalName();
-    }
-
     public String getRegistratorType() {
         return registratorType;
     }
@@ -74,29 +47,4 @@ public class AbstractModuleTemplate extends GeneralClassTemplate {
         return runtime;
     }
 
-    public String getDependencyResolverType() {
-        return DependencyResolver.class.getCanonicalName();
-    }
-
-    public String getDynamicMBeanWithInstanceType() {
-        return DynamicMBeanWithInstance.class.getCanonicalName();
-    }
-
-    public String getRootRuntimeRegistratorType() {
-        return RootRuntimeBeanRegistrator.class.getCanonicalName();
-    }
-
-    @Override
-    public String getFtlTempleteLocation() {
-        return "module_abs_template_new.ftl";
-    }
-
-    public String getLoggerType() {
-        return Logger.class.getCanonicalName();
-    }
-
-    public String getLoggerFactoryType() {
-        return LoggerFactory.class.getCanonicalName();
-    }
-
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlFilePersister.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlFilePersister.java
deleted file mode 100644 (file)
index 37d5e6b..0000000
+++ /dev/null
@@ -1,116 +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.config.yangjmxgenerator.plugin.ftl;
-
-import com.google.common.annotations.VisibleForTesting;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.AnnotationsDirective;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.ConstructorsDirective;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.FieldsDirectiveProg;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.HeaderDirective;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.JavadocDirective;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.MethodsDirective;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.ModuleFieldsDirective;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.TypeDeclarationDirective;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.directives.UnimplementedExceptionDirective;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.regex.Pattern;
-
-public class FtlFilePersister {
-    private static final Logger logger = LoggerFactory
-            .getLogger(FtlFilePersister.class);
-
-    private static final Pattern TRAILING_WHITESPACES = Pattern.compile(" +$", Pattern.MULTILINE);
-
-    @VisibleForTesting
-    public Map<FtlTemplate, String> serializeFtls(
-            Collection<? extends FtlTemplate> ftlFiles) {
-        Map<FtlTemplate, String> result = new HashMap<>();
-        for (FtlTemplate ftlFile : ftlFiles) {
-
-            try (Writer writer = new StringWriter()) {
-                Template template = getCfg().getTemplate(
-                        ftlFile.getFtlTempleteLocation());
-                try {
-                    template.process(ftlFile, writer);
-                } catch (Exception e) {
-                    throw new IllegalStateException(
-                            "Template error while generating " + ftlFile, e);
-                }
-                String fileContent = writer.toString();
-                // remove trailing spaces
-                fileContent = TRAILING_WHITESPACES.matcher(fileContent).replaceAll("");
-                result.put(ftlFile, fileContent);
-            } catch (IOException e) {
-                throw new IllegalStateException(
-                        "Exception while processing template", e);
-            }
-        }
-
-        return result;
-    }
-
-    public List<File> persist(Collection<? extends FtlTemplate> ftlFiles,
-            File dstFolder, boolean overwrite) throws IOException {
-        Map<FtlTemplate, String> ftlFileStringMap = serializeFtls(ftlFiles);
-        List<File> result = new ArrayList<>();
-        for (Entry<FtlTemplate, String> entry : ftlFileStringMap.entrySet()) {
-            FtlTemplate ftlFile = entry.getKey();
-            File targetFile = new File(dstFolder, ftlFile.getRelativeFile()
-                    .getPath());
-            File pathToFile = targetFile.getParentFile();
-            if (pathToFile.exists() == false) {
-                pathToFile.mkdirs();
-            }
-            if (targetFile.exists() && overwrite == false) {
-                logger.trace("Skipping {} since it already exists", targetFile);
-            } else {
-                try (Writer fileWriter = new FileWriter(targetFile)) {
-                    fileWriter.write(entry.getValue());
-                }
-                logger.trace("{}: File {} generated successfully",
-                        JMXGenerator.class.getCanonicalName(), targetFile);
-                result.add(targetFile);
-            }
-        }
-        return result;
-    }
-
-    private Configuration getCfg() {
-        Configuration cfg = new Configuration();
-        cfg.setClassForTemplateLoading(getClass(), "/freeMarker/");
-        cfg.setSharedVariable("javadocD", new JavadocDirective());
-        cfg.setSharedVariable("annotationsD", new AnnotationsDirective());
-        cfg.setSharedVariable("typeDeclarationD",
-                new TypeDeclarationDirective());
-        cfg.setSharedVariable("constructorsD", new ConstructorsDirective());
-        cfg.setSharedVariable("fieldsD", new FieldsDirectiveProg());
-        cfg.setSharedVariable("moduleFieldsD", new ModuleFieldsDirective());
-        cfg.setSharedVariable("methodsD", new MethodsDirective());
-        cfg.setSharedVariable("headerD", new HeaderDirective());
-        cfg.setSharedVariable("unimplementedExceptionD",
-                new UnimplementedExceptionDirective());
-        return cfg;
-    }
-
-}
index 8172a58af6e6567020679968fe38d9f0eed7d362..d01f3f92239867cbc47689f3d69cf363004f35a8 100644 (file)
@@ -7,22 +7,24 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
 
-import java.io.File;
-import java.util.List;
-
+import com.google.common.base.Optional;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.TypeDeclaration;
 
+import java.util.List;
+
 public interface FtlTemplate {
 
     Header getHeader();
+    Optional<String> getHeaderString();
 
     String getPackageName();
 
-    String getJavadoc();
+    Optional<String> getMaybeJavadoc();
 
     public List<Annotation> getAnnotations();
 
@@ -34,14 +36,5 @@ public interface FtlTemplate {
 
     List<? extends Method> getMethods();
 
-    /**
-     * @return relative path to file to be created.
-     */
-    public File getRelativeFile();
-
-    /**
-     *
-     * @return ftl template location
-     */
-    public String getFtlTempleteLocation();
+    List<Constructor> getConstructors();
 }
index be49f93bca7c13fb0a5e97ca1d4824e9a8730082..5d2d6644b0cfee7308d69dc3b721c0d26fc5e0c6 100644 (file)
@@ -7,33 +7,21 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
 
-import java.util.Collections;
-
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
+import com.google.common.collect.Lists;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition;
 
-import com.google.common.collect.Lists;
+import java.util.Collections;
 
 public class StubFactoryTemplate extends GeneralClassTemplate {
 
-    private final String moduleInstanceType;
-
     public StubFactoryTemplate(Header header, String packageName, String name,
-            String extendedClass, String moduleInstanceType) {
+                               String extendedClass) {
         super(header, packageName, name, Lists.newArrayList(extendedClass),
                 Collections.<String> emptyList(), Collections
                         .<Field> emptyList(), Collections
                         .<MethodDefinition> emptyList());
-        this.moduleInstanceType = moduleInstanceType;
-    }
-
-    public String getModuleInstanceType() {
-        return moduleInstanceType;
     }
 
-    public String getDynamicMBeanWithInstanceType() {
-        return DynamicMBeanWithInstance.class.getCanonicalName();
-    }
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/StubModuleTemplate.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/StubModuleTemplate.java
deleted file mode 100644 (file)
index f49bbba..0000000
+++ /dev/null
@@ -1,73 +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.config.yangjmxgenerator.plugin.ftl;
-
-import java.util.Collections;
-
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
-import org.opendaylight.controller.config.spi.Module;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition;
-
-import com.google.common.collect.Lists;
-
-/**
- *
- */
-public class StubModuleTemplate extends GeneralClassTemplate {
-
-    private final String extendedClass;
-
-    public StubModuleTemplate(Header header, String packageName,
-            String stubModuleName, String extendedClass) {
-        super(header, packageName, stubModuleName, Lists
-                .newArrayList(extendedClass), Collections.<String> emptyList(),
-                Collections.<Field> emptyList(), Collections
-                        .<MethodDefinition> emptyList(), false, true,
-                Collections.<Constructor> emptyList());
-        this.extendedClass = extendedClass;
-    }
-
-    public String getExtendedClass() {
-        return extendedClass;
-    }
-
-    public String getInstanceType() {
-        return AutoCloseable.class.getCanonicalName();
-    }
-
-    public String getModuleNameType() {
-        return ModuleIdentifier.class.getCanonicalName();
-    }
-
-    public String getAbstractServiceInterfaceType() {
-        return AbstractServiceInterface.class.getCanonicalName();
-    }
-
-    public String getModuleType() {
-        return Module.class.getCanonicalName();
-    }
-
-    public String getDependencyResolverType() {
-        return DependencyResolver.class.getCanonicalName();
-    }
-
-    public String getDynamicMBeanWithInstanceType() {
-        return DynamicMBeanWithInstance.class.getCanonicalName();
-    }
-
-    @Override
-    public String getFtlTempleteLocation() {
-        return "module_stub_template.ftl";
-    }
-}
index fea9a796168dddd4d335236dbd410c0ac3cd2195..7b7aab85597eafbd4fcb113abfea20dfe19c49d1 100644 (file)
@@ -7,9 +7,7 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl;
 
-import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Collections2;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.opendaylight.controller.config.api.DependencyResolver;
@@ -45,12 +43,10 @@ import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FullyQual
 import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
-import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 
 import javax.management.openmbean.SimpleType;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -59,49 +55,6 @@ import java.util.Map.Entry;
 
 public class TemplateFactory {
 
-    public static Map<String, FtlTemplate> getFtlTemplates(
-            ModuleMXBeanEntry entry) {
-        Map<String, FtlTemplate> result = new HashMap<>();
-
-        result.putAll(TemplateFactory.tOsFromMbe(entry));
-
-        // IFC
-        result.put(entry.getMXBeanInterfaceName() + ".java",
-                TemplateFactory.mXBeanInterfaceTemplateFromMbe(entry));
-
-        // ABS fact
-        result.put(entry.getAbstractFactoryName() + ".java",
-                TemplateFactory.abstractFactoryTemplateFromMbe(entry));
-
-        // ABS module
-        result.put(entry.getAbstractModuleName() + ".java",
-                TemplateFactory.abstractModuleTemplateFromMbe(entry));
-
-        return result;
-    }
-
-    public static Map<String, FtlTemplate> getFtlStubTemplates(
-            ModuleMXBeanEntry entry) {
-        Map<String, FtlTemplate> result = new HashMap<>();
-        // STUB fact
-        result.put(entry.getStubFactoryName() + ".java",
-                TemplateFactory.stubFactoryTemplateFromMbe(entry));
-
-        result.put(entry.getStubModuleName() + ".java",
-                TemplateFactory.stubModuleTemplateFromMbe(entry));
-        return result;
-    }
-
-    public static Map<String, FtlTemplate> getFtlTemplates(
-            ServiceInterfaceEntry entry) {
-
-        Map<String, FtlTemplate> result = new HashMap<>();
-        result.put(entry.getTypeName() + ".java",
-                TemplateFactory.serviceInterfaceFromSie(entry));
-
-        return result;
-    }
-
     /**
      * Get map of file name as key, FtlFile instance representing runtime mx
      * bean as value that should be persisted from this instance.
@@ -183,11 +136,6 @@ public class TemplateFactory {
         return serializeType(type, false);
     }
 
-    private static boolean isIdentityRefType(Type type) {
-        return type instanceof IdentityrefTypeDefinition;
-    }
-
-
     private static String getReturnType(AttributeIfc attributeIfc) {
         String returnType;
         if (attributeIfc instanceof TypedAttribute) {
@@ -234,28 +182,17 @@ public class TemplateFactory {
         attrProcessor.processAttributes(mbe.getAttributes(),
                 mbe.getPackageName());
 
-        Collection<String> transformed = Collections2.transform(mbe
-                .getProvidedServices().keySet(),
-                new Function<String, String>() {
 
-                    @Override
-                    public String apply(String input) {
-                        return input + ".class";
-                    }
-                });
 
         return new AbstractFactoryTemplate(getHeaderFromEntry(mbe),
                 mbe.getPackageName(), mbe.getAbstractFactoryName(),
-                mbe.getGloballyUniqueName(), mbe.getFullyQualifiedName(mbe
-                        .getStubModuleName()), attrProcessor.getFields(),
-                Lists.newArrayList(transformed), mbe);
+                attrProcessor.getFields()
+        );
     }
 
     public static AbstractModuleTemplate abstractModuleTemplateFromMbe(
             ModuleMXBeanEntry mbe) {
-        AbstractModuleAttributesProcessor attrProcessor = new AbstractModuleAttributesProcessor();
-        attrProcessor.processAttributes(mbe.getAttributes(),
-                mbe.getPackageName());
+        AbstractModuleAttributesProcessor attrProcessor = new AbstractModuleAttributesProcessor(mbe.getAttributes());
 
         List<ModuleField> moduleFields = attrProcessor.getModuleFields();
         List<String> implementedIfcs = Lists.newArrayList(
@@ -298,15 +235,8 @@ public class TemplateFactory {
             ModuleMXBeanEntry mbe) {
         return new StubFactoryTemplate(getHeaderFromEntry(mbe),
                 mbe.getPackageName(), mbe.getStubFactoryName(),
-                mbe.getFullyQualifiedName(mbe.getAbstractFactoryName()),
-                mbe.getStubModuleName());
-    }
-
-    public static StubModuleTemplate stubModuleTemplateFromMbe(
-            ModuleMXBeanEntry mbe) {
-        return new StubModuleTemplate(getHeaderFromEntry(mbe),
-                mbe.getPackageName(), mbe.getStubModuleName(),
-                mbe.getFullyQualifiedName(mbe.getAbstractModuleName()));
+                mbe.getFullyQualifiedName(mbe.getAbstractFactoryName())
+        );
     }
 
     public static GeneralInterfaceTemplate mXBeanInterfaceTemplateFromMbe(
@@ -612,12 +542,26 @@ public class TemplateFactory {
     }
 
     private static class AbstractModuleAttributesProcessor {
+        private static class Holder {
+            private final List<ModuleField> moduleFields;
+            private final List<MethodDefinition> methods;
+
+            private Holder(List<ModuleField> moduleFields, List<MethodDefinition> methods) {
+                this.moduleFields = Collections.unmodifiableList(moduleFields);
+                this.methods = Collections.unmodifiableList(methods);
+            }
+        }
 
-        private final List<ModuleField> moduleFields = Lists.newArrayList();
-        private final List<MethodDefinition> methods = Lists.newArrayList();
+        private final Holder holder;
 
-        void processAttributes(Map<String, AttributeIfc> attributes,
-                String packageName) {
+
+        private AbstractModuleAttributesProcessor(Map<String, AttributeIfc> attributes) {
+            this.holder = processAttributes(attributes);
+        }
+
+        private static Holder processAttributes(Map<String, AttributeIfc> attributes) {
+            List<ModuleField> moduleFields = new ArrayList<>();
+            List<MethodDefinition> methods = new ArrayList<>();
             for (Entry<String, AttributeIfc> attrEntry : attributes.entrySet()) {
                 String type, nullableDefaultWrapped = null;
                 AttributeIfc attributeIfc = attrEntry.getValue();
@@ -661,7 +605,7 @@ public class TemplateFactory {
 
                 String varName = BindingGeneratorUtil
                         .parseToValidParamName(attrEntry.getKey());
-
+                {
                 ModuleField field;
 
                 if (isIdentity) {
@@ -695,7 +639,7 @@ public class TemplateFactory {
                             nullableDefaultWrapped, isDependency, dependency, isListOfDependencies, needsDepResolver);
                 }
                 moduleFields.add(field);
-
+                }
                 String getterName = "get"
                         + attributeIfc.getUpperCaseCammelCase();
                 MethodDefinition getter = new MethodDefinition(type,
@@ -727,14 +671,15 @@ public class TemplateFactory {
 
                 methods.add(setter);
             }
+            return new Holder(moduleFields, methods);
         }
 
         List<ModuleField> getModuleFields() {
-            return moduleFields;
+            return holder.moduleFields;
         }
 
         List<MethodDefinition> getMethods() {
-            return methods;
+            return holder.methods;
         }
 
     }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/AnnotationsDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/AnnotationsDirective.java
deleted file mode 100644 (file)
index 4a34a1f..0000000
+++ /dev/null
@@ -1,85 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation.Parameter;
-
-import com.google.common.collect.Lists;
-
-import freemarker.core.Environment;
-import freemarker.template.SimpleSequence;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add annotations to freemarker template.
- */
-public class AnnotationsDirective implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "object";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-        List<Annotation> annotations = Lists.newArrayList();
-
-        if (object != null) {
-            if (object instanceof SimpleSequence)
-                annotations = ((SimpleSequence) object).toList();
-            else if (object instanceof FtlTemplate) {
-                annotations = ((FtlTemplate) object).getAnnotations();
-            } else
-                throw new IllegalArgumentException(
-                        "Object must be a SimpleSequence or instance of "
-                                + FtlTemplate.class + "but was "
-                                + object.getClass());
-        }
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        writeAnnotations(annotations, build, "");
-
-        if (!annotations.isEmpty())
-            out.write(build.toString().toCharArray());
-    }
-
-    static void writeAnnotations(List<Annotation> annotations,
-            StringBuilder build, String linePrefix) {
-        for (Annotation annotation : annotations) {
-            build.append(linePrefix + "@");
-            build.append(annotation.getName());
-            if (!annotation.getParams().isEmpty()) {
-                build.append("(");
-                for (Parameter param : annotation.getParams()) {
-                    build.append(param.getKey());
-                    build.append(" = ");
-                    build.append(fixString(param.getValue()));
-                    build.append(", ");
-                }
-                build.setCharAt(build.length() - 2, ')');
-            }
-            build.append(System.lineSeparator());
-        }
-    }
-
-    private static String fixString(String value) {
-        // TODO replace with compress single line if possible
-        return value.replaceAll("\\r\\n|\\r|\\n", " ").replaceAll(" +", " ");
-    }
-
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/ConstructorsDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/ConstructorsDirective.java
deleted file mode 100644 (file)
index 56b7286..0000000
+++ /dev/null
@@ -1,76 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.GeneralClassTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
-
-import com.google.common.collect.Lists;
-
-import freemarker.core.Environment;
-import freemarker.template.SimpleSequence;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add annotations to freemarker template.
- */
-public class ConstructorsDirective implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "object";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-        List<Constructor> constructors = Lists.newArrayList();
-
-        if (object != null) {
-            if (object instanceof SimpleSequence)
-                constructors = ((SimpleSequence) object).toList();
-            else if (object instanceof GeneralClassTemplate) {
-                constructors = ((GeneralClassTemplate) object)
-                        .getConstructors();
-            } else
-                throw new IllegalArgumentException(
-                        "Object must be a SimpleSequence or instance of "
-                                + GeneralClassTemplate.class + "but was "
-                                + object.getClass());
-        }
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        for (Constructor constr : constructors) {
-            build.append("    ");
-            if (constr.isPublic())
-                build.append("public ");
-            build.append(constr.getTypeName() + " ");
-            build.append("() {");
-            build.append(System.lineSeparator());
-            build.append("    ");
-            build.append("    ");
-            build.append(constr.getBody());
-            build.append(System.lineSeparator());
-            build.append("    ");
-            build.append("}");
-            build.append(System.lineSeparator());
-            build.append(System.lineSeparator());
-        }
-
-        if (!constructors.isEmpty())
-            out.write(build.toString().toCharArray());
-    }
-
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/FieldsDirectiveProg.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/FieldsDirectiveProg.java
deleted file mode 100644 (file)
index 7dd0f8e..0000000
+++ /dev/null
@@ -1,74 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
-
-import com.google.common.collect.Lists;
-
-import freemarker.core.Environment;
-import freemarker.template.SimpleSequence;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add fields to freemarker template.
- */
-public class FieldsDirectiveProg implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "object";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-        List<Field> fields = Lists.newArrayList();
-
-        if (object != null) {
-            if (object instanceof SimpleSequence)
-                fields = ((SimpleSequence) object).toList();
-            else if (object instanceof FtlTemplate) {
-                fields = ((FtlTemplate) object).getFields();
-            } else
-                throw new IllegalArgumentException(
-                        "Object must be a SimpleSequence or instance of "
-                                + FtlTemplate.class + "but was "
-                                + object.getClass());
-        }
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        for (Field field : fields) {
-            build.append("     private ");
-            for (String mod : field.getModifiers()) {
-                build.append(mod + " ");
-            }
-            build.append(field.getType() + " ");
-            build.append(field.getName());
-            if (field.getDefinition() != null)
-                build.append(" = " + field.getDefinition());
-            build.append(";");
-            build.append(System.lineSeparator());
-        }
-
-        if (!fields.isEmpty())
-            out.write(build.toString().toCharArray());
-    }
-
-    // String templateStr = "Hello ${user}";
-    // Template t = new Template("name", new StringReader(templateStr), new
-    // Configuration());
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/FieldsDirectiveTemplate.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/FieldsDirectiveTemplate.java
deleted file mode 100644 (file)
index 268d898..0000000
+++ /dev/null
@@ -1,57 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.Writer;
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-import freemarker.core.Environment;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add fields to freemarker template.
- */
-public class FieldsDirectiveTemplate implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "object";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-
-        // TODO check type
-
-        String templateStr = "    <#list fields as field>"
-                + "private <#if field.final==true>final </#if> <#if field.static==true>static </#if>"
-                + "${field.type} ${field.name}<#if field.definition??> = ${field.definition}</#if>;"
-                + System.lineSeparator() + " </#list>";
-        Template t = new Template("name", new StringReader(templateStr),
-                new Configuration());
-
-        try {
-            Map<String, Object> map = Maps.newHashMap();
-            map.put("fields", object);
-            Writer out = env.getOut();
-            t.process(map, out);
-        } catch (TemplateException e) {
-            throw new IllegalStateException(
-                    "Template error while generating fields" + e);
-        }
-    }
-
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/HeaderDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/HeaderDirective.java
deleted file mode 100644 (file)
index 93fde59..0000000
+++ /dev/null
@@ -1,81 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Date;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
-
-import com.google.common.base.Preconditions;
-
-import freemarker.core.Environment;
-import freemarker.ext.beans.StringModel;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add annotations to freemarker template.
- */
-public class HeaderDirective implements TemplateDirectiveModel {
-
-    private static final String GENERATOR_CLASS = JMXGenerator.class
-            .getCanonicalName();
-    private static final String OBJECT = "header";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-
-        // FIXME do not allow null header
-        // Preconditions.checkNotNull(object, "Null type declaration");
-        Object object = params.get(OBJECT);
-        Header header = null;
-        if (object != null) {
-            object = ((StringModel) object).getWrappedObject();
-            Preconditions.checkArgument(object instanceof Header,
-                    "Template header should be instance of " + Header.class
-                            + " but was " + object.getClass());
-
-            header = (Header) object;
-        }
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        build.append("/**");
-        build.append(System.lineSeparator());
-        build.append("* ");
-        build.append("Generated file");
-        build.append(System.lineSeparator());
-        build.append(System.lineSeparator());
-        build.append("* ");
-        build.append("Generated from: ");
-        build.append(header != null ? header.toString() : "");
-        build.append(System.lineSeparator());
-        build.append("* ");
-        build.append("Generated by: " + GENERATOR_CLASS);
-        build.append(System.lineSeparator());
-        build.append("* ");
-        build.append("Generated at: " + new Date());
-        build.append(System.lineSeparator());
-        build.append("* ");
-        build.append(System.lineSeparator());
-        build.append("* ");
-        build.append("Do not modify this file unless it is present under src/main directory ");
-        build.append(System.lineSeparator());
-        build.append("*/");
-        build.append(System.lineSeparator());
-
-        out.write(build.toString().toCharArray());
-    }
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/JavadocDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/JavadocDirective.java
deleted file mode 100644 (file)
index 9817be3..0000000
+++ /dev/null
@@ -1,65 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
-
-import freemarker.core.Environment;
-import freemarker.template.SimpleScalar;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add javadoc to freemarker template as String.
- */
-public class JavadocDirective implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "object";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-        String javadoc = "";
-
-        if (object != null) {
-            if (object instanceof SimpleScalar)
-                javadoc = ((SimpleScalar) object).getAsString();
-            else if (object instanceof FtlTemplate) {
-                javadoc = ((FtlTemplate) object).getJavadoc();
-            } else
-                throw new IllegalArgumentException(
-                        "Object must be a String or instance of "
-                                + FtlTemplate.class + "but was "
-                                + object.getClass());
-        }
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        writeJavadoc(build, javadoc, "");
-        out.write(build.toString().toCharArray());
-    }
-
-    static void writeJavadoc(StringBuilder build, String javadoc,
-            String linePrefix) {
-        build.append(linePrefix + "/**");
-        build.append(System.lineSeparator());
-        build.append(linePrefix + "* ");
-        build.append(javadoc == null ? "" : javadoc);
-        build.append(System.lineSeparator());
-        build.append(linePrefix + "*/");
-        build.append(System.lineSeparator());
-    }
-
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/MethodsDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/MethodsDirective.java
deleted file mode 100644 (file)
index 975d8fd..0000000
+++ /dev/null
@@ -1,115 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDefinition;
-
-import com.google.common.collect.Lists;
-
-import freemarker.core.Environment;
-import freemarker.template.SimpleSequence;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add annotations to freemarker template.
- */
-public class MethodsDirective implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "object";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-        List<? extends Method> methods = Lists.newArrayList();
-
-        if (object != null) {
-            if (object instanceof SimpleSequence)
-                methods = ((SimpleSequence) object).toList();
-            else if (object instanceof FtlTemplate) {
-                methods = ((FtlTemplate) object).getMethods();
-            } else
-                throw new IllegalArgumentException(
-                        "Object must be a SimpleSequence or instance of "
-                                + FtlTemplate.class + "but was "
-                                + object.getClass());
-        }
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        for (Method method : methods) {
-            if (method.getJavadoc() != null)
-                JavadocDirective.writeJavadoc(build, method.getJavadoc(), "    ");
-
-            if (!method.getAnnotations().isEmpty()) {
-                AnnotationsDirective.writeAnnotations(method.getAnnotations(),
-                        build, "    ");
-            }
-
-            build.append("    " + "public ");
-            for (String mod : method.getModifiers()) {
-                build.append(mod + " ");
-            }
-            build.append(method.getReturnType() + " ");
-
-            build.append(method.getName() + "(");
-            for (Field param : method.getParameters()) {
-                for (String mod : param.getModifiers()) {
-                    build.append(mod + " ");
-                }
-                build.append(param.getType() + " ");
-                build.append(param.getName() + ", ");
-            }
-            if (method.getParameters().isEmpty())
-                build.append(")");
-            else {
-                build.deleteCharAt(build.length() - 1);
-                build.deleteCharAt(build.length() - 1);
-                build.append(')');
-            }
-
-            if (method instanceof MethodDeclaration) {
-                build.append(";");
-                build.append(System.lineSeparator());
-            } else if (method instanceof MethodDefinition) {
-                if (!((MethodDefinition) method).getThrowsExceptions()
-                        .isEmpty())
-                    build.append(" throws ");
-                for (String ex : ((MethodDefinition) method)
-                        .getThrowsExceptions()) {
-                    build.append(ex + " ");
-                }
-                build.append(" {");
-                build.append(System.lineSeparator());
-                build.append("        ");
-                build.append(((MethodDefinition) method).getBody());
-                build.append(System.lineSeparator());
-                build.append("    ");
-                build.append("}");
-                build.append(System.lineSeparator());
-            }
-            build.append(System.lineSeparator());
-
-        }
-
-        if (!methods.isEmpty())
-            out.write(build.toString().toCharArray());
-    }
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/ModuleFieldsDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/ModuleFieldsDirective.java
deleted file mode 100644 (file)
index 144419e..0000000
+++ /dev/null
@@ -1,88 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-import java.util.Map;
-
-import org.opendaylight.controller.config.api.JmxAttribute;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractModuleTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField;
-
-import com.google.common.collect.Lists;
-
-import freemarker.core.Environment;
-import freemarker.template.SimpleSequence;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add annotations to freemarker template.
- */
-public class ModuleFieldsDirective implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "moduleFields";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-        List<ModuleField> fields = Lists.newArrayList();
-
-        if (object != null) {
-            if (object instanceof SimpleSequence)
-                fields = ((SimpleSequence) object).toList();
-            else if (object instanceof AbstractModuleTemplate) {
-                fields = ((AbstractModuleTemplate) object).getModuleFields();
-            } else
-                throw new IllegalArgumentException(
-                        "Object must be a SimpleSequence or instance of "
-                                + AbstractModuleTemplate.class + "but was "
-                                + object.getClass());
-        }
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        for (ModuleField field : fields) {
-            build.append("    ");
-            build.append("protected final "
-                    + JmxAttribute.class.getCanonicalName() + " "
-                    + field.getName() + "JmxAttribute = new "
-                    + JmxAttribute.class.getCanonicalName() + "(\""
-                    + field.getAttributeName() + "\");");
-            build.append(System.lineSeparator());
-
-            build.append("     private ");
-            for (String mod : field.getModifiers()) {
-                build.append(mod + " ");
-            }
-            build.append(field.getType() + " ");
-            build.append(field.getName());
-            if (field.getNullableDefault() != null)
-                build.append(" = " + field.getNullableDefault());
-            build.append(";");
-
-            if (field.isDependent()) {
-                String comment = field.getDependency().isMandatory() ? "mandatory"
-                        : "optional";
-                build.append(" // " + comment);
-            }
-            build.append(System.lineSeparator());
-
-            build.append(System.lineSeparator());
-
-        }
-
-        if (!fields.isEmpty())
-            out.write(build.toString().toCharArray());
-    }
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/TypeDeclarationDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/TypeDeclarationDirective.java
deleted file mode 100644 (file)
index 42556c2..0000000
+++ /dev/null
@@ -1,80 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Collection;
-import java.util.Map;
-
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.TypeDeclaration;
-
-import com.google.common.base.Preconditions;
-
-import freemarker.core.Environment;
-import freemarker.ext.beans.StringModel;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add type declaration to freemarker template.
- */
-public class TypeDeclarationDirective implements TemplateDirectiveModel {
-
-    private static final String OBJECT = "object";
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-        Object object = params.get(OBJECT);
-        Preconditions.checkNotNull(object, "Null type declaration");
-
-        object = ((StringModel) object).getWrappedObject();
-        Preconditions.checkArgument(
-                object instanceof TypeDeclaration,
-                "Type declaration should be instance of "
-                        + TypeDeclaration.class + " but was "
-                        + object.getClass());
-
-        TypeDeclaration type = (TypeDeclaration) object;
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder("public ");
-        if (type.isAbstract())
-            build.append("abstract ");
-        if (type.isFinal())
-            build.append("final ");
-        build.append(type.getType() + " ");
-        build.append(type.getName() + " ");
-
-        generateExtendOrImplement(build, "extends", type.getExtended());
-
-        generateExtendOrImplement(build, "implements", type.getImplemented());
-
-        build.append(System.lineSeparator());
-        out.write(build.toString().toCharArray());
-    }
-
-    private void generateExtendOrImplement(StringBuilder build, String prefix,
-            Collection<String> elements) {
-        if (elements.isEmpty())
-            return;
-
-        build.append(prefix + " ");
-
-        for (String extended : elements) {
-            build.append(extended);
-            build.append(", ");
-        }
-        build.deleteCharAt(build.length() - 1);
-        build.deleteCharAt(build.length() - 1);
-    }
-
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/UnimplementedExceptionDirective.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/directives/UnimplementedExceptionDirective.java
deleted file mode 100644 (file)
index 5175ade..0000000
+++ /dev/null
@@ -1,39 +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.config.yangjmxgenerator.plugin.ftl.directives;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Map;
-
-import freemarker.core.Environment;
-import freemarker.template.TemplateDirectiveBody;
-import freemarker.template.TemplateDirectiveModel;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
-
-/**
- * Add annotations to freemarker template.
- */
-public class UnimplementedExceptionDirective implements TemplateDirectiveModel {
-
-    @Override
-    public void execute(Environment env, Map params, TemplateModel[] loopVars,
-            TemplateDirectiveBody body) throws TemplateException, IOException {
-
-        Writer out = env.getOut();
-        StringBuilder build = new StringBuilder();
-        build.append("        ");
-        build.append("throw new "
-                + UnsupportedOperationException.class.getCanonicalName()
-                + "(\"Unimplemented stub method\");");
-        build.append(System.lineSeparator());
-
-        out.write(build.toString().toCharArray());
-    }
-}
index 7cf241725d78674cd6f7ca9e16aa3cebcc0f7be4..a8ddabc4cf01086b4634538b53d2747c88f319c8 100644 (file)
@@ -7,18 +7,21 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
 import org.opendaylight.controller.config.api.annotations.Description;
 import org.opendaylight.controller.config.api.annotations.RequireInterface;
 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
-import org.opendaylight.yangtools.yang.binding.annotations.ModuleQName;
 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
+import org.opendaylight.yangtools.yang.binding.annotations.ModuleQName;
+import org.opendaylight.yangtools.yang.common.QName;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 public class Annotation {
     final String name;
@@ -37,6 +40,14 @@ public class Annotation {
         return params;
     }
 
+    public static Annotation createFromMap(Class<?> annotationClass, Map<String, String> parameters) {
+        List<Parameter> parameterList = new ArrayList<>();
+        for(Entry<String, String> entry: parameters.entrySet()) {
+            parameterList.add(new Parameter(entry.getKey(), entry.getValue()));
+        }
+        return new Annotation(annotationClass.getCanonicalName(), parameterList);
+    }
+
     public static Annotation createDescriptionAnnotation(String description) {
         Preconditions.checkNotNull(description,
                 "Cannot create annotation from null description");
@@ -44,6 +55,14 @@ public class Annotation {
                 Lists.newArrayList(new Parameter("value", q(description))));
     }
 
+    public static Annotation createModuleQNameANnotation(QName qName) {
+        Map<String, String> parameters = new HashMap<>();
+        parameters.put("namespace", q(qName.getNamespace().toString()));
+        parameters.put("revision", q(qName.getFormattedRevision()));
+        parameters.put("name", q(qName.getLocalName()));
+        return Annotation.createFromMap(ModuleQName.class, parameters);
+    }
+
     public static Collection<Annotation> createSieAnnotations(ServiceInterfaceEntry sie){
 
         String exportedClassName = sie.getExportedOsgiClassName();
@@ -85,7 +104,7 @@ public class Annotation {
 
     private static final String quote = "\"";
 
-    private static String q(String nullableDescription) {
+    public static String q(String nullableDescription) {
         return nullableDescription == null ? null : quote + nullableDescription
                 + quote;
     }
@@ -107,4 +126,8 @@ public class Annotation {
         }
     }
 
+    @Override
+    public String toString() {
+        return AnnotationSerializer.toString(this);
+    }
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/AnnotationSerializer.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/AnnotationSerializer.java
new file mode 100644 (file)
index 0000000..6b4ce38
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.ftl.model;
+
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation.Parameter;
+
+class AnnotationSerializer {
+
+    static String toString(Annotation annotation) {
+        StringBuilder builder = new StringBuilder();
+        builder.append("@");
+        builder.append(annotation.getName());
+        if (!annotation.getParams().isEmpty()) {
+            builder.append("(");
+            for (Parameter param : annotation.getParams()) {
+                builder.append(param.getKey());
+                builder.append(" = ");
+                builder.append(fixString(param.getValue()));
+                builder.append(", ");
+            }
+            builder.setCharAt(builder.length() - 2, ')');
+        }
+        builder.append("\n");
+        return builder.toString();
+    }
+
+    private static String fixString(String value) {
+        // TODO replace with compress single line if possible
+        return value.replaceAll("\\r\\n|\\r|\\n", " ").replaceAll(" +", " ");
+    }
+
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ConstructorSerializer.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ConstructorSerializer.java
new file mode 100644 (file)
index 0000000..c257aa6
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.ftl.model;
+
+public class ConstructorSerializer {
+
+    public static String toString(Constructor constr) {
+        StringBuilder build = new StringBuilder();
+        build.append("    ");
+        if (constr.isPublic()) {
+            build.append("public ");
+        }
+        build.append(constr.getTypeName() + " ");
+        build.append("() {");
+        build.append("\n");
+        build.append("    ");
+        build.append("    ");
+        build.append(constr.getBody());
+        build.append("\n");
+        build.append("    ");
+        build.append("}");
+        build.append("\n");
+        build.append("\n");
+        return build.toString();
+    }
+}
index ad5cbb287c73a4aef2cafebce6afb442f57fd1ed..3639b6d727274d9656c24a04cd62e09a7a3ae62a 100644 (file)
@@ -11,6 +11,8 @@ import com.google.common.collect.Lists;
 
 import java.util.List;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 public class Field {
     private final String type;
     private final String name;
@@ -36,11 +38,11 @@ public class Field {
     }
 
     public Field(List<String> modifiers, String type, String name,
-            String definition, boolean needsDepResolver) {
-        this.modifiers = modifiers;
-        this.type = type;
-        this.name = name;
-        this.definition = definition;
+            String nullableDefinition, boolean needsDepResolver) {
+        this.modifiers = checkNotNull(modifiers);
+        this.type = checkNotNull(type);
+        this.name = checkNotNull(name);
+        this.definition = nullableDefinition;
         this.needsDepResolver = needsDepResolver;
     }
 
@@ -56,6 +58,10 @@ public class Field {
         return type;
     }
 
+    public String getGenericInnerType() {
+        return type.substring(type.indexOf("<") + 1, type.indexOf(">"));
+    }
+
     public List<String> getModifiers() {
         return modifiers;
     }
@@ -71,4 +77,9 @@ public class Field {
     public boolean isArray() {
         return type.endsWith("[]");
     }
+
+    @Override
+    public String toString() {
+        return FieldSerializer.toString(this);
+    }
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/FieldSerializer.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/FieldSerializer.java
new file mode 100644 (file)
index 0000000..90a2b56
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.ftl.model;
+
+public class FieldSerializer {
+
+    public static String toString(Field field) {
+        StringBuilder build = new StringBuilder();
+        build.append("private ");
+        for (String mod : field.getModifiers()) {
+            build.append(mod + " ");
+        }
+        build.append(field.getType() + " ");
+        build.append(field.getName());
+        if (field.getDefinition() != null) {
+            build.append(" = " + field.getDefinition());
+        }
+        build.append(";");
+        build.append("\n");
+        return build.toString();
+    }
+}
index 047e87a3dc7f58bac0046bcfb6673374d1a1fa9b..b9a628495d71f8a8f2210d1178aa4ed85badf8ac 100644 (file)
@@ -26,8 +26,7 @@ public class Header {
 
     @Override
     public String toString() {
-        return "yang module name: " + yangModuleName + " "
-                + " yang module local name: " + yangModuleLocalName;
+        return HeaderSerializer.toString(this);
     }
 
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/HeaderSerializer.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/HeaderSerializer.java
new file mode 100644 (file)
index 0000000..eb07c80
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.ftl.model;
+
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator;
+
+import java.util.Date;
+
+public class HeaderSerializer {
+    private static final String GENERATOR_CLASS = JMXGenerator.class.getCanonicalName();
+
+    public static String toString(Header header) {
+        StringBuilder build = new StringBuilder();
+
+
+        build.append("Generated file");
+        build.append("\n");
+        build.append("\n");
+        build.append("Generated from: ");
+        //build.append(header.toString());
+
+        build.append("yang module name: ");
+        build.append(header.getYangModuleName());
+        build.append(" yang module local name: ");
+        build.append(header.getYangModuleLocalName());
+
+        build.append("\n");
+        build.append("Generated by: " + GENERATOR_CLASS);
+        build.append("\n");
+        build.append("Generated at: " + new Date());
+        build.append("\n");
+        build.append("\n");
+        build.append("Do not modify this file unless it is present under src/main directory ");
+
+        return build.toString();
+    }
+
+}
index bd4e22e084cb115142ebde865ac82a9074604383..be6b23e879e36de82bb1a2abf5f82107a161ea11 100644 (file)
@@ -63,4 +63,9 @@ public class MethodDeclaration implements Method {
     public List<String> getModifiers() {
         return Collections.emptyList();
     }
+
+    @Override
+    public String toString() {
+        return MethodSerializer.toString(this);
+    }
 }
index bf453ac135fa9fd230ec5fcb0a4ccd411076874b..9af011fe7199230d03f7e00a93bcca10e0b96b9b 100644 (file)
@@ -93,4 +93,9 @@ public class MethodDefinition implements Method {
     public List<String> getModifiers() {
         return modifiers;
     }
+
+    @Override
+    public String toString() {
+        return MethodSerializer.toString(this);
+    }
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/MethodSerializer.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/MethodSerializer.java
new file mode 100644 (file)
index 0000000..7d2b9fc
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.ftl.model;
+
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
+
+class MethodSerializer {
+
+    static String toString(Method method) {
+        StringBuilder build = new StringBuilder();
+        if (method.getJavadoc() != null) {
+            build.append(StringUtil.writeComment(method.getJavadoc(), true));
+        }
+
+        for(Annotation a: method.getAnnotations()) {
+            build.append(a);
+        }
+
+        build.append("    " + "public ");
+        for (String mod : method.getModifiers()) {
+            build.append(mod + " ");
+        }
+        build.append(method.getReturnType() + " ");
+
+        build.append(method.getName() + "(");
+        for (Field param : method.getParameters()) {
+            for (String mod : param.getModifiers()) {
+                build.append(mod + " ");
+            }
+            build.append(param.getType() + " ");
+            build.append(param.getName() + ", ");
+        }
+        if (method.getParameters().isEmpty()) {
+            build.append(")");
+        } else {
+            build.deleteCharAt(build.length() - 1);
+            build.deleteCharAt(build.length() - 1);
+            build.append(')');
+        }
+
+        if (method instanceof MethodDeclaration) {
+            build.append(";");
+            build.append("\n");
+        } else if (method instanceof MethodDefinition) {
+            if (!((MethodDefinition) method).getThrowsExceptions()
+                    .isEmpty()) {
+                build.append(" throws ");
+            }
+            for (String ex : ((MethodDefinition) method)
+                    .getThrowsExceptions()) {
+                build.append(ex + " ");
+            }
+            build.append(" {");
+            build.append("\n");
+            build.append("        ");
+            build.append(((MethodDefinition) method).getBody());
+            build.append("\n");
+            build.append("    ");
+            build.append("}");
+            build.append("\n");
+        }
+        build.append("\n");
+        return build.toString();
+    }
+}
index 74e5bb0490c5de483a357476ecf3bde7b3aeb790..37d660353f55d1a5a418b8dac0213f6e630ba3e2 100644 (file)
@@ -44,6 +44,11 @@ public class ModuleField extends Field {
         return false;
     }
 
+    @Override
+    public String toString() {
+        return ModuleFieldSerializer.toString(this);
+    }
+
     public Dependency getDependency() {
         return dependency;
     }
@@ -64,4 +69,9 @@ public class ModuleField extends Field {
         return attributeName;
     }
 
+
+    public boolean isList() {
+        return getType().startsWith("java.util.List");
+    }
+
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleFieldSerializer.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/ModuleFieldSerializer.java
new file mode 100644 (file)
index 0000000..c0e3bc1
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.ftl.model;
+
+import org.opendaylight.controller.config.api.JmxAttribute;
+
+public class ModuleFieldSerializer {
+
+
+    public static String toString(ModuleField moduleField) {
+        StringBuilder builder = new StringBuilder();
+        builder.append("    ");
+        builder.append("protected final "
+                + JmxAttribute.class.getCanonicalName() + " "
+                + moduleField.getName() + "JmxAttribute = new "
+                + JmxAttribute.class.getCanonicalName() + "(\""
+                + moduleField.getAttributeName() + "\");");
+        builder.append("\n");
+
+        builder.append("     private ");
+        for (String mod : moduleField.getModifiers()) {
+            builder.append(mod + " ");
+        }
+        builder.append(moduleField.getType() + " ");
+        builder.append(moduleField.getName());
+        if (moduleField.getNullableDefault() != null) {
+            builder.append(" = " + moduleField.getNullableDefault());
+        }
+        builder.append(";");
+
+        if (moduleField.isDependent()) {
+            String comment = moduleField.getDependency().isMandatory() ? "mandatory"
+                    : "optional";
+            builder.append(" // " + comment);
+        }
+        builder.append("\n");
+
+        builder.append("\n");
+
+        return builder.toString();
+    }
+}
index ee0aa2ff5c22a7e054a931b7a36a6d0b89569c94..a5bb987fd33d4adc52d66daa707fb0fe1877c3dc 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model;
 
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.TypeName;
+
 import java.util.List;
 
 public class TypeDeclaration {
@@ -54,6 +56,24 @@ public class TypeDeclaration {
         return implemented;
     }
 
+    public TypeName toTypeName() {
+        if ("interface".equals(type)) {
+            return TypeName.interfaceType;
+        } else if ("class".equals(type)) {
+            if (isAbstract) {
+                return TypeName.absClassType;
+            } else if (isFinal) {
+                return TypeName.finalClassType;
+            } else {
+                return TypeName.classType;
+            }
+        } else if ("enum".equals(type)) {
+            return TypeName.enumType;
+        } else {
+            throw new IllegalStateException("Type not supported: " + type);
+        }
+    }
+
     @Override
     public String toString() {
         return "TypeDeclaration{" + "type='" + type + '\'' + ", name='" + name
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsFactoryGeneratedObjectFactory.groovy b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsFactoryGeneratedObjectFactory.groovy
new file mode 100644 (file)
index 0000000..baff88c
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.gofactory
+import com.google.common.base.Optional
+import org.opendaylight.controller.config.api.DependencyResolver
+import org.opendaylight.controller.config.api.DynamicMBeanWithInstance
+import org.opendaylight.controller.config.api.ModuleIdentifier
+import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface
+import org.opendaylight.controller.config.api.annotations.Description
+import org.opendaylight.controller.config.spi.Module
+import org.opendaylight.controller.config.spi.ModuleFactory
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractFactoryTemplate
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.*
+import org.opendaylight.yangtools.yang.common.QName
+import org.osgi.framework.BundleContext
+
+public class AbsFactoryGeneratedObjectFactory {
+
+    public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright) {
+        FullyQualifiedName absFactoryFQN = new FullyQualifiedName(mbe.packageName, mbe.abstractFactoryName)
+        FullyQualifiedName moduleFQN = new FullyQualifiedName(mbe.packageName, mbe.stubModuleName)
+        Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription())
+
+        AbstractFactoryTemplate abstractFactoryTemplate = TemplateFactory.abstractFactoryTemplateFromMbe(mbe)
+        Optional<String> header = abstractFactoryTemplate.headerString;
+        List<FullyQualifiedName> providedServices = mbe.providedServices.keySet().collect {
+            FullyQualifiedName.fromString(it)
+        }
+
+
+        return toGeneratedObject(absFactoryFQN, copyright,
+                header, classJavaDoc, mbe.yangModuleQName,
+                mbe.globallyUniqueName,
+                providedServices,
+                moduleFQN,
+                abstractFactoryTemplate.fields)
+    }
+
+    public GeneratedObject toGeneratedObject(FullyQualifiedName absFactoryFQN, Optional<String> copyright,
+                                             Optional<String> header, Optional<String> classJavaDoc, QName yangModuleQName,
+                                             String globallyUniqueName,
+                                             List<FullyQualifiedName> providedServices,
+                                             FullyQualifiedName moduleFQN,
+                                             List<Field> moduleFields) {
+        JavaFileInputBuilder b = new JavaFileInputBuilder()
+        Annotation moduleQNameAnnotation = Annotation.createModuleQNameANnotation(yangModuleQName)
+        b.addClassAnnotation(moduleQNameAnnotation)
+
+        b.setFqn(absFactoryFQN)
+        b.setTypeName(TypeName.absClassType)
+
+        b.setCopyright(copyright);
+        b.setHeader(header);
+        b.setClassJavaDoc(classJavaDoc);
+        b.addImplementsFQN(new FullyQualifiedName(ModuleFactory))
+        if (classJavaDoc.isPresent()) {
+            b.addClassAnnotation("@${Description.canonicalName}(value=\"${classJavaDoc.get()}\")")
+        }
+
+        b.addToBody("public static final java.lang.String NAME = \"${globallyUniqueName}\";")
+        b.addToBody("private static final java.util.Set<Class<? extends ${AbstractServiceInterface.canonicalName}>> serviceIfcs;")
+
+        b.addToBody("@Override\n public final String getImplementationName() { \n return NAME; \n}")
+
+        b.addToBody(getServiceIfcsInitialization(providedServices))
+
+        // createModule
+        b.addToBody("""
+            @Override
+            public ${Module.canonicalName} createModule(String instanceName, ${DependencyResolver.canonicalName} dependencyResolver, ${BundleContext.canonicalName} bundleContext) {
+                return instantiateModule(instanceName, dependencyResolver, bundleContext);
+            }
+            """)
+
+        b.addToBody(getCreateModule(moduleFQN, moduleFields))
+
+        b.addToBody("""
+            public ${moduleFQN} instantiateModule(String instanceName, ${DependencyResolver.canonicalName} dependencyResolver, ${moduleFQN} oldModule, ${AutoCloseable.canonicalName} oldInstance, ${BundleContext.canonicalName} bundleContext) {
+                return new ${moduleFQN}(new ${ModuleIdentifier.canonicalName}(NAME, instanceName), dependencyResolver, oldModule, oldInstance);
+            }
+            """)
+
+        b.addToBody("""
+            public ${moduleFQN} instantiateModule(String instanceName, ${DependencyResolver.canonicalName} dependencyResolver, ${BundleContext.canonicalName} bundleContext) {
+                return new ${moduleFQN}(new ${ModuleIdentifier.canonicalName}(NAME, instanceName), dependencyResolver);
+            }
+            """)
+
+        b.addToBody("""
+            public ${moduleFQN} handleChangedClass(${DynamicMBeanWithInstance.canonicalName} old) throws Exception {
+                throw new UnsupportedOperationException("Class reloading is not supported");
+            }
+            """)
+
+        b.addToBody("""
+            @Override
+            public java.util.Set<${moduleFQN}> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory, ${BundleContext.canonicalName} bundleContext) {
+                return new java.util.HashSet<${moduleFQN}>();
+            }
+            """)
+
+        return new GeneratedObjectBuilder(b.build()).toGeneratedObject()
+    }
+
+    private static String getCreateModule(FullyQualifiedName moduleFQN, List<Field> moduleFields) {
+        String result = """
+            @Override
+            public ${Module.canonicalName} createModule(String instanceName, ${DependencyResolver.canonicalName} dependencyResolver, ${DynamicMBeanWithInstance.canonicalName} old, ${BundleContext.canonicalName} bundleContext) throws Exception {
+                ${moduleFQN} oldModule = null;
+                try {
+                    oldModule = (${moduleFQN}) old.getModule();
+                } catch(Exception e) {
+                    return handleChangedClass(old);
+                }
+                ${moduleFQN} module = instantiateModule(instanceName, dependencyResolver, oldModule, old.getInstance(), bundleContext);
+            """
+        result += moduleFields.collect{"module.set${it.name}(oldModule.get${it.name}());"}.join("\n")
+        result += """
+                return module;
+            }
+            """
+        return result
+    }
+
+    private static String getServiceIfcsInitialization(List<FullyQualifiedName> providedServices) {
+        String generic = "Class<? extends ${AbstractServiceInterface.canonicalName}>"
+
+        String result = """static {
+            java.util.Set<${generic}> serviceIfcs2 = new java.util.HashSet<${generic}>();
+            """
+        result += providedServices.collect{"serviceIfcs2.add(${it}.class);"}.join("\n")
+        result += """serviceIfcs = java.util.Collections.unmodifiableSet(serviceIfcs2);
+            }
+            """
+
+        // add isModuleImplementingServiceInterface and getImplementedServiceIntefaces methods
+
+        result += """
+            @Override
+            public final boolean isModuleImplementingServiceInterface(Class<? extends ${AbstractServiceInterface.canonicalName}> serviceInterface) {
+                for (Class<?> ifc: serviceIfcs) {
+                    if (serviceInterface.isAssignableFrom(ifc)){
+                        return true;
+                    }
+                }
+                return false;
+            }
+
+            @Override
+            public java.util.Set<Class<? extends ${AbstractServiceInterface.canonicalName}>> getImplementedServiceIntefaces() {
+                return serviceIfcs;
+            }
+            """
+
+        return result
+    }
+
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsModuleGeneratedObjectFactory.groovy b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsModuleGeneratedObjectFactory.groovy
new file mode 100644 (file)
index 0000000..930acff
--- /dev/null
@@ -0,0 +1,400 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.gofactory
+import com.google.common.base.Optional
+import org.opendaylight.controller.config.api.DependencyResolver
+import org.opendaylight.controller.config.api.ModuleIdentifier
+import org.opendaylight.controller.config.api.annotations.Description
+import org.opendaylight.controller.config.api.runtime.RootRuntimeBeanRegistrator
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.AbstractModuleTemplate
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.TemplateFactory
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.IdentityRefModuleField
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Method
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.ModuleField
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.*
+import org.opendaylight.yangtools.yang.common.QName
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+public class AbsModuleGeneratedObjectFactory {
+
+    public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright) {
+        FullyQualifiedName abstractFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractModuleName())
+        Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription())
+        AbstractModuleTemplate abstractModuleTemplate = TemplateFactory.abstractModuleTemplateFromMbe(mbe)
+        Optional<String> header = abstractModuleTemplate.headerString;
+        List<FullyQualifiedName> implementedInterfaces = abstractModuleTemplate.getTypeDeclaration().getImplemented().collect {
+            FullyQualifiedName.fromString(it)
+        }
+        Optional<FullyQualifiedName> maybeRegistratorType
+        if (abstractModuleTemplate.isRuntime()) {
+            maybeRegistratorType = Optional.of(FullyQualifiedName.fromString(abstractModuleTemplate.getRegistratorType()))
+        } else {
+            maybeRegistratorType = Optional.absent()
+        }
+
+        return toGeneratedObject(abstractFQN, copyright, header, classJavaDoc, implementedInterfaces,
+                abstractModuleTemplate.getModuleFields(), maybeRegistratorType, abstractModuleTemplate.getMethods(),
+                mbe.yangModuleQName
+        )
+    }
+
+    public GeneratedObject toGeneratedObject(FullyQualifiedName abstractFQN,
+                                             Optional<String> copyright,
+                                             Optional<String> header,
+                                             Optional<String> classJavaDoc,
+                                             List<FullyQualifiedName> implementedInterfaces,
+                                             List<ModuleField> moduleFields,
+                                             Optional<FullyQualifiedName> maybeRegistratorType,
+                                             List<Method> methods,
+                                             QName yangModuleQName) {
+        JavaFileInputBuilder b = new JavaFileInputBuilder()
+
+        Annotation moduleQNameAnnotation = Annotation.createModuleQNameANnotation(yangModuleQName)
+        b.addClassAnnotation(moduleQNameAnnotation)
+
+        b.setFqn(abstractFQN)
+        b.setTypeName(TypeName.absClassType)
+
+        b.setCopyright(copyright);
+        b.setHeader(header);
+        b.setClassJavaDoc(classJavaDoc);
+        implementedInterfaces.each { b.addImplementsFQN(it) }
+        if (classJavaDoc.isPresent()) {
+            b.addClassAnnotation("@${Description.canonicalName}(value=\"${classJavaDoc.get()}\")")
+        }
+
+        // add logger:
+        b.addToBody(getLogger(abstractFQN));
+
+        b.addToBody("//attributes start");
+
+        b.addToBody(moduleFields.collect { it.toString() }.join("\n"))
+
+        b.addToBody("//attributes end");
+
+
+        b.addToBody(getCommonFields(abstractFQN));
+
+
+        b.addToBody(getNewConstructor(abstractFQN))
+        b.addToBody(getCopyFromOldConstructor(abstractFQN))
+
+        b.addToBody(getRuntimeRegistratorCode(maybeRegistratorType))
+        b.addToBody(getValidationMethods(moduleFields))
+
+        b.addToBody(getCachesOfResolvedDependencies(moduleFields))
+        b.addToBody(getCachesOfResolvedIdentityRefs(moduleFields))
+        b.addToBody(getGetInstance(moduleFields))
+        b.addToBody(getReuseLogic(moduleFields, abstractFQN))
+        b.addToBody(getEqualsAndHashCode(abstractFQN))
+
+        b.addToBody(getMethods(methods))
+
+        return new GeneratedObjectBuilder(b.build()).toGeneratedObject()
+    }
+
+    private static String getMethods(List<Method> methods) {
+        String result = """
+            // getters and setters
+        """
+        result += methods.collect{it.toString()}.join("\n")
+        return result
+    }
+
+    private static String getEqualsAndHashCode(FullyQualifiedName abstractFQN) {
+        return """
+            @Override
+            public boolean equals(Object o) {
+                if (this == o) return true;
+                if (o == null || getClass() != o.getClass()) return false;
+                ${abstractFQN.typeName} that = (${abstractFQN.typeName}) o;
+                return identifier.equals(that.identifier);
+            }
+
+            @Override
+            public int hashCode() {
+                return identifier.hashCode();
+            }
+        """
+    }
+
+    private static String getReuseLogic(List<ModuleField> moduleFields, FullyQualifiedName abstractFQN) {
+        String result = """
+            public boolean canReuseInstance(${abstractFQN.typeName} oldModule){
+                // allow reusing of old instance if no parameters was changed
+                return isSame(oldModule);
+            }
+
+            public ${AutoCloseable.canonicalName} reuseInstance(${AutoCloseable.canonicalName} oldInstance){
+                // implement if instance reuse should be supported. Override canReuseInstance to change the criteria.
+                return oldInstance;
+            }
+            """
+        // isSame method that detects changed fields
+        result += """
+            public boolean isSame(${abstractFQN.typeName} other) {
+                if (other == null) {
+                    throw new IllegalArgumentException("Parameter 'other' is null");
+                }
+            """
+        // loop through fields, do deep equals on each field
+        result += moduleFields.collect { field ->
+            if (field.isListOfDependencies()) {
+                return """
+                    if (${field.name}Dependency.equals(other.${field.name}Dependency) == false) {
+                        return false;
+                    }
+                    for (int idx = 0; idx < ${field.name}Dependency.size(); idx++) {
+                        if (${field.name}Dependency.get(idx) != other.${field.name}Dependency.get(idx)) {
+                            return false;
+                        }
+                    }
+                """
+            } else if (field.isDependent()) {
+                return """
+                    if (${field.name}Dependency != other.${field.name}Dependency) { // reference to dependency must be same
+                        return false;
+                    }
+                """
+            } else {
+                return """
+                    if (java.util.Objects.deepEquals(${field.name}, other.${field.name}) == false) {
+                        return false;
+                    }
+                """
+            }
+        }.join("\n")
+
+
+        result += """
+                return true;
+            }
+            """
+
+        return result
+    }
+
+    private static String getGetInstance(List<ModuleField> moduleFields) {
+        String result = """
+            @Override
+            public final ${AutoCloseable.canonicalName} getInstance() {
+                if(instance==null) {
+            """
+        // create instance start
+
+        // loop through dependent fields, use dependency resolver to instantiate dependencies. Do it in loop in case field represents list of dependencies.
+        Map<ModuleField, String> resolveDependenciesMap = moduleFields.findAll {
+            it.isDependent()
+        }.collectEntries { ModuleField field ->
+            [field, field.isList() ?
+                    """
+                ${field.name}Dependency = new java.util.ArrayList<${field.dependency.sie.exportedOsgiClassName}>();
+                for(javax.management.ObjectName dep : ${field.name}) {
+                    ${field.name}Dependency.add(dependencyResolver.resolveInstance(${
+                        field.dependency.sie.exportedOsgiClassName
+                    }.class, dep, ${field.name}JmxAttribute));
+                }
+                """
+                    :
+                    """
+                ${field.name}Dependency = dependencyResolver.resolveInstance(${
+                        field.dependency.sie.exportedOsgiClassName
+                    }.class, ${field.name}, ${field.name}JmxAttribute);
+                """
+            ]
+        }
+        // wrap each field resolvation statement with if !=null when dependency is not mandatory
+        def wrapWithNullCheckClosure = {Map<ModuleField, String> map, predicate -> map.collect { ModuleField key, String value ->
+            predicate(key) ? """
+                if(${key.name}!=null) {
+                    ${value}
+                }
+                """ : value
+            }.join("\n")
+        }
+
+        result += wrapWithNullCheckClosure(resolveDependenciesMap, {ModuleField key ->
+            key.getDependency().isMandatory() == false} )
+
+        // add code to inject dependency resolver to fields that support it
+        Map<ModuleField, String> injectDepsMap = moduleFields.findAll { it.needsDepResolver }.collectEntries { field ->
+            if (field.isList()) {
+                return [field,"""
+                for(${field.genericInnerType} candidate : ${field.name}) {
+                    candidate.injectDependencyResolver(dependencyResolver);
+                }
+                """]
+            } else {
+                return [field, "${field.name}.injectDependencyResolver(dependencyResolver);"]
+            }
+        }
+
+        result += wrapWithNullCheckClosure(injectDepsMap, {true})
+
+        // identity refs need to be injected with dependencyResolver and base class
+        Map<ModuleField, String> resolveIdentityMap = moduleFields.findAll { it.isIdentityRef() }.collectEntries { IdentityRefModuleField field ->
+            [field,
+            "set${field.attributeName}(${field.name}.resolveIdentity(dependencyResolver, ${field.identityBaseClass}.class));"]
+        }
+
+        result += wrapWithNullCheckClosure(resolveIdentityMap, {true})
+
+        // create instance end: reuse and recreate logic
+        result += """
+                    if(oldInstance!=null && canReuseInstance(oldModule)) {
+                        instance = reuseInstance(oldInstance);
+                    } else {
+                        if(oldInstance!=null) {
+                            try {
+                                oldInstance.close();
+                            } catch(Exception e) {
+                                logger.error("An error occurred while closing old instance " + oldInstance, e);
+                            }
+                        }
+                        instance = createInstance();
+                        if (instance == null) {
+                            throw new IllegalStateException("Error in createInstance - null is not allowed as return value");
+                        }
+                    }
+                }
+                return instance;
+            }
+            public abstract ${AutoCloseable.canonicalName} createInstance();
+            """
+        return result
+    }
+
+    private static String getCommonFields(FullyQualifiedName abstractFQN) {
+        return """
+            private final ${abstractFQN.typeName} oldModule;
+            private final ${AutoCloseable.canonicalName} oldInstance;
+            private ${AutoCloseable.canonicalName} instance;
+            private final ${DependencyResolver.canonicalName} dependencyResolver;
+            private final ${ModuleIdentifier.canonicalName} identifier;
+            @Override
+            public ${ModuleIdentifier.canonicalName} getIdentifier() {
+                return identifier;
+            }
+            """
+    }
+
+    private static String getCachesOfResolvedIdentityRefs(List<ModuleField> moduleFields) {
+        return moduleFields.findAll { it.isIdentityRef() }.collect { IdentityRefModuleField field ->
+            "private ${field.identityClassType} ${field.identityClassName};"
+        }.join("\n")
+    }
+
+    private static String getCachesOfResolvedDependencies(List<ModuleField> moduleFields) {
+        return moduleFields.findAll { it.dependent }.collect { field ->
+            if (field.isList()) {
+                return """
+                    private java.util.List<${field.dependency.sie.exportedOsgiClassName}> ${
+                    field.name
+                }Dependency = new java.util.ArrayList<${field.dependency.sie.exportedOsgiClassName}>();
+                    protected final java.util.List<${field.dependency.sie.exportedOsgiClassName}> get${
+                    field.attributeName
+                }Dependency(){
+                        return ${field.name}Dependency;
+                    }
+                    """
+            } else {
+                return """
+                    private ${field.dependency.sie.exportedOsgiClassName} ${field.name}Dependency;
+                    protected final ${field.dependency.sie.exportedOsgiClassName} get${field.attributeName}Dependency(){
+                        return ${field.name}Dependency;
+                    }
+                    """
+            }
+        }.join("\n")
+    }
+
+    private static String getRuntimeRegistratorCode(Optional<FullyQualifiedName> maybeRegistratorType) {
+        if (maybeRegistratorType.isPresent()) {
+            String registratorType = maybeRegistratorType.get()
+
+            return """
+                private ${registratorType} rootRuntimeBeanRegistratorWrapper;
+
+                public ${registratorType} getRootRuntimeBeanRegistratorWrapper(){
+                    return rootRuntimeBeanRegistratorWrapper;
+                }
+
+                @Override
+                public void setRuntimeBeanRegistrator(${RootRuntimeBeanRegistrator.canonicalName} rootRuntimeRegistrator){
+                    this.rootRuntimeBeanRegistratorWrapper = new ${registratorType}(rootRuntimeRegistrator);
+                }
+                """
+        } else {
+            return ""
+        }
+    }
+
+    private static String getValidationMethods(List<ModuleField> moduleFields) {
+        String result = """
+            @Override
+            public void validate() {
+            """
+        // validate each mandatory dependency
+        List<String> lines = moduleFields.findAll{(it.dependent && it.dependency.mandatory)}.collect { field ->
+            if (field.isList()) {
+                return "" +
+                        "for(javax.management.ObjectName dep : ${field.name}) {\n" +
+                        "    dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, dep, ${field.name}JmxAttribute);\n" +
+                        "}\n"
+            } else {
+                return "dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, ${field.name}, ${field.name}JmxAttribute);"
+            }
+        }
+        result += lines.findAll { it.isEmpty() == false }.join("\n")
+        result += """
+                customValidation();
+            }
+
+            protected void customValidation(){
+            }
+        """
+        return result
+    }
+
+    private static String getLogger(FullyQualifiedName fqn) {
+        return "private static final ${Logger.canonicalName} logger = ${LoggerFactory.canonicalName}.getLogger(${fqn.toString()}.class);"
+    }
+
+    // assumes that each parameter name corresponds to an field in this class, constructs lines setting this.field = field;
+    private static String getConstructorStart(FullyQualifiedName fqn,
+                                              LinkedHashMap<String, String> parameters, String after) {
+        return "public ${fqn.typeName}(" +
+                parameters.collect { it.key + " " + it.value }.join(",") +
+                ") {\n" +
+                parameters.values().collect { "this.${it}=${it};\n" }.join() +
+                after +
+                "}\n"
+    }
+
+    private static String getNewConstructor(FullyQualifiedName abstractFQN) {
+        LinkedHashMap<String, String> parameters = [
+                (ModuleIdentifier.canonicalName): "identifier",
+                (DependencyResolver.canonicalName): "dependencyResolver"
+        ]
+        String setToNulls = ["oldInstance", "oldModule"].collect { "this.${it}=null;\n" }.join()
+        return getConstructorStart(abstractFQN, parameters, setToNulls)
+    }
+
+    private static String getCopyFromOldConstructor(FullyQualifiedName abstractFQN) {
+        LinkedHashMap<String, String> parameters = [
+                (ModuleIdentifier.canonicalName): "identifier",
+                (DependencyResolver.canonicalName): "dependencyResolver",
+                (abstractFQN.typeName): "oldModule",
+                (AutoCloseable.canonicalName): "oldInstance"
+        ]
+        return getConstructorStart(abstractFQN, parameters, "")
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/ConcreteModuleGeneratedObjectFactory.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/ConcreteModuleGeneratedObjectFactory.java
new file mode 100644 (file)
index 0000000..fbc507d
--- /dev/null
@@ -0,0 +1,101 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.TypeName;
+
+import java.util.LinkedHashMap;
+
+public class ConcreteModuleGeneratedObjectFactory {
+
+    public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright, Optional<String> header) {
+        FullyQualifiedName concreteFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getStubModuleName());
+        FullyQualifiedName abstractFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractModuleName());
+        Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription());
+        return toGeneratedObject(concreteFQN, abstractFQN, copyright, header, classJavaDoc);
+    }
+
+    GeneratedObject toGeneratedObject(FullyQualifiedName concreteFQN,
+                                             FullyQualifiedName abstractFQN,
+                                             Optional<String> copyright,
+                                             Optional<String> header,
+                                             Optional<String> classJavaDoc) {
+        // there are two constructors and two methods
+        JavaFileInputBuilder builder = new JavaFileInputBuilder();
+        builder.setTypeName(TypeName.classType);
+        builder.setFqn(concreteFQN);
+        builder.addExtendsFQN(abstractFQN);
+
+        builder.setCopyright(copyright);
+        builder.setHeader(header);
+        builder.setClassJavaDoc(classJavaDoc);
+
+        builder.addToBody(getNewCtor(concreteFQN));
+        builder.addToBody(getCopyCtor(concreteFQN));
+        builder.addToBody(getCustomValidationStub());
+        builder.addToBody(getCreateInstanceStub());
+
+        return new GeneratedObjectBuilder(builder.build()).toGeneratedObject();
+    }
+
+    private static String getNewCtor(FullyQualifiedName fqn) {
+        LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>(){
+            {
+                put(ModuleIdentifier.class.getCanonicalName(), "identifier");
+                put(DependencyResolver.class.getCanonicalName(), "dependencyResolver");
+            }
+        };
+        StringBuilder stringBuilder = getCtor(fqn, parameters);
+        return stringBuilder.toString();
+    }
+
+    private static StringBuilder getCtor(FullyQualifiedName fqn , LinkedHashMap<String, String> parameters) {
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append("public ").append(fqn.getTypeName()).append("(");
+        // parameters
+        stringBuilder.append(Joiner.on(", ").withKeyValueSeparator(" ").join(parameters));
+        stringBuilder.append(") {\n");
+        if (parameters.isEmpty() == false) {
+            stringBuilder.append("super(");
+            stringBuilder.append(Joiner.on(", ").join(parameters.values()));
+            stringBuilder.append(");\n");
+        }
+        stringBuilder.append("}");
+        return stringBuilder;
+    }
+
+    private static String getCopyCtor(final FullyQualifiedName fqn) {
+        LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>(){
+            {
+                put(ModuleIdentifier.class.getCanonicalName(), "identifier");
+                put(DependencyResolver.class.getCanonicalName(), "dependencyResolver");
+                put(fqn.toString(), "oldModule");
+                put(AutoCloseable.class.getCanonicalName(), "oldInstance");
+            }
+        };
+        StringBuilder stringBuilder = getCtor(fqn, parameters);
+        return stringBuilder.toString();
+    }
+
+    private static String getCustomValidationStub() {
+        return "@Override\n" +
+                "public void customValidation() {\n" +
+                "// add custom validation form module attributes here.\n" +
+                "}";
+    }
+
+    private static String getCreateInstanceStub() {
+        return "@Override\n" +
+                "public " + AutoCloseable.class.getCanonicalName() + " createInstance() {\n" +
+                "// TODO:implement\n" +
+                "throw new " + UnsupportedOperationException.class.getCanonicalName() + "();\n"+
+                "}";
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/GenericGeneratedObjectFactory.groovy b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/GenericGeneratedObjectFactory.groovy
new file mode 100644 (file)
index 0000000..6504aac
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.gofactory
+
+import com.google.common.base.Optional
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObjectBuilder
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder
+
+public class GenericGeneratedObjectFactory {
+
+    public GeneratedObject toGeneratedObject(FtlTemplate template, Optional<String> copyright) {
+        JavaFileInputBuilder b = new JavaFileInputBuilder();
+        b.setHeader(template.headerString)
+        b.setFqn(new FullyQualifiedName(template.packageName, template.typeDeclaration.name))
+        b.setClassJavaDoc(template.maybeJavadoc)
+        template.annotations.each { b.addClassAnnotation(it) }
+        // type declaration
+        template.typeDeclaration.extended.each { b.addExtendsFQN(FullyQualifiedName.fromString(it)) }
+        template.typeDeclaration.implemented.each { b.addImplementsFQN(FullyQualifiedName.fromString(it)) }
+        b.setCopyright(copyright);
+        b.setTypeName(template.typeDeclaration.toTypeName())
+        // fields
+        template.fields.each { b.addToBody(it.toString()) }
+        // constructors
+        template.constructors.each { b.addToBody(it.toString()) }
+        // methods
+        template.methods.each { b.addToBody(it.toString()) }
+
+        return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/FullyQualifiedName.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/FullyQualifiedName.java
new file mode 100644 (file)
index 0000000..f72551a
--- /dev/null
@@ -0,0 +1,81 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
+
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class FullyQualifiedName {
+
+    private final String packageName;
+    private final String typeName;
+
+    public FullyQualifiedName(String packageName, String typeName) {
+        this.packageName = checkNotNull(packageName);
+        this.typeName = checkNotNull(typeName);
+    }
+
+    public FullyQualifiedName(Class<?> clazz) {
+        this(clazz.getPackage().getName(), clazz.getSimpleName());
+    }
+
+    public static FullyQualifiedName fromString(String fqn) {
+        Matcher m = Pattern.compile("(.*)\\.([^\\.]+)$").matcher(fqn);
+        if (m.matches()) {
+            return new FullyQualifiedName(m.group(1), m.group(2));
+        } else {
+            return new FullyQualifiedName("", fqn);
+        }
+    }
+
+    public String getPackageName() {
+        return packageName;
+    }
+
+    public String getTypeName() {
+        return typeName;
+    }
+
+    public File toFile(File srcDirectory) {
+        String directory = packageName.replace(".", File.separator);
+        return new File(srcDirectory, directory + File.separator + typeName + ".java");
+    }
+
+
+    @Override
+    public String toString() {
+        if (packageName.isEmpty()){
+            return typeName;
+        }
+        return packageName + "." + typeName;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        FullyQualifiedName that = (FullyQualifiedName) o;
+
+        if (!packageName.equals(that.packageName)) {
+            return false;
+        }
+        if (!typeName.equals(that.typeName)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = packageName.hashCode();
+        result = 31 * result + typeName.hashCode();
+        return result;
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObject.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObject.java
new file mode 100644 (file)
index 0000000..4ad080c
--- /dev/null
@@ -0,0 +1,75 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Maps;
+import org.apache.commons.io.FileUtils;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map.Entry;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class GeneratedObject {
+
+    private final FullyQualifiedName fqn;
+    private final String content;
+
+    public GeneratedObject(FullyQualifiedName fqn, String content) {
+        this.fqn = checkNotNull(fqn);
+        this.content = StringUtil.formatJavaSource(checkNotNull(content));
+    }
+
+    public FullyQualifiedName getFQN(){
+        return fqn;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory, boolean overwrite) throws IOException {
+        File dstFile = fqn.toFile(srcDirectory);
+        if (overwrite == true || dstFile.exists() == false) {
+            FileUtils.write(dstFile, content);
+            return Optional.of(Maps.immutableEntry(fqn, dstFile));
+        } else {
+            return Optional.absent();
+        }
+    }
+
+    public Optional<Entry<FullyQualifiedName,File>> persist(File srcDirectory) throws IOException {
+        return persist(srcDirectory, true);
+    }
+
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + "{" +
+                "fqn=" + fqn +
+                '}';
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        GeneratedObject that = (GeneratedObject) o;
+
+        if (!fqn.equals(that.fqn)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return fqn.hashCode();
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObjectBuilder.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/GeneratedObjectBuilder.java
new file mode 100644 (file)
index 0000000..72819db
--- /dev/null
@@ -0,0 +1,68 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil;
+
+import static org.opendaylight.controller.config.yangjmxgenerator.plugin.util.StringUtil.prefixAndJoin;
+
+public class GeneratedObjectBuilder {
+    private final JavaFileInput input;
+
+    public GeneratedObjectBuilder(JavaFileInput input) {
+        this.input = input;
+    }
+
+
+    public GeneratedObject toGeneratedObject() {
+        FullyQualifiedName fqn = input.getFQN();
+        StringBuilder content = new StringBuilder();
+
+
+        content.append(maybeAddComment(input.getCopyright()));
+        content.append(maybeAddComment(input.getHeader()));
+
+        if (input.getFQN().getPackageName().isEmpty() == false) {
+            content.append("package ");
+            content.append(input.getFQN().getPackageName());
+            content.append(";\n");
+        }
+        content.append(maybeAddComment(input.getClassJavaDoc(), true));
+
+        for (String classAnnotation : input.getClassAnnotations()) {
+            content.append(classAnnotation);
+            content.append("\n");
+        }
+
+        content.append("public ");
+        content.append(input.getType());
+        content.append(" ");
+        content.append(input.getFQN().getTypeName());
+        content.append(prefixAndJoin(input.getExtends(), "extends"));
+        content.append(prefixAndJoin(input.getImplements(), "implements"));
+        content.append(" {\n");
+
+        for (String method : input.getBodyElements()) {
+            content.append(method);
+            content.append("\n");
+        }
+
+        content.append("\n}\n");
+
+        return new GeneratedObject(fqn, content.toString());
+    }
+
+    private static String maybeAddComment(Optional<String> comment) {
+        return maybeAddComment(comment, false);
+    }
+
+    private static String maybeAddComment(Optional<String> comment, boolean isJavadoc) {
+
+        if (comment.isPresent()) {
+            String input = comment.get();
+            return StringUtil.writeComment(input, isJavadoc);
+        } else {
+            return "";
+        }
+    }
+
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/JavaFileInput.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/JavaFileInput.java
new file mode 100644 (file)
index 0000000..ba8537b
--- /dev/null
@@ -0,0 +1,27 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
+
+import com.google.common.base.Optional;
+
+import java.util.List;
+
+public interface JavaFileInput {
+
+    FullyQualifiedName getFQN();
+
+    Optional<String> getCopyright();
+
+    Optional<String> getHeader();
+
+    TypeName getType();
+
+    Optional<String> getClassJavaDoc();
+
+    List<String> getClassAnnotations();
+
+    List<FullyQualifiedName> getExtends();
+
+    List<FullyQualifiedName> getImplements();
+
+    List<String> getBodyElements();
+
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/JavaFileInputBuilder.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/JavaFileInputBuilder.java
new file mode 100644 (file)
index 0000000..c739f57
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.java;
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public class JavaFileInputBuilder {
+
+    private Optional<String> copyright = Optional.absent(), header = Optional.absent(), classJavaDoc = Optional.absent();
+
+    private TypeName typeName = TypeName.classType;
+
+    private FullyQualifiedName fqn;
+
+    private final List<String> classAnnotations = new ArrayList<>();
+
+    private final List<FullyQualifiedName> extendsFQNs = new ArrayList<>();
+
+    private final List<FullyQualifiedName> implementsFQNs = new ArrayList<>();
+
+    private final List<String> bodyElements = new ArrayList<>();
+
+    public void addToBody(String element) {
+        bodyElements.add(element + "\n");
+    }
+
+    public void addClassAnnotation(Annotation annotation) {
+        addClassAnnotation(annotation.toString());
+    }
+
+    public void addClassAnnotation(String annotation) {
+        classAnnotations.add(checkNotNull(annotation));
+    }
+
+    public void addExtendsFQN(FullyQualifiedName fqn) {
+        extendsFQNs.add(fqn);
+    }
+
+    public void addImplementsFQN(FullyQualifiedName fqn) {
+        implementsFQNs.add(fqn);
+    }
+
+    public Optional<String> getCopyright() {
+        return copyright;
+    }
+
+    public void setCopyright(Optional<String> copyright) {
+        this.copyright = checkNotNull(copyright);
+    }
+
+    public Optional<String> getHeader() {
+        return header;
+    }
+
+    public void setHeader(Optional<String> header) {
+        this.header = checkNotNull(header);
+    }
+
+
+    public Optional<String> getClassJavaDoc() {
+        return classJavaDoc;
+    }
+
+    public void setClassJavaDoc(Optional<String> classJavaDoc) {
+        this.classJavaDoc = checkNotNull(classJavaDoc);
+    }
+
+
+    public FullyQualifiedName getFqn() {
+        return fqn;
+    }
+
+    public void setFqn(FullyQualifiedName fqn) {
+        this.fqn = fqn;
+    }
+
+    public List<FullyQualifiedName> getExtendsFQNs() {
+        return extendsFQNs;
+    }
+
+
+    public List<FullyQualifiedName> getImplementsFQNs() {
+        return implementsFQNs;
+    }
+
+
+    public TypeName getTypeName() {
+        return typeName;
+    }
+
+    public void setTypeName(TypeName typeName) {
+        this.typeName = typeName;
+    }
+
+
+    public JavaFileInput build() {
+        checkNotNull(copyright);
+        checkNotNull(header);
+        checkNotNull(classJavaDoc);
+        checkNotNull(typeName);
+        checkNotNull(fqn);
+
+        return new JavaFileInput() {
+
+            @Override
+            public FullyQualifiedName getFQN() {
+                return fqn;
+            }
+
+            @Override
+            public Optional<String> getCopyright() {
+                return copyright;
+            }
+
+            @Override
+            public Optional<String> getHeader() {
+                return header;
+            }
+
+            @Override
+            public Optional<String> getClassJavaDoc() {
+                return classJavaDoc;
+            }
+
+            @Override
+            public TypeName getType() {
+                return typeName;
+            }
+
+            @Override
+            public List<FullyQualifiedName> getExtends() {
+                return Collections.unmodifiableList(extendsFQNs);
+            }
+
+            @Override
+            public List<FullyQualifiedName> getImplements() {
+                return Collections.unmodifiableList(implementsFQNs);
+            }
+
+            @Override
+            public List<String> getClassAnnotations() {
+                return Collections.unmodifiableList(classAnnotations);
+            }
+
+            @Override
+            public List<String> getBodyElements() {
+                return Collections.unmodifiableList(bodyElements);
+            }
+        };
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/TypeName.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/java/TypeName.java
new file mode 100644 (file)
index 0000000..d6ed12d
--- /dev/null
@@ -0,0 +1,17 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
+
+public enum TypeName {
+
+    classType("class"), interfaceType("interface"), enumType("enum"), absClassType("abstract class"), finalClassType("final class");
+
+    private final String value;
+
+    TypeName(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        return value;
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtil.java b/opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtil.java
new file mode 100644 (file)
index 0000000..265aea1
--- /dev/null
@@ -0,0 +1,101 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.util;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.regex.Pattern;
+
+public class StringUtil {
+    private static final Logger logger = LoggerFactory.getLogger(StringUtils.class);
+
+    /**
+     * @param list   of strings to be joined by ','
+     * @param prefix e.g. 'extends' or 'implements'
+     */
+    public static String prefixAndJoin(List<FullyQualifiedName> list, String prefix) {
+        if (list.isEmpty()) {
+            return "";
+        }
+        Joiner joiner = Joiner.on(",");
+        return " " + prefix + " " + joiner.join(list);
+    }
+
+    public static String addAsterixAtEachLineStart(String input) {
+        String s = Pattern.compile("^", Pattern.MULTILINE).matcher(input).replaceAll("* ");
+        // remove trailing spaces
+        s = Pattern.compile("\\s+$", Pattern.MULTILINE).matcher(s).replaceAll("");
+        s = ensureEndsWithSingleNewLine(s);
+        return s;
+    }
+
+    private static String ensureEndsWithSingleNewLine(String s) {
+        // .split Only trailing empty strings are skipped.
+        String[] split = s.split("\n");
+        s = Joiner.on("\n").join(split);
+        s = s + "\n";
+        return s;
+    }
+
+    public static String writeComment(String input, boolean isJavadoc) {
+        StringBuilder content = new StringBuilder();
+        content.append("/*");
+        if (isJavadoc) {
+            content.append("*");
+        }
+        content.append("\n");
+
+        content.append(addAsterixAtEachLineStart(input));
+        content.append("*/\n");
+        return content.toString();
+    }
+
+
+    public static Optional<String> loadCopyright() {
+        try (InputStream in = StringUtil.class.getResourceAsStream("/copyright.txt")) {
+            if (in != null) {
+                return Optional.of(IOUtils.toString(in));
+            }
+        } catch (IOException e) {
+            logger.warn("Cannot load copyright.txt", e);
+        }
+        return Optional.absent();
+    }
+
+    public static String formatJavaSource(String input) {
+        Iterable<String> split = Splitter.on("\n").trimResults().split(input);
+
+        int basicIndent = 4;
+        StringBuilder sb = new StringBuilder();
+        int intends = 0, empty = 0;
+        for (String line : split) {
+            intends -= StringUtils.countMatches(line, "}");
+            if (intends < 0) {
+                intends = 0;
+            }
+            if (line.isEmpty() == false) {
+                sb.append(Strings.repeat(" ", basicIndent * intends));
+                sb.append(line);
+                sb.append("\n");
+                empty = 0;
+            } else {
+                empty++; // one empty line is allowed
+                if (empty < 2) {
+                    sb.append("\n");
+                }
+            }
+            intends += StringUtils.countMatches(line, "{");
+        }
+        return ensureEndsWithSingleNewLine(sb.toString());
+    }
+
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/copyright.txt b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/copyright.txt
new file mode 100644 (file)
index 0000000..4a0c355
--- /dev/null
@@ -0,0 +1,5 @@
+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
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/abstract_ftl_file.ftl b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/abstract_ftl_file.ftl
deleted file mode 100644 (file)
index 0c6bf83..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<@headerD header=header/>
-package ${packageName};
-
-<@javadocD object=javadoc/>
-<@annotationsD object=annotations/>
-<#-- class/interface -->
-<@typeDeclarationD object=typeDeclaration/>
-{
-<@constructorsD object=constructors>
-</@constructorsD>
-<@fieldsD object=fields/>
-
-<@methodsD object=methods/>
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/factory_abs_template.ftl b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/factory_abs_template.ftl
deleted file mode 100644 (file)
index b9bbf1f..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-<@headerD header=header/>
-package ${packageName};
-
-<@javadocD object=javadoc/>
-@org.opendaylight.yangtools.yang.binding.annotations.ModuleQName(namespace="${mbe.getYangModuleQName().getNamespace().toString()}",revision="${mbe.getYangModuleQName().getFormattedRevision()}",name="${mbe.getYangModuleQName().getLocalName()}")
-<@typeDeclarationD object=typeDeclaration/>
-{
-
-    public static final java.lang.String NAME = "${globallyUniqueName}";
-    private static final java.util.Set<Class<? extends ${abstractServiceInterfaceType}>> serviceIfcs;
-    <#if providedServices??>
-    static {
-        java.util.Set<Class<? extends ${abstractServiceInterfaceType}>> serviceIfcs2 = new java.util.HashSet<Class<? extends ${abstractServiceInterfaceType}>>();
-        <#list providedServices as refId>
-        serviceIfcs2.add(${refId});
-        </#list>
-        serviceIfcs = java.util.Collections.unmodifiableSet(serviceIfcs2);
-    }
-    </#if>
-
-    @Override
-    public final boolean isModuleImplementingServiceInterface(Class<? extends ${abstractServiceInterfaceType}> serviceInterface) {
-        for (Class<?> ifc: serviceIfcs) {
-            if (serviceInterface.isAssignableFrom(ifc)){
-                return true;
-            }
-        }
-        return false;
-    }
-
-    @Override
-    public java.util.Set<Class<? extends ${abstractServiceInterfaceType}>> getImplementedServiceIntefaces() {
-        return serviceIfcs;
-    }
-
-
-    @Override
-    public ${moduleType} createModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${bundleContextType} bundleContext) {
-        return instantiateModule(instanceName, dependencyResolver, bundleContext);
-    }
-
-    @Override
-    public ${moduleType} createModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${dynamicMBeanWithInstanceType} old, ${bundleContextType} bundleContext) throws Exception {
-        ${moduleInstanceType} oldModule = null;
-        try {
-            oldModule = (${moduleInstanceType}) old.getModule();
-        } catch(Exception e) {
-            return handleChangedClass(old);
-        }
-        ${moduleInstanceType} module = instantiateModule(instanceName, dependencyResolver, oldModule, old.getInstance(), bundleContext);
-
-        <#list fields as attr>
-        module.set${attr.name}(oldModule.get${attr.name}());
-        </#list>
-
-        return module;
-    }
-
-    public ${moduleInstanceType} instantiateModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${moduleInstanceType} oldModule, ${instanceType} oldInstance, ${bundleContextType} bundleContext) {
-        return new ${moduleInstanceType}(new ${moduleNameType}(NAME, instanceName), dependencyResolver, oldModule, oldInstance);
-    }
-
-    public ${moduleInstanceType} instantiateModule(String instanceName, ${dependencyResolverType} dependencyResolver, ${bundleContextType} bundleContext) {
-        return new ${moduleInstanceType}(new ${moduleNameType}(NAME, instanceName), dependencyResolver);
-    }
-
-    @Override
-    public final String getImplementationName() {
-        return NAME;
-    }
-
-
-    public ${moduleInstanceType} handleChangedClass(${dynamicMBeanWithInstanceType} old) throws Exception {
-        throw new UnsupportedOperationException("Class reloading is not supported");
-    }
-
-    @Override
-    public java.util.Set<${moduleInstanceType}> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory, ${bundleContextType} bundleContext) {
-        return new java.util.HashSet<${moduleInstanceType}>();
-    }
-
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_abs_template_new.ftl
deleted file mode 100644 (file)
index 848fcfe..0000000
+++ /dev/null
@@ -1,223 +0,0 @@
-<@headerD header=header/>
-package ${packageName};
-
-<@javadocD object=javadoc/>
-<@annotationsD object=annotations/>
-<@typeDeclarationD object=typeDeclaration/>
-{
-    // attributes
-    <@moduleFieldsD moduleFields=moduleFields/>
-    //attributes end
-
-    private static final ${loggerType} logger = ${loggerFactoryType}.getLogger(${typeDeclaration.name}.class);
-
-    private final ${typeDeclaration.name} oldModule;
-    private final ${instanceType} oldInstance;
-    private ${instanceType} instance;
-    private final ${dependencyResolverType} dependencyResolver;
-    private final ${moduleNameType} identifier;
-    <#if runtime=true>
-    private ${registratorType} rootRuntimeBeanRegistratorWrapper;
-    </#if>
-
-    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver) {
-        this.identifier = identifier;
-        this.dependencyResolver = dependencyResolver;
-        this.oldInstance = null;
-        this.oldModule = null;
-    }
-
-    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver, ${typeDeclaration.name} oldModule, ${instanceType} oldInstance) {
-        this.identifier = identifier;
-        this.dependencyResolver = dependencyResolver;
-        this.oldInstance = oldInstance;
-        this.oldModule = oldModule;
-    }
-
-    // getters and setters exported into MXBean
-    <@methodsD object=methods/>
-
-    <#if runtime=true>
-    public ${registratorType} getRootRuntimeBeanRegistratorWrapper(){
-        return rootRuntimeBeanRegistratorWrapper;
-    }
-
-    @Override
-    public void setRuntimeBeanRegistrator(${rootRuntimeRegistratorType} rootRuntimeRegistrator){
-        this.rootRuntimeBeanRegistratorWrapper = new ${registratorType}(rootRuntimeRegistrator);
-    }
-    </#if>
-
-    @Override
-    public void validate(){
-    <#list moduleFields as field>
-        <#if field.dependent==true && field.dependency.mandatory==true>
-        <#if field.type?starts_with("java.util.List")>
-        for(javax.management.ObjectName dep : ${field.name}) {
-            dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, dep, ${field.name}JmxAttribute);
-        }
-        <#else>
-        dependencyResolver.validateDependency(${field.dependency.sie.fullyQualifiedName}.class, ${field.name}, ${field.name}JmxAttribute);
-        </#if>
-        </#if>
-    </#list>
-        customValidation();
-    }
-
-    protected void customValidation(){
-
-    }
-
-    // caches of resolved dependencies
-    <#list moduleFields as field>
-    <#if field.dependent==true>
-        <#if field.type?starts_with("java.util.List")>
-        private java.util.List<${field.dependency.sie.exportedOsgiClassName}> ${field.name}Dependency = new java.util.ArrayList<${field.dependency.sie.exportedOsgiClassName}>();
-        protected final java.util.List<${field.dependency.sie.exportedOsgiClassName}> get${field.attributeName}Dependency(){
-            return ${field.name}Dependency;
-        }
-        <#else>
-        private ${field.dependency.sie.exportedOsgiClassName} ${field.name}Dependency;
-        protected final ${field.dependency.sie.exportedOsgiClassName} get${field.attributeName}Dependency(){
-            return ${field.name}Dependency;
-        }
-        </#if>
-    </#if>
-    </#list>
-
-    // caches of resolved IdentityRefs
-    <#list moduleFields as field>
-    <#if field.identityRef==true>
-        private ${field.identityClassType} ${field.identityClassName};
-    </#if>
-    </#list>
-
-    @Override
-    public final ${instanceType} getInstance(){
-        if(instance==null) {
-
-            <#list moduleFields as field>
-                <#if field.dependent==true>
-                    <#if field.dependency.mandatory==false>
-                        if(${field.name}!=null) {
-                    </#if>
-
-                    <#if field.type?starts_with("java.util.List")>
-            ${field.name}Dependency = new java.util.ArrayList<${field.dependency.sie.exportedOsgiClassName}>();
-            for(javax.management.ObjectName dep : ${field.name}) {
-                ${field.name}Dependency.add(dependencyResolver.resolveInstance(${field.dependency.sie.exportedOsgiClassName}.class, dep, ${field.name}JmxAttribute));
-            }
-                    <#else>
-            ${field.name}Dependency = dependencyResolver.resolveInstance(${field.dependency.sie.exportedOsgiClassName}.class, ${field.name}, ${field.name}JmxAttribute);
-                    </#if>
-
-                    <#if field.dependency.mandatory==false>
-                        }
-                    </#if>
-                </#if>
-
-                <#if field.needsDepResolver==true>
-            if(${field.name} != null) {
-                    <#if field.type?starts_with("java.util.List")>
-                for(${field.type?substring(field.type?index_of("<") + 1, field.type?index_of(">"))} candidate : ${field.name}) {
-                    candidate.injectDependencyResolver(dependencyResolver);
-                }
-                    <#else>
-                ${field.name}.injectDependencyResolver(dependencyResolver);
-                    </#if>
-            }
-                </#if>
-
-                <#if field.identityRef==true>
-            if(${field.name} != null) {
-                set${field.attributeName}(${field.name}.resolveIdentity(dependencyResolver, ${field.identityBaseClass}.class));
-            }
-                </#if>
-            </#list>
-
-            if(oldInstance!=null && canReuseInstance(oldModule)) {
-                instance = reuseInstance(oldInstance);
-            } else {
-                if(oldInstance!=null) {
-                    try {
-                        oldInstance.close();
-                    } catch(Exception e) {
-                        logger.error("An error occurred while closing old instance " + oldInstance, e);
-                    }
-                }
-                instance = createInstance();
-            }
-        }
-        return instance;
-    }
-
-    @Override
-    public ${moduleNameType} getIdentifier() {
-        return identifier;
-    }
-
-    public boolean canReuseInstance(${typeDeclaration.name} oldModule){
-        // allow reusing of old instance if no parameters was changed
-        return isSame(oldModule);
-    }
-
-    public ${instanceType} reuseInstance(${instanceType} oldInstance){
-        // implement if instance reuse should be supported. Override canReuseInstance to change the criteria.
-        return oldInstance;
-    }
-
-    public abstract ${instanceType} createInstance();
-
-    public boolean isSame(${typeDeclaration.name} other) {
-        if (other == null) {
-            throw new IllegalArgumentException("Parameter 'other' is null");
-        }
-        <#list moduleFields as field>
-        <#if field.dependent==true && field.listOfDependencies == false>
-        if (${field.name}Dependency != other.${field.name}Dependency) { // reference to dependency must be same
-            return false;
-        }
-        <#elseif field.listOfDependencies>
-        if (${field.name}Dependency.equals(other.${field.name}Dependency) == false) {
-            return false;
-        }
-        for (int idx = 0; idx < ${field.name}Dependency.size(); idx++) {
-            if (${field.name}Dependency.get(idx) != other.${field.name}Dependency.get(idx)) {
-                return false;
-            }
-        }
-        <#else>
-        if (${field.name} == null) {
-            if (other.${field.name} != null) {
-                return false;
-            }
-        } else if
-            <#if field.array == false>
-                (${field.name}.equals(other.${field.name}) == false)
-            <#else>
-                (java.util.Arrays.equals(${field.name},other.${field.name}) == false)
-            </#if>
-                 {
-            return false;
-        }
-        </#if>
-        </#list>
-
-        return true;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
-        ${typeDeclaration.name} that = (${typeDeclaration.name}) o;
-
-        return identifier.equals(that.identifier);
-    }
-
-    @Override
-    public int hashCode() {
-        return identifier.hashCode();
-    }
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl b/opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/module_stub_template.ftl
deleted file mode 100644 (file)
index 2db505e..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<@headerD header=header/>
-package ${packageName};
-
-<@javadocD object=javadoc/>
-<@typeDeclarationD object=typeDeclaration/> {
-
-    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver) {
-        super(identifier, dependencyResolver);
-    }
-
-    public ${typeDeclaration.name}(${moduleNameType} identifier, ${dependencyResolverType} dependencyResolver,
-            ${typeDeclaration.name} oldModule, ${instanceType} oldInstance) {
-
-        super(identifier, dependencyResolver, oldModule, oldInstance);
-    }
-
-    @Override
-    protected void customValidation(){
-        // Add custom validation for module attributes here.
-    }
-
-    @Override
-    public ${instanceType} createInstance() {
-        //TODO:implement
-        <@unimplementedExceptionD/>
-    }
-}
index 9e2f334dac6eb22f647030ae8b6e776c9e6295d1..1dde94b48244fed6b8ca5867b874280f3aa425ee 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin;
 
-import java.io.File;
-
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.opendaylight.controller.config.yangjmxgenerator.AbstractYangTest;
 
+import java.io.File;
+
 public abstract class AbstractGeneratorTest extends AbstractYangTest {
     private static final File GENERATOR_OUTPUT_PATH_ROOT = new File(
             "target/testgen");
index 3ef406694a6b12b7825f860e0130fbf20a1075dd..0fd9720f79be60b0abab01dd60c651e1ed865ba6 100644 (file)
@@ -119,7 +119,7 @@ public class JMXGeneratorTest extends AbstractGeneratorTest {
                         + JMXGenerator.NAMESPACE_TO_PACKAGE_DIVIDER
                         + PackageTranslatorTest.EXPECTED_PACKAGE_PREFIX);
         map.put(JMXGenerator.MODULE_FACTORY_FILE_BOOLEAN, "false");
-        jmxGenerator = new JMXGenerator(new FreeMarkerCodeWriterImpl());
+        jmxGenerator = new JMXGenerator(new CodeWriter());
         jmxGenerator.setAdditionalConfig(map);
         File targetDir = new File(generatorOutputPath, "target");
         generatedResourcesDir = new File(targetDir, "generated-resources");
index 48d5b30eb282731bc7adabe46427384352272bf4..3c01cc00d46ef40bb0191560fcdc7cccf23f2697 100644 (file)
@@ -34,7 +34,7 @@ public class ModuleMXBeanEntryTemplatesTest {
         assertNotNull(template);
     }
 
-    private ModuleMXBeanEntry mockMbe(String packageName) {
+    public static ModuleMXBeanEntry mockMbe(String packageName) {
         ModuleMXBeanEntry mbe = mock(ModuleMXBeanEntry.class);
         Map<String, AttributeIfc> a = Maps.newHashMap();
         JavaAttribute attr = mockJavaAttr();
@@ -52,7 +52,7 @@ public class ModuleMXBeanEntryTemplatesTest {
         return mbe;
     }
 
-    private JavaAttribute mockJavaAttr() {
+    public static JavaAttribute mockJavaAttr() {
         JavaAttribute attr = mock(JavaAttribute.class);
         Type typeA = mock(Type.class);
         doReturn("package").when(typeA).getName();
index b12ee5023f237f8243468e6f4d0f665ba8380a63..f21765e536f9f5a4405323a8a048e0b561fd59d9 100644 (file)
@@ -7,26 +7,21 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.internal.matchers.StringContains.containsString;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Map;
-
 import org.junit.Test;
 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry;
 import org.opendaylight.controller.config.yangjmxgenerator.RuntimeRegistratorTest;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlFilePersister;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.FtlTemplate;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.RuntimeRegistratorFtlTemplate;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FormattingUtil;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 
 public class RuntimeRegistratorFtlFileTest extends RuntimeRegistratorTest {
-    private final FtlFilePersister ftlFilePersister = new FtlFilePersister();
 
     @Test
     public void testRootWithoutAnything() {
@@ -40,9 +35,7 @@ public class RuntimeRegistratorFtlFileTest extends RuntimeRegistratorTest {
         FtlTemplate rootFtlFile = createdFtls.get(rootRegistratorName);
         assertNotNull(rootFtlFile);
 
-        Map<FtlTemplate, String> serializedFtls = ftlFilePersister
-                .serializeFtls(createdFtls.values());
-        assertThat(serializedFtls.size(), is(2));
+        assertThat(createdFtls.values().size(), is(2));
     }
 
     @Test
@@ -55,29 +48,6 @@ public class RuntimeRegistratorFtlFileTest extends RuntimeRegistratorTest {
 
         Map<String, FtlTemplate> createdFtls = RuntimeRegistratorFtlTemplate
                 .create(rootRB);
-        Map<FtlTemplate, String> serializedFtls = ftlFilePersister
-                .serializeFtls(createdFtls.values());
-        assertThat(serializedFtls.size(), is(4));
-
-        assertThat(
-                findRegistrationOutput(createdFtls, grandChildRB,
-                        serializedFtls), not(containsString(" register(")));
-
-        FtlTemplate registrator = createdFtls.get(RuntimeRegistratorFtlTemplate
-                .getJavaNameOfRuntimeRegistrator(rootRB));
-        FormattingUtil.cleanUpEmptyLinesAndIndent(serializedFtls
-                .get(registrator));
-
+        assertThat(createdFtls.values().size(), is(4));
     }
-
-    private String findRegistrationOutput(Map<String, FtlTemplate> createdFtls,
-            RuntimeBeanEntry rb, Map<FtlTemplate, String> serializedFtls) {
-        RuntimeRegistratorFtlTemplate rbFtlFile = (RuntimeRegistratorFtlTemplate) createdFtls
-                .get(RuntimeRegistratorFtlTemplate.getJavaNameOfRuntimeRegistration(rb.getJavaNamePrefix()));
-        assertNotNull(rbFtlFile);
-        String unformatted = serializedFtls.get(rbFtlFile);
-        assertNotNull(unformatted);
-        return FormattingUtil.cleanUpEmptyLinesAndIndent(unformatted);
-    }
-
 }
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlFilePersisterTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/FtlFilePersisterTest.java
deleted file mode 100644 (file)
index 2582a60..0000000
+++ /dev/null
@@ -1,72 +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.config.yangjmxgenerator.plugin.ftl;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.MethodDeclaration;
-import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.FormattingUtil;
-
-import com.google.common.collect.Lists;
-
-public class FtlFilePersisterTest {
-    private final FtlFilePersister tested = new FtlFilePersister();
-
-    @Before
-    public void setUp() {
-        MockitoAnnotations.initMocks(this);
-    }
-
-    @Test
-    public void testGeneralInterface() {
-        String packageName = "pa.cka.ge";
-        String name = "GeneralClassImpl";
-        List<String> extendedInterfaces = Arrays.asList("List", "Set");
-        List<MethodDeclaration> methods = new ArrayList<>();
-        methods.add(new MethodDeclaration("String", "executeOperation",
-                Collections.<Field> emptyList()));
-
-        List<String> mods = Lists.newArrayList();
-        List<String> mods2 = Lists.newArrayList("final");
-        methods.add(new MethodDeclaration("String", "executeOperation", Arrays
-                .asList(new Field(mods, "int", "param1"), new Field(mods2, "long", "param2"))));
-
-        GeneralInterfaceTemplate generalInterface = new GeneralInterfaceTemplate(
-                null, packageName, name, extendedInterfaces, methods);
-
-        Map<FtlTemplate, String> abstractFtlFileStringMap = tested
-                .serializeFtls(Arrays.asList(generalInterface));
-        String content = FormattingUtil
-                .cleanUpEmptyLinesAndIndent(abstractFtlFileStringMap.get(generalInterface));
-
-        // skip header
-        content = content.substring(content.indexOf("package"));
-
-        String expected = "package pa.cka.ge;\n"
-                + "/**\n"
-                + "*\n"
-                + "*/\n"
-                + "public interface GeneralClassImpl extends List, Set\n{\n"
-                + "public String executeOperation();\n"
-                + "public String executeOperation(int param1, final long param2);\n"
-                + "}\n";
-
-        assertEquals(expected, content);
-    }
-
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/AbstractGeneratedObjectTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/AbstractGeneratedObjectTest.java
new file mode 100644 (file)
index 0000000..957fbf5
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.module;
+
+import net.sourceforge.pmd.lang.Parser;
+import net.sourceforge.pmd.lang.ParserOptions;
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.java.Java17Parser;
+import org.apache.commons.io.FileUtils;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.AbstractGeneratorTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class AbstractGeneratedObjectTest extends AbstractGeneratorTest {
+    private static final Logger logger = LoggerFactory.getLogger(AbstractGeneratedObjectTest.class);
+
+    protected void assertHasMethodNamed(Node c, String method) {
+        assertTrue(c.hasDescendantMatchingXPath("//MethodDeclaration[MethodDeclarator[@Image='" +
+                method +
+                "']]"));
+    }
+
+    protected Node parse(File dstFile) throws IOException {
+        assertNotNull(dstFile);
+        logger.debug(FileUtils.readFileToString(dstFile));
+        Parser parser = new Java17Parser(new ParserOptions());
+        return parser.parse(dstFile.toString(), new FileReader(dstFile));
+    }
+
+
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/abs/AbsModuleGeneratedObjectFactoryTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/abs/AbsModuleGeneratedObjectFactoryTest.java
new file mode 100644 (file)
index 0000000..164d1a5
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.config.yangjmxgenerator.plugin.module.abs;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
+import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.module.AbstractGeneratedObjectTest;
+import org.opendaylight.yangtools.yang.common.QName;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class AbsModuleGeneratedObjectFactoryTest extends AbstractGeneratedObjectTest {
+
+    @Test
+    public void test() throws IOException {
+        Map<QName,ServiceInterfaceEntry> serviceInterfaceEntryMap = loadThreadsServiceInterfaceEntries("packages.sis");
+        Map<String, ModuleMXBeanEntry> namesToMBEs = loadThreadsJava(serviceInterfaceEntryMap, "packages.pack2");
+        ModuleMXBeanEntry dynamicThreadPool = namesToMBEs.get(THREADPOOL_DYNAMIC_MXB_NAME);
+        parseGeneratedFile(dynamicThreadPool);
+
+    }
+
+    private void parseGeneratedFile(ModuleMXBeanEntry moduleMXBeanEntry) throws IOException {
+        Optional<String> copyright = Optional.absent();
+        GeneratedObject generatedObject = new AbsModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright);
+        Entry<FullyQualifiedName,File> entry = generatedObject.persist(generatorOutputPath).get();
+
+        File dstFile = entry.getValue();
+        parse(dstFile);
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/concrete/ConcreteModuleGeneratedObjectFactoryTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/module/concrete/ConcreteModuleGeneratedObjectFactoryTest.java
new file mode 100644 (file)
index 0000000..519b0ed
--- /dev/null
@@ -0,0 +1,52 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.module.concrete;
+
+import com.google.common.base.Optional;
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
+import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
+import org.junit.Test;
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.ConcreteModuleGeneratedObjectFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.module.AbstractGeneratedObjectTest;
+
+import java.io.File;
+import java.util.Map.Entry;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+public class ConcreteModuleGeneratedObjectFactoryTest extends AbstractGeneratedObjectTest {
+
+    @Test
+    public void test() throws Exception {
+        FullyQualifiedName fqn = new FullyQualifiedName("foo.bar", "Baz");
+        FullyQualifiedName abstractFQN = new FullyQualifiedName("foo.bar", "AbstractBaz");
+        String nullableDescription = null;
+
+        ModuleMXBeanEntry moduleMXBeanEntry = mockModuleMXBeanEntry(fqn, abstractFQN, nullableDescription);
+        Optional<String> copyright = Optional.absent();
+        Optional<String> header = Optional.absent();
+        GeneratedObject go = new ConcreteModuleGeneratedObjectFactory().toGeneratedObject(moduleMXBeanEntry, copyright, header);
+        Entry<FullyQualifiedName, File> entry = go.persist(generatorOutputPath).get();
+
+        File dstFile = entry.getValue();
+        Node c = parse(dstFile);
+        assertEquals(fqn.getPackageName(), ((ASTCompilationUnit) c).getPackageDeclaration().getPackageNameImage());
+        assertEquals(fqn.getTypeName(), c.getFirstDescendantOfType(ASTClassOrInterfaceDeclaration.class).getImage());
+        assertHasMethodNamed(c, "customValidation");
+        assertHasMethodNamed(c, "createInstance");
+    }
+
+    static ModuleMXBeanEntry mockModuleMXBeanEntry(FullyQualifiedName fqn, FullyQualifiedName abstractFQN, String nullableDescription) {
+        ModuleMXBeanEntry mock = mock(ModuleMXBeanEntry.class);
+        assertEquals(fqn.getPackageName(), abstractFQN.getPackageName());
+        doReturn(fqn.getPackageName()).when(mock).getPackageName();
+        doReturn(fqn.getTypeName()).when(mock).getStubModuleName();
+        doReturn(nullableDescription).when(mock).getNullableDescription();
+        doReturn(abstractFQN.getTypeName()).when(mock).getAbstractModuleName();
+        return mock;
+    }
+}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/FormattingUtil.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/FormattingUtil.java
deleted file mode 100644 (file)
index e62cb7c..0000000
+++ /dev/null
@@ -1,32 +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.config.yangjmxgenerator.plugin.util;
-
-import java.util.Scanner;
-
-public class FormattingUtil {
-
-    public static String cleanUpEmptyLinesAndIndent(String input) {
-        StringBuffer output = new StringBuffer();
-        Scanner scanner = new Scanner(input);
-        while (scanner.hasNextLine()) {
-            String line = scanner.nextLine();
-            line = line.replaceAll("\t", " ");
-            while (line.contains("  ")) {
-                line = line.replaceAll("  ", " ");
-            }
-            line = line.trim();
-            if (line.length() > 0) {
-                output.append(line);
-                output.append("\n");
-            }
-        }
-
-        return output.toString();
-    }
-}
diff --git a/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtilTest.java b/opendaylight/config/yang-jmx-generator-plugin/src/test/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/util/StringUtilTest.java
new file mode 100644 (file)
index 0000000..b0217a4
--- /dev/null
@@ -0,0 +1,60 @@
+package org.opendaylight.controller.config.yangjmxgenerator.plugin.util;
+
+import org.junit.Test;
+import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.FullyQualifiedName;
+
+import java.io.IOException;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class StringUtilTest {
+    @Test
+    public void testPrefixAndJoin() {
+        assertEquals(" extends p1.Foo,Bar", StringUtil.prefixAndJoin(asList(
+                new FullyQualifiedName("p1", "Foo"), new FullyQualifiedName("", "Bar")), "extends"));
+    }
+
+    @Test
+    public void testAddAsterixAtEachLineStart() {
+        String input = "foo   \nbar";
+        String expectedOutput = "* foo\n* bar\n";
+        assertEquals(expectedOutput, StringUtil.addAsterixAtEachLineStart(input));
+    }
+
+    @Test
+    public void testCopyright() throws IOException {
+        assertTrue(StringUtil.loadCopyright().isPresent());
+    }
+
+    @Test
+    public void testFormatting() {
+        {
+        String input = "  \tpack;\n" +
+                "class Bar{ \n" +
+                " method() {\n" +
+                "  body\n" +
+                "}\n" +
+                "  }";
+        String expected = "pack;\n" +
+                "class Bar{\n" +
+                "    method() {\n" +
+                "        body\n" +
+                "    }\n" +
+                "}\n";
+        assertEquals(expected, StringUtil.formatJavaSource(input));
+        }
+        {
+            String input = "{\n" +
+                    "bar\n" +
+                    "}\n" +
+                    "\n\nbaz\n\n\n\n";
+            String expected = "{\n" +
+                    "    bar\n" +
+                    "}\n\n" +
+                    "baz\n";
+            assertEquals(expected, StringUtil.formatJavaSource(input));
+        }
+    }
+}
index 1100b3543748cc89b7f26d4d521b7bf09712286f..76d97703af3722142bf361db63960fac77364d3d 100644 (file)
@@ -7,25 +7,29 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator;
 
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.format;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+import org.junit.Assert;
 import org.junit.Before;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.util.YangModelSearchUtils;
+import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 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 com.google.common.base.Preconditions;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.format;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
 
 public abstract class AbstractYangTest {
     protected SchemaContext context;
@@ -35,6 +39,14 @@ public abstract class AbstractYangTest {
             threadsJavaModule, bgpListenerJavaModule, ietfInetTypesModule,
             jmxModule, jmxImplModule, testFilesModule, testFiles1Module;
 
+    public static final String EVENTBUS_MXB_NAME = "eventbus";
+    public static final String ASYNC_EVENTBUS_MXB_NAME = "async-eventbus";
+    public static final String THREADFACTORY_NAMING_MXB_NAME = "threadfactory-naming";
+    public static final String THREADPOOL_DYNAMIC_MXB_NAME = "threadpool-dynamic";
+    public static final String THREADPOOL_REGISTRY_IMPL_NAME = "threadpool-registry-impl";
+
+    public static final String BGP_LISTENER_IMPL_MXB_NAME = "bgp-listener-impl";
+
     @Before
     public void loadYangFiles() throws Exception {
         List<InputStream> yangISs = new ArrayList<>();
@@ -97,4 +109,22 @@ public abstract class AbstractYangTest {
         }
         return result;
     }
+
+    protected Map<QName, ServiceInterfaceEntry>  loadThreadsServiceInterfaceEntries(String packageName) {
+        Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
+        return ServiceInterfaceEntry.create(threadsModule, packageName,identitiesToSIs);
+    }
+
+    protected Map<String /* identity local name */, ModuleMXBeanEntry> loadThreadsJava(Map<QName, ServiceInterfaceEntry> modulesToSIEs, String packageName) {
+        Map<String /* identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry
+                .create(threadsJavaModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl
+                        (context)), packageName);
+        Assert.assertNotNull(namesToMBEs);
+        Set<String> expectedMXBeanNames = Sets.newHashSet(EVENTBUS_MXB_NAME,
+                ASYNC_EVENTBUS_MXB_NAME, THREADFACTORY_NAMING_MXB_NAME,
+                THREADPOOL_DYNAMIC_MXB_NAME, THREADPOOL_REGISTRY_IMPL_NAME);
+        assertThat(namesToMBEs.keySet(), is(expectedMXBeanNames));
+        return namesToMBEs;
+    }
+
 }
index 8ca2bb5bc98247198a405fe8cb75bd42561f642e..dd44246867abb9af1e51bfe1bc5dbd8ea8c63f91 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.config.yangjmxgenerator;
 
 import com.google.common.collect.Sets;
-import java.util.HashMap;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
@@ -36,6 +35,7 @@ import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -52,13 +52,6 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
 public class ModuleMXBeanEntryTest extends AbstractYangTest {
-    public static final String EVENTBUS_MXB_NAME = "eventbus";
-    public static final String ASYNC_EVENTBUS_MXB_NAME = "async-eventbus";
-    public static final String THREADFACTORY_NAMING_MXB_NAME = "threadfactory-naming";
-    public static final String THREADPOOL_DYNAMIC_MXB_NAME = "threadpool-dynamic";
-    public static final String THREADPOOL_REGISTRY_IMPL_NAME = "threadpool-registry-impl";
-
-    public static final String BGP_LISTENER_IMPL_MXB_NAME = "bgp-listener-impl";
 
     public static final String PACKAGE_NAME = "pack2";
 
@@ -82,23 +75,15 @@ public class ModuleMXBeanEntryTest extends AbstractYangTest {
 
     protected Map<QName, ServiceInterfaceEntry> modulesToSIEs;
 
-    protected Map<String /* identity local name */, ModuleMXBeanEntry> loadThreadsJava() {
-        Map<String /* identity local name */, ModuleMXBeanEntry> namesToMBEs = ModuleMXBeanEntry
-                .create(threadsJavaModule, modulesToSIEs, context, new TypeProviderWrapper(new TypeProviderImpl
-                        (context)), PACKAGE_NAME);
-        assertNotNull(namesToMBEs);
-        Set<String> expectedMXBeanNames = Sets.newHashSet(EVENTBUS_MXB_NAME,
-                ASYNC_EVENTBUS_MXB_NAME, THREADFACTORY_NAMING_MXB_NAME,
-                THREADPOOL_DYNAMIC_MXB_NAME, THREADPOOL_REGISTRY_IMPL_NAME);
-        assertThat(namesToMBEs.keySet(), is(expectedMXBeanNames));
-        return namesToMBEs;
-    }
 
     @Before
     public void setUp() {
-        Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
-        modulesToSIEs = ServiceInterfaceEntry.create(threadsModule,
-                "packages.sis",identitiesToSIs);
+        modulesToSIEs = loadThreadsServiceInterfaceEntries("packages.sis");
+    }
+
+
+    protected Map<String /* identity local name */, ModuleMXBeanEntry> loadThreadsJava() {
+        return loadThreadsJava(modulesToSIEs, PACKAGE_NAME);
     }
 
     @Test
index 0b4fc8b1b534209f112faeacdd564c12ecc089ad..a4306c15c4cdd3401591b7fc99b269117828f71d 100644 (file)
@@ -22,5 +22,9 @@
             <artifactId>maven-plugin-api</artifactId>
             <version>3.0.5</version>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
index dbb9ddb363fb168ed820d06c30c1444f4db3b719..f2a56f2b1bfbe2a1e1066a90f3ef16ba6afef660 100644 (file)
@@ -7,18 +7,14 @@
  */
 package org.opendaylight.controller.config.yang.test.plugin;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
+import java.util.regex.Pattern;
 
 /**
  * Add implementation code from stub.txt
@@ -45,55 +41,25 @@ public class ProcessSources extends AbstractMojo{
         if (!sourceDirectory.exists()) {
             super.getLog().error("Source directory does not exists " + sourceDirectory.getPath());
         }
-        String header = "";
-        try {
-            header = Util.loadHeader();
-        } catch (IOException e) {
-           super.getLog().error("Header.txt not found.");
-        }
+
         File[] sourceFiles = sourceDirectory.listFiles();
         for (File sourceFile: sourceFiles) {
             if(sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) {
                 File stubFile = new File(sourceFile.getPath().replace(".java", "Stub.txt"));
-                String stubLines = null;
-                try {
-                    if (stubFile.exists()) {
-                        stubLines = Util.loadStubFile(stubFile.getPath());
-                    }
-
-                    InputStream javaIn = new FileInputStream(sourceFile.getPath());
-                    BufferedReader javaBuf = new BufferedReader(new InputStreamReader(javaIn));
-                    StringBuffer output = new StringBuffer();
-                    String line = javaBuf.readLine();
-                    boolean writeLine = false;
-                    while ((line = javaBuf.readLine()) != null) {
-                        if(!writeLine && line.contains("*/")) {
-                            line = header;
-                            writeLine = true;
-                        } else {
-                            if (line.contains("TODO")) {
-                                writeLine = false;
-                            } else {
-                                if (stubLines != null && line.contains("throw new")) {
-                                    line = stubLines.toString();
-                                    writeLine = true;
-                                }
-                            }
-                        }
-                        if(writeLine) {
-                            output.append(line).append(System.lineSeparator());
-                        }
+                if (stubFile.exists()) {
+                    try {
+                        rewrite(sourceFile, FileUtils.readFileToString(stubFile));
+                    } catch (IOException e) {
+                        getLog().error("Error while reading/writing to files.", e);
                     }
-                    javaBuf.close();
-
-                    OutputStream javaOut = new FileOutputStream(sourceFile.getPath());
-                    javaOut.write(output.toString().getBytes());
-                    javaOut.close();
-                } catch (IOException e) {
-                    getLog().error("Error while reading/writing to files.", e);
                 }
-
             }
         }
     }
+
+    private static void rewrite(File sourceFile, String replaceTODOWith) throws IOException {
+        String source = FileUtils.readFileToString(sourceFile);
+        String target = Pattern.compile("^.*TODO.*\n.*throw new java.lang.UnsupportedOperationException.*$", Pattern.MULTILINE).matcher(source).replaceFirst(replaceTODOWith);
+        FileUtils.write(sourceFile, target);
+    }
 }
index 16a41d9adb65c5786039bc3d7cf4615cfcfcc2e8..136733cbff138fcc292746baa9ccd152a3348683 100644 (file)
@@ -8,12 +8,7 @@
 
 package org.opendaylight.controller.config.yang.test.plugin;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.util.regex.Matcher;
 
 public class Util {
@@ -22,29 +17,4 @@ public class Util {
         path = path.replace(".", Matcher.quoteReplacement(File.separator));
         return path;
     }
-
-    public static String loadHeader() throws IOException {
-        StringBuffer header = new StringBuffer();
-        InputStream headIn = Util.class.getClassLoader().getResourceAsStream("Header.txt");
-        BufferedReader headBuf = new BufferedReader(new InputStreamReader(headIn));
-        String line = null;
-        while ((line = headBuf.readLine()) != null) {
-            header.append(line).append(System.lineSeparator());
-        }
-        headBuf.close();
-        return header.toString();
-    }
-
-    public static String loadStubFile(String fileName) throws IOException {
-        InputStream stubIn = new FileInputStream(fileName);
-        BufferedReader stubBuf = new BufferedReader(new InputStreamReader(stubIn));
-
-        StringBuffer stubLines = new StringBuffer();
-        String stubLine = null;
-        while ((stubLine = stubBuf.readLine()) != null) {
-            stubLines.append(stubLine).append(System.lineSeparator());
-        }
-        stubBuf.close();
-        return stubLines.toString();
-    }
 }
index 3e75d00943dec03e12074ebc0c5aff04bdfa46a5..ecce3e33fc6feca62fcb180ae3bf42230fabfff2 100644 (file)
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
             </plugin>
+
             <plugin>
                 <groupId>org.opendaylight.controller</groupId>
                 <artifactId>yang-test-plugin</artifactId>
                     <execution>
                         <goals>
                             <goal>delete-sources</goal>
+
                             <goal>process-sources</goal>
                         </goals>
                     </execution>
index c64f824b150f07c6f2179a6b8ab65909d9774454..07d7438a00b9758ccd28ee10b70f2059b37f77a8 100644 (file)
@@ -1,32 +1,23 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public final class DepTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModule
- {
-
+package org.opendaylight.controller.config.yang.test.impl;
+public class DepTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModule {
     public DepTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public DepTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
-            DepTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-
+    public DepTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.test.impl.DepTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    protected void customValidation(){
-        // Add custom validation for module attributes here.
+    public void customValidation() {
+        // add custom validation form module attributes here.
     }
 
     @Override
@@ -38,4 +29,5 @@ public final class DepTestImplModule extends org.opendaylight.controller.config.
         };
 
     }
+
 }
index c26c29ed60636f94b8dc73405cbaf7ecc948aa6b..849dd1464d1f5f756f0e82edc31ddad1adfe5746 100644 (file)
@@ -1,18 +1,20 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public class DepTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModuleFactory
-{
-
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl-dep
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Mon Mar 17 14:04:38 CET 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class DepTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractDepTestImplModuleFactory {
 
 }
index 398bba99bde6b3923028f9e20d88582a33c96454..a5b7f55df382b4b403404f168a32bfd04c8a1976 100644 (file)
@@ -1,32 +1,23 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public final class IdentityTestModule extends org.opendaylight.controller.config.yang.test.impl.AbstractIdentityTestModule
- {
-
+package org.opendaylight.controller.config.yang.test.impl;
+public class IdentityTestModule extends org.opendaylight.controller.config.yang.test.impl.AbstractIdentityTestModule {
     public IdentityTestModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public IdentityTestModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
-            IdentityTestModule oldModule, java.lang.AutoCloseable oldInstance) {
-
+    public IdentityTestModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.test.impl.IdentityTestModule oldModule, java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    protected void customValidation(){
-        // Add custom validation for module attributes here.
+    public void customValidation() {
+        // add custom validation form module attributes here.
     }
 
     @Override
@@ -49,4 +40,5 @@ public final class IdentityTestModule extends org.opendaylight.controller.config
         };
 
     }
+
 }
index 9de3e0bb7449fb770082e3aa0cdabebdb35f8266..5560b6ec3f2f12504e86a8fd005d6ccff3bf90c9 100644 (file)
@@ -1,18 +1,20 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public class IdentityTestModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractIdentityTestModuleFactory
-{
-
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl-identity-test
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Mon Mar 17 14:04:38 CET 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class IdentityTestModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractIdentityTestModuleFactory {
 
 }
index 3594ee03538f4f2bb097f319cba13a679bc39960..ecbf4aba33c436b9354f4c4abe0a674de258745c 100644 (file)
@@ -1,32 +1,23 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public final class NetconfTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModule
- {
-
+package org.opendaylight.controller.config.yang.test.impl;
+public class NetconfTestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModule {
     public NetconfTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public NetconfTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
-            NetconfTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-
+    public NetconfTestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    protected void customValidation(){
-        // Add custom validation for module attributes here.
+    public void customValidation() {
+        // add custom validation form module attributes here.
     }
 
     @Override
@@ -34,4 +25,5 @@ public final class NetconfTestImplModule extends org.opendaylight.controller.con
 return NetconfTestImplModuleUtil.registerRuntimeBeans(this);
 
     }
+
 }
index accc1db76e72cf5292a8ece54cc31fb71644ead4..b857c6211d6f787ddd539b0eed08a90054a0ba2d 100644 (file)
@@ -1,18 +1,20 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public class NetconfTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModuleFactory
-{
-
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl-netconf
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Mon Mar 17 14:04:38 CET 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class NetconfTestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractNetconfTestImplModuleFactory {
 
 }
index 9ba1db4eedc7b690499704ff6da29cb7275438d5..9132407356e8b4c52ab23610079d1d189e029c8b 100644 (file)
@@ -1,32 +1,23 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public final class TestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModule
- {
-
+package org.opendaylight.controller.config.yang.test.impl;
+public class TestImplModule extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModule {
     public TestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public TestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
-            TestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
-
+    public TestImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.test.impl.TestImplModule oldModule, java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
     @Override
-    protected void customValidation(){
-        // Add custom validation for module attributes here.
+    public void customValidation() {
+        // add custom validation form module attributes here.
     }
 
     @Override
@@ -38,4 +29,5 @@ public final class TestImplModule extends org.opendaylight.controller.config.yan
         };
 
     }
+
 }
index a6ce734f96ac83fe14c31d24b4b7e1e1b2094c5c..ae0ef6acf4841971ba1df575810a46d5e25840a5 100644 (file)
@@ -1,18 +1,20 @@
 /*
- * 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.config.yang.test.impl;
-
-/**
+* 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
 */
-public class TestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModuleFactory
-{
-
+/*
+* Generated file
+*
+* Generated from: yang module name: config-test-impl yang module local name: impl
+* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+* Generated at: Mon Mar 17 14:04:38 CET 2014
+*
+* Do not modify this file unless it is present under src/main directory
+*/
+package org.opendaylight.controller.config.yang.test.impl;
+public class TestImplModuleFactory extends org.opendaylight.controller.config.yang.test.impl.AbstractTestImplModuleFactory {
 
 }
index fc0ef32954db4df6396de30ad529cd6669b9ea4a..f3fd230d5bd36fcc80335975e57f8375c1c37285 100644 (file)
@@ -30,9 +30,6 @@
         <groupId>org.eclipse.xtend</groupId>
         <artifactId>xtend-maven-plugin</artifactId>
       </plugin>
-      <plugin>
-        <artifactId>maven-clean-plugin</artifactId>
-      </plugin>
     </plugins>
   </build>
 
index b7e193b59d76e0938ed1537b829422adc54f3d5b..aef489ec83fad1f896d64b889bb5210f6ade0381 100644 (file)
@@ -31,9 +31,6 @@
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 
index 00cbc18e7e44ae7b0a8efbbfeb332374dc7b471b..68eaa96871257416aca64274f40bd763e45c4051 100644 (file)
@@ -31,9 +31,6 @@
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 
index 362a3496574237a4b48aba49dff16fa859231e67..31621deeea9ffa5ce1d5f92752aecc76e85c4275 100644 (file)
@@ -59,9 +59,6 @@
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 </project>
index 4c8a74c62bf91a7cc30aadd1c3f07d2ce2520561..a2a526426ed3006ab30bb1f6b11f4765ebd118d3 100644 (file)
                     </dependency>
                 </dependencies>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.7</version>
-                <executions>
-                    <execution>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>target/generated-sources/sal</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
 
index a45cadab7ce76359f0dcbbba7a9612df04042f2b..631f1118c5d756d5daa2760ad1e22a6ea2200a6c 100644 (file)
                 <!--module>test/sal-rest-connector-it</modulei -->
             </modules>
         </profile>
-        <profile>
-            <id>IDE</id>
-            <activation>
-                <property>
-                    <name>m2e.version</name>
-                </property>
-            </activation>
-            <build>
-                <!-- Put the IDE's build output in a folder other than target,
-                    so that IDE builds don't interact with Maven builds -->
-                <directory>target-ide</directory>
-            </build>
-        </profile>
     </profiles>
 
     <properties>
-        <salGeneratorPath>${project.build.directory}/generated-sources/sal</salGeneratorPath>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
         <!-- Plugin Versions -->
                     <groupId>org.eclipse.xtend</groupId>
                     <artifactId>xtend-maven-plugin</artifactId>
                     <version>${xtend.version}</version>
-                    <executions>
-                        <execution>
-                            <goals>
-                                <goal>compile</goal>
-                            </goals>
-                            <configuration>
-                                <outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-clean-plugin</artifactId>
-                    <version>${maven.clean.plugin.version}</version>
-                    <configuration>
-                        <filesets>
-                            <fileset>
-                                <directory>${basedir}/src/main/xtend-gen</directory>
-                                <includes>
-                                    <include>**</include>
-                                </includes>
-                            </fileset>
-                        </filesets>
-                    </configuration>
                 </plugin>
                 <plugin>
                     <groupId>org.jacoco</groupId>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/config</source>
-                                <source>${project.build.directory}/generated-sources/sal</source>
-                                <source>src/main/xtend-gen</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
index dafb3ef6343c895385ebe99aee565e7d082182cd..9976f48114bc3c5d45c639a98f931f92382bf15c 100644 (file)
@@ -30,7 +30,7 @@
                                     <codeGeneratorClass>
                                         org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
                                     </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/config</outputBaseDir>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
                                     <additionalConfiguration>
                                         <namespaceToPackage1>
                                             urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
                 </dependencies>
             </plugin>
 
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-
-
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/config</source>
-                                <source>src/main/xtend-gen</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
index 4f9c429e503da20ba4f7308fea81b5f061cb71ca..6334457fd4961ae34d913fb9138a8313f6eb30b1 100644 (file)
@@ -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<T extends AsyncTransaction<org.openday
                 .toNormalizedNode(path, data);
 
         org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalizedPath = normalized.getKey();
-        try {
-            List<PathArgument> currentArguments = new ArrayList<>();
-            DataNormalizationOperation<?> currentOp = codec.getDataNormalizer().getRootOperation();
-            Iterator<PathArgument> iterator = normalizedPath.getPath().iterator();
-            while (iterator.hasNext()) {
-                PathArgument currentArg = iterator.next();
+        List<PathArgument> currentArguments = new ArrayList<>();
+        DataNormalizationOperation<?> currentOp = codec.getDataNormalizer().getRootOperation();
+        Iterator<PathArgument> 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<NormalizedNode<?, ?>> 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/codegen/RuntimeCodeHelper.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.java
new file mode 100644 (file)
index 0000000..ea8b6c0
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * 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.sal.binding.codegen;
+
+import com.google.common.base.Objects;
+import java.lang.reflect.Field;
+import java.util.Map;
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+
+@SuppressWarnings("all")
+public class RuntimeCodeHelper {
+  /**
+   * Helper method to return delegate from ManagedDirectedProxy with use of reflection.
+   *
+   * Note: This method uses reflection, but access to delegate field should be
+   * avoided and called only if neccessary.
+   */
+  public static <T extends RpcService> T getDelegate(final RpcService proxy) {
+    try {
+      Class<? extends RpcService> _class = proxy.getClass();
+      final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD);
+      boolean _equals = Objects.equal(field, null);
+      if (_equals) {
+        UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to get delegate from proxy");
+        throw _unsupportedOperationException;
+      }
+      try {
+        Object _get = field.get(proxy);
+        return ((T) _get);
+      } catch (Throwable _e) {
+        throw Exceptions.sneakyThrow(_e);
+      }
+    } catch (Throwable _e_1) {
+      throw Exceptions.sneakyThrow(_e_1);
+    }
+  }
+
+  /**
+   * Helper method to set delegate to ManagedDirectedProxy with use of reflection.
+   *
+   * Note: This method uses reflection, but setting delegate field should not occur too much
+   * to introduce any significant performance hits.
+   */
+  public static void setDelegate(final RpcService proxy, final RpcService delegate) {
+    try {
+      Class<? extends RpcService> _class = proxy.getClass();
+      final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD);
+      boolean _equals = Objects.equal(field, null);
+      if (_equals) {
+        UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to set delegate to proxy");
+        throw _unsupportedOperationException;
+      }
+      boolean _or = false;
+      boolean _equals_1 = Objects.equal(delegate, null);
+      if (_equals_1) {
+        _or = true;
+      } else {
+        Class<? extends Object> _type = field.getType();
+        Class<? extends RpcService> _class_1 = delegate.getClass();
+        boolean _isAssignableFrom = _type.isAssignableFrom(_class_1);
+        _or = (_equals_1 || _isAssignableFrom);
+      }
+      if (_or) {
+        field.set(proxy, delegate);
+      } else {
+        IllegalArgumentException _illegalArgumentException = new IllegalArgumentException("delegate class is not assignable to proxy");
+        throw _illegalArgumentException;
+      }
+    } catch (Throwable _e) {
+      throw Exceptions.sneakyThrow(_e);
+    }
+  }
+
+  /**
+   * Helper method to set delegate to ManagedDirectedProxy with use of reflection.
+   *
+   * Note: This method uses reflection, but setting delegate field should not occur too much
+   * to introduce any significant performance hits.
+   */
+  public static void setDelegate(final Object proxy, final Object delegate) {
+    try {
+      Class<? extends Object> _class = proxy.getClass();
+      final Field field = _class.getField(RuntimeCodeSpecification.DELEGATE_FIELD);
+      boolean _equals = Objects.equal(field, null);
+      if (_equals) {
+        UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException("Unable to set delegate to proxy");
+        throw _unsupportedOperationException;
+      }
+      boolean _or = false;
+      boolean _equals_1 = Objects.equal(delegate, null);
+      if (_equals_1) {
+        _or = true;
+      } else {
+        Class<? extends Object> _type = field.getType();
+        Class<? extends Object> _class_1 = delegate.getClass();
+        boolean _isAssignableFrom = _type.isAssignableFrom(_class_1);
+        _or = (_equals_1 || _isAssignableFrom);
+      }
+      if (_or) {
+        field.set(proxy, delegate);
+      } else {
+        IllegalArgumentException _illegalArgumentException = new IllegalArgumentException("delegate class is not assignable to proxy");
+        throw _illegalArgumentException;
+      }
+    } catch (Throwable _e) {
+      throw Exceptions.sneakyThrow(_e);
+    }
+  }
+
+  public static Map<InstanceIdentifier<? extends Object>,? extends RpcService> getRoutingTable(final RpcService target, final Class<? extends BaseIdentity> tableClass) {
+    try {
+      Class<? extends RpcService> _class = target.getClass();
+      String _routingTableField = RuntimeCodeSpecification.getRoutingTableField(tableClass);
+      final Field field = _class.getField(_routingTableField);
+      boolean _equals = Objects.equal(field, null);
+      if (_equals) {
+        UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException(
+          "Unable to get routing table. Table field does not exists");
+        throw _unsupportedOperationException;
+      }
+      try {
+        Object _get = field.get(target);
+        return ((Map<InstanceIdentifier<? extends Object>,? extends RpcService>) _get);
+      } catch (Throwable _e) {
+        throw Exceptions.sneakyThrow(_e);
+      }
+    } catch (Throwable _e_1) {
+      throw Exceptions.sneakyThrow(_e_1);
+    }
+  }
+
+  public static void setRoutingTable(final RpcService target, final Class<? extends BaseIdentity> tableClass, final Map<InstanceIdentifier<? extends Object>,? extends RpcService> routingTable) {
+    try {
+      Class<? extends RpcService> _class = target.getClass();
+      String _routingTableField = RuntimeCodeSpecification.getRoutingTableField(tableClass);
+      final Field field = _class.getField(_routingTableField);
+      boolean _equals = Objects.equal(field, null);
+      if (_equals) {
+        UnsupportedOperationException _unsupportedOperationException = new UnsupportedOperationException(
+          "Unable to set routing table. Table field does not exists");
+        throw _unsupportedOperationException;
+      }
+      field.set(target, routingTable);
+    } catch (Throwable _e) {
+      throw Exceptions.sneakyThrow(_e);
+    }
+  }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend
deleted file mode 100644 (file)
index dff0d21..0000000
+++ /dev/null
@@ -1,81 +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.sal.binding.codegen
-
-import java.util.Map
-
-import org.opendaylight.yangtools.yang.binding.BaseIdentity
-import org.opendaylight.yangtools.yang.binding.RpcService
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-
-import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification.*
-
-class RuntimeCodeHelper {
-    /**
-     * Helper method to return delegate from ManagedDirectedProxy with use of reflection.
-     * 
-     * Note: This method uses reflection, but access to delegate field should be 
-     * avoided and called only if neccessary.
-     * 
-     */
-    public static def <T extends RpcService> getDelegate(RpcService proxy) {
-        val field = proxy.class.getField(DELEGATE_FIELD)
-        if (field == null) throw new UnsupportedOperationException("Unable to get delegate from proxy");
-        return field.get(proxy) as T
-    }
-
-    /**
-     * Helper method to set delegate to ManagedDirectedProxy with use of reflection.
-     * 
-     * Note: This method uses reflection, but setting delegate field should not occur too much
-     * to introduce any significant performance hits.
-     * 
-     */
-    public static def void setDelegate(RpcService proxy, RpcService delegate) {
-        val field = proxy.class.getField(DELEGATE_FIELD)
-        if (field == null) throw new UnsupportedOperationException("Unable to set delegate to proxy");
-        if (delegate == null || field.type.isAssignableFrom(delegate.class)) {
-            field.set(proxy, delegate)
-        } else
-            throw new IllegalArgumentException("delegate class is not assignable to proxy");
-    }
-    
-        /**
-     * Helper method to set delegate to ManagedDirectedProxy with use of reflection.
-     * 
-     * Note: This method uses reflection, but setting delegate field should not occur too much
-     * to introduce any significant performance hits.
-     * 
-     */
-    public static def void setDelegate(Object proxy, Object delegate) {
-        val field = proxy.class.getField(DELEGATE_FIELD)
-        if (field == null) throw new UnsupportedOperationException("Unable to set delegate to proxy");
-        if (delegate == null || field.type.isAssignableFrom(delegate.class)) {
-            field.set(proxy, delegate)
-        } else
-            throw new IllegalArgumentException("delegate class is not assignable to proxy");
-    }
-    
-
-    public static def Map<InstanceIdentifier<?>, ? extends RpcService> getRoutingTable(RpcService target,
-        Class<? extends BaseIdentity> tableClass) {
-        val field = target.class.getField(tableClass.routingTableField)
-        if (field == null) throw new UnsupportedOperationException(
-            "Unable to get routing table. Table field does not exists");
-        return field.get(target) as Map<InstanceIdentifier<? extends Object>, ? extends RpcService>;
-    }
-
-    public static def void setRoutingTable(RpcService target, Class<? extends BaseIdentity> tableClass,
-        Map<InstanceIdentifier<?>, ? extends RpcService> routingTable) {
-         val field = target.class.getField(tableClass.routingTableField)
-        if (field == null) throw new UnsupportedOperationException(
-            "Unable to set routing table. Table field does not exists");
-        field.set(target,routingTable);
-    }
-
-}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java
new file mode 100644 (file)
index 0000000..0bc11d9
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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.sal.binding.codegen;
+
+import java.lang.reflect.Method;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+@SuppressWarnings("all")
+public class YangtoolsMappingHelper {
+  public static boolean isNotificationCallback(final Method it) {
+      return it.getName().startsWith("on") && (it.getParameterTypes().length == 1) &&
+              Notification.class.isAssignableFrom(it.getParameterTypes()[0]);
+  }
+
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.xtend
deleted file mode 100644 (file)
index 18d3e26..0000000
+++ /dev/null
@@ -1,19 +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.sal.binding.codegen
-
-import java.lang.reflect.Method
-import org.opendaylight.yangtools.yang.binding.Notification
-
-public static class YangtoolsMappingHelper {
-
-    public static def boolean isNotificationCallback(Method it) {
-        return name.startsWith("on") && parameterTypes.size === 1 &&
-            Notification.isAssignableFrom(parameterTypes.get(0))
-    }
-}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/BrokerImplClassLoader.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/BrokerImplClassLoader.java
new file mode 100644 (file)
index 0000000..cab4fe9
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.sal.binding.codegen.impl;
+
+import org.eclipse.xtext.xbase.lib.Exceptions;
+
+@SuppressWarnings("all")
+public class BrokerImplClassLoader extends ClassLoader {
+  private final ClassLoader spiClassLoader;
+
+  public BrokerImplClassLoader(final ClassLoader model, final ClassLoader spi) {
+    super(model);
+    this.spiClassLoader = spi;
+  }
+
+  public Class<? extends Object> loadClass(final String name) throws ClassNotFoundException {
+    try {
+      return super.loadClass(name);
+    } catch (ClassNotFoundException e) {
+        return this.spiClassLoader.loadClass(name);
+    }
+  }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/BrokerImplClassLoader.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/BrokerImplClassLoader.xtend
deleted file mode 100644 (file)
index 6481c9d..0000000
+++ /dev/null
@@ -1,29 +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.sal.binding.codegen.impl
-
-import java.lang.ClassLoader
-
-class BrokerImplClassLoader extends ClassLoader {
-
-    val ClassLoader spiClassLoader
-    
-    public new(ClassLoader model, ClassLoader spi) {
-        super(model)
-        spiClassLoader = spi;
-    }
-
-    override public loadClass(String name) throws ClassNotFoundException {
-        try {
-            return super.loadClass(name);
-        } catch (ClassNotFoundException e) {
-            return spiClassLoader.loadClass(name);
-        }
-    }
-
-}
index fe2681f1f768ab6c1f607550d2c637cda1297d4e..6d675b4b5eb5f546b1a7fd7743d301fb62a56f0b 100644 (file)
@@ -60,7 +60,7 @@ class NotificationBrokerImpl implements NotificationProviderService, AutoCloseab
     override publish(Notification notification, ExecutorService service) {\r
         val allTypes = notification.notificationTypes\r
 \r
-        var Iterable<NotificationListener<?>> listenerToNotify = Collections.emptySet();\r
+        var Iterable<NotificationListener<? extends Object>> listenerToNotify = Collections.emptySet();\r
         for (type : allTypes) {\r
             listenerToNotify = listenerToNotify + listeners.get(type as Class<? extends Notification>)\r
         }\r
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.java
new file mode 100644 (file)
index 0000000..3b6a253
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.sal.binding.impl;
+
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.osgi.framework.ServiceRegistration;
+
+@SuppressWarnings("all")
+public class RpcProxyContext {
+  public RpcProxyContext(final Class<? extends RpcService> proxyClass) {
+    this.proxyClass = proxyClass;
+  }
+
+  protected final Class<? extends RpcService> proxyClass;
+
+  protected RpcService _proxy;
+
+  public RpcService getProxy() {
+    return this._proxy;
+  }
+
+  public void setProxy(final RpcService proxy) {
+    this._proxy = proxy;
+  }
+
+  protected ServiceRegistration<? extends RpcService> _registration;
+
+  public ServiceRegistration<? extends RpcService> getRegistration() {
+    return this._registration;
+  }
+
+  public void setRegistration(final ServiceRegistration<? extends RpcService> registration) {
+    this._registration = registration;
+  }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProxyContext.xtend
deleted file mode 100644 (file)
index 0749459..0000000
+++ /dev/null
@@ -1,26 +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.sal.binding.impl
-
-import org.opendaylight.yangtools.yang.binding.RpcService
-import org.osgi.framework.ServiceRegistration
-
-class RpcProxyContext {
-       
-       new(Class<? extends RpcService> proxyClass) {
-               this.proxyClass = proxyClass
-       }
-       
-       protected val Class<? extends RpcService> proxyClass;
-       
-       @Property
-       protected var RpcService proxy;
-       
-       @Property
-       protected var ServiceRegistration<? extends RpcService> registration;
-}
\ No newline at end of file
index 9edea0c2fd59fb9f50b94551fbf5574a174a2a07..93849c2e91f47142f71d7cd1fb55cf3d1a506152 100644 (file)
@@ -91,6 +91,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class BindingIndependentConnector implements //
         RuntimeDataProvider, //
@@ -699,8 +700,9 @@ public class BindingIndependentConnector implements //
             }
         }
 
+
         @Override
-        public RpcResult<CompositeNode> invokeRpc(final QName rpc, final CompositeNode domInput) {
+        public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(final QName rpc, final CompositeNode domInput) {
             checkArgument(rpc != null);
             checkArgument(domInput != null);
 
@@ -709,10 +711,11 @@ public class BindingIndependentConnector implements //
             RpcService rpcService = baRpcRegistry.getRpcService(rpcType);
             checkState(rpcService != null);
             CompositeNode domUnwrappedInput = domInput.getFirstCompositeByName(QName.create(rpc, "input"));
+
             try {
-                return resolveInvocationStrategy(rpc).invokeOn(rpcService, domUnwrappedInput);
+                return Futures.immediateFuture(resolveInvocationStrategy(rpc).invokeOn(rpcService, domUnwrappedInput));
             } catch (Exception e) {
-                throw new IllegalStateException(e);
+                return Futures.immediateFailedFuture(e);
             }
         }
 
@@ -813,21 +816,25 @@ public class BindingIndependentConnector implements //
         }
 
         @Override
-        public Future<RpcResult<?>> forwardToDomBroker(final DataObject input) {
-            if(biRpcRegistry != null) {
-                CompositeNode xml = mappingService.toDataDom(input);
-                CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc, ImmutableList.<Node<?>> of(xml));
-                RpcResult<CompositeNode> result = biRpcRegistry.invokeRpc(rpc, wrappedXml);
-                Object baResultValue = null;
-                if (result.getResult() != null) {
-                    baResultValue = mappingService.dataObjectFromDataDom(outputClass.get(), result.getResult());
-                }
-                RpcResult<?> baResult = Rpcs.getRpcResult(result.isSuccessful(), baResultValue, result.getErrors());
-                return Futures.<RpcResult<?>> immediateFuture(baResult);
+        public ListenableFuture<RpcResult<?>> forwardToDomBroker(final DataObject input) {
+            if(biRpcRegistry == null) {
+                return Futures.<RpcResult<?>> immediateFuture(Rpcs.getRpcResult(false));
             }
-            return Futures.<RpcResult<?>> immediateFuture(Rpcs.getRpcResult(false));
-        }
 
+            CompositeNode xml = mappingService.toDataDom(input);
+            CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc, ImmutableList.<Node<?>> of(xml));
+
+            return Futures.transform(biRpcRegistry.invokeRpc(rpc, wrappedXml), new Function<RpcResult<CompositeNode>, RpcResult<?>>() {
+                @Override
+                public RpcResult<?> apply(RpcResult<CompositeNode> input) {
+                    Object baResultValue = null;
+                    if (input.getResult() != null) {
+                        baResultValue = mappingService.dataObjectFromDataDom(outputClass.get(), input.getResult());
+                    }
+                    return Rpcs.getRpcResult(input.isSuccessful(), baResultValue, input.getErrors());
+                }
+            });
+        }
     }
 
     private class NoInputNoOutputInvocationStrategy extends RpcInvocationStrategy {
@@ -876,18 +883,21 @@ public class BindingIndependentConnector implements //
         }
 
         @Override
-        public Future<RpcResult<?>> forwardToDomBroker(final DataObject input) {
-            if(biRpcRegistry != null) {
-                CompositeNode xml = mappingService.toDataDom(input);
-                CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc,ImmutableList.<Node<?>>of(xml));
-                RpcResult<CompositeNode> result = biRpcRegistry.invokeRpc(rpc, wrappedXml);
-                Object baResultValue = null;
-                RpcResult<?> baResult = Rpcs.<Void>getRpcResult(result.isSuccessful(), null, result.getErrors());
-                return Futures.<RpcResult<?>>immediateFuture(baResult);
+        public ListenableFuture<RpcResult<?>> forwardToDomBroker(final DataObject input) {
+            if(biRpcRegistry == null) {
+                return Futures.<RpcResult<?>> immediateFuture(Rpcs.getRpcResult(false));
             }
-            return Futures.<RpcResult<?>>immediateFuture(Rpcs.getRpcResult(false));
-        }
 
+            CompositeNode xml = mappingService.toDataDom(input);
+            CompositeNode wrappedXml = ImmutableCompositeNode.create(rpc,ImmutableList.<Node<?>>of(xml));
+
+            return Futures.transform(biRpcRegistry.invokeRpc(rpc, wrappedXml), new Function<RpcResult<CompositeNode>, RpcResult<?>>() {
+                @Override
+                public RpcResult<?> apply(RpcResult<CompositeNode> input) {
+                    return Rpcs.<Void>getRpcResult(input.isSuccessful(), null, input.getErrors());
+                }
+            });
+        }
     }
 
     public boolean isRpcForwarding() {
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/BindingAwareDataReaderRouter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/BindingAwareDataReaderRouter.java
new file mode 100644 (file)
index 0000000..b031663
--- /dev/null
@@ -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.sal.binding.impl.util;
+
+import java.util.Iterator;
+import org.opendaylight.controller.md.sal.common.impl.routing.AbstractDataReadRouter;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+@SuppressWarnings("all")
+public class BindingAwareDataReaderRouter extends AbstractDataReadRouter<InstanceIdentifier<? extends DataObject>,DataObject> {
+  protected DataObject merge(final InstanceIdentifier<? extends DataObject> path, final Iterable<DataObject> data) {
+    return data.iterator().next();
+  }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/BindingAwareDataReaderRouter.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/BindingAwareDataReaderRouter.xtend
deleted file mode 100644 (file)
index 5b77580..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * 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.sal.binding.impl.util
-
-import org.opendaylight.controller.md.sal.common.impl.routing.AbstractDataReadRouter
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.DataObject
-
-class BindingAwareDataReaderRouter extends AbstractDataReadRouter<InstanceIdentifier<? extends DataObject>, DataObject> {
-    
-    override protected merge(InstanceIdentifier<? extends DataObject> path, Iterable<DataObject> data) {
-        return data.iterator.next;
-    }
-    
-}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/MapUtils.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/MapUtils.java
new file mode 100644 (file)
index 0000000..aa6a9a2
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.sal.binding.impl.util;
+
+import com.google.common.collect.Multimap;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import org.opendaylight.yangtools.concepts.Path;
+
+@SuppressWarnings("all")
+public class MapUtils {
+  public static <P extends Path<P>, V extends Object> Collection<Entry<? extends P,? extends V>> getAllChildren(final Multimap<? extends P,? extends V> map, final P path) {
+    HashSet<Entry<? extends P,? extends V>> _hashSet = new HashSet<Entry<? extends P, ? extends V>>();
+    final HashSet<Entry<? extends P,? extends V>> ret = _hashSet;
+    final Collection<? extends Entry<? extends P,? extends V>> entries = map.entries();
+    for (final Entry<? extends P,? extends V> entry : entries) {
+      {
+        final P currentPath = entry.getKey();
+        if (path.contains(currentPath)) {
+          ret.add(entry);
+        } else if (currentPath.contains(path)){
+            ret.add(entry);
+        }
+      }
+    }
+    return ret;
+  }
+}
+
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/MapUtils.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/MapUtils.xtend
deleted file mode 100644 (file)
index c60686d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.sal.binding.impl.util
-
-import com.google.common.collect.Multimap
-import java.util.Collection
-import java.util.HashSet
-import java.util.Map.Entry
-import org.opendaylight.yangtools.concepts.Path
-
-class MapUtils {
-
-    public static def <P extends Path<P>, V> Collection<Entry<? extends P, ? extends V>> getAllChildren(
-        Multimap<? extends P, ? extends V> map, P path) {
-        val ret = new HashSet();
-        val entries = map.entries;
-
-        for (entry : entries) {
-            val currentPath = entry.key;
-            // If the registered reader processes nested elements
-            if (path.contains(currentPath)) {
-                ret.add(entry);
-            } else if(currentPath.contains(path)) {
-                // If the registered reader is parent of entry
-                ret.add(entry);
-            }
-        }
-
-        return ret;
-    }
-}
index 4bad2bbb86140a5f04ac6a704b84e0b314cad76b..d6d87bac84b307d388147cc3bd44c0346b5afa77 100644 (file)
@@ -351,7 +351,6 @@ public class BindingTestContext implements AutoCloseable, SchemaContextProvider
     private void startDomBroker() {
         checkState(executor != null);
         biBrokerImpl = new BrokerImpl();
-        biBrokerImpl.setExecutor(executor);
         biBrokerImpl.setRouter(new SchemaAwareRpcBroker("/", this));
 
     }
index 145dc37552329335fcb4e6198fe70ff302f7f560..f75995dc2265fc2edb94d654310cea4b7b965e5d 100644 (file)
@@ -43,7 +43,7 @@
                                     <codeGeneratorClass>
                                         org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
                                     </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/config</outputBaseDir>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
                                     <additionalConfiguration>
                                         <namespaceToPackage1>
                                             urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
                     </dependency>
                 </dependencies>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/config</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
 
index 82e3d975720ee97d7ba4e9b1451b82a620b47d02..94832c14b6e695f4eeaf2615e9127c201ead2434 100644 (file)
@@ -19,9 +19,6 @@
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
index b1547b66a763d690aee4aee76226bf9659d7ac53..ca38ed0797e1f1d0433a2281a2763672d1d19300 100644 (file)
@@ -50,6 +50,7 @@ import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 
 public class CrossBrokerRpcTest {
@@ -64,7 +65,7 @@ public class CrossBrokerRpcTest {
     public static final NodeId NODE_B = new NodeId("b");
     public static final NodeId NODE_C = new NodeId("c");
     public static final NodeId NODE_D = new NodeId("d");
-    
+
     private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "id");
     private static final QName ADD_FLOW_QNAME = QName.create(NodeFlowRemoved.QNAME, "add-flow");
 
@@ -78,7 +79,7 @@ public class CrossBrokerRpcTest {
     public static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier BI_NODE_C_ID = createBINodeIdentifier(NODE_C);
     public static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier BI_NODE_D_ID = createBINodeIdentifier(NODE_D);
 
-    
+
 
     @Before
     public void setup() {
@@ -99,7 +100,7 @@ public class CrossBrokerRpcTest {
     }
 
     @Test
-    public void bindingRoutedRpcProvider_DomInvokerTest() {
+    public void bindingRoutedRpcProvider_DomInvokerTest() throws Exception {
 
         flowService//
                 .registerPath(NodeContext.class, BA_NODE_A_ID) //
@@ -114,7 +115,7 @@ public class CrossBrokerRpcTest {
 
         CompositeNode addFlowDom = toDomRpc(ADD_FLOW_QNAME, addFlowA);
         assertNotNull(addFlowDom);
-        RpcResult<CompositeNode> domResult = biRpcInvoker.invokeRpc(ADD_FLOW_QNAME, addFlowDom);
+        RpcResult<CompositeNode> domResult = biRpcInvoker.invokeRpc(ADD_FLOW_QNAME, addFlowDom).get();
         assertNotNull(domResult);
         assertTrue("DOM result is successful.", domResult.isSuccessful());
         assertTrue("Bidning Add Flow RPC was captured.", flowService.getReceivedAddFlows().containsKey(BA_NODE_A_ID));
@@ -128,18 +129,18 @@ public class CrossBrokerRpcTest {
         final AddFlowOutput output = builder.build();
         org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration registration = biRpcRegistry.addRoutedRpcImplementation(ADD_FLOW_QNAME, new RpcImplementation() {
             @Override
-            public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
-                CompositeNode result = testContext.getBindingToDomMappingService().toDataDom(output);
-                return Rpcs.getRpcResult(true, result, ImmutableList.<RpcError>of());
+            public Set<QName> getSupportedRpcs() {
+                return ImmutableSet.of(ADD_FLOW_QNAME);
             }
 
             @Override
-            public Set<QName> getSupportedRpcs() {
-                return ImmutableSet.of(ADD_FLOW_QNAME);
+            public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
+                CompositeNode result = testContext.getBindingToDomMappingService().toDataDom(output);
+                return Futures.immediateFuture(Rpcs.getRpcResult(true, result, ImmutableList.<RpcError>of()));
             }
         });
         registration.registerPath(NodeContext.QNAME, BI_NODE_C_ID);
-        
+
         SalFlowService baFlowInvoker = baRpcRegistry.getRpcService(SalFlowService.class);
         Future<RpcResult<AddFlowOutput>> baResult = baFlowInvoker.addFlow(addFlow(BA_NODE_C_ID).setPriority(500).build());
         assertNotNull(baResult);
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 (file)
index 0000000..f7a15b6
--- /dev/null
@@ -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);
+       }
+}
index 941f2fdb39059950a5d3ae910848a282c7c3311a..1055fa81fde264b1949217b0ca860dac945918d8 100644 (file)
@@ -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<T extends PathArgument> 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<T extends PathArgument> impleme
 
             Set<DataNormalizationOperation<?>> 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<T extends PathArgument> 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<T extends PathArgument> 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<T extends PathArgument> 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<T extends PathArgument> 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<org.opendaylight.yangtools.yang.model.api.ChoiceNode> 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<T extends PathArgument> 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());
index 28b2bde26d31e4558b5f716666147983446811cc..e1fc3c3cdb200b3c79a2e72b4d96abd03ca0572c 100644 (file)
@@ -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<PathArgument> 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<PathArgument> reworkedArgs = new ArrayList<>(normalizedPath.getPath());
index 15932d56cedf1df6cc76ca35a323bcd28cdc8992..181fc5c0c5ba3a3f9bb72327c910ebd3aa2036da 100644 (file)
@@ -33,7 +33,7 @@
                                     <codeGeneratorClass>
                                         org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
                                     </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/config</outputBaseDir>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
                                     <additionalConfiguration>
                                         <namespaceToPackage1>
                                             urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
                     </dependency>
                 </dependencies>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/config</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
     <dependencies>
index c8eb7fd56f1f68654a14785e5a5f81121e47a692..4f11ba066110be3f73d855a5c4871195fc47306c 100644 (file)
@@ -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.sal.core.api;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -5,8 +12,10 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
+import com.google.common.util.concurrent.ListenableFuture;
+
 public interface RoutedRpcDefaultImplementation {
 
-  public RpcResult<CompositeNode> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input);
+    ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input);
 
 }
index 6b1030a81500f5a909d6df30f69e52208025c482..38b33d5d2a509f228a3fcc88a28c3b4f64a11dad 100644 (file)
@@ -15,6 +15,8 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
+import com.google.common.util.concurrent.ListenableFuture;
+
 /**
  * {@link Provider}'s implementation of an RPC.
  *
@@ -42,8 +44,6 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
  * {@link RpcResult}
  * <li> {@link Broker} returns the {@link RpcResult} to {@link Consumer}
  * </ol>
- *
- *
  */
 public interface RpcImplementation extends Provider.ProviderFunctionality {
 
@@ -59,13 +59,12 @@ public interface RpcImplementation extends Provider.ProviderFunctionality {
     Set<QName> getSupportedRpcs();
 
     /**
-     * Invokes a implementation of specified rpc.
-     *
+     * Invokes a implementation of specified RPC asynchronously.
      *
      * @param rpc
-     *            Rpc to be invoked
+     *            RPC to be invoked
      * @param input
-     *            Input data for rpc.
+     *            Input data for the RPC.
      *
      * @throws IllegalArgumentException
      *             <ul>
@@ -73,9 +72,9 @@ public interface RpcImplementation extends Provider.ProviderFunctionality {
      *             <li>If input is not <code>null</code> and
      *             <code>false == rpc.equals(input.getNodeType)</code>
      *             </ul>
-     * @return RpcResult containing the output of rpc if was executed
-     *         successfully, the list of errors otherwise.
+     * @return Future promising an RpcResult containing the output of
+     *         the RPC if was executed successfully, the list of errors
+     *         otherwise.
      */
-    RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input);
-
+    ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input);
 }
index 5063e4339b6d013014064ac2057b6e05683423ba..360988fbb2fa5ec186d65c757ac325d808a5c16c 100644 (file)
@@ -84,7 +84,7 @@
                                     <codeGeneratorClass>
                                         org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
                                     </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/config</outputBaseDir>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
                                     <additionalConfiguration>
                                         <namespaceToPackage1>
                                             urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
                     </instructions>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/config</source>
-                                <source>src/main/xtend-gen</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
             <plugin>
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
index fce24945549e9bf4c36cd7815216f550b5dc40b7..b905d2f673d77e01a4b8ee56cd0ca09ffddc14c8 100644 (file)
@@ -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<T extends DOMDataReadTransa
             Iterator<PathArgument> 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();
index 64de8683d1d1a8a5c3854aa5f55e6b907852c448..0ed14c1027905f22fff667201d5a3294ed6afc56 100644 (file)
@@ -7,13 +7,11 @@
  */
 package org.opendaylight.controller.sal.dom.broker;
 
+import com.google.common.util.concurrent.ListenableFuture
 import java.util.Collections
 import java.util.HashSet
 import java.util.Set
-import java.util.concurrent.Callable
-import java.util.concurrent.ExecutorService
-import java.util.concurrent.Executors
-import java.util.concurrent.Future
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener
 import org.opendaylight.controller.sal.core.api.Broker
 import org.opendaylight.controller.sal.core.api.Consumer
 import org.opendaylight.controller.sal.core.api.Provider
@@ -26,7 +24,6 @@ import org.opendaylight.controller.sal.dom.broker.spi.RpcRouter
 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener
 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry
 import org.opendaylight.controller.sal.core.api.RpcImplementation
-import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener
 import org.opendaylight.controller.sal.core.api.RpcRoutingContext
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
 import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation
@@ -39,12 +36,9 @@ public class BrokerImpl implements Broker, RpcProvisionRegistry, AutoCloseable {
     private val Set<ProviderContextImpl> providerSessions = Collections.synchronizedSet(
         new HashSet<ProviderContextImpl>());
 
-    // Implementation specific
-    @Property
-    private var ExecutorService executor = Executors.newFixedThreadPool(5);
     @Property
     private var BundleContext bundleContext;
-    
+
     @Property
     private var AutoCloseable deactivator;
 
@@ -69,9 +63,8 @@ public class BrokerImpl implements Broker, RpcProvisionRegistry, AutoCloseable {
         return session;
     }
 
-    protected def Future<RpcResult<CompositeNode>> invokeRpcAsync(QName rpc, CompositeNode input) {
-        val result = executor.submit([|router.invokeRpc(rpc, input)] as Callable<RpcResult<CompositeNode>>);
-        return result;
+    protected def ListenableFuture<RpcResult<CompositeNode>> invokeRpcAsync(QName rpc, CompositeNode input) {
+        return router.invokeRpc(rpc, input);
     }
 
     // Validation
@@ -111,15 +104,15 @@ public class BrokerImpl implements Broker, RpcProvisionRegistry, AutoCloseable {
         sessions.remove(consumerContextImpl);
         providerSessions.remove(consumerContextImpl);
     }
-    
+
     override close() throws Exception {
         deactivator?.close();
     }
-    
+
     override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
         router.addRpcImplementation(rpcType,implementation);
     }
-    
+
     override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
         router.addRoutedRpcImplementation(rpcType,implementation);
     }
@@ -131,17 +124,17 @@ public class BrokerImpl implements Broker, RpcProvisionRegistry, AutoCloseable {
     override addRpcRegistrationListener(RpcRegistrationListener listener) {
         return router.addRpcRegistrationListener(listener);
     }
-    
+
     override <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> registerRouteChangeListener(L listener) {
         return router.registerRouteChangeListener(listener);
     }
 
-    override invokeRpc(QName rpc,CompositeNode input){
-        return router.invokeRpc(rpc,input)
-    }
-
     override getSupportedRpcs() {
         return router.getSupportedRpcs();
     }
-    
+
+    override invokeRpc(QName rpc, CompositeNode input) {
+        return router.invokeRpc(rpc,input)
+    }
+
 }
index f9f977e3c24d67abe809ce2f3648df5f63960d83..263f0500fd1c280b470171352716c70b723c18c7 100644 (file)
@@ -123,9 +123,8 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv
         return rpcs.getSupportedRpcs();
     }
 
-
     @Override
-    public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
+    public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
         return rpcs.invokeRpc(rpc, input);
     }
 
@@ -134,7 +133,6 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv
         return rpcs.addRpcRegistrationListener(listener);
     }
 
-
     @Override
     public ListenableFuture<RpcResult<CompositeNode>> rpc(QName type, CompositeNode input) {
         return null;
@@ -228,6 +226,4 @@ public class MountPointImpl implements MountProvisionInstance, SchemaContextProv
             L listener) {
         return rpcs.registerRouteChangeListener(listener);
     }
-
-
 }
index 598361c3ae3cbf7e41eed5a69ea9cf0d74727702..3e7b115f11e28667114c798062bd4737cda9f333 100644 (file)
@@ -46,6 +46,7 @@ import com.google.common.base.Optional;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class SchemaAwareRpcBroker implements RpcRouter, Identifiable<String>, RoutedRpcDefaultImplementation {
 
@@ -85,16 +86,16 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable<String>, Ro
         this.schemaProvider = schemaProvider;
     }
 
-  public RoutedRpcDefaultImplementation getRoutedRpcDefaultDelegate() {
-    return defaultDelegate;
-  }
+    public RoutedRpcDefaultImplementation getRoutedRpcDefaultDelegate() {
+        return defaultDelegate;
+    }
 
     @Override
-  public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultDelegate) {
-    this.defaultDelegate = defaultDelegate;
-  }
+    public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultDelegate) {
+        this.defaultDelegate = defaultDelegate;
+    }
 
-  @Override
+    @Override
     public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
         checkArgument(rpcType != null, "RPC Type should not be null");
         checkArgument(implementation != null, "RPC Implementatoin should not be null");
@@ -163,7 +164,7 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable<String>, Ro
     }
 
     @Override
-    public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
+    public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
         return findRpcImplemention(rpc).invokeRpc(rpc, input);
     }
 
@@ -235,7 +236,7 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable<String>, Ro
     }
 
     @Override
-    public RpcResult<CompositeNode> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) {
+    public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) {
       checkState(defaultDelegate != null);
       return defaultDelegate.invokeRpc(rpc, identifier, input);
     }
@@ -319,7 +320,7 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable<String>, Ro
         }
 
         @Override
-        public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
+        public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
             CompositeNode inputContainer = input.getFirstCompositeByName(QName.create(rpc,"input"));
             checkArgument(inputContainer != null, "Rpc payload must contain input element");
             SimpleNode<?> routeContainer = inputContainer.getFirstSimpleByName(strategy.getLeaf());
index 40842c004a2779ede0d231b2fef122920bc4ebc9..6e44cba494eda0d29d333ba89492aea18cba55f6 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.controller.sal.dom.broker.osgi;
 
+import java.util.Set;
+
 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
 import org.opendaylight.controller.sal.core.api.*;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
@@ -17,7 +19,7 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.osgi.framework.ServiceReference;
 
-import java.util.Set;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class RpcProvisionRegistryProxy extends AbstractBrokerServiceProxy<RpcProvisionRegistry>
                                        implements RpcProvisionRegistry {
@@ -41,24 +43,23 @@ public class RpcProvisionRegistryProxy extends AbstractBrokerServiceProxy<RpcPro
         return getDelegate().addRoutedRpcImplementation(rpcType, implementation);
     }
 
-  @Override
-  public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) {
-    getDelegate().setRoutedRpcDefaultDelegate(defaultImplementation);
-  }
+    @Override
+    public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) {
+        getDelegate().setRoutedRpcDefaultDelegate(defaultImplementation);
+    }
 
-  @Override
+    @Override
     public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(L listener) {
         return getDelegate().registerRouteChangeListener(listener);
     }
 
+    @Override
+    public Set<QName> getSupportedRpcs() {
+        return getDelegate().getSupportedRpcs();
+    }
 
-  @Override
-  public Set<QName> getSupportedRpcs() {
-    return getDelegate().getSupportedRpcs();
-  }
-
-  @Override
-  public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
-    return getDelegate().invokeRpc(rpc,input);
-  }
+    @Override
+    public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
+        return getDelegate().invokeRpc(rpc, input);
+    }
 }
index 02419ff529ac7627edf04c00320f9771b05b0b28..2976c76ffa0a8ea91679baa975ecf2e77efc14cf 100644 (file)
@@ -8,27 +8,20 @@
 package org.opendaylight.controller.sal.dom.broker.spi;
 
 import java.util.Map;
-import java.util.Set;
 
 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
 public interface RoutedRpcProcessor extends RpcImplementation {
 
-    public RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation);
+    RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation);
 
-    public Set<QName> getSupportedRpcs();
-
-    public QName getRpcType();
-    
-    public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input);
+    QName getRpcType();
 
     Map<InstanceIdentifier,RpcImplementation> getRoutes();
-    
+
     RpcImplementation getDefaultRoute();
 
 }
index d1523a01d695f2033ee9bfa557b1aaf0ea4c592d..b19dac5535bbf3facbd72df32470bc719bb00ff8 100644 (file)
@@ -14,8 +14,6 @@ import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 public interface RpcRouter extends RpcProvisionRegistry, RpcImplementation {
 
@@ -28,7 +26,4 @@ public interface RpcRouter extends RpcProvisionRegistry, RpcImplementation {
 
     @Override
     public Set<QName> getSupportedRpcs();
-
-    @Override
-    public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input);
 }
index 182441d3f5df53135133505448e4979135126989..ae819b0f7825219d930246691602203972b125c0 100644 (file)
                                     <codeGeneratorClass>
                                         org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
                                     </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/config</outputBaseDir>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
                                     <additionalConfiguration>
                                         <namespaceToPackage1>
                                             urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
                 </dependencies>
             </plugin>
 
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/config</source>
-                                <source>src/main/xtend-gen</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-
             <plugin>
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
index 5c6702ae640f66d412aae775e80d044f84d08df5..e6dc59cc107dafa859b3b2a5481d2ec3e12fff37 100644 (file)
@@ -14,9 +14,11 @@ import java.util.Date;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class InventoryUtils {
-
+    private static final Logger LOG = LoggerFactory.getLogger(InventoryUtils.class);
     private static final URI INVENTORY_NAMESPACE = URI.create("urn:opendaylight:inventory");
     private static final URI NETCONF_INVENTORY_NAMESPACE = URI.create("urn:opendaylight:netconf-node-inventory");
     private static final Date INVENTORY_REVISION = dateFromString("2013-08-19");
@@ -33,18 +35,23 @@ public class InventoryUtils {
             .toInstance();
     public static final QName NETCONF_INVENTORY_MOUNT = null;
 
+    private InventoryUtils() {
+        throw new UnsupportedOperationException("Utility class cannot be instantiated");
+    }
+
     /**
      * Converts date in string format yyyy-MM-dd to java.util.Date.
-     * 
+     *
      * @return java.util.Date conformant to string formatted date yyyy-MM-dd.
      */
     private static Date dateFromString(final String date) {
+        // We do not reuse the formatter because it's not thread-safe
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
         try {
             return formatter.parse(date);
         } catch (ParseException e) {
-            e.printStackTrace();
+            LOG.error("Failed to parse date {}", date, e);
+            return null;
         }
-        return null;
     }
 }
index 4ae84c7d310c4c4d7b54c7dffa403ec2f8fff5ce..12e8b5587caa230cb693610d21f8135f61e9e2e9 100644 (file)
@@ -13,19 +13,18 @@ import io.netty.util.concurrent.EventExecutor
 import java.io.InputStream
 import java.net.InetSocketAddress
 import java.net.URI
+import java.util.ArrayList
+import java.util.Collection
 import java.util.Collections
 import java.util.List
 import java.util.Set
 import java.util.concurrent.ExecutorService
-import java.util.concurrent.Future
 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler
 import org.opendaylight.controller.md.sal.common.api.data.DataModification
 import org.opendaylight.controller.md.sal.common.api.data.DataReader
-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.util.xml.XmlUtil
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession
+import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration
 import org.opendaylight.controller.sal.core.api.Provider
 import org.opendaylight.controller.sal.core.api.RpcImplementation
 import org.opendaylight.controller.sal.core.api.data.DataBrokerService
@@ -45,7 +44,6 @@ import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl
 import org.opendaylight.yangtools.yang.model.api.SchemaContext
 import org.opendaylight.yangtools.yang.model.util.repo.AbstractCachingSchemaSourceProvider
 import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider
-import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProviders
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl
 import org.opendaylight.yangtools.yang.parser.impl.util.YangSourceContext
 import org.slf4j.Logger
@@ -56,14 +54,12 @@ import static org.opendaylight.controller.sal.connect.netconf.InventoryUtils.*
 
 import static extension org.opendaylight.controller.sal.connect.netconf.NetconfMapping.*
 
-class NetconfDevice implements Provider, // 
+class NetconfDevice implements Provider, //
 DataReader<InstanceIdentifier, CompositeNode>, //
 DataCommitHandler<InstanceIdentifier, CompositeNode>, //
 RpcImplementation, //
 AutoCloseable {
 
-    var NetconfClient client;
-
     @Property
     var InetSocketAddress socketAddress;
 
@@ -93,15 +89,12 @@ AutoCloseable {
     Registration<DataReader<InstanceIdentifier, CompositeNode>> operReaderReg
     Registration<DataReader<InstanceIdentifier, CompositeNode>> confReaderReg
     Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> commitHandlerReg
+    List<RpcRegistration> rpcReg
 
+    @Property
     val String name
-    MountProvisionService mountService
 
-    int messegeRetryCount = 5;
-
-    int messageTimeoutCount = 5 * 1000;
-
-    Set<QName> cachedCapabilities
+    MountProvisionService mountService
 
     @Property
     var NetconfClientDispatcher dispatcher
@@ -110,11 +103,13 @@ AutoCloseable {
 
     @Property
     var SchemaSourceProvider<InputStream> remoteSourceProvider
-    
+
     DataBrokerService dataBroker
 
+    var NetconfDeviceListener listener;
+
     public new(String name) {
-        this.name = name;
+        this._name = name;
         this.logger = LoggerFactory.getLogger(NetconfDevice.name + "#" + name);
         this.path = InstanceIdentifier.builder(INVENTORY_PATH).nodeWithKey(INVENTORY_NODE,
             Collections.singletonMap(INVENTORY_ID, name)).toInstance;
@@ -125,10 +120,11 @@ AutoCloseable {
         checkState(schemaSourceProvider != null, "Schema Source Provider must be set.")
         checkState(eventExecutor != null, "Event executor must be set.");
 
-        val listener = new NetconfDeviceListener(this);
-        val task = startClientTask(dispatcher, listener)
-        return processingExecutor.submit(task) as Future<Void>;
+        listener = new NetconfDeviceListener(this);
+
+        logger.info("Starting NETCONF Client {} for address {}", name, socketAddress);
 
+        dispatcher.createClient(socketAddress, listener, reconnectStrategy);
     }
 
     def Optional<SchemaContext> getSchemaContext() {
@@ -138,59 +134,65 @@ AutoCloseable {
         return deviceContextProvider.currentContext;
     }
 
-    private def Runnable startClientTask(NetconfClientDispatcher dispatcher, NetconfDeviceListener listener) {
-        return [ |
-            try {
-                logger.info("Starting Netconf Client on: {}", socketAddress);
-                client = NetconfClient.clientFor(name, socketAddress, reconnectStrategy, dispatcher, listener);
-                logger.debug("Initial capabilities {}", initialCapabilities);
-                var SchemaSourceProvider<String> delegate;
-                if (NetconfRemoteSchemaSourceProvider.isSupportedFor(initialCapabilities)) {
-                    delegate = new NetconfRemoteSchemaSourceProvider(this);
-                }  else if(client.capabilities.contains(NetconfRemoteSchemaSourceProvider.IETF_NETCONF_MONITORING.namespace.toString)) {
-                    delegate = new NetconfRemoteSchemaSourceProvider(this);
-                } else {
-                    logger.info("Netconf server {} does not support IETF Netconf Monitoring", socketAddress);
-                    delegate = SchemaSourceProviders.<String>noopProvider();
-                }
-                remoteSourceProvider = schemaSourceProvider.createInstanceFor(delegate);
-                deviceContextProvider = new NetconfDeviceSchemaContextProvider(this, remoteSourceProvider);
-                deviceContextProvider.createContextFromCapabilities(initialCapabilities);
-                if (mountInstance != null && schemaContext.isPresent) {
-                    mountInstance.schemaContext = schemaContext.get();
-                    val operations = schemaContext.get().operations;
-                    for (rpc : operations) {
-                        mountInstance.addRpcImplementation(rpc.QName, this);
-                    }
-                }
-                updateDeviceState()
-                if (mountInstance != null && confReaderReg == null && operReaderReg == null) {
-                    confReaderReg = mountInstance.registerConfigurationReader(ROOT_PATH, this);
-                    operReaderReg = mountInstance.registerOperationalReader(ROOT_PATH, this);
-                    commitHandlerReg = mountInstance.registerCommitHandler(ROOT_PATH, this);
-                }
-            } catch (Exception e) {
-                logger.error("Netconf client NOT started. ", e)
+    def bringDown() {
+        if (rpcReg != null) {
+            for (reg : rpcReg) {
+                reg.close()
             }
-        ]
+            rpcReg = null
+        }
+        confReaderReg?.close()
+        confReaderReg = null
+        operReaderReg?.close()
+        operReaderReg = null
+        commitHandlerReg?.close()
+        commitHandlerReg = null
+
+        updateDeviceState(false, Collections.emptySet())
     }
 
-    private def updateDeviceState() {
+    def bringUp(SchemaSourceProvider<String> delegate, Set<QName> capabilities) {
+        remoteSourceProvider = schemaSourceProvider.createInstanceFor(delegate);
+        deviceContextProvider = new NetconfDeviceSchemaContextProvider(this, remoteSourceProvider);
+        deviceContextProvider.createContextFromCapabilities(capabilities);
+        if (mountInstance != null && schemaContext.isPresent) {
+            mountInstance.schemaContext = schemaContext.get();
+        }
+
+        updateDeviceState(true, capabilities)
+
+        if (mountInstance != null) {
+            confReaderReg = mountInstance.registerConfigurationReader(ROOT_PATH, this);
+            operReaderReg = mountInstance.registerOperationalReader(ROOT_PATH, this);
+            commitHandlerReg = mountInstance.registerCommitHandler(ROOT_PATH, this);
+
+            val rpcs = new ArrayList<RpcRegistration>();
+            for (rpc : mountInstance.schemaContext.operations) {
+                rpcs.add(mountInstance.addRpcImplementation(rpc.QName, this));
+            }
+            rpcReg = rpcs
+        }
+    }
+
+    private def updateDeviceState(boolean up, Set<QName> capabilities) {
         val transaction = dataBroker.beginTransaction
 
         val it = ImmutableCompositeNode.builder
         setQName(INVENTORY_NODE)
         addLeaf(INVENTORY_ID, name)
-        addLeaf(INVENTORY_CONNECTED, client.clientSession.up)
+        addLeaf(INVENTORY_CONNECTED, up)
 
-        logger.debug("Client capabilities {}", client.capabilities)
-        for (capability : client.capabilities) {
+        logger.debug("Client capabilities {}", capabilities)
+        for (capability : capabilities) {
             addLeaf(NETCONF_INVENTORY_INITIAL_CAPABILITY, capability)
         }
 
         logger.debug("Update device state transaction " + transaction.identifier + " putting operational data started.")
+        transaction.removeOperationalData(path)
         transaction.putOperationalData(path, it.toInstance)
         logger.debug("Update device state transaction " + transaction.identifier + " putting operational data ended.")
+
+        // FIXME: this has to be asynchronous
         val transactionStatus = transaction.commit.get;
 
         if (transactionStatus.successful) {
@@ -203,13 +205,13 @@ AutoCloseable {
 
     override readConfigurationData(InstanceIdentifier path) {
         val result = invokeRpc(NETCONF_GET_CONFIG_QNAME,
-            wrap(NETCONF_GET_CONFIG_QNAME, CONFIG_SOURCE_RUNNING, path.toFilterStructure()));
+            wrap(NETCONF_GET_CONFIG_QNAME, CONFIG_SOURCE_RUNNING, path.toFilterStructure())).get();
         val data = result.result.getFirstCompositeByName(NETCONF_DATA_QNAME);
         return data?.findNode(path) as CompositeNode;
     }
 
     override readOperationalData(InstanceIdentifier path) {
-        val result = invokeRpc(NETCONF_GET_QNAME, wrap(NETCONF_GET_QNAME, path.toFilterStructure()));
+        val result = invokeRpc(NETCONF_GET_QNAME, wrap(NETCONF_GET_QNAME, path.toFilterStructure())).get();
         val data = result.result.getFirstCompositeByName(NETCONF_DATA_QNAME);
         return data?.findNode(path) as CompositeNode;
     }
@@ -218,30 +220,8 @@ AutoCloseable {
         Collections.emptySet;
     }
 
-    def createSubscription(String streamName) {
-        val it = ImmutableCompositeNode.builder()
-        QName = NETCONF_CREATE_SUBSCRIPTION_QNAME
-        addLeaf("stream", streamName);
-        invokeRpc(QName, toInstance())
-    }
-
     override invokeRpc(QName rpc, CompositeNode input) {
-        try {
-            val message = rpc.toRpcMessage(input,schemaContext);
-            val result = sendMessageImpl(message, messegeRetryCount, messageTimeoutCount);
-            return result.toRpcResult(rpc, schemaContext);
-
-        } catch (Exception e) {
-            logger.error("Rpc was not processed correctly.", e)
-            throw e;
-        }
-    }
-
-    def NetconfMessage sendMessageImpl(NetconfMessage message, int retryCount, int timeout) {
-        logger.debug("Send message {}",XmlUtil.toString(message.document))
-        val result = client.sendMessage(message, retryCount, timeout);
-        NetconfMapping.checkValidReply(message, result)
-        return result;
+        return listener.sendRequest(rpc.toRpcMessage(input,schemaContext));
     }
 
     override getProviderFunctionality() {
@@ -284,7 +264,7 @@ AutoCloseable {
                 return null;
             } else if (current instanceof CompositeNode) {
                 val currentComposite = (current as CompositeNode);
-                
+
                 current = currentComposite.getFirstCompositeByName(arg.nodeType);
                 if(current == null) {
                     current = currentComposite.getFirstCompositeByName(arg.nodeType.withoutRevision());
@@ -303,18 +283,13 @@ AutoCloseable {
     }
 
     override requestCommit(DataModification<InstanceIdentifier, CompositeNode> modification) {
-        val twoPhaseCommit = new NetconfDeviceTwoPhaseCommitTransaction(this, modification);
+        val twoPhaseCommit = new NetconfDeviceTwoPhaseCommitTransaction(this, modification, true);
         twoPhaseCommit.prepare()
         return twoPhaseCommit;
     }
 
-    def getInitialCapabilities() {
-        val capabilities = client?.capabilities;
-        if (capabilities == null) {
-            return null;
-        }
-        if (cachedCapabilities == null) {
-            cachedCapabilities = FluentIterable.from(capabilities).filter[
+    def getCapabilities(Collection<String> capabilities) {
+        return FluentIterable.from(capabilities).filter[
                 contains("?") && contains("module=") && contains("revision=")].transform [
                 val parts = split("\\?");
                 val namespace = parts.get(0);
@@ -333,16 +308,11 @@ AutoCloseable {
                 }
                 return QName.create(namespace, revision, moduleName);
             ].toSet();
-        }
-        return cachedCapabilities;
     }
 
     override close() {
-        confReaderReg?.close()
-        operReaderReg?.close()
-        client?.close()
+        bringDown()
     }
-
 }
 
 package class NetconfDeviceSchemaContextProvider {
index 13cd5dbcf03a185ce99a5631684696bf74ef3ab5..d5e1d35d7d5721e06b9b515822813b54feac779f 100644 (file)
  */
 package org.opendaylight.controller.sal.connect.netconf;
 
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.FutureListener;
+
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Queue;
+import java.util.Set;
+
 import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.client.AbstractNetconfClientNotifySessionListener;
+import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
 import org.opendaylight.controller.netconf.client.NetconfClientSession;
+import org.opendaylight.controller.netconf.client.NetconfClientSessionListener;
+import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
+import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
+import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProviders;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
+class NetconfDeviceListener implements NetconfClientSessionListener {
+    private static final class Request {
+        final UncancellableFuture<RpcResult<CompositeNode>> future;
+        final NetconfMessage request;
+
+        private Request(UncancellableFuture<RpcResult<CompositeNode>> future, NetconfMessage request) {
+            this.future = future;
+            this.request = request;
+        }
+    }
 
-class NetconfDeviceListener extends AbstractNetconfClientNotifySessionListener {
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceListener.class);
+    private final Queue<Request> requests = new ArrayDeque<>();
     private final NetconfDevice device;
+    private NetconfClientSession session;
 
     public NetconfDeviceListener(final NetconfDevice device) {
         this.device = Preconditions.checkNotNull(device);
     }
 
-    /**
-     * Method intended to customize notification processing.
-     * 
-     * @param session
-     *            {@see
-     *            NetconfClientSessionListener#onMessage(NetconfClientSession,
-     *            NetconfMessage)}
-     * @param message
-     *            {@see
-     *            NetconfClientSessionListener#onMessage(NetconfClientSession,
-     *            NetconfMessage)}
-     */
     @Override
-    public void onNotification(final NetconfClientSession session, final NetconfMessage message) {
-        this.device.logger.debug("Received NETCONF notification.", message);
-        CompositeNode domNotification = null;
-        if (message != null) {
-            domNotification = NetconfMapping.toNotificationNode(message, device.getSchemaContext());
-        }
-        if (domNotification != null) {
-            MountProvisionInstance _mountInstance = null;
-            if (this.device != null) {
-                _mountInstance = this.device.getMountInstance();
+    public synchronized void onSessionUp(final NetconfClientSession session) {
+        LOG.debug("Session with {} established as address {} session-id {}",
+                device.getName(), device.getSocketAddress(), session.getSessionId());
+
+        final Set<QName> caps = device.getCapabilities(session.getServerCapabilities());
+        LOG.trace("Server {} advertized capabilities {}", device.getName(), caps);
+
+        // Select the appropriate provider
+        final SchemaSourceProvider<String> delegate;
+        if (NetconfRemoteSchemaSourceProvider.isSupportedFor(caps)) {
+            delegate = new NetconfRemoteSchemaSourceProvider(device);
+        } else if(caps.contains(NetconfRemoteSchemaSourceProvider.IETF_NETCONF_MONITORING.getNamespace().toString())) {
+            delegate = new NetconfRemoteSchemaSourceProvider(device);
+        } else {
+            LOG.info("Netconf server {} does not support IETF Netconf Monitoring", device.getName());
+            delegate = SchemaSourceProviders.<String>noopProvider();
+        }
+
+        device.bringUp(delegate, caps);
+
+        this.session = session;
+    }
+
+    private synchronized void tearDown(final Exception e) {
+        session = null;
+
+        /*
+         * Walk all requests, check if they have been executing
+         * or cancelled and remove them from the queue.
+         */
+        final Iterator<Request> it = requests.iterator();
+        while (it.hasNext()) {
+            final Request r = it.next();
+            if (r.future.isUncancellable()) {
+                // FIXME: add a RpcResult instead?
+                r.future.setException(e);
+                it.remove();
+            } else if (r.future.isCancelled()) {
+                // This just does some house-cleaning
+                it.remove();
             }
-            if (_mountInstance != null) {
-                _mountInstance.publish(domNotification);
+        }
+
+        device.bringDown();
+    }
+
+    @Override
+    public void onSessionDown(final NetconfClientSession session, final Exception e) {
+        LOG.debug("Session with {} went down", device.getName(), e);
+        tearDown(e);
+    }
+
+    @Override
+    public void onSessionTerminated(final NetconfClientSession session, final NetconfTerminationReason reason) {
+        LOG.debug("Session with {} terminated {}", session, reason);
+        tearDown(new RuntimeException(reason.getErrorMessage()));
+    }
+
+    @Override
+    public void onMessage(final NetconfClientSession session, final NetconfMessage message) {
+        /*
+         * Dispatch between notifications and messages. Messages need to be processed
+         * with lock held, notifications do not.
+         */
+        if (isNotification(message)) {
+            processNotification(message);
+        } else {
+            processMessage(message);
+        }
+    }
+
+    private synchronized void processMessage(final NetconfMessage message) {
+        final Request r = requests.peek();
+        if (r.future.isUncancellable()) {
+            requests.poll();
+            LOG.debug("Matched {} to {}", r.request, message);
+
+            // FIXME: this can throw exceptions, which should result
+            // in the future failing
+            NetconfMapping.checkValidReply(r.request, message);
+            r.future.set(Rpcs.getRpcResult(true, NetconfMapping.toNotificationNode(message, device.getSchemaContext()),
+                    Collections.<RpcError>emptyList()));
+        } else {
+            LOG.warn("Ignoring unsolicited message", message);
+        }
+    }
+
+    synchronized ListenableFuture<RpcResult<CompositeNode>> sendRequest(final NetconfMessage message) {
+        if (session == null) {
+            LOG.debug("Session to {} is disconnected, failing RPC request {}", device.getName(), message);
+            return Futures.<RpcResult<CompositeNode>>immediateFuture(new RpcResult<CompositeNode>() {
+                @Override
+                public boolean isSuccessful() {
+                    return false;
+                }
+
+                @Override
+                public CompositeNode getResult() {
+                    return null;
+                }
+
+                @Override
+                public Collection<RpcError> getErrors() {
+                    // FIXME: indicate that the session is down
+                    return Collections.emptySet();
+                }
+            });
+        }
+
+        final Request req = new Request(new UncancellableFuture<RpcResult<CompositeNode>>(true), message);
+        requests.add(req);
+
+        session.sendMessage(req.request).addListener(new FutureListener<Void>() {
+            @Override
+            public void operationComplete(final Future<Void> future) throws Exception {
+                if (!future.isSuccess()) {
+                    // We expect that a session down will occur at this point
+                    LOG.debug("Failed to send request {}", req.request, future.cause());
+                    req.future.setException(future.cause());
+                } else {
+                    LOG.trace("Finished sending request {}", req.request);
+                }
             }
+        });
+
+        return req.future;
+    }
+
+    /**
+     * Process an incoming notification.
+     *
+     * @param notification Notification message
+     */
+    private void processNotification(final NetconfMessage notification) {
+        this.device.logger.debug("Received NETCONF notification.", notification);
+        CompositeNode domNotification = NetconfMapping.toNotificationNode(notification, device.getSchemaContext());
+        if (domNotification == null) {
+            return;
+        }
+
+        MountProvisionInstance mountInstance =  this.device.getMountInstance();
+        if (mountInstance != null) {
+            mountInstance.publish(domNotification);
         }
     }
+
+    private static boolean isNotification(final NetconfMessage message) {
+        final XmlElement xmle = XmlElement.fromDomDocument(message.getDocument());
+        return XmlNetconfConstants.NOTIFICATION_ELEMENT_NAME.equals(xmle.getName()) ;
+    }
 }
index c5390e540911d23865b83d53aaf55c230f1098dd..5f14c264edb4cac6ab3dc1b81ccd8f2b1744a598 100644 (file)
@@ -15,14 +15,17 @@ import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NET
 import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_RUNNING_QNAME;
 import static org.opendaylight.controller.sal.connect.netconf.NetconfMapping.NETCONF_TARGET_QNAME;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.ExecutionException;
 
 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
@@ -31,51 +34,52 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
 import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
-public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransaction<InstanceIdentifier, CompositeNode> {
-
-    private final NetconfDevice device;
+class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransaction<InstanceIdentifier, CompositeNode> {
+    private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceTwoPhaseCommitTransaction.class);
     private final DataModification<InstanceIdentifier, CompositeNode> modification;
-    private final boolean candidateSupported = true;
+    private final NetconfDevice device;
+    private final boolean candidateSupported;
 
     public NetconfDeviceTwoPhaseCommitTransaction(NetconfDevice device,
-            DataModification<InstanceIdentifier, CompositeNode> modification) {
-        super();
-        this.device = device;
-        this.modification = modification;
+            DataModification<InstanceIdentifier, CompositeNode> modification,
+            boolean candidateSupported) {
+        this.device = Preconditions.checkNotNull(device);
+        this.modification = Preconditions.checkNotNull(modification);
+        this.candidateSupported = candidateSupported;
     }
 
-    public void prepare() {
+    void prepare() throws InterruptedException, ExecutionException {
         for (InstanceIdentifier toRemove : modification.getRemovedConfigurationData()) {
             sendDelete(toRemove);
         }
         for(Entry<InstanceIdentifier, CompositeNode> toUpdate : modification.getUpdatedConfigurationData().entrySet()) {
             sendMerge(toUpdate.getKey(),toUpdate.getValue());
         }
-
     }
 
-    private void sendMerge(InstanceIdentifier key, CompositeNode value) {
+    private void sendMerge(InstanceIdentifier key, CompositeNode value) throws InterruptedException, ExecutionException {
         sendEditRpc(createEditStructure(key, Optional.<String>absent(), Optional.of(value)));
     }
 
-    private void sendDelete(InstanceIdentifier toDelete) {
+    private void sendDelete(InstanceIdentifier toDelete) throws InterruptedException, ExecutionException {
         sendEditRpc(createEditStructure(toDelete, Optional.of("delete"), Optional.<CompositeNode> absent()));
     }
 
-    private void sendEditRpc(CompositeNode editStructure) {
+    private void sendEditRpc(CompositeNode editStructure) throws InterruptedException, ExecutionException {
         CompositeNodeBuilder<ImmutableCompositeNode> builder = configurationRpcBuilder();
         builder.setQName(NETCONF_EDIT_CONFIG_QNAME);
         builder.add(editStructure);
 
-        RpcResult<CompositeNode> rpcResult = device.invokeRpc(NETCONF_EDIT_CONFIG_QNAME, builder.toInstance());
+        RpcResult<CompositeNode> rpcResult = device.invokeRpc(NETCONF_EDIT_CONFIG_QNAME, builder.toInstance()).get();
         Preconditions.checkState(rpcResult.isSuccessful(),"Rpc Result was unsuccessful");
-
     }
 
     private CompositeNodeBuilder<ImmutableCompositeNode> configurationRpcBuilder() {
@@ -135,8 +139,45 @@ public class NetconfDeviceTwoPhaseCommitTransaction implements DataCommitTransac
     public RpcResult<Void> finish() {
         CompositeNodeBuilder<ImmutableCompositeNode> commitInput = ImmutableCompositeNode.builder();
         commitInput.setQName(NETCONF_COMMIT_QNAME);
-        RpcResult<?> rpcResult = device.invokeRpc(NetconfMapping.NETCONF_COMMIT_QNAME, commitInput.toInstance());
-        return (RpcResult<Void>) rpcResult;
+        try {
+            final RpcResult<?> rpcResult = device.invokeRpc(NetconfMapping.NETCONF_COMMIT_QNAME, commitInput.toInstance()).get();
+            return new RpcResult<Void>() {
+
+                @Override
+                public boolean isSuccessful() {
+                    return rpcResult.isSuccessful();
+                }
+
+                @Override
+                public Void getResult() {
+                    return null;
+                }
+
+                @Override
+                public Collection<RpcError> getErrors() {
+                    return rpcResult.getErrors();
+                }
+            };
+        } catch (final InterruptedException | ExecutionException e) {
+            LOG.warn("Failed to finish operation", e);
+            return new RpcResult<Void>() {
+                @Override
+                public boolean isSuccessful() {
+                    return false;
+                }
+
+                @Override
+                public Void getResult() {
+                    return null;
+                }
+
+                @Override
+                public Collection<RpcError> getErrors() {
+                    // FIXME: wrap the exception
+                    return Collections.emptySet();
+                }
+            };
+        }
     }
 
     @Override
index bae0f089473be0b5dab92d717dc52b800a4cf57d..b68f18f52ebb06a47dc57249ae990469b5d0693b 100644 (file)
@@ -11,18 +11,19 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 public class NetconfInventoryUtils {
-
-    
     public static final QName NETCONF_MOUNT = null;
     public static final QName NETCONF_ENDPOINT = null;
     public static final QName NETCONF_ENDPOINT_ADDRESS = null;
     public static final QName NETCONF_ENDPOINT_PORT = null;
 
+    private NetconfInventoryUtils() {
+        throw new UnsupportedOperationException("Utility class cannot be instantiated");
+    }
 
     public static String getEndpointAddress(CompositeNode node) {
         return node.getCompositesByName(NETCONF_ENDPOINT).get(0).getFirstSimpleByName(NETCONF_ENDPOINT_ADDRESS).getValue().toString();
     }
-    
+
     public static String getEndpointPort(CompositeNode node) {
         return node.getCompositesByName(NETCONF_ENDPOINT).get(0).getFirstSimpleByName(NETCONF_ENDPOINT_PORT).getValue().toString();
     }
index e5a24fcf63914f35492f50e7186ff2ed844761e4..228a01eb4c8340fe3a8aa58867cbb0312a664ff5 100644 (file)
@@ -39,8 +39,8 @@ class NetconfMapping {
     public static val NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0")
     public static val NETCONF_MONITORING_URI = "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"
     public static val NETCONF_NOTIFICATION_URI = URI.create("urn:ietf:params:xml:ns:netconf:notification:1.0")
-    
-    
+
+
     public static val NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf");
     public static val NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc");
     public static val NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get");
@@ -51,15 +51,15 @@ class NetconfMapping {
     public static val NETCONF_DELETE_CONFIG_QNAME = QName.create(NETCONF_QNAME, "delete-config");
     public static val NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation");
     public static val NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit");
-    
+
     public static val NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config");
     public static val NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source");
     public static val NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target");
-    
+
     public static val NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate");
     public static val NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running");
-    
-    
+
+
     public static val NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply");
     public static val NETCONF_OK_QNAME = QName.create(NETCONF_QNAME, "ok");
     public static val NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data");
@@ -78,7 +78,7 @@ class NetconfMapping {
         if(identifier.path.empty) {
             return null;
         }
-        
+
         for (component : identifier.path.reverseView) {
             val Node<?> current = component.toNode(previous);
             previous = current;
@@ -106,11 +106,11 @@ class NetconfMapping {
     }
 
     static def CompositeNode toCompositeNode(NetconfMessage message,Optional<SchemaContext> ctx) {
-        //TODO: implement general normalization to normalize incoming Netconf Message 
+        //TODO: implement general normalization to normalize incoming Netconf Message
         // for Schema Context counterpart
         return null
     }
-    
+
     static def CompositeNode toNotificationNode(NetconfMessage message,Optional<SchemaContext> ctx) {
         if (ctx.present) {
             val schemaContext = ctx.get
@@ -127,56 +127,53 @@ class NetconfMapping {
         w3cPayload.documentElement.setAttribute("message-id", "m-" + messageId.andIncrement)
         return new NetconfMessage(w3cPayload);
     }
-    
+
     def static flattenInput(CompositeNode node) {
         val inputQName = QName.create(node.nodeType,"input");
         val input = node.getFirstCompositeByName(inputQName);
         if(input == null) return node;
         if(input instanceof CompositeNode) {
-            
+
             val nodes = ImmutableList.builder() //
                 .addAll(input.children) //
                 .addAll(node.children.filter[nodeType != inputQName]) //
                 .build()
             return ImmutableCompositeNode.create(node.nodeType,nodes);
-        } 
-        
+        }
+
     }
 
     static def RpcResult<CompositeNode> toRpcResult(NetconfMessage message,QName rpc,Optional<SchemaContext> context) {
         var CompositeNode rawRpc;
         if(context.present) {
             if(isDataRetrievalReply(rpc)) {
-                
+
                 val xmlData = message.document.dataSubtree
                 val dataNodes = XmlDocumentUtils.toDomNodes(xmlData, Optional.of(context.get.dataDefinitions))
-                
+
                 val it = ImmutableCompositeNode.builder()
                 setQName(NETCONF_RPC_REPLY_QNAME)
                 add(ImmutableCompositeNode.create(NETCONF_DATA_QNAME, dataNodes));
-                
+
                 rawRpc = it.toInstance;
                 //sys(xmlData)
             } else {
                 val rpcSchema = context.get.operations.findFirst[QName == rpc]
                 rawRpc = message.document.toCompositeNode() as CompositeNode;
             }
-            
-            
-            
         } else {
             rawRpc = message.document.toCompositeNode() as CompositeNode;
         }
         //rawRpc.
         return Rpcs.getRpcResult(true, rawRpc, Collections.emptySet());
     }
-    
+
     def static Element getDataSubtree(Document doc) {
         doc.getElementsByTagNameNS(NETCONF_URI.toString,"data").item(0) as Element
     }
-    
+
     def static boolean isDataRetrievalReply(QName it) {
-        return NETCONF_URI == namespace && ( localName == NETCONF_GET_CONFIG_QNAME.localName || localName == NETCONF_GET_QNAME.localName) 
+        return NETCONF_URI == namespace && ( localName == NETCONF_GET_CONFIG_QNAME.localName || localName == NETCONF_GET_QNAME.localName)
     }
 
     static def wrap(QName name, Node<?> node) {
@@ -209,12 +206,12 @@ class NetconfMapping {
     public static def Node<?> toCompositeNode(Document document) {
         return XmlDocumentUtils.toDomNode(document) as Node<?>
     }
-    
+
     public static def checkValidReply(NetconfMessage input, NetconfMessage output) {
         val inputMsgId = input.document.documentElement.getAttribute("message-id")
         val outputMsgId = output.document.documentElement.getAttribute("message-id")
         Preconditions.checkState(inputMsgId == outputMsgId,"Rpc request and reply message IDs must be same.");
-        
+
     }
-    
+
 }
index fa6b6f7ca58f4403e9c9c3b97f79fbb2aa47d2ea..c734e80d9aa06f76d3c4a96c277b8c71a7a48d74 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.controller.sal.connect.netconf;
 
-import java.util.Set;
+import java.util.Collection;
+import java.util.concurrent.ExecutionException;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -18,6 +19,7 @@ import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
 import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 
 class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String> {
 
@@ -26,11 +28,10 @@ class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String>
     public static final QName GET_SCHEMA_QNAME = QName.create(IETF_NETCONF_MONITORING, "get-schema");
     public static final QName GET_DATA_QNAME = QName.create(IETF_NETCONF_MONITORING, "data");
 
-    NetconfDevice device;
+    private final NetconfDevice device;
 
     public NetconfRemoteSchemaSourceProvider(NetconfDevice device) {
-        super();
-        this.device = device;
+        this.device = Preconditions.checkNotNull(device);
     }
 
     @Override
@@ -44,15 +45,19 @@ class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String>
         }
 
         device.logger.trace("Loading YANG schema source for {}:{}", moduleName, revision);
-        RpcResult<CompositeNode> schemaReply = device.invokeRpc(GET_SCHEMA_QNAME, request.toInstance());
-        if (schemaReply.isSuccessful()) {
-            String schemaBody = getSchemaFromRpc(schemaReply.getResult());
-            if (schemaBody != null) {
-                device.logger.trace("YANG Schema successfully retrieved from remote for {}:{}", moduleName, revision);
-                return Optional.of(schemaBody);
+        try {
+            RpcResult<CompositeNode> schemaReply = device.invokeRpc(GET_SCHEMA_QNAME, request.toInstance()).get();
+            if (schemaReply.isSuccessful()) {
+                String schemaBody = getSchemaFromRpc(schemaReply.getResult());
+                if (schemaBody != null) {
+                    device.logger.trace("YANG Schema successfully retrieved from remote for {}:{}", moduleName, revision);
+                    return Optional.of(schemaBody);
+                }
             }
+            device.logger.warn("YANG shcema was not successfully retrieved.");
+        } catch (InterruptedException | ExecutionException e) {
+            device.logger.warn("YANG shcema was not successfully retrieved.", e);
         }
-        device.logger.warn("YANG shcema was not successfully retrieved.");
         return Optional.absent();
     }
 
@@ -68,7 +73,7 @@ class NetconfRemoteSchemaSourceProvider implements SchemaSourceProvider<String>
         return null;
     }
 
-    public static final boolean isSupportedFor(Set<QName> capabilities) {
+    public static final boolean isSupportedFor(Collection<QName> capabilities) {
         return capabilities.contains(IETF_NETCONF_MONITORING);
     }
 }
diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/UncancellableFuture.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/UncancellableFuture.java
new file mode 100644 (file)
index 0000000..c353f86
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.sal.connect.netconf;
+
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.GuardedBy;
+
+import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.AbstractFuture;
+
+final class UncancellableFuture<V> extends AbstractFuture<V> {
+    @GuardedBy("this")
+    private boolean uncancellable = false;
+
+    public UncancellableFuture(boolean uncancellable) {
+        this.uncancellable = uncancellable;
+    }
+
+    public synchronized boolean setUncancellable() {
+        if (isCancelled()) {
+            return false;
+        }
+
+        uncancellable = true;
+        return true;
+    }
+
+    public synchronized boolean isUncancellable() {
+        return uncancellable;
+    }
+
+    @Override
+    public synchronized boolean cancel(boolean mayInterruptIfRunning) {
+        if (uncancellable) {
+            return false;
+        }
+
+        return super.cancel(mayInterruptIfRunning);
+    }
+
+    @Override
+    public synchronized boolean set(@Nullable V value) {
+        Preconditions.checkState(uncancellable == true);
+        return super.set(value);
+    }
+
+    @Override
+    protected boolean setException(Throwable throwable) {
+        Preconditions.checkState(uncancellable == true);
+        return super.setException(throwable);
+    }
+}
diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/YangModelInputStreamAdapter.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/YangModelInputStreamAdapter.java
deleted file mode 100644 (file)
index 23892e1..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.sal.connect.netconf;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.opendaylight.yangtools.concepts.Delegator;
-import org.opendaylight.yangtools.yang.common.QName;
-
-import com.google.common.base.Charsets;
-
-/**
- *
- *
- */
-public class YangModelInputStreamAdapter extends InputStream implements Delegator<InputStream> {
-
-    final String source;
-    final QName moduleIdentifier;
-    final InputStream delegate;
-
-    private YangModelInputStreamAdapter(String source, QName moduleIdentifier, InputStream delegate) {
-        super();
-        this.source = source;
-        this.moduleIdentifier = moduleIdentifier;
-        this.delegate = delegate;
-    }
-
-    @Override
-    public int read() throws IOException {
-        return delegate.read();
-    }
-
-    @Override
-    public int hashCode() {
-        return delegate.hashCode();
-    }
-
-    @Override
-    public int read(byte[] b) throws IOException {
-        return delegate.read(b);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        return delegate.equals(obj);
-    }
-
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException {
-        return delegate.read(b, off, len);
-    }
-
-    @Override
-    public long skip(long n) throws IOException {
-        return delegate.skip(n);
-    }
-
-    @Override
-    public int available() throws IOException {
-        return delegate.available();
-    }
-
-    @Override
-    public void close() throws IOException {
-        delegate.close();
-    }
-
-    @Override
-    public void mark(int readlimit) {
-        delegate.mark(readlimit);
-    }
-
-    @Override
-    public void reset() throws IOException {
-        delegate.reset();
-    }
-
-    @Override
-    public boolean markSupported() {
-        return delegate.markSupported();
-    }
-
-    @Override
-    public InputStream getDelegate() {
-        return delegate;
-    }
-
-    @Override
-    public String toString() {
-        return "YangModelInputStreamAdapter [moduleIdentifier=" + moduleIdentifier + ", delegate=" + delegate + "]";
-    }
-
-    public static YangModelInputStreamAdapter create(QName name, String module) {
-        return new YangModelInputStreamAdapter(null, name, new ByteArrayInputStream(module.getBytes(Charsets.UTF_8)));
-    }
-}
index 15bd2e7a303f73caa644eed78e20330f27b6467a..0c06b4490d1ebeb75d733f67319138788aab0f4d 100644 (file)
                     </dependency>
                 </dependencies>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
 </project>
index 415ae5aa052ef76a6a3379f1480875543004955f..0c817d26f6a3c2deda4e2a1f18a4d093ea3bbe20 100644 (file)
                                     <codeGeneratorClass>
                                         org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
                                     </codeGeneratorClass>
-                                    <outputBaseDir>${project.build.directory}/generated-sources/config</outputBaseDir>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
                                     <additionalConfiguration>
                                         <namespaceToPackage1>
                                             urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
index 84df2e43f01cd54084357d58b67abbe0ea6e93e9..8f95e73b15cdcd8307612bb155a0c3c406647a57 100644 (file)
@@ -7,7 +7,16 @@
 
 package org.opendaylight.controller.sal.connector.remoterpc;
 
-import com.google.common.base.Optional;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+
 import org.opendaylight.controller.sal.common.util.RpcErrors;
 import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.controller.sal.connector.api.RpcRouter;
@@ -27,16 +36,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.zeromq.ZMQ;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.TimeUnit;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 
 /**
  * An implementation of {@link RpcImplementation} that makes
@@ -46,8 +48,8 @@ public class ClientImpl implements RemoteRpcClient {
 
   private final Logger _logger = LoggerFactory.getLogger(ClientImpl.class);
 
-  private ZMQ.Context context = ZMQ.context(1);
-  private ClientRequestHandler handler;
+  private final ZMQ.Context context = ZMQ.context(1);
+  private final ClientRequestHandler handler;
   private RoutingTableProvider routingTableProvider;
 
   public ClientImpl(){
@@ -64,6 +66,7 @@ public class ClientImpl implements RemoteRpcClient {
     return routingTableProvider;
   }
 
+  @Override
   public void setRoutingTableProvider(RoutingTableProvider routingTableProvider) {
     this.routingTableProvider = routingTableProvider;
   }
@@ -93,7 +96,7 @@ public class ClientImpl implements RemoteRpcClient {
    * @param input payload for the remote service
    * @return
    */
-  public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
+  public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
     RouteIdentifierImpl routeId = new RouteIdentifierImpl();
     routeId.setType(rpc);
 
@@ -115,7 +118,7 @@ public class ClientImpl implements RemoteRpcClient {
    *          payload
    * @return
    */
-  public RpcResult<CompositeNode> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) {
+  public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) {
 
     RouteIdentifierImpl routeId = new RouteIdentifierImpl();
     routeId.setType(rpc);
@@ -126,7 +129,7 @@ public class ClientImpl implements RemoteRpcClient {
     return sendMessage(input, routeId, address);
   }
 
-  private RpcResult<CompositeNode> sendMessage(CompositeNode input, RouteIdentifierImpl routeId, String address) {
+  private ListenableFuture<RpcResult<CompositeNode>> sendMessage(CompositeNode input, RouteIdentifierImpl routeId, String address) {
     Message request = new Message.MessageBuilder()
         .type(Message.MessageType.REQUEST)
         .sender(Context.getInstance().getLocalUri())
@@ -164,11 +167,11 @@ public class ClientImpl implements RemoteRpcClient {
 
         }
       }
-      return Rpcs.getRpcResult(true, payload, errors);
+      return Futures.immediateFuture(Rpcs.getRpcResult(true, payload, errors));
 
     } catch (Exception e){
       collectErrors(e, errors);
-      return Rpcs.getRpcResult(false, null, errors);
+      return Futures.immediateFuture(Rpcs.<CompositeNode>getRpcResult(false, null, errors));
     }
   }
 
index 16e720024752c157b0bd68b4df5f790ffb639fca..edcef83574983718711d644f7c5a89c91d9d5035 100644 (file)
@@ -8,7 +8,14 @@
 
 package org.opendaylight.controller.sal.connector.remoterpc;
 
-import com.google.common.base.Optional;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
 import org.opendaylight.controller.md.sal.common.api.routing.RouteChange;
 import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
 import org.opendaylight.controller.sal.connector.api.RpcRouter;
@@ -32,13 +39,8 @@ import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
 
 public class RemoteRpcProvider implements
     RpcImplementation,
@@ -46,7 +48,7 @@ public class RemoteRpcProvider implements
     AutoCloseable,
     Provider {
 
-  private Logger _logger = LoggerFactory.getLogger(RemoteRpcProvider.class);
+  private final Logger _logger = LoggerFactory.getLogger(RemoteRpcProvider.class);
 
   private final ServerImpl server;
   private final ClientImpl client;
@@ -96,12 +98,12 @@ public class RemoteRpcProvider implements
   }
 
   @Override
-  public RpcResult<CompositeNode> invokeRpc(QName rpc, CompositeNode input) {
+  public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
     return client.invokeRpc(rpc, input);
   }
 
   @Override
-  public RpcResult<CompositeNode> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) {
+  public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) {
     return client.invokeRpc(rpc, identifier, input);
   }
 
@@ -289,8 +291,5 @@ public class RemoteRpcProvider implements
       return routeIdSet;
     }
 
-
-
   }
-
 }
index 722ca0687904f2c7f2e5c42572fc2d16c762936b..d256b998d4f8abd254fffea087778600a1b70051 100644 (file)
@@ -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;
index c0aae2dfb56590a39ac1e90a5a413b29c2a87cdb..0fa12e351c19d075ce934f4ca2ccccafa6918514 100644 (file)
@@ -7,29 +7,25 @@
  */
 package org.opendaylight.controller.sal.connector.remoterpc;
 
-import com.google.common.base.Optional;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
 import junit.framework.Assert;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.controller.sal.connector.api.RpcRouter;
-import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener;
 import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable;
-import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException;
-import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException;
 import org.opendaylight.controller.sal.connector.remoterpc.dto.Message;
 import org.opendaylight.controller.sal.connector.remoterpc.utils.MessagingUtil;
-import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
-import java.io.IOException;
-import java.util.*;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import com.google.common.base.Optional;
 
 /**
  *
@@ -88,7 +84,7 @@ public class ClientImplTest {
     when(mockHandler.handle(any(Message.class))).
             thenReturn(MessagingUtil.createEmptyMessage());
 
-    RpcResult<CompositeNode> result = client.invokeRpc(null, null);
+    RpcResult<CompositeNode> result = client.invokeRpc(null, null).get();
 
     Assert.assertTrue(result.isSuccessful());
     Assert.assertTrue(result.getErrors().isEmpty());
@@ -101,7 +97,7 @@ public class ClientImplTest {
     when(mockHandler.handle(any(Message.class))).
             thenThrow(new IOException());
 
-    RpcResult<CompositeNode> result = client.invokeRpc(null, null);
+    RpcResult<CompositeNode> result = client.invokeRpc(null, null).get();
 
     Assert.assertFalse(result.isSuccessful());
     Assert.assertFalse(result.getErrors().isEmpty());
index 837d7ae5b7d147b59aa762b1fda4a32de0b86175..cb02fc89bfe604fb58e34854ea85f27edb1a403e 100644 (file)
@@ -483,7 +483,7 @@ class ControllerContext implements SchemaContextListener {
                         + "\" cannot contain \"null\" value as a key."
                     )
                 }
-                keyValues.addKeyValue(listNode.getDataChildByName(key), uriKeyValue);
+                keyValues.addKeyValue(listNode.getDataChildByName(key), uriKeyValue, mountPoint);
                 i = i + 1;
             }
             consumed = consumed + i;
@@ -541,13 +541,13 @@ class ControllerContext implements SchemaContextListener {
         }
     }
     
-    private def void addKeyValue(HashMap<QName, Object> map, DataSchemaNode node, String uriValue) {
+    private def void addKeyValue(HashMap<QName, Object> map, DataSchemaNode node, String uriValue, MountInstance mountPoint) {
         checkNotNull(uriValue);
         checkArgument(node instanceof LeafSchemaNode);
         val urlDecoded = URLDecoder.decode(uriValue);
         val typedef = (node as LeafSchemaNode).type;
         
-        var decoded = TypeDefinitionAwareCodec.from(typedef)?.deserialize(urlDecoded)
+        var decoded = RestCodec.from(typedef, mountPoint)?.deserialize(urlDecoded)
         var additionalInfo = ""
         if(decoded === null) {
             var baseType = RestUtil.resolveBaseTypeFrom(typedef)
index 2fe625ffb3fc2596eb8e14e111e4aa7ab8cfafbe..c086db7ba4be29762c8c20bdaa53634ac961ba50 100644 (file)
                     </instructions>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${project.build.directory}/generated-sources/</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
 </project>
index d0ef2e0c65eb752d78fa1c8f9b69ad4fcfae10cf..7c54309fa10cb6866c22c697f48076634bfef847 100644 (file)
@@ -41,7 +41,7 @@
                                 org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
                             </codeGeneratorClass>
                             <outputBaseDir>
-                                target/generated-sources/sal
+                                ${salGeneratorPath}
                             </outputBaseDir>
                         </generator>
                         <generator>
index 67fc824a7b41d0784425920eb8dc7f6ae3e86bc4..0c16a92586c0518a14bc11b572a9890462792bd7 100644 (file)
@@ -16,8 +16,6 @@
 
     <properties>
         <sal-binding-api.version>1.1-SNAPSHOT</sal-binding-api.version>
-        <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
-
     </properties>
 
        <build>
                 </dependencies>
             </plugin>
 
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${jmxGeneratorPath}</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
                </plugins>
        </build>
 
index 4e4cfeda2aaee2e9ec8e05e7e60e4c582824e53c..11ee47b8c74df91c3c622db28358b8bb864cb0ed 100644 (file)
@@ -16,7 +16,6 @@
 
 
     <properties>
-        <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
         <sal-binding-api.version>1.1-SNAPSHOT</sal-binding-api.version>
     </properties>
 
                     </dependency>
                 </dependencies>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.8</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>${jmxGeneratorPath}</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
     </build>
 
index 59f8955d4b0bab2d41ac57bc134115d4c4f66842..eb13e64adcea71eeb2a63a61d329bdabb381ca9e 100644 (file)
                     </dependency>
                 </dependencies>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.7</version>
-                <executions>
-                    <execution>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                <source>target/generated-sources/sal</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
         </plugins>
         <pluginManagement>
             <plugins>
index b829990bd3be3e26cb0b30407fbf7e6d9e5c4101..9ace8a119fb4d9dfa27654502647c688f123fe91 100644 (file)
@@ -66,9 +66,6 @@
                     </instructions>
                 </configuration>
             </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 </project>
index 590e8ea91a0349345124b3aa552942d036ca6352..627934eb6743aa6cac036df44a74a89ca300074b 100644 (file)
             <plugin>
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
-                <executions>
-                  <execution>
-                      <goals>
-                          <goal>compile</goal>
-                      </goals>
-                      <configuration>
-                          <outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>
-                      </configuration>
-                  </execution>
-              </executions>
-            </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-                <configuration>
-                    <filesets>
-                        <fileset>
-                            <directory>${basedir}/src/main/xtend-gen</directory>
-                            <includes>
-                                <include>**</include>
-                            </includes>
-                        </fileset>
-                    </filesets>
-                </configuration>
             </plugin>
         </plugins>
     </build>
index 8035f420fb3797396f7abe7bec6753ed4eaa3c2d..8503864f62f8ccb181c9acc42d28c12061d8f9a4 100644 (file)
@@ -68,9 +68,6 @@
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <artifactId>maven-clean-plugin</artifactId>
-            </plugin>
         </plugins>
     </build>
 </project>
index 43edced0a1088bba2edc6347d67b0e5d9cc0f94c..96522712daa90c8e52b67e37fd178296835f9611 100644 (file)
@@ -75,7 +75,7 @@ import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStore
 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot;
 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
 import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl;
 import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
@@ -119,7 +119,7 @@ public class NetconfMappingTest extends AbstractConfigTest {
     @Mock
     NetconfOperationRouter netconfOperationRouter;
     @Mock
-    NetconfOperationServiceSnapshot netconfOperationServiceSnapshot;
+    NetconfOperationServiceSnapshotImpl netconfOperationServiceSnapshot;
 
     private TransactionProvider transactionProvider;
 
index 76afe8eb39b95f4500fd847cfe5df9a297c656e7..0cc55719e12875ece51220073657867fc3a9c21f 100644 (file)
@@ -10,14 +10,17 @@ package org.opendaylight.controller.netconf.persist.impl.osgi;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.controller.netconf.persist.impl.ConfigPersisterNotificationHandler;
 import org.opendaylight.controller.netconf.persist.impl.ConfigPusher;
 import org.opendaylight.controller.netconf.persist.impl.PersisterAggregator;
+import org.opendaylight.controller.netconf.util.CloseableUtil;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -33,6 +36,7 @@ import java.util.concurrent.TimeUnit;
 public class ConfigPersisterActivator implements BundleActivator {
 
     private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterActivator.class);
+    private static final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
 
     public static final String MAX_WAIT_FOR_CAPABILITIES_MILLIS_PROPERTY = "maxWaitForCapabilitiesMillis";
     private static final long MAX_WAIT_FOR_CAPABILITIES_MILLIS_DEFAULT = TimeUnit.MINUTES.toMillis(2);
@@ -43,9 +47,6 @@ public class ConfigPersisterActivator implements BundleActivator {
 
     public static final String STORAGE_ADAPTER_CLASS_PROP_SUFFIX = "storageAdapterClass";
 
-
-    private static final MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
-
     private List<AutoCloseable> autoCloseables;
 
 
@@ -55,56 +56,32 @@ public class ConfigPersisterActivator implements BundleActivator {
         autoCloseables = new ArrayList<>();
         PropertiesProviderBaseImpl propertiesProvider = new PropertiesProviderBaseImpl(context);
 
-
         final PersisterAggregator persisterAggregator = PersisterAggregator.createFromProperties(propertiesProvider);
         autoCloseables.add(persisterAggregator);
-        final long maxWaitForCapabilitiesMillis = getMaxWaitForCapabilitiesMillis(propertiesProvider);
-        final List<ConfigSnapshotHolder> configs = persisterAggregator.loadLastConfigs();
-        final long conflictingVersionTimeoutMillis = getConflictingVersionTimeoutMillis(propertiesProvider);
+        long maxWaitForCapabilitiesMillis = getMaxWaitForCapabilitiesMillis(propertiesProvider);
+        List<ConfigSnapshotHolder> configs = persisterAggregator.loadLastConfigs();
+        long conflictingVersionTimeoutMillis = getConflictingVersionTimeoutMillis(propertiesProvider);
         logger.trace("Following configs will be pushed: {}", configs);
-        ServiceTrackerCustomizer<NetconfOperationServiceFactory, NetconfOperationServiceFactory> configNetconfCustomizer = new ServiceTrackerCustomizer<NetconfOperationServiceFactory, NetconfOperationServiceFactory>() {
-            @Override
-            public NetconfOperationServiceFactory addingService(ServiceReference<NetconfOperationServiceFactory> reference) {
-                NetconfOperationServiceFactory service = reference.getBundle().getBundleContext().getService(reference);
-                final ConfigPusher configPusher = new ConfigPusher(service, maxWaitForCapabilitiesMillis, conflictingVersionTimeoutMillis);
-                logger.debug("Configuration Persister got %s", service);
-                final Thread pushingThread = new Thread(new Runnable() {
-                    @Override
-                    public void run() {
-                        configPusher.pushConfigs(configs);
-                        logger.info("Configuration Persister initialization completed.");
-                        ConfigPersisterNotificationHandler jmxNotificationHandler = new ConfigPersisterNotificationHandler(platformMBeanServer, persisterAggregator);
-                        synchronized (ConfigPersisterActivator.this) {
-                            autoCloseables.add(jmxNotificationHandler);
-                        }
-                    }
-                }, "config-pusher");
-                synchronized (ConfigPersisterActivator.this){
-                    autoCloseables.add(new AutoCloseable() {
-                        @Override
-                        public void close() throws Exception {
-                            pushingThread.interrupt();
-                        }
-                    });
-                }
-                pushingThread.start();
-                return service;
-            }
 
-            @Override
-            public void modifiedService(ServiceReference<NetconfOperationServiceFactory> reference, NetconfOperationServiceFactory service) {
-            }
+        InnerCustomizer innerCustomizer = new InnerCustomizer(configs, maxWaitForCapabilitiesMillis,
+                conflictingVersionTimeoutMillis, persisterAggregator);
+        OuterCustomizer outerCustomizer = new OuterCustomizer(context, innerCustomizer);
+        new ServiceTracker<>(context, NetconfOperationProvider.class, outerCustomizer).open();
+    }
 
-            @Override
-            public void removedService(ServiceReference<NetconfOperationServiceFactory> reference, NetconfOperationServiceFactory service) {
-            }
-        };
+    private long getConflictingVersionTimeoutMillis(PropertiesProviderBaseImpl propertiesProvider) {
+        String timeoutProperty = propertiesProvider.getProperty(CONFLICTING_VERSION_TIMEOUT_MILLIS_PROPERTY);
+        return timeoutProperty == null ? CONFLICTING_VERSION_TIMEOUT_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
+    }
 
-        Filter filter = context.createFilter(getFilterString());
+    private long getMaxWaitForCapabilitiesMillis(PropertiesProviderBaseImpl propertiesProvider) {
+        String timeoutProperty = propertiesProvider.getProperty(MAX_WAIT_FOR_CAPABILITIES_MILLIS_PROPERTY);
+        return timeoutProperty == null ? MAX_WAIT_FOR_CAPABILITIES_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
+    }
 
-        ServiceTracker<NetconfOperationServiceFactory, NetconfOperationServiceFactory> tracker =
-                new ServiceTracker<>(context, filter, configNetconfCustomizer);
-        tracker.open();
+    @Override
+    public synchronized void stop(BundleContext context) throws Exception {
+        CloseableUtil.closeAll(autoCloseables);
     }
 
 
@@ -116,32 +93,92 @@ public class ConfigPersisterActivator implements BundleActivator {
                 ")";
     }
 
-    private long getConflictingVersionTimeoutMillis(PropertiesProviderBaseImpl propertiesProvider) {
-        String timeoutProperty = propertiesProvider.getProperty(CONFLICTING_VERSION_TIMEOUT_MILLIS_PROPERTY);
-        return timeoutProperty == null ? CONFLICTING_VERSION_TIMEOUT_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
-    }
+    class OuterCustomizer implements ServiceTrackerCustomizer<NetconfOperationProvider, NetconfOperationProvider> {
+        private final BundleContext context;
+        private final InnerCustomizer innerCustomizer;
 
-    private long getMaxWaitForCapabilitiesMillis(PropertiesProviderBaseImpl propertiesProvider) {
-        String timeoutProperty = propertiesProvider.getProperty(MAX_WAIT_FOR_CAPABILITIES_MILLIS_PROPERTY);
-        return timeoutProperty == null ? MAX_WAIT_FOR_CAPABILITIES_MILLIS_DEFAULT : Long.valueOf(timeoutProperty);
-    }
+        OuterCustomizer(BundleContext context, InnerCustomizer innerCustomizer) {
+            this.context = context;
+            this.innerCustomizer = innerCustomizer;
+        }
 
-    @Override
-    public synchronized void stop(BundleContext context) throws Exception {
-        Exception lastException = null;
-        for (AutoCloseable autoCloseable : autoCloseables) {
+        @Override
+        public NetconfOperationProvider addingService(ServiceReference<NetconfOperationProvider> reference) {
+            logger.trace("Got OuterCustomizer.addingService {}", reference);
+            // JMX was registered, track config-netconf-connector
+            Filter filter;
             try {
-                autoCloseable.close();
-            } catch (Exception e) {
-                if (lastException == null) {
-                    lastException = e;
-                } else {
-                    lastException.addSuppressed(e);
+                filter = context.createFilter(getFilterString());
+            } catch (InvalidSyntaxException e) {
+                throw new IllegalStateException(e);
+            }
+            new ServiceTracker<>(context, filter, innerCustomizer).open();
+            return null;
+        }
+
+        @Override
+        public void modifiedService(ServiceReference<NetconfOperationProvider> reference, NetconfOperationProvider service) {
+
+        }
+
+        @Override
+        public void removedService(ServiceReference<NetconfOperationProvider> reference, NetconfOperationProvider service) {
+
+        }
+    }
+
+    class InnerCustomizer implements ServiceTrackerCustomizer<NetconfOperationServiceFactory, NetconfOperationServiceFactory> {
+        private final List<ConfigSnapshotHolder> configs;
+        private final PersisterAggregator persisterAggregator;
+        private final long maxWaitForCapabilitiesMillis, conflictingVersionTimeoutMillis;
+
+
+        InnerCustomizer(List<ConfigSnapshotHolder> configs, long maxWaitForCapabilitiesMillis, long conflictingVersionTimeoutMillis,
+                        PersisterAggregator persisterAggregator) {
+            this.configs = configs;
+            this.maxWaitForCapabilitiesMillis = maxWaitForCapabilitiesMillis;
+            this.conflictingVersionTimeoutMillis = conflictingVersionTimeoutMillis;
+            this.persisterAggregator = persisterAggregator;
+        }
+
+        @Override
+        public NetconfOperationServiceFactory addingService(ServiceReference<NetconfOperationServiceFactory> reference) {
+            logger.trace("Got InnerCustomizer.addingService {}", reference);
+            NetconfOperationServiceFactory service = reference.getBundle().getBundleContext().getService(reference);
+
+            final ConfigPusher configPusher = new ConfigPusher(service, maxWaitForCapabilitiesMillis, conflictingVersionTimeoutMillis);
+            logger.debug("Configuration Persister got {}", service);
+            final Thread pushingThread = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    configPusher.pushConfigs(configs);
+                    logger.info("Configuration Persister initialization completed.");
+                    ConfigPersisterNotificationHandler jmxNotificationHandler = new ConfigPersisterNotificationHandler(platformMBeanServer, persisterAggregator);
+                    synchronized (ConfigPersisterActivator.this) {
+                        autoCloseables.add(jmxNotificationHandler);
+                    }
                 }
+            }, "config-pusher");
+            synchronized (ConfigPersisterActivator.this) {
+                autoCloseables.add(new AutoCloseable() {
+                    @Override
+                    public void close() throws Exception {
+                        pushingThread.interrupt();
+                    }
+                });
             }
+            pushingThread.start();
+            return service;
+        }
+
+        @Override
+        public void modifiedService(ServiceReference<NetconfOperationServiceFactory> reference, NetconfOperationServiceFactory service) {
         }
-        if (lastException != null) {
-            throw lastException;
+
+        @Override
+        public void removedService(ServiceReference<NetconfOperationServiceFactory> reference, NetconfOperationServiceFactory service) {
         }
+
     }
 }
+
index 493ecd9250262959e78523c4ed1dc49c7d177474..b1bf23292875611d40c6875fd1a05bb8d81b328e 100644 (file)
@@ -25,9 +25,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
 
-import javax.management.MBeanServer;
 import java.io.IOException;
-import java.lang.management.ManagementFactory;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
@@ -41,7 +39,6 @@ public class ConfigPersisterTest {
 
     private MockedBundleContext ctx;
     private ConfigPersisterActivator configPersisterActivator;
-    private static final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
     private TestingExceptionHandler handler;
 
 
index 8bc787bdef39e571fc4cef62add5b0854c491130..95fd5f65498e507c54e6d88023dc24b25475031a 100644 (file)
@@ -14,6 +14,7 @@ import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
 import org.opendaylight.controller.config.persist.api.Persister;
 import org.opendaylight.controller.config.persist.api.PropertiesProvider;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
 import org.opendaylight.controller.netconf.persist.impl.DummyAdapter;
@@ -39,7 +40,7 @@ final class MockedBundleContext {
     @Mock
     private BundleContext context;
     @Mock
-    private Filter filter;
+    private Filter outerFilter, innerFilter;
     @Mock
     private ServiceReference<?> serviceReference;
     @Mock
@@ -53,12 +54,21 @@ final class MockedBundleContext {
         MockitoAnnotations.initMocks(this);
         doReturn(null).when(context).getProperty(anyString());
         initContext(maxWaitForCapabilitiesMillis, conflictingVersionTimeoutMillis);
-        doReturn(filter).when(context).createFilter(ConfigPersisterActivator.getFilterString());
-        String filterString = "filter";
-        doReturn(filterString).when(filter).toString();
-        doNothing().when(context).addServiceListener(any(ServiceListener.class), eq(filterString));
+
+        String outerFilterString = "(objectClass=org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider)";
+        doReturn(outerFilter).when(context).createFilter(outerFilterString);
+        doNothing().when(context).addServiceListener(any(ServiceListener.class), eq(outerFilterString));
         ServiceReference<?>[] toBeReturned = {serviceReference};
-        doReturn(toBeReturned).when(context).getServiceReferences((String) null, filterString);
+        doReturn(toBeReturned).when(context).getServiceReferences(NetconfOperationProvider.class.getName(), null);
+
+        String innerFilterString = "innerfilter";
+        doReturn(innerFilterString).when(outerFilter).toString();
+
+        doReturn(innerFilter).when(context).createFilter(ConfigPersisterActivator.getFilterString());
+        doReturn(innerFilterString).when(innerFilter).toString();
+        doNothing().when(context).addServiceListener(any(ServiceListener.class), eq(innerFilterString));
+
+        doReturn(toBeReturned).when(context).getServiceReferences((String) null, innerFilterString);
         doReturn(bundle).when(serviceReference).getBundle();
         doReturn(context).when(bundle).getBundleContext();
         doReturn("").when(serviceReference).toString();
@@ -66,6 +76,7 @@ final class MockedBundleContext {
         doReturn(service).when(serviceFactory).createService(anyString());
         doReturn(Collections.emptySet()).when(service).getCapabilities();
         doNothing().when(service).close();
+        doReturn("serviceFactoryMock").when(serviceFactory).toString();
     }
 
     public BundleContext getBundleContext() {
index 7b872db9a66a72dd89da334533f15916cf25d93c..2590ad8b118141a2def9cc5190303e9ef0a48489 100644 (file)
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-            </plugin>
 
             <plugin>
                 <groupId>org.apache.felix</groupId>
index f1e5764ca6bf5983fae7aa69cd3749b2878e481b..bd2f1cc807f43cec20a6dc9279df060a9fde810c 100644 (file)
                 <groupId>org.opendaylight.yangtools</groupId>
                 <artifactId>yang-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-            </plugin>
 
             <plugin>
                 <groupId>org.apache.felix</groupId>
index e2a2d832c779e37f3e26c2d86efc37fb27d1b345..dcd2ffad55e28518edd6d64bed944f8734db2187 100644 (file)
@@ -15,7 +15,5 @@ public interface NetconfOperationRouter extends AutoCloseable {
     Document onNetconfMessage(Document message, NetconfSession session)
             throws NetconfDocumentedException;
 
-    @Override
-    void close();
 
 }
index 9de3071060ac5a67f58fc687f153adcdf15d57ba..a15f9e092576c6d2a26f4168bc978a2b3140a773 100644 (file)
@@ -22,4 +22,9 @@ public class NetconfTerminationReason implements TerminationReason {
     public String getErrorMessage() {
         return reason;
     }
+
+    @Override
+    public String toString() {
+        return reason;
+    }
 }
index b0f5f748106ab499ab95983cbb358f84536dbd66..25ed0e7ab120b3b926f2c1cfc5b48ffae4e3a9d4 100644 (file)
                     </instructions>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.4</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 
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 (file)
index 6ae966d..0000000
+++ /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 (file)
index 4cdca20..0000000
+++ /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<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strat);
-        this.address = address;
-        clientSession = get(clientFuture);
-        this.sessionId = clientSession.getSessionId();
-    }
-
-    private NetconfClientSession get(Future<NetconfClientSession> 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<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strategy);
-        this.address = address;
-        clientSession = get(clientFuture);
-        this.sessionId = clientSession.getSessionId();
-    }
-
-    public Future<NetconfMessage> 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<String> getCapabilities() {
-        Preconditions.checkState(clientSession != null, "Client was not initialized successfully");
-        return Sets.newHashSet(clientSession.getServerCapabilities());
-    }
-
-    public NetconfClientSession getClientSession() {
-        return clientSession;
-    }
-}
index bb372b3affc3e379bbff702805d7db6cca2b6b7f..cff214401c0ff2ac8a24548adda3e44c8a4f186b 100644 (file)
@@ -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,
index e96161c29ad08e36f128252fd805903c3bd3139b..504e4c994915aeafc5d303fc2a56ab4bcf2722d8 100644 (file)
@@ -101,7 +101,7 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
         }
     }
 
-    final synchronized Future<NetconfMessage> sendRequest(NetconfMessage message) {
+    public final synchronized Future<NetconfMessage> sendRequest(NetconfMessage message) {
         final RequestEntry req = new RequestEntry(GlobalEventExecutor.INSTANCE.<NetconfMessage>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 (file)
index 1357201..0000000
+++ /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 (file)
index 0000000..32c6ea8
--- /dev/null
@@ -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<NetconfClientSession> clientFuture = netconfClientDispatcher.createClient(address, sessionListener, strat);
+        clientSession = get(clientFuture);
+        this.sessionId = clientSession.getSessionId();
+    }
+
+    private NetconfClientSession get(Future<NetconfClientSession> 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<NetconfMessage> 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<String> getCapabilities() {
+        Preconditions.checkState(clientSession != null, "Client was not initialized successfully");
+        return Sets.newHashSet(clientSession.getServerCapabilities());
+    }
+}
\ No newline at end of file
index 76a0bd9908ac571a911f7309c33eb91a42ef87cd..4e78b2e4d640994ef12f1d8c5efe45b553496553 100644 (file)
             <artifactId>netconf-client</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>netconf-client</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
         <dependency>
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>commons.logback_settings</artifactId>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
                 <version>2.4</version>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
             </plugin>
         </plugins>
     </build>
index e0d7e319be8b1be2bd9fa8305dea9eb65f6d8870..6a86ecd21f4d81fdfa9db9de1a81d6e28e1d9488 100644 (file)
@@ -12,9 +12,9 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot;
 import org.opendaylight.controller.netconf.mapping.api.Capability;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index ee9009762e8cda9d3f2ac8896f2df8bced568f83..130818b12a7d6e040ff863b1026e9e9101d81385 100644 (file)
@@ -12,13 +12,12 @@ import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Promise;
-
-import java.net.InetSocketAddress;
-
 import org.opendaylight.controller.netconf.impl.util.DeserializerExceptionHandler;
 import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
 
+import java.net.InetSocketAddress;
+
 public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSession, NetconfServerSessionListener> {
 
     private final ServerChannelInitializer initializer;
@@ -44,12 +43,11 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSes
         public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
 
         private final NetconfServerSessionNegotiatorFactory negotiatorFactory;
-        private final NetconfServerSessionListenerFactory listenerFactory;
 
-        public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory,
-                                            NetconfServerSessionListenerFactory listenerFactory) {
+
+        public ServerChannelInitializer(NetconfServerSessionNegotiatorFactory negotiatorFactory) {
             this.negotiatorFactory = negotiatorFactory;
-            this.listenerFactory = listenerFactory;
+
         }
 
         @Override
@@ -60,7 +58,8 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSes
 
         @Override
         protected void initializeSessionNegotiator(SocketChannel ch, Promise<NetconfServerSession> promise) {
-            ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR, negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise));
+            ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
+                    negotiatorFactory.getSessionNegotiator(null, ch, promise));
         }
     }
 
index f8d9a45c201ed993ca081e27ecb995e743974d4a..86cfac0b606537973ab1bdeb32bcbad3d23aba7a 100644 (file)
@@ -8,8 +8,8 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import static com.google.common.base.Preconditions.checkState;
-
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;
@@ -25,8 +25,7 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
+import static com.google.common.base.Preconditions.checkState;
 
 public class NetconfServerSessionListener implements NetconfSessionListener<NetconfServerSession> {
     public static final String MESSAGE_ID = "message-id";
@@ -34,10 +33,13 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
     static final Logger logger = LoggerFactory.getLogger(NetconfServerSessionListener.class);
     private final SessionMonitoringService monitoringService;
     private final NetconfOperationRouter operationRouter;
+    private final AutoCloseable onSessionDownCloseable;
 
-    public NetconfServerSessionListener(NetconfOperationRouter operationRouter, SessionMonitoringService monitoringService) {
+    public NetconfServerSessionListener(NetconfOperationRouter operationRouter, SessionMonitoringService monitoringService,
+                                        AutoCloseable onSessionDownCloseable) {
         this.operationRouter = operationRouter;
         this.monitoringService = monitoringService;
+        this.onSessionDownCloseable = onSessionDownCloseable;
     }
 
     @Override
@@ -46,11 +48,24 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
     }
 
     @Override
-    public void onSessionDown(NetconfServerSession netconfNetconfServerSession, Exception e) {
-        logger.debug("Session {} down, reason: {}", netconfNetconfServerSession, e.getMessage());
+    public void onSessionDown(NetconfServerSession netconfNetconfServerSession, Exception cause) {
+        logger.debug("Session {} down, reason: {}", netconfNetconfServerSession, cause.getMessage());
+        onDown(netconfNetconfServerSession);
+    }
+
+    public void onDown(NetconfServerSession netconfNetconfServerSession) {
         monitoringService.onSessionDown(netconfNetconfServerSession);
 
-        operationRouter.close();
+        try {
+            operationRouter.close();
+        } catch (Exception closingEx) {
+            logger.debug("Ignoring exception while closing operationRouter", closingEx);
+        }
+        try {
+            onSessionDownCloseable.close();
+        } catch(Exception ex){
+            logger.debug("Ignoring exception while closing onSessionDownCloseable", ex);
+        }
     }
 
     @Override
@@ -58,9 +73,7 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
             NetconfTerminationReason netconfTerminationReason) {
         logger.debug("Session {} terminated, reason: {}", netconfNetconfServerSession,
                 netconfTerminationReason.getErrorMessage());
-        monitoringService.onSessionDown(netconfNetconfServerSession);
-
-        operationRouter.close();
+        onDown(netconfNetconfServerSession);
     }
 
     @Override
index 7e047b14fccda2b07a4f04e2320b096780f97501..b947d9184d75b190ced83e04d1533a6441882733 100644 (file)
@@ -11,41 +11,32 @@ package org.opendaylight.controller.netconf.impl;
 import org.opendaylight.controller.netconf.api.NetconfOperationRouter;
 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationRouterImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot;
 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
 
 public class NetconfServerSessionListenerFactory implements SessionListenerFactory<NetconfServerSessionListener> {
 
-    private final NetconfOperationServiceFactoryListener factoriesListener;
-
     private final DefaultCommitNotificationProducer commitNotifier;
-
-    private final SessionIdProvider idProvider;
-
     private final SessionMonitoringService monitor;
+    private final NetconfOperationServiceSnapshot netconfOperationServiceSnapshot;
+    private final CapabilityProvider capabilityProvider;
+
+    public NetconfServerSessionListenerFactory(DefaultCommitNotificationProducer commitNotifier,
+                                               SessionMonitoringService monitor,
+                                               NetconfOperationServiceSnapshot netconfOperationServiceSnapshot,
+                                               CapabilityProvider capabilityProvider) {
 
-    public NetconfServerSessionListenerFactory(NetconfOperationServiceFactoryListener factoriesListener,
-                                               DefaultCommitNotificationProducer commitNotifier,
-                                               SessionIdProvider idProvider, SessionMonitoringService monitor) {
-        this.factoriesListener = factoriesListener;
         this.commitNotifier = commitNotifier;
-        this.idProvider = idProvider;
         this.monitor = monitor;
+        this.netconfOperationServiceSnapshot = netconfOperationServiceSnapshot;
+        this.capabilityProvider = capabilityProvider;
     }
 
     @Override
     public NetconfServerSessionListener getSessionListener() {
-        NetconfOperationServiceSnapshot netconfOperationServiceSnapshot = factoriesListener.getSnapshot(idProvider
-                .getCurrentSessionId());
-
-        CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot);
-
         NetconfOperationRouter operationRouter = NetconfOperationRouterImpl.createOperationRouter(
-                netconfOperationServiceSnapshot, capabilityProvider,
-                commitNotifier);
-
-        return new NetconfServerSessionListener(operationRouter, monitor);
+                netconfOperationServiceSnapshot, capabilityProvider, commitNotifier);
+        return new NetconfServerSessionListener(operationRouter, monitor, netconfOperationServiceSnapshot);
     }
 }
index f8024922cfc5a5ba021e97b519493ae80a02c4d2..5c389fa966af340ef277f5d51ebe992b2c6081ff 100644 (file)
@@ -8,8 +8,10 @@
 
 package org.opendaylight.controller.netconf.impl;
 
-import java.net.InetSocketAddress;
-
+import com.google.common.base.Optional;
+import io.netty.channel.Channel;
+import io.netty.util.Timer;
+import io.netty.util.concurrent.Promise;
 import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
 import org.opendaylight.controller.netconf.util.AbstractNetconfSessionNegotiator;
 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
@@ -17,11 +19,7 @@ import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAddi
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-
-import io.netty.channel.Channel;
-import io.netty.util.Timer;
-import io.netty.util.concurrent.Promise;
+import java.net.InetSocketAddress;
 
 public class NetconfServerSessionNegotiator extends
         AbstractNetconfSessionNegotiator<NetconfServerSessionPreferences, NetconfServerSession, NetconfServerSessionListener> {
@@ -52,4 +50,4 @@ public class NetconfServerSessionNegotiator extends
         return new NetconfServerSession(sessionListener, channel, getSessionPreferences().getSessionId(), parsedHeader);
     }
 
-   }
+}
index 4c551a60209fc09068b966f8af9e8f4fe8503cf3..9ffb8da1dd975fc6592e2b789e49e7f5492e0069 100644 (file)
@@ -19,7 +19,9 @@ import javax.xml.xpath.XPathExpression;
 
 import org.opendaylight.controller.netconf.api.NetconfServerSessionPreferences;
 import org.opendaylight.controller.netconf.impl.mapping.CapabilityProvider;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
+import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
 import org.opendaylight.controller.netconf.util.NetconfUtil;
 import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage;
 import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil;
@@ -35,6 +37,8 @@ import org.w3c.dom.Node;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
+import static org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider.NetconfOperationProviderUtil.getNetconfSessionIdForReporting;
+
 public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorFactory<NetconfHelloMessage, NetconfServerSession, NetconfServerSessionListener> {
 
     public static final String SERVER_HELLO_XML_LOCATION = "/server_hello.xml";
@@ -43,15 +47,20 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
 
     private static final Document helloMessageTemplate = loadHelloMessageTemplate();
     private final SessionIdProvider idProvider;
-    private final NetconfOperationServiceFactoryListener factoriesListener;
+    private final NetconfOperationProvider netconfOperationProvider;
     private final long connectionTimeoutMillis;
+    private final DefaultCommitNotificationProducer commitNotificationProducer;
+    private final SessionMonitoringService monitoringService;
 
-    public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationServiceFactoryListener factoriesListener,
-            SessionIdProvider idProvider, long connectionTimeoutMillis) {
+    public NetconfServerSessionNegotiatorFactory(Timer timer, NetconfOperationProvider netconfOperationProvider,
+                                                 SessionIdProvider idProvider, long connectionTimeoutMillis,
+                                                 DefaultCommitNotificationProducer commitNot, SessionMonitoringService monitoringService) {
         this.timer = timer;
-        this.factoriesListener = factoriesListener;
+        this.netconfOperationProvider = netconfOperationProvider;
         this.idProvider = idProvider;
         this.connectionTimeoutMillis = connectionTimeoutMillis;
+        this.commitNotificationProducer = commitNot;
+        this.monitoringService = monitoringService;
     }
 
     private static Document loadHelloMessageTemplate() {
@@ -62,13 +71,30 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
         return NetconfUtil.createMessage(resourceAsStream).getDocument();
     }
 
+    /**
+     *
+     * @param defunctSessionListenerFactory will not be taken into account as session listener factory can
+     *                                      only be created after snapshot is opened, thus this method constructs
+     *                                      proper session listener factory.
+     * @param channel Underlying channel
+     * @param promise Promise to be notified
+     * @return session negotiator
+     */
     @Override
-    public SessionNegotiator<NetconfServerSession> getSessionNegotiator(SessionListenerFactory<NetconfServerSessionListener> sessionListenerFactory, Channel channel,
-            Promise<NetconfServerSession> promise) {
+    public SessionNegotiator<NetconfServerSession> getSessionNegotiator(SessionListenerFactory<NetconfServerSessionListener> defunctSessionListenerFactory,
+                                                                        Channel channel, Promise<NetconfServerSession> promise) {
         long sessionId = idProvider.getNextSessionId();
+        NetconfOperationServiceSnapshot netconfOperationServiceSnapshot = netconfOperationProvider.openSnapshot(
+                getNetconfSessionIdForReporting(sessionId));
+        CapabilityProvider capabilityProvider = new CapabilityProviderImpl(netconfOperationServiceSnapshot);
+
+        NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences(
+                createHelloMessage(sessionId, capabilityProvider), sessionId);
+
+        NetconfServerSessionListenerFactory sessionListenerFactory = new NetconfServerSessionListenerFactory(
+                commitNotificationProducer, monitoringService,
+                netconfOperationServiceSnapshot, capabilityProvider);
 
-        NetconfServerSessionPreferences proposal = new NetconfServerSessionPreferences(createHelloMessage(sessionId),
-                sessionId);
         return new NetconfServerSessionNegotiator(proposal, promise, channel, timer,
                 sessionListenerFactory.getSessionListener(), connectionTimeoutMillis);
     }
@@ -78,7 +104,7 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
     private static final XPathExpression capabilitiesXPath = XMLNetconfUtil
             .compileXPath("/netconf:hello/netconf:capabilities");
 
-    private NetconfHelloMessage createHelloMessage(long sessionId) {
+    private NetconfHelloMessage createHelloMessage(long sessionId, CapabilityProvider capabilityProvider) {
         Document helloMessageTemplate = getHelloTemplateClone();
 
         // change session ID
@@ -90,8 +116,6 @@ public class NetconfServerSessionNegotiatorFactory implements SessionNegotiatorF
         final Element capabilitiesElement = (Element) XmlUtil.evaluateXPath(capabilitiesXPath, helloMessageTemplate,
                 XPathConstants.NODE);
 
-        CapabilityProvider capabilityProvider = new CapabilityProviderImpl(factoriesListener.getSnapshot(sessionId));
-
         for (String capability : capabilityProvider.getCapabilities()) {
             final Element capabilityElement = XmlUtil.createElement(helloMessageTemplate, XmlNetconfConstants.CAPABILITY, Optional.<String>absent());
             capabilityElement.setTextContent(capability);
index 2b48f5d51c5877d6441a9052e75b5aae283ac2c2..f31233987e97531a563fca3f186fee480e6b6616 100644 (file)
@@ -8,8 +8,6 @@
 
 package org.opendaylight.controller.netconf.impl.mapping.operations;
 
-import java.util.Collections;
-
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
 import org.opendaylight.controller.netconf.util.mapping.AbstractSingletonNetconfOperation;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
@@ -20,6 +18,8 @@ import org.w3c.dom.Element;
 
 import com.google.common.base.Optional;
 
+import java.util.Collections;
+
 public class DefaultCloseSession extends AbstractSingletonNetconfOperation {
     public static final String CLOSE_SESSION = "close-session";
     private final AutoCloseable sessionResources;
index b8dc9550c7f1fff5b4a544d3be0bc68f07f6d235..bbd07e42bf515c46dec0a6900bd2105f3140596f 100644 (file)
@@ -12,9 +12,9 @@ import io.netty.util.HashedWheelTimer;
 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
-import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFactory;
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -34,7 +34,6 @@ public class NetconfImplActivator implements BundleActivator {
 
     private NetconfOperationServiceFactoryTracker factoriesTracker;
     private DefaultCommitNotificationProducer commitNot;
-    private NetconfServerDispatcher dispatch;
     private NioEventLoopGroup eventLoopGroup;
     private HashedWheelTimer timer;
     private ServiceRegistration<NetconfMonitoringService> regMonitoring;
@@ -50,25 +49,26 @@ public class NetconfImplActivator implements BundleActivator {
         SessionIdProvider idProvider = new SessionIdProvider();
         timer = new HashedWheelTimer();
         long connectionTimeoutMillis = NetconfConfigUtil.extractTimeoutMillis(context);
-        NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
-                timer, factoriesListener, idProvider, connectionTimeoutMillis);
+
 
         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
 
-        NetconfMonitoringServiceImpl monitoringService = startMonitoringService(context, factoriesListener);
+        SessionMonitoringService monitoringService = startMonitoringService(context, factoriesListener);
 
-        NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
-                factoriesListener, commitNot, idProvider, monitoringService);
+        NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
+                timer, factoriesListener, idProvider, connectionTimeoutMillis, commitNot, monitoringService);
 
         eventLoopGroup = new NioEventLoopGroup();
 
         NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
-                serverNegotiatorFactory, listenerFactory);
-        dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
+                serverNegotiatorFactory);
+        NetconfServerDispatcher dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
 
         logger.info("Starting TCP netconf server at {}", address);
         dispatch.createServer(address);
 
+        context.registerService(NetconfOperationProvider.class, factoriesListener, null);
+
     }
 
     private void startOperationServiceFactoryTracker(BundleContext context, NetconfOperationServiceFactoryListenerImpl factoriesListener) {
index 505c74714a71c269ad9721497cdbffaedd4fb706..a7560fadb602cc450f84c71e2f9936cb131cd495 100644 (file)
@@ -16,7 +16,9 @@ import io.netty.util.internal.ConcurrentSet;
 import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession;
 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.controller.netconf.mapping.api.Capability;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.Yang;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Schemas;
@@ -40,10 +42,10 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, S
     private static final Logger logger = LoggerFactory.getLogger(NetconfMonitoringServiceImpl.class);
 
     private final Set<NetconfManagementSession> sessions = new ConcurrentSet<>();
-    private final NetconfOperationServiceFactoryListener factoriesListener;
+    private final NetconfOperationProvider netconfOperationProvider;
 
-    public NetconfMonitoringServiceImpl(NetconfOperationServiceFactoryListener factoriesListener) {
-        this.factoriesListener = factoriesListener;
+    public NetconfMonitoringServiceImpl(NetconfOperationProvider netconfOperationProvider) {
+        this.netconfOperationProvider = netconfOperationProvider;
     }
 
     @Override
@@ -56,7 +58,7 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, S
     @Override
     public void onSessionDown(NetconfManagementSession session) {
         logger.debug("Session {} down", session);
-        Preconditions.checkState(sessions.contains(session) == true, "Session %s not present", session);
+        Preconditions.checkState(sessions.contains(session), "Session %s not present", session);
         sessions.remove(session);
     }
 
@@ -67,17 +69,23 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, S
 
     @Override
     public Schemas getSchemas() {
-        // FIXME, session ID
         // capabilities should be split from operations (it will allow to move getSchema operation to monitoring module)
-        return transformSchemas(factoriesListener.getSnapshot(0));
+        try (NetconfOperationServiceSnapshot snapshot = netconfOperationProvider.openSnapshot("netconf-monitoring")) {
+            return transformSchemas(snapshot.getServices());
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new IllegalStateException("Exception while closing", e);
+        }
     }
 
-    private Schemas transformSchemas(NetconfOperationServiceSnapshot snapshot) {
+    private Schemas transformSchemas(Set<NetconfOperationService> services) {
         Set<Capability> caps = Sets.newHashSet();
 
         List<Schema> schemas = Lists.newArrayList();
 
-        for (NetconfOperationService netconfOperationService : snapshot.getServices()) {
+
+        for (NetconfOperationService netconfOperationService : services) {
             // TODO check for duplicates ? move capability merging to snapshot
             // Split capabilities from operations first and delete this duplicate code
             caps.addAll(netconfOperationService.getCapabilities());
@@ -86,8 +94,9 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, S
         for (Capability cap : caps) {
             SchemaBuilder builder = new SchemaBuilder();
 
-            if(cap.getCapabilitySchema().isPresent() == false)
+            if (cap.getCapabilitySchema().isPresent() == false) {
                 continue;
+            }
 
             Preconditions.checkState(cap.getModuleNamespace().isPresent());
             builder.setNamespace(new Uri(cap.getModuleNamespace().get()));
@@ -102,7 +111,7 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, S
 
             builder.setFormat(Yang.class);
 
-            builder.setLocation(transformLocations(cap.getLocation().or(Collections.<String> emptyList())));
+            builder.setLocation(transformLocations(cap.getLocation().or(Collections.<String>emptyList())));
 
             builder.setKey(new SchemaKey(Yang.class, identifier, version));
 
index a35851445381f8bdcfd3142d036b9c3c34280d13..80ba8388efe6671275bdfadc67d7b07979d1f6f2 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.controller.netconf.mapping.api.HandlingPriority;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperation;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -107,11 +108,11 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
             String errorMessage = String.format("Unable to handle rpc %s on session %s", messageAsString, session);
             Map<String, String> errorInfo = Maps.newHashMap();
 
-            NetconfDocumentedException.ErrorTag tag = null;
+            NetconfDocumentedException.ErrorTag tag;
             if (e instanceof IllegalArgumentException) {
                 errorInfo.put(NetconfDocumentedException.ErrorTag.operation_not_supported.toString(), e.getMessage());
                 tag = NetconfDocumentedException.ErrorTag.operation_not_supported;
-            } else if (e instanceof IllegalStateException) {
+            } else {
                 errorInfo.put(NetconfDocumentedException.ErrorTag.operation_failed.toString(), e.getMessage());
                 tag = NetconfDocumentedException.ErrorTag.operation_failed;
             }
@@ -130,7 +131,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     }
 
     @Override
-    public void close() {
+    public void close() throws Exception {
         netconfOperationServiceSnapshot.close();
     }
 
index 385ad09754f1a3b85b72febe63478d3a0c5b2899..8e1052cfeb71da6f776d3d0c8aebe6a502a0f2c5 100644 (file)
@@ -16,5 +16,5 @@ public interface NetconfOperationServiceFactoryListener {
 
     void onRemoveNetconfOperationServiceFactory(NetconfOperationServiceFactory service);
 
-    NetconfOperationServiceSnapshot getSnapshot(long sessionId);
+
 }
index 134c38ba971bcfd510386f112ed6cf00c1a941c4..63cd0baf347f8821a2f639cac5fca55cf4eae774 100644 (file)
@@ -7,12 +7,14 @@
  */
 package org.opendaylight.controller.netconf.impl.osgi;
 
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
+
 import java.util.HashSet;
 import java.util.Set;
 
-import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
-
-public class NetconfOperationServiceFactoryListenerImpl implements NetconfOperationServiceFactoryListener {
+public class NetconfOperationServiceFactoryListenerImpl implements NetconfOperationServiceFactoryListener,
+        NetconfOperationProvider {
     private final Set<NetconfOperationServiceFactory> allFactories = new HashSet<>();
 
     @Override
@@ -26,8 +28,8 @@ public class NetconfOperationServiceFactoryListenerImpl implements NetconfOperat
     }
 
     @Override
-    public synchronized NetconfOperationServiceSnapshot getSnapshot(long sessionId) {
-        return new NetconfOperationServiceSnapshot(allFactories, sessionId);
+    public synchronized NetconfOperationServiceSnapshotImpl openSnapshot(String sessionIdForReporting) {
+        return new NetconfOperationServiceSnapshotImpl(allFactories, sessionIdForReporting);
     }
 
 }
@@ -10,62 +10,46 @@ package org.opendaylight.controller.netconf.impl.osgi;
 
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot;
+import org.opendaylight.controller.netconf.util.CloseableUtil;
 
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
-public class NetconfOperationServiceSnapshot implements AutoCloseable {
-    private static final Logger logger = LoggerFactory.getLogger(NetconfOperationServiceSnapshot.class);
+public class NetconfOperationServiceSnapshotImpl implements NetconfOperationServiceSnapshot {
 
     private final Set<NetconfOperationService> services;
     private final String netconfSessionIdForReporting;
 
-    public NetconfOperationServiceSnapshot(Set<NetconfOperationServiceFactory> factories, long sessionId) {
+    public NetconfOperationServiceSnapshotImpl(Set<NetconfOperationServiceFactory> factories, String sessionIdForReporting) {
         Set<NetconfOperationService> services = new HashSet<>();
-        netconfSessionIdForReporting = getNetconfSessionIdForReporting(sessionId);
+        netconfSessionIdForReporting = sessionIdForReporting;
         for (NetconfOperationServiceFactory factory : factories) {
             services.add(factory.createService(netconfSessionIdForReporting));
         }
         this.services = Collections.unmodifiableSet(services);
     }
 
-    private static String getNetconfSessionIdForReporting(long sessionId) {
-        return "netconf session id " + sessionId;
-    }
 
+
+    @Override
     public String getNetconfSessionIdForReporting() {
         return netconfSessionIdForReporting;
     }
 
+    @Override
     public Set<NetconfOperationService> getServices() {
         return services;
     }
 
     @Override
-    public void close() {
-        RuntimeException firstException = null;
-        for (NetconfOperationService service : services) {
-            try {
-                service.close();
-            } catch (RuntimeException e) {
-                logger.warn("Got exception while closing {}", service, e);
-                if (firstException == null) {
-                    firstException = e;
-                } else {
-                    firstException.addSuppressed(e);
-                }
-            }
-        }
-        if (firstException != null) {
-            throw firstException;
-        }
+    public void close() throws Exception {
+        CloseableUtil.closeAll(services);
     }
 
     @Override
     public String toString() {
-        return "NetconfOperationServiceSnapshot{" + netconfSessionIdForReporting + '}';
+        return "NetconfOperationServiceSnapshotImpl{" + netconfSessionIdForReporting + '}';
     }
 }
index c1a7b1478b3edde41ea5f13004afc48df540c6bf..db5a359d7a16c72784911a447b2756de36356b42 100644 (file)
@@ -18,10 +18,9 @@ import org.apache.commons.io.IOUtils;
 import org.junit.After;
 import org.junit.Before;
 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;
@@ -53,7 +52,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doNothing;
-import static org.mockito.MockitoAnnotations.initMocks;
+import static org.mockito.Mockito.mock;
 
 public class ConcurrentClientsTest {
 
@@ -68,14 +67,20 @@ public class ConcurrentClientsTest {
     private DefaultCommitNotificationProducer commitNot;
     private NetconfServerDispatcher dispatch;
 
-    @Mock
-    private SessionMonitoringService monitoring;
+
 
     HashedWheelTimer hashedWheelTimer;
 
+    public static SessionMonitoringService createMockedMonitoringService() {
+        SessionMonitoringService monitoring = mock(SessionMonitoringService.class);
+        doNothing().when(monitoring).onSessionUp(any(NetconfServerSession.class));
+        doNothing().when(monitoring).onSessionDown(any(NetconfServerSession.class));
+        return monitoring;
+    }
+
     @Before
     public void setUp() throws Exception {
-        initMocks(this);
+
         nettyGroup = new NioEventLoopGroup();
         NetconfHelloMessageAdditionalHeader additionalHeader = new NetconfHelloMessageAdditionalHeader("uname", "10.10.10.1", "830", "tcp", "client");
         netconfClientDispatcher = new NetconfClientDispatcher( nettyGroup, nettyGroup, additionalHeader, 5000);
@@ -86,16 +91,13 @@ public class ConcurrentClientsTest {
         SessionIdProvider idProvider = new SessionIdProvider();
         hashedWheelTimer = new HashedWheelTimer();
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
-                hashedWheelTimer, factoriesListener, idProvider, 5000);
+                hashedWheelTimer, factoriesListener, idProvider, 5000, commitNot, createMockedMonitoringService());
 
         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
 
-        doNothing().when(monitoring).onSessionUp(any(NetconfServerSession.class));
-        doNothing().when(monitoring).onSessionDown(any(NetconfServerSession.class));
 
-        NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
-                factoriesListener, commitNot, idProvider, monitoring);
-        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory);
+
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory);
         dispatch = new NetconfServerDispatcher(serverChannelInitializer, nettyGroup, nettyGroup);
 
         ChannelFuture s = dispatch.createServer(netconfAddress);
@@ -259,13 +261,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);
index 9835c2393ba489e7dcf7ead4ceca119beef7f63b..42bd033c712d22daf600322680739b1f7b9f2b10 100644 (file)
@@ -15,7 +15,6 @@ import io.netty.util.HashedWheelTimer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
 
 import java.lang.management.ManagementFactory;
@@ -28,22 +27,21 @@ public class NetconfDispatcherImplTest {
     private DefaultCommitNotificationProducer commitNot;
     private HashedWheelTimer hashedWheelTimer;
 
+
     @Before
     public void setUp() throws Exception {
         nettyGroup = new NioEventLoopGroup();
 
         commitNot = new DefaultCommitNotificationProducer(
                 ManagementFactory.getPlatformMBeanServer());
-        NetconfOperationServiceFactoryListener factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
+        NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
 
         SessionIdProvider idProvider = new SessionIdProvider();
         hashedWheelTimer = new HashedWheelTimer();
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
-                hashedWheelTimer, factoriesListener, idProvider, 5000);
+                hashedWheelTimer, factoriesListener, idProvider, 5000, commitNot, ConcurrentClientsTest.createMockedMonitoringService());
 
-        NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
-                factoriesListener, commitNot, idProvider, null);
-        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory, listenerFactory);
+        NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(serverNegotiatorFactory);
 
         dispatch = new NetconfServerDispatcher(
                 serverChannelInitializer, nettyGroup, nettyGroup);
index aab939e8d90933dedc0dfb496d6db1ada9e48217..3ca79be9d9d1cafca126370f768ef8f68f2a90f0 100644 (file)
@@ -1,6 +1,9 @@
 <?xml version="1.0"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
+    <properties>
+        <tinybundles.version>2.0.0</tinybundles.version>
+    </properties>
 
     <parent>
         <artifactId>netconf-subsystem</artifactId>
             <artifactId>netconf-client</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>netconf-client</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>config-netconf-connector</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>netty-config-api</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>config-manager</artifactId>
             <artifactId>netconf-impl</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>netconf-impl</artifactId>
+            <scope>test</scope>
+            <type>test-jar</type>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>netconf-monitoring</artifactId>
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>commons.logback_settings</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.tinybundles</groupId>
+            <artifactId>tinybundles</artifactId>
+            <version>${tinybundles.version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
index b261218bf1c17129b6761b48668519b5ca99ab29..b81f950cb362cf8f810201bfe98c983e1bf0988d 100644 (file)
@@ -15,7 +15,6 @@ import org.junit.Before;
 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
-import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFactory;
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
@@ -39,14 +38,10 @@ public class AbstractNetconfConfigTest extends AbstractConfigTest {
         SessionIdProvider idProvider = new SessionIdProvider();
 
         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
-                hashedWheelTimer, factoriesListener, idProvider, 5000);
-
-        NetconfServerSessionListenerFactory listenerFactory = new NetconfServerSessionListenerFactory(
-                factoriesListener, commitNotifier, idProvider,
-                sessionMonitoringService);
+                hashedWheelTimer, factoriesListener, idProvider, 5000, commitNotifier, sessionMonitoringService);
 
         NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
-                serverNegotiatorFactory, listenerFactory);
+                serverNegotiatorFactory);
         return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
     }
 
index 997cae0f7cf258a8a3074af1f525ea17347b1ce1..fc1c73f7b08a663e6b876f827710a0928d7e5deb 100644 (file)
@@ -25,16 +25,16 @@ 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;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl;
 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
 import org.opendaylight.controller.netconf.mapping.api.Capability;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
@@ -57,7 +57,7 @@ import java.util.Set;
 
 import static junit.framework.Assert.assertEquals;
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
@@ -78,7 +78,7 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest {
         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(NetconfITTest.getModuleFactoriesS().toArray(
                 new ModuleFactory[0])));
 
-        NetconfMonitoringServiceImpl monitoringService = new NetconfMonitoringServiceImpl(getFactoriesListener());
+        NetconfMonitoringServiceImpl monitoringService = new NetconfMonitoringServiceImpl(getNetconfOperationProvider());
 
         NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
         factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));
@@ -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, "<modules");
                     assertResponse(response, "<services");
@@ -178,15 +178,15 @@ public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest {
     }
 
 
-    public NetconfOperationServiceFactoryListener getFactoriesListener() {
-        NetconfOperationServiceFactoryListener factoriesListener = mock(NetconfOperationServiceFactoryListener.class);
-        NetconfOperationServiceSnapshot snap = mock(NetconfOperationServiceSnapshot.class);
+    public NetconfOperationProvider getNetconfOperationProvider() {
+        NetconfOperationProvider factoriesListener = mock(NetconfOperationProvider.class);
+        NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class);
         NetconfOperationService service = mock(NetconfOperationService.class);
         Set<Capability> caps = Sets.newHashSet();
         doReturn(caps).when(service).getCapabilities();
         Set<NetconfOperationService> services = Sets.newHashSet(service);
         doReturn(services).when(snap).getServices();
-        doReturn(snap).when(factoriesListener).getSnapshot(anyLong());
+        doReturn(snap).when(factoriesListener).openSnapshot(anyString());
 
         return factoriesListener;
     }
index 6989bf512fb702f2b6a3b32b15f803134b27c654..e45a249ad4e1f901075060451c6865a5fd54b585 100644 (file)
@@ -14,10 +14,10 @@ import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
 import org.opendaylight.controller.config.spi.ModuleFactory;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException;
-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;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
@@ -91,7 +91,7 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest {
     @Test
     public void testSecure() throws Exception {
         NetconfClientDispatcher dispatch = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup, 5000);
-        try (NetconfClient netconfClient = new NetconfClient("tls-client", tlsAddress, 4000, dispatch))  {
+        try (TestingNetconfClient netconfClient = new TestingNetconfClient("tls-client", tlsAddress, 4000, dispatch))  {
 
         }
     }
index 4ca9690211c87bccd6ee79ddc23985c191024653..ae4a9bf4b2af8a14a937039c8505e0a7fc5aaf5f 100644 (file)
@@ -28,16 +28,16 @@ import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMX
 import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory;
 import org.opendaylight.controller.netconf.StubUserManager;
 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.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl;
 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
 import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
@@ -71,7 +71,7 @@ import static java.util.Collections.emptyList;
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertTrue;
-import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
@@ -118,11 +118,11 @@ public class NetconfITTest extends AbstractNetconfConfigTest {
     }
 
     static NetconfMonitoringServiceImpl getNetconfMonitoringListenerService() {
-        NetconfOperationServiceFactoryListener factoriesListener = mock(NetconfOperationServiceFactoryListener.class);
-        NetconfOperationServiceSnapshot snap = mock(NetconfOperationServiceSnapshot.class);
+        NetconfOperationProvider netconfOperationProvider = mock(NetconfOperationProvider.class);
+        NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class);
         doReturn(Collections.<NetconfOperationService>emptySet()).when(snap).getServices();
-        doReturn(snap).when(factoriesListener).getSnapshot(anyLong());
-        return new NetconfMonitoringServiceImpl(factoriesListener);
+        doReturn(snap).when(netconfOperationProvider).openSnapshot(anyString());
+        return new NetconfMonitoringServiceImpl(netconfOperationProvider);
     }
 
     @After
@@ -176,7 +176,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest {
 
     @Test
     public void testNetconfClientDemonstration() throws Exception {
-        try (NetconfClient netconfClient = new NetconfClient("client", tcpAddress, 4000, clientDispatcher)) {
+        try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", tcpAddress, 4000, clientDispatcher)) {
 
             Set<String> 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 = "<rpc message-id=\"5\" a=\"a\" b=\"44\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
                     + "<get/>" + "</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 = "<rpc message-id=\"1\" a=\"adada\" b=\"4\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
                     + "<commit/>" + "</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 = "<rpc message-id=\"5\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
@@ -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;
     }
index 4af66532a18ec2d8a8fc067f61a777905f4011a2..e36261c6eb4803b68498c592860d15f65381f357 100644 (file)
@@ -7,54 +7,54 @@
  */
 package org.opendaylight.controller.netconf.it;
 
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
+import com.google.common.base.Charsets;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
 import io.netty.channel.ChannelFuture;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
 import junit.framework.Assert;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.matchers.JUnitMatchers;
 import org.mockito.Mock;
 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
 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.confignetconfconnector.osgi.YangStoreException;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListener;
+import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
-import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshot;
+import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl;
 import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService;
 import org.opendaylight.controller.netconf.mapping.api.Capability;
 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService;
 import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringActivator;
 import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService;
 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
+import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 
-import com.google.common.base.Charsets;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
 
 public class NetconfMonitoringITTest extends AbstractNetconfConfigTest {
 
@@ -75,7 +75,7 @@ public class NetconfMonitoringITTest extends AbstractNetconfConfigTest {
         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(NetconfITTest.getModuleFactoriesS().toArray(
                 new ModuleFactory[0])));
 
-        monitoringService = new NetconfMonitoringServiceImpl(getFactoriesListener());
+        monitoringService = new NetconfMonitoringServiceImpl(getNetconfOperationProvider());
 
         NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
         factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));
@@ -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);
         }
@@ -171,16 +171,17 @@ public class NetconfMonitoringITTest extends AbstractNetconfConfigTest {
 
     private void assertSessionElementsInResponse(Document document, int i) {
         int elementSize = document.getElementsByTagName("session-id").getLength();
-        Assert.assertEquals(i, elementSize);
+        Assert.assertEquals("Incorrect number of session-id tags in " + XmlUtil.toString(document),i, elementSize);
     }
 
     private NetconfMessage loadGetMessage() throws Exception {
         return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/get.xml");
     }
 
-    public static NetconfOperationServiceFactoryListener getFactoriesListener() {
-        NetconfOperationServiceFactoryListener factoriesListener = mock(NetconfOperationServiceFactoryListener.class);
-        NetconfOperationServiceSnapshot snap = mock(NetconfOperationServiceSnapshot.class);
+    public static NetconfOperationProvider getNetconfOperationProvider() throws Exception {
+        NetconfOperationProvider factoriesListener = mock(NetconfOperationProvider.class);
+        NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class);
+        doNothing().when(snap).close();
         NetconfOperationService service = mock(NetconfOperationService.class);
         Set<Capability> caps = Sets.newHashSet();
         caps.add(new Capability() {
@@ -218,7 +219,7 @@ public class NetconfMonitoringITTest extends AbstractNetconfConfigTest {
         doReturn(caps).when(service).getCapabilities();
         Set<NetconfOperationService> services = Sets.newHashSet(service);
         doReturn(services).when(snap).getServices();
-        doReturn(snap).when(factoriesListener).getSnapshot(anyLong());
+        doReturn(snap).when(factoriesListener).openSnapshot(anyString());
 
         return factoriesListener;
     }
index c75adbba8d775845ef6623dbc9f296cedbe9f88a..18275ad78b0c53081fee38fdbfbffb7f34aa6867 100644 (file)
@@ -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",
-                        "<afi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity1</afi>",
-                        "<afi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity2</afi>",
-                        "<safi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity2</safi>",
-                        "<safi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity1</safi>");
-            }
+        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",
+                    "<afi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity1</afi>",
+                    "<afi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity2</afi>",
+                    "<safi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity2</safi>",
+                    "<safi xmlns:prefix=\"urn:opendaylight:params:xml:ns:yang:controller:config:test:types\">prefix:test-identity1</safi>");
 
             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/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationProvider.java b/opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationProvider.java
new file mode 100644 (file)
index 0000000..f5c50f8
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.mapping.api;
+
+public interface NetconfOperationProvider {
+
+    NetconfOperationServiceSnapshot openSnapshot(String sessionIdForReporting);
+
+    public static class NetconfOperationProviderUtil {
+
+        public static String getNetconfSessionIdForReporting(long sessionId) {
+            return "netconf session id " + sessionId;
+        }
+
+    }
+
+}
similarity index 54%
rename from opendaylight/config/yang-test-plugin/src/main/resources/Header.txt
rename to opendaylight/netconf/netconf-mapping-api/src/main/java/org/opendaylight/controller/netconf/mapping/api/NetconfOperationServiceSnapshot.java
index 068fd26844b003f5b8770c0b049a66521a7d0426..eaa69379f763ec74e7fb8fbb251ad5e35ed67896 100644 (file)
@@ -4,4 +4,15 @@
  * 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
- */
\ No newline at end of file
+ */
+
+package org.opendaylight.controller.netconf.mapping.api;
+
+import java.util.Set;
+
+public interface NetconfOperationServiceSnapshot extends AutoCloseable {
+    String getNetconfSessionIdForReporting();
+
+    Set<NetconfOperationService> getServices();
+
+}
diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/CloseableUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/CloseableUtil.java
new file mode 100644 (file)
index 0000000..27960df
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.util;
+
+public class CloseableUtil {
+
+    public static void closeAll(Iterable<? extends AutoCloseable> autoCloseables) throws Exception {
+        Exception lastException = null;
+        for (AutoCloseable autoCloseable : autoCloseables) {
+            try {
+                autoCloseable.close();
+            } catch (Exception e) {
+                if (lastException == null) {
+                    lastException = e;
+                } else {
+                    lastException.addSuppressed(e);
+                }
+            }
+        }
+        if (lastException != null) {
+            throw lastException;
+        }
+
+    }
+}
index 2be64a8a9873f138ae29876a2ac1c1d1998213e4..ab71180ba9ae626f84a5da6e80f2930d5b7ef416 100644 (file)
@@ -47,7 +47,6 @@
         <osgi.version>5.0.0</osgi.version>
         <maven.bundle.version>2.4.0</maven.bundle.version>
         <slf4j.version>1.7.2</slf4j.version>
-        <salGeneratorPath>${project.build.directory}/generated-sources/sal</salGeneratorPath>
     </properties>
 
     <dependencies>
                 <artifactId>netconf-impl</artifactId>
                 <version>${netconf.version}</version>
             </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>netconf-impl</artifactId>
+                <version>${netconf.version}</version>
+                <type>test-jar</type>
+            </dependency>
             <dependency>
                 <groupId>${project.groupId}</groupId>
                 <artifactId>netconf-monitoring</artifactId>
                         </dependency>
                     </dependencies>
                 </plugin>
-                <plugin>
-                    <groupId>org.codehaus.mojo</groupId>
-                    <artifactId>build-helper-maven-plugin</artifactId>
-                    <version>1.7</version>
-                    <executions>
-                        <execution>
-                            <phase>generate-sources</phase>
-                            <goals>
-                                <goal>add-source</goal>
-                            </goals>
-                            <configuration>
-                                <sources>
-                                    <source>${salGeneratorPath}</source>
-                                </sources>
-                            </configuration>
-                        </execution>
-                    </executions>
-                </plugin>
             </plugins>
 
         </pluginManagement>
index 4aa4e0328be3d9051e2cbb4f6f798b1992fd53bd..6de347fdded0b541fd2c6cf01ec62131314c632b 100644 (file)
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>build-helper-maven-plugin</artifactId>
-        <version>1.8</version>
         <executions>
           <execution>
             <id>attach-artifacts</id>