Merge "Added karaf branding."
authorEd Warnicke <eaw@cisco.com>
Wed, 11 Jun 2014 19:38:21 +0000 (19:38 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 11 Jun 2014 19:38:21 +0000 (19:38 +0000)
307 files changed:
opendaylight/commons/filter-valve/pom.xml [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/FilterValve.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Context.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Filter.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/FilterMapping.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Host.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/InitParam.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Parser.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/model/FilterProcessor.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcher.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/DummyFilter.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/MockedFilter.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/ParserTest.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcherTest.java [new file with mode: 0644]
opendaylight/commons/filter-valve/src/test/resources/conflicting-class.xml [new file with mode: 0644]
opendaylight/commons/filter-valve/src/test/resources/no-filter-defined.xml [new file with mode: 0644]
opendaylight/commons/filter-valve/src/test/resources/sample-cors-config.xml [new file with mode: 0644]
opendaylight/commons/opendaylight/pom.xml
opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java
opendaylight/config/pom.xml
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/fixed/FixedThreadPoolConfigBeanTest.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/gofactory/AbsFactoryGeneratedObjectFactory.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntryBuilder.java
opendaylight/distribution/opendaylight/pom.xml
opendaylight/distribution/opendaylight/src/main/resources/configuration/config.ini
opendaylight/distribution/opendaylight/src/main/resources/configuration/cors-config.xml [new file with mode: 0644]
opendaylight/distribution/opendaylight/src/main/resources/configuration/tomcat-server.xml
opendaylight/distribution/opendaylight/src/main/resources/run.sh
opendaylight/md-sal/compatibility/inventory-topology-compatibility/pom.xml
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.xtend [deleted file]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/CompatibleSwitchManager.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/CompatibleSwitchManager.xtend [deleted file]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/ConfigurableSwitchManager.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/ConfigurableSwitchManager.xtend [deleted file]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.xtend [deleted file]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyReader.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyReader.xtend [deleted file]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.xtend [deleted file]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.xtend [deleted file]
opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/ConfigurableLinkManager.java [moved from opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/ConfigurableLinkManager.xtend with 57% similarity]
opendaylight/md-sal/compatibility/pom.xml
opendaylight/md-sal/compatibility/sal-compatibility/pom.xml
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/FromSalConversionsUtils.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java [new file with mode: 0644]
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend [deleted file]
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryMapping.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/ToSalConversionsUtils.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/NodeMappingTest.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestFromSalConversionsUtils.java
opendaylight/md-sal/compatibility/sal-compatibility/src/test/java/org/opendaylight/controller/sal/compatibility/test/TestToSalConversionsUtils.java
opendaylight/md-sal/feature/src/main/resources/features.xml
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/AbstractChangeListener.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/FRMActivator.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/flow/FlowChangeListener.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/flow/FlowProvider.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/flow/FlowTransactionValidator.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/group/GroupChangeListener.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/group/GroupProvider.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/meter/MeterChangeListener.java
opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/meter/MeterProvider.java
opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/NodeChangeCommiter.java
opendaylight/md-sal/pom.xml
opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java
opendaylight/md-sal/remoterpc-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBrokerAwareActivator.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareConsumer.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareProvider.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareService.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/NotificationListener.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/RpcConsumerRegistry.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataModificationTransaction.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataProviderService.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/mount/MountProviderInstance.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/rpc/RpcContextIdentifier.java
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/rpc/RpcRoutingTable.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/BindingBrokerImplModuleFactory.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeGenerator.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/YangtoolsMappingHelper.java [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/BrokerImplClassLoader.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcMetadata.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcServiceMetadata.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeCodeGenerator.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvoker.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvokerPrototype.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RootBindingAwareBroker.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingDomConnectorDeployer.java
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/forward/DomForwardingUtils.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/BindingAwareDataReaderRouter.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/spi/DelegateProxy.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/spi/remote/RemoteRpcRouter.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/MultipleAugmentationPutsTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/UnionSerializationTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/mock/BarListener.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/mock/FooListener.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/mock/FooService.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/RpcRegistrationNullPointer.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/BrokerIntegrationTest.java
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/MessageCapturingFlowService.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/RegistrationListener.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/AsyncReadTransaction.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/AsyncWriteTransaction.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/DataProvisionService.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionCommitFailedException.java [new file with mode: 0644]
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/notify/NotificationPublishService.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/routing/MutableRoutingTable.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/routing/Route.java
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/routing/RoutingTable.java
opendaylight/md-sal/sal-common-impl/pom.xml
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/routing/AbstractDataReadRouter.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/service/DataChangeEventImpl.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/service/InitialDataChangeEventImpl.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationException.java
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/CommitHandlerTransactions.java
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/RpcErrors.java
opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ToSalPropertyClassUtils.java
opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareRpcRouter.java
opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/BindingAwareZeroMqRpcRouter.java
opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/Connector.java
opendaylight/md-sal/sal-connector-api/src/main/java/org/opendaylight/controller/sal/connector/api/RpcRouter.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/AbstractConsumer.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/Broker.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/BrokerService.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/Consumer.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/Provider.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcConsumptionRegistry.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcImplementation.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcProvisionRegistry.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcRegistrationListener.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/RpcRoutingContext.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataProviderService.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataStore.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataValidator.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationListener.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationPublishService.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/notify/NotificationService.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/statistics/DomBrokerRuntimeMXBeanImpl.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SnapshotBackedWriteTransaction.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeFactory.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerConfigActivator.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/DataBrokerImpl.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/DataTransactionImpl.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/AbstractBrokerServiceProxy.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/DataBrokerServiceProxy.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/DataProviderServiceProxy.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/NotificationRouter.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangDataUtils.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/util/YangSchemaUtils.java
opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/sal/core/spi/data/DOMStore.java
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/sal/core/spi/data/DOMStoreReadTransaction.java
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/sal/core/spi/data/DOMStoreWriteTransaction.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/api/SchemaSourceProviderFactory.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/listener/NetconfDeviceCommunicator.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/sal/NetconfDeviceRpc.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/NetconfDeviceSchemaProviderFactory.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/NetconfRemoteSchemaSourceProvider.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NodeContainerProxy.java [new file with mode: 0644]
opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModule.java
opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModuleFactory.java
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/dto/MessageWrapper.java
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/java/org/opendaylight/controller/sample/zeromq/consumer/ExampleConsumer.java
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/src/main/java/org/opendaylight/controller/sample/zeromq/provider/ExampleProvider.java
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/java/org/opendaylight/controller/sample/zeromq/test/it/RouterTest.java
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/pom.xml
opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqrouter/rest/Router.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/api/RestconfService.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestUtil.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/EmptyNodeWrapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/IdentityValuesDTO.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NodeWrapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestCodec.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/SimpleNodeWrapper.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/StructuredData.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/ListenerAdapter.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/websockets/WebSocketServer.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/websockets/WebSocketServerHandler.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/websockets/WebSocketServerInitializer.java
opendaylight/md-sal/sal-rest-connector/src/main/resources/WEB-INF/web.xml
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnJsonChoiceCaseTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonBasicDataTypesTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/json/test/CnSnToJsonLeafrefType.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnInstanceIdentifierToXmlTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/cnsn/to/xml/test/CnSnToXmlWithDataFromSeveralModulesTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyFuture.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyRpcResult.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyType.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/NormalizeNodeTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestDeleteOperationTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/CompareLf.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/Lst.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/xml/to/cnsn/test/XmlAugmentedElementToCnSnTest.java
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/augmentation/xml/data.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_case_defined_without_case.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_container.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_leaflist.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_list.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_more_choices_same_level.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_more_choices_same_level_various_paths_err.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_no_first_case.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_random_level.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_three_choices_same_level.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/choice/xml/data_various_path_err.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/xml/data_absolut_ref_to_existing_leaf.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/xml/data_from_leafref_to_leafref.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/xml/data_ref_to_non_existing_leaf.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/xml/data_ref_to_not_leaf.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/xml/data_relativ_ref_from_leaflist_to_existing_leaf.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/leafref/xml/data_relativ_ref_to_existing_leaf.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/simple-data-types/xml/data.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/simple-yang-types/xml/data.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/cnsn-to-json/simple-yang-types/xml/empty_data.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/full-versions/test-data2/data-rpc-input.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/instanceidentifier/xml/xmldata.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/parts/ietf-interfaces_interfaces_absolute_path.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/data-container.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/data-list.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/empty-data.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/identityref/xml/data-default-nmspc-in-element.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/identityref/xml/data-default-nmspc-in-parrent-element.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/identityref/xml/data-nmspc-in-parrent-element.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/identityref/xml/data-no-nmspc-value-with-prefix.xml
opendaylight/md-sal/sal-rest-connector/src/test/resources/xml-to-cnsn/identityref/xml/data-no-nmspc-value-without-prefix.xml
opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/DocProvider.java
opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/impl/ApiDocGenerator.java
opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGenerator.java
opendaylight/md-sal/sal-rest-docgen/src/main/resources/WEB-INF/web.xml
opendaylight/md-sal/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/DocGeneratorTest.java
opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/config/yang/config/kitchen_service/impl/KitchenServiceModule.java
opendaylight/md-sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/config/yang/config/kitchen_service/impl/KitchenServiceModuleFactory.java
opendaylight/md-sal/samples/toaster-it/src/test/resources/controller.xml
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsProvider.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/StatisticsRequestScheduler.java
opendaylight/md-sal/topology-lldp-discovery/src/main/java/org/opendaylight/md/controller/topology/lldp/LLDPDiscoveryListener.java
opendaylight/md-sal/topology-lldp-discovery/src/main/java/org/opendaylight/md/controller/topology/lldp/LLDPLinkAger.java
opendaylight/md-sal/topology-lldp-discovery/src/main/java/org/opendaylight/md/controller/topology/lldp/utils/LLDPDiscoveryUtils.java
opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java
opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyProvider.java
opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java [new file with mode: 0644]
opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/TopologyOperation.java [new file with mode: 0644]
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializer.java
opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/TcpClientChannelInitializer.java
opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java
opendaylight/netconf/netconf-impl/pom.xml
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/osgi/NetconfImplActivator.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-netty-util/src/main/java/org/opendaylight/controller/netconf/nettyutil/AbstractChannelInitializer.java
opendaylight/netconf/netconf-ssh/pom.xml
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/NetconfSSHServer.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProvider.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProviderInterface.java [deleted file]
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/PEMGenerator.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/osgi/NetconfSSHActivator.java
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/Handshaker.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/IOThread.java [deleted file]
opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java [deleted file]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/KeyGeneratorTest.java [deleted file]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/SSHServerTest.java [deleted file]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClient.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClientHandler.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoServer.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoServerHandler.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/ProxyServer.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/ProxyServerHandler.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/ssh/authentication/SSHServerTest.java [new file with mode: 0644]
opendaylight/netconf/netconf-ssh/src/test/resources/logback-test.xml [new file with mode: 0644]
opendaylight/netconf/netconf-tcp/pom.xml [new file with mode: 0644]
opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/netty/ProxyServer.java [new file with mode: 0644]
opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/netty/ProxyServerHandler.java [new file with mode: 0644]
opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/osgi/NetconfTCPActivator.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/pom.xml
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java
opendaylight/netconf/pom.xml
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/ContainerFlow.java
pom.xml

diff --git a/opendaylight/commons/filter-valve/pom.xml b/opendaylight/commons/filter-valve/pom.xml
new file mode 100644 (file)
index 0000000..7b5be02
--- /dev/null
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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
+  -->
+<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>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>commons.opendaylight</artifactId>
+    <version>1.4.2-SNAPSHOT</version>
+    <relativePath>../opendaylight</relativePath>
+  </parent>
+  <artifactId>filter-valve</artifactId>
+  <packaging>bundle</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>equinoxSDK381</groupId>
+      <artifactId>javax.servlet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>orbit</groupId>
+      <artifactId>org.apache.catalina</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-classic</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Fragment-Host>org.eclipse.gemini.web.tomcat</Fragment-Host>
+            <Import-Package>javax.servlet,
+                            org.apache.catalina,
+                            org.apache.catalina.connector,
+                            org.apache.catalina.valves,
+                            org.slf4j,
+                            javax.xml.bind,
+                            javax.xml.bind.annotation,
+                            org.apache.commons.io,
+                            com.google.common.base,
+                            com.google.common.collect</Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.opendaylight.yangtools</groupId>
+        <artifactId>yang-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/FilterValve.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/FilterValve.java
new file mode 100644 (file)
index 0000000..54d8be1
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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.filtervalve.cors;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Objects;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.apache.catalina.valves.ValveBase;
+import org.apache.commons.io.FileUtils;
+import org.opendaylight.controller.filtervalve.cors.jaxb.Host;
+import org.opendaylight.controller.filtervalve.cors.jaxb.Parser;
+import org.opendaylight.controller.filtervalve.cors.model.FilterProcessor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Valve that allows adding filters per context. Each context can have its own filter definitions.
+ * Main purpose is to allow externalizing security filters from application bundles to a single
+ * file per OSGi distribution.
+ */
+public class FilterValve extends ValveBase {
+    private static final Logger logger = LoggerFactory.getLogger(FilterValve.class);
+    private FilterProcessor filterProcessor;
+
+    public void invoke(final Request request, final Response response) throws IOException, ServletException {
+        if (filterProcessor == null) {
+            throw new IllegalStateException("Initialization error");
+        }
+
+        FilterChain nextValveFilterChain = new FilterChain() {
+            @Override
+            public void doFilter(ServletRequest req, ServletResponse resp) throws IOException, ServletException {
+                boolean reqEquals = Objects.equals(request, req);
+                boolean respEquals = Objects.equals(response, resp);
+                if (reqEquals == false || respEquals == false) {
+                    logger.error("Illegal change was detected by valve - request {} or " +
+                            "response {} was replaced by a filter. This is not supported by this valve",
+                            reqEquals, respEquals);
+                    throw new IllegalStateException("Request or response was replaced in a filter");
+                }
+                getNext().invoke(request, response);
+            }
+        };
+        filterProcessor.process(request, response, nextValveFilterChain);
+    }
+
+    /**
+     * Called by Tomcat when configurationFile attribute is set.
+     * @param fileName path to xml file containing valve configuration
+     * @throws Exception
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    public void setConfigurationFile(String fileName) throws Exception {
+        File configurationFile = new File(fileName);
+        if (configurationFile.exists() == false || configurationFile.canRead() == false) {
+            throw new IllegalArgumentException(
+                    "Cannot read 'configurationFile' of this valve defined in tomcat-server.xml: " + fileName);
+        }
+        String xmlContent;
+        try {
+            xmlContent = FileUtils.readFileToString(configurationFile);
+        } catch (IOException e) {
+            logger.error("Cannot read {} of this valve defined in tomcat-server.xml", fileName, e);
+            throw new IllegalStateException("Cannot read " + fileName, e);
+        }
+        Host host;
+        try {
+            host = Parser.parse(xmlContent, fileName);
+        } catch (Exception e) {
+            logger.error("Cannot parse {} of this valve defined in tomcat-server.xml", fileName, e);
+            throw new IllegalStateException("Error while parsing " + fileName, e);
+        }
+        filterProcessor = new FilterProcessor(host);
+    }
+
+    /**
+     * @see org.apache.catalina.valves.ValveBase#getInfo()
+     */
+    public String getInfo() {
+        return getClass() + "/1.0";
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Context.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Context.java
new file mode 100644 (file)
index 0000000..dbe0745
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.lang.String.format;
+
+import com.google.common.base.Optional;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import org.opendaylight.controller.filtervalve.cors.model.UrlMatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@XmlRootElement
+public class Context {
+    private static final Logger logger = LoggerFactory.getLogger(Context.class);
+
+    private String path;
+    private List<Filter> filters = new ArrayList<>();
+    private List<FilterMapping> filterMappings = new ArrayList<>();
+    private boolean initialized;
+    private UrlMatcher<Filter> urlMatcher;
+
+
+    public synchronized void initialize(String fileName, Map<String, Filter> namesToTemplates) {
+        checkState(initialized == false, "Already initialized");
+        Map<String, Filter> namesToFilters = new HashMap<>();
+        for (Filter filter : filters) {
+            try {
+                filter.initialize(fileName, Optional.fromNullable(namesToTemplates.get(filter.getFilterName())));
+            } catch (Exception e) {
+                throw new IllegalStateException(format("Error while processing filter %s of context %s, defined in %s",
+                        filter.getFilterName(), path, fileName), e);
+            }
+            namesToFilters.put(filter.getFilterName(), filter);
+        }
+        filters = Collections.unmodifiableList(new ArrayList<>(filters));
+        LinkedHashMap<String, Filter> patternMap = new LinkedHashMap<>();
+        for (FilterMapping filterMapping : filterMappings) {
+            filterMapping.initialize();
+            Filter found = namesToFilters.get(filterMapping.getFilterName());
+            if (found != null) {
+                patternMap.put(filterMapping.getUrlPattern(), found);
+            } else {
+                logger.error("Cannot find matching filter for filter-mapping {} of context {}, defined in {}",
+                        filterMapping.getFilterName(), path, fileName);
+                throw new IllegalStateException(format(
+                        "Cannot find filter for filter-mapping %s of context %s, defined in %s",
+                        filterMapping.getFilterName(), path, fileName));
+            }
+        }
+        filterMappings = Collections.unmodifiableList(new ArrayList<>(filterMappings));
+        urlMatcher = new UrlMatcher<>(patternMap);
+        initialized = true;
+    }
+
+    public List<Filter> findMatchingFilters(String pathInfo) {
+        checkState(initialized, "Not initialized");
+        return urlMatcher.findMatchingFilters(pathInfo);
+    }
+
+    @XmlAttribute(name = "path")
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        checkArgument(initialized == false, "Already initialized");
+        this.path = path;
+    }
+
+    @XmlElement(name = "filter")
+    public List<Filter> getFilters() {
+        return filters;
+    }
+
+    public void setFilters(List<Filter> filters) {
+        checkArgument(initialized == false, "Already initialized");
+        this.filters = filters;
+    }
+
+    @XmlElement(name = "filter-mapping")
+    public List<FilterMapping> getFilterMappings() {
+        return filterMappings;
+    }
+
+    public void setFilterMappings(List<FilterMapping> filterMappings) {
+        checkArgument(initialized == false, "Already initialized");
+        this.filterMappings = filterMappings;
+    }
+
+    @Override
+    public String toString() {
+        return "Context{" +
+                "path='" + path + '\'' +
+                '}';
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Filter.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Filter.java
new file mode 100644 (file)
index 0000000..3dde5b1
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.MapDifference;
+import com.google.common.collect.Maps;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@XmlRootElement
+public class Filter implements FilterConfig {
+    private static final Logger logger = LoggerFactory.getLogger(Filter.class);
+
+    private String filterName;
+    private String filterClass;
+    private List<InitParam> initParams = new ArrayList<>();
+    private javax.servlet.Filter actualFilter;
+    private boolean initialized, isTemplate;
+
+
+    /**
+     * Called in filter-template nodes defined in <Host/> node - do not actually initialize the filter.
+     * In this case filter is only used to hold values of init params to be merged with
+     * filter defined in <Context/>
+     */
+    public synchronized void initializeTemplate(){
+        checkState(initialized == false, "Already initialized");
+        for (InitParam initParam : initParams) {
+            initParam.inititialize();
+        }
+        isTemplate = true;
+        initialized = true;
+    }
+
+
+    public synchronized void initialize(String fileName, Optional<Filter> maybeTemplate) {
+        checkState(initialized == false, "Already initialized");
+        logger.trace("Initializing filter {} : {}", filterName, filterClass);
+        for (InitParam initParam : initParams) {
+            initParam.inititialize();
+        }
+        if (maybeTemplate.isPresent()) {
+            // merge non conflicting init params
+            Filter template = maybeTemplate.get();
+            checkArgument(template.isTemplate);
+            Map<String, InitParam> templateParams = template.getInitParamsMap();
+            Map<String, InitParam> currentParams = getInitParamsMap();
+            // add values of template that are not present in current
+            MapDifference<String, InitParam> difference = Maps.difference(templateParams, currentParams);
+            for (Entry<String, InitParam> templateUnique : difference.entriesOnlyOnLeft().entrySet()) {
+                initParams.add(templateUnique.getValue());
+            }
+            // merge filterClass
+            if (filterClass == null) {
+                filterClass = template.filterClass;
+            } else if (Objects.equals(filterClass, template.filterClass) == false) {
+                logger.error("Conflict detected in filter-class of {} defined in {}, template class {}, child class {}" ,
+                        filterName, fileName, template.filterClass, filterClass);
+                throw new IllegalStateException("Conflict detected in template/filter filter-class definitions," +
+                        " filter name: " + filterName + " in file " + fileName);
+            }
+        }
+        initParams = Collections.unmodifiableList(new ArrayList<>(initParams));
+        Class<?> clazz;
+        try {
+            clazz = Class.forName(filterClass);
+        } catch (Exception e) {
+            throw new IllegalStateException("Cannot instantiate class defined in filter " + filterName
+                    + " in file " + fileName, e);
+        }
+        try {
+            actualFilter = (javax.servlet.Filter) clazz.newInstance();
+        } catch (Exception e) {
+            throw new IllegalStateException("Cannot instantiate class defined in filter " + filterName
+                    + " in file " + fileName, e);
+        }
+        logger.trace("Initializing {} with following init-params:{}", filterName, getInitParams());
+        try {
+            actualFilter.init(this);
+        } catch (Exception e) {
+            throw new IllegalStateException("Cannot initialize filter " + filterName
+                    + " in file " + fileName, e);
+        }
+        initialized = true;
+    }
+
+    @Override
+    public ServletContext getServletContext() {
+        throw new UnsupportedOperationException("Getting ServletContext is currently not supported");
+    }
+
+    @Override
+    public String getInitParameter(String name) {
+        for (InitParam initParam : initParams) {
+            if (Objects.equals(name, initParam.getParamName())) {
+                return initParam.getParamValue();
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public Enumeration<String> getInitParameterNames() {
+        final Iterator<InitParam> iterator = initParams.iterator();
+        return new Enumeration<String>() {
+            @Override
+            public boolean hasMoreElements() {
+                return iterator.hasNext();
+            }
+
+            @Override
+            public String nextElement() {
+                return iterator.next().getParamName();
+            }
+        };
+    }
+
+    public javax.servlet.Filter getActualFilter() {
+        checkState(initialized, "Not initialized");
+        return actualFilter;
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+
+    @XmlElement(name = "filter-name")
+    public String getFilterName() {
+        return filterName;
+    }
+
+    public void setFilterName(String filterName) {
+        this.filterName = filterName;
+    }
+
+    @XmlElement(name = "filter-class")
+    public String getFilterClass() {
+        return filterClass;
+    }
+
+    public void setFilterClass(String filterClass) {
+        this.filterClass = filterClass;
+    }
+
+    @XmlElement(name = "init-param")
+    public List<InitParam> getInitParams() {
+        return initParams;
+    }
+
+    public void setInitParams(List<InitParam> initParams) {
+        this.initParams = initParams;
+    }
+
+
+    @Override
+    public String toString() {
+        return "Filter{" +
+                "filterName='" + filterName + '\'' +
+                '}';
+    }
+
+    public Map<String, InitParam> getInitParamsMap() {
+        Map<String, InitParam> result = new HashMap<>();
+        for (InitParam initParam : initParams) {
+            checkState(initParam.isInitialized());
+            result.put(initParam.getParamName(), initParam);
+        }
+        return result;
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/FilterMapping.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/FilterMapping.java
new file mode 100644 (file)
index 0000000..03fcbf2
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class FilterMapping {
+    private String filterName;
+    private String urlPattern;
+    private boolean initialized;
+
+    @XmlElement(name = "filter-name")
+    public String getFilterName() {
+        return filterName;
+    }
+
+    public void setFilterName(String filterName) {
+        checkArgument(initialized == false, "Already initialized");
+        this.filterName = filterName;
+    }
+
+    @XmlElement(name = "url-pattern")
+    public String getUrlPattern() {
+        return urlPattern;
+    }
+
+    public void setUrlPattern(String urlPattern) {
+        checkArgument(initialized == false, "Already initialized");
+        this.urlPattern = urlPattern;
+    }
+
+    public synchronized void initialize() {
+        checkArgument(initialized == false, "Already initialized");
+        initialized = true;
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Host.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Host.java
new file mode 100644 (file)
index 0000000..4e3c3ba
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
+import com.google.common.base.Optional;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+/**
+ * Root element, arbitrarily named Host to match tomcat-server.xml, but does not allow specifying which host
+ * name to be matched.
+ */
+@XmlRootElement(name = "Host")
+public class Host {
+    private List<Context> contexts = new ArrayList<>();
+    private List<Filter> filterTemplates = new ArrayList<>();
+    private boolean initialized;
+    private Map<String, Context> contextMap;
+
+
+    public synchronized void initialize(String fileName) {
+        checkState(initialized == false, "Already initialized");
+        Map<String, Filter> namesToTemplates = new HashMap<>();
+        for (Filter template : filterTemplates) {
+            template.initializeTemplate();
+            namesToTemplates.put(template.getFilterName(), template);
+        }
+        contextMap = new HashMap<>();
+        for (Context context : getContexts()) {
+            checkState(contextMap.containsKey(context.getPath()) == false,
+                    "Context {} already defined in {}", context.getPath(), fileName);
+            context.initialize(fileName, namesToTemplates);
+            contextMap.put(context.getPath(), context);
+        }
+        contextMap = Collections.unmodifiableMap(new HashMap<>(contextMap));
+        contexts = Collections.unmodifiableList(new ArrayList<>(contexts));
+        initialized = true;
+    }
+
+    public Optional<Context> findContext(String contextPath) {
+        checkState(initialized, "Not initialized");
+        Context context = contextMap.get(contextPath);
+        return Optional.fromNullable(context);
+    }
+
+    @XmlElement(name = "Context")
+    public List<Context> getContexts() {
+        return contexts;
+    }
+
+    public void setContexts(List<Context> contexts) {
+        checkArgument(initialized == false, "Already initialized");
+        this.contexts = contexts;
+    }
+
+    @XmlElement(name = "filter-template")
+    public List<Filter> getFilterTemplates() {
+        return filterTemplates;
+    }
+
+    public void setFilterTemplates(List<Filter> filterTemplates) {
+        checkArgument(initialized == false, "Already initialized");
+        this.filterTemplates = filterTemplates;
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/InitParam.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/InitParam.java
new file mode 100644 (file)
index 0000000..edc9e45
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class InitParam {
+    private String paramName;
+    private String paramValue;
+    private boolean initialized;
+
+    public synchronized void inititialize() {
+        checkState(initialized == false, "Already initialized");
+        initialized = true;
+    }
+
+    @XmlElement(name = "param-name")
+    public String getParamName() {
+        return paramName;
+    }
+
+    public void setParamName(String paramName) {
+        this.paramName = paramName;
+    }
+
+    @XmlElement(name = "param-value")
+    public String getParamValue() {
+        return paramValue;
+    }
+
+    public void setParamValue(String paramValue) {
+        this.paramValue = paramValue;
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    @Override
+    public String toString() {
+        return "{" + paramName + '=' + paramValue + "}";
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Parser.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/jaxb/Parser.java
new file mode 100644 (file)
index 0000000..bc4f12e
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import java.io.StringReader;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+public class Parser {
+
+    public static Host parse(String xmlFileContent, String fileName) throws JAXBException {
+        JAXBContext context = JAXBContext.newInstance(Host.class);
+        javax.xml.bind.Unmarshaller um = context.createUnmarshaller();
+        Host host = (Host) um.unmarshal(new StringReader(xmlFileContent));
+        host.initialize(fileName);
+        return host;
+    }
+
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/model/FilterProcessor.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/model/FilterProcessor.java
new file mode 100644 (file)
index 0000000..dc3e9dc
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.filtervalve.cors.model;
+
+import com.google.common.base.Optional;
+import java.io.IOException;
+import java.util.List;
+import java.util.ListIterator;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+import org.opendaylight.controller.filtervalve.cors.jaxb.Context;
+import org.opendaylight.controller.filtervalve.cors.jaxb.Filter;
+import org.opendaylight.controller.filtervalve.cors.jaxb.Host;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FilterProcessor {
+    private static final Logger logger = LoggerFactory.getLogger(FilterProcessor.class);
+
+    private final Host host;
+
+    public FilterProcessor(Host host) {
+        this.host = host;
+    }
+
+    public void process(Request request, Response response, FilterChain nextValveFilterChain)
+            throws IOException, ServletException {
+
+        String contextPath = request.getContext().getPath();
+        String pathInfo = request.getPathInfo();
+
+        Optional<Context> maybeContext = host.findContext(contextPath);
+        logger.trace("Processing context {} path {}, found {}", contextPath, pathInfo, maybeContext);
+        if (maybeContext.isPresent()) {
+            // process filters
+            Context context = maybeContext.get();
+            List<Filter> matchingFilters = context.findMatchingFilters(pathInfo);
+            FilterChain fromLast = nextValveFilterChain;
+            ListIterator<Filter> it = matchingFilters.listIterator(matchingFilters.size());
+            final boolean trace = logger.isTraceEnabled();
+            while (it.hasPrevious()) {
+                final Filter currentFilter = it.previous();
+                final FilterChain copy = fromLast;
+                fromLast = new FilterChain() {
+                    @Override
+                    public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
+                        if (trace) {
+                            logger.trace("Applying {}", currentFilter);
+                        }
+                        javax.servlet.Filter actualFilter = currentFilter.getActualFilter();
+                        actualFilter.doFilter(request, response, copy);
+                    }
+                };
+            }
+            // call first filter
+            fromLast.doFilter(request, response);
+        } else {
+            // move to next valve
+            nextValveFilterChain.doFilter(request, response);
+        }
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcher.java b/opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcher.java
new file mode 100644 (file)
index 0000000..9535fb1
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * 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.filtervalve.cors.model;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Maps.immutableEntry;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Match incoming URL with user defined patterns according to servlet specification.
+ * In the Web application deployment descriptor, the following syntax is used to define mappings:
+ * <ul>
+ * <li>A string beginning with a â€˜/’ character and ending with a â€˜/*’ suffix is used for path mapping.</li>
+ * <li>A string beginning with a â€˜*.’ prefix is used as an extension mapping.</li>
+ * <li>All other strings are used for exact matches only.</li>
+ * </ul>
+ */
+public class UrlMatcher<FILTER> {
+    private static final Logger logger = LoggerFactory.getLogger(UrlMatcher.class);
+    // order index for each FILTER is kept as Entry.value
+    private final Map<String, Entry<FILTER, Integer>> prefixMap = new HashMap<>(); // contains patterns ending with '/*', '*' is stripped from each key
+    private final Map<String, Entry<FILTER, Integer>> suffixMap = new HashMap<>(); // contains patterns starting with '*.' prefix, '*' is stripped from each key
+    private final Map<String, Entry<FILTER, Integer>> exactMatchMap = new HashMap<>(); // contains exact matches only
+
+    /**
+     * @param patternMap order preserving map containing path info pattern as key
+     */
+    public UrlMatcher(LinkedHashMap<String, FILTER> patternMap) {
+        int idx = 0;
+        for (Entry<String, FILTER> entry : patternMap.entrySet()) {
+            idx++;
+            String pattern = checkNotNull(entry.getKey());
+            FILTER value = entry.getValue();
+            Entry<FILTER, Integer> valueWithIdx = immutableEntry(value, idx);
+            if (pattern.startsWith("/") && pattern.endsWith("/*")) {
+                pattern = pattern.substring(0, pattern.length() - 1);
+                prefixMap.put(pattern, valueWithIdx);
+            } else if (pattern.startsWith("*.")) {
+                pattern = pattern.substring(1);
+                suffixMap.put(pattern, valueWithIdx);
+            } else {
+                exactMatchMap.put(pattern, valueWithIdx);
+            }
+        }
+    }
+
+    /**
+     * Find filters matching path
+     *
+     * @param pathInfo as returned by request.getPathInfo()
+     * @return list of matching filters
+     */
+    public List<FILTER> findMatchingFilters(String pathInfo) {
+        checkNotNull(pathInfo);
+        TreeMap<Integer, FILTER> sortedMap = new TreeMap<>();
+        // add matching prefixes
+        for (Entry<String, Entry<FILTER, Integer>> prefixEntry : prefixMap.entrySet()) {
+            if (pathInfo.startsWith(prefixEntry.getKey())) {
+                put(sortedMap, prefixEntry.getValue());
+            }
+        }
+        // add matching suffixes
+        for (Entry<String, Entry<FILTER, Integer>> suffixEntry : suffixMap.entrySet()) {
+            if (pathInfo.endsWith(suffixEntry.getKey())) {
+                put(sortedMap, suffixEntry.getValue());
+            }
+        }
+        // add exact match
+        Entry<FILTER, Integer> exactMatch = exactMatchMap.get(pathInfo);
+        if (exactMatch != null) {
+            put(sortedMap, exactMatch);
+        }
+        ArrayList<FILTER> filters = new ArrayList<>(sortedMap.values());
+        logger.trace("Matching filters for path {} are {}", pathInfo, filters);
+        return filters;
+    }
+
+    private void put(TreeMap<Integer, FILTER> sortedMap, Entry<FILTER, Integer> entry) {
+        sortedMap.put(entry.getValue(), entry.getKey());
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/DummyFilter.java b/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/DummyFilter.java
new file mode 100644 (file)
index 0000000..d14caf9
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import java.io.IOException;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class DummyFilter implements javax.servlet.Filter {
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void destroy() {
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/MockedFilter.java b/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/MockedFilter.java
new file mode 100644 (file)
index 0000000..56d851b
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import java.io.IOException;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class MockedFilter implements javax.servlet.Filter {
+    private FilterConfig filterConfig;
+
+    @Override
+    public void init(FilterConfig filterConfig) throws ServletException {
+        this.filterConfig = filterConfig;
+    }
+
+    public FilterConfig getFilterConfig() {
+        return filterConfig;
+    }
+
+    @Override
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void destroy() {
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/ParserTest.java b/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/jaxb/ParserTest.java
new file mode 100644 (file)
index 0000000..fc6c01b
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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.filtervalve.cors.jaxb;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+import com.google.common.base.Optional;
+import java.io.File;
+import javax.servlet.FilterConfig;
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+
+public class ParserTest {
+
+    @Test
+    public void testParsing() throws Exception {
+        File xmlFile = new File(getClass().getResource("/sample-cors-config.xml").getFile());
+        assertThat(xmlFile.canRead(), is(true));
+        String xmlFileContent = FileUtils.readFileToString(xmlFile);
+        Host host = Parser.parse(xmlFileContent, "fileName");
+        assertEquals(1, host.getContexts().size());
+        // check that MockedFilter has init params merged/replaced
+        Optional<Context> context = host.findContext("/restconf");
+        assertTrue(context.isPresent());
+        assertEquals(1, context.get().getFilters().size());
+        MockedFilter filter = (MockedFilter) context.get().getFilters().get(0).getActualFilter();
+        FilterConfig filterConfig = filter.getFilterConfig();
+        assertEquals("*", filterConfig.getInitParameter("cors.allowed.origins"));
+        assertEquals("11", filterConfig.getInitParameter("cors.preflight.maxage"));
+    }
+
+
+    @Test
+    public void testParsing_NoFilterDefined() throws Exception {
+        File xmlFile = new File(getClass().getResource("/no-filter-defined.xml").getFile());
+        assertThat(xmlFile.canRead(), is(true));
+        String xmlFileContent = FileUtils.readFileToString(xmlFile);
+        try {
+            Parser.parse(xmlFileContent, "fileName");
+            fail();
+        }catch(Exception e){
+            assertThat(e.getMessage(), containsString("Cannot find filter for filter-mapping CorsFilter"));
+        }
+    }
+
+    @Test
+    public void testConflictingClass() throws Exception {
+        File xmlFile = new File(getClass().getResource("/conflicting-class.xml").getFile());
+        assertThat(xmlFile.canRead(), is(true));
+        String xmlFileContent = FileUtils.readFileToString(xmlFile);
+        try {
+            Parser.parse(xmlFileContent, "fileName");
+            fail();
+        } catch (RuntimeException e) {
+            assertThat(e.getMessage(), containsString("Error while processing filter CorsFilter of context /restconf"));
+            assertThat(e.getCause().getMessage(), containsString("Conflict detected in template/filter filter-class definitions, filter name: CorsFilter"));
+        }
+    }
+}
diff --git a/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcherTest.java b/opendaylight/commons/filter-valve/src/test/java/org/opendaylight/controller/filtervalve/cors/model/UrlMatcherTest.java
new file mode 100644 (file)
index 0000000..07f6354
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.filtervalve.cors.model;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+
+import java.util.LinkedHashMap;
+import org.junit.Test;
+
+public class UrlMatcherTest {
+    UrlMatcher<String> urlMatcher;
+
+    @Test
+    public void test() throws Exception {
+        final String defaultFilter = "default";
+        final String exactMatchFilter = "someFilter";
+        final String jspFilter = "jspFilter";
+        final String exactMatch = "/somePath";
+        final String prefixFilter = "prefixFilter";
+        LinkedHashMap<String, String> patternMap = new LinkedHashMap<String, String>() {
+            {
+                put(exactMatch, exactMatchFilter);
+                put("/*", defaultFilter);
+                put("*.jsp", jspFilter);
+                put("/foo/*", prefixFilter);
+            }
+        };
+        urlMatcher = new UrlMatcher<>(patternMap);
+        assertMatches("/abc", defaultFilter);
+        assertMatches(exactMatch, exactMatchFilter, defaultFilter);
+        assertMatches("/some.jsp", defaultFilter, jspFilter);
+        assertMatches("/foo/bar", defaultFilter, prefixFilter);
+        assertMatches("/foo/bar.jsp", defaultFilter, jspFilter, prefixFilter);
+    }
+
+    public void assertMatches(String testedPath, String... filters) {
+        assertEquals(asList(filters), urlMatcher.findMatchingFilters(testedPath));
+    }
+
+}
diff --git a/opendaylight/commons/filter-valve/src/test/resources/conflicting-class.xml b/opendaylight/commons/filter-valve/src/test/resources/conflicting-class.xml
new file mode 100644 (file)
index 0000000..c1faf34
--- /dev/null
@@ -0,0 +1,34 @@
+<!--
+  ~ 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
+  -->
+
+<Host>
+    <filter-template>
+        <filter-name>CorsFilter</filter-name>
+        <filter-class>org.opendaylight.controller.filtervalve.cors.jaxb.MockedFilter</filter-class>
+        <init-param>
+            <param-name>cors.preflight.maxage</param-name>
+            <param-value>10</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.allowed.origins</param-name>
+            <param-value>*</param-value>
+        </init-param>
+    </filter-template>
+
+    <Context path="/restconf">
+        <filter>
+            <filter-name>CorsFilter</filter-name>
+            <!-- conflict -->
+            <filter-class>org.opendaylight.controller.filtervalve.cors.jaxb.DummyFilter</filter-class>
+        </filter>
+        <filter-mapping>
+            <filter-name>CorsFilter</filter-name>
+            <url-pattern>/*</url-pattern>
+        </filter-mapping>
+    </Context>
+</Host>
diff --git a/opendaylight/commons/filter-valve/src/test/resources/no-filter-defined.xml b/opendaylight/commons/filter-valve/src/test/resources/no-filter-defined.xml
new file mode 100644 (file)
index 0000000..521d578
--- /dev/null
@@ -0,0 +1,61 @@
+<!--
+  ~ 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
+  -->
+
+<Host>
+    <!-- Filters are allowed here, only serving as a template -->
+    <filter-template>
+        <filter-name>CorsFilter</filter-name>
+        <filter-class>org.opendaylight.controller.filtervalve.cors.jaxb.MockedFilter</filter-class>
+        <init-param>
+            <param-name>cors.allowed.origins</param-name>
+            <param-value>*</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.allowed.methods</param-name>
+            <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.allowed.headers</param-name>
+            <param-value>Content-Type,X-Requested-With,accept,authorization,
+                origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers
+            </param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.exposed.headers</param-name>
+            <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.support.credentials</param-name>
+            <param-value>true</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.preflight.maxage</param-name>
+            <param-value>10</param-value>
+        </init-param>
+    </filter-template>
+
+    <Context path="/restconf">
+        <!-- Filters are also allowed here. -->
+        <filter>
+            <filter-name>CorsFilter</filter-name>
+            <!-- init params can be added/overriden if template is used -->
+        </filter>
+        <!-- only local references are allowed -->
+        <filter-mapping>
+            <filter-name>CorsFilter</filter-name>
+            <url-pattern>/*</url-pattern>
+        </filter-mapping>
+    </Context>
+
+    <Context path="/controller/nb/v2/connectionmanager">
+        <filter-mapping>
+            <filter-name>CorsFilter</filter-name>
+            <url-pattern>/*</url-pattern>
+        </filter-mapping>
+    </Context>
+</Host>
diff --git a/opendaylight/commons/filter-valve/src/test/resources/sample-cors-config.xml b/opendaylight/commons/filter-valve/src/test/resources/sample-cors-config.xml
new file mode 100644 (file)
index 0000000..613dc82
--- /dev/null
@@ -0,0 +1,37 @@
+<!--
+  ~ 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
+  -->
+
+<Host>
+    <filter-template>
+        <filter-name>CorsFilter</filter-name>
+        <filter-class>org.opendaylight.controller.filtervalve.cors.jaxb.MockedFilter</filter-class>
+        <init-param>
+            <param-name>cors.preflight.maxage</param-name>
+            <param-value>10</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.allowed.origins</param-name>
+            <param-value>*</param-value>
+        </init-param>
+    </filter-template>
+
+    <Context path="/restconf">
+        <filter>
+            <filter-name>CorsFilter</filter-name>
+            <!-- override value -->
+            <init-param>
+                <param-name>cors.preflight.maxage</param-name>
+                <param-value>11</param-value>
+            </init-param>
+        </filter>
+        <filter-mapping>
+            <filter-name>CorsFilter</filter-name>
+            <url-pattern>/*</url-pattern>
+        </filter-mapping>
+    </Context>
+</Host>
index 927c8a3fd25a94c3f96d1d4eac1780aef6bfc50c..c3c8168bd77abcf00d84baeabad33576984c54e5 100644 (file)
@@ -65,6 +65,7 @@
     <felix.dependencymanager.version>3.1.0</felix.dependencymanager.version>
     <felix.fileinstall.version>3.1.6</felix.fileinstall.version>
     <felix.webconsole.version>4.2.0</felix.webconsole.version>
+    <filtervalve.version>1.4.2-SNAPSHOT</filtervalve.version>
     <flowprogrammer.northbound.version>0.4.2-SNAPSHOT</flowprogrammer.northbound.version>
     <flows.web.version>0.4.2-SNAPSHOT</flows.web.version>
     <forwarding.staticrouting>0.5.2-SNAPSHOT</forwarding.staticrouting>
         <artifactId>devices.web</artifactId>
         <version>${devices.web.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>filter-valve</artifactId>
+        <version>${filtervalve.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.opendaylight.controller</groupId>
         <artifactId>flowprogrammer.northbound</artifactId>
         <version>${netconf.version}</version>
         <type>test-jar</type>
       </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>netconf-tcp</artifactId>
+        <version>${netconf.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.opendaylight.controller</groupId>
         <artifactId>netconf-util</artifactId>
index 916ef9a88befa87ac8b5c17902ec6d970f23807d..fef2c7196948c007705b4444a5c9445065618648 100644 (file)
@@ -7,12 +7,16 @@
  */
 package org.opendaylight.protocol.framework;
 
+import com.google.common.base.Preconditions;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
+import io.netty.channel.ServerChannel;
+import io.netty.channel.local.LocalServerChannel;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.channel.socket.nio.NioSocketChannel;
@@ -21,22 +25,20 @@ import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
-
 import java.io.Closeable;
 import java.net.InetSocketAddress;
-
+import java.net.SocketAddress;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
 /**
  * Dispatcher class for creating servers and clients. The idea is to first create servers and clients and the run the
  * start method that will handle sockets in different thread.
  */
 public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends SessionListener<?, ?, ?>> implements Closeable {
 
-    protected interface PipelineInitializer<S extends ProtocolSession<?>> {
+
+    protected interface ChannelPipelineInitializer<CH extends Channel, S extends ProtocolSession<?>> {
         /**
          * Initializes channel by specifying the handlers in its pipeline. Handlers are protocol specific, therefore this
          * method needs to be implemented in protocol specific Dispatchers.
@@ -44,7 +46,11 @@ public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends
          * @param channel whose pipeline should be defined, also to be passed to {@link SessionNegotiatorFactory}
          * @param promise to be passed to {@link SessionNegotiatorFactory}
          */
-        void initializeChannel(SocketChannel channel, Promise<S> promise);
+        void initializeChannel(CH channel, Promise<S> promise);
+    }
+
+    protected interface PipelineInitializer<S extends ProtocolSession<?>> extends ChannelPipelineInitializer<SocketChannel, S> {
+
     }
 
 
@@ -76,25 +82,43 @@ public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends
      * @return ChannelFuture representing the binding process
      */
     protected ChannelFuture createServer(final InetSocketAddress address, final PipelineInitializer<S> initializer) {
+        return createServer(address, NioServerSocketChannel.class, initializer);
+    }
+
+    /**
+     * Creates server. Each server needs factories to pass their instances to client sessions.
+     *
+     * @param address address to which the server should be bound
+     * @param channelClass The {@link Class} which is used to create {@link Channel} instances from.
+     * @param initializer instance of PipelineInitializer used to initialize the channel pipeline
+     *
+     * @return ChannelFuture representing the binding process
+     */
+    protected <CH extends Channel> ChannelFuture createServer(SocketAddress address, Class<? extends ServerChannel> channelClass,
+                                                              final ChannelPipelineInitializer<CH, S> initializer) {
         final ServerBootstrap b = new ServerBootstrap();
-        b.childHandler(new ChannelInitializer<SocketChannel>() {
+        b.childHandler(new ChannelInitializer<CH>() {
 
             @Override
-            protected void initChannel(final SocketChannel ch) {
+            protected void initChannel(final CH ch) {
                 initializer.initializeChannel(ch, new DefaultPromise<S>(executor));
             }
         });
 
         b.option(ChannelOption.SO_BACKLOG, 128);
-        b.childOption(ChannelOption.SO_KEEPALIVE, true);
+        if (LocalServerChannel.class.equals(channelClass) == false) {
+            // makes no sense for LocalServer and produces warning
+            b.childOption(ChannelOption.SO_KEEPALIVE, true);
+        }
         customizeBootstrap(b);
 
         if (b.group() == null) {
             b.group(bossGroup, workerGroup);
         }
         try {
-            b.channel(NioServerSocketChannel.class);
+            b.channel(channelClass);
         } catch (IllegalStateException e) {
+            // FIXME: if this is ok, document why
             LOG.trace("Not overriding channelFactory on bootstrap {}", b, e);
         }
 
index 613940144bed213bc7ad76c70a288d9700844d70..5f34a9aa82d0ab35780b04862882710b7ae47fe8 100644 (file)
       </plugins>
     </pluginManagement>
     <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>2.12</version>
+        <configuration>
+          <failsOnError>false</failsOnError>
+          <failOnViolation>false</failOnViolation>
+          <configLocation>checkstyle-logging.xml</configLocation>
+          <consoleOutput>true</consoleOutput>
+          <includeTestSourceDirectory>true</includeTestSourceDirectory>
+          <sourceDirectory>${project.basedir}</sourceDirectory>
+          <includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat,**\/*.yang</includes>
+          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/${jmxGeneratorPath}\/,**\/${salGeneratorPath}\/</excludes>
+        </configuration>
+        <dependencies>
+          <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>checkstyle-logging</artifactId>
+            <version>${yangtools.version}</version>
+          </dependency>
+        </dependencies>
+        <executions>
+          <execution>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
index af7f01a6327529521dfd70e5230c4155605919c5..62b295be8d1c53e8b648f7c352ab9b0c5244e875 100644 (file)
@@ -7,12 +7,16 @@
  */
 package org.opendaylight.controller.config.threadpool.fixed;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.junit.matchers.JUnitMatchers.containsString;
 
 import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.util.ArrayList;
+import java.util.List;
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.ObjectName;
@@ -28,8 +32,11 @@ import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFacto
 import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;
 import org.opendaylight.controller.config.yang.threadpool.impl.fixed.FixedThreadPoolModuleFactory;
 import org.opendaylight.controller.config.yang.threadpool.impl.fixed.FixedThreadPoolModuleMXBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
+    private static final Logger logger = LoggerFactory.getLogger(FixedThreadPoolConfigBeanTest.class);
 
     private FixedThreadPoolModuleFactory factory;
     private final String nameInstance = "fixedInstance";
@@ -37,7 +44,7 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
     @Before
     public void setUp() {
         factory = new FixedThreadPoolModuleFactory();
-        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,factory,
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory,
                 new NamingThreadFactoryModuleFactory()));
     }
 
@@ -45,7 +52,7 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
     public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
             ConflictingVersionException {
         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-        createFixed(transaction, nameInstance, 2);
+        createFixed(transaction, nameInstance, 2, nameInstance);
 
         transaction.validateConfig();
         CommitStatus status = transaction.commit();
@@ -58,7 +65,7 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
     public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
             ValidationException {
         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-        createFixed(transaction, nameInstance, 4);
+        createFixed(transaction, nameInstance, 4, nameInstance);
 
         transaction.validateConfig();
         transaction.commit();
@@ -76,12 +83,12 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
     public void testNegative() throws ConflictingVersionException, ValidationException, InstanceAlreadyExistsException {
         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
 
-        createFixed(transaction, nameInstance, 5);
+        createFixed(transaction, nameInstance, 5, nameInstance);
         transaction.commit();
 
         transaction = configRegistryClient.createTransaction();
         try {
-            createFixed(transaction, nameInstance, 0);
+            createFixed(transaction, nameInstance, 0, nameInstance);
             fail();
         } catch (InstanceAlreadyExistsException e) {
             assertThat(
@@ -90,18 +97,35 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
         }
     }
 
+    private int countThreadsByPrefix(String prefix) {
+        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+        int result = 0;
+        List<String> names = new ArrayList<>();
+        for (ThreadInfo threadInfo : threadMXBean.dumpAllThreads(false, false)) {
+            names.add(threadInfo.getThreadName());
+            if (threadInfo.getThreadName().startsWith(prefix)) {
+                result++;
+            }
+        }
+        logger.info("Current threads {}", names);
+        return result;
+    }
+
     @Test
     public void testDestroy() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException,
-            InstanceNotFoundException {
+            InstanceNotFoundException, InterruptedException {
+
+        String prefix = org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(10);
 
         int numberOfThreads = 100;
-        int threadCount1 = ManagementFactory.getThreadMXBean().getThreadCount();
-        assertTrue("Expected less than " + numberOfThreads + " threads, got " + threadCount1, threadCount1 < numberOfThreads);
+        int threadCount1 = countThreadsByPrefix(prefix);
+        assertEquals(0, threadCount1);
         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-        createFixed(transaction, nameInstance, numberOfThreads);
+
+        createFixed(transaction, nameInstance, numberOfThreads, prefix);
         transaction.commit();
-        int threadCount2 = ManagementFactory.getThreadMXBean().getThreadCount();
-        assertTrue("Expected more than " + numberOfThreads + " threads, got " + threadCount2, threadCount2 > numberOfThreads);
+        int threadCount2 = countThreadsByPrefix(prefix);
+        assertEquals(numberOfThreads, threadCount2);
 
         transaction = configRegistryClient.createTransaction();
         transaction.destroyModule(factory.getImplementationName(), nameInstance);
@@ -109,14 +133,20 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
 
         assertBeanCount(0, factory.getImplementationName());
         assertStatus(status, 0, 0, 1);
-        int threadCount3 = ManagementFactory.getThreadMXBean().getThreadCount();
-        assertTrue("Expected less than " + numberOfThreads + " threads, got " + threadCount3, threadCount3 < numberOfThreads);
+
+        for (int i = 0; i < 60; i++) {
+            if (countThreadsByPrefix(prefix) == 0) {
+                return;
+            }
+            Thread.sleep(1000);
+        }
+        assertEquals(0, countThreadsByPrefix(prefix));
     }
 
     @Test
     public void testValidationException() throws InstanceAlreadyExistsException {
         ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-        createFixed(transaction, nameInstance, -1);
+        createFixed(transaction, nameInstance, -1, nameInstance);
         try {
             transaction.validateConfig();
             fail();
@@ -125,7 +155,7 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
         }
     }
 
-    private ObjectName createFixed(ConfigTransactionJMXClient transaction, String name, int numberOfThreads)
+    private ObjectName createFixed(ConfigTransactionJMXClient transaction, String name, int numberOfThreads, String prefix)
             throws InstanceAlreadyExistsException {
         ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), name);
         FixedThreadPoolModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, FixedThreadPoolModuleMXBean.class);
@@ -134,7 +164,7 @@ public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
         ObjectName threadFactoryON = transaction.createModule(NamingThreadFactoryModuleFactory.NAME, "naming");
         NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON,
                 NamingThreadFactoryModuleMXBean.class);
-        namingThreadFactoryModuleMXBean.setNamePrefix("prefix");
+        namingThreadFactoryModuleMXBean.setNamePrefix(prefix);
 
         mxBean.setThreadFactory(threadFactoryON);
 
index 48a6c15706a209fe5001b60c0c17e1bdf80d1c96..8c65eaad14247a8be963c1dbc1d3095c7427d4d9 100644 (file)
@@ -31,9 +31,9 @@ import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.Generated
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.JavaFileInputBuilder;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.java.TypeName;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.osgi.framework.BundleContext;
 
 public class AbsFactoryGeneratedObjectFactory {
+    private static final String BUNDLE_CONTEXT = "org.osgi.framework.BundleContext";
 
     public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright) {
         FullyQualifiedName absFactoryFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractFactoryName());
@@ -91,7 +91,7 @@ public class AbsFactoryGeneratedObjectFactory {
             "public %s createModule(String instanceName, %s dependencyResolver, %s bundleContext) {\n"+
                 "return instantiateModule(instanceName, dependencyResolver, bundleContext);\n"+
             "}\n",
-                Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(), BundleContext.class.getCanonicalName()));
+                Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(), BUNDLE_CONTEXT));
 
         b.addToBody(getCreateModule(moduleFQN, moduleFields));
 
@@ -100,12 +100,12 @@ public class AbsFactoryGeneratedObjectFactory {
                 "return new %s(new %s(NAME, instanceName), dependencyResolver, oldModule, oldInstance);\n"+
             "}\n",
                 moduleFQN, DependencyResolver.class.getCanonicalName(), moduleFQN, AutoCloseable.class.getCanonicalName(),
-                BundleContext.class.getCanonicalName(), moduleFQN, ModuleIdentifier.class.getCanonicalName()));
+                BUNDLE_CONTEXT, moduleFQN, ModuleIdentifier.class.getCanonicalName()));
 
         b.addToBody(format("\n"+
             "public %s instantiateModule(String instanceName, %s dependencyResolver, %s bundleContext) {\n"+
                 "return new %s(new %s(NAME, instanceName), dependencyResolver);\n"+
-            "}\n", moduleFQN, DependencyResolver.class.getCanonicalName(), BundleContext.class.getCanonicalName(),
+            "}\n", moduleFQN, DependencyResolver.class.getCanonicalName(), BUNDLE_CONTEXT,
                 moduleFQN, ModuleIdentifier.class.getCanonicalName()
         ));
 
@@ -118,7 +118,7 @@ public class AbsFactoryGeneratedObjectFactory {
             "@Override\n"+
             "public java.util.Set<%s> getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory dependencyResolverFactory, %s bundleContext) {\n"+
                 "return new java.util.HashSet<%s>();\n"+
-            "}\n", moduleFQN, BundleContext.class.getCanonicalName(), moduleFQN));
+            "}\n", moduleFQN, BUNDLE_CONTEXT, moduleFQN));
 
         return new GeneratedObjectBuilder(b.build()).toGeneratedObject();
     }
@@ -127,8 +127,8 @@ public class AbsFactoryGeneratedObjectFactory {
         String result = "\n"+
             "@Override\n"+
             format("public %s createModule(String instanceName, %s dependencyResolver, %s old, %s bundleContext) throws Exception {\n",
-                                Module.class.getCanonicalName(),DependencyResolver.class.getCanonicalName(),
-                                DynamicMBeanWithInstance.class.getCanonicalName(),BundleContext.class.getCanonicalName())+
+                                Module.class.getCanonicalName(), DependencyResolver.class.getCanonicalName(),
+                                DynamicMBeanWithInstance.class.getCanonicalName(), BUNDLE_CONTEXT)+
                 format("%s oldModule = null;\n",moduleFQN)+
                 "try {\n"+
                     format("oldModule = (%s) old.getModule();\n",moduleFQN)+
index 6da8dfc663b9cb1e8b8ef43a384151af7c7d18f0..89f3a4a51923a3f126f09b50af7e0d14b7af62a3 100644 (file)
@@ -18,7 +18,6 @@ import com.google.common.base.Optional;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -96,14 +95,10 @@ final class ModuleMXBeanEntryBuilder {
     // TODO: the XPath should be parsed by code generator IMO
     private static final String MAGIC_STRING = "MAGIC_STRING";
     private static final String MODULE_CONDITION_XPATH_TEMPLATE = "^/MAGIC_STRING:modules/MAGIC_STRING:module/MAGIC_STRING:type\\s*=\\s*['\"](.+)['\"]$";
-    private static final SchemaPath expectedConfigurationAugmentationSchemaPath = new SchemaPath(
-            Arrays.asList(createConfigQName("modules"),
-                    createConfigQName("module"),
-                    createConfigQName("configuration")), true);
-    private static final SchemaPath expectedStateAugmentationSchemaPath = new SchemaPath(
-            Arrays.asList(createConfigQName("modules"),
-                    createConfigQName("module"), createConfigQName("state")),
-            true);
+    private static final SchemaPath expectedConfigurationAugmentationSchemaPath = SchemaPath.create(true,
+            createConfigQName("modules"), createConfigQName("module"), createConfigQName("configuration"));
+    private static final SchemaPath expectedStateAugmentationSchemaPath = SchemaPath.create(true,
+            createConfigQName("modules"), createConfigQName("module"), createConfigQName("state"));
     private static final Pattern PREFIX_COLON_LOCAL_NAME = Pattern
             .compile("^(.+):(.+)$");
 
index 5b44bb7569b9c3df2bce4c6ef76c4741e7541061..3916e05496ab2a40fc34e2adb71fd53839172ceb 100644 (file)
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>config-persister-impl</artifactId>
         </dependency>
+        <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>filter-valve</artifactId>
+        </dependency>
         <dependency>
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>logback-config</artifactId>
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>netconf-ssh</artifactId>
         </dependency>
+        <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>netconf-tcp</artifactId>
+        </dependency>
         <dependency>
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>netconf-util</artifactId>
index f15f8f7404d1420d0efc361551c99b0355d60170..f05afbb346f7f157162b313981874c4d3d6bdd40 100644 (file)
@@ -14,13 +14,11 @@ osgi.bundles=\
 
 # Netconf startup configuration
 
-# Netconf tcp address:port is optional with default value 127.0.0.1:8383
+# Netconf tcp address:port is optional
 #netconf.tcp.address=127.0.0.1
-#netconf.tcp.port=8384
-
-#netconf.tcp.client.address=127.0.0.1
-#netconf.tcp.client.port=8384
+#netconf.tcp.port=8383
 
+# Netconf tcp address:port is optional
 netconf.ssh.address=0.0.0.0
 netconf.ssh.port=1830
 netconf.ssh.pk.path = ./configuration/RSA.pk
diff --git a/opendaylight/distribution/opendaylight/src/main/resources/configuration/cors-config.xml b/opendaylight/distribution/opendaylight/src/main/resources/configuration/cors-config.xml
new file mode 100644 (file)
index 0000000..00abf6c
--- /dev/null
@@ -0,0 +1,54 @@
+<!--
+  ~ 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
+  -->
+
+<Host>
+    <!-- Filters are allowed here, only serving as a template -->
+    <filter-template>
+        <filter-name>CorsFilter</filter-name>
+        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
+        <init-param>
+            <param-name>cors.allowed.origins</param-name>
+            <param-value>*</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.allowed.methods</param-name>
+            <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.allowed.headers</param-name>
+            <param-value>Content-Type,X-Requested-With,accept,authorization,
+                origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers
+            </param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.exposed.headers</param-name>
+            <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.support.credentials</param-name>
+            <param-value>true</param-value>
+        </init-param>
+        <init-param>
+            <param-name>cors.preflight.maxage</param-name>
+            <param-value>10</param-value>
+        </init-param>
+    </filter-template>
+
+    <Context path="/restconf">
+        <filter>
+            <filter-name>CorsFilter</filter-name>
+            <!-- init params can be added/overriden if template is used -->
+        </filter>
+        <!-- references to templates without <filter> declaration are not allowed -->
+        <filter-mapping>
+            <filter-name>CorsFilter</filter-name>
+            <url-pattern>/*</url-pattern>
+        </filter-mapping>
+    </Context>
+
+</Host>
index 56d469b59932f591b93cd91eb7e491ab3c683085..da2500be622e48cf735f5ac349de8d96c4e39c96 100644 (file)
@@ -56,6 +56,9 @@
                         rotatable="true" fileDateFormat="yyyy-MM"
                         pattern="%{yyyy-MM-dd HH:mm:ss.SSS z}t - [%a] - %r"/>
 
+          <Valve className="org.opendaylight.controller.filtervalve.cors.FilterValve"
+                 configurationFile="configuration/cors-config.xml"
+                  />
       </Host>
     </Engine>
   </Service>
index dba996a99425036ed0044514380726513671b47b..1e903d06503c286d7a0e8b41556c826eb5d6d105 100755 (executable)
@@ -13,7 +13,7 @@ if [[ $platform == 'linux' ]]; then
 
    if [[ -z ${JAVA_HOME} ]]; then
       # Find the actual location of the Java launcher:
-      java_launcher=`which java`
+      java_launcher=`command -v java`
       java_launcher=`readlink -f "${java_launcher}"`
 
       # Compute the Java home from the location of the Java launcher:
index 18fb785dd16f332f4d381de0512713521a06ab5f..fc58ed96e1b9fba37af9ff846621e107a3671440 100644 (file)
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.eclipse.xtend</groupId>
-      <artifactId>org.eclipse.xtend.lib</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>forwardingrulesmanager</artifactId>
           </instructions>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.eclipse.xtend</groupId>
-        <artifactId>xtend-maven-plugin</artifactId>
-      </plugin>
     </plugins>
   </build>
   <scm>
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.java
new file mode 100644 (file)
index 0000000..b37b501
--- /dev/null
@@ -0,0 +1,97 @@
+/**
+ * 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.compatibility.inventory;
+
+import java.util.ArrayList;
+import java.util.Set;
+
+import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider;
+import org.opendaylight.controller.sal.compatibility.InventoryMapping;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InventoryReader implements RuntimeDataProvider {
+    private static final Logger LOG = LoggerFactory.getLogger(InventoryReader.class);
+    private ISwitchManager switchManager;
+
+    public ISwitchManager getSwitchManager() {
+        return switchManager;
+    }
+
+    public void setSwitchManager(final ISwitchManager switchManager) {
+        this.switchManager = switchManager;
+    }
+
+    @Override
+    public DataObject readConfigurationData(final InstanceIdentifier<? extends DataObject> path) {
+        // Topology and Inventory are operational only
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public DataObject readOperationalData(final InstanceIdentifier<? extends DataObject> path) {
+        final Class<? extends DataObject> type = path.getTargetType();
+        if (Nodes.class.equals(type)) {
+            return readNodes(((InstanceIdentifier<Nodes>) path));
+        }
+        if (Node.class.equals(type)) {
+            return readNode(((InstanceIdentifier<Node>) path));
+        }
+        if (NodeConnector.class.equals(type)) {
+            return readNodeConnector(((InstanceIdentifier<NodeConnector>) path));
+        }
+
+        LOG.debug("Unsupported type {}", type);
+        return null;
+    }
+
+    private NodeConnector readNodeConnector(final InstanceIdentifier<NodeConnector> identifier) {
+        return constructNodeConnector(InventoryMapping.toAdNodeConnector(identifier));
+    }
+
+    private Node readNode(final InstanceIdentifier<Node> identifier) {
+        return constructNode(InventoryMapping.toAdNode(identifier));
+    }
+
+    private Node constructNode(final org.opendaylight.controller.sal.core.Node node) {
+        final Set<org.opendaylight.controller.sal.core.NodeConnector> connectors = getSwitchManager().getNodeConnectors(node);
+        final ArrayList<NodeConnector> tpList = new ArrayList<NodeConnector>(connectors.size());
+        for (final org.opendaylight.controller.sal.core.NodeConnector connector : connectors) {
+            tpList.add(constructNodeConnector(connector));
+        }
+
+        return new NodeBuilder()
+        .setKey(InventoryMapping.toNodeKey(node))
+        .setNodeConnector(tpList)
+        .build();
+    }
+
+    private Nodes readNodes(final InstanceIdentifier<Nodes> identifier) {
+        final Set<org.opendaylight.controller.sal.core.Node> nodes = getSwitchManager().getNodes();
+        final ArrayList<Node> nodeList = new ArrayList<Node>(nodes.size());
+        for (final org.opendaylight.controller.sal.core.Node node : nodes) {
+            nodeList.add(constructNode(node));
+        }
+
+        return new NodesBuilder().setNode(nodeList).build();
+    }
+
+    private static NodeConnector constructNodeConnector(final org.opendaylight.controller.sal.core.NodeConnector connector) {
+        return new NodeConnectorBuilder().setKey(InventoryMapping.toNodeConnectorKey(connector)).build();
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/inventory/InventoryReader.xtend
deleted file mode 100644 (file)
index 9b71369..0000000
+++ /dev/null
@@ -1,90 +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.md.compatibility.inventory
-
-import org.opendaylight.controller.switchmanager.ISwitchManager
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider
-import java.util.ArrayList
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
-import static extension org.opendaylight.controller.sal.compatibility.InventoryMapping.*;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder
-
-class InventoryReader implements RuntimeDataProvider {
-
-    @Property
-    var ISwitchManager switchManager;
-
-    override readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
-
-        // Topology and Inventory are operational only
-        return null;
-    }
-
-    override readOperationalData(InstanceIdentifier<? extends DataObject> path) {
-        val type = path.targetType;
-        var DataObject data = null;
-        switch (type) {
-            case Nodes:
-                data = readNodes(path as InstanceIdentifier<Nodes>)
-            case Node:
-                data = readNode(path as InstanceIdentifier<Node>)
-            case NodeConnector:
-                data = readNodeConnector(path as InstanceIdentifier<NodeConnector>)
-        }
-        return data;
-    }
-
-    def DataObject readNodeConnector(InstanceIdentifier<NodeConnector> identifier) {
-        val nodeConnector = identifier.toAdNodeConnector();
-        return constructNodeConnector(nodeConnector)
-    }
-
-    def DataObject readNode(InstanceIdentifier<Node> identifier) {
-        val node = identifier.toAdNode();
-        return constructNode(node);
-    }
-
-
-    def Node constructNode(org.opendaylight.controller.sal.core.Node node) {
-        val connectors = switchManager.getNodeConnectors(node)
-
-        val tpList = new ArrayList<NodeConnector>(connectors.size)
-        for (connector : connectors) {
-            tpList.add(constructNodeConnector(connector));
-        }
-
-        val it = new NodeBuilder()
-        key = node.toNodeKey();
-        nodeConnector = tpList
-        return build();
-    }
-
-    def NodeConnector constructNodeConnector(org.opendaylight.controller.sal.core.NodeConnector connector) {
-        val it = new NodeConnectorBuilder()
-        key = connector.toNodeConnectorKey()
-        return build();
-    }
-
-    def readNodes(InstanceIdentifier<Nodes> identifier) {
-        val nodes = switchManager.nodes
-        val nodeList = new ArrayList<Node>(nodes.size)
-        for (node : nodes) {
-            nodeList.add(constructNode(node))
-        }
-        val it = new NodesBuilder();
-        node = nodeList
-        return build()
-
-    }
-}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/CompatibleSwitchManager.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/CompatibleSwitchManager.java
new file mode 100644 (file)
index 0000000..82c5b7b
--- /dev/null
@@ -0,0 +1,347 @@
+/**
+ * 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.compatibility.switchmanager;
+
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.compatibility.NodeMapping;
+import org.opendaylight.controller.sal.core.Bandwidth;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Description;
+import org.opendaylight.controller.sal.core.ForwardingMode;
+import org.opendaylight.controller.sal.core.MacAddress;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.Tier;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.controller.switchmanager.Subnet;
+import org.opendaylight.controller.switchmanager.Switch;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CompatibleSwitchManager extends ConfigurableSwitchManager implements ISwitchManager {
+    private static final  Logger LOG = LoggerFactory.getLogger(CompatibleSwitchManager.class);
+
+    private DataBrokerService _dataService;
+
+    public DataBrokerService getDataService() {
+        return this._dataService;
+    }
+
+    public void setDataService(final DataBrokerService dataService) {
+        this._dataService = dataService;
+    }
+
+    @Override
+    public Status addNodeConnectorProp(final NodeConnector nodeConnector, final Property prop) {
+        final DataModificationTransaction it = getDataService().beginTransaction();
+        final NodeConnectorRef path = NodeMapping.toNodeConnectorRef(nodeConnector);
+        return null;
+    }
+
+    @Override
+    public Property createProperty(final String propName, final String propValue) {
+        try {
+            if (propName.equalsIgnoreCase(Description.propertyName)) {
+                return new Description(propValue);
+            } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
+                return new Tier(Integer.parseInt(propValue));
+            } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
+                return new Bandwidth(Long.parseLong(propValue));
+            } else if (propName.equalsIgnoreCase(ForwardingMode.name)) {
+                return new ForwardingMode(Integer.parseInt(propValue));
+            } else if (propName.equalsIgnoreCase(MacAddress.name)) {
+                return new MacAddress(propValue);
+            } else {
+                LOG.debug("Not able to create {} property", propName);
+            }
+        } catch (Exception e) {
+            LOG.debug("createProperty caught exception {}", e.getMessage());
+        }
+
+        return null;
+    }
+
+    @Override
+    public boolean doesNodeConnectorExist(final NodeConnector nc) {
+        return (getDataService().readOperationalData(NodeMapping.toNodeConnectorRef(nc).getValue()) != null);
+    }
+
+    @Override
+    public byte[] getControllerMAC() {
+        final Enumeration<NetworkInterface> nis;
+        try {
+            nis = NetworkInterface.getNetworkInterfaces();
+        } catch (SocketException e) {
+            LOG.error("Failed to acquire list of interfaces, cannot determine controller MAC", e);
+            return null;
+        }
+
+        while (nis.hasMoreElements()) {
+            final NetworkInterface ni = nis.nextElement();
+            try {
+                return ni.getHardwareAddress();
+            } catch (SocketException e) {
+                LOG.error("Failed to acquire controller MAC from interface {}", ni, e);
+            }
+        }
+
+        // This happens when running controller on windows VM, for example
+        // Try parsing the OS command output
+        LOG.warn("Failed to acquire controller MAC: No physical interface found");
+        return null;
+    }
+
+    @Override
+    public Map<String,Property> getControllerProperties() {
+        return Collections.<String, Property>emptyMap();
+    }
+
+    @Override
+    public Property getControllerProperty(final String propertyName) {
+        return null;
+    }
+
+    @Override
+    public List<Switch> getNetworkDevices() {
+        final InstanceIdentifier<Nodes> path = InstanceIdentifier.builder(Nodes.class).toInstance();
+        final Nodes data = ((Nodes) getDataService().readOperationalData(path));
+        final ArrayList<Switch> ret = new ArrayList<>();
+        for (final Node node : data.getNode()) {
+            try {
+                ret.add(toSwitch(node));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to create switch {}", node), e);
+            }
+        }
+        return ret;
+    }
+
+    @Override
+    public NodeConnector getNodeConnector(final org.opendaylight.controller.sal.core.Node node, final String nodeConnectorName) {
+        final NodeConnectorKey key = new NodeConnectorKey(new NodeConnectorId(nodeConnectorName));
+        try {
+            return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, node);
+        } catch (ConstructionException e) {
+            throw new IllegalStateException(String.format("Failed to create node connector for {} {}", node, nodeConnectorName), e);
+        }
+    }
+
+    @Override
+    public Property getNodeConnectorProp(final NodeConnector nodeConnector, final String propName) {
+        return getNodeConnectorProps(nodeConnector).get(propName);
+    }
+
+    @Override
+    public Map<String,Property> getNodeConnectorProps(final NodeConnector nodeConnector) {
+        final NodeConnectorRef ref = NodeMapping.toNodeConnectorRef(nodeConnector);
+        return toAdProperties(readNodeConnector(ref.getValue()));
+    }
+
+    @Override
+    public Set<NodeConnector> getNodeConnectors(final org.opendaylight.controller.sal.core.Node node) {
+        final Node data = this.readNode(NodeMapping.toNodeRef(node).getValue());
+        final HashSet<NodeConnector> ret = new HashSet<>();
+        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc : data.getNodeConnector()) {
+            try {
+                ret.add(new NodeConnector(NodeMapping.MD_SAL_TYPE, nc.getKey(), node));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to create node {} connector", node, nc.getKey()), e);
+            }
+        }
+        return ret;
+    }
+
+    @Override
+    public String getNodeDescription(final org.opendaylight.controller.sal.core.Node node) {
+        return ((Description) getNodeProps(node).get(Description.propertyName)).getValue();
+    }
+
+    @Override
+    public byte[] getNodeMAC(final org.opendaylight.controller.sal.core.Node node) {
+        return ((MacAddress) getNodeProps(node).get(MacAddress.name)).getMacAddress();
+    }
+
+    @Override
+    public Property getNodeProp(final org.opendaylight.controller.sal.core.Node node, final String propName) {
+        return getNodeProps(node).get(propName);
+    }
+
+    @Override
+    public Map<String,Property> getNodeProps(final org.opendaylight.controller.sal.core.Node node) {
+        final NodeRef ref = NodeMapping.toNodeRef(node);
+        return toAdProperties(((Node) getDataService().readOperationalData(ref.getValue())));
+    }
+
+    @Override
+    public Set<org.opendaylight.controller.sal.core.Node> getNodes() {
+        final InstanceIdentifier<Nodes> path = InstanceIdentifier.builder(Nodes.class).toInstance();
+        final Nodes data = ((Nodes) getDataService().readOperationalData(path));
+        final HashSet<org.opendaylight.controller.sal.core.Node> ret = new HashSet<>();
+        for (final Node node : data.getNode()) {
+            try {
+                ret.add(new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, node.getKey()));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to create node for {}", node), e);
+            }
+        }
+        return ret;
+    }
+
+    private static Switch toSwitch(final Node node) throws ConstructionException {
+        return new Switch(new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, node.getKey()));
+    }
+
+    @Override
+    public Set<NodeConnector> getPhysicalNodeConnectors(final org.opendaylight.controller.sal.core.Node node) {
+        final NodeRef ref = NodeMapping.toNodeRef(node);
+        final Node data = readNode(ref.getValue());
+        final HashSet<NodeConnector> ret = new HashSet<>();
+        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc : data.getNodeConnector()) {
+            final FlowCapableNodeConnector flowConnector = nc.getAugmentation(FlowCapableNodeConnector.class);
+            try {
+                ret.add(new NodeConnector(NodeMapping.MD_SAL_TYPE, nc.getKey(), node));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to create connector for {} on node {}", nc.getKey(), node), e);
+            }
+        }
+        return ret;
+    }
+
+    private static Map<String,Property> toAdProperties(final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector connector) {
+        return Collections.emptyMap();
+    }
+
+    private static Map<String,Property> toAdProperties(final Node connector) {
+        return Collections.emptyMap();
+    }
+
+    private Node readNode(final InstanceIdentifier<? extends Object> ref) {
+        return (Node) getDataService().readOperationalData((ref));
+    }
+
+    private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector readNodeConnector(final InstanceIdentifier<? extends Object> ref) {
+        return ((org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) getDataService().readOperationalData(ref));
+    }
+
+    @Override
+    public List<NodeConnector> getSpanPorts(final org.opendaylight.controller.sal.core.Node node) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public Subnet getSubnetByNetworkAddress(final InetAddress networkAddress) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public Set<NodeConnector> getUpNodeConnectors(final org.opendaylight.controller.sal.core.Node node) {
+        final Node data = readNode(NodeMapping.toNodeRef(node).getValue());
+        final HashSet<NodeConnector> ret = new HashSet<>();
+        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc : data.getNodeConnector()) {
+            final FlowCapableNodeConnector flowConn = nc.<FlowCapableNodeConnector>getAugmentation(FlowCapableNodeConnector.class);
+            if (flowConn != null && flowConn.getState() != null && !flowConn.getState().isLinkDown()) {
+                try {
+                    ret.add(new NodeConnector(NodeMapping.MD_SAL_TYPE, nc.getKey(), node));
+                } catch (ConstructionException e) {
+                    throw new IllegalStateException(String.format("Failed to create node connector for node {} connector {}", node, nc), e);
+                }
+            }
+        }
+        return ret;
+    }
+
+    @Override
+    public Boolean isNodeConnectorEnabled(final NodeConnector nodeConnector) {
+        final NodeConnectorRef ref = NodeMapping.toNodeConnectorRef(nodeConnector);
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector data = readNodeConnector(ref.getValue());
+        return true;
+    }
+
+    @Override
+    public boolean isSpecial(final NodeConnector p) {
+        final NodeConnectorRef ref = NodeMapping.toNodeConnectorRef(p);
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector data = readNodeConnector(ref.getValue());
+        return true;
+    }
+
+    @Override
+    public Status removeControllerProperty(final String propertyName) {
+        return null;
+    }
+
+    @Override
+    public Status removeNodeAllProps(final org.opendaylight.controller.sal.core.Node node) {
+        return null;
+    }
+
+    @Override
+    public Status removeNodeConnectorAllProps(final NodeConnector nodeConnector) {
+        return null;
+    }
+
+    @Override
+    public Status removeNodeConnectorProp(final NodeConnector nc, final String propName) {
+        return null;
+    }
+
+    @Override
+    public Status removeNodeProp(final org.opendaylight.controller.sal.core.Node node, final String propName) {
+        return null;
+    }
+
+    @Override
+    public Status removePortsFromSubnet(final String name, final List<String> nodeConnectors) {
+        return null;
+    }
+
+    @Override
+    public Status removeSubnet(final String name) {
+        return null;
+    }
+
+    @Override
+    public Status setControllerProperty(final Property property) {
+        return null;
+    }
+
+    @Override
+    public void setNodeProp(final org.opendaylight.controller.sal.core.Node node, final Property prop) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public Status addPortsToSubnet(final String name, final List<String> nodeConnectors) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public Set<Switch> getConfiguredNotConnectedSwitches() {
+        return null;
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/CompatibleSwitchManager.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/CompatibleSwitchManager.xtend
deleted file mode 100644 (file)
index 20d375f..0000000
+++ /dev/null
@@ -1,298 +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.md.compatibility.switchmanager
-
-import java.net.InetAddress
-import java.net.NetworkInterface
-import java.net.SocketException
-import java.util.ArrayList
-import java.util.Collections
-import java.util.HashSet
-import java.util.List
-import java.util.Map
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
-import org.opendaylight.controller.sal.core.Bandwidth
-import org.opendaylight.controller.sal.core.Description
-import org.opendaylight.controller.sal.core.ForwardingMode
-import org.opendaylight.controller.sal.core.MacAddress
-import org.opendaylight.controller.sal.core.Node
-import org.opendaylight.controller.sal.core.NodeConnector
-import org.opendaylight.controller.sal.core.Property
-import org.opendaylight.controller.sal.core.Tier
-import org.opendaylight.controller.switchmanager.ISwitchManager
-import org.opendaylight.controller.switchmanager.Switch
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.slf4j.LoggerFactory
-
-import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*
-
-class CompatibleSwitchManager extends ConfigurableSwitchManager implements ISwitchManager {
-
-    private static val log = LoggerFactory.getLogger(CompatibleSwitchManager)
-
-    @org.eclipse.xtend.lib.Property
-    var DataBrokerService dataService;
-
-    override addNodeConnectorProp(NodeConnector nodeConnector, Property prop) {
-        val it = dataService.beginTransaction
-        val path = nodeConnector.toNodeConnectorRef
-
-        // TODO: Update FlowCapableNode
-        return null;
-    }
-
-    override createProperty(String propName, String propValue) {
-        try {
-            if (propName.equalsIgnoreCase(Description.propertyName)) {
-                return new Description(propValue);
-            } else if (propName.equalsIgnoreCase(Tier.TierPropName)) {
-                val tier = Integer.parseInt(propValue);
-                return new Tier(tier);
-            } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) {
-                val bw = Long.parseLong(propValue);
-                return new Bandwidth(bw);
-            } else if (propName.equalsIgnoreCase(ForwardingMode.name)) {
-                val mode = Integer.parseInt(propValue);
-                return new ForwardingMode(mode);
-            } else if (propName.equalsIgnoreCase(MacAddress.name)) {
-                return new MacAddress(propValue);
-            } else {
-                log.debug("Not able to create {} property", propName);
-            }
-        } catch (Exception e) {
-            log.debug("createProperty caught exception {}", e.getMessage());
-        }
-        return null;
-    }
-
-    override doesNodeConnectorExist(NodeConnector nc) {
-        val ref = nc.toNodeConnectorRef
-        return dataService.readOperationalData(ref.value as InstanceIdentifier<? extends DataObject>) !== null
-    }
-
-    override getControllerMAC() {
-        var byte[] macAddress = null;
-
-        try {
-            val nis = NetworkInterface.getNetworkInterfaces();
-            while (nis.hasMoreElements()) {
-                val ni = nis.nextElement();
-                try {
-                    macAddress = ni.getHardwareAddress();
-                    return macAddress;
-                } catch (SocketException e) {
-                    log.error("Failed to acquire controller MAC: ", e);
-                }
-            }
-        } catch (SocketException e) {
-            log.error("Failed to acquire controller MAC: ", e);
-            return macAddress;
-        }
-
-        if (macAddress == null) {
-            log.warn("Failed to acquire controller MAC: No physical interface found");
-
-            // This happens when running controller on windows VM, for example
-            // Try parsing the OS command output
-            }
-            return macAddress;
-        }
-
-    override getControllerProperties() {
-        return Collections.emptyMap()
-    }
-
-    override getControllerProperty(String propertyName) {
-        return null;
-    }
-
-    override getNetworkDevices() {
-        val path = InstanceIdentifier.builder(Nodes).toInstance;
-        val data = dataService.readOperationalData(path) as Nodes;
-        val ret = new ArrayList<Switch>();
-        for (node : data.node) {
-            ret.add(node.toSwitch());
-        }
-        return ret;
-    }
-
-    override getNodeConnector(Node node, String nodeConnectorName) {
-        val key = new NodeConnectorKey(new NodeConnectorId(nodeConnectorName));
-        return new NodeConnector(MD_SAL_TYPE, key, node);
-    }
-
-    override getNodeConnectorProp(NodeConnector nodeConnector, String propName) {
-        getNodeConnectorProps(nodeConnector).get(propName);
-    }
-
-    override getNodeConnectorProps(NodeConnector nodeConnector) {
-        val ref = nodeConnector.toNodeConnectorRef
-        val data = readNodeConnector(ref.value);
-        return data.toAdProperties();
-    }
-
-    override getNodeConnectors(Node node) {
-        val ref = node.toNodeRef;
-        val data = readNode(ref.value);
-        val ret = new HashSet();
-        for (nc : data.nodeConnector) {
-
-            val adConnector = new NodeConnector(MD_SAL_TYPE, nc.key, node);
-            ret.add(adConnector);
-        }
-        return ret;
-    }
-
-    override getNodeDescription(Node node) {
-        (getNodeProps(node).get(Description.propertyName) as Description).value;
-    }
-
-    override getNodeMAC(Node node) {
-        (getNodeProps(node).get(MacAddress.name) as MacAddress).macAddress;
-    }
-
-    override getNodeProp(Node node, String propName) {
-        getNodeProps(node).get(propName)
-    }
-
-    override getNodeProps(Node node) {
-        val ref = node.toNodeRef;
-        val data = dataService.readOperationalData(ref.value as InstanceIdentifier<? extends DataObject>) as org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-        return data.toAdProperties();
-    }
-
-    override getNodes() {
-        val path = InstanceIdentifier.builder(Nodes).toInstance;
-        val data = dataService.readOperationalData(path) as Nodes;
-        val ret = new HashSet<Node>();
-        for (node : data.node) {
-            ret.add(new Node(MD_SAL_TYPE, node.key));
-        }
-        return ret;
-    }
-
-    def Switch toSwitch(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node) {
-        val adNode = new Node(MD_SAL_TYPE, node.key);
-        val sw = new Switch(adNode)
-        return sw;
-    }
-
-    override getPhysicalNodeConnectors(Node node) {
-        val ref = node.toNodeRef;
-        val data = readNode(ref.value);
-        val ret = new HashSet();
-        for (nc : data.nodeConnector) {
-            val flowConnector = nc.getAugmentation(FlowCapableNodeConnector)
-            val adConnector = new NodeConnector(MD_SAL_TYPE, nc.key, node);
-            ret.add(adConnector);
-        }
-        return ret;
-    }
-
-    def Map<String, Property> toAdProperties(
-        org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector connector) {
-        return Collections.emptyMap
-    }
-
-    def Map<String, Property> toAdProperties(
-        org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node connector) {
-        return Collections.emptyMap
-    }
-
-    def readNode(InstanceIdentifier<?> ref) {
-        dataService.readOperationalData(ref as InstanceIdentifier<? extends DataObject>) as org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
-    }
-
-    def readNodeConnector(InstanceIdentifier<?> ref) {
-        dataService.readOperationalData(ref as InstanceIdentifier<? extends DataObject>) as org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
-    }
-
-    override getSpanPorts(Node node) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override getSubnetByNetworkAddress(InetAddress networkAddress) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override getUpNodeConnectors(Node node) {
-        val ref = node.toNodeRef
-        val data = readNode(ref.value);
-        val ret = new HashSet<NodeConnector>();
-        for (nc : data.nodeConnector) {
-            val flowConn = nc.getAugmentation(FlowCapableNodeConnector);
-            if (flowConn != null && flowConn.state != null && !flowConn.state.linkDown) {
-                ret.add(new NodeConnector(MD_SAL_TYPE, nc.key, node));
-            }
-        }
-        return ret;
-    }
-
-    override isNodeConnectorEnabled(NodeConnector nodeConnector) {
-        val ref = nodeConnector.toNodeConnectorRef
-        val data = readNodeConnector(ref.value);
-
-        return true;
-    }
-
-    override isSpecial(NodeConnector p) {
-        val ref = p.toNodeConnectorRef
-        val data = readNodeConnector(ref.value);
-
-        return true;
-    }
-
-    override removeControllerProperty(String propertyName) {
-        // NOOP
-    }
-
-    override removeNodeAllProps(Node node) {
-        // NOOP: not supported node has more properties than AD-SAL is capable to see
-    }
-
-    override removeNodeConnectorAllProps(NodeConnector nodeConnector) {
-        // NOOP: not supported node has more properties than AD-SAL is capable to see
-    }
-
-    override removeNodeConnectorProp(NodeConnector nc, String propName) {
-        // NOOP: not supported node has more properties than AD-SAL is capable to see
-    }
-
-    override removeNodeProp(Node node, String propName) {
-        // NOOP: not supported node has more properties than AD-SAL is capable to see
-    }
-
-    override removePortsFromSubnet(String name, List<String> nodeConnectors) {
-        // NOOP
-    }
-
-    override removeSubnet(String name) {
-        // NOOP
-    }
-
-    override setControllerProperty(Property property) {
-        // NOOP
-    }
-
-    override setNodeProp(Node node, Property prop) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override addPortsToSubnet(String name, List<String> nodeConnectors) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override getConfiguredNotConnectedSwitches() {
-        return null;
-    }
-}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/ConfigurableSwitchManager.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/ConfigurableSwitchManager.java
new file mode 100644 (file)
index 0000000..63f682a
--- /dev/null
@@ -0,0 +1,86 @@
+/**
+ * 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.compatibility.switchmanager;
+
+import java.util.List;
+
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.controller.switchmanager.SpanConfig;
+import org.opendaylight.controller.switchmanager.SubnetConfig;
+import org.opendaylight.controller.switchmanager.SwitchConfig;
+
+/**
+ * These methods should be backed by config subsystem.
+ */
+public abstract class ConfigurableSwitchManager implements ISwitchManager {
+    @Override
+    public Status saveSwitchConfig() {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public Status removeSpanConfig(final SpanConfig cfgObject) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public Status addSubnet(final SubnetConfig configObject) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final Status addSpanConfig(final SpanConfig configObject) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final List<SpanConfig> getSpanConfigList() {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final void updateSwitchConfig(final SwitchConfig cfgObject) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final Status updateNodeConfig(final SwitchConfig switchConfig) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final SubnetConfig getSubnetConfig(final String subnet) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final Status removeNodeConfig(final String nodeId) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final Status removeSubnet(final SubnetConfig configObject) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final List<SubnetConfig> getSubnetsConfigList() {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public final SwitchConfig getSwitchConfig(final String nodeId) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public Status modifySubnet(final SubnetConfig configObject) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/ConfigurableSwitchManager.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/switchmanager/ConfigurableSwitchManager.xtend
deleted file mode 100644 (file)
index faa4b8d..0000000
+++ /dev/null
@@ -1,78 +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.md.compatibility.switchmanager
-
-import org.opendaylight.controller.switchmanager.ISwitchManager
-import org.opendaylight.controller.switchmanager.SpanConfig
-import org.opendaylight.controller.switchmanager.SwitchConfig
-import org.opendaylight.controller.switchmanager.SubnetConfig
-
-/**
- * 
- * THis methods should be backed by config subsystem.
- * 
- */
-abstract class ConfigurableSwitchManager implements ISwitchManager {
-
-    override saveSwitchConfig() {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override removeSpanConfig(SpanConfig cfgObject) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override addSubnet(SubnetConfig configObject) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-
-    }
-
-    final override addSpanConfig(SpanConfig configObject) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-
-    }
-
-    final override getSpanConfigList() {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-
-    }
-
-    final override updateSwitchConfig(SwitchConfig cfgObject) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-
-    }
-
-    final override updateNodeConfig(SwitchConfig switchConfig) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-
-    }
-
-    final override getSubnetConfig(String subnet) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    final override removeNodeConfig(String nodeId) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    final override removeSubnet(SubnetConfig configObject) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    final override getSubnetsConfigList() {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    final override getSwitchConfig(String nodeId) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override modifySubnet(SubnetConfig configObject) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.java
new file mode 100644 (file)
index 0000000..8e50bd8
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * 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.compatibility.topology;
+
+import java.util.Iterator;
+
+import org.opendaylight.controller.sal.compatibility.InventoryMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+import com.google.common.base.Splitter;
+
+public class TopologyMapping {
+    private static final String HEAD_TAIL_STRING = "::::";
+    private static final Splitter HEAD_TAIL_SPLITTER = Splitter.on(HEAD_TAIL_STRING);
+
+    public TopologyMapping(final TopologyKey path, final InstanceIdentifier<Topology> key) {
+        // No-op for now. Multi-instance will require fixing InventoryMapping first.
+    }
+
+    public Edge toAdTopologyEdge(final InstanceIdentifier<Link> identifier) throws ConstructionException {
+        @SuppressWarnings("unchecked")
+        final LinkKey linkKey = ((KeyedInstanceIdentifier<Link, LinkKey>)identifier).getKey();
+
+        final Iterator<String> it = HEAD_TAIL_SPLITTER.split(linkKey.getLinkId().getValue()).iterator();
+        final NodeConnector tail = InventoryMapping.nodeConnectorFromId(it.next());
+        final NodeConnector head = InventoryMapping.nodeConnectorFromId(it.next());
+        return new Edge(tail, head);
+    }
+
+    public NodeConnector toAdTopologyNodeConnector(final InstanceIdentifier<TerminationPoint> identifier) {
+        @SuppressWarnings("unchecked")
+        final TerminationPointKey tpKey = ((KeyedInstanceIdentifier<TerminationPoint, TerminationPointKey>)identifier).getKey();
+
+        return InventoryMapping.nodeConnectorFromId(tpKey.getTpId().getValue());
+    }
+
+    public org.opendaylight.controller.sal.core.Node toAdTopologyNode(final InstanceIdentifier<Node> identifier) {
+        @SuppressWarnings("unchecked")
+        final NodeKey nodeKey = ((KeyedInstanceIdentifier<Node, NodeKey>)identifier).getKey();
+
+        return InventoryMapping.nodeFromNodeId(nodeKey.getNodeId().getValue());
+    }
+
+    public NodeKey toTopologyNodeKey(final org.opendaylight.controller.sal.core.Node node) {
+        return new NodeKey(new NodeId(InventoryMapping.toNodeId(node)));
+    }
+
+    public TerminationPointKey toTopologyTerminationPointKey(final NodeConnector nc) {
+        return new TerminationPointKey(new TpId(InventoryMapping.toNodeConnectorId(nc)));
+    }
+
+    public LinkKey toTopologyLinkKey(final Edge edge) {
+        final TerminationPointKey sourceTp = toTopologyTerminationPointKey(edge.getTailNodeConnector());
+        final TerminationPointKey destTp = toTopologyTerminationPointKey(edge.getHeadNodeConnector());
+
+        final StringBuilder sb = new StringBuilder();
+        sb.append(sourceTp.getTpId().toString());
+        sb.append(HEAD_TAIL_STRING);
+        sb.append(destTp.getTpId().toString());
+        return new LinkKey(new LinkId(sb.toString()));
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyMapping.xtend
deleted file mode 100644 (file)
index 0889de1..0000000
+++ /dev/null
@@ -1,74 +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.md.compatibility.topology
-
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
-import org.opendaylight.controller.sal.core.Edge
-import java.util.Set
-import org.opendaylight.controller.sal.core.Property
-import org.opendaylight.controller.sal.core.NodeConnector
-
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
-import org.opendaylight.controller.sal.compatibility.InventoryMapping
-class TopologyMapping {
-
-    new(TopologyKey path, InstanceIdentifier<Topology> key) {
-        // NOOP
-    }
-
-    def Edge toAdTopologyEdge(InstanceIdentifier<Link> identifier) {
-        val linkKey = (identifier.path.last as IdentifiableItem<Link,LinkKey>).key;
-        val components = linkKey.linkId.value.split("::::");
-        val tail = InventoryMapping.nodeConnectorFromId(components.get(0));
-        val head = InventoryMapping.nodeConnectorFromId(components.get(1));
-        return new Edge(tail, head);
-    }
-
-    def NodeConnector toAdTopologyNodeConnector(InstanceIdentifier<TerminationPoint> identifier) {
-        val tpKey = (identifier.path.last as IdentifiableItem<TerminationPoint,TerminationPointKey>).key;
-        return InventoryMapping.nodeConnectorFromId(tpKey.tpId.value);
-    }
-
-    def org.opendaylight.controller.sal.core.Node toAdTopologyNode(
-        InstanceIdentifier<Node> identifier) {
-        val tpKey = (identifier.path.last as IdentifiableItem<Node,NodeKey>).key;
-        return InventoryMapping.nodeFromNodeId(tpKey.nodeId.value);
-    }
-    
-
-
-    def NodeKey toTopologyNodeKey(org.opendaylight.controller.sal.core.Node node) {
-        val nodeId = new NodeId(InventoryMapping.toNodeId(node));
-        return new NodeKey(nodeId);
-    }
-
-    def TerminationPointKey toTopologyTerminationPointKey(NodeConnector nc) {
-        val node = nc.node;
-        val nodeId = new TpId(InventoryMapping.toNodeConnectorId(nc))
-        return new TerminationPointKey(nodeId);
-    }
-
-    def LinkKey toTopologyLinkKey(Edge edge) {
-        val sourceTp = edge.tailNodeConnector.toTopologyTerminationPointKey;
-        val destTp = edge.headNodeConnector.toTopologyTerminationPointKey;
-        val linkId = new LinkId('''«sourceTp.tpId»::::«destTp.tpId»''')
-        return new LinkKey(linkId);
-    }
-}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyReader.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyReader.java
new file mode 100644 (file)
index 0000000..a4ac6f9
--- /dev/null
@@ -0,0 +1,199 @@
+/**
+ * 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.compatibility.topology;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+import org.opendaylight.controller.topologymanager.ITopologyManager;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TopologyReader implements RuntimeDataProvider {
+    private static final Logger LOG = LoggerFactory.getLogger(TopologyReader.class);
+    private final InstanceIdentifier<Topology> topologyPath;
+    private final TopologyKey topologyKey;
+    private final TopologyMapping mapping;
+    private ITopologyManager topologyManager;
+    private ISwitchManager switchManager;
+
+    public ISwitchManager getSwitchManager() {
+        return this.switchManager;
+    }
+
+    public void setSwitchManager(final ISwitchManager switchManager) {
+        this.switchManager = switchManager;
+    }
+
+    public ITopologyManager getTopologyManager() {
+        return this.topologyManager;
+    }
+
+    public void setTopologyManager(final ITopologyManager topologyManager) {
+        this.topologyManager = topologyManager;
+    }
+
+    public TopologyKey getTopologyKey() {
+        return this.topologyKey;
+    }
+
+    public TopologyMapping getMapping() {
+        return this.mapping;
+    }
+
+    public TopologyReader() {
+        this.topologyKey = new TopologyKey(new TopologyId("compatibility:ad-sal"));
+        this.topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
+                .child(Topology.class, topologyKey)
+                .toInstance();
+        this.mapping = new TopologyMapping(topologyKey, topologyPath);
+    }
+
+    @Override
+    public DataObject readConfigurationData(final InstanceIdentifier<? extends DataObject> path) {
+        // Topology and Inventory are operational only
+        return null;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public DataObject readOperationalData(final InstanceIdentifier<? extends DataObject> path) {
+        if (!topologyPath.contains(path)) {
+            return null;
+        }
+
+        final Class<? extends DataObject> type = path.getTargetType();
+        if (Link.class.equals(type)) {
+            return readLink((InstanceIdentifier<Link>) path);
+        }
+        if (Node.class.equals(type)) {
+            return readNode((InstanceIdentifier<Node>) path);
+        }
+        if (TerminationPoint.class.equals(type)) {
+            return readTerminationPoint((InstanceIdentifier<TerminationPoint>) path);
+
+        }
+        if (Topology.class.equals(type)) {
+            return readTopology((InstanceIdentifier<Topology>) path);
+        }
+
+        LOG.debug("Unsupported type {}", type);
+        return null;
+    }
+
+    private Link readLink(final InstanceIdentifier<Link> identifier) {
+        final Edge edge;
+        try {
+            edge = this.mapping.toAdTopologyEdge(identifier);
+        } catch (ConstructionException e) {
+            throw new IllegalStateException(String.format("Failed to construct edge for link %s", identifier), e);
+        }
+
+        final Map<Edge,Set<Property>> edges;
+        if (topologyManager != null) {
+            edges = topologyManager.getEdges();
+        } else {
+            edges = null;
+        }
+
+        final Set<Property> properties;
+        if (edges != null) {
+            properties = edges.get(edge);
+        } else {
+            properties = null;
+        }
+
+        return constructLink(edge);
+    }
+
+    private TerminationPoint readTerminationPoint(final InstanceIdentifier<TerminationPoint> identifier) {
+        return constructTerminationPoint(mapping.toAdTopologyNodeConnector(identifier));
+    }
+
+    private Node readNode(final InstanceIdentifier<Node> identifier) {
+        return constructNode(mapping.toAdTopologyNode(identifier));
+    }
+
+    private Topology readTopology(final InstanceIdentifier<Topology> identifier) {
+        final Set<org.opendaylight.controller.sal.core.Node> nodes = getSwitchManager().getNodes();
+        final ArrayList<Node> nodeList = new ArrayList<Node>(nodes.size());
+        for (final org.opendaylight.controller.sal.core.Node node : nodes) {
+            nodeList.add(constructNode(node));
+        }
+
+        final Map<Edge,Set<Property>> edges = getTopologyManager().getEdges();
+        final ArrayList<Link> linkList = new ArrayList<Link>(edges.size());
+        for (final Edge edge : edges.keySet()) {
+            linkList.add(constructLink(edge));
+        }
+
+        return new TopologyBuilder()
+        .setKey(topologyKey)
+        .setNode(nodeList)
+        .setLink(linkList)
+        .build();
+    }
+
+    private Link constructLink(final Edge edge) {
+        final NodeConnector sourceNc = edge.getTailNodeConnector();
+        final NodeConnector destNc = edge.getHeadNodeConnector();
+
+        final LinkBuilder it = new LinkBuilder().setKey(mapping.toTopologyLinkKey(edge));
+
+        it.setSource(new SourceBuilder()
+        .setSourceNode(mapping.toTopologyNodeKey(sourceNc.getNode()).getNodeId())
+        .setSourceTp(mapping.toTopologyTerminationPointKey(sourceNc).getTpId())
+        .build());
+
+        it.setDestination(new DestinationBuilder()
+        .setDestNode(mapping.toTopologyNodeKey(destNc.getNode()).getNodeId())
+        .setDestTp(mapping.toTopologyTerminationPointKey(destNc).getTpId())
+        .build());
+
+        return it.build();
+    }
+
+    private Node constructNode(final org.opendaylight.controller.sal.core.Node node) {
+        final Set<NodeConnector> connectors = getSwitchManager().getNodeConnectors(node);
+        final ArrayList<TerminationPoint> tpList = new ArrayList<TerminationPoint>(connectors.size());
+        for (final NodeConnector connector : connectors) {
+            tpList.add(constructTerminationPoint(connector));
+        }
+
+        return new NodeBuilder()
+        .setKey(mapping.toTopologyNodeKey(node))
+        .setTerminationPoint(tpList)
+        .build();
+    }
+
+    private TerminationPoint constructTerminationPoint(final NodeConnector connector) {
+        return new TerminationPointBuilder().setKey(mapping.toTopologyTerminationPointKey(connector)).build();
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyReader.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topology/TopologyReader.xtend
deleted file mode 100644 (file)
index 6ebe20b..0000000
+++ /dev/null
@@ -1,153 +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.md.compatibility.topology
-
-import java.util.ArrayList
-import org.opendaylight.controller.sal.binding.api.data.RuntimeDataProvider
-import org.opendaylight.controller.sal.core.Edge
-import org.opendaylight.controller.sal.core.NodeConnector
-import org.opendaylight.controller.switchmanager.ISwitchManager
-import org.opendaylight.controller.topologymanager.ITopologyManager
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.DestinationBuilder
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointBuilder
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-
-class TopologyReader implements RuntimeDataProvider {
-
-    @Property
-    var ISwitchManager switchManager;
-
-    @Property
-    var ITopologyManager topologyManager;
-
-    @Property
-    val TopologyKey topologyKey;
-
-    @Property
-    val InstanceIdentifier<Topology> topologyPath;
-
-    @Property
-    val extension TopologyMapping mapping;
-
-    new() {
-        _topologyKey = new TopologyKey(new TopologyId("compatibility:ad-sal"));
-        _topologyPath = InstanceIdentifier.builder(NetworkTopology).child(Topology, topologyKey).toInstance;
-        _mapping = new TopologyMapping(topologyKey, topologyPath);
-    }
-
-    override readConfigurationData(InstanceIdentifier<? extends DataObject> path) {
-
-        // Topology and Inventory are operational only
-        return null;
-    }
-
-    override readOperationalData(InstanceIdentifier<? extends DataObject> path) {
-        val type = path.targetType;
-        var DataObject data = null;
-        if (false == topologyPath.contains(path)) {
-            return null;
-        }
-        switch (type) {
-            case Topology:
-                data = readTopology(path as InstanceIdentifier<Topology>)
-            case Node:
-                data = readNode(path as InstanceIdentifier<Node>)
-            case TerminationPoint:
-                data = readTerminationPoint(path as InstanceIdentifier<TerminationPoint>)
-            case Link:
-                data = readLink(path as InstanceIdentifier<Link>)
-        }
-        return data;
-    }
-
-    def DataObject readLink(InstanceIdentifier<Link> identifier) {
-        val edge = identifier.toAdTopologyEdge();
-        val properties = topologyManager?.edges?.get(edge);
-
-        return constructLink(edge);
-    }
-
-    def DataObject readTerminationPoint(InstanceIdentifier<TerminationPoint> identifier) {
-        val nodeConnector = identifier.toAdTopologyNodeConnector();
-        return constructTerminationPoint(nodeConnector)
-    }
-
-    def DataObject readNode(InstanceIdentifier<Node> identifier) {
-        val node = identifier.toAdTopologyNode();
-        return constructNode(node);
-    }
-
-    def DataObject readTopology(InstanceIdentifier<Topology> identifier) {
-
-        //val nodeConnectors = switchManager.
-        val nodes = switchManager.nodes
-        val edges = topologyManager.edges
-
-        val nodeList = new ArrayList<Node>(nodes.size)
-        for (node : nodes) {
-            nodeList.add(constructNode(node))
-        }
-
-        val linkList = new ArrayList<Link>(edges.size)
-        for (edge : edges.keySet) {
-            linkList.add(constructLink(edge))
-        }
-
-        val it = new TopologyBuilder();
-        key = topologyKey
-        node = nodeList
-        link = linkList
-        return build()
-    }
-
-    def constructLink(Edge edge) {
-        val sourceNc = edge.tailNodeConnector
-        val destNc = edge.headNodeConnector
-
-        val it = new LinkBuilder()
-        key = edge.toTopologyLinkKey();
-        source = new SourceBuilder().setSourceNode(sourceNc.node.toTopologyNodeKey.nodeId).setSourceTp(
-            sourceNc.toTopologyTerminationPointKey.tpId).build()
-        destination = new DestinationBuilder().setDestNode(destNc.node.toTopologyNodeKey.nodeId).setDestTp(
-            destNc.toTopologyTerminationPointKey.tpId).build
-        return build()
-    }
-
-    def Node constructNode(org.opendaylight.controller.sal.core.Node node) {
-        val connectors = switchManager.getNodeConnectors(node)
-
-        val tpList = new ArrayList<TerminationPoint>(connectors.size)
-        for (connector : connectors) {
-            tpList.add(constructTerminationPoint(connector));
-        }
-
-        val it = new NodeBuilder()
-        key = node.toTopologyNodeKey();
-        terminationPoint = tpList
-        return build();
-    }
-
-    def TerminationPoint constructTerminationPoint(NodeConnector connector) {
-        val it = new TerminationPointBuilder()
-        key = connector.toTopologyTerminationPointKey
-        return build();
-    }
-
-}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.java
new file mode 100644 (file)
index 0000000..a7a7a9a
--- /dev/null
@@ -0,0 +1,109 @@
+/**
+ * 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.compatibility.topologymanager;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.controller.sal.compatibility.NodeMapping;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Destination;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class AdSalTopologyMapping {
+    private final InstanceIdentifier<Topology> topologyPath;
+
+    public AdSalTopologyMapping(final TopologyKey topology) {
+        this.topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
+                .child(Topology.class, topology).toInstance();
+    }
+
+    public InstanceIdentifier<Topology> getTopologyPath() {
+        return topologyPath;
+    }
+
+    public InstanceIdentifier<TerminationPoint> toTerminationPoint(final NodeConnector connector) {
+        return getTopologyPath().builder()
+                .child(Node.class)
+                .child(TerminationPoint.class, toTerminationPointKey(connector))
+                .toInstance();
+    }
+
+    public Map<Edge,Set<Property>> toEdgePropertiesMap(final Iterable<Link> links) {
+        final HashMap<Edge,Set<Property>> ret = new HashMap<>();
+        for (final Link link : links) {
+            try {
+                ret.put(toEdge(link), toProperties(link));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to create edge properties for {}", link), e);
+            }
+        }
+        return ret;
+    }
+
+    public static Set<Edge> toEdges(final Iterable<Link> links) throws ConstructionException {
+        final HashSet<Edge> ret = new HashSet<Edge>();
+        for (final Link link : links) {
+            ret.add(toEdge(link));
+        }
+        return ret;
+    }
+
+    public static Edge toEdge(final Link link) throws ConstructionException {
+        final NodeConnector tail = toNodeConnector(link.getSource());
+        final NodeConnector head = toNodeConnector(link.getDestination());
+        return new Edge(tail, head);
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toAdNode(final Node node) throws ConstructionException {
+        return toAdNode(node.getNodeId());
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toAdNode(final NodeId node) throws ConstructionException {
+        final NodeKey key = new NodeKey(
+                new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId(node));
+        return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, key);
+    }
+
+    public static NodeConnector toNodeConnector(final Source ref) throws ConstructionException {
+        final org.opendaylight.controller.sal.core.Node adNode = toAdNode(ref.getSourceNode());
+        final NodeConnectorKey key = new NodeConnectorKey(new NodeConnectorId(ref.getSourceTp()));
+        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
+    }
+
+    public static NodeConnector toNodeConnector(final Destination ref) throws ConstructionException {
+        final org.opendaylight.controller.sal.core.Node adNode = toAdNode(ref.getDestNode());
+        final NodeConnectorKey key = new NodeConnectorKey(new NodeConnectorId(ref.getDestTp()));
+        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
+    }
+
+    public TerminationPointKey toTerminationPointKey(final NodeConnector connector) {
+        return null;
+    }
+
+    public Set<Property> toProperties(final Link link) {
+        return null;
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/AdSalTopologyMapping.xtend
deleted file mode 100644 (file)
index aa238a8..0000000
+++ /dev/null
@@ -1,96 +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.md.compatibility.topologymanager
-
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
-import org.opendaylight.controller.sal.core.NodeConnector
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
-import java.util.Map
-import org.opendaylight.controller.sal.core.Edge
-import java.util.Set
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node
-import java.util.HashSet
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
-import org.opendaylight.controller.sal.compatibility.NodeMapping
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Destination
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey
-import java.util.HashMap
-
-class AdSalTopologyMapping {
-
-    val TopologyKey topologyMapping;
-    @Property
-    val InstanceIdentifier<Topology> topologyPath;
-
-    new(TopologyKey topology) {
-        topologyMapping = topology;
-        _topologyPath = InstanceIdentifier.builder(NetworkTopology).child(Topology, topology).toInstance;
-    }
-
-    def InstanceIdentifier<TerminationPoint> toTerminationPoint(NodeConnector connector) {
-        InstanceIdentifier.builder(topologyPath).child(Node).child(TerminationPoint, connector.toTerminationPointKey()).toInstance;
-    }
-
-    def Map<Edge, Set<org.opendaylight.controller.sal.core.Property>> toEdgePropertiesMap(Iterable<Link> links) {
-        val ret = new HashMap<Edge, Set<org.opendaylight.controller.sal.core.Property>>
-        for (link : links) {
-            ret.put(link.toEdge(), link.toProperties())
-        }
-        return ret;
-    }
-
-    def Set<Edge> toEdges(Iterable<Link> links) {
-        val ret = new HashSet<Edge>
-        for (link : links) {
-            ret.add(link.toEdge)
-        }
-        return ret;
-    }
-
-    def Edge toEdge(Link link) {
-        val tail = link.source.toNodeConnector();
-        val head = link.destination.toNodeConnector();
-        return new Edge(tail, head);
-    }
-
-    def org.opendaylight.controller.sal.core.Node toAdNode(Node node) {
-        return node.nodeId.toAdNode;
-    }
-
-    def org.opendaylight.controller.sal.core.Node toAdNode(
-        org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId node) {
-        val key = new NodeKey(new NodeId(node))
-        return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, key);
-    }
-
-    def NodeConnector toNodeConnector(Source ref) {
-        val adNode = ref.sourceNode.toAdNode();
-        val key = new NodeConnectorKey(new NodeConnectorId(ref.sourceTp))
-        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
-    }
-
-    def NodeConnector toNodeConnector(Destination ref) {
-        val adNode = ref.destNode.toAdNode();
-        val key = new NodeConnectorKey(new NodeConnectorId(ref.destTp))
-        return new NodeConnector(NodeMapping.MD_SAL_TYPE, key, adNode);
-    }
-
-    def TerminationPointKey toTerminationPointKey(NodeConnector connector) {
-    }
-
-    def Set<org.opendaylight.controller.sal.core.Property> toProperties(Link link) {
-    }
-}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.java b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.java
new file mode 100644 (file)
index 0000000..11320a1
--- /dev/null
@@ -0,0 +1,149 @@
+/**
+ * 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.compatibility.topologymanager;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.Host;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.topologymanager.ITopologyManager;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.FluentIterable;
+
+@SuppressWarnings("all")
+public class CompatibleTopologyManager extends ConfigurableLinkManager implements ITopologyManager {
+    private AdSalTopologyMapping topologyMapping;
+    private TypeSafeDataReader dataReader;
+
+    public TypeSafeDataReader getDataReader() {
+        return dataReader;
+    }
+
+    public void setDataReader(final TypeSafeDataReader dataReader) {
+        this.dataReader = dataReader;
+    }
+
+    public AdSalTopologyMapping getTopologyMapping() {
+        return topologyMapping;
+    }
+
+    public void setTopologyMapping(final AdSalTopologyMapping topologyMapping) {
+        this.topologyMapping = topologyMapping;
+    }
+
+    @Override
+    public Map<Edge,Set<Property>> getEdges() {
+        final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
+        return this.topologyMapping.toEdgePropertiesMap(topology.getLink());
+    }
+
+    @Override
+    public Map<org.opendaylight.controller.sal.core.Node, Set<Edge>> getNodeEdges() {
+        final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
+        final HashMap<org.opendaylight.controller.sal.core.Node, Set<Edge>> ret = new HashMap<>();
+        for (final Node node : topology.getNode()) {
+            try {
+                ret.put(topologyMapping.toAdNode(node), topologyMapping.toEdges(
+                        FluentIterable.from(topology.getLink()).filter(new Predicate<Link>() {
+                            @Override
+                            public boolean apply(final Link input) {
+                                final NodeId nodeId = node.getNodeId();
+                                if (nodeId.equals(input.getSource().getSourceNode())) {
+                                    return true;
+                                }
+                                if (nodeId.equals(input.getDestination().getDestNode())) {
+                                    return true;
+                                }
+
+                                return false;
+                            }
+                        })));
+            } catch (ConstructionException e) {
+                throw new IllegalStateException(String.format("Failed to construct node for {}", node), e);
+            }
+        }
+        return ret;
+    }
+
+    /**
+     * Returns true if point is connected to link
+     */
+    private boolean isInternal(final TerminationPoint point) {
+        final Topology topology = getDataReader().readConfigurationData(topologyMapping.getTopologyPath());
+        final TpId tpId = point.getKey().getTpId();
+        return FluentIterable.from(topology.getLink()).anyMatch(new Predicate<Link>() {
+            @Override
+            public boolean apply(final Link input) {
+                if (tpId.equals(input.getSource().getSourceTp())) {
+                    return true;
+                }
+                if (tpId.equals(input.getDestination().getDestTp())) {
+                    return true;
+                }
+                return false;
+            }
+        });
+    }
+
+    @Override
+    public Set<NodeConnector> getNodeConnectorWithHost() {
+        return null;
+    }
+
+    @Override
+    public Host getHostAttachedToNodeConnector(final NodeConnector p) {
+        final InstanceIdentifier<TerminationPoint> tpPath = topologyMapping.toTerminationPoint(p);
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public List<Host> getHostsAttachedToNodeConnector(final NodeConnector p) {
+        final Topology topology = getDataReader().readOperationalData(topologyMapping.getTopologyPath());
+        throw new UnsupportedOperationException("Hosts not mapped yet");
+    }
+
+    @Override
+    public Map<org.opendaylight.controller.sal.core.Node, Set<NodeConnector>> getNodesWithNodeConnectorHost() {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
+    }
+
+    @Override
+    public boolean isInternal(final NodeConnector p) {
+        final TerminationPoint connector = getDataReader()
+                .readConfigurationData(topologyMapping.toTerminationPoint(p));
+        return this.isInternal(connector);
+    }
+
+    @Override
+    public void updateHostLink(final NodeConnector p, final Host h, final UpdateType t, final Set<Property> props) {
+        // Update app defined topology
+    }
+
+    @Override
+    public Status saveConfig() {
+        // FIXME: commit configuration
+        return null;
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.xtend b/opendaylight/md-sal/compatibility/inventory-topology-compatibility/src/main/java/org/opendaylight/controller/md/compatibility/topologymanager/CompatibleTopologyManager.xtend
deleted file mode 100644 (file)
index 4fdea4b..0000000
+++ /dev/null
@@ -1,92 +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.md.compatibility.topologymanager
-
-import org.opendaylight.controller.topologymanager.ITopologyManager
-import org.opendaylight.controller.sal.core.NodeConnector
-import org.opendaylight.controller.sal.core.Host
-import org.opendaylight.controller.sal.core.UpdateType
-import java.util.Set
-import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader
-import java.util.HashMap
-import org.opendaylight.controller.sal.core.Edge
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint
-import com.google.common.collect.FluentIterable
-
-class CompatibleTopologyManager extends ConfigurableLinkManager implements ITopologyManager {
-
-    @Property
-    var TypeSafeDataReader dataReader;
-
-    @Property
-    var extension AdSalTopologyMapping topologyMapping;
-
-    override getEdges() {
-        val topology = dataReader.readOperationalData(topologyPath);
-        return topology.link.toEdgePropertiesMap();
-    }
-
-    override getNodeEdges() {
-        val topology = dataReader.readOperationalData(topologyPath);
-        val ret = new HashMap<org.opendaylight.controller.sal.core.Node, Set<Edge>>;
-        for (node : topology.node) {
-            val adNode = node.toAdNode();
-            val adEdges = FluentIterable.from(topology.link).filter[
-                source.sourceNode == node.nodeId || destination.destNode == node.nodeId].toEdges();
-            ret.put(adNode, adEdges)
-        }
-        return ret;
-    }
-
-    /**
-     *   Returns true if point is connected to link
-    */
-    def isInternal(TerminationPoint point) {
-        val topology = dataReader.readConfigurationData(topologyPath);
-        val tpId = point.key.tpId;
-        return FluentIterable.from(topology.link).anyMatch(
-            [
-                source.sourceTp == tpId || destination.destTp == tpId
-            ])
-    }
-
-    override getNodeConnectorWithHost() {
-    }
-
-    override getHostAttachedToNodeConnector(NodeConnector p) {
-        val tpPath = p.toTerminationPoint();
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-    }
-
-    override getHostsAttachedToNodeConnector(NodeConnector p) {
-        val topology = dataReader.readOperationalData(topologyPath);
-
-        throw new UnsupportedOperationException("Hosts not mapped yet")
-    }
-
-    override getNodesWithNodeConnectorHost() {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-
-    }
-
-    override isInternal(NodeConnector p) {
-        val tpPath = p.toTerminationPoint();
-        val connector = dataReader.readConfigurationData(tpPath);
-        return connector.isInternal();
-    }
-
-    override updateHostLink(NodeConnector p, Host h, UpdateType t,
-        Set<org.opendaylight.controller.sal.core.Property> props) {
-        // Update app defined topology
-    }
-
-    override saveConfig() {
-        // FIXME: commit configuration
-    }
-
-}
@@ -1,31 +1,31 @@
-/*
+/**
  * 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.compatibility.topologymanager
+package org.opendaylight.controller.md.compatibility.topologymanager;
 
-import org.opendaylight.controller.topologymanager.ITopologyManager
-import org.opendaylight.controller.topologymanager.TopologyUserLinkConfig
+import java.util.concurrent.ConcurrentMap;
 
-abstract class ConfigurableLinkManager implements ITopologyManager {
-    
-    final override addUserLink(TopologyUserLinkConfig link) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-        
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.topologymanager.ITopologyManager;
+import org.opendaylight.controller.topologymanager.TopologyUserLinkConfig;
+
+public abstract class ConfigurableLinkManager implements ITopologyManager {
+    @Override
+    public final Status addUserLink(final TopologyUserLinkConfig link) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
     }
-    
-    
-    final override deleteUserLink(String linkName) {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-        
+
+    @Override
+    public final Status deleteUserLink(final String linkName) {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
     }
-    
-    
-    final override getUserLinks() {
-        throw new UnsupportedOperationException("TODO: auto-generated method stub")
-        
+
+    @Override
+    public final ConcurrentMap<String,TopologyUserLinkConfig> getUserLinks() {
+        throw new UnsupportedOperationException("TODO: auto-generated method stub");
     }
 }
index 3ed1edf7d68b3fb8617af9689b92b93b9b80441d..688e6ac09b25b29d8160ad05b10ef078430e1d37 100644 (file)
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.eclipse.xtend</groupId>
-      <artifactId>org.eclipse.xtend.lib</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal</artifactId>
           </instructions>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.eclipse.xtend</groupId>
-        <artifactId>xtend-maven-plugin</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
index a145a3b4e179dcc9a9dea8c9df54cd526a84071e..6c79e053e16b353a5e4bdd51f6e44a469aec8b26 100644 (file)
           </instructions>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.eclipse.xtend</groupId>
-        <artifactId>xtend-maven-plugin</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
index 53257f8c835759543fea5cc2c74dd4706e50f1dc..a879a36f8c23e6321f26c8fee0ec47a4569df2a9 100644 (file)
@@ -261,11 +261,11 @@ public class FromSalConversionsUtils {
                     .setType(etherType);
             targetEthMatchBuild.setEthernetType(ethType.build());
         }
-        if((sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) || 
-                (sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null)|| 
+        if((sourceMatch.getField(DL_SRC) != null && sourceMatch.getField(DL_SRC).getValue() != null) ||
+                (sourceMatch.getField(DL_DST) != null && sourceMatch.getField(DL_DST).getValue() != null)||
                 dataLinkType != null ) {
-            return targetEthMatchBuild.build();            
-        } 
+            return targetEthMatchBuild.build();
+        }
         return null;
     }
 
@@ -372,7 +372,7 @@ public class FromSalConversionsUtils {
                     .toAddrString(inetDestAddress);
             layer4MatchBuild
             .setIpv4Destination(new Ipv4Prefix(inetDstAddressString));
-        }       
+        }
         return layer4MatchBuild.build();
 
     }
@@ -388,13 +388,13 @@ public class FromSalConversionsUtils {
         }
         if(inetDestAddress != null) {
             String inetDstAddressString = InetAddresses
-                    .toAddrString(inetDestAddress);    
+                    .toAddrString(inetDestAddress);
             layer6MatchBuild
                     .setIpv6Destination(new Ipv6Prefix(inetDstAddressString));
         }
         return layer6MatchBuild.build();
     }
-    
+
     public static boolean flowEquals(Flow statsFlow, Flow storedFlow) {
         if (statsFlow.getClass() != storedFlow.getClass()) {
             return false;
diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.java
new file mode 100644 (file)
index 0000000..2830165
--- /dev/null
@@ -0,0 +1,770 @@
+/**
+ * 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.compatibility;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
+import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.controller.sal.core.ConstructionException;
+import org.opendaylight.controller.sal.core.Edge;
+import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.NodeTable;
+import org.opendaylight.controller.sal.core.Property;
+import org.opendaylight.controller.sal.core.UpdateType;
+import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
+import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
+import org.opendaylight.controller.sal.reader.FlowOnNode;
+import org.opendaylight.controller.sal.reader.IPluginInReadService;
+import org.opendaylight.controller.sal.reader.IPluginOutReadService;
+import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
+import org.opendaylight.controller.sal.reader.NodeDescription;
+import org.opendaylight.controller.sal.reader.NodeTableStatistics;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.Link;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.GenericStatistics;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Bytes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.node.connector.statistics.Packets;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatistics;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventoryService, OpendaylightInventoryListener, OpendaylightFlowStatisticsListener, OpendaylightFlowTableStatisticsListener, OpendaylightPortStatisticsListener {
+    private static final Logger LOG = LoggerFactory.getLogger(InventoryAndReadAdapter.class);
+    private static final short OPENFLOWV10_TABLE_ID = 0;
+
+    private final InventoryNotificationProvider inventoryNotificationProvider = new InventoryNotificationProvider();
+    private final Map<PathArgument,List<PathArgument>> nodeToNodeConnectorsMap = new ConcurrentHashMap<>();
+    private List<IPluginOutInventoryService> inventoryPublisher = new CopyOnWriteArrayList<>();
+    private List<IPluginOutReadService> statisticsPublisher = new CopyOnWriteArrayList<>();
+
+    private OpendaylightFlowTableStatisticsService flowTableStatisticsService;
+    private OpendaylightPortStatisticsService nodeConnectorStatisticsService;
+    private OpendaylightFlowStatisticsService flowStatisticsService;
+    private FlowTopologyDiscoveryService topologyDiscovery;
+    private DataProviderService dataProviderService;
+    private DataBrokerService dataService;
+
+    public DataBrokerService getDataService() {
+        return dataService;
+    }
+
+    public void setDataService(final DataBrokerService dataService) {
+        this.dataService = dataService;
+    }
+
+    public DataProviderService getDataProviderService() {
+        return dataProviderService;
+    }
+
+    public void setDataProviderService(final DataProviderService dataProviderService) {
+        this.dataProviderService = dataProviderService;
+    }
+
+    public OpendaylightFlowStatisticsService getFlowStatisticsService() {
+        return flowStatisticsService;
+    }
+
+    public void setFlowStatisticsService(final OpendaylightFlowStatisticsService flowStatisticsService) {
+        this.flowStatisticsService = flowStatisticsService;
+    }
+
+    public OpendaylightPortStatisticsService getNodeConnectorStatisticsService() {
+        return nodeConnectorStatisticsService;
+    }
+
+    public void setNodeConnectorStatisticsService(final OpendaylightPortStatisticsService nodeConnectorStatisticsService) {
+        this.nodeConnectorStatisticsService = nodeConnectorStatisticsService;
+    }
+
+    public OpendaylightFlowTableStatisticsService getFlowTableStatisticsService() {
+        return flowTableStatisticsService;
+    }
+
+    public void setFlowTableStatisticsService(final OpendaylightFlowTableStatisticsService flowTableStatisticsService) {
+        this.flowTableStatisticsService = flowTableStatisticsService;
+    }
+
+    public FlowTopologyDiscoveryService getTopologyDiscovery() {
+        return topologyDiscovery;
+    }
+
+    public void setTopologyDiscovery(final FlowTopologyDiscoveryService topologyDiscovery) {
+        this.topologyDiscovery = topologyDiscovery;
+    }
+
+    public List<IPluginOutReadService> getStatisticsPublisher() {
+        return statisticsPublisher;
+    }
+
+    public void setStatisticsPublisher(final List<IPluginOutReadService> statisticsPublisher) {
+        this.statisticsPublisher = statisticsPublisher;
+    }
+
+    public List<IPluginOutInventoryService> getInventoryPublisher() {
+        return inventoryPublisher;
+    }
+
+    public void setInventoryPublisher(final List<IPluginOutInventoryService> inventoryPublisher) {
+        this.inventoryPublisher = inventoryPublisher;
+    }
+
+    public void startAdapter() {
+        inventoryNotificationProvider.setDataProviderService(getDataProviderService());
+        inventoryNotificationProvider.setInventoryPublisher(getInventoryPublisher());
+        // inventoryNotificationProvider.start();
+    }
+
+    public boolean setInventoryPublisher(final IPluginOutInventoryService listener) {
+        return getInventoryPublisher().add(listener);
+    }
+
+    public boolean unsetInventoryPublisher(final IPluginOutInventoryService listener) {
+        return getInventoryPublisher().remove(listener);
+    }
+
+    public boolean setReadPublisher(final IPluginOutReadService listener) {
+        return getStatisticsPublisher().add(listener);
+    }
+
+    public Boolean unsetReadPublisher(final IPluginOutReadService listener) {
+        if (listener != null) {
+            return getStatisticsPublisher().remove(listener);
+        }
+        return false;
+    }
+
+    protected DataModificationTransaction startChange() {
+        return getDataProviderService().beginTransaction();
+    }
+
+    @Override
+    public long getTransmitRate(final NodeConnector connector) {
+        final FlowCapableNodeConnector nodeConnector = this.readOperFlowCapableNodeConnector(NodeMapping.toNodeConnectorRef(connector));
+        return nodeConnector.getCurrentSpeed().longValue();
+    }
+
+    private FlowCapableNode readOperFlowCapableNode(final NodeRef ref) {
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node =
+                (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)getDataService().readOperationalData(ref.getValue());
+        if (node == null) {
+            return null;
+        }
+
+        return node.getAugmentation(FlowCapableNode.class);
+    }
+
+    private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node readConfigNode(final Node node) {
+        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
+                InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, InventoryMapping.toNodeKey(node))
+                .build();
+
+        return (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) startChange().readConfigurationData(nodeRef);
+    }
+
+    private org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector readConfigNodeConnector(final NodeConnector connector) {
+        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector> nodeConnectorRef =
+                InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, InventoryMapping.toNodeKey(connector.getNode()))
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector.class, InventoryMapping.toNodeConnectorKey(connector))
+                .toInstance();
+
+        return((org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) startChange().readConfigurationData(nodeConnectorRef));
+    }
+
+    /**
+     * Read a table of a node from configuration data store.
+     *
+     * @param node Node id
+     * @param id Table id
+     * @return Table contents, or null if not present
+     */
+    private Table readConfigTable(final Node node, final short id) {
+        final InstanceIdentifier<Table> tableRef = InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, InventoryMapping.toNodeKey(node))
+                .augmentation(FlowCapableNode.class)
+                .child(Table.class, new TableKey(id))
+                .build();
+
+        return (Table) startChange().readConfigurationData(tableRef);
+    }
+
+    @Override
+    public List<FlowOnNode> readAllFlow(final Node node, final boolean cached) {
+        final ArrayList<FlowOnNode> output = new ArrayList<>();
+        final Table table = readConfigTable(node, OPENFLOWV10_TABLE_ID);
+        if (table != null) {
+            final List<Flow> flows = table.getFlow();
+            LOG.trace("Number of flows installed in table 0 of node {} : {}", node, flows.size());
+
+            for (final Flow flow : flows) {
+                final FlowStatisticsData statsFromDataStore = flow.getAugmentation(FlowStatisticsData.class);
+                if (statsFromDataStore != null) {
+                    final FlowOnNode it = new FlowOnNode(ToSalConversionsUtils.toFlow(flow, node));
+                    output.add(addFlowStats(it, statsFromDataStore.getFlowStatistics()));
+                }
+            }
+        }
+
+        // TODO (main): Shall we send request to the switch? It will make async request to the switch.
+        // Once the plugin receives a response, it will let the adaptor know through onFlowStatisticsUpdate()
+        // If we assume that md-sal statistics manager will always be running, then it is not required
+        // But if not, then sending request will collect the latest data for adaptor at least.
+        getFlowStatisticsService().getAllFlowsStatisticsFromAllFlowTables(
+                new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder().setNode(NodeMapping.toNodeRef(node)).build());
+        return output;
+    }
+
+    @Override
+    public List<NodeConnectorStatistics> readAllNodeConnector(final Node node, final boolean cached) {
+        final ArrayList<NodeConnectorStatistics> ret = new ArrayList<>();
+
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node dsNode = readConfigNode(node);
+        if (dsNode != null) {
+            for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector dsNodeConnector : dsNode.getNodeConnector()) {
+                final FlowCapableNodeConnectorStatistics stats = (dsNodeConnector.getAugmentation(FlowCapableNodeConnectorStatisticsData.class));
+                if (stats != null) {
+                    try {
+                        ret.add(toNodeConnectorStatistics(stats.getFlowCapableNodeConnectorStatistics(), dsNode.getId(), dsNodeConnector.getId()));
+                    } catch (ConstructionException e) {
+                        LOG.warn("Failed to instantiate node connector statistics for node {} connector {}, ignoring it",
+                                dsNode.getId(), dsNodeConnector.getId(), e);
+                    }
+                }
+            }
+        }
+
+        //TODO: Refer TODO (main)
+        getNodeConnectorStatisticsService().getAllNodeConnectorsStatistics(
+                new GetAllNodeConnectorsStatisticsInputBuilder().setNode(NodeMapping.toNodeRef(node)).build());
+        return ret;
+    }
+
+    @Override
+    public List<NodeTableStatistics> readAllNodeTable(final Node node, final boolean cached) {
+        final NodeRef nodeRef = NodeMapping.toNodeRef(node);
+
+        final ArrayList<NodeTableStatistics> ret = new ArrayList<>();
+        final FlowCapableNode dsFlowCapableNode = this.readOperFlowCapableNode(nodeRef);
+        if (dsFlowCapableNode != null) {
+            for (final Table table : dsFlowCapableNode.getTable()) {
+                final FlowTableStatisticsData tableStats = table.getAugmentation(FlowTableStatisticsData.class);
+                if (tableStats != null) {
+                    try {
+                        ret.add(toNodeTableStatistics(tableStats.getFlowTableStatistics(), table.getId(), node));
+                    } catch (ConstructionException e) {
+                        LOG.warn("Failed to instantiate table statistics for node {} table {}, ignoring it", node, table.getId(), e);
+                    }
+                }
+            }
+        }
+
+        //TODO: Refer TODO (main)
+        getFlowTableStatisticsService().getFlowTablesStatistics(new GetFlowTablesStatisticsInputBuilder().setNode(nodeRef).build());
+        return ret;
+    }
+
+    @Override
+    public NodeDescription readDescription(final Node node, final boolean cached) {
+        return this.toNodeDescription(NodeMapping.toNodeRef(node));
+    }
+
+    @Override
+    public FlowOnNode readFlow(final Node node, final org.opendaylight.controller.sal.flowprogrammer.Flow targetFlow, final boolean cached) {
+        FlowOnNode ret = null;
+        final Table table = readConfigTable(node, OPENFLOWV10_TABLE_ID);
+        if (table != null) {
+            final List<Flow> flows = table.getFlow();
+            InventoryAndReadAdapter.LOG.trace("Number of flows installed in table 0 of node {} : {}", node, flows.size());
+
+            for (final Flow mdsalFlow : flows) {
+                if(FromSalConversionsUtils.flowEquals(mdsalFlow, MDFlowMapping.toMDSalflow(targetFlow))) {
+                    final FlowStatisticsData statsFromDataStore = mdsalFlow.getAugmentation(FlowStatisticsData.class);
+                    if (statsFromDataStore != null) {
+                        InventoryAndReadAdapter.LOG.debug("Found matching flow in the data store flow table ");
+                        ret = addFlowStats(new FlowOnNode(targetFlow), statsFromDataStore.getFlowStatistics());
+
+                        // FIXME: break; ?
+                    }
+                }
+            }
+        }
+
+        //TODO: Refer TODO (main)
+        final GetFlowStatisticsFromFlowTableInputBuilder input = new GetFlowStatisticsFromFlowTableInputBuilder().setNode(NodeMapping.toNodeRef(node));
+        input.fieldsFrom(MDFlowMapping.toMDSalflow(targetFlow));
+        getFlowStatisticsService().getFlowStatisticsFromFlowTable(input.build());
+        return ret;
+    }
+
+    @Override
+    public NodeConnectorStatistics readNodeConnector(final NodeConnector connector, final boolean cached) {
+        final NodeConnectorId ncId = InventoryMapping.toNodeConnectorKey(connector).getId();
+
+        NodeConnectorStatistics ret = null;
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nodeConnectorFromDS = readConfigNodeConnector(connector);
+        if (nodeConnectorFromDS != null) {
+            final FlowCapableNodeConnectorStatistics stats = nodeConnectorFromDS.getAugmentation(FlowCapableNodeConnectorStatisticsData.class);
+            if (stats != null) {
+                try {
+                    ret = toNodeConnectorStatistics(stats.getFlowCapableNodeConnectorStatistics(),
+                            InventoryMapping.toNodeKey(connector.getNode()).getId(), ncId);
+                } catch (ConstructionException e) {
+                    LOG.warn("Failed to instantiate node connector statistics for connector {}, ignoring it",
+                            connector, e);
+                }
+            }
+        }
+
+        getNodeConnectorStatisticsService().getNodeConnectorStatistics(
+                new GetNodeConnectorStatisticsInputBuilder().setNode(NodeMapping.toNodeRef(connector.getNode())).setNodeConnectorId(ncId).build());
+        return ret;
+    }
+
+    @Override
+    public NodeTableStatistics readNodeTable(final NodeTable nodeTable, final boolean cached) {
+        NodeTableStatistics nodeStats = null;
+        final Table table = readConfigTable(nodeTable.getNode(), (short) nodeTable.getID());
+        if (table != null) {
+            final FlowTableStatisticsData tableStats = table.getAugmentation(FlowTableStatisticsData.class);
+            if (tableStats != null) {
+                try {
+                    nodeStats = toNodeTableStatistics(tableStats.getFlowTableStatistics(), table.getId(), nodeTable.getNode());
+                } catch (ConstructionException e) {
+                    LOG.warn("Failed to instantiate table statistics for node {} table {}, ignoring it",
+                            nodeTable.getNode(), table.getId(), e);
+                }
+            }
+        }
+
+        //TODO: Refer TODO (main)
+        getFlowTableStatisticsService().getFlowTablesStatistics(
+                new GetFlowTablesStatisticsInputBuilder().setNode(NodeMapping.toNodeRef(nodeTable.getNode())).build());
+        return nodeStats;
+    }
+
+    @Override
+    public void onNodeConnectorRemoved(final NodeConnectorRemoved update) {
+        // Never received
+    }
+
+    @Override
+    public void onNodeRemoved(final NodeRemoved notification) {
+        this.removeNodeConnectors(notification.getNodeRef().getValue());
+        try {
+            final Node aDNode = NodeMapping.toADNode(notification.getNodeRef());
+            this.publishNodeUpdate(aDNode, UpdateType.REMOVED, Collections.<Property>emptySet());
+        } catch (ConstructionException e) {
+            LOG.warn("Failed to construct node for {}, not propagating update", notification.getNodeRef(), e);
+        }
+    }
+
+    @Override
+    public void onNodeConnectorUpdated(final NodeConnectorUpdated update) {
+        final NodeConnectorRef ref = update.getNodeConnectorRef();
+        final UpdateType updateType;
+        if (!this.isKnownNodeConnector(ref.getValue())) {
+            this.recordNodeConnector(ref.getValue());
+            updateType = UpdateType.ADDED;
+        } else {
+            updateType = UpdateType.CHANGED;
+        }
+
+        try {
+            final NodeConnector nodeConnector;
+            nodeConnector = NodeMapping.toADNodeConnector(ref);
+            this.publishNodeConnectorUpdate(nodeConnector, updateType, NodeMapping.toADNodeConnectorProperties(update));
+        } catch (ConstructionException e) {
+            LOG.warn("Failed to construct node connector for {}, not reporting the update", ref, e);
+        }
+    }
+
+    @Override
+    public void onNodeUpdated(final NodeUpdated notification) {
+        final NodeRef ref = notification.getNodeRef();
+
+        final UpdateType updateType;
+        if (dataService.readOperationalData(ref.getValue()) == null) {
+            updateType = UpdateType.ADDED;
+        } else {
+            updateType = UpdateType.CHANGED;
+        }
+
+        final Node aDNode;
+        try {
+            aDNode = NodeMapping.toADNode(ref);
+        } catch (ConstructionException e) {
+            LOG.warn("Failed to construct node for {}, not reporting the update", ref, e);
+            return;
+        }
+
+        this.publishNodeUpdate(aDNode, updateType, NodeMapping.toADNodeProperties(notification));
+        for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
+            final NodeDescription description = this.toNodeDescription(ref);
+            if (description != null) {
+                final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
+                        InstanceIdentifier.builder(Nodes.class)
+                        .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
+                        .toInstance();
+                try {
+                    statsPublisher.descriptionStatisticsUpdated(NodeMapping.toADNode(nodeRef), description);
+                } catch (ConstructionException e) {
+                    LOG.warn("Failed to construct node for {}, not reporting the update to publisher {}", nodeRef, statsPublisher, e);
+                }
+            }
+        }
+    }
+
+    @Override
+    public ConcurrentMap<Node,Map<String,Property>> getNodeProps() {
+        final ConcurrentHashMap<Node,Map<String,Property>> props = new ConcurrentHashMap<>();
+        final Nodes nodes = this.readOperAllMDNodes();
+        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node : nodes.getNode()) {
+            final FlowCapableNode fcn = node.getAugmentation(FlowCapableNode.class);
+            if (fcn != null) {
+                final ConcurrentHashMap<String,Property> perNodePropMap = new ConcurrentHashMap<String, Property>();
+                final HashSet<Property> perNodeProps = NodeMapping.toADNodeProperties(fcn, node.getId());
+                if (perNodeProps != null) {
+                    for (final Property perNodeProp : perNodeProps) {
+                        perNodePropMap.put(perNodeProp.getName(), perNodeProp);
+                    }
+                }
+
+                try {
+                    final Node adNode = new Node(NodeMapping.MD_SAL_TYPE, NodeMapping.toADNodeId(node.getId()));
+                    props.put(adNode, perNodePropMap);
+                } catch (ConstructionException e) {
+                    LOG.warn("Failed to construct node for {}, skipping it", node, e);
+                }
+            }
+        }
+        return props;
+    }
+
+    private Nodes readOperAllMDNodes() {
+        final TypeSafeDataReader reader = TypeSafeDataReader.forReader(getDataService());
+        return reader.readOperationalData(InstanceIdentifier.builder(Nodes.class).build());
+    }
+
+    @Override
+    public ConcurrentMap<NodeConnector,Map<String,Property>> getNodeConnectorProps(final Boolean refresh) {
+        final ConcurrentHashMap<NodeConnector,Map<String,Property>> props = new ConcurrentHashMap<>();
+        for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node : this.readOperAllMDNodes().getNode()) {
+            for (final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc : node.getNodeConnector()) {
+                final FlowCapableNodeConnector fcnc = nc.getAugmentation(FlowCapableNodeConnector.class);
+                if (fcnc != null) {
+                    final ConcurrentHashMap<String,Property> ncpsm = new ConcurrentHashMap<>();
+                    final HashSet<Property> ncps = NodeMapping.toADNodeConnectorProperties(fcnc);
+                    if (ncps != null) {
+                        for (final Property p : ncps) {
+                            ncpsm.put(p.getName(), p);
+                        }
+                    }
+
+                    try {
+                        props.put(NodeMapping.toADNodeConnector(nc.getId(), node.getId()), ncpsm);
+                    } catch (ConstructionException e) {
+                        LOG.warn("Failed to instantiate node {} connector {}, not reporting it", node.getId(), nc.getId(), e);
+                    }
+                }
+            }
+        }
+        return props;
+    }
+
+    private FlowCapableNodeConnector readOperFlowCapableNodeConnector(final NodeConnectorRef ref) {
+        final org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector nc =
+                (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector)
+                getDataService().readOperationalData(ref.getValue());
+        return nc.getAugmentation(FlowCapableNodeConnector.class);
+    }
+
+    private static NodeConnectorStatistics toNodeConnectorStatistics(final org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.NodeConnectorStatistics nodeConnectorStatistics, final NodeId nodeId, final NodeConnectorId nodeConnectorId) throws ConstructionException {
+        final NodeConnectorStatistics it = new NodeConnectorStatistics();
+
+        final Packets packets = nodeConnectorStatistics.getPackets();
+        it.setReceivePacketCount(packets.getReceived().longValue());
+        it.setTransmitPacketCount(packets.getTransmitted().longValue());
+
+        final Bytes bytes = nodeConnectorStatistics.getBytes();
+        it.setReceiveByteCount(bytes.getReceived().longValue());
+        it.setTransmitByteCount(bytes.getTransmitted().longValue());
+
+        it.setReceiveDropCount(nodeConnectorStatistics.getReceiveDrops().longValue());
+        it.setTransmitDropCount(nodeConnectorStatistics.getTransmitDrops().longValue());
+        it.setReceiveErrorCount(nodeConnectorStatistics.getReceiveErrors().longValue());
+        it.setTransmitErrorCount(nodeConnectorStatistics.getTransmitErrors().longValue());
+        it.setReceiveFrameErrorCount(nodeConnectorStatistics.getReceiveFrameError().longValue());
+        it.setReceiveOverRunErrorCount(nodeConnectorStatistics.getReceiveOverRunError().longValue());
+        it.setReceiveCRCErrorCount(nodeConnectorStatistics.getReceiveCrcError().longValue());
+        it.setCollisionCount(nodeConnectorStatistics.getCollisionCount().longValue());
+
+        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector> nodeConnectorRef =
+                InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(nodeId))
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector.class, new NodeConnectorKey(nodeConnectorId))
+                .build();
+        it.setNodeConnector(NodeMapping.toADNodeConnector(new NodeConnectorRef(nodeConnectorRef)));
+        return it;
+    }
+
+    private static NodeTableStatistics toNodeTableStatistics(final FlowTableStatistics tableStats, final Short tableId, final Node node) throws ConstructionException {
+        final NodeTableStatistics it = new NodeTableStatistics();
+        it.setActiveCount(tableStats.getActiveFlows().getValue().intValue());
+        it.setLookupCount(tableStats.getPacketsLookedUp().getValue().longValue());
+        it.setMatchedCount(tableStats.getPacketsMatched().getValue().longValue());
+        it.setName(tableId.toString());
+        it.setNodeTable(new NodeTable(NodeMapping.MD_SAL_TYPE, tableId, node));
+        return it;
+    }
+
+    private NodeDescription toNodeDescription(final NodeRef nodeRef) {
+        final FlowCapableNode capableNode = this.readOperFlowCapableNode(nodeRef);
+        if (capableNode == null) {
+            return null;
+        }
+
+        final NodeDescription it = new NodeDescription();
+        it.setManufacturer(capableNode.getManufacturer());
+        it.setSerialNumber(capableNode.getSerialNumber());
+        it.setSoftware(capableNode.getSoftware());
+        it.setDescription(capableNode.getDescription());
+        return it;
+    }
+
+    public Edge toADEdge(final Link link) throws ConstructionException {
+        NodeConnectorRef _source = link.getSource();
+        NodeConnector _aDNodeConnector = NodeMapping.toADNodeConnector(_source);
+        NodeConnectorRef _destination = link.getDestination();
+        NodeConnector _aDNodeConnector_1 = NodeMapping.toADNodeConnector(_destination);
+        Edge _edge = new Edge(_aDNodeConnector, _aDNodeConnector_1);
+        return _edge;
+    }
+
+    /**
+     * OpendaylightFlowStatisticsListener interface implementation
+     */
+    @Override
+    public void onAggregateFlowStatisticsUpdate(final AggregateFlowStatisticsUpdate notification) {
+        // Ignoring this notification as there does not seem to be a way to bubble this up to AD-SAL
+    }
+
+    @Override
+    public void onFlowsStatisticsUpdate(final FlowsStatisticsUpdate notification) {
+        final ArrayList<FlowOnNode> adsalFlowsStatistics = new ArrayList<>();
+        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
+                InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
+                .build();
+
+        final Node aDNode;
+        try {
+            aDNode = NodeMapping.toADNode(nodeRef);
+        } catch (ConstructionException e) {
+            LOG.warn("Failed to construct node for {}, ignoring it", notification.getId(), e);
+            return;
+        }
+
+        for (final FlowAndStatisticsMapList flowStats : notification.getFlowAndStatisticsMapList()) {
+            if (flowStats.getTableId() == 0) {
+                adsalFlowsStatistics.add(InventoryAndReadAdapter.toFlowOnNode(flowStats, aDNode));
+            }
+        }
+        for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
+            statsPublisher.nodeFlowStatisticsUpdated(aDNode, adsalFlowsStatistics);
+        }
+    }
+
+    /**
+     * OpendaylightFlowTableStatisticsListener interface implementation
+     */
+    @Override
+    public void onFlowTableStatisticsUpdate(final FlowTableStatisticsUpdate notification) {
+        ArrayList<NodeTableStatistics> adsalFlowTableStatistics = new ArrayList<>();
+        for (final FlowTableAndStatisticsMap stats : notification.getFlowTableAndStatisticsMap()) {
+            if (stats.getTableId().getValue() == 0) {
+                final NodeTableStatistics it = new NodeTableStatistics();
+                it.setActiveCount(stats.getActiveFlows().getValue().intValue());
+                it.setLookupCount(stats.getPacketsLookedUp().getValue().longValue());
+                it.setMatchedCount(stats.getPacketsMatched().getValue().longValue());
+                adsalFlowTableStatistics.add(it);
+            }
+        }
+
+        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
+                InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
+                .build();
+
+        final Node aDNode;
+        try {
+            aDNode = NodeMapping.toADNode(nodeRef);
+        } catch (ConstructionException e) {
+            LOG.warn("Failed to construct node for {}, ignoring it", notification.getId(), e);
+            return;
+        }
+
+        for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
+            statsPublisher.nodeTableStatisticsUpdated(aDNode, adsalFlowTableStatistics);
+        }
+    }
+
+    /**
+     * OpendaylightPortStatisticsUpdate interface implementation
+     */
+    @Override
+    public void onNodeConnectorStatisticsUpdate(final NodeConnectorStatisticsUpdate notification) {
+        final ArrayList<NodeConnectorStatistics> adsalPortStatistics = new ArrayList<NodeConnectorStatistics>();
+        for (final NodeConnectorStatisticsAndPortNumberMap nodeConnectorStatistics : notification.getNodeConnectorStatisticsAndPortNumberMap()) {
+            try {
+                adsalPortStatistics.add(toNodeConnectorStatistics(
+                        nodeConnectorStatistics, notification.getId(), nodeConnectorStatistics.getNodeConnectorId()));
+            } catch (ConstructionException e) {
+                LOG.warn("Failed to create statistics for node {} connector {}, not updating them",
+                        notification.getId(), nodeConnectorStatistics.getNodeConnectorId(), e);
+            }
+        }
+
+        final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> nodeRef =
+                InstanceIdentifier.builder(Nodes.class)
+                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, new NodeKey(notification.getId()))
+                .build();
+
+        final Node aDNode;
+        try {
+            aDNode = NodeMapping.toADNode(nodeRef);
+        } catch (ConstructionException e) {
+            LOG.warn("Failed to construct node for {}, ignoring it", notification.getId(), e);
+            return;
+        }
+
+        for (final IPluginOutReadService statsPublisher : getStatisticsPublisher()) {
+            statsPublisher.nodeConnectorStatisticsUpdated(aDNode, adsalPortStatistics);
+        }
+    }
+
+    private static FlowOnNode toFlowOnNode(final FlowAndStatisticsMapList flowAndStatsMap, final Node node) {
+        final FlowOnNode it = new FlowOnNode(ToSalConversionsUtils.toFlow(flowAndStatsMap, node));
+        return addFlowStats(it, flowAndStatsMap);
+    }
+
+    private static FlowOnNode addFlowStats(final FlowOnNode node, final GenericStatistics stats) {
+        node.setByteCount(stats.getByteCount().getValue().longValue());
+        node.setPacketCount(stats.getPacketCount().getValue().longValue());
+        node.setDurationSeconds(stats.getDuration().getSecond().getValue().intValue());
+        node.setDurationNanoseconds(stats.getDuration().getNanosecond().getValue().intValue());
+        return node;
+    }
+
+    @Override
+    public Set<Node> getConfiguredNotConnectedNodes() {
+        return Collections.emptySet();
+    }
+
+    private void publishNodeUpdate(final Node node, final UpdateType updateType, final Set<Property> properties) {
+        for (final IPluginOutInventoryService publisher : getInventoryPublisher()) {
+            publisher.updateNode(node, updateType, properties);
+        }
+    }
+
+    private void publishNodeConnectorUpdate(final NodeConnector nodeConnector, final UpdateType updateType, final Set<Property> properties) {
+        for (final IPluginOutInventoryService publisher : getInventoryPublisher()) {
+            publisher.updateNodeConnector(nodeConnector, updateType, properties);
+        }
+    }
+
+    private boolean isKnownNodeConnector(final InstanceIdentifier<? extends Object> nodeConnectorIdentifier) {
+        final List<PathArgument> path = nodeConnectorIdentifier.getPath();
+        if (path.size() >= 3) {
+            final PathArgument nodePath = path.get(1);
+            final PathArgument nodeConnectorPath = path.get(2);
+            final List<PathArgument> nodeConnectors = nodeToNodeConnectorsMap.get(nodePath);
+            if (nodeConnectors != null) {
+                return nodeConnectors.contains(nodeConnectorPath);
+            }
+        }
+        return false;
+    }
+
+    private boolean recordNodeConnector(final InstanceIdentifier<? extends Object> nodeConnectorIdentifier) {
+        final List<PathArgument> path = nodeConnectorIdentifier.getPath();
+        if (path.size() < 3) {
+            return false;
+        }
+
+        final PathArgument nodePath = path.get(1);
+        final PathArgument nodeConnectorPath = path.get(2);
+
+        synchronized (this) {
+            List<PathArgument> nodeConnectors = this.nodeToNodeConnectorsMap.get(nodePath);
+            if (nodeConnectors == null) {
+                nodeConnectors = new ArrayList<>();
+                this.nodeToNodeConnectorsMap.put(nodePath, nodeConnectors);
+            }
+
+            return nodeConnectors.add(nodeConnectorPath);
+        }
+    }
+
+    private List<PathArgument> removeNodeConnectors(final InstanceIdentifier<? extends Object> nodeIdentifier) {
+        return this.nodeToNodeConnectorsMap.remove(nodeIdentifier.getPath().get(1));
+    }
+}
diff --git a/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend b/opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/InventoryAndReadAdapter.xtend
deleted file mode 100644 (file)
index 8908504..0000000
+++ /dev/null
@@ -1,683 +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.compatibility
-
-import java.util.ArrayList
-import java.util.Collections
-import java.util.List
-import java.util.Map
-import java.util.Set
-import java.util.concurrent.ConcurrentHashMap
-import java.util.concurrent.CopyOnWriteArrayList
-import java.util.concurrent.locks.Lock
-import java.util.concurrent.locks.ReentrantLock
-import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService
-import org.opendaylight.controller.sal.core.Edge
-import org.opendaylight.controller.sal.core.Node
-import org.opendaylight.controller.sal.core.NodeTable
-import org.opendaylight.controller.sal.core.UpdateType
-import org.opendaylight.controller.sal.flowprogrammer.Flow
-import org.opendaylight.controller.sal.inventory.IPluginInInventoryService
-import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService
-import org.opendaylight.controller.sal.reader.FlowOnNode
-import org.opendaylight.controller.sal.reader.IPluginInReadService
-import org.opendaylight.controller.sal.reader.IPluginOutReadService
-import org.opendaylight.controller.sal.reader.NodeConnectorStatistics
-import org.opendaylight.controller.sal.reader.NodeDescription
-import org.opendaylight.controller.sal.reader.NodeTableStatistics
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInputBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInputBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsListener
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsListener
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.Link
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatistics
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetAllNodeConnectorsStatisticsInputBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.GetNodeConnectorStatisticsInputBuilder
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsListener
-import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService
-import org.opendaylight.yangtools.yang.binding.DataObject
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.slf4j.LoggerFactory
-
-import static extension org.opendaylight.controller.sal.common.util.Arguments.*
-import static extension org.opendaylight.controller.sal.compatibility.NodeMapping.*
-
-class InventoryAndReadAdapter implements IPluginInReadService,
-                                             IPluginInInventoryService,
-                                             OpendaylightInventoryListener,
-                                             OpendaylightFlowStatisticsListener,
-                                             OpendaylightFlowTableStatisticsListener,
-                                             OpendaylightPortStatisticsListener {
-
-    private static val LOG = LoggerFactory.getLogger(InventoryAndReadAdapter);
-
-    private static val OPENFLOWV10_TABLE_ID = new Integer(0).shortValue;
-    @Property
-    DataBrokerService dataService;
-
-    @Property
-    DataProviderService dataProviderService;
-
-    @Property
-    OpendaylightFlowStatisticsService flowStatisticsService;
-
-    @Property
-    OpendaylightPortStatisticsService nodeConnectorStatisticsService;
-    
-    @Property
-    OpendaylightFlowTableStatisticsService flowTableStatisticsService;
-
-    @Property
-    FlowTopologyDiscoveryService topologyDiscovery;
-    
-    @Property
-    List<IPluginOutReadService> statisticsPublisher = new CopyOnWriteArrayList<IPluginOutReadService>();
-
-    @Property
-    List<IPluginOutInventoryService> inventoryPublisher = new CopyOnWriteArrayList<IPluginOutInventoryService>();
-
-    private final InventoryNotificationProvider inventoryNotificationProvider = new InventoryNotificationProvider();
-
-    private final Map<InstanceIdentifier.PathArgument, List<InstanceIdentifier.PathArgument>> nodeToNodeConnectorsMap = new ConcurrentHashMap<InstanceIdentifier.PathArgument, List<InstanceIdentifier.PathArgument>>();
-
-    private final Lock nodeToNodeConnectorsLock = new ReentrantLock();
-
-
-    def startAdapter(){
-        inventoryNotificationProvider.dataProviderService = dataProviderService;
-        inventoryNotificationProvider.inventoryPublisher = inventoryPublisher;
-        // inventoryNotificationProvider.start();
-    }
-
-    def start(){
-    }
-
-    def setInventoryPublisher(IPluginOutInventoryService listener){
-        inventoryPublisher.add(listener);
-    }
-
-    def unsetInventoryPublisher(IPluginOutInventoryService listener){
-        inventoryPublisher.remove(listener);
-    }
-
-    def setReadPublisher(IPluginOutReadService listener) {
-        statisticsPublisher.add(listener);
-    }
-    
-    def unsetReadPublisher (IPluginOutReadService listener) {
-        if( listener != null)
-            statisticsPublisher.remove(listener);
-    }
-
-    protected def startChange() {
-        return dataProviderService.beginTransaction;
-    }
-
-    override getTransmitRate(org.opendaylight.controller.sal.core.NodeConnector connector) {
-        val nodeConnector = readFlowCapableNodeConnector(connector.toNodeConnectorRef);
-        return nodeConnector.currentSpeed
-    }
-
-    override readAllFlow(Node node, boolean cached) {
-
-        val output = new ArrayList<FlowOnNode>();
-        val tableRef = InstanceIdentifier.builder(Nodes)
-                                        .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, InventoryMapping.toNodeKey(node))
-                                        .augmentation(FlowCapableNode).child(Table, new TableKey(OPENFLOWV10_TABLE_ID)).toInstance();
-        
-        val it = this.startChange();
-        
-        val table= it.readConfigurationData(tableRef) as Table;
-        
-        if(table != null){
-            LOG.trace("Number of flows installed in table 0 of node {} : {}",node,table.flow.size);
-            
-            for(flow : table.flow){
-                
-                val adsalFlow = ToSalConversionsUtils.toFlow(flow,node);
-                val statsFromDataStore = flow.getAugmentation(FlowStatisticsData);
-                
-                if(statsFromDataStore != null){
-                    val it = new FlowOnNode(adsalFlow);
-                    byteCount =  statsFromDataStore.flowStatistics.byteCount.value.longValue;
-                    packetCount = statsFromDataStore.flowStatistics.packetCount.value.longValue;
-                    durationSeconds = statsFromDataStore.flowStatistics.duration.second.value.intValue;
-                    durationNanoseconds = statsFromDataStore.flowStatistics.duration.nanosecond.value.intValue;
-                    
-                    output.add(it);
-                }
-            }
-        }
-        
-        //TODO (main): Shell we send request to the switch? It will make async request to the switch.
-        // Once plugin receive response, it will let adaptor know through onFlowStatisticsUpdate()
-        // If we assume that md-sal statistics manager will always be running, then its not required
-        // But if not, then sending request will collect the latest data for adaptor atleast.
-        val input = new GetAllFlowsStatisticsFromAllFlowTablesInputBuilder;
-        input.setNode(node.toNodeRef);
-        flowStatisticsService.getAllFlowsStatisticsFromAllFlowTables(input.build)
-        
-        return output;
-    }
-
-    override readAllNodeConnector(Node node, boolean cached) {
-        
-        val ret = new ArrayList<NodeConnectorStatistics>();
-        val nodeRef = InstanceIdentifier.builder(Nodes)
-                                    .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, InventoryMapping.toNodeKey(node))
-                                    .toInstance();
-        
-        val provider = this.startChange();
-        
-        val dsNode= provider.readConfigurationData(nodeRef) as org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-        
-         if(dsNode != null){
-             
-             for (dsNodeConnector : dsNode.nodeConnector){
-                val nodeConnectorRef = InstanceIdentifier.builder(Nodes)
-                                    .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, InventoryMapping.toNodeKey(node))
-                                    .child(NodeConnector, dsNodeConnector.key)
-                                    .toInstance();
-                 
-                 val nodeConnectorFromDS = provider.readConfigurationData(nodeConnectorRef) as NodeConnector;
-                 
-                 if(nodeConnectorFromDS != null){
-                     val nodeConnectorStatsFromDs = nodeConnectorFromDS.getAugmentation(FlowCapableNodeConnectorStatisticsData) as FlowCapableNodeConnectorStatistics;
-                     
-                    ret.add(toNodeConnectorStatistics(nodeConnectorStatsFromDs.flowCapableNodeConnectorStatistics,dsNode.id,dsNodeConnector.id));
-                 }
-             }
-         }
-
-        //TODO: Refer TODO (main)
-        val input = new GetAllNodeConnectorsStatisticsInputBuilder();
-        input.setNode(node.toNodeRef);
-        nodeConnectorStatisticsService.getAllNodeConnectorsStatistics(input.build());
-        return ret;
-    }
-
-    override readAllNodeTable(Node node, boolean cached) {
-        val ret = new ArrayList<NodeTableStatistics>();
-        
-        val dsFlowCapableNode= readFlowCapableNode(node.toNodeRef)
-        
-         if(dsFlowCapableNode != null){
-             
-             for (table : dsFlowCapableNode.table){
-                 
-                 val tableStats = table.getAugmentation(FlowTableStatisticsData);
-                 
-                 if(tableStats != null){
-                     ret.add(toNodeTableStatistics(tableStats.flowTableStatistics,table.id,node));
-                 }
-             }
-         }
-
-        //TODO: Refer TODO (main)
-        val input = new GetFlowTablesStatisticsInputBuilder();
-        input.setNode(node.toNodeRef);
-        flowTableStatisticsService.getFlowTablesStatistics(input.build);
-        return ret;
-    }
-
-    override readDescription(Node node, boolean cached) {
-        return toNodeDescription(node.toNodeRef);
-    }
-
-    override readFlow(Node node, Flow targetFlow, boolean cached) {
-        var FlowOnNode ret= null;
-        
-        val tableRef = InstanceIdentifier.builder(Nodes)
-                                        .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, InventoryMapping.toNodeKey(node))
-                                        .augmentation(FlowCapableNode).child(Table, new TableKey(OPENFLOWV10_TABLE_ID)).toInstance();
-        
-        val it = this.startChange();
-        
-        val table= it.readConfigurationData(tableRef) as Table;
-        
-        if(table != null){
-            LOG.trace("Number of flows installed in table 0 of node {} : {}",node,table.flow.size);
-            
-            for(mdsalFlow : table.flow){
-                if(FromSalConversionsUtils.flowEquals(mdsalFlow, MDFlowMapping.toMDSalflow(targetFlow))){
-                    val statsFromDataStore = mdsalFlow.getAugmentation(FlowStatisticsData);
-                    
-                    if(statsFromDataStore != null){
-                        LOG.debug("Found matching flow in the data store flow table ");
-                        val it = new FlowOnNode(targetFlow);
-                        byteCount =  statsFromDataStore.flowStatistics.byteCount.value.longValue;
-                        packetCount = statsFromDataStore.flowStatistics.packetCount.value.longValue;
-                        durationSeconds = statsFromDataStore.flowStatistics.duration.second.value.intValue;
-                        durationNanoseconds = statsFromDataStore.flowStatistics.duration.nanosecond.value.intValue;
-                        
-                        ret = it;
-                    }
-                }            
-            }
-        }
-        
-        //TODO: Refer TODO (main)
-        val input = new GetFlowStatisticsFromFlowTableInputBuilder;
-        input.setNode(node.toNodeRef);
-        input.fieldsFrom(MDFlowMapping.toMDSalflow(targetFlow));
-        flowStatisticsService.getFlowStatisticsFromFlowTable(input.build)
-        
-        return ret;
-        
-    }
-
-    override readNodeConnector(org.opendaylight.controller.sal.core.NodeConnector connector, boolean cached) {
-        var NodeConnectorStatistics  nodeConnectorStatistics = null;
-    
-        val nodeConnectorRef = InstanceIdentifier.builder(Nodes)
-                                    .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, InventoryMapping.toNodeKey(connector.node))
-                                    .child(NodeConnector, InventoryMapping.toNodeConnectorKey(connector))
-                                    .toInstance();
-         val provider = this.startChange();
-                 
-         val nodeConnectorFromDS = provider.readConfigurationData(nodeConnectorRef) as NodeConnector;
-                 
-         if(nodeConnectorFromDS != null){
-            val nodeConnectorStatsFromDs = nodeConnectorFromDS.getAugmentation(FlowCapableNodeConnectorStatisticsData) as FlowCapableNodeConnectorStatistics;
-            if(nodeConnectorStatsFromDs != null) {
-                nodeConnectorStatistics = toNodeConnectorStatistics(nodeConnectorStatsFromDs.flowCapableNodeConnectorStatistics,
-                                                                        InventoryMapping.toNodeKey(connector.node).id,
-                                                                        InventoryMapping.toNodeConnectorKey(connector).id);
-            }
-        }
-
-        //TODO: Refer TODO (main)
-        val input = new GetNodeConnectorStatisticsInputBuilder();
-        input.setNode(connector.node.toNodeRef);
-        input.setNodeConnectorId(InventoryMapping.toNodeConnectorKey(connector).id);
-        nodeConnectorStatisticsService.getNodeConnectorStatistics(input.build());
-        return nodeConnectorStatistics;
-    }
-
-    override readNodeTable(NodeTable nodeTable, boolean cached) {
-        var NodeTableStatistics nodeStats = null
-        
-        val tableRef = InstanceIdentifier.builder(Nodes)
-                                        .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, InventoryMapping.toNodeKey(nodeTable.node))
-                                        .augmentation(FlowCapableNode).child(Table, new TableKey(nodeTable.ID as Short)).toInstance();
-        
-        val it = this.startChange();
-        
-        val table= it.readConfigurationData(tableRef) as Table;
-        
-        if(table != null){
-            val tableStats = table.getAugmentation(FlowTableStatisticsData);
-                 
-             if(tableStats != null){
-                 nodeStats =  toNodeTableStatistics(tableStats.flowTableStatistics,table.id,nodeTable.node);
-            }
-        }
-
-        //TODO: Refer TODO (main)
-        val input = new GetFlowTablesStatisticsInputBuilder();
-        input.setNode(nodeTable.node.toNodeRef);
-        flowTableStatisticsService.getFlowTablesStatistics(input.build);
-        
-        return nodeStats;
-    }
-
-    override onNodeConnectorRemoved(NodeConnectorRemoved update) {
-        // Never received
-    }
-
-    override onNodeRemoved(NodeRemoved notification) {
-        val properties = Collections.<org.opendaylight.controller.sal.core.Property>emptySet();
-
-        removeNodeConnectors(notification.nodeRef.value);
-
-        publishNodeUpdate(notification.nodeRef.toADNode, UpdateType.REMOVED, properties);
-    }
-
-    override onNodeConnectorUpdated(NodeConnectorUpdated update) {
-        var updateType = UpdateType.CHANGED;
-        if(!isKnownNodeConnector(update.nodeConnectorRef.value)){
-            updateType = UpdateType.ADDED;
-            recordNodeConnector(update.nodeConnectorRef.value);
-        }
-
-        var nodeConnector = update.nodeConnectorRef.toADNodeConnector
-
-        publishNodeConnectorUpdate(nodeConnector , updateType , update.toADNodeConnectorProperties);
-    }
-
-    override onNodeUpdated(NodeUpdated notification) {
-        val InstanceIdentifier<? extends DataObject> identifier = notification.nodeRef.value  as InstanceIdentifier<? extends DataObject>;
-
-        var updateType = UpdateType.CHANGED;
-        if ( this._dataService.readOperationalData(identifier) == null ){
-            updateType = UpdateType.ADDED;
-        }
-        publishNodeUpdate(notification.nodeRef.toADNode, updateType, notification.toADNodeProperties);
-
-        //Notify the listeners of IPluginOutReadService
-
-        for (statsPublisher : statisticsPublisher){
-            val nodeRef = InstanceIdentifier.builder(Nodes).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(notification.id)).toInstance;
-            val description = notification.nodeRef.toNodeDescription
-            if(description != null) {
-              statsPublisher.descriptionStatisticsUpdated(nodeRef.toADNode,description);
-            }
-        }
-    }
-
-    override getNodeProps() {
-        val props = new ConcurrentHashMap<Node, Map<String, org.opendaylight.controller.sal.core.Property>>()
-        
-        val nodes = readAllMDNodes()
-        for (node : nodes.node ) {
-            val fcn = node.getAugmentation(FlowCapableNode)
-            if(fcn != null) {
-                val perNodeProps = fcn.toADNodeProperties(node.id)
-                val perNodePropMap = new ConcurrentHashMap<String, org.opendaylight.controller.sal.core.Property>
-                if(perNodeProps != null ) {
-                    for(perNodeProp : perNodeProps) {
-                        perNodePropMap.put(perNodeProp.name,perNodeProp)
-                    }
-                }
-                props.put(new Node(MD_SAL_TYPE, node.id.toADNodeId),perNodePropMap)
-            }
-        }
-        return props;
-    }
-    
-    private def readAllMDNodes() {
-        val nodesRef = InstanceIdentifier.builder(Nodes)
-            .toInstance
-        val reader = TypeSafeDataReader.forReader(dataService)
-        return reader.readOperationalData(nodesRef)
-    }
-    
-    private def readAllMDNodeConnectors(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node) {
-        val nodeRef = InstanceIdentifier.builder(Nodes)
-            .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(node.id))
-            .toInstance
-        val reader = TypeSafeDataReader.forReader(dataService)
-        return reader.readOperationalData(nodeRef).nodeConnector
-    }
-
-    override getNodeConnectorProps(Boolean refresh) {
-        // Note, because the MD-SAL has a unified data store, we can ignore the Boolean refresh, as we have no secondary 
-        // data store to refresh from
-        val props = new ConcurrentHashMap<org.opendaylight.controller.sal.core.NodeConnector, Map<String, org.opendaylight.controller.sal.core.Property>>()
-        val nodes = readAllMDNodes()
-        for (node : nodes.node) {
-            val ncs = node.readAllMDNodeConnectors
-            if(ncs != null) {
-                for( nc : ncs ) {
-                    val fcnc = nc.getAugmentation(FlowCapableNodeConnector)
-                    if(fcnc != null) {
-                        val ncps = fcnc.toADNodeConnectorProperties
-                        val ncpsm = new ConcurrentHashMap<String, org.opendaylight.controller.sal.core.Property>
-                        if(ncps != null) {
-                            for(p : ncps) {
-                                ncpsm.put(p.name,p)
-                            }
-                        }  
-                        props.put(nc.id.toADNodeConnector(node.id),ncpsm)
-                    }
-                }
-            }
-        }
-        return props
-    }
-
-    private def FlowCapableNode readFlowCapableNode(NodeRef ref) {
-        val dataObject = dataService.readOperationalData(ref.value as InstanceIdentifier<? extends DataObject>);
-        if(dataObject != null) {
-            val node = dataObject.checkInstanceOf(
-                org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node);
-            return node.getAugmentation(FlowCapableNode);
-        }
-        return null;
-    }
-
-    private def FlowCapableNodeConnector readFlowCapableNodeConnector(NodeConnectorRef ref) {
-        val dataObject = dataService.readOperationalData(ref.value as InstanceIdentifier<? extends DataObject>);
-        val node = dataObject.checkInstanceOf(
-            NodeConnector);
-        return node.getAugmentation(FlowCapableNodeConnector);
-    }
-
-    private def toNodeConnectorStatistics(
-        org.opendaylight.yang.gen.v1.urn.opendaylight.model.statistics.types.rev130925.NodeConnectorStatistics nodeConnectorStatistics, NodeId nodeId, NodeConnectorId nodeConnectorId) {
-            
-            val it = new NodeConnectorStatistics();
-            
-            receivePacketCount = nodeConnectorStatistics.packets.received.longValue;
-            transmitPacketCount = nodeConnectorStatistics.packets.transmitted.longValue;
-            
-            receiveByteCount = nodeConnectorStatistics.bytes.received.longValue;
-            transmitByteCount = nodeConnectorStatistics.bytes.transmitted.longValue;
-            
-            receiveDropCount = nodeConnectorStatistics.receiveDrops.longValue;
-            transmitDropCount = nodeConnectorStatistics.transmitDrops.longValue;
-            
-            receiveErrorCount = nodeConnectorStatistics.receiveErrors.longValue;
-            transmitErrorCount = nodeConnectorStatistics.transmitErrors.longValue;
-            
-            receiveFrameErrorCount = nodeConnectorStatistics.receiveFrameError.longValue;
-            receiveOverRunErrorCount = nodeConnectorStatistics.receiveOverRunError.longValue;
-            receiveCRCErrorCount = nodeConnectorStatistics.receiveCrcError.longValue;
-            collisionCount = nodeConnectorStatistics.collisionCount.longValue;
-            
-            val nodeConnectorRef = InstanceIdentifier.builder(Nodes)
-                                .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(nodeId))
-                                .child(NodeConnector,new NodeConnectorKey(nodeConnectorId)).toInstance;
-            
-            nodeConnector = NodeMapping.toADNodeConnector(new NodeConnectorRef(nodeConnectorRef));
-            
-            return it;
-    }
-
-    private def toNodeTableStatistics(
-        FlowTableStatistics tableStats,
-        Short tableId,Node node){
-        var it = new NodeTableStatistics();
-        
-        activeCount = tableStats.activeFlows.value.intValue;
-        lookupCount = tableStats.packetsLookedUp.value.intValue;
-        matchedCount = tableStats.packetsMatched.value.intValue;
-        name = tableId.toString;
-        nodeTable = new NodeTable(NodeMapping.MD_SAL_TYPE,tableId,node);
-        return it;
-    }
-    
-    private def toNodeDescription(NodeRef nodeRef){
-        val capableNode = readFlowCapableNode(nodeRef);
-        if(capableNode !=null) {
-            val it = new NodeDescription()
-            manufacturer = capableNode.manufacturer
-            serialNumber = capableNode.serialNumber
-            software = capableNode.software
-            description = capableNode.description
-            
-            return it;
-         }
-         return null;
-    }
-    
-    
-    def Edge toADEdge(Link link) {
-        new Edge(link.source.toADNodeConnector,link.destination.toADNodeConnector)
-    }
-    
-    /*
-     * OpendaylightFlowStatisticsListener interface implementation
-     */
-    override onAggregateFlowStatisticsUpdate(AggregateFlowStatisticsUpdate notification) {
-        //Ignoring this notification as there does not seem to be a way to bubble this up to AD-SAL
-    }
-    
-    override onFlowsStatisticsUpdate(FlowsStatisticsUpdate notification) {
-        
-        val adsalFlowsStatistics = new ArrayList<FlowOnNode>();
-        val nodeRef = InstanceIdentifier.builder(Nodes).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(notification.id)).toInstance;
-        
-        for(flowStats : notification.flowAndStatisticsMapList){
-            if(flowStats.tableId == 0)
-                adsalFlowsStatistics.add(toFlowOnNode(flowStats,nodeRef.toADNode));
-        }
-        
-        for (statsPublisher : statisticsPublisher){
-            statsPublisher.nodeFlowStatisticsUpdated(nodeRef.toADNode,adsalFlowsStatistics);
-        }
-        
-    }
-    /*
-     * OpendaylightFlowTableStatisticsListener interface implementation
-     */    
-    override onFlowTableStatisticsUpdate(FlowTableStatisticsUpdate notification) {
-        var adsalFlowTableStatistics = new ArrayList<NodeTableStatistics>();
-        
-        for(stats : notification.flowTableAndStatisticsMap){
-            if (stats.tableId.value == 0){
-                val it = new NodeTableStatistics();
-                activeCount = stats.activeFlows.value.intValue;
-                lookupCount = stats.packetsLookedUp.value.longValue;
-                matchedCount = stats.packetsMatched.value.longValue;
-                
-                adsalFlowTableStatistics.add(it);
-            }
-        }
-        for (statsPublisher : statisticsPublisher){
-            val nodeRef = InstanceIdentifier.builder(Nodes).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(notification.id)).toInstance;
-            statsPublisher.nodeTableStatisticsUpdated(nodeRef.toADNode,adsalFlowTableStatistics);
-        }
-    }
-    
-    /*
-     * OpendaylightPortStatisticsUpdate interface implementation
-     */
-    override onNodeConnectorStatisticsUpdate(NodeConnectorStatisticsUpdate notification) {
-        
-        val adsalPortStatistics  = new ArrayList<NodeConnectorStatistics>();
-        
-        for(nodeConnectorStatistics : notification.nodeConnectorStatisticsAndPortNumberMap){
-            adsalPortStatistics.add(toNodeConnectorStatistics(nodeConnectorStatistics,notification.id,nodeConnectorStatistics.nodeConnectorId));
-        }
-        
-        for (statsPublisher : statisticsPublisher){
-            val nodeRef = InstanceIdentifier.builder(Nodes).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,new NodeKey(notification.id)).toInstance;
-            statsPublisher.nodeConnectorStatisticsUpdated(nodeRef.toADNode,adsalPortStatistics);
-        }
-        
-    }
-    
-    private static def toFlowOnNode (FlowAndStatisticsMapList flowAndStatsMap,Node node){
-        
-        val it = new FlowOnNode(ToSalConversionsUtils.toFlow(flowAndStatsMap,node));
-        
-        byteCount = flowAndStatsMap.byteCount.value.longValue;
-        packetCount = flowAndStatsMap.packetCount.value.longValue;
-        durationSeconds = flowAndStatsMap.duration.second.value.intValue;
-        durationNanoseconds = flowAndStatsMap.duration.nanosecond.value.intValue;
-        
-        return it;
-    }
-
-    override  getConfiguredNotConnectedNodes() {
-        return Collections.emptySet();
-    }
-
-
-    private def publishNodeUpdate(Node node, UpdateType updateType, Set<org.opendaylight.controller.sal.core.Property> properties){
-        for( publisher : inventoryPublisher){
-            publisher.updateNode(node, updateType, properties);
-        }
-    }
-
-    private def publishNodeConnectorUpdate(org.opendaylight.controller.sal.core.NodeConnector nodeConnector, UpdateType updateType, Set<org.opendaylight.controller.sal.core.Property> properties){
-        for( publisher : inventoryPublisher){
-            publisher.updateNodeConnector(nodeConnector, updateType, properties);
-        }
-    }
-
-    private def isKnownNodeConnector(InstanceIdentifier<? extends Object> nodeConnectorIdentifier){
-        if(nodeConnectorIdentifier.path.size() < 3) {
-            return false;
-        }
-
-        val nodePath = nodeConnectorIdentifier.path.get(1);
-        val nodeConnectorPath = nodeConnectorIdentifier.getPath().get(2);
-
-        val nodeConnectors = nodeToNodeConnectorsMap.get(nodePath);
-
-        if(nodeConnectors == null){
-            return false;
-        }
-        return nodeConnectors.contains(nodeConnectorPath);
-    }
-
-
-    private def recordNodeConnector(InstanceIdentifier<? extends Object> nodeConnectorIdentifier){
-        if(nodeConnectorIdentifier.path.size() < 3) {
-            return false;
-        }
-
-        val nodePath = nodeConnectorIdentifier.path.get(1);
-        val nodeConnectorPath = nodeConnectorIdentifier.getPath().get(2);
-
-        nodeToNodeConnectorsLock.lock();
-
-        try {
-            var nodeConnectors = nodeToNodeConnectorsMap.get(nodePath);
-
-            if(nodeConnectors == null){
-                nodeConnectors = new ArrayList<InstanceIdentifier.PathArgument>();
-                nodeToNodeConnectorsMap.put(nodePath, nodeConnectors);
-            }
-
-            nodeConnectors.add(nodeConnectorPath);
-        } finally {
-            nodeToNodeConnectorsLock.unlock();
-        }
-    }
-
-    private def removeNodeConnectors(InstanceIdentifier<? extends Object> nodeIdentifier){
-        val nodePath = nodeIdentifier.path.get(1);
-
-        nodeToNodeConnectorsMap.remove(nodePath);
-    }
-}
index 29904220d710933c71320f0069e78aef03e2046d..1e4d97446f3596b6fef7668b3bd2f74da316a9f1 100644 (file)
 /**
  * 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.compatibility;
 
-import org.eclipse.xtend2.lib.StringConcatenation;
-import org.eclipse.xtext.xbase.lib.Conversions;
-import org.eclipse.xtext.xbase.lib.IterableExtensions;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.core.NodeConnector;
+import java.util.Iterator;
+
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
-
-import java.util.List;
-
-@SuppressWarnings("all")
-public class InventoryMapping {
-  public static NodeConnector toAdNodeConnector(final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector> identifier) {
-    final List<PathArgument> path = identifier.getPath();
-    final PathArgument lastPathArgument = IterableExtensions.<PathArgument>last(path);
-    final NodeConnectorKey tpKey = ((IdentifiableItem<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector,NodeConnectorKey>) lastPathArgument).getKey();
-    return InventoryMapping.nodeConnectorFromId(tpKey.getId().getValue());
-  }
-  
-  public static Node toAdNode(final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> identifier) {
-    final List<PathArgument> path = identifier.getPath();
-    final PathArgument lastPathArgument = IterableExtensions.<PathArgument>last(path);
-    final NodeKey tpKey = ((IdentifiableItem<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node,NodeKey>) lastPathArgument).getKey();
-    return InventoryMapping.nodeFromNodeId(tpKey.getId().getValue());
-  }
-  
-  public static NodeRef toNodeRef(final Node node) {
-    final NodeId nodeId = new NodeId(InventoryMapping.toNodeId(node));
-    final NodeKey nodeKey = new NodeKey(nodeId);
-    final InstanceIdentifierBuilder<Nodes> nodes = InstanceIdentifier.builder(Nodes.class);
-    final InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> child =
-            nodes.<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node, NodeKey>child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class, nodeKey);
-    final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> path = child.toInstance();
-    return new NodeRef(path);
-  }
-  
-  public static NodeKey toNodeKey(final Node node) {
-    final NodeId nodeId = new NodeId(InventoryMapping.toNodeId(node));
-    return new NodeKey(nodeId);
-  }
-  
-  public static NodeConnectorKey toNodeConnectorKey(final NodeConnector nc) {
-    final NodeConnectorId nodeConnectorId = new NodeConnectorId(InventoryMapping.toNodeConnectorId(nc));
-    return new NodeConnectorKey(nodeConnectorId);
-  }
-  
-  public static String toNodeId(final Node node) {
-    final StringConcatenation builder = new StringConcatenation();
-    builder.append("ad-sal:");
-    builder.append(node.getType(), "");
-    builder.append("::");
-    builder.append(node.getNodeIDString(), "");
-    return builder.toString();
-  }
-  
-  public static String toNodeConnectorId(final NodeConnector nc) {
-    final StringConcatenation builder = new StringConcatenation();
-    builder.append(InventoryMapping.toNodeId(nc.getNode()), "");
-    builder.append("::");
-    builder.append(nc.getNodeConnectorIDString(), "");
-    return builder.toString();
-  }
-  
-  public static Node nodeFromNodeId(final String nodeId) {
-    final String[] split = nodeId.split("::");
-    return InventoryMapping.nodeFromString(split);
-  }
-  
-  public static NodeConnector nodeConnectorFromId(final String invId) {
-    final String[] split = invId.split("::");
-    return InventoryMapping.nodeConnectorFromString(split);
-  }
-  
-  private static NodeConnector nodeConnectorFromString(final String[] string) {
-    final List<String> subList = ((List<String>)Conversions.doWrapArray(string)).subList(0, 1);
-    final Node node = InventoryMapping.nodeFromString(((String[])Conversions.unwrapArray(subList, String.class)));
-    final String index3 = string[2];
-    return NodeConnector.fromStringNoNode(index3, node);
-  }
-  
-  private static Node nodeFromString(final String[] strings) {
-      String index0 = strings[0];
-      final String type = index0.substring(6);
-      String id = strings[1];
-      return Node.fromString(type, id);
-  }
+import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+
+import com.google.common.base.Splitter;
+
+public final class InventoryMapping {
+    private static final String NODE_TYPE_STRING = "::";
+    private static final Splitter NODE_TYPE_SPLITTER = Splitter.on(NODE_TYPE_STRING);
+
+    private InventoryMapping() {
+        throw new UnsupportedOperationException("Utility class");
+    }
+
+    public static org.opendaylight.controller.sal.core.NodeConnector toAdNodeConnector(final InstanceIdentifier<NodeConnector> identifier) {
+        @SuppressWarnings("unchecked")
+        final NodeConnectorKey tpKey = ((KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey>) identifier).getKey();
+        return InventoryMapping.nodeConnectorFromId(tpKey.getId().getValue());
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toAdNode(final InstanceIdentifier<Node> identifier) {
+        @SuppressWarnings("unchecked")
+        final NodeKey tpKey = ((KeyedInstanceIdentifier<Node,NodeKey>)identifier).getKey();
+        return InventoryMapping.nodeFromNodeId(tpKey.getId().getValue());
+    }
+
+    public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) {
+        final NodeKey nodeKey = new NodeKey(new NodeId(InventoryMapping.toNodeId(node)));
+        final InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class)
+                .child(Node.class, nodeKey).toInstance();
+        return new NodeRef(path);
+    }
+
+    public static NodeKey toNodeKey(final org.opendaylight.controller.sal.core.Node node) {
+        final NodeId nodeId = new NodeId(InventoryMapping.toNodeId(node));
+        return new NodeKey(nodeId);
+    }
+
+    public static NodeConnectorKey toNodeConnectorKey(final org.opendaylight.controller.sal.core.NodeConnector nc) {
+        final NodeConnectorId nodeConnectorId = new NodeConnectorId(InventoryMapping.toNodeConnectorId(nc));
+        return new NodeConnectorKey(nodeConnectorId);
+    }
+
+    private static StringBuilder nodeIdBulder(final org.opendaylight.controller.sal.core.Node node) {
+        final StringBuilder sb = new StringBuilder();
+        sb.append("ad-sal:");
+        sb.append(node.getType());
+        sb.append(NODE_TYPE_STRING);
+        sb.append(node.getNodeIDString());
+        return sb;
+    }
+
+    public static String toNodeId(final org.opendaylight.controller.sal.core.Node node) {
+        return nodeIdBulder(node).toString();
+    }
+
+    public static String toNodeConnectorId(final org.opendaylight.controller.sal.core.NodeConnector nc) {
+        final StringBuilder sb = nodeIdBulder(nc.getNode());
+        sb.append(NODE_TYPE_STRING);
+        sb.append(nc.getNodeConnectorIDString());
+        return sb.toString();
+    }
+
+    public static org.opendaylight.controller.sal.core.Node nodeFromNodeId(final String nodeId) {
+        return InventoryMapping.nodeFromStrings(NODE_TYPE_SPLITTER.split(nodeId).iterator());
+    }
+
+    public static org.opendaylight.controller.sal.core.NodeConnector nodeConnectorFromId(final String invId) {
+        return InventoryMapping.nodeConnectorFromString(NODE_TYPE_SPLITTER.split(invId).iterator());
+    }
+
+    private static org.opendaylight.controller.sal.core.NodeConnector nodeConnectorFromString(final Iterator<String> it) {
+        final org.opendaylight.controller.sal.core.Node node = InventoryMapping.nodeFromStrings(it);
+        return org.opendaylight.controller.sal.core.NodeConnector.fromStringNoNode(it.next(), node);
+    }
+
+    private static org.opendaylight.controller.sal.core.Node nodeFromStrings(final Iterator<String> it) {
+        final String type = it.next().substring(6);
+        return org.opendaylight.controller.sal.core.Node.fromString(type, it.next());
+    }
 }
index 2c95252ac7f6a3e571dcb8cceb03de24dbc2d0c0..ba86ad99fb9bcde573c3cb4404d12d444ab697ba 100644 (file)
@@ -61,314 +61,314 @@ import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
 
 public final class NodeMapping {
-  public final static String MD_SAL_TYPE = "MD_SAL";
-
-  private final static Class<Node> NODE_CLASS = Node.class;
-
-  private final static Class<NodeConnector> NODECONNECTOR_CLASS = NodeConnector.class;
-
-  private NodeMapping() {
-    throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
-  }
-
-  public static org.opendaylight.controller.sal.core.Node toADNode(final InstanceIdentifier<? extends Object> node) throws ConstructionException {
-    NodeId nodeId = NodeMapping.toNodeId(node);
-    return NodeMapping.toADNode(nodeId);
-  }
-
-  public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) throws ConstructionException {
-      String aDNodeId = NodeMapping.toADNodeId(id);
-      return  new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, aDNodeId);
-  }
-
-  public static NodeId toNodeId(final InstanceIdentifier<?> id) {
-    final NodeKey key = id.firstKeyOf(Node.class, NodeKey.class);
-    Preconditions.checkArgument(key != null, "No node identifier found in %s", id);
-    return key.getId();
-  }
-
-  public static String toADNodeId(final NodeId nodeId) {
-    return nodeId.getValue();
-  }
-
-  public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorRef source) throws ConstructionException {
-    final InstanceIdentifier<?> id = Preconditions.checkNotNull(source.getValue());
-    final NodeConnectorKey key = id.firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
-    return NodeMapping.toADNodeConnector(key.getId(), NodeMapping.toNodeId(id));
-  }
-
-  public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorId ncid, final NodeId nid) throws ConstructionException {
-    String nodeConnectorType = NodeMapping.toNodeConnectorType(ncid, nid);
-    Object aDNodeConnectorId = NodeMapping.toADNodeConnectorId(ncid, nid);
-    org.opendaylight.controller.sal.core.Node aDNode = NodeMapping.toADNode(nid);
-    return new org.opendaylight.controller.sal.core.NodeConnector(nodeConnectorType, aDNodeConnectorId, aDNode);
-  }
-
-  public static String toNodeConnectorType(final NodeConnectorId ncId, final NodeId nodeId) {
-    if (ncId.equals(toLocalNodeConnectorId(nodeId))) {
-        return NodeConnectorIDType.SWSTACK;
-    } else if (ncId.equals(toNormalNodeConnectorId(nodeId))) {
-        return NodeConnectorIDType.HWPATH;
-    } else if (ncId.equals(toControllerNodeConnectorId(nodeId))) {
-        return NodeConnectorIDType.CONTROLLER;
-    }
-    return MD_SAL_TYPE;
-  }
-
-  public static Object toADNodeConnectorId(final NodeConnectorId nodeConnectorId, final NodeId nodeId) {
-    if (nodeConnectorId.equals(toLocalNodeConnectorId(nodeId)) ||
-        nodeConnectorId.equals(toNormalNodeConnectorId(nodeId)) ||
-        nodeConnectorId.equals(toControllerNodeConnectorId(nodeId))) {
-        return org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID;
-    }
-    return nodeConnectorId.getValue();
-  }
-
-  public static NodeConnectorId toControllerNodeConnectorId(final NodeId node) {
-    return new NodeConnectorId(node.getValue() + ":" + 4294967293L);
-  }
-
-  public static NodeConnectorId toLocalNodeConnectorId(final NodeId node) {
-    return new NodeConnectorId(node.getValue() + ":" + 4294967294L);
-  }
-
-  public static NodeConnectorId toNormalNodeConnectorId(final NodeId node) {
-    return new NodeConnectorId(node.getValue() + ":" + 4294967290L);
-  }
-
-  public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) {
-    Preconditions.checkArgument(MD_SAL_TYPE.equals(node.getType()));
-    final String nodeId = Arguments.<String>checkInstanceOf(node.getID(), String.class);
-    final NodeKey nodeKey = new NodeKey(new NodeId(nodeId));
-    final InstanceIdentifier<Node> nodePath = InstanceIdentifier.builder(Nodes.class).child(NODE_CLASS, nodeKey).toInstance();
-    return new NodeRef(nodePath);
-  }
-
-  public static NodeConnectorRef toNodeConnectorRef(final org.opendaylight.controller.sal.core.NodeConnector nodeConnector) {
-
-    final NodeRef node = NodeMapping.toNodeRef(nodeConnector.getNode());
-    @SuppressWarnings("unchecked")
-    final InstanceIdentifier<Node> nodePath = ((InstanceIdentifier<Node>) node.getValue());
-    NodeConnectorId nodeConnectorId = null;
-
-    if (nodeConnector.getID().equals(org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID)) {
-        final NodeId nodeId = toNodeId(nodePath);
-        final String nodeConnectorType = nodeConnector.getType();
-        if (nodeConnectorType.equals(NodeConnectorIDType.SWSTACK)) {
-            nodeConnectorId = toLocalNodeConnectorId(nodeId);
-        } else if (nodeConnectorType.equals(NodeConnectorIDType.HWPATH)) {
-            nodeConnectorId = toNormalNodeConnectorId(nodeId);
-        } else if (nodeConnectorType.equals(NodeConnectorIDType.CONTROLLER)) {
-            nodeConnectorId = toControllerNodeConnectorId(nodeId);
+    public final static String MD_SAL_TYPE = "MD_SAL";
+
+    private final static Class<Node> NODE_CLASS = Node.class;
+
+    private final static Class<NodeConnector> NODECONNECTOR_CLASS = NodeConnector.class;
+
+    private NodeMapping() {
+        throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toADNode(final InstanceIdentifier<? extends Object> node) throws ConstructionException {
+        NodeId nodeId = NodeMapping.toNodeId(node);
+        return NodeMapping.toADNode(nodeId);
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toADNode(final NodeId id) throws ConstructionException {
+        String aDNodeId = NodeMapping.toADNodeId(id);
+        return new org.opendaylight.controller.sal.core.Node(NodeMapping.MD_SAL_TYPE, aDNodeId);
+    }
+
+    public static NodeId toNodeId(final InstanceIdentifier<?> id) {
+        final NodeKey key = id.firstKeyOf(Node.class, NodeKey.class);
+        Preconditions.checkArgument(key != null, "No node identifier found in %s", id);
+        return key.getId();
+    }
+
+    public static String toADNodeId(final NodeId nodeId) {
+        return nodeId.getValue();
+    }
+
+    public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorRef source) throws ConstructionException {
+        final InstanceIdentifier<?> id = Preconditions.checkNotNull(source.getValue());
+        final NodeConnectorKey key = id.firstKeyOf(NodeConnector.class, NodeConnectorKey.class);
+        return NodeMapping.toADNodeConnector(key.getId(), NodeMapping.toNodeId(id));
+    }
+
+    public static org.opendaylight.controller.sal.core.NodeConnector toADNodeConnector(final NodeConnectorId ncid, final NodeId nid) throws ConstructionException {
+        String nodeConnectorType = NodeMapping.toNodeConnectorType(ncid, nid);
+        Object aDNodeConnectorId = NodeMapping.toADNodeConnectorId(ncid, nid);
+        org.opendaylight.controller.sal.core.Node aDNode = NodeMapping.toADNode(nid);
+        return new org.opendaylight.controller.sal.core.NodeConnector(nodeConnectorType, aDNodeConnectorId, aDNode);
+    }
+
+    public static String toNodeConnectorType(final NodeConnectorId ncId, final NodeId nodeId) {
+        if (ncId.equals(toLocalNodeConnectorId(nodeId))) {
+            return NodeConnectorIDType.SWSTACK;
+        } else if (ncId.equals(toNormalNodeConnectorId(nodeId))) {
+            return NodeConnectorIDType.HWPATH;
+        } else if (ncId.equals(toControllerNodeConnectorId(nodeId))) {
+            return NodeConnectorIDType.CONTROLLER;
         }
-    } else {
-        nodeConnectorId = new NodeConnectorId(Arguments.<String>checkInstanceOf(nodeConnector.getID(), String.class));
+        return MD_SAL_TYPE;
     }
-    final NodeConnectorKey connectorKey = new NodeConnectorKey(nodeConnectorId);
-    final InstanceIdentifier<NodeConnector> path = nodePath.child(NODECONNECTOR_CLASS, connectorKey);
-    return new NodeConnectorRef(path);
-  }
 
-  public static org.opendaylight.controller.sal.core.Node toADNode(final NodeRef node) throws ConstructionException {
-    return NodeMapping.toADNode(node.getValue());
-  }
+    public static Object toADNodeConnectorId(final NodeConnectorId nodeConnectorId, final NodeId nodeId) {
+        if (nodeConnectorId.equals(toLocalNodeConnectorId(nodeId)) ||
+                nodeConnectorId.equals(toNormalNodeConnectorId(nodeId)) ||
+                nodeConnectorId.equals(toControllerNodeConnectorId(nodeId))) {
+            return org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID;
+        }
+        return nodeConnectorId.getValue();
+    }
 
-  public static HashSet<Property> toADNodeConnectorProperties(final NodeConnectorUpdated nc) {
-    final FlowCapableNodeConnectorUpdated fcncu = nc.<FlowCapableNodeConnectorUpdated>getAugmentation(FlowCapableNodeConnectorUpdated.class);
-    if (!Objects.equal(fcncu, null)) {
-      return NodeMapping.toADNodeConnectorProperties(fcncu);
+    public static NodeConnectorId toControllerNodeConnectorId(final NodeId node) {
+        return new NodeConnectorId(node.getValue() + ":" + 4294967293L);
     }
-    return new HashSet<Property>();
-  }
 
-  public static HashSet<Property> toADNodeConnectorProperties(final NodeConnector nc) {
-    final FlowCapableNodeConnector fcnc = nc.<FlowCapableNodeConnector>getAugmentation(FlowCapableNodeConnector.class);
-    if (!Objects.equal(fcnc, null)) {
-      return NodeMapping.toADNodeConnectorProperties(fcnc);
+    public static NodeConnectorId toLocalNodeConnectorId(final NodeId node) {
+        return new NodeConnectorId(node.getValue() + ":" + 4294967294L);
     }
-    return new HashSet<Property>();
-  }
 
-  public static HashSet<Property> toADNodeConnectorProperties(final FlowNodeConnector fcncu) {
+    public static NodeConnectorId toNormalNodeConnectorId(final NodeId node) {
+        return new NodeConnectorId(node.getValue() + ":" + 4294967290L);
+    }
+
+    public static NodeRef toNodeRef(final org.opendaylight.controller.sal.core.Node node) {
+        Preconditions.checkArgument(MD_SAL_TYPE.equals(node.getType()));
+        final String nodeId = Arguments.<String>checkInstanceOf(node.getID(), String.class);
+        final NodeKey nodeKey = new NodeKey(new NodeId(nodeId));
+        final InstanceIdentifier<Node> nodePath = InstanceIdentifier.builder(Nodes.class).child(NODE_CLASS, nodeKey).toInstance();
+        return new NodeRef(nodePath);
+    }
 
-    final HashSet<org.opendaylight.controller.sal.core.Property> props = new HashSet<>();
-    if (fcncu != null) {
-        if (fcncu.getCurrentFeature() != null && toAdBandwidth(fcncu.getCurrentFeature()) != null) {
-            props.add(toAdBandwidth(fcncu.getCurrentFeature()));
+    public static NodeConnectorRef toNodeConnectorRef(final org.opendaylight.controller.sal.core.NodeConnector nodeConnector) {
+
+        final NodeRef node = NodeMapping.toNodeRef(nodeConnector.getNode());
+        @SuppressWarnings("unchecked")
+        final InstanceIdentifier<Node> nodePath = ((InstanceIdentifier<Node>) node.getValue());
+        NodeConnectorId nodeConnectorId = null;
+
+        if (nodeConnector.getID().equals(org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID)) {
+            final NodeId nodeId = toNodeId(nodePath);
+            final String nodeConnectorType = nodeConnector.getType();
+            if (nodeConnectorType.equals(NodeConnectorIDType.SWSTACK)) {
+                nodeConnectorId = toLocalNodeConnectorId(nodeId);
+            } else if (nodeConnectorType.equals(NodeConnectorIDType.HWPATH)) {
+                nodeConnectorId = toNormalNodeConnectorId(nodeId);
+            } else if (nodeConnectorType.equals(NodeConnectorIDType.CONTROLLER)) {
+                nodeConnectorId = toControllerNodeConnectorId(nodeId);
+            }
+        } else {
+            nodeConnectorId = new NodeConnectorId(Arguments.<String>checkInstanceOf(nodeConnector.getID(), String.class));
         }
-        if (fcncu.getAdvertisedFeatures() != null && toAdAdvertizedBandwidth(fcncu.getAdvertisedFeatures()) != null) {
-            props.add(toAdAdvertizedBandwidth(fcncu.getAdvertisedFeatures()));
+        final NodeConnectorKey connectorKey = new NodeConnectorKey(nodeConnectorId);
+        final InstanceIdentifier<NodeConnector> path = nodePath.child(NODECONNECTOR_CLASS, connectorKey);
+        return new NodeConnectorRef(path);
+    }
+
+    public static org.opendaylight.controller.sal.core.Node toADNode(final NodeRef node) throws ConstructionException {
+        return NodeMapping.toADNode(node.getValue());
+    }
+
+    public static HashSet<Property> toADNodeConnectorProperties(final NodeConnectorUpdated nc) {
+        final FlowCapableNodeConnectorUpdated fcncu = nc.<FlowCapableNodeConnectorUpdated>getAugmentation(FlowCapableNodeConnectorUpdated.class);
+        if (!Objects.equal(fcncu, null)) {
+            return NodeMapping.toADNodeConnectorProperties(fcncu);
         }
-        if (fcncu.getSupported() != null && toAdSupportedBandwidth(fcncu.getSupported()) != null) {
-            props.add(toAdSupportedBandwidth(fcncu.getSupported()));
+        return new HashSet<Property>();
+    }
+
+    public static HashSet<Property> toADNodeConnectorProperties(final NodeConnector nc) {
+        final FlowCapableNodeConnector fcnc = nc.<FlowCapableNodeConnector>getAugmentation(FlowCapableNodeConnector.class);
+        if (!Objects.equal(fcnc, null)) {
+            return NodeMapping.toADNodeConnectorProperties(fcnc);
         }
-        if (fcncu.getPeerFeatures() != null && toAdPeerBandwidth(fcncu.getPeerFeatures()) != null) {
-            props.add(toAdPeerBandwidth(fcncu.getPeerFeatures()));
+        return new HashSet<Property>();
+    }
+
+    public static HashSet<Property> toADNodeConnectorProperties(final FlowNodeConnector fcncu) {
+
+        final HashSet<org.opendaylight.controller.sal.core.Property> props = new HashSet<>();
+        if (fcncu != null) {
+            if (fcncu.getCurrentFeature() != null && toAdBandwidth(fcncu.getCurrentFeature()) != null) {
+                props.add(toAdBandwidth(fcncu.getCurrentFeature()));
+            }
+            if (fcncu.getAdvertisedFeatures() != null && toAdAdvertizedBandwidth(fcncu.getAdvertisedFeatures()) != null) {
+                props.add(toAdAdvertizedBandwidth(fcncu.getAdvertisedFeatures()));
+            }
+            if (fcncu.getSupported() != null && toAdSupportedBandwidth(fcncu.getSupported()) != null) {
+                props.add(toAdSupportedBandwidth(fcncu.getSupported()));
+            }
+            if (fcncu.getPeerFeatures() != null && toAdPeerBandwidth(fcncu.getPeerFeatures()) != null) {
+                props.add(toAdPeerBandwidth(fcncu.getPeerFeatures()));
+            }
+            if (fcncu.getName() != null && toAdName(fcncu.getName()) != null) {
+                props.add(toAdName(fcncu.getName()));
+            }
+            if (fcncu.getConfiguration() != null && toAdConfig(fcncu.getConfiguration()) != null) {
+                props.add(toAdConfig(fcncu.getConfiguration()));
+            }
+            if (fcncu.getState() != null && toAdState(fcncu.getState()) != null) {
+                props.add(toAdState(fcncu.getState()));
+            }
         }
-        if (fcncu.getName() != null && toAdName(fcncu.getName()) != null) {
-            props.add(toAdName(fcncu.getName()));
+        return props;
+    }
+
+    public static Name toAdName(final String name) {
+        return new Name(name);
+    }
+
+    public static Config toAdConfig(final PortConfig pc) {
+        Config config = null;
+        if (pc.isPORTDOWN()) {
+            config = new Config(Config.ADMIN_DOWN);
+        } else {
+            config = new Config(Config.ADMIN_UP);
+        }
+        return config;
+    }
+
+    public static org.opendaylight.controller.sal.core.State toAdState(final State s) {
+
+        org.opendaylight.controller.sal.core.State state = null;
+        if (s.isLinkDown()) {
+            state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_DOWN);
+        } else {
+            state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_UP);
         }
-        if (fcncu.getConfiguration() != null && toAdConfig(fcncu.getConfiguration()) != null) {
-            props.add(toAdConfig(fcncu.getConfiguration()));
+        return state;
+    }
+
+    public static Bandwidth toAdBandwidth(final PortFeatures pf) {
+        Bandwidth bw = null;
+        if (pf.isTenMbHd() || pf.isTenMbFd()) {
+            bw = new Bandwidth(Bandwidth.BW10Mbps);
+        } else if (pf.isHundredMbHd() || pf.isHundredMbFd()) {
+            bw = new Bandwidth(Bandwidth.BW100Mbps);
+        } else if (pf.isOneGbHd() || pf.isOneGbFd()) {
+            bw = new Bandwidth(Bandwidth.BW1Gbps);
+        } else if (pf.isOneGbFd()) {
+            bw = new Bandwidth(Bandwidth.BW10Gbps);
+        } else if (pf.isTenGbFd()) {
+            bw = new Bandwidth(Bandwidth.BW10Gbps);
+        } else if (pf.isFortyGbFd()) {
+            bw = new Bandwidth(Bandwidth.BW40Gbps);
+        } else if (pf.isHundredGbFd()) {
+            bw = new Bandwidth(Bandwidth.BW100Gbps);
+        } else if (pf.isOneTbFd()) {
+            bw = new Bandwidth(Bandwidth.BW1Tbps);
         }
-        if (fcncu.getState() != null && toAdState(fcncu.getState()) != null) {
-            props.add(toAdState(fcncu.getState()));
+        return bw;
+    }
+
+    public static AdvertisedBandwidth toAdAdvertizedBandwidth(final PortFeatures pf) {
+        AdvertisedBandwidth abw = null;
+        final Bandwidth bw = toAdBandwidth(pf);
+        if (bw != null) {
+            abw = new AdvertisedBandwidth(bw.getValue());
         }
+        return abw;
     }
-    return props;
-  }
-
-  public static Name toAdName(final String name) {
-    return new Name(name);
-  }
-
-  public static Config toAdConfig(final PortConfig pc) {
-    Config config = null;
-    if (pc.isPORTDOWN()) {
-        config = new Config(Config.ADMIN_DOWN);
-    } else {
-        config = new Config(Config.ADMIN_UP);
-    }
-    return config;
-  }
-
-  public static org.opendaylight.controller.sal.core.State toAdState(final State s) {
-
-    org.opendaylight.controller.sal.core.State state = null;
-    if (s.isLinkDown()) {
-        state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_DOWN);
-    } else {
-        state = new org.opendaylight.controller.sal.core.State(org.opendaylight.controller.sal.core.State.EDGE_UP);
-    }
-    return state;
-  }
-
-  public static Bandwidth toAdBandwidth(final PortFeatures pf) {
-    Bandwidth bw = null;
-    if (pf.isTenMbHd() || pf.isTenMbFd()) {
-        bw = new Bandwidth(Bandwidth.BW10Mbps);
-    } else if (pf.isHundredMbHd() || pf.isHundredMbFd()) {
-        bw = new Bandwidth(Bandwidth.BW100Mbps);
-    } else if (pf.isOneGbHd() || pf.isOneGbFd()) {
-        bw = new Bandwidth(Bandwidth.BW1Gbps);
-    } else if (pf.isOneGbFd()) {
-        bw = new Bandwidth(Bandwidth.BW10Gbps);
-    } else if (pf.isTenGbFd()) {
-        bw = new Bandwidth(Bandwidth.BW10Gbps);
-    } else if (pf.isFortyGbFd()) {
-        bw = new Bandwidth(Bandwidth.BW40Gbps);
-    } else if (pf.isHundredGbFd()) {
-        bw = new Bandwidth(Bandwidth.BW100Gbps);
-    } else if (pf.isOneTbFd()) {
-        bw = new Bandwidth(Bandwidth.BW1Tbps);
-    }
-    return bw;
-  }
-
-  public static AdvertisedBandwidth toAdAdvertizedBandwidth(final PortFeatures pf) {
-    AdvertisedBandwidth abw = null;
-    final Bandwidth bw = toAdBandwidth(pf);
-    if (bw != null) {
-        abw = new AdvertisedBandwidth(bw.getValue());
-    }
-    return abw;
-  }
-
-  public static SupportedBandwidth toAdSupportedBandwidth(final PortFeatures pf) {
-    SupportedBandwidth sbw = null;
-    final Bandwidth bw = toAdBandwidth(pf);
-    if (bw != null) {
-        sbw = new SupportedBandwidth(bw.getValue());
-    }
-    return sbw;
-  }
-
-  public static PeerBandwidth toAdPeerBandwidth(final PortFeatures pf) {
-    PeerBandwidth pbw = null;
-    final Bandwidth bw = toAdBandwidth(pf);
-    if (bw != null) {
-        pbw = new PeerBandwidth(bw.getValue());
-    }
-    return pbw;
-  }
-
-  public static HashSet<Property> toADNodeProperties(final NodeUpdated nu) {
-    final FlowCapableNodeUpdated fcnu = nu.getAugmentation(FlowCapableNodeUpdated.class);
-    if (fcnu != null) {
-        return toADNodeProperties(fcnu, nu.getId());
-    }
-    return new HashSet<org.opendaylight.controller.sal.core.Property>();
-  }
-
-  public static HashSet<Property> toADNodeProperties(final FlowNode fcnu, final NodeId id) {
-
-    final HashSet<org.opendaylight.controller.sal.core.Property> props = new HashSet<>();
-
-    if (fcnu != null) {
-        props.add(toADTimestamp());
-
-        // props.add(fcnu.supportedActions.toADActions) - TODO
-        if (id != null) {
-            props.add(toADMacAddress(id));
+
+    public static SupportedBandwidth toAdSupportedBandwidth(final PortFeatures pf) {
+        SupportedBandwidth sbw = null;
+        final Bandwidth bw = toAdBandwidth(pf);
+        if (bw != null) {
+            sbw = new SupportedBandwidth(bw.getValue());
         }
-        SwitchFeatures switchFeatures = fcnu.getSwitchFeatures();
-        if (switchFeatures != null) {
-            if (switchFeatures.getMaxTables() != null) {
-                props.add(toADTables(switchFeatures.getMaxTables()));
-            }
-            if (switchFeatures.getCapabilities() != null) {
-                props.add(toADCapabiliities(switchFeatures.getCapabilities()));
+        return sbw;
+    }
+
+    public static PeerBandwidth toAdPeerBandwidth(final PortFeatures pf) {
+        PeerBandwidth pbw = null;
+        final Bandwidth bw = toAdBandwidth(pf);
+        if (bw != null) {
+            pbw = new PeerBandwidth(bw.getValue());
+        }
+        return pbw;
+    }
+
+    public static HashSet<Property> toADNodeProperties(final NodeUpdated nu) {
+        final FlowCapableNodeUpdated fcnu = nu.getAugmentation(FlowCapableNodeUpdated.class);
+        if (fcnu != null) {
+            return toADNodeProperties(fcnu, nu.getId());
+        }
+        return new HashSet<org.opendaylight.controller.sal.core.Property>();
+    }
+
+    public static HashSet<Property> toADNodeProperties(final FlowNode fcnu, final NodeId id) {
+
+        final HashSet<org.opendaylight.controller.sal.core.Property> props = new HashSet<>();
+
+        if (fcnu != null) {
+            props.add(toADTimestamp());
+
+            // props.add(fcnu.supportedActions.toADActions) - TODO
+            if (id != null) {
+                props.add(toADMacAddress(id));
             }
-            if (switchFeatures.getMaxBuffers() != null) {
-                props.add(toADBuffers(switchFeatures.getMaxBuffers()));
+            SwitchFeatures switchFeatures = fcnu.getSwitchFeatures();
+            if (switchFeatures != null) {
+                if (switchFeatures.getMaxTables() != null) {
+                    props.add(toADTables(switchFeatures.getMaxTables()));
+                }
+                if (switchFeatures.getCapabilities() != null) {
+                    props.add(toADCapabiliities(switchFeatures.getCapabilities()));
+                }
+                if (switchFeatures.getMaxBuffers() != null) {
+                    props.add(toADBuffers(switchFeatures.getMaxBuffers()));
+                }
             }
         }
+        return props;
     }
-    return props;
-  }
-
-  public static TimeStamp toADTimestamp() {
-    final Date date = new Date();
-    final TimeStamp timestamp = new TimeStamp(date.getTime(), "connectedSince");
-    return timestamp;
-  }
-
-  public static MacAddress toADMacAddress(final NodeId id) {
-    final String nodeId = id.getValue().replaceAll("openflow:", "");
-    BigInteger nodeIdRaw = new BigInteger(nodeId);
-    long lNodeId = nodeIdRaw.longValue();
-    byte[] bytesFromDpid = ToSalConversionsUtils.bytesFromDpid(lNodeId);
-    return new MacAddress(bytesFromDpid);
-  }
-
-  public static Tables toADTables(final Short tables) {
-    return new Tables(tables.byteValue());
-  }
-
-  public static Capabilities toADCapabiliities(final List<Class<? extends FeatureCapability>> capabilities) {
-
-    int b = 0;
-    for (Class<? extends FeatureCapability> capability : capabilities) {
-        if (capability.equals(FlowFeatureCapabilityFlowStats.class)) {
-            b = Capabilities.CapabilitiesType.FLOW_STATS_CAPABILITY.getValue() | b;
-        } else if (capability.equals(FlowFeatureCapabilityTableStats.class)) {
-            b = Capabilities.CapabilitiesType.TABLE_STATS_CAPABILITY.getValue() | b;
-        } else if (capability.equals(FlowFeatureCapabilityPortStats.class)) {
-            b = Capabilities.CapabilitiesType.PORT_STATS_CAPABILITY.getValue() | b;
-        } else if (capability.equals(FlowFeatureCapabilityStp.class)) {
-            b = Capabilities.CapabilitiesType.STP_CAPABILITY.getValue() | b;
-        } else if (capability.equals(FlowFeatureCapabilityIpReasm.class)) {
-            b = Capabilities.CapabilitiesType.IP_REASSEM_CAPABILITY.getValue() | b;
-        } else if (capability.equals(FlowFeatureCapabilityQueueStats.class)) {
-            b = Capabilities.CapabilitiesType.QUEUE_STATS_CAPABILITY.getValue() | b;
-        } else if (capability.equals(FlowFeatureCapabilityArpMatchIp.class)) {
-            b = Capabilities.CapabilitiesType.ARP_MATCH_IP_CAPABILITY.getValue() | b;
+
+    public static TimeStamp toADTimestamp() {
+        final Date date = new Date();
+        final TimeStamp timestamp = new TimeStamp(date.getTime(), "connectedSince");
+        return timestamp;
+    }
+
+    public static MacAddress toADMacAddress(final NodeId id) {
+        final String nodeId = id.getValue().replaceAll("openflow:", "");
+        BigInteger nodeIdRaw = new BigInteger(nodeId);
+        long lNodeId = nodeIdRaw.longValue();
+        byte[] bytesFromDpid = ToSalConversionsUtils.bytesFromDpid(lNodeId);
+        return new MacAddress(bytesFromDpid);
+    }
+
+    public static Tables toADTables(final Short tables) {
+        return new Tables(tables.byteValue());
+    }
+
+    public static Capabilities toADCapabiliities(final List<Class<? extends FeatureCapability>> capabilities) {
+
+        int b = 0;
+        for (Class<? extends FeatureCapability> capability : capabilities) {
+            if (capability.equals(FlowFeatureCapabilityFlowStats.class)) {
+                b = Capabilities.CapabilitiesType.FLOW_STATS_CAPABILITY.getValue() | b;
+            } else if (capability.equals(FlowFeatureCapabilityTableStats.class)) {
+                b = Capabilities.CapabilitiesType.TABLE_STATS_CAPABILITY.getValue() | b;
+            } else if (capability.equals(FlowFeatureCapabilityPortStats.class)) {
+                b = Capabilities.CapabilitiesType.PORT_STATS_CAPABILITY.getValue() | b;
+            } else if (capability.equals(FlowFeatureCapabilityStp.class)) {
+                b = Capabilities.CapabilitiesType.STP_CAPABILITY.getValue() | b;
+            } else if (capability.equals(FlowFeatureCapabilityIpReasm.class)) {
+                b = Capabilities.CapabilitiesType.IP_REASSEM_CAPABILITY.getValue() | b;
+            } else if (capability.equals(FlowFeatureCapabilityQueueStats.class)) {
+                b = Capabilities.CapabilitiesType.QUEUE_STATS_CAPABILITY.getValue() | b;
+            } else if (capability.equals(FlowFeatureCapabilityArpMatchIp.class)) {
+                b = Capabilities.CapabilitiesType.ARP_MATCH_IP_CAPABILITY.getValue() | b;
+            }
         }
+        return new Capabilities(b);
     }
-    return new Capabilities(b);
-  }
 
-  public static Buffers toADBuffers(final Long buffers) {
-    return new Buffers(buffers.intValue());
-  }
+    public static Buffers toADBuffers(final Long buffers) {
+        return new Buffers(buffers.intValue());
+    }
 }
index 74b94c7cba10771fee33f10eeddb6e6a0c2e2b16..da3477ee45329e57d6174c01b9d53de76b098c39 100644 (file)
@@ -168,7 +168,7 @@ public class ToSalConversionsUtils {
     public static List<org.opendaylight.controller.sal.action.Action> actionFrom(List<Action> actions, Node node) {
         List<org.opendaylight.controller.sal.action.Action> targetAction = new ArrayList<>();
         for (Action action : actions) {
-               org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action sourceAction = action
+            org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action sourceAction = action
                     .getAction();
 
             if (sourceAction instanceof ControllerActionCase) {
@@ -585,7 +585,7 @@ public class ToSalConversionsUtils {
         }
         return macAddress;
     }
-    
+
     public static byte[] bytesFromDpid(long dpid) {
         byte[] mac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
 
index b9a2f5bff0154418b102504173c1eed30b5d5673..041924af336c7b1e20647eb64526cbdf961e9329 100644 (file)
@@ -45,7 +45,7 @@ public class NodeMappingTest {
                 {(byte) 0x7f, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff},
                 {(byte) 0x76, (byte) 0x4a, (byte) 0xe9, (byte) 0xac, (byte) 0xe6, (byte) 0x5a}
         };
-        
+
         Assert.assertEquals(expectedMacs.length, nodeIds.length);
 
         for (int i = 0; i < expectedMacs.length; i++) {
index 81ccb35cd982070bc85a7845dfa10d8787f8e450..5d5a409445a4708bf3b04472ded1e3bac89be496 100644 (file)
@@ -249,7 +249,7 @@ public class TestFromSalConversionsUtils {
             boolean b) {
         int numOfFoundActions = 0;
         for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action : actions) {
-               org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action innerAction = action
+            org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action innerAction = action
                     .getAction();
             if (cl.isInstance(innerAction)) {
                 numOfFoundActions++;
index 71f2e9480543feae77bb92275595c29d2119f1c6..4d3509769c5c791e399e6a98357759c6c009d952 100644 (file)
@@ -155,9 +155,9 @@ public class TestToSalConversionsUtils {
     public void testToSalConversion() throws ConstructionException {
         FlowAddedBuilder odNodeFlowBuilder = new FlowAddedBuilder();
         odNodeFlowBuilder = prepareOdFlowCommon();
-        
+
         Node node = new Node(NodeIDType.OPENFLOW,(long)1);
-        
+
         Flow salFlow = ToSalConversionsUtils.toFlow(prepareOdFlow(odNodeFlowBuilder, MtchType.other), node);
         checkSalMatch(salFlow.getMatch(), MtchType.other);
 
@@ -185,7 +185,7 @@ public class TestToSalConversionsUtils {
     private void checkSalMatch(org.opendaylight.controller.sal.match.Match match, MtchType mt) {
         switch (mt) {
         case other:
-            /*assertNotNull("DL_DST isn't equal.", "3C:A9:F4:00:E0:C8", 
+            /*assertNotNull("DL_DST isn't equal.", "3C:A9:F4:00:E0:C8",
                     new String((byte[]) match.getField(MatchType.DL_DST).getValue()));
             assertEquals("DL_SRC isn't equal.", "24:77:03:7C:C5:F1",
                     new String((byte[]) match.getField(MatchType.DL_SRC).getValue()));
@@ -312,7 +312,7 @@ public class TestToSalConversionsUtils {
             //assertEquals("Wrong value for action SetDlSrc for MAC address.", "24:77:03:7C:C5:F1", new String(
             //      ((SetDlSrc) action).getDlAddress()));
         } else if (action instanceof SetDlType) {
-            assertEquals("Wrong value for action SetDlType for.", 513l, ((SetDlType) action).getDlType());
+            assertEquals("Wrong value for action SetDlType for.", 513L, ((SetDlType) action).getDlType());
         } else if (action instanceof SetNextHop) {
             InetAddress inetAddress = ((SetNextHop) action).getAddress();
             checkIpAddresses(inetAddress, "192.168.100.100", "2001:db8:85a3::8a2e:370:7334");
@@ -431,14 +431,14 @@ public class TestToSalConversionsUtils {
         odActions.add(new ActionBuilder().setAction(setVlanPcpActionBuilder.build()).build());
         odActions.add(new ActionBuilder().setAction(swPathActionBuilder.build()).build());
 
-        
+
         ApplyActionsCase innerInst = new ApplyActionsCaseBuilder().setApplyActions(new ApplyActionsBuilder().setAction(odActions).build()).build();
         Instruction applyActions = new InstructionBuilder().setInstruction(innerInst).build();
         List<Instruction> instructions = Collections.singletonList(applyActions );
         InstructionsBuilder instBuilder = new InstructionsBuilder();
-        
+
         instBuilder.setInstruction(instructions);
-        
+
         return instBuilder.build();
     }
 
@@ -492,7 +492,7 @@ public class TestToSalConversionsUtils {
 
     private void prepareActionSetNwDst(List<Action> odActions) {
         // test case for IPv4
-        
+
         SetNwDstActionBuilder setNwDstActionBuilderIpv4 = new SetNwDstActionBuilder();
         setNwDstActionBuilderIpv4.setAddress(prapareIpv4Address("192.168.100.101"));
         odActions.add(new ActionBuilder().setAction(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilderIpv4.build()).build()).build());
@@ -529,7 +529,7 @@ public class TestToSalConversionsUtils {
 
     private void prepareActionSetDlType(SetDlTypeActionCaseBuilder wrapper) {
         SetDlTypeActionBuilder setDlTypeActionBuilder = new SetDlTypeActionBuilder();
-        setDlTypeActionBuilder.setDlType(new EtherType(513l));
+        setDlTypeActionBuilder.setDlType(new EtherType(513L));
         wrapper.setSetDlTypeAction(setDlTypeActionBuilder.build());
     }
 
@@ -674,7 +674,7 @@ public class TestToSalConversionsUtils {
 
     private EthernetType prepEthType() {
         EthernetTypeBuilder ethTypeBuild = new EthernetTypeBuilder();
-        ethTypeBuild.setType(new EtherType(0xffffl));
+        ethTypeBuild.setType(new EtherType(0xffffL));
         return ethTypeBuild.build();
     }
 
index f816018519d61761c3f2c2a81048260bdfee012e..16b457403740b7cac4f3fc137e1a1a9d00db4521 100644 (file)
@@ -3,7 +3,7 @@
 <features name="mdsal-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0">
-    <feature name='mdsal-all' version='${project.version}'>
+    <feature name='odl-mdsal-all' version='${project.version}'>
         <feature version='${project.version}'>odl-mdsal-commons</feature>
         <feature version='${project.version}'>odl-mdsal-broker</feature>
         <feature version='${project.version}'>odl-mdsal-restconf</feature>
@@ -46,4 +46,4 @@
         <bundle>wrap:mvn:io.netty/netty-handler/${netty.version}</bundle>
         <bundle>wrap:mvn:io.netty/netty-transport/${netty.version}</bundle>
     </feature>
-</features>
\ No newline at end of file
+</features>
index 426f4ba2d5ac9dc9625d2a919ef658fdbeb57bd5..c8a7f01e132b519c5f522554faa7e2dd8bfd2ae7 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -19,7 +19,7 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
- * 
+ *
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
  *
  */
@@ -32,17 +32,17 @@ public abstract class AbstractChangeListener implements DataChangeListener {
     public void onDataChanged(DataChangeEvent<InstanceIdentifier<?>, DataObject> changeEvent) {
         this.transactionId = this.newTransactionIdentifier().toString();
 
-        final Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> createdEntries = 
+        final Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> createdEntries =
                 changeEvent.getCreatedConfigurationData().entrySet();
-        final Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> updatedEntries = 
+        final Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> updatedEntries =
                 new HashSet<Entry<InstanceIdentifier<? extends DataObject>, DataObject>>();
 
-        Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> updateConfigEntrySet = 
+        Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> updateConfigEntrySet =
                 changeEvent.getUpdatedConfigurationData().entrySet();
         updatedEntries.addAll(updateConfigEntrySet);
         updatedEntries.removeAll(createdEntries);
 
-        final Set<InstanceIdentifier<? extends DataObject>> removeEntriesInstanceIdentifiers = 
+        final Set<InstanceIdentifier<? extends DataObject>> removeEntriesInstanceIdentifiers =
                 changeEvent.getRemovedConfigurationData();
 
         for (final Entry<InstanceIdentifier<? extends DataObject>, DataObject> createdEntry : createdEntries) {
@@ -52,7 +52,7 @@ public abstract class AbstractChangeListener implements DataChangeListener {
         }
 
         for (final Entry<InstanceIdentifier<?>, DataObject> updatedEntrie : updatedEntries) {
-            Map<InstanceIdentifier<? extends DataObject>, DataObject> origConfigData = 
+            Map<InstanceIdentifier<? extends DataObject>, DataObject> origConfigData =
                     changeEvent.getOriginalConfigurationData();
 
             InstanceIdentifier<? extends Object> u_key = updatedEntrie.getKey();
@@ -62,7 +62,7 @@ public abstract class AbstractChangeListener implements DataChangeListener {
         }
 
         for (final InstanceIdentifier<?> instanceId : removeEntriesInstanceIdentifiers) {
-            Map<InstanceIdentifier<? extends DataObject>, DataObject> origConfigData = 
+            Map<InstanceIdentifier<? extends DataObject>, DataObject> origConfigData =
                     changeEvent.getOriginalConfigurationData();
 
             final DataObject removeValue = origConfigData.get(instanceId);
index 929c489eaf36fa200c88a7bec70834a0fa9f2c1b..2f986ea5bcbbf83c75d81adb9a6724855641fe60 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -24,10 +24,10 @@ public class FRMActivator extends AbstractBindingAwareProvider {
 
     private final static Logger LOG = LoggerFactory.getLogger(FRMActivator.class);
 
-    private static FlowProvider flowProvider = new FlowProvider(); 
+    private static FlowProvider flowProvider = new FlowProvider();
     private static GroupProvider groupProvider = new GroupProvider();
     private static MeterProvider meterProvider = new MeterProvider();
-    
+
     @Override
     public void onSessionInitiated(final ProviderContext session) {
         DataProviderService flowSalService = session.<DataProviderService>getSALService(DataProviderService.class);
@@ -46,7 +46,7 @@ public class FRMActivator extends AbstractBindingAwareProvider {
         FRMActivator.meterProvider.setSalMeterService(rpcMeterSalService);
         FRMActivator.meterProvider.start();
     }
-    
+
     @Override
     protected void stopImpl(final BundleContext context) {
         try {
index df086c7acc9ac92f13bad11cec3f5957d75beebe..b60424513f2fb9f6c930e1648f937008bf9d203e 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -32,7 +32,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * 
+ *
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
  *
  */
@@ -45,7 +45,7 @@ public class FlowChangeListener extends AbstractChangeListener {
     public SalFlowService getSalFlowService() {
         return this.salFlowService;
     }
-    
+
     public FlowChangeListener(final SalFlowService manager) {
         this.salFlowService = manager;
     }
@@ -58,16 +58,16 @@ public class FlowChangeListener extends AbstractChangeListener {
     @Override
     protected void remove(InstanceIdentifier<? extends DataObject> identifier, DataObject removeDataObj) {
         if ((removeDataObj instanceof Flow)) {
-            
+
             final Flow flow = ((Flow) removeDataObj);
             final InstanceIdentifier<Table> tableInstanceId = identifier.<Table> firstIdentifierOf(Table.class);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final RemoveFlowInputBuilder builder = new RemoveFlowInputBuilder(flow);
-            
+
             builder.setFlowRef(new FlowRef(identifier));
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setFlowTable(new FlowTableRef(tableInstanceId));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
             this.salFlowService.removeFlow((RemoveFlowInput) builder.build());
@@ -78,21 +78,21 @@ public class FlowChangeListener extends AbstractChangeListener {
     @Override
     protected void update(InstanceIdentifier<? extends DataObject> identifier, DataObject original, DataObject update) {
         if (original instanceof Flow && update instanceof Flow) {
-            
+
             final Flow originalFlow = ((Flow) original);
             final Flow updatedFlow = ((Flow) update);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node>firstIdentifierOf(Node.class);
             final UpdateFlowInputBuilder builder = new UpdateFlowInputBuilder();
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setFlowRef(new FlowRef(identifier));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
-            
+
             builder.setUpdatedFlow((UpdatedFlow) (new UpdatedFlowBuilder(updatedFlow)).build());
             builder.setOriginalFlow((OriginalFlow) (new OriginalFlowBuilder(originalFlow)).build());
-            
+
             this.salFlowService.updateFlow((UpdateFlowInput) builder.build());
             LOG.debug("Transaction {} - Update Flow has updated flow {} with {}", new Object[]{uri, original, update});
       }
@@ -101,16 +101,16 @@ public class FlowChangeListener extends AbstractChangeListener {
     @Override
     protected void add(InstanceIdentifier<? extends DataObject> identifier, DataObject addDataObj) {
         if ((addDataObj instanceof Flow)) {
-            
+
             final Flow flow = ((Flow) addDataObj);
             final InstanceIdentifier<Table> tableInstanceId = identifier.<Table> firstIdentifierOf(Table.class);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final AddFlowInputBuilder builder = new AddFlowInputBuilder(flow);
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setFlowRef(new FlowRef(identifier));
             builder.setFlowTable(new FlowTableRef(tableInstanceId));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
             this.salFlowService.addFlow((AddFlowInput) builder.build());
index afdd628bbb7d39ff8d61d1a6ef079e3677921fa9..33db529598dc9115c4dfcb52906f585bcb00313e 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -42,7 +42,7 @@ public class FlowProvider implements AutoCloseable {
         InstanceIdentifierBuilder<Table> tableChild = augmentFlowCapNode.<Table> child(Table.class);
         InstanceIdentifierBuilder<Flow> flowChild = tableChild.<Flow> child(Flow.class);
         final InstanceIdentifier<? extends DataObject> flowDataObjectPath = flowChild.toInstance();
-        
+
         /* DataChangeListener registration */
         this.flowDataChangeListener = new FlowChangeListener(this.salFlowService);
         this.flowDataChangeListenerRegistration = this.dataService.registerDataChangeListener(flowDataObjectPath, flowDataChangeListener);
index 4ef93a55e9d515ebcc8e15312ae72108658d379b..9cd42466a6d91e987d69b8d512d08bafcb95511e 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
index 1260f0ec530ebd3daecfbfa43fbe9fb4b3efc791..54f12bfdcf64346191ab589969e579b0dfdf5db7 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -30,7 +30,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * 
+ *
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
  *
  */
@@ -43,7 +43,7 @@ public class GroupChangeListener extends AbstractChangeListener {
     public SalGroupService getSalGroupService() {
         return this.salGroupService;
     }
-    
+
     public GroupChangeListener(final SalGroupService manager) {
         this.salGroupService = manager;
     }
@@ -56,14 +56,14 @@ public class GroupChangeListener extends AbstractChangeListener {
     @Override
     protected void remove(InstanceIdentifier<? extends DataObject> identifier, DataObject removeDataObj) {
         if ((removeDataObj instanceof Group)) {
-            
+
             final Group group = ((Group) removeDataObj);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final RemoveGroupInputBuilder builder = new RemoveGroupInputBuilder(group);
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setGroupRef(new GroupRef(identifier));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
             this.salGroupService.removeGroup((RemoveGroupInput) builder.build());
@@ -74,21 +74,21 @@ public class GroupChangeListener extends AbstractChangeListener {
     @Override
     protected void update(InstanceIdentifier<? extends DataObject> identifier, DataObject original, DataObject update) {
         if (original instanceof Group && update instanceof Group) {
-            
+
             final Group originalGroup = ((Group) original);
             final Group updatedGroup = ((Group) update);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final UpdateGroupInputBuilder builder = new UpdateGroupInputBuilder();
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setGroupRef(new GroupRef(identifier));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
-            
+
             builder.setUpdatedGroup((UpdatedGroup) (new UpdatedGroupBuilder(updatedGroup)).build());
             builder.setOriginalGroup((OriginalGroup) (new OriginalGroupBuilder(originalGroup)).build());
-            
+
             this.salGroupService.updateGroup((UpdateGroupInput) builder.build());
             LOG.debug("Transaction {} - Update Group has updated group {} with group {}", new Object[]{uri, original, update});
         }
@@ -100,10 +100,10 @@ public class GroupChangeListener extends AbstractChangeListener {
             final Group group = ((Group) addDataObj);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final AddGroupInputBuilder builder = new AddGroupInputBuilder(group);
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setGroupRef(new GroupRef(identifier));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
             this.salGroupService.addGroup((AddGroupInput) builder.build());
index 14b1b6f2fd85eed770b177ffa6c79a600c995ea5..9f2806e929a25344726fa125ec1ec7b918b8197e 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -46,11 +46,11 @@ public class GroupProvider implements AutoCloseable {
         this.groupDataChangeListenerRegistration = this.dataService.registerDataChangeListener(groupDataObjectPath, groupDataChangeListener);
         LOG.info("Group Config Provider started.");
     }
-    
+
     protected DataModificationTransaction startChange() {
         return this.dataService.beginTransaction();
     }
-    
+
     public void close() throws Exception {
         if(groupDataChangeListenerRegistration != null){
             groupDataChangeListenerRegistration.close();
index 839e556fbc65d6207a0b41d651fcd7abc600190e..48d5257978cc28ff5c86a44449b55a45f15024cc 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -30,7 +30,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * 
+ *
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
  *
  */
@@ -43,7 +43,7 @@ public class MeterChangeListener extends AbstractChangeListener {
     public SalMeterService getSalMeterService() {
         return this.salMeterService;
     }
-    
+
     public MeterChangeListener(final SalMeterService manager) {
         this.salMeterService = manager;
     }
@@ -56,14 +56,14 @@ public class MeterChangeListener extends AbstractChangeListener {
     @Override
     protected void remove(InstanceIdentifier<? extends DataObject> identifier, DataObject removeDataObj) {
         if ((removeDataObj instanceof Meter)) {
-            
+
             final Meter meter = ((Meter) removeDataObj);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final RemoveMeterInputBuilder builder = new RemoveMeterInputBuilder(meter);
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setMeterRef(new MeterRef(identifier));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
             this.salMeterService.removeMeter((RemoveMeterInput) builder.build());
@@ -74,21 +74,21 @@ public class MeterChangeListener extends AbstractChangeListener {
     @Override
     protected void update(InstanceIdentifier<? extends DataObject> identifier, DataObject original, DataObject update) {
         if (original instanceof Meter && update instanceof Meter) {
-            
+
             final Meter originalMeter = ((Meter) original);
             final Meter updatedMeter = ((Meter) update);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final UpdateMeterInputBuilder builder = new UpdateMeterInputBuilder();
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setMeterRef(new MeterRef(identifier));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
-            
+
             builder.setUpdatedMeter((UpdatedMeter) (new UpdatedMeterBuilder(updatedMeter)).build());
             builder.setOriginalMeter((OriginalMeter) (new OriginalMeterBuilder(originalMeter)).build());
-            
+
             this.salMeterService.updateMeter((UpdateMeterInput) builder.build());
             LOG.debug("Transaction {} - Update Meter has updated meter {} with {}", new Object[]{uri, original, update});
         }
@@ -97,14 +97,14 @@ public class MeterChangeListener extends AbstractChangeListener {
     @Override
     protected void add(InstanceIdentifier<? extends DataObject> identifier, DataObject addDataObj) {
         if ((addDataObj instanceof Meter)) {
-            
+
             final Meter meter = ((Meter) addDataObj);
             final InstanceIdentifier<Node> nodeInstanceId = identifier.<Node> firstIdentifierOf(Node.class);
             final AddMeterInputBuilder builder = new AddMeterInputBuilder(meter);
-            
+
             builder.setNode(new NodeRef(nodeInstanceId));
             builder.setMeterRef(new MeterRef(identifier));
-            
+
             Uri uri = new Uri(this.getTransactionId());
             builder.setTransactionUri(uri);
             this.salMeterService.addMeter((AddMeterInput) builder.build());
index 620801fba502c1850460b9f39b7f431752e2f925..8596c3fec6e7f8f04dc2fcc4917240d35b85f8eb 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -46,7 +46,7 @@ public class MeterProvider implements AutoCloseable {
         this.meterDataChangeListenerRegistration = this.dataService.registerDataChangeListener(meterDataObjectPath, meterDataChangeListener);
         LOG.info("Meter Config Provider started.");
     }
-    
+
     protected DataModificationTransaction startChange() {
         return this.dataService.beginTransaction();
     }
index 2a3d8fd37e26c1cafc012c68102f417063c51713..674ae398d3194d06e8a097d28be01a5b8d7a1ec3 100644 (file)
@@ -126,7 +126,7 @@ public class NodeChangeCommiter implements OpendaylightInventoryListener {
         Future<RpcResult<TransactionStatus>> commitResult = it.commit();
         listenOnTransactionState(it.getIdentifier(), commitResult, "node update", ref.getValue());
     }
-    
+
     /**
      * @param txId transaction identificator
      * @param future transaction result
@@ -136,13 +136,13 @@ public class NodeChangeCommiter implements OpendaylightInventoryListener {
     private static void listenOnTransactionState(final Object txId, Future<RpcResult<TransactionStatus>> future,
             final String action, final InstanceIdentifier<?> nodeConnectorPath) {
         Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future),new FutureCallback<RpcResult<TransactionStatus>>() {
-            
+
             @Override
             public void onFailure(Throwable t) {
                 LOG.error("Action {} [{}] failed for Tx:{}", action, nodeConnectorPath, txId, t);
-                
+
             }
-            
+
             @Override
             public void onSuccess(RpcResult<TransactionStatus> result) {
                 if(!result.isSuccessful()) {
index 94bd0731aaa64b8bed970a2bee7a8fe4aec5f0ce..9222734360a0b1cb81b58caafe36381728056048 100644 (file)
       </plugin>
       <plugin>
         <!-- FIXME: BUG-272: remove this configuration override -->
+        <!-- replaced with new configuration -->
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-checkstyle-plugin</artifactId>
-        <version>${checkstyle.version}</version>
+        <version>2.12</version>
+        <configuration>
+          <failsOnError>false</failsOnError>
+          <failOnViolation>false</failOnViolation>
+          <configLocation>checkstyle-logging.xml</configLocation>
+          <consoleOutput>true</consoleOutput>
+          <includeTestSourceDirectory>true</includeTestSourceDirectory>
+          <sourceDirectory>${project.basedir}</sourceDirectory>
+          <includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat,**\/*.yang</includes>
+          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/${jmxGeneratorPath}\/,**\/${salGeneratorPath}\/</excludes>
+        </configuration>
+        <dependencies>
+          <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>checkstyle-logging</artifactId>
+            <version>${yangtools.version}</version>
+          </dependency>
+        </dependencies>
         <executions>
           <execution>
-            <phase>none</phase>
+            <goals>
+              <goal>check</goal>
+            </goals>
           </execution>
         </executions>
       </plugin>
index d6b42faccf60f8351f849cdd350f02819bec0674..e242b0a3938a3e25237f551a322633248ff2aed7 100644 (file)
 
 package org.opendaylight.controller.sal.connector.remoterpc.impl;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+
 import org.apache.felix.dm.Component;
-import org.opendaylight.controller.clustering.services.*;
+import org.opendaylight.controller.clustering.services.CacheConfigException;
+import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.CacheListenerAddException;
+import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
+import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
+import org.opendaylight.controller.clustering.services.IClusterServices;
 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.NotSupportedException;
-import javax.transaction.RollbackException;
-import java.util.*;
-import java.util.concurrent.ConcurrentMap;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
 
 public class RoutingTableImpl<I, R> implements RoutingTable<I, R>, ICacheUpdateAware<I, R> {
 
-  private Logger log = LoggerFactory.getLogger(RoutingTableImpl.class);
+    private final Logger log = LoggerFactory.getLogger(RoutingTableImpl.class);
 
-  private IClusterGlobalServices clusterGlobalServices = null;
+    private IClusterGlobalServices clusterGlobalServices = null;
 
-  private ConcurrentMap<I,R> globalRpcCache = null;
-  private ConcurrentMap<I, LinkedHashSet<R>> rpcCache = null;  //need routes to ordered by insert-order
+    private ConcurrentMap<I,R> globalRpcCache = null;
+    private ConcurrentMap<I, LinkedHashSet<R>> rpcCache = null;  //need routes to ordered by insert-order
 
-  public static final String GLOBALRPC_CACHE = "remoterpc_routingtable.globalrpc_cache";
-  public static final String RPC_CACHE = "remoterpc_routingtable.rpc_cache";
+    public static final String GLOBALRPC_CACHE = "remoterpc_routingtable.globalrpc_cache";
+    public static final String RPC_CACHE = "remoterpc_routingtable.rpc_cache";
 
-  public RoutingTableImpl() {
-  }
-
-  @Override
-  public R getGlobalRoute(I routeId) throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeId, "getGlobalRoute: routeId cannot be null!");
-    return globalRpcCache.get(routeId);
-  }
-
-  @Override
-  public void addGlobalRoute(I routeId, R route) throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeId, "addGlobalRoute: routeId cannot be null!");
-    Preconditions.checkNotNull(route, "addGlobalRoute: route cannot be null!");
-    try {
-
-      log.debug("addGlobalRoute: adding  a new route with id[{}] and value [{}]", routeId, route);
-      clusterGlobalServices.tbegin();
-      if (globalRpcCache.putIfAbsent(routeId, route) != null) {
-        throw new DuplicateRouteException(" There is already existing route " + routeId);
-      }
-      clusterGlobalServices.tcommit();
-
-    } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
-      throw new RoutingTableException("Transaction error - while trying to create route id="
-          + routeId + "with route" + route, e);
-    } catch (javax.transaction.SystemException e) {
-      throw new SystemException("System error occurred - while trying to create with value", e);
+    public RoutingTableImpl() {
     }
 
-  }
+    @Override
+    public R getGlobalRoute(final I routeId) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeId, "getGlobalRoute: routeId cannot be null!");
+        return globalRpcCache.get(routeId);
+    }
 
-  @Override
-  public void removeGlobalRoute(I routeId) throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeId, "removeGlobalRoute: routeId cannot be null!");
-    try {
-      log.debug("removeGlobalRoute: removing  a new route with id [{}]", routeId);
+    @Override
+    public void addGlobalRoute(final I routeId, final R route) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeId, "addGlobalRoute: routeId cannot be null!");
+        Preconditions.checkNotNull(route, "addGlobalRoute: route cannot be null!");
+        try {
+
+            log.debug("addGlobalRoute: adding  a new route with id[{}] and value [{}]", routeId, route);
+            clusterGlobalServices.tbegin();
+            if (globalRpcCache.putIfAbsent(routeId, route) != null) {
+                throw new DuplicateRouteException(" There is already existing route " + routeId);
+            }
+            clusterGlobalServices.tcommit();
+
+        } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
+            throw new RoutingTableException("Transaction error - while trying to create route id="
+                    + routeId + "with route" + route, e);
+        } catch (javax.transaction.SystemException e) {
+            throw new SystemException("System error occurred - while trying to create with value", e);
+        }
 
-      clusterGlobalServices.tbegin();
-      globalRpcCache.remove(routeId);
-      clusterGlobalServices.tcommit();
+    }
 
-    } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
-      throw new RoutingTableException("Transaction error - while trying to remove route id="
-          + routeId, e);
-    } catch (javax.transaction.SystemException e) {
-      throw new SystemException("System error occurred - while trying to remove with value", e);
+    @Override
+    public void removeGlobalRoute(final I routeId) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeId, "removeGlobalRoute: routeId cannot be null!");
+        try {
+            log.debug("removeGlobalRoute: removing  a new route with id [{}]", routeId);
+
+            clusterGlobalServices.tbegin();
+            globalRpcCache.remove(routeId);
+            clusterGlobalServices.tcommit();
+
+        } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
+            throw new RoutingTableException("Transaction error - while trying to remove route id="
+                    + routeId, e);
+        } catch (javax.transaction.SystemException e) {
+            throw new SystemException("System error occurred - while trying to remove with value", e);
+        }
     }
-  }
 
 
-  @Override
-  public Set<R> getRoutes(I routeId) {
-    Preconditions.checkNotNull(routeId, "getRoutes: routeId cannot be null!");
-    Set<R> routes = rpcCache.get(routeId);
+    @Override
+    public Set<R> getRoutes(final I routeId) {
+        Preconditions.checkNotNull(routeId, "getRoutes: routeId cannot be null!");
+        Set<R> routes = rpcCache.get(routeId);
 
-    if (routes == null) return Collections.emptySet();
+        if (routes == null) {
+            return Collections.emptySet();
+        }
 
-    return ImmutableSet.copyOf(routes);
-  }
+        return ImmutableSet.copyOf(routes);
+    }
 
 
 
-  public R getLastAddedRoute(I routeId) {
+    @Override
+    public R getLastAddedRoute(final I routeId) {
 
-    Set<R> routes = getRoutes(routeId);
+        Set<R> routes = getRoutes(routeId);
 
-    if (routes.isEmpty()) return null;
+        if (routes.isEmpty()) {
+            return null;
+        }
 
-    R route = null;
-    Iterator<R> iter = routes.iterator();
-    while (iter.hasNext())
-      route = iter.next();
+        R route = null;
+        Iterator<R> iter = routes.iterator();
+        while (iter.hasNext()) {
+            route = iter.next();
+        }
 
-    return route;
-  }
+        return route;
+    }
 
-  @Override
-  public void addRoute(I routeId, R route)  throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeId, "addRoute: routeId cannot be null");
-    Preconditions.checkNotNull(route, "addRoute: route cannot be null");
+    @Override
+    public void addRoute(final I routeId, final R route)  throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeId, "addRoute: routeId cannot be null");
+        Preconditions.checkNotNull(route, "addRoute: route cannot be null");
+
+        try{
+            clusterGlobalServices.tbegin();
+            log.debug("addRoute: adding a route with k/v [{}/{}]", routeId, route);
+            threadSafeAdd(routeId, route);
+            clusterGlobalServices.tcommit();
+
+        } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
+            throw new RoutingTableException("Transaction error - while trying to remove route id="
+                    + routeId, e);
+        } catch (javax.transaction.SystemException e) {
+            throw new SystemException("System error occurred - while trying to remove with value", e);
+        }
+    }
 
-    try{
-      clusterGlobalServices.tbegin();
-      log.debug("addRoute: adding a route with k/v [{}/{}]", routeId, route);
-      threadSafeAdd(routeId, route);
-      clusterGlobalServices.tcommit();
+    @Override
+    public void addRoutes(final Set<I> routeIds, final R route) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeIds, "addRoutes: routeIds must not be null");
+        for (I routeId : routeIds){
+            addRoute(routeId, route);
+        }
+    }
 
-    } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
-      throw new RoutingTableException("Transaction error - while trying to remove route id="
-          + routeId, e);
-    } catch (javax.transaction.SystemException e) {
-      throw new SystemException("System error occurred - while trying to remove with value", e);
+    @Override
+    public void removeRoute(final I routeId, final R route) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeId, "removeRoute: routeId cannot be null!");
+        Preconditions.checkNotNull(route, "removeRoute: route cannot be null!");
+
+        LinkedHashSet<R> routes = rpcCache.get(routeId);
+        if (routes == null) {
+            return;
+        }
+
+        try {
+            log.debug("removeRoute: removing  a new route with k/v [{}/{}]", routeId, route);
+
+            clusterGlobalServices.tbegin();
+            threadSafeRemove(routeId, route);
+            clusterGlobalServices.tcommit();
+
+        } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
+            throw new RoutingTableException("Transaction error - while trying to remove route id="
+                    + routeId, e);
+        } catch (javax.transaction.SystemException e) {
+            throw new SystemException("System error occurred - while trying to remove with value", e);
+        }
     }
-  }
 
-  @Override
-  public void addRoutes(Set<I> routeIds, R route) throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeIds, "addRoutes: routeIds must not be null");
-    for (I routeId : routeIds){
-      addRoute(routeId, route);
+    @Override
+    public void removeRoutes(final Set<I> routeIds, final R route) throws RoutingTableException, SystemException {
+        Preconditions.checkNotNull(routeIds, "removeRoutes: routeIds must not be null");
+        for (I routeId : routeIds){
+            removeRoute(routeId, route);
+        }
     }
-  }
 
-  @Override
-  public void removeRoute(I routeId, R route) throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeId, "removeRoute: routeId cannot be null!");
-    Preconditions.checkNotNull(route, "removeRoute: route cannot be null!");
+    /**
+     * This method guarantees that no 2 thread over write each other's changes.
+     * Just so that we dont end up in infinite loop, it tries for 100 times then throw
+     */
+    private void threadSafeAdd(final I routeId, final R route) {
+
+        for (int i=0;i<100;i++){
+
+            LinkedHashSet<R> updatedRoutes = new LinkedHashSet<>();
+            updatedRoutes.add(route);
+            LinkedHashSet<R> oldRoutes = rpcCache.putIfAbsent(routeId, updatedRoutes);
+            if (oldRoutes == null) {
+                return;
+            }
+
+            updatedRoutes = new LinkedHashSet<>(oldRoutes);
+            updatedRoutes.add(route);
+
+            if (rpcCache.replace(routeId, oldRoutes, updatedRoutes)) {
+                return;
+            }
+        }
+        //the method did not already return means it failed to add route in 10 attempts
+        throw new IllegalStateException("Failed to add route [" + routeId + "]");
+    }
 
-    LinkedHashSet<R> routes = rpcCache.get(routeId);
-    if (routes == null) return;
+    /**
+     * This method guarantees that no 2 thread over write each other's changes.
+     * Just so that we dont end up in infinite loop, it tries for 10 times then throw
+     */
+    private void threadSafeRemove(final I routeId, final R route) {
+        LinkedHashSet<R> updatedRoutes = null;
+        for (int i=0;i<10;i++){
+            LinkedHashSet<R> oldRoutes = rpcCache.get(routeId);
+
+            // if route to be deleted is the only entry in the set then remove routeId from the cache
+            if ((oldRoutes.size() == 1) && oldRoutes.contains(route)){
+                rpcCache.remove(routeId);
+                return;
+            }
+
+            // if there are multiple routes for this routeId, remove the route to be deleted only from the set.
+            updatedRoutes = new LinkedHashSet<>(oldRoutes);
+            updatedRoutes.remove(route);
+            if (rpcCache.replace(routeId, oldRoutes, updatedRoutes)) {
+                return;
+            }
+
+        }
+        //the method did not already return means it failed to remove route in 10 attempts
+        throw new IllegalStateException("Failed to remove route [" + routeId + "]");
+    }
 
-    try {
-      log.debug("removeRoute: removing  a new route with k/v [{}/{}]", routeId, route);
 
-      clusterGlobalServices.tbegin();
-      threadSafeRemove(routeId, route);
-      clusterGlobalServices.tcommit();
+    //    /**
+    //     * @deprecated doesn't do anything will be removed once listeners used
+    //     *             whiteboard pattern Registers listener for sending any change
+    //     *             notification
+    //     * @param listener
+    //     */
+    //    @Override
+    //    public void registerRouteChangeListener(RouteChangeListener listener) {
+    //
+    //    }
+
+    //    public void setRouteChangeListener(RouteChangeListener rcl) {
+    //        if(rcl != null){
+    //            routeChangeListeners.add(rcl);
+    //        }else{
+    //            log.warn("setRouteChangeListener called with null listener");
+    //        }
+    //    }
+    //
+    //    public void unSetRouteChangeListener(RouteChangeListener rcl) {
+    //        if(rcl != null){
+    //         routeChangeListeners.remove(rcl);
+    //        }else{
+    //            log.warn("unSetRouteChangeListener called with null listener");
+    //        }
+    //    }
+
+    /**
+     * Returning the set of route change listeners for Unit testing Note: the
+     * package scope is default
+     *
+     * @return List of registered RouteChangeListener<I,R> listeners
+     */
+    //    Set<RouteChangeListener> getRegisteredRouteChangeListeners() {
+    //        return routeChangeListeners;
+    //    }
+    public void setClusterGlobalServices(final IClusterGlobalServices clusterGlobalServices) {
+        this.clusterGlobalServices = clusterGlobalServices;
+    }
 
-    } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) {
-      throw new RoutingTableException("Transaction error - while trying to remove route id="
-          + routeId, e);
-    } catch (javax.transaction.SystemException e) {
-      throw new SystemException("System error occurred - while trying to remove with value", e);
+    public void unsetClusterGlobalServices(final IClusterGlobalServices clusterGlobalServices) {
+        if ((clusterGlobalServices != null) && (this.clusterGlobalServices.equals(clusterGlobalServices))) {
+            this.clusterGlobalServices = null;
+        }
     }
-  }
 
-  @Override
-  public void removeRoutes(Set<I> routeIds, R route) throws RoutingTableException, SystemException {
-    Preconditions.checkNotNull(routeIds, "removeRoutes: routeIds must not be null");
-    for (I routeId : routeIds){
-      removeRoute(routeId, route);
+    /**
+     * Finds OR Creates clustered cache for Global RPCs
+     *
+     * @throws CacheExistException       -- cluster global services exception when cache exist
+     * @throws CacheConfigException      -- cluster global services exception during cache config
+     * @throws CacheListenerAddException -- cluster global services exception during adding of listener
+     */
+
+    @SuppressWarnings("unchecked")
+    void findOrCreateGlobalRpcCache() throws CacheExistException, CacheConfigException,
+    CacheListenerAddException {
+        // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it
+        // should be caching?
+
+        // let us check here if the cache already exists -- if so don't create
+        if (!clusterGlobalServices.existCache(GLOBALRPC_CACHE)) {
+
+            globalRpcCache = (ConcurrentMap<I,R>) clusterGlobalServices.createCache(GLOBALRPC_CACHE,
+                    EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
+            log.debug("Cache created [{}] ", GLOBALRPC_CACHE);
+
+        } else {
+            globalRpcCache = (ConcurrentMap<I,R>) clusterGlobalServices.getCache(GLOBALRPC_CACHE);
+            log.debug("Cache exists [{}] ", GLOBALRPC_CACHE);
+        }
     }
-  }
 
-  /**
-   * This method guarantees that no 2 thread over write each other's changes.
-   * Just so that we dont end up in infinite loop, it tries for 100 times then throw
-   */
-  private void threadSafeAdd(I routeId, R route) {
+    /**
+     * Finds OR Creates clustered cache for Routed RPCs
+     *
+     * @throws CacheExistException       -- cluster global services exception when cache exist
+     * @throws CacheConfigException      -- cluster global services exception during cache config
+     * @throws CacheListenerAddException -- cluster global services exception during adding of listener
+     */
+
+    @SuppressWarnings("unchecked")
+    void findOrCreateRpcCache() throws CacheExistException, CacheConfigException,
+    CacheListenerAddException {
+        // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it
+        // should be caching?
+
+        if (clusterGlobalServices.existCache(RPC_CACHE)){
+            rpcCache = (ConcurrentMap<I,LinkedHashSet<R>>) clusterGlobalServices.getCache(RPC_CACHE);
+            log.debug("Cache exists [{}] ", RPC_CACHE);
+            return;
+        }
+
+        //cache doesnt exist, create one
+        rpcCache = (ConcurrentMap<I,LinkedHashSet<R>>) clusterGlobalServices.createCache(RPC_CACHE,
+                EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
+        log.debug("Cache created [{}] ", RPC_CACHE);
+    }
 
-    for (int i=0;i<100;i++){
 
-      LinkedHashSet<R> updatedRoutes = new LinkedHashSet<>();
-      updatedRoutes.add(route);
-      LinkedHashSet<R> oldRoutes = rpcCache.putIfAbsent(routeId, updatedRoutes);
-      if (oldRoutes == null) return;
+    /**
+     * Function called by the dependency manager when all the required
+     * dependencies are satisfied
+     */
+    void init(final Component c) {
+        try {
 
-      updatedRoutes = new LinkedHashSet<>(oldRoutes);
-      updatedRoutes.add(route);
+            findOrCreateGlobalRpcCache();
+            findOrCreateRpcCache();
 
-      if (rpcCache.replace(routeId, oldRoutes, updatedRoutes)) return;
+        } catch (CacheExistException|CacheConfigException|CacheListenerAddException e) {
+            throw new IllegalStateException("could not construct routing table cache");
+        }
     }
-    //the method did not already return means it failed to add route in 10 attempts
-    throw new IllegalStateException("Failed to add route [" + routeId + "]");
-  }
-
-  /**
-   * This method guarantees that no 2 thread over write each other's changes.
-   * Just so that we dont end up in infinite loop, it tries for 10 times then throw
-   */
-  private void threadSafeRemove(I routeId, R route) {
-    LinkedHashSet<R> updatedRoutes = null;
-    for (int i=0;i<10;i++){
-      LinkedHashSet<R> oldRoutes = rpcCache.get(routeId);
-
-      // if route to be deleted is the only entry in the set then remove routeId from the cache
-      if ((oldRoutes.size() == 1) && oldRoutes.contains(route)){
-        rpcCache.remove(routeId);
-        return;
-      }
-
-      // if there are multiple routes for this routeId, remove the route to be deleted only from the set.
-      updatedRoutes = new LinkedHashSet<>(oldRoutes);
-      updatedRoutes.remove(route);
-      if (rpcCache.replace(routeId, oldRoutes, updatedRoutes)) return;
 
+    /**
+     * Useful for unit testing <note>It has package
+     * scope</note>
+     */
+    ConcurrentMap<I, R> getGlobalRpcCache() {
+        return this.globalRpcCache;
     }
-    //the method did not already return means it failed to remove route in 10 attempts
-    throw new IllegalStateException("Failed to remove route [" + routeId + "]");
-  }
-
-
-//    /**
-//     * @deprecated doesn't do anything will be removed once listeners used
-//     *             whiteboard pattern Registers listener for sending any change
-//     *             notification
-//     * @param listener
-//     */
-//    @Override
-//    public void registerRouteChangeListener(RouteChangeListener listener) {
-//
-//    }
-
-//    public void setRouteChangeListener(RouteChangeListener rcl) {
-//        if(rcl != null){
-//            routeChangeListeners.add(rcl);
-//        }else{
-//            log.warn("setRouteChangeListener called with null listener");
-//        }
-//    }
-//
-//    public void unSetRouteChangeListener(RouteChangeListener rcl) {
-//        if(rcl != null){
-//         routeChangeListeners.remove(rcl);
-//        }else{
-//            log.warn("unSetRouteChangeListener called with null listener");
-//        }
-//    }
-
-  /**
-   * Returning the set of route change listeners for Unit testing Note: the
-   * package scope is default
-   *
-   * @return List of registered RouteChangeListener<I,R> listeners
-   */
-//    Set<RouteChangeListener> getRegisteredRouteChangeListeners() {
-//        return routeChangeListeners;
-//    }
-  public void setClusterGlobalServices(IClusterGlobalServices clusterGlobalServices) {
-    this.clusterGlobalServices = clusterGlobalServices;
-  }
-
-  public void unsetClusterGlobalServices(IClusterGlobalServices clusterGlobalServices) {
-    if ((clusterGlobalServices != null) && (this.clusterGlobalServices.equals(clusterGlobalServices))) {
-      this.clusterGlobalServices = null;
-    }
-  }
-
-  /**
-   * Finds OR Creates clustered cache for Global RPCs
-   *
-   * @throws CacheExistException       -- cluster global services exception when cache exist
-   * @throws CacheConfigException      -- cluster global services exception during cache config
-   * @throws CacheListenerAddException -- cluster global services exception during adding of listener
-   */
-
-  void findOrCreateGlobalRpcCache() throws CacheExistException, CacheConfigException,
-      CacheListenerAddException {
-    // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it
-    // should be caching?
-
-    // let us check here if the cache already exists -- if so don't create
-    if (!clusterGlobalServices.existCache(GLOBALRPC_CACHE)) {
-
-      globalRpcCache = (ConcurrentMap<I,R>) clusterGlobalServices.createCache(GLOBALRPC_CACHE,
-          EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-      log.debug("Cache created [{}] ", GLOBALRPC_CACHE);
-
-    } else {
-      globalRpcCache = (ConcurrentMap<I,R>) clusterGlobalServices.getCache(GLOBALRPC_CACHE);
-      log.debug("Cache exists [{}] ", GLOBALRPC_CACHE);
-    }
-  }
-
-  /**
-   * Finds OR Creates clustered cache for Routed RPCs
-   *
-   * @throws CacheExistException       -- cluster global services exception when cache exist
-   * @throws CacheConfigException      -- cluster global services exception during cache config
-   * @throws CacheListenerAddException -- cluster global services exception during adding of listener
-   */
-
-  void findOrCreateRpcCache() throws CacheExistException, CacheConfigException,
-      CacheListenerAddException {
-    // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it
-    // should be caching?
-
-    if (clusterGlobalServices.existCache(RPC_CACHE)){
-      rpcCache = (ConcurrentMap<I,LinkedHashSet<R>>) clusterGlobalServices.getCache(RPC_CACHE);
-      log.debug("Cache exists [{}] ", RPC_CACHE);
-      return;
-    }
-
-    //cache doesnt exist, create one
-    rpcCache = (ConcurrentMap<I,LinkedHashSet<R>>) clusterGlobalServices.createCache(RPC_CACHE,
-          EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
-    log.debug("Cache created [{}] ", RPC_CACHE);
-  }
-
-
-  /**
-   * Function called by the dependency manager when all the required
-   * dependencies are satisfied
-   */
-  void init(Component c) {
-    try {
 
-      findOrCreateGlobalRpcCache();
-      findOrCreateRpcCache();
-
-    } catch (CacheExistException|CacheConfigException|CacheListenerAddException e) {
-      throw new IllegalStateException("could not construct routing table cache");
+    /**
+     * Useful for unit testing <note>It has package
+     * scope</note>
+     */
+    ConcurrentMap<I, LinkedHashSet<R>> getRpcCache() {
+        return this.rpcCache;
     }
-  }
-
-  /**
-   * Useful for unit testing <note>It has package
-   * scope</note>
-   */
-  ConcurrentMap getGlobalRpcCache() {
-    return this.globalRpcCache;
-  }
-
-  /**
-   * Useful for unit testing <note>It has package
-   * scope</note>
-   */
-  ConcurrentMap getRpcCache() {
-    return this.rpcCache;
-  }
-
-  /**
-   * This is used from integration test NP rest API to check out the result of the
-   * cache population
-   * <Note> For testing purpose only-- use it wisely</Note>
-   *
-   * @return
-   */
-  public String dumpGlobalRpcCache() {
-    Set<Map.Entry<I, R>> cacheEntrySet = this.globalRpcCache.entrySet();
-    StringBuilder sb = new StringBuilder();
-    for (Map.Entry<I, R> entry : cacheEntrySet) {
-      sb.append("Key:").append(entry.getKey()).append("---->Value:")
-          .append((entry.getValue() != null) ? entry.getValue() : "null")
-          .append("\n");
+
+    /**
+     * This is used from integration test NP rest API to check out the result of the
+     * cache population
+     * <Note> For testing purpose only-- use it wisely</Note>
+     *
+     * @return
+     */
+    public String dumpGlobalRpcCache() {
+        Set<Map.Entry<I, R>> cacheEntrySet = this.globalRpcCache.entrySet();
+        StringBuilder sb = new StringBuilder();
+        for (Map.Entry<I, R> entry : cacheEntrySet) {
+            sb.append("Key:").append(entry.getKey()).append("---->Value:")
+            .append((entry.getValue() != null) ? entry.getValue() : "null")
+            .append("\n");
+        }
+        return sb.toString();
     }
-    return sb.toString();
-  }
-
-  public String dumpRpcCache() {
-    Set<Map.Entry<I, LinkedHashSet<R>>> cacheEntrySet = this.rpcCache.entrySet();
-    StringBuilder sb = new StringBuilder();
-    for (Map.Entry<I, LinkedHashSet<R>> entry : cacheEntrySet) {
-      sb.append("Key:").append(entry.getKey()).append("---->Value:")
-          .append((entry.getValue() != null) ? entry.getValue() : "null")
-          .append("\n");
+
+    public String dumpRpcCache() {
+        Set<Map.Entry<I, LinkedHashSet<R>>> cacheEntrySet = this.rpcCache.entrySet();
+        StringBuilder sb = new StringBuilder();
+        for (Map.Entry<I, LinkedHashSet<R>> entry : cacheEntrySet) {
+            sb.append("Key:").append(entry.getKey()).append("---->Value:")
+            .append((entry.getValue() != null) ? entry.getValue() : "null")
+            .append("\n");
+        }
+        return sb.toString();
     }
-    return sb.toString();
-  }
-  /**
-   * Invoked when a new entry is available in the cache, the key is only
-   * provided, the value will come as an entryUpdate invocation
-   *
-   * @param key         Key for the entry just created
-   * @param cacheName   name of the cache for which update has been received
-   * @param originLocal true if the event is generated from this node
-   */
-  @Override
-  public void entryCreated(I key, String cacheName, boolean originLocal) {
-    // TBD: do we require this.
-    if (log.isDebugEnabled()) {
-      log.debug("RoutingTableUpdates: entryCreated  routeId = " + key + " cacheName=" + cacheName);
+    /**
+     * Invoked when a new entry is available in the cache, the key is only
+     * provided, the value will come as an entryUpdate invocation
+     *
+     * @param key         Key for the entry just created
+     * @param cacheName   name of the cache for which update has been received
+     * @param originLocal true if the event is generated from this node
+     */
+    @Override
+    public void entryCreated(final I key, final String cacheName, final boolean originLocal) {
+        // TBD: do we require this.
+        if (log.isDebugEnabled()) {
+            log.debug("RoutingTableUpdates: entryCreated  routeId = " + key + " cacheName=" + cacheName);
+        }
     }
-  }
-
-  /**
-   * Called anytime a given entry is updated
-   *
-   * @param key         Key for the entry modified
-   * @param new_value   the new value the key will have
-   * @param cacheName   name of the cache for which update has been received
-   * @param originLocal true if the event is generated from this node
-   */
-  @Override
-  public void entryUpdated(I key, R new_value, String cacheName, boolean originLocal) {
-    if (log.isDebugEnabled()) {
-      log.debug("RoutingTableUpdates: entryUpdated  routeId = " + key + ",value = " + new_value
-          + " ,cacheName=" + cacheName + " originLocal=" + originLocal);
+
+    /**
+     * Called anytime a given entry is updated
+     *
+     * @param key         Key for the entry modified
+     * @param new_value   the new value the key will have
+     * @param cacheName   name of the cache for which update has been received
+     * @param originLocal true if the event is generated from this node
+     */
+    @Override
+    public void entryUpdated(final I key, final R new_value, final String cacheName, final boolean originLocal) {
+        if (log.isDebugEnabled()) {
+            log.debug("RoutingTableUpdates: entryUpdated  routeId = " + key + ",value = " + new_value
+                    + " ,cacheName=" + cacheName + " originLocal=" + originLocal);
+        }
+        //        if (!originLocal) {
+        //            for (RouteChangeListener rcl : routeChangeListeners) {
+        //                rcl.onRouteUpdated(key, new_value);
+        //            }
+        //        }
     }
-//        if (!originLocal) {
-//            for (RouteChangeListener rcl : routeChangeListeners) {
-//                rcl.onRouteUpdated(key, new_value);
-//            }
-//        }
-  }
-
-  /**
-   * Called anytime a given key is removed from the ConcurrentHashMap we are
-   * listening to.
-   *
-   * @param key         Key of the entry removed
-   * @param cacheName   name of the cache for which update has been received
-   * @param originLocal true if the event is generated from this node
-   */
-  @Override
-  public void entryDeleted(I key, String cacheName, boolean originLocal) {
-    if (log.isDebugEnabled()) {
-      log.debug("RoutingTableUpdates: entryUpdated  routeId = " + key + " local = " + originLocal
-          + " cacheName=" + cacheName + " originLocal=" + originLocal);
+
+    /**
+     * Called anytime a given key is removed from the ConcurrentHashMap we are
+     * listening to.
+     *
+     * @param key         Key of the entry removed
+     * @param cacheName   name of the cache for which update has been received
+     * @param originLocal true if the event is generated from this node
+     */
+    @Override
+    public void entryDeleted(final I key, final String cacheName, final boolean originLocal) {
+        if (log.isDebugEnabled()) {
+            log.debug("RoutingTableUpdates: entryUpdated  routeId = " + key + " local = " + originLocal
+                    + " cacheName=" + cacheName + " originLocal=" + originLocal);
+        }
+        //        if (!originLocal) {
+        //            for (RouteChangeListener rcl : routeChangeListeners) {
+        //                rcl.onRouteDeleted(key);
+        //            }
+        //        }
     }
-//        if (!originLocal) {
-//            for (RouteChangeListener rcl : routeChangeListeners) {
-//                rcl.onRouteDeleted(key);
-//            }
-//        }
-  }
-}
\ No newline at end of file
+}
index 0987df595689176b2d734da6c048ef00a909b2b0..1ff49c1543feb3c59b81c027eac81e47f19b3a02 100644 (file)
@@ -8,7 +8,22 @@
 
 package org.opendaylight.controller.sal.connector.remoterpc.impl;
 
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.when;
+
+import java.net.URI;
+import java.util.EnumSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
 import junit.framework.Assert;
+
 import org.apache.felix.dm.Component;
 import org.junit.After;
 import org.junit.Before;
@@ -17,314 +32,303 @@ import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
 import org.opendaylight.controller.clustering.services.IClusterServices;
 import org.opendaylight.controller.sal.connector.api.RpcRouter;
 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.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
-import java.net.URI;
-import java.util.EnumSet;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.concurrent.*;
-
-import static org.mockito.Mockito.*;
-
 public class RoutingTableImplTest {
 
-  private final URI namespace = URI.create("http://cisco.com/example");
-  private final QName QNAME = new QName(namespace, "global");
-
-  private IClusterGlobalServices clusterService;
-  private RoutingTableImpl<RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier>, String> routingTable;
-  ConcurrentMap mockGlobalRpcCache;
-  ConcurrentMap mockRpcCache;
-
-  @Before
-  public void setUp() throws Exception{
-    clusterService = mock(IClusterGlobalServices.class);
-    routingTable = new RoutingTableImpl<RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier>, String>();
-    mockGlobalRpcCache = new ConcurrentHashMap<>();
-    mockRpcCache = new ConcurrentHashMap<>();
-    createRoutingTableCache();
-  }
-
-  @After
-  public void tearDown(){
-    reset(clusterService);
-    mockGlobalRpcCache = null;
-    mockRpcCache = null;
-  }
+    private final URI namespace = URI.create("http://cisco.com/example");
+    private final QName QNAME = new QName(namespace, "global");
+
+    private IClusterGlobalServices clusterService;
+    private RoutingTableImpl<RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier>, String> routingTable;
+    ConcurrentMap mockGlobalRpcCache;
+    ConcurrentMap mockRpcCache;
+
+    @Before
+    public void setUp() throws Exception{
+        clusterService = mock(IClusterGlobalServices.class);
+        routingTable = new RoutingTableImpl<RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier>, String>();
+        mockGlobalRpcCache = new ConcurrentHashMap<>();
+        mockRpcCache = new ConcurrentHashMap<>();
+        createRoutingTableCache();
+    }
 
-  @Test
-  public void addGlobalRoute_ValidArguments_ShouldAdd() throws Exception {
+    @After
+    public void tearDown(){
+        reset(clusterService);
+        mockGlobalRpcCache = null;
+        mockRpcCache = null;
+    }
 
-    Assert.assertNotNull(mockGlobalRpcCache);
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
+    @Test
+    public void addGlobalRoute_ValidArguments_ShouldAdd() throws Exception {
 
-    final String expectedRoute = "172.27.12.1:5000";
-    routingTable.addGlobalRoute(routeIdentifier, expectedRoute);
+        Assert.assertNotNull(mockGlobalRpcCache);
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
 
-    ConcurrentMap latestCache = routingTable.getGlobalRpcCache();
-    Assert.assertEquals(mockGlobalRpcCache, latestCache);
-    Assert.assertEquals(expectedRoute, latestCache.get(routeIdentifier));
-  }
+        final String expectedRoute = "172.27.12.1:5000";
+        routingTable.addGlobalRoute(routeIdentifier, expectedRoute);
 
-  @Test (expected = RoutingTable.DuplicateRouteException.class)
-  public void addGlobalRoute_DuplicateRoute_ShouldThrow() throws Exception{
+        ConcurrentMap latestCache = routingTable.getGlobalRpcCache();
+        Assert.assertEquals(mockGlobalRpcCache, latestCache);
+        Assert.assertEquals(expectedRoute, latestCache.get(routeIdentifier));
+    }
 
-    Assert.assertNotNull(mockGlobalRpcCache);
+    @Test (expected = RoutingTable.DuplicateRouteException.class)
+    public void addGlobalRoute_DuplicateRoute_ShouldThrow() throws Exception{
 
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
-    routingTable.addGlobalRoute(routeIdentifier, new String());
-    routingTable.addGlobalRoute(routeIdentifier, new String());
-  }
+        Assert.assertNotNull(mockGlobalRpcCache);
 
-  @Test
-  public void getGlobalRoute_ExistingRouteId_ShouldReturnRoute() throws Exception {
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
+        routingTable.addGlobalRoute(routeIdentifier, new String());
+        routingTable.addGlobalRoute(routeIdentifier, new String());
+    }
 
-    Assert.assertNotNull(mockGlobalRpcCache);
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
-    String expectedRoute = "172.27.12.1:5000";
+    @Test
+    public void getGlobalRoute_ExistingRouteId_ShouldReturnRoute() throws Exception {
 
-    routingTable.addGlobalRoute(routeIdentifier, expectedRoute);
+        Assert.assertNotNull(mockGlobalRpcCache);
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
+        String expectedRoute = "172.27.12.1:5000";
 
-    String actualRoute = (String) routingTable.getGlobalRoute(routeIdentifier);
-    Assert.assertEquals(expectedRoute, actualRoute);
-  }
+        routingTable.addGlobalRoute(routeIdentifier, expectedRoute);
 
-  @Test
-  public void getGlobalRoute_NonExistentRouteId_ShouldReturnNull() throws Exception {
+        String actualRoute = routingTable.getGlobalRoute(routeIdentifier);
+        Assert.assertEquals(expectedRoute, actualRoute);
+    }
 
-    Assert.assertNotNull(mockGlobalRpcCache);
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
+    @Test
+    public void getGlobalRoute_NonExistentRouteId_ShouldReturnNull() throws Exception {
 
-    String actualRoute = (String) routingTable.getGlobalRoute(routeIdentifier);
-    Assert.assertNull(actualRoute);
-  }
+        Assert.assertNotNull(mockGlobalRpcCache);
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
 
-  @Test
-  public void removeGlobalRoute_ExistingRouteId_ShouldRemove() throws Exception {
+        String actualRoute = routingTable.getGlobalRoute(routeIdentifier);
+        Assert.assertNull(actualRoute);
+    }
 
-    Assert.assertNotNull(mockGlobalRpcCache);
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
+    @Test
+    public void removeGlobalRoute_ExistingRouteId_ShouldRemove() throws Exception {
 
-    ConcurrentMap cache = routingTable.getGlobalRpcCache();
-    Assert.assertTrue(cache.size() == 0);
-    routingTable.addGlobalRoute(routeIdentifier, "172.27.12.1:5000");
-    Assert.assertTrue(cache.size() == 1);
+        Assert.assertNotNull(mockGlobalRpcCache);
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
 
-    routingTable.removeGlobalRoute(routeIdentifier);
-    Assert.assertTrue(cache.size() == 0);
+        ConcurrentMap cache = routingTable.getGlobalRpcCache();
+        Assert.assertTrue(cache.size() == 0);
+        routingTable.addGlobalRoute(routeIdentifier, "172.27.12.1:5000");
+        Assert.assertTrue(cache.size() == 1);
 
-  }
+        routingTable.removeGlobalRoute(routeIdentifier);
+        Assert.assertTrue(cache.size() == 0);
 
-  @Test
-  public void removeGlobalRoute_NonExistentRouteId_ShouldDoNothing() throws Exception {
+    }
 
-    Assert.assertNotNull(mockGlobalRpcCache);
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
+    @Test
+    public void removeGlobalRoute_NonExistentRouteId_ShouldDoNothing() throws Exception {
 
-    ConcurrentMap cache = routingTable.getGlobalRpcCache();
-    Assert.assertTrue(cache.size() == 0);
+        Assert.assertNotNull(mockGlobalRpcCache);
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = getRouteIdentifier();
 
-    routingTable.removeGlobalRoute(routeIdentifier);
-    Assert.assertTrue(cache.size() == 0);
+        ConcurrentMap cache = routingTable.getGlobalRpcCache();
+        Assert.assertTrue(cache.size() == 0);
 
-  }
+        routingTable.removeGlobalRoute(routeIdentifier);
+        Assert.assertTrue(cache.size() == 0);
 
-  @Test
-  public void addRoute_ForNewRouteId_ShouldAddRoute() throws Exception {
-    Assert.assertTrue(mockRpcCache.size() == 0);
+    }
 
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeId = getRouteIdentifier();
+    @Test
+    public void addRoute_ForNewRouteId_ShouldAddRoute() throws Exception {
+        Assert.assertTrue(mockRpcCache.size() == 0);
 
-    routingTable.addRoute(routeId, new String());
-    Assert.assertTrue(mockRpcCache.size() == 1);
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeId = getRouteIdentifier();
 
-    Set<String> routes = routingTable.getRoutes(routeId);
-    Assert.assertEquals(1, routes.size());
-  }
+        routingTable.addRoute(routeId, new String());
+        Assert.assertTrue(mockRpcCache.size() == 1);
 
-  @Test
-  public void addRoute_ForExistingRouteId_ShouldAppendRoute() throws Exception {
+        Set<String> routes = routingTable.getRoutes(routeId);
+        Assert.assertEquals(1, routes.size());
+    }
 
-    Assert.assertTrue(mockRpcCache.size() == 0);
+    @Test
+    public void addRoute_ForExistingRouteId_ShouldAppendRoute() throws Exception {
 
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeId = getRouteIdentifier();
+        Assert.assertTrue(mockRpcCache.size() == 0);
 
-    String route_1 = "10.0.0.1:5955";
-    String route_2 = "10.0.0.2:5955";
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeId = getRouteIdentifier();
 
-    routingTable.addRoute(routeId, route_1);
-    routingTable.addRoute(routeId, route_2);
+        String route_1 = "10.0.0.1:5955";
+        String route_2 = "10.0.0.2:5955";
 
-    Assert.assertTrue(mockRpcCache.size() == 1);
+        routingTable.addRoute(routeId, route_1);
+        routingTable.addRoute(routeId, route_2);
 
-    Set<String> routes = routingTable.getRoutes(routeId);
-    Assert.assertEquals(2, routes.size());
-    Assert.assertTrue(routes.contains(route_1));
-    Assert.assertTrue(routes.contains(route_2));
-  }
+        Assert.assertTrue(mockRpcCache.size() == 1);
 
-  @Test
-  public void addRoute_UsingMultipleThreads_ShouldNotOverwrite(){
-    ExecutorService threadPool = Executors.newCachedThreadPool();
+        Set<String> routes = routingTable.getRoutes(routeId);
+        Assert.assertEquals(2, routes.size());
+        Assert.assertTrue(routes.contains(route_1));
+        Assert.assertTrue(routes.contains(route_2));
+    }
 
-    int numOfRoutesToAdd = 100;
-    String routePrefix_1   = "10.0.0.1:555";
-    RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
-    threadPool.submit(addRoutes(numOfRoutesToAdd, routePrefix_1, routeId));
-    String routePrefix_2   = "10.0.0.1:556";
-    threadPool.submit(addRoutes(numOfRoutesToAdd, routePrefix_2, routeId));
+    @Test
+    public void addRoute_UsingMultipleThreads_ShouldNotOverwrite(){
+        ExecutorService threadPool = Executors.newCachedThreadPool();
+
+        int numOfRoutesToAdd = 100;
+        String routePrefix_1   = "10.0.0.1:555";
+        RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
+        threadPool.submit(addRoutes(numOfRoutesToAdd, routePrefix_1, routeId));
+        String routePrefix_2   = "10.0.0.1:556";
+        threadPool.submit(addRoutes(numOfRoutesToAdd, routePrefix_2, routeId));
+
+        // wait for all tasks to complete; timeout in 10 sec
+        threadPool.shutdown();
+        try {
+            threadPool.awaitTermination(10, TimeUnit.SECONDS); //
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
 
-    // wait for all tasks to complete; timeout in 10 sec
-    threadPool.shutdown();
-    try {
-      threadPool.awaitTermination(10, TimeUnit.SECONDS); //
-    } catch (InterruptedException e) {
-      e.printStackTrace();
+        Assert.assertEquals(2*numOfRoutesToAdd, routingTable.getRoutes(routeId).size());
     }
 
-    Assert.assertEquals(2*numOfRoutesToAdd, routingTable.getRoutes(routeId).size());
-  }
-
-  @Test(expected = NullPointerException.class)
-  public void addRoute_NullRouteId_shouldThrowNpe() throws Exception {
+    @Test(expected = NullPointerException.class)
+    public void addRoute_NullRouteId_shouldThrowNpe() throws Exception {
 
-    routingTable.addRoute(null, new String());
-  }
+        routingTable.addRoute(null, new String());
+    }
 
-  @Test(expected = NullPointerException.class)
-  public void addRoute_NullRoute_shouldThrowNpe() throws Exception{
+    @Test(expected = NullPointerException.class)
+    public void addRoute_NullRoute_shouldThrowNpe() throws Exception{
 
-    routingTable.addRoute(getRouteIdentifier(), null);
-  }
+        routingTable.addRoute(getRouteIdentifier(), null);
+    }
 
-  @Test (expected = UnsupportedOperationException.class)
-  public void getRoutes_Call_ShouldReturnImmutableCopy() throws Exception{
-    Assert.assertNotNull(routingTable);
-    RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
-    routingTable.addRoute(routeId, new String());
+    @Test (expected = UnsupportedOperationException.class)
+    public void getRoutes_Call_ShouldReturnImmutableCopy() throws Exception{
+        Assert.assertNotNull(routingTable);
+        RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
+        routingTable.addRoute(routeId, new String());
 
-    Set<String> routes = routingTable.getRoutes(routeId); //returns Immutable Set
+        Set<String> routes = routingTable.getRoutes(routeId); //returns Immutable Set
 
-    routes.add(new String()); //can not be modified; should throw
-  }
+        routes.add(new String()); //can not be modified; should throw
+    }
 
-  @Test
-  public void getRoutes_With2RoutesFor1RouteId_ShouldReturnASetWithSize2() throws Exception{
-    Assert.assertNotNull(routingTable);
-    RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
-    routingTable.addRoute(routeId, "10.0.0.1:5555");
-    routingTable.addRoute(routeId, "10.0.0.2:5555");
+    @Test
+    public void getRoutes_With2RoutesFor1RouteId_ShouldReturnASetWithSize2() throws Exception{
+        Assert.assertNotNull(routingTable);
+        RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
+        routingTable.addRoute(routeId, "10.0.0.1:5555");
+        routingTable.addRoute(routeId, "10.0.0.2:5555");
 
-    Set<String> routes = routingTable.getRoutes(routeId); //returns Immutable Set
+        Set<String> routes = routingTable.getRoutes(routeId); //returns Immutable Set
 
-    Assert.assertEquals(2, routes.size());
-  }
+        Assert.assertEquals(2, routes.size());
+    }
 
-  @Test
-  public void getLastAddedRoute_WhenMultipleRoutesExists_ShouldReturnLatestRoute()
-    throws Exception {
+    @Test
+    public void getLastAddedRoute_WhenMultipleRoutesExists_ShouldReturnLatestRoute()
+            throws Exception {
 
-    Assert.assertNotNull(routingTable);
-    RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
-    String route_1 = "10.0.0.1:5555";
-    String route_2 = "10.0.0.2:5555";
-    routingTable.addRoute(routeId, route_1);
-    routingTable.addRoute(routeId, route_2);
+        Assert.assertNotNull(routingTable);
+        RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
+        String route_1 = "10.0.0.1:5555";
+        String route_2 = "10.0.0.2:5555";
+        routingTable.addRoute(routeId, route_1);
+        routingTable.addRoute(routeId, route_2);
 
-    Assert.assertEquals(route_2, routingTable.getLastAddedRoute(routeId));
-  }
+        Assert.assertEquals(route_2, routingTable.getLastAddedRoute(routeId));
+    }
 
-  @Test
-  public void removeRoute_WhenMultipleRoutesExist_RemovesGivenRoute() throws Exception{
-    Assert.assertNotNull(routingTable);
-    RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
-    String route_1 = "10.0.0.1:5555";
-    String route_2 = "10.0.0.2:5555";
+    @Test
+    public void removeRoute_WhenMultipleRoutesExist_RemovesGivenRoute() throws Exception{
+        Assert.assertNotNull(routingTable);
+        RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
+        String route_1 = "10.0.0.1:5555";
+        String route_2 = "10.0.0.2:5555";
 
-    routingTable.addRoute(routeId, route_1);
-    routingTable.addRoute(routeId, route_2);
+        routingTable.addRoute(routeId, route_1);
+        routingTable.addRoute(routeId, route_2);
 
-    Assert.assertEquals(2, routingTable.getRoutes(routeId).size());
+        Assert.assertEquals(2, routingTable.getRoutes(routeId).size());
 
-    routingTable.removeRoute(routeId, route_1);
-    Assert.assertEquals(1, routingTable.getRoutes(routeId).size());
+        routingTable.removeRoute(routeId, route_1);
+        Assert.assertEquals(1, routingTable.getRoutes(routeId).size());
 
-  }
+    }
 
-  @Test
-  public void removeRoute_WhenOnlyOneRouteExists_RemovesRouteId() throws Exception{
-    Assert.assertNotNull(routingTable);
-    RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
-    String route_1 = "10.0.0.1:5555";
+    @Test
+    public void removeRoute_WhenOnlyOneRouteExists_RemovesRouteId() throws Exception{
+        Assert.assertNotNull(routingTable);
+        RpcRouter.RouteIdentifier routeId = getRouteIdentifier();
+        String route_1 = "10.0.0.1:5555";
 
-    routingTable.addRoute(routeId, route_1);
-    Assert.assertEquals(1, routingTable.getRoutes(routeId).size());
+        routingTable.addRoute(routeId, route_1);
+        Assert.assertEquals(1, routingTable.getRoutes(routeId).size());
 
-    routingTable.removeRoute(routeId, route_1);
-    ConcurrentMap cache = routingTable.getRpcCache();
-    Assert.assertFalse(cache.containsKey(routeId));
+        routingTable.removeRoute(routeId, route_1);
+        ConcurrentMap cache = routingTable.getRpcCache();
+        Assert.assertFalse(cache.containsKey(routeId));
 
-  }
+    }
 
-  /*
-   * Private helper methods
-   */
-  private void createRoutingTableCache() throws Exception {
+    /*
+     * Private helper methods
+     */
+    private void createRoutingTableCache() throws Exception {
 
-    //here init
-    Component c = mock(Component.class);
+        //here init
+        Component c = mock(Component.class);
 
-    when(clusterService.existCache(
-        RoutingTableImpl.GLOBALRPC_CACHE)).thenReturn(false);
+        when(clusterService.existCache(
+                RoutingTableImpl.GLOBALRPC_CACHE)).thenReturn(false);
 
-    when(clusterService.createCache(RoutingTableImpl.GLOBALRPC_CACHE,
-        EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL))).
-        thenReturn(mockGlobalRpcCache);
+        when(clusterService.createCache(RoutingTableImpl.GLOBALRPC_CACHE,
+                EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL))).
+                thenReturn(mockGlobalRpcCache);
 
-    when(clusterService.existCache(
-        RoutingTableImpl.RPC_CACHE)).thenReturn(false);
+        when(clusterService.existCache(
+                RoutingTableImpl.RPC_CACHE)).thenReturn(false);
 
-    when(clusterService.createCache(RoutingTableImpl.RPC_CACHE,
-        EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL))).
-        thenReturn(mockRpcCache);
+        when(clusterService.createCache(RoutingTableImpl.RPC_CACHE,
+                EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL))).
+                thenReturn(mockRpcCache);
 
-    doNothing().when(clusterService).tbegin();
-    doNothing().when(clusterService).tcommit();
+        doNothing().when(clusterService).tbegin();
+        doNothing().when(clusterService).tcommit();
 
-    routingTable.setClusterGlobalServices(this.clusterService);
-    routingTable.init(c);
+        routingTable.setClusterGlobalServices(this.clusterService);
+        routingTable.init(c);
 
-    Assert.assertEquals(mockGlobalRpcCache, routingTable.getGlobalRpcCache());
-    Assert.assertEquals(mockRpcCache, routingTable.getRpcCache());
-  }
+        Assert.assertEquals(mockGlobalRpcCache, routingTable.getGlobalRpcCache());
+        Assert.assertEquals(mockRpcCache, routingTable.getRpcCache());
+    }
 
-  private RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> getRouteIdentifier(){
-    RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = mock(RpcRouter.RouteIdentifier.class);
-    InstanceIdentifier identifier = mock(InstanceIdentifier.class);
-    when(routeIdentifier.getType()).thenReturn(QNAME);
-    when(routeIdentifier.getRoute()).thenReturn(identifier);
+    private RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> getRouteIdentifier(){
+        RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier = mock(RpcRouter.RouteIdentifier.class);
+        InstanceIdentifier identifier = mock(InstanceIdentifier.class);
+        when(routeIdentifier.getType()).thenReturn(QNAME);
+        when(routeIdentifier.getRoute()).thenReturn(identifier);
 
-    return routeIdentifier;
-  }
+        return routeIdentifier;
+    }
 
-  private Runnable addRoutes(final int numRoutes, final String routePrefix, final RpcRouter.RouteIdentifier routeId){
-    return new Runnable() {
-      @Override
-      public void run() {
-        for (int i=0;i<numRoutes;i++){
-          String route = routePrefix + i;
-          try {
-            routingTable.addRoute(routeId, route);
-          } catch (Exception e) {
-            e.printStackTrace();
-          }
-        }
-      }
-    };
-  }
+    private Runnable addRoutes(final int numRoutes, final String routePrefix, final RpcRouter.RouteIdentifier routeId){
+        return new Runnable() {
+            @Override
+            public void run() {
+                for (int i=0;i<numRoutes;i++){
+                    String route = routePrefix + i;
+                    try {
+                        routingTable.addRoute(routeId, route);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        };
+    }
 }
index 4d008295a367d0ede83219326cb610c8c89a6b32..b62e4529f341f76a53d522f49dd4f935e781887d 100644 (file)
@@ -23,63 +23,63 @@ public abstract class AbstractBrokerAwareActivator implements BundleActivator {
     private ServiceTracker<BindingAwareBroker, BindingAwareBroker> tracker;
     private BindingAwareBroker broker;
     private ServiceTrackerCustomizer<BindingAwareBroker, BindingAwareBroker> customizer = new ServiceTrackerCustomizer<BindingAwareBroker, BindingAwareBroker>() {
-        
+
         @Override
         public BindingAwareBroker addingService(ServiceReference<BindingAwareBroker> reference) {
             broker = context.getService(reference);
             mdActivationPool.execute(new Runnable() {
-                
+
                 @Override
                 public void run() {
-                    onBrokerAvailable(broker, context);;
+                    onBrokerAvailable(broker, context);
                 }
             });
             return broker;
         }
-        
+
         @Override
         public void modifiedService(ServiceReference<BindingAwareBroker> reference, BindingAwareBroker service) {
             // TODO Auto-generated method stub
-            
+
         }
 
         @Override
         public void removedService(ServiceReference<BindingAwareBroker> reference, BindingAwareBroker service) {
             // TODO Auto-generated method stub
-            
+
         }
 
     };
-    
-    
+
+
     @Override
     public final void start(BundleContext context) throws Exception {
         this.context = context;
         startImpl(context);
         tracker = new ServiceTracker<>(context, BindingAwareBroker.class, customizer);
         tracker.open();
-        
+
     }
 
 
-    
+
     @Override
     public final  void stop(BundleContext context) throws Exception {
         tracker.close();
         stopImpl(context);
     }
-    
-    
+
+
     /**
      * Called when this bundle is started (before
      * {@link #onSessionInitiated(ProviderContext)} so the Framework can perform
      * the bundle-specific activities necessary to start this bundle. This
      * method can be used to register services or to allocate any resources that
      * this bundle needs.
-     * 
+     *
      * <p>
      * This method must complete and return to its caller in a timely manner.
-     * 
+     *
      * @param context
      *            The execution context of the bundle being started.
      * @throws Exception
@@ -99,10 +99,10 @@ public abstract class AbstractBrokerAwareActivator implements BundleActivator {
      * started. There should be no active threads that were started by this
      * bundle when this bundle returns. A stopped bundle must not call any
      * Framework objects.
-     * 
+     *
      * <p>
      * This method must complete and return to its caller in a timely manner.
-     * 
+     *
      * @param context The execution context of the bundle being stopped.
      * @throws Exception If this method throws an exception, the bundle is still
      *         marked as stopped, and the Framework will remove the bundle's
@@ -112,11 +112,11 @@ public abstract class AbstractBrokerAwareActivator implements BundleActivator {
     protected void stopImpl(BundleContext context) {
         // NOOP
     }
-    
+
 
     protected abstract void onBrokerAvailable(BindingAwareBroker broker, BundleContext context);
-    
+
     protected void onBrokerRemoved(BindingAwareBroker broker, BundleContext context) {
-        
+
     }
 }
index 5b700703bc0b522357f42ec2580e9b64e94c924e..453ff449118ffab0898f429cb02c8ec0ca8ed5ff 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.controller.sal.binding.api;
 
 import org.opendaylight.controller.md.sal.common.api.routing.RoutedRegistration;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality;
-import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -39,8 +37,8 @@ import org.osgi.framework.BundleContext;
  * <li>Notification Service - see {@link NotificationService} and
  * {@link NotificationProviderService}
  * <li>Functionality and Data model
- * <li>Data Store access and modification - see {@link DataBrokerService} and
- * {@link DataProviderService}
+ * <li>Data Store access and modification - see {@link org.opendaylight.controller.sal.binding.api.data.DataBrokerService} and
+ * {@link org.opendaylight.controller.sal.binding.api.data.DataProviderService}
  * </ul>
  *
  * The services are exposed via session.
@@ -52,9 +50,6 @@ import org.osgi.framework.BundleContext;
  *
  * For more information about session-based access see {@link ConsumerContext}
  * and {@link ProviderContext}
- *
- *
- *
  */
 public interface BindingAwareBroker {
     /**
@@ -122,9 +117,6 @@ public interface BindingAwareBroker {
      * functionality) for the consumer and provides access to the SAL
      * infrastructure services and other functionality provided by
      * {@link Provider}s.
-     *
-     *
-     *
      */
     public interface ConsumerContext extends RpcConsumerRegistry {
 
@@ -137,8 +129,6 @@ public interface BindingAwareBroker {
          * @return Session specific implementation of service
          */
         <T extends BindingAwareService> T getSALService(Class<T> service);
-
-
     }
 
     /**
index 871abb211710cf52d393398570d83a2ffcd21c59..4327451d2126fa51b6a3a7767e0c2fbd0781703c 100644 (file)
@@ -10,28 +10,28 @@ package org.opendaylight.controller.sal.binding.api;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
 
 /**
- * 
+ *
  * Defines the component of controller and supplies additional metadata. A
  * component of the controller or application supplies a concrete implementation
  * of this interface.
- * 
+ *
  * A user-implemented component (application) which facilitates the SAL and SAL
  * services to access infrastructure services or providers' functionality.
- * 
- * 
- * 
+ *
+ *
+ *
  */
 public interface BindingAwareConsumer {
 
     /**
      * Callback signaling initialization of the consumer session to the SAL.
-     * 
+     *
      * The consumer MUST use the session for all communication with SAL or
      * retrieving SAL infrastructure services.
-     * 
+     *
      * This method is invoked by
      * {@link BindingAwareBroker#registerConsumer(BindingAwareConsumer)}
-     * 
+     *
      * @param session
      *            Unique session between consumer and SAL.
      */
index 120674fa0d578746992656b83aa52ca88792598f..0812e5f53c3d9193cbafaae8acabaaa06be3b880 100644 (file)
@@ -14,24 +14,24 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderCo
 import org.opendaylight.yangtools.yang.binding.RpcService;
 
 /**
- * 
+ *
  * Defines the component of controller and supplies additional metadata. A
  * component of the controller or application supplies a concrete implementation
  * of this interface.
- * 
+ *
  * <p>
  * A user-implemented component (application) which facilitates the SAL and SAL
  * services to access infrastructure services and to provide functionality to
  * {@link Consumer}s and other providers.
- * 
- * 
+ *
+ *
  */
 public interface BindingAwareProvider {
 
     /**
      * Returns a set of provided implementations of YANG modules and their rpcs.
-     * 
-     * 
+     *
+     *
      * @return Set of provided implementation of YANG modules and their Rpcs
      */
     Collection<? extends RpcService> getImplementations();
@@ -39,24 +39,24 @@ public interface BindingAwareProvider {
     /**
      * Gets a set of implementations of provider functionality to be registered
      * into system during the provider registration to the SAL.
-     * 
+     *
      * <p>
      * This method is invoked by {@link Broker#registerProvider(Provider)} to
      * learn the initial provided functionality
-     * 
+     *
      * @return Set of provider's functionality.
      */
     Collection<? extends ProviderFunctionality> getFunctionality();
 
     /**
      * Functionality provided by the {@link BindingAwareProvider}
-     * 
+     *
      * <p>
      * Marker interface used to mark the interfaces describing specific
      * functionality which could be exposed by providers to other components.
-     * 
-     * 
-     * 
+     *
+     *
+     *
      */
     public interface ProviderFunctionality {
 
index b3680568bba9a9d1ed3ae59bc3eb0e03d4eaf17a..adaa27f3e62b9551ccf4cd37fc651ccd7966950a 100644 (file)
@@ -7,33 +7,26 @@
  */
 package org.opendaylight.controller.sal.binding.api;
 
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
-
 /**
- * 
  * Session-specific instance of the broker functionality.
- * 
+ *
  * <p>
  * BindingAwareService is marker interface for infrastructure services provided
  * by the SAL. These services are session-specific, each
  * {@link BindingAwareConsumer} and {@link BindingAwareProvider} usually has own
  * instance of the service with it's own context.
- * 
+ *
  * <p>
  * The consumer's (or provider's) instance of specific service could be obtained
- * by invoking {@link ConsumerContext#getSALService(Class)} method on session
+ * by invoking {@link org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext#getSALService(Class)} method on session
  * assigned to the consumer.
- * 
+ *
  * <p>
- * {@link BindingAwareService} and {@link BindingAwareProvider} may seem
+ * {@link org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext} and {@link BindingAwareProvider} may seem
  * similar, but provider provides YANG model-based functionality and
  * {@link BindingAwareProvider} exposes the necessary supporting functionality
  * to implement specific functionality of YANG and to reuse it in the
- * development of {@link BindingAwareConsumer}s and {@link BindingAwareProvider}
- * s.
- * 
- * 
- * 
+ * development of {@link BindingAwareConsumer}s and {@link BindingAwareProvider}s.
  */
 public interface BindingAwareService {
 
index dd454c66207f5012f83f5f8426ec33b0dc6c2ff3..9429d3f8fa33372dedbbc8b0a00201db695d99a9 100644 (file)
@@ -19,13 +19,13 @@ import org.opendaylight.yangtools.yang.binding.Notification;
  * @param <T> Notification type
  */
 public interface NotificationListener<T extends Notification> extends EventListener {
-       /**
-        * Invoked to deliver the notification. Note that this method may be invoked
-        * from a shared thread pool, so implementations SHOULD NOT perform CPU-intensive
-        * operations and they definitely MUST NOT invoke any potentially blocking
-        * operations.
-        *
-        * @param notification Notification being delivered.
-        */
+    /**
+     * Invoked to deliver the notification. Note that this method may be invoked
+     * from a shared thread pool, so implementations SHOULD NOT perform CPU-intensive
+     * operations and they definitely MUST NOT invoke any potentially blocking
+     * operations.
+     *
+     * @param notification Notification being delivered.
+     */
     void onNotification(T notification);
 }
index f71d69b860d5127ee0f01be5c409a319e36cfd6e..7da0a48517fddf715db5f55ced1d431680f0a755 100644 (file)
@@ -12,13 +12,13 @@ import org.opendaylight.yangtools.yang.binding.RpcService;
 /**
  * Base interface defining contract for retrieving MD-SAL
  * version of RpcServices
- * 
+ *
  */
 public interface RpcConsumerRegistry extends BindingAwareService {
     /**
      * Returns a session specific instance (implementation) of requested
      * YANG module implementation / service provided by consumer.
-     * 
+     *
      * @return Session specific implementation of service
      */
     <T extends RpcService> T getRpcService(Class<T> module);
index 65f1ff2fe368ac07255d852e57c58ee2e5e1f610..d0225768b4e2500acf0eccfb13e4999e0a8591e3 100644 (file)
@@ -33,7 +33,7 @@ public interface DataBrokerService extends //
      * @return new blank data modification transaction.
      */
     @Override
-       DataModificationTransaction beginTransaction();
+    DataModificationTransaction beginTransaction();
 
     /**
      * Reads data subtree from configurational store.
index 719063832314cfa069121fb92d79c62165439424..5fafabbd1b6e9104bd72c3946acce0aa2e580871 100644 (file)
@@ -11,7 +11,6 @@ import java.util.EventListener;
 import java.util.concurrent.Future;
 
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
-import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -19,13 +18,12 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public interface DataModificationTransaction extends DataModification<InstanceIdentifier<? extends DataObject>, DataObject> {
-
     /**
      * Returns an unique identifier for transaction
      *
      */
     @Override
-    public Object getIdentifier();
+    Object getIdentifier();
 
     /**
      * Initiates a two-phase commit of candidate data.
@@ -44,7 +42,7 @@ public interface DataModificationTransaction extends DataModification<InstanceId
      * of this changes.
      *
      *
-     * @see DataCommitHandler for further information how two-phase commit is
+     * @see org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler for further information how two-phase commit is
      *      processed.
      * @param store
      *            Identifier of the store, where commit should occur.
@@ -52,9 +50,7 @@ public interface DataModificationTransaction extends DataModification<InstanceId
      *         encountered errors, if commit was not successful.
      */
     @Override
-    public Future<RpcResult<TransactionStatus>> commit();
-
-
+    Future<RpcResult<TransactionStatus>> commit();
 
     /**
      * Register a listener for transaction
@@ -64,12 +60,8 @@ public interface DataModificationTransaction extends DataModification<InstanceId
      */
     ListenerRegistration<DataTransactionListener> registerListener(DataTransactionListener listener);
 
-
-
     /**
      * Listener for transaction state changes
-     *
-     *
      */
     public interface DataTransactionListener extends EventListener {
         /**
index 7d662cfcf20ebc60bd722fded3a6b04ab6eda9c7..b496d1dfb4ba58636e2af34abcd1e7cd186f4f55 100644 (file)
@@ -7,22 +7,17 @@
  */
 package org.opendaylight.controller.sal.binding.api.data;
 
-
 import org.opendaylight.controller.md.sal.common.api.data.DataProvisionService;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
- * DataProviderService is common access point for {@link BindingAwareProvider} providers
+ * DataProviderService is common access point for {@link org.opendaylight.controller.sal.binding.api.BindingAwareProvider} providers
  * to access data trees described by the YANG model.
- *
  */
 public interface DataProviderService extends DataBrokerService, DataProvisionService<InstanceIdentifier<? extends DataObject>, DataObject> {
-
-
     /**
      * Registers a data reader for particular subtree of overal YANG data tree.
      *
index dec44f364fc10e95c4ffdb6f9b93422de52e0b53..0d9a90286e091693ca4ffd66b6322d88dda00a69 100644 (file)
@@ -15,9 +15,9 @@ import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
  * Provider's version of Mount Point, this version allows access to MD-SAL
  * services specific for this mountpoint and registration / provision of
  * interfaces for mount point.
- * 
+ *
  * @author ttkacik
- * 
+ *
  */
 public interface MountProviderInstance //
         extends //
index d6374fff909a2e8972b152269fbbfd8b6ff66a5c..e3bedd33f9a2307bf9e76437e48729765698c763 100644 (file)
@@ -15,7 +15,7 @@ public final  class RpcContextIdentifier implements Immutable{
 
     public final Class<? extends RpcService> rpcService;
     public final Class<? extends BaseIdentity> routingContext;
-   
+
     private RpcContextIdentifier(Class<? extends RpcService> rpcService, Class<? extends BaseIdentity> routingContext) {
         super();
         this.rpcService = rpcService;
@@ -29,11 +29,11 @@ public final  class RpcContextIdentifier implements Immutable{
     public Class<? extends BaseIdentity> getRoutingContext() {
         return routingContext;
     }
-    
+
     public static final RpcContextIdentifier contextForGlobalRpc(Class<? extends RpcService> serviceType) {
         return new RpcContextIdentifier(serviceType, null);
     }
-    
+
     public static final RpcContextIdentifier contextFor(Class<? extends RpcService> serviceType,Class<? extends BaseIdentity> routingContext) {
         return new RpcContextIdentifier(serviceType, routingContext);
     }
index cc800b6bbbdfd6c9b6f46678134fa6fa1fb9713a..61c7cfc9533b376c33f9243aae6e63abd5c66ae6 100644 (file)
@@ -22,7 +22,7 @@ public interface RpcRoutingTable<C extends BaseIdentity, S extends RpcService> e
     /**
      * Updates route for particular path to specified instance of
      * {@link RpcService}.
-     * 
+     *
      * @param path
      *            Path for which RpcService routing is to be updated
      * @param service
@@ -33,19 +33,19 @@ public interface RpcRoutingTable<C extends BaseIdentity, S extends RpcService> e
 
     /**
      * Deletes a route for particular path
-     * 
+     *
      * @param path
      *            Path for which
      */
     void removeRoute(InstanceIdentifier<?> path);
 
     /**
-     * 
+     *
      */
     S getRoute(InstanceIdentifier<?> nodeInstance);
 
     /**
-     * 
+     *
      * @return
      */
     Map<InstanceIdentifier<?>, S> getRoutes();
index df3b7ece5dbd13a7b3bc2c24618ce79355d6ee7d..a11a7d67f5d4077006676dc476cf154e1de8ade8 100644 (file)
@@ -26,14 +26,14 @@ import org.osgi.framework.BundleContext;
 */
 public class BindingBrokerImplModuleFactory extends org.opendaylight.controller.config.yang.md.sal.binding.impl.AbstractBindingBrokerImplModuleFactory {
 
-    
+
     @Override
     public Module createModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) {
         BindingBrokerImplModule module = (BindingBrokerImplModule) super.createModule(instanceName, dependencyResolver, bundleContext);
         module.setBundleContext(bundleContext);
         return module;
     }
-    
+
     @Override
     public Module createModule(String instanceName, DependencyResolver dependencyResolver,
             DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception {
index 8aff12b44a5f1b5c58dfd816f457a918b497925d..9b7b8e28c90657aedc2f53c8c17d1697a0cd6e62 100644 (file)
@@ -9,56 +9,54 @@ package org.opendaylight.controller.sal.binding.codegen;
 
 import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter;
 import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
 
 public interface RuntimeCodeGenerator {
 
     /**
      * Returns an instance of provided RpcService type which delegates all calls
      * to the delegate.
-     * 
+     *
      * <p>
      * Returned instance:
      * <ul>
      * <li>implements provided subclass of RpcService type and
-     * {@link DelegateProxy} interface.
+     * {@link org.opendaylight.controller.sal.binding.spi.DelegateProxy} interface.
      * <li>
      * <p>
      * delegates all invocations of methods, which are defined in RpcService
      * subtype to delegate which is defined by
-     * {@link DelegateProxy#setDelegate(Object)}.
+     * {@link org.opendaylight.controller.sal.binding.spi.DelegateProxy#setDelegate(Object)}.
      * <p>
      * If delegate is not defined (<code>getDelegate() == null</code>)
      * implementation throws {@link IllegalStateException}
-     * <li>{@link DelegateProxy#getDelegate()} - returns the delegate to which
+     * <li>{@link org.opendaylight.controller.sal.binding.spi.DelegateProxy#getDelegate()} - returns the delegate to which
      * all calls are delegated.
-     * <li>{@link DelegateProxy#setDelegate(Object)} - sets the delegate for
+     * <li>{@link org.opendaylight.controller.sal.binding.spi.DelegateProxy#setDelegate(Object)} - sets the delegate for
      * particular instance
-     * 
+     *
      * </ul>
-     * 
+     *
      * @param serviceType
      *            - Subclass of RpcService for which direct proxy is to be
      *            generated.
      * @return Instance of RpcService of provided serviceType which implements
-     *         and {@link DelegateProxy}
+     *         and {@link org.opendaylight.controller.sal.binding.spi.DelegateProxy}
      * @throws IllegalArgumentException
-     * 
+     *
      */
     <T extends RpcService> T getDirectProxyFor(Class<T> serviceType) throws IllegalArgumentException;
 
     /**
      * Returns an instance of provided RpcService type which routes all calls to
      * other instances selected on particular input field.
-     * 
+     *
      * <p>
      * Returned instance:
      * <ul>
      * <li>Implements:
      * <ul>
-     * <li>{@link DelegateProxy}
+     * <li>{@link org.opendaylight.controller.sal.binding.spi.DelegateProxy}
      * <li>{@link RpcRouter}
      * </ul>
      * <li>
@@ -69,22 +67,23 @@ public interface RuntimeCodeGenerator {
      * <ul>
      * <li>
      * Implementation uses
-     * {@link RpcRouter#getService(Class, InstanceIdentifier)} method to
+     * {@link RpcRouter#getService(Class, org.opendaylight.yangtools.yang.binding.InstanceIdentifier)} method to
      * retrieve particular instance to which call will be routed.
      * <li>
-     * Instance of {@link InstanceIdentifier} is determined by first argument of
+     * Instance of {@link org.opendaylight.yangtools.yang.binding.InstanceIdentifier} is determined by first argument of
      * method and is retrieved via method which is annotated with
-     * {@link RoutingContext}. Class representing Routing Context Identifier is
-     * retrieved by {@link RoutingContext}.
-     * <li>If first argument is not defined / {@link RoutingContext} annotation
+     * {@link org.opendaylight.yangtools.yang.binding.annotations.RoutingContext}.
+     * Class representing Routing Context Identifier is retrieved by a
+     * {@link org.opendaylight.yangtools.yang.binding.annotations.RoutingContext}.
+     * <li>If first argument is not defined / {@link org.opendaylight.yangtools.yang.binding.annotations.RoutingContext} annotation
      * is not present on any field invocation will be delegated to default
      * service {@link RpcRouter#getDefaultService()}.
      * </ul>
-     * 
+     *
      * @param serviceType
      *            - Subclass of RpcService for which Router is to be generated.
      * @return Instance of RpcService of provided serviceType which implements
-     *         also {@link RpcRouter}<T> and {@link DelegateProxy}
+     *         also {@link RpcRouter}<T> and {@link org.opendaylight.controller.sal.binding.spi.DelegateProxy}
      */
     <T extends RpcService> RpcRouter<T> getRouterFor(Class<T> serviceType,String name) throws IllegalArgumentException;
 
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
deleted file mode 100644 (file)
index 4ad0bb0..0000000
+++ /dev/null
@@ -1,23 +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 final class YangtoolsMappingHelper {
-    private YangtoolsMappingHelper() {
-        throw new UnsupportedOperationException("Utility class");
-    }
-
-    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/impl/AbstractRuntimeCodeGenerator.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/AbstractRuntimeCodeGenerator.java
new file mode 100644 (file)
index 0000000..9605a4d
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * 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.codegen.impl;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMethod;
+import javassist.NotFoundException;
+
+import javax.annotation.concurrent.GuardedBy;
+
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.opendaylight.controller.sal.binding.api.rpc.RpcRouter;
+import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
+import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
+import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils;
+
+import com.google.common.base.Supplier;
+
+abstract class AbstractRuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator, NotificationInvokerFactory {
+    @GuardedBy("this")
+    private final Map<Class<? extends NotificationListener>, RuntimeGeneratedInvokerPrototype> invokerClasses = new WeakHashMap<>();
+    private final CtClass brokerNotificationListener;
+
+    @Extension
+    protected final JavassistUtils utils;
+
+    protected AbstractRuntimeCodeGenerator(final ClassPool pool) {
+        utils = JavassistUtils.forClassPool(pool);
+
+        /*
+         * Make sure Javassist ClassPool sees the classloader of RpcService
+         */
+        utils.ensureClassLoader(RpcService.class);
+
+        brokerNotificationListener = utils.asCtClass(org.opendaylight.controller.sal.binding.api.NotificationListener.class);
+    }
+
+    protected final CtClass getBrokerNotificationListener() {
+        return brokerNotificationListener;
+    }
+
+    protected abstract RuntimeGeneratedInvokerPrototype generateListenerInvoker(Class<? extends NotificationListener> cls);
+    protected abstract <T extends RpcService> Supplier<T> directProxySupplier(final Class<T> serviceType);
+    protected abstract <T extends RpcService> Supplier<T> routerSupplier(final Class<T> serviceType, RpcServiceMetadata metadata);
+
+    private RpcServiceMetadata getRpcMetadata(final CtClass iface) throws ClassNotFoundException, NotFoundException {
+        final RpcServiceMetadata metadata = new RpcServiceMetadata();
+
+        for (CtMethod method : iface.getMethods()) {
+            if (iface.equals(method.getDeclaringClass()) && method.getParameterTypes().length == 1) {
+                final RpcMetadata routingPair = getRpcMetadata(method);
+                if (routingPair != null) {
+                    metadata.addContext(routingPair.getContext());
+                    metadata.addRpcMethod(method.getName(), routingPair);
+
+                    /*
+                     * Force-load the RPC class representing the "input" of this RPC.
+                     *
+                     * FIXME: this is pre-existing side-effect of the original code, which
+                     *        kept a reference to the loaded class, but it did not use it.
+                     *
+                     *        There was no explanation as to why forcing this load was
+                     *        necessary. As far as I can tell now is that it forces the
+                     *        resolution of method arguments, which would (according to
+                     *        my reading of JLS) occur only when the method is invoked via
+                     *        binding-aware class action, not when coming from
+                     *        binding-independent world. Whether that makes sense or not,
+                     *        remains to be investigated.
+                     */
+                    Thread.currentThread().getContextClassLoader().loadClass(routingPair.getInputType().getName());
+                }
+            }
+        }
+
+        return metadata;
+    }
+
+    private RpcMetadata getRpcMetadata(final CtMethod method) throws NotFoundException {
+        final CtClass inputClass = method.getParameterTypes()[0];
+        return rpcMethodMetadata(inputClass, inputClass, method.getName());
+    }
+
+    private RpcMetadata rpcMethodMetadata(final CtClass dataClass, final CtClass inputClass, final String rpcMethod) throws NotFoundException {
+        for (CtMethod method : dataClass.getMethods()) {
+            if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
+                for (Object annotation : method.getAvailableAnnotations()) {
+                    if (annotation instanceof RoutingContext) {
+                        boolean encapsulated = !method.getReturnType().equals(utils.asCtClass(InstanceIdentifier.class));
+                        return new RpcMetadata(rpcMethod, ((RoutingContext)annotation).value(), method, encapsulated, inputClass);
+                    }
+                }
+            }
+        }
+
+        for (CtClass iface : dataClass.getInterfaces()) {
+            final RpcMetadata ret = rpcMethodMetadata(iface, inputClass, rpcMethod);
+            if(ret != null) {
+                return ret;
+            }
+        }
+        return null;
+    }
+
+    private synchronized RuntimeGeneratedInvokerPrototype resolveInvokerClass(final Class<? extends NotificationListener> cls) {
+        RuntimeGeneratedInvokerPrototype invoker = invokerClasses.get(cls);
+        if (invoker != null) {
+            return invoker;
+        }
+
+        utils.getLock().lock();
+        try {
+            invoker = ClassLoaderUtils.withClassLoader(cls.getClassLoader(), new Supplier<RuntimeGeneratedInvokerPrototype>() {
+                @Override
+                public RuntimeGeneratedInvokerPrototype get() {
+                    return generateListenerInvoker(cls);
+                }
+            });
+
+            invokerClasses.put(cls, invoker);
+            return invoker;
+        } finally {
+            utils.getLock().unlock();
+        }
+    }
+
+    @Override
+    public final NotificationInvokerFactory getInvokerFactory() {
+        return this;
+    }
+
+    @Override
+    public final <T extends RpcService> T getDirectProxyFor(final Class<T> serviceType) {
+        utils.getLock().lock();
+        try {
+            return ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), directProxySupplier(serviceType));
+        } finally {
+            utils.getLock().unlock();
+        }
+    }
+
+    @Override
+    public final <T extends RpcService> RpcRouter<T> getRouterFor(final Class<T> serviceType, final String name) {
+        final RpcServiceMetadata metadata = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), new Supplier<RpcServiceMetadata>() {
+            @Override
+            public RpcServiceMetadata get() {
+                try {
+                    return getRpcMetadata(utils.asCtClass(serviceType));
+                } catch (ClassNotFoundException | NotFoundException e) {
+                    throw new IllegalStateException(String.format("Failed to load metadata for class {}", serviceType), e);
+                }
+            }
+        });
+
+        utils.getLock().lock();
+        try {
+            final T instance = ClassLoaderUtils.withClassLoader(serviceType.getClassLoader(), routerSupplier(serviceType, metadata));
+            return new RpcRouterCodegenInstance<T>(name, serviceType, instance, metadata.getContexts());
+        } finally {
+            utils.getLock().unlock();
+        }
+    }
+
+    @Override
+    public NotificationInvoker invokerFor(final NotificationListener instance) {
+        final Class<? extends NotificationListener> cls = instance.getClass();
+        final RuntimeGeneratedInvokerPrototype prototype = resolveInvokerClass(cls);
+
+        try {
+            return RuntimeGeneratedInvoker.create(instance, prototype);
+        } catch (InstantiationException | IllegalAccessException e) {
+            throw new IllegalStateException(String.format("Failed to create invoker for %s", instance), e);
+        }
+    }
+}
index cab4fe90e0f30da4c0f1b8a38be37a72fe8f25ea..fdd9350680f450131049800a9965843ae2c807a3 100644 (file)
@@ -6,25 +6,22 @@
  * 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;
+    private final ClassLoader spiClassLoader;
 
-  public BrokerImplClassLoader(final ClassLoader model, final ClassLoader spi) {
-    super(model);
-    this.spiClassLoader = spi;
-  }
+    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);
+    @Override
+    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/RpcMetadata.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcMetadata.java
new file mode 100644 (file)
index 0000000..6f9f85f
--- /dev/null
@@ -0,0 +1,95 @@
+/**
+ * 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 javassist.CtClass;
+import javassist.CtMethod;
+
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+final class RpcMetadata {
+    private final Class<? extends BaseIdentity> context;
+    private final CtMethod inputRouteGetter;
+    private final Boolean routeEncapsulated;
+    private final CtClass inputType;
+    private final String methodName;
+
+    public Class<? extends BaseIdentity> getContext() {
+        return context;
+    }
+
+    public CtMethod getInputRouteGetter() {
+        return inputRouteGetter;
+    }
+
+    public CtClass getInputType() {
+        return inputType;
+    }
+
+    public boolean isRouteEncapsulated() {
+        return routeEncapsulated;
+    }
+
+    public RpcMetadata(final String methodName, final Class<? extends BaseIdentity> context, final CtMethod inputRouteGetter, final boolean routeEncapsulated, final CtClass inputType) {
+        this.inputRouteGetter = Preconditions.checkNotNull(inputRouteGetter);
+        this.methodName = Preconditions.checkNotNull(methodName);
+        this.inputType = Preconditions.checkNotNull(inputType);
+        this.context = Preconditions.checkNotNull(context);
+        this.routeEncapsulated = routeEncapsulated;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + methodName.hashCode();
+        result = prime * result + context.hashCode();
+        result = prime * result + inputRouteGetter.hashCode();
+        result = prime * result + routeEncapsulated.hashCode();
+        result = prime * result +  inputType.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof RpcMetadata)) {
+            return false;
+        }
+        final RpcMetadata other = (RpcMetadata) obj;
+        if (!methodName.equals(other.methodName)) {
+            return false;
+        }
+        if (!context.equals(other.context)) {
+            return false;
+        }
+        if (!inputRouteGetter.equals(other.inputRouteGetter)) {
+            return false;
+        }
+        if (!routeEncapsulated.equals(other.routeEncapsulated)) {
+            return false;
+        }
+        return inputType.equals(other.inputType);
+    }
+
+    @Override
+    public String toString() {
+        return Objects.toStringHelper(this)
+                .add("context", context)
+                .add("inputRouteGetter", inputRouteGetter)
+                .add("inputType", inputType)
+                .add("methodName", methodName)
+                .add("routeEncapsulated", routeEncapsulated)
+                .toString();
+    }
+}
index 5578f75ae21d6800cf2c73661afa15a071bd6ef8..052fd2169a523b955a427f036e2a0ab6b7a03bc4 100644 (file)
@@ -24,7 +24,6 @@ import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.slf4j.Logger;
@@ -34,7 +33,7 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
 public class RpcRouterCodegenInstance<T extends RpcService> implements //
-        RpcRouter<T>, RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>> {
+RpcRouter<T>, RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>> {
 
     private static final Logger LOG = LoggerFactory.getLogger(RpcRouterCodegenInstance.class);
 
@@ -53,8 +52,7 @@ public class RpcRouterCodegenInstance<T extends RpcService> implements //
     private final String name;
 
     @SuppressWarnings("unchecked")
-    public RpcRouterCodegenInstance(String name,Class<T> type, T routerImpl, Set<Class<? extends BaseIdentity>> contexts,
-            Set<Class<? extends DataContainer>> inputs) {
+    public RpcRouterCodegenInstance(final String name,final Class<T> type, final T routerImpl, final Iterable<Class<? extends BaseIdentity>> contexts) {
         this.name = name;
         this.listeners = ListenerRegistry.create();
         this.serviceType = type;
@@ -86,7 +84,7 @@ public class RpcRouterCodegenInstance<T extends RpcService> implements //
 
     @Override
     @SuppressWarnings("unchecked")
-    public <C extends BaseIdentity> RpcRoutingTable<C, T> getRoutingTable(Class<C> routeContext) {
+    public <C extends BaseIdentity> RpcRoutingTable<C, T> getRoutingTable(final Class<C> routeContext) {
         return (RpcRoutingTable<C, T>) routingTables.get(routeContext);
     }
 
@@ -102,12 +100,12 @@ public class RpcRouterCodegenInstance<T extends RpcService> implements //
 
     @Override
     public <L extends RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
-            L listener) {
+            final L listener) {
         return listeners.registerWithType(listener);
     }
 
     @Override
-    public void onRouteChange(RouteChange<Class<? extends BaseIdentity>, InstanceIdentifier<?>> change) {
+    public void onRouteChange(final RouteChange<Class<? extends BaseIdentity>, InstanceIdentifier<?>> change) {
         for (ListenerRegistration<RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>>> listener : listeners) {
             try {
                 listener.getInstance().onRouteChange(change);
@@ -118,17 +116,17 @@ public class RpcRouterCodegenInstance<T extends RpcService> implements //
     }
 
     @Override
-    public T getService(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+    public T getService(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> path) {
         return routingTables.get(context).getRoute(path);
     }
 
     @Override
-    public RoutedRpcRegistration<T> addRoutedRpcImplementation(T service) {
+    public RoutedRpcRegistration<T> addRoutedRpcImplementation(final T service) {
         return new RoutedRpcRegistrationImpl(service);
     }
 
     @Override
-    public RpcRegistration<T> registerDefaultService(T service) {
+    public RpcRegistration<T> registerDefaultService(final T service) {
         // TODO Auto-generated method stub
         RuntimeCodeHelper.setDelegate(invocationProxy, service);
         return null;
@@ -136,7 +134,7 @@ public class RpcRouterCodegenInstance<T extends RpcService> implements //
 
     private class RoutedRpcRegistrationImpl extends AbstractObjectRegistration<T> implements RoutedRpcRegistration<T> {
 
-        public RoutedRpcRegistrationImpl(T instance) {
+        public RoutedRpcRegistrationImpl(final T instance) {
             super(instance);
         }
 
@@ -146,22 +144,22 @@ public class RpcRouterCodegenInstance<T extends RpcService> implements //
         }
 
         @Override
-        public void registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+        public void registerPath(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> path) {
             routingTables.get(context).updateRoute(path, getInstance());
         }
 
         @Override
-        public void unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+        public void unregisterPath(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> path) {
             routingTables.get(context).removeRoute(path, getInstance());
         }
 
         @Override
-        public void registerInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance) {
+        public void registerInstance(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> instance) {
             registerPath(context, instance);
         }
 
         @Override
-        public void unregisterInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance) {
+        public void unregisterInstance(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> instance) {
             unregisterPath(context, instance);
         }
 
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcServiceMetadata.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcServiceMetadata.java
new file mode 100644 (file)
index 0000000..430b7a7
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * 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.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+
+import com.google.common.collect.Iterables;
+
+final class RpcServiceMetadata {
+    private final Set<Class<? extends BaseIdentity>> contexts = new HashSet<>();
+    private final Map<String, RpcMetadata> rpcMethods = new HashMap<>();
+    private final Iterable<Class<? extends BaseIdentity>> roContexts = Iterables.unmodifiableIterable(contexts);
+
+    public Iterable<Class<? extends BaseIdentity>> getContexts() {
+        return roContexts;
+    }
+
+    public RpcMetadata getRpcMethod(final String name) {
+        return rpcMethods.get(name);
+    }
+
+    public void addContext(final Class<? extends BaseIdentity> context) {
+        contexts.add(context);
+    }
+
+    public void addRpcMethod(final String name, final RpcMetadata routingPair) {
+        rpcMethods.put(name, routingPair);
+    }
+}
index 465a1f7d9dd2d1e5ef33fd088ed076a2597a326b..3fef544f8115879aa5dc9df4c7d4ab1306d6ca1a 100644 (file)
@@ -7,59 +7,28 @@
  */
 package org.opendaylight.controller.sal.binding.codegen.impl
 
+import java.util.Map
 import javassist.ClassPool
-import org.opendaylight.yangtools.yang.binding.RpcService
-
-import javassist.CtClass
-import javassist.CtMethod
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext
-import org.opendaylight.yangtools.yang.binding.BaseIdentity
-
-import java.util.Map
-import java.util.HashMap
-
-
-import org.opendaylight.yangtools.yang.binding.NotificationListener
 import org.opendaylight.yangtools.yang.binding.Notification
-
-
-import static extension org.opendaylight.controller.sal.binding.codegen.YangtoolsMappingHelper.*
-import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification.*
-import java.util.HashSet
-import static org.opendaylight.yangtools.concepts.util.ClassLoaderUtils.*
-import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory
-import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker
-import java.util.Set
-import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper
-import java.util.WeakHashMap
-import org.opendaylight.yangtools.yang.binding.annotations.QName
-import org.opendaylight.yangtools.yang.binding.DataContainer
 import org.opendaylight.yangtools.yang.binding.RpcImplementation
-import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils
-import org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils
-import javassist.LoaderClassPath
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections
+import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils
 
-class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator, NotificationInvokerFactory {
-
-    val CtClass BROKER_NOTIFICATION_LISTENER;
-    val extension JavassistUtils utils;
-    val Map<Class<? extends NotificationListener>, RuntimeGeneratedInvokerPrototype> invokerClasses;
+import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeSpecification.*
 
+class RuntimeCodeGenerator extends AbstractRuntimeCodeGenerator {
 
     new(ClassPool pool) {
-        utils = new JavassistUtils(pool);
-        invokerClasses = new WeakHashMap();
-        BROKER_NOTIFICATION_LISTENER = org.opendaylight.controller.sal.binding.api.NotificationListener.asCtClass;
-        pool.appendClassPath(new LoaderClassPath(RpcService.classLoader));
+        super(pool)
     }
 
-    override <T extends RpcService> getDirectProxyFor(Class<T> iface) {
-        val T instance =  withClassLoaderAndLock(iface.classLoader,lock) [|
+    override directProxySupplier(Class iface) {
+        return [|
             val proxyName = iface.directProxyName;
             val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(proxyName)
             if(potentialClass != null) {
-                return potentialClass.newInstance as T;
+                return potentialClass.newInstance;
             }
             val supertype = iface.asCtClass
             val createdCls = createClass(iface.directProxyName, supertype) [
@@ -84,23 +53,17 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
                     '''
                 ]
             ]
-            return createdCls.toClass(iface.classLoader).newInstance as T
+            return createdCls.toClass(iface.classLoader).newInstance
         ]
-        return instance;
     }
 
-    override <T extends RpcService> getRouterFor(Class<T> iface,String routerInstanceName) {
-        val metadata = withClassLoader(iface.classLoader) [|
-            val supertype = iface.asCtClass
-            return supertype.rpcMetadata;
-        ]
-
-        val instance = <T>withClassLoaderAndLock(iface.classLoader,lock) [ |
+    override routerSupplier(Class iface, RpcServiceMetadata metadata) {
+        return [ |
             val supertype = iface.asCtClass
             val routerName = iface.routerName;
             val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(routerName)
             if(potentialClass != null) {
-                return potentialClass.newInstance as T;
+                return potentialClass.newInstance;
             }
 
             val targetCls = createClass(iface.routerName, supertype) [
@@ -115,7 +78,7 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
                 }
                 implementMethodsFrom(supertype) [
                     if (parameterTypes.size === 1) {
-                        val rpcMeta = metadata.rpcMethods.get(name);
+                        val rpcMeta = metadata.getRpcMethod(name);
                         val bodyTmp = '''
                         {
                             final Â«InstanceIdentifier.name» identifier = $1.«rpcMeta.inputRouteGetter.name»()«IF rpcMeta.
@@ -143,74 +106,18 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
                     '''
                 ]
             ]
-            return targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance as T
-
+            return targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance
         ];
-        return new RpcRouterCodegenInstance(routerInstanceName,iface, instance, metadata.contexts,metadata.supportedInputs);
-    }
-
-    private def RpcServiceMetadata getRpcMetadata(CtClass iface) {
-        val metadata = new RpcServiceMetadata;
-
-        iface.methods.filter[declaringClass == iface && parameterTypes.size === 1].forEach [ method |
-            val routingPair = method.rpcMetadata;
-            if (routingPair !== null) {
-                metadata.contexts.add(routingPair.context)
-                metadata.rpcMethods.put(method.name,routingPair)
-                val input = routingPair.inputType.javaClass as Class<? extends DataContainer>;
-                metadata.supportedInputs.add(input);
-                metadata.rpcInputs.put(input,routingPair);
-            }
-        ]
-        return metadata;
-    }
-
-    private def getRpcMetadata(CtMethod method) {
-        val inputClass = method.parameterTypes.get(0);
-        return inputClass.rpcMethodMetadata(inputClass,method.name);
-    }
-
-    private def RpcMetadata rpcMethodMetadata(CtClass dataClass,CtClass inputClass,String rpcMethod) {
-        for (method : dataClass.methods) {
-            if (method.name.startsWith("get") && method.parameterTypes.size === 0) {
-                for (annotation : method.availableAnnotations) {
-                    if (annotation instanceof RoutingContext) {
-                        val encapsulated = !method.returnType.equals(InstanceIdentifier.asCtClass);
-                        return new RpcMetadata(null,rpcMethod,(annotation as RoutingContext).value, method, encapsulated,inputClass);
-                    }
-                }
-            }
-        }
-        for (iface : dataClass.interfaces) {
-            val ret = rpcMethodMetadata(iface,inputClass,rpcMethod);
-            if(ret != null) return ret;
-        }
-        return null;
     }
 
-    private def getJavaClass(CtClass cls) {
-        Thread.currentThread.contextClassLoader.loadClass(cls.name)
-    }
-
-    override getInvokerFactory() {
-        return this;
-    }
-
-    override invokerFor(NotificationListener instance) {
-        val cls = instance.class
-        val prototype = resolveInvokerClass(cls);
-
-        return new RuntimeGeneratedInvoker(instance, prototype)
-    }
-
-    protected def generateListenerInvoker(Class<? extends NotificationListener> iface) {
-        val callbacks = iface.methods.filter[notificationCallback]
+    override generateListenerInvoker(Class iface) {
+        val callbacks = iface.methods.filter[BindingReflections.isNotificationCallback(it)]
 
         val supportedNotification = callbacks.map[parameterTypes.get(0) as Class<? extends Notification>].toSet;
 
-        val targetCls = createClass(iface.invokerName, BROKER_NOTIFICATION_LISTENER) [
+        val targetCls = createClass(iface.invokerName, brokerNotificationListener) [
             field(DELEGATE_FIELD, iface)
-            implementMethodsFrom(BROKER_NOTIFICATION_LISTENER) [
+            implementMethodsFrom(brokerNotificationListener) [
                 body = '''
                     {
                         Â«FOR callback : callbacks SEPARATOR " else "»
@@ -229,95 +136,4 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
         return new RuntimeGeneratedInvokerPrototype(supportedNotification,
             finalClass as Class<? extends org.opendaylight.controller.sal.binding.api.NotificationListener<?>>);
     }
-
-
-
-
-
-    protected def resolveInvokerClass(Class<? extends NotificationListener> class1) {
-        return <RuntimeGeneratedInvokerPrototype>withClassLoaderAndLock(class1.classLoader,lock) [|
-            val invoker = invokerClasses.get(class1);
-            if (invoker !== null) {
-                return invoker;
-            }
-            val newInvoker = generateListenerInvoker(class1);
-            invokerClasses.put(class1, newInvoker);
-            return newInvoker
-
-        ]
-    }
-}
-
-@Data
-package class RuntimeGeneratedInvoker implements NotificationInvoker {
-
-    @Property
-    val NotificationListener delegate;
-
-    @Property
-    var org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> invocationProxy;
-
-    @Property
-    var RuntimeGeneratedInvokerPrototype prototype;
-
-    new(NotificationListener delegate, RuntimeGeneratedInvokerPrototype prototype) {
-        _delegate = delegate;
-        _prototype = prototype;
-        _invocationProxy = prototype.protoClass.newInstance as org.opendaylight.controller.sal.binding.api.NotificationListener<Notification>;
-        RuntimeCodeHelper.setDelegate(_invocationProxy, delegate);
-    }
-
-    override getSupportedNotifications() {
-        prototype.supportedNotifications;
-    }
-
-    override close() {
-    }
-}
-
-@Data
-package class RuntimeGeneratedInvokerPrototype {
-
-    @Property
-    val Set<Class<? extends Notification>> supportedNotifications;
-
-    @Property
-    val Class<? extends org.opendaylight.controller.sal.binding.api.NotificationListener<?>> protoClass;
-}
-
-package class RpcServiceMetadata {
-
-    @Property
-    val contexts = new HashSet<Class<? extends BaseIdentity>>();
-
-    @Property
-    val rpcMethods = new HashMap<String, RpcMetadata>();
-
-    @Property
-    val rpcInputs = new HashMap<Class<? extends DataContainer>, RpcMetadata>();
-
-
-    @Property
-    val supportedInputs = new HashSet<Class<? extends DataContainer>>();
-}
-
-@Data
-package class RpcMetadata {
-
-    @Property
-    val QName qname;
-
-    @Property
-    val String methodName;
-
-    @Property
-    val Class<? extends BaseIdentity> context;
-    @Property
-    val CtMethod inputRouteGetter;
-
-    @Property
-    val boolean routeEncapsulated;
-
-    @Property
-    val CtClass inputType;
 }
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvoker.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvoker.java
new file mode 100644 (file)
index 0000000..8762562
--- /dev/null
@@ -0,0 +1,91 @@
+/**
+ * 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.util.Set;
+
+import org.eclipse.xtext.xbase.lib.util.ToStringHelper;
+import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper;
+import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory.NotificationInvoker;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+
+import com.google.common.base.Preconditions;
+
+final class RuntimeGeneratedInvoker implements NotificationInvoker {
+    private final org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> invocationProxy;
+    private final RuntimeGeneratedInvokerPrototype prototype;
+    private final NotificationListener delegate;
+
+    @SuppressWarnings("unchecked")
+    private RuntimeGeneratedInvoker(final NotificationListener delegate, final RuntimeGeneratedInvokerPrototype prototype, final org.opendaylight.controller.sal.binding.api.NotificationListener<?> proxy) {
+        this.invocationProxy = (org.opendaylight.controller.sal.binding.api.NotificationListener<Notification>) proxy;
+        this.delegate = Preconditions.checkNotNull(delegate);
+        this.prototype = prototype;
+    }
+
+    public static RuntimeGeneratedInvoker create(final NotificationListener delegate, final RuntimeGeneratedInvokerPrototype prototype) throws InstantiationException, IllegalAccessException {
+        final org.opendaylight.controller.sal.binding.api.NotificationListener<?> proxy = Preconditions.checkNotNull(prototype.getProtoClass().newInstance());
+        RuntimeCodeHelper.setDelegate(proxy, delegate);
+        return new RuntimeGeneratedInvoker(delegate, prototype, proxy);
+    }
+
+    @Override
+    public NotificationListener getDelegate() {
+        return delegate;
+    }
+
+    @Override
+    public org.opendaylight.controller.sal.binding.api.NotificationListener<Notification> getInvocationProxy() {
+        return invocationProxy;
+    }
+
+    @Override
+    public Set<Class<? extends Notification>> getSupportedNotifications() {
+        return prototype.getSupportedNotifications();
+    }
+
+    @Override
+    public void close() {
+        // Nothing to do
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + delegate.hashCode();
+        result = prime * result + invocationProxy.hashCode();
+        result = prime * result + prototype.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof RuntimeGeneratedInvoker)) {
+            return false;
+        }
+        final RuntimeGeneratedInvoker other = (RuntimeGeneratedInvoker) obj;
+        if (!delegate.equals(other.delegate)) {
+            return false;
+        }
+        if (!invocationProxy.equals(other.invocationProxy)) {
+            return false;
+        }
+        return prototype.equals(other.prototype);
+    }
+
+    @Override
+    public String toString() {
+        String result = new ToStringHelper().toString(this);
+        return result;
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvokerPrototype.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RuntimeGeneratedInvokerPrototype.java
new file mode 100644 (file)
index 0000000..3172684
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * 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.util.Set;
+
+import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.yangtools.yang.binding.Notification;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+final class RuntimeGeneratedInvokerPrototype {
+    private final Set<Class<? extends Notification>> supportedNotifications;
+    private final Class<? extends NotificationListener<?>> protoClass;
+
+    public RuntimeGeneratedInvokerPrototype(final Set<Class<? extends Notification>> supportedNotifications, final Class<? extends NotificationListener<?>> protoClass) {
+        this.supportedNotifications = Preconditions.checkNotNull(supportedNotifications);
+        this.protoClass = Preconditions.checkNotNull(protoClass);
+    }
+
+    public Set<Class<? extends Notification>> getSupportedNotifications() {
+        return supportedNotifications;
+    }
+
+    public Class<? extends NotificationListener<?>> getProtoClass() {
+        return protoClass;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + supportedNotifications.hashCode();
+        result = prime * result + protoClass.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!(obj instanceof RuntimeGeneratedInvokerPrototype)) {
+            return false;
+        }
+        final RuntimeGeneratedInvokerPrototype other = (RuntimeGeneratedInvokerPrototype) obj;
+        if (!protoClass.equals(other.protoClass)) {
+            return false;
+        }
+        return supportedNotifications.equals(other.supportedNotifications);
+    }
+
+    @Override
+    public String toString() {
+        return Objects.toStringHelper(this)
+                .add("protoClass", protoClass)
+                .add("supportedNotifications", supportedNotifications)
+                .toString();
+    }
+}
index 3ad1dabffe0b39958b65019274b459fae167d8bb..75d44db9d190df195e80381ce2611f50ccd5ef68 100644 (file)
@@ -112,7 +112,7 @@ public class RootBindingAwareBroker implements //
         LOG.info("Starting Binding Aware Broker: {}", identifier);
 
         controllerRoot = new RootSalInstance(getRpcProviderRegistry(), getNotificationBroker(), getDataBroker());
-        
+
 
         supportedConsumerServices = ImmutableClassToInstanceMap.<BindingAwareService> builder()
                 .put(NotificationService.class, getRoot()) //
@@ -144,19 +144,19 @@ public class RootBindingAwareBroker implements //
     public void close() throws Exception {
         // FIXME: Close all sessions
     }
-    
+
     @Override
     public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> type, T implementation)
             throws IllegalStateException {
         return getRoot().addRoutedRpcImplementation(type, implementation);
     }
-    
+
     @Override
     public <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> type, T implementation)
             throws IllegalStateException {
         return getRoot().addRpcImplementation(type, implementation);
     }
-    
+
     @Override
     public <T extends RpcService> T getRpcService(Class<T> module) {
         return getRoot().getRpcService(module);
@@ -166,7 +166,7 @@ public class RootBindingAwareBroker implements //
             L arg0) {
         return getRoot().registerRouteChangeListener(arg0);
     }
-    
+
 
     public class RootSalInstance extends
             AbstractBindingSalProviderInstance<DataProviderService, NotificationProviderService, RpcProviderRegistry> {
index 978c79ea02752b1a6d19e3fbc953dc80e50c011c..bfafc1f9b722e2100b4e327a3050e25b5188914c 100644 (file)
@@ -80,7 +80,7 @@ public class BindingDomConnectorDeployer {
         connector.startDataForwarding();
     }
 
-    public static void startNotificationForwarding(BindingIndependentConnector connector, 
+    public static void startNotificationForwarding(BindingIndependentConnector connector,
             NotificationProviderService baService, NotificationPublishService domService) {
         if(connector.isNotificationForwarding()) {
             return;
index 5bbebe6f1b00544021bb64d5cdf0ea4bf77c82a5..d2472669fa39def5ae4862fb86be2fea5fa7b067 100644 (file)
@@ -83,7 +83,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Function;
-import com.google.common.base.Optional;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSet.Builder;
index e455bea19cdb258e020a454c7e110c1e68707ed4..d28b3b5c9182b031cc0521f3f22d6b52f698c377 100644 (file)
@@ -21,7 +21,7 @@ public class DomForwardingUtils {
         DomForwardedBroker forwardedSource = (DomForwardedBroker) source;
         DomForwardedBroker forwardedTarget = (DomForwardedBroker) target;
         reuseForwardingFrom(forwardedTarget, forwardedSource);
-        
+
     }
 
     private static void reuseForwardingFrom(DomForwardedBroker target, DomForwardedBroker source) {
index b0316635e2f03a981a6bc9ede0485e4df84023d9..97f74ff6f37c86f891e5a95ed0ae0c84dff9dc39 100644 (file)
@@ -7,14 +7,13 @@
  */
 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();
-  }
+    @Override
+    protected DataObject merge(final InstanceIdentifier<? extends DataObject> path, final Iterable<DataObject> data) {
+        return data.iterator().next();
+    }
 }
index e34ee28a316ad0b9229f21382e663ffa0099a743..d22335e66e1cf1d0346272f0a4070b8e57b6fb2f 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.controller.sal.binding.spi;
 
 public interface DelegateProxy<T> {
-    
+
     void setDelegate(T delegate);
     T getDelegate();
 }
index 526ca4059517544938d1331a69abe894b08c67d3..068c68a81f499d0cc4626e63f67caa8e52d50e45 100644 (file)
@@ -12,13 +12,13 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
 public interface RemoteRpcRouter {
 
 
-    
-    
-    
-    
+
+
+
+
     ListenerRegistration<RouteChangeListener> registerRouteChangeListener(RouteChangeListener listener);
 
-    
-    
+
+
 
 }
index 02870c4ef7f29895028abe4a3cbc516f1b59a77d..25c57ccd5f81ebe3860930604127cf793b864ea1 100644 (file)
@@ -89,7 +89,6 @@ public class MultipleAugmentationPutsTest extends AbstractDataServiceTest implem
 
         Nodes nodes = checkForNodes();
         verifyNode(nodes, flowCapableNode).assertHasAugmentation(FlowCapableNode.class);
-        ;
         assertBindingIndependentVersion(NODE_INSTANCE_ID_BI);
 //        Node meterStatsNode = createTestNode(NodeMeterStatistics.class, nodeMeterStatistics());
 //        commitNodeAndVerifyTransaction(meterStatsNode);
index 36a172d09c3f1a99bee21586f9a2b47c75103d9f..9f8a443bbf7e37400683736c64d2a08fad2f13f8 100644 (file)
@@ -19,22 +19,22 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 public class UnionSerializationTest extends AbstractDataServiceTest {
-    
+
     public static final String PREFIX_STRING = "192.168.0.1/32";
-    
-    
+
+
     @Test
     public void testPrefixSerialization() throws Exception {
-        
+
         Ipv4Prefix ipv4prefix = new Ipv4Prefix(PREFIX_STRING);
         IpPrefix ipPrefix = new IpPrefix(ipv4prefix);
         Prefix prefix = new PrefixBuilder().setPrefix(ipPrefix).build();
-        
+
         CompositeNode serialized = testContext.getBindingToDomMappingService().toDataDom(prefix);
         assertNotNull(serialized);
         assertNotNull(serialized.getFirstSimpleByName(Prefix.QNAME));
         assertEquals(PREFIX_STRING, serialized.getFirstSimpleByName(Prefix.QNAME).getValue());
-        
+
         Prefix deserialized = (Prefix) testContext.getBindingToDomMappingService().dataObjectFromDataDom(Prefix.class, serialized);
         assertNotNull(deserialized);
         assertNotNull(deserialized.getPrefix());
index f7c19ba1c3c211397e362eb12f6260cd8d096976..6c133728b67bc73fb888457076b95b20976c534d 100644 (file)
@@ -12,7 +12,7 @@ import org.opendaylight.yangtools.yang.binding.NotificationListener;
 public interface BarListener extends NotificationListener {
 
     void onBarUpdate(BarUpdate notification);
-    
+
     void onFlowDelete(FlowDelete notification);
 
 }
index 3b872d0149b04937fbb2ab9ca1e6c0a1ef93767a..cb8020e3fd4e200f3e06ae4ca4e6fd22faca533a 100644 (file)
@@ -12,5 +12,5 @@ import org.opendaylight.yangtools.yang.binding.NotificationListener;
 public interface FooListener extends NotificationListener {
 
     void onFooUpdate(FooUpdate notification);
-    
+
 }
index e844809662e3b6fb9e22d747fcf016df4fffc4c8..2bd211995d4a74bacabcbc47998b757ebc9bca66 100644 (file)
@@ -13,11 +13,11 @@ import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public interface FooService extends RpcService {
-    
+
     Future<RpcResult<Void>> foo();
-    
+
     Future<RpcResult<Void>> simple(SimpleInput obj);
-    
+
     Future<RpcResult<Void>> inheritedContext(InheritedContextInput obj);
 
 }
index 1480f0c610247f7d9334e6a32bc4f3a00cd1b4f4..6d0226849f3a81a02b143046ea8d092cfd755b5b 100644 (file)
@@ -78,14 +78,14 @@ public class BrokerIntegrationTest extends AbstractDataServiceTest {
 
         /**
          * We create transaction no 2
-         * 
+         *
          */
         DataModificationTransaction removalTransaction = baDataService.beginTransaction();
         assertNotNull(transaction);
 
         /**
          * We remove node 1
-         * 
+         *
          */
         removalTransaction.removeConfigurationData(node1.getValue());
 
index cfdab376516a3db39393a79dd713035db348e9a2..df287791ef01fa53e14c79320c75662e3fb60349 100644 (file)
@@ -114,16 +114,16 @@ public class MessageCapturingFlowService implements SalFlowService, AutoCloseabl
         registration.unregisterPath(context, path);
         return this;
     }
-    
+
     public static MessageCapturingFlowService create() {
         return new MessageCapturingFlowService();
     }
-    
+
     public static MessageCapturingFlowService create(RpcProviderRegistry registry) {
         MessageCapturingFlowService ret = new MessageCapturingFlowService();
         ret.registerTo(registry);
         return ret;
     }
-    
-    
+
+
 }
index b4f51f5771950826ede6d67f37b568106f29f01e..f088c0a0bdde1f29f5ff0bd4054d3b3137ab8f7e 100644 (file)
@@ -14,6 +14,6 @@ import org.opendaylight.yangtools.concepts.Registration;
 public interface RegistrationListener<T extends Registration<?>> extends EventListener {
 
     void onRegister(T registration);
-    
+
     void onUnregister(T registration);
 }
index 1d1d9101ec61c0e403760b6845f80e70de912deb..7744f71888fe0ac6017bea1513962e00915da57e 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.controller.md.sal.common.api.data;
 
-import java.util.concurrent.Future;
-
 import org.opendaylight.yangtools.concepts.Path;
 
 import com.google.common.base.Optional;
index 2ce43b5f7c36d6a4146ed52b922f59b8db330743..82c48d2ddb27e657c12cb9c8f56f49997923b370 100644 (file)
@@ -110,8 +110,10 @@ public interface AsyncWriteTransaction<P extends Path<P>, D>  extends AsyncTrans
      * @param store Identifier of the store, where commit should occur.
      * @return Result of the Commit, containing success information or list of
      *         encountered errors, if commit was not successful. The Future
-     *         blocks until {@link TransactionStatus#COMMITED} or
-     *         {@link TransactionStatus#FAILED} is reached.
+     *         blocks until {@link TransactionStatus#COMMITED} is reached.
+     *         Future will fail with {@link TransactionCommitFailedException}
+     *         if Commit of this transaction failed.
+     *
      * @throws IllegalStateException if the transaction is not {@link TransactionStatus#NEW}
      */
     public ListenableFuture<RpcResult<TransactionStatus>> commit();
index 7d78fd283d169d16cc11510d4b68750ecb5c5733..da7efebdfeb1f7f02eda505d48a1f83be6a79b89 100644 (file)
@@ -16,8 +16,8 @@ import org.opendaylight.yangtools.concepts.Registration;
 public interface DataProvisionService<P extends Path<P> , D> {
 
     public Registration<DataCommitHandler<P, D>> registerCommitHandler(P path, DataCommitHandler<P, D> commitHandler);
-    
-    public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<P, D>>> 
+
+    public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<P, D>>>
         registerCommitHandlerListener(RegistrationListener<DataCommitHandlerRegistration<P, D>> commitHandlerListener);
 
 }
diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionCommitFailedException.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionCommitFailedException.java
new file mode 100644 (file)
index 0000000..f3c2e10
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.api.data;
+
+/**
+ *
+ * Failed commit of asynchronous transaction
+ *
+ * This exception is raised and returned when transaction commit
+ * failed.
+ *
+ */
+public class TransactionCommitFailedException extends Exception {
+
+    private static final long serialVersionUID = -6138306275373237068L;
+
+    protected TransactionCommitFailedException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) {
+        super(message, cause, enableSuppression, writableStackTrace);
+    }
+
+    public TransactionCommitFailedException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+
+    public TransactionCommitFailedException(final String message) {
+        super(message);
+    }
+
+}
index 6a906c5b880df468e7dce19c63e44152089bd568..f5f03a106b36119b188ca489924d514f88b12f00 100644 (file)
@@ -12,6 +12,6 @@ import java.util.concurrent.ExecutorService;
 public interface NotificationPublishService<N> {
 
     void publish(N notification);
-    
+
     void publish(N notification,ExecutorService executor);
 }
index f99c13ecf53499ab6770d9107025cb7f91828b8a..0ecb2c57689d907af476ac1e68cac04b537f8e39 100644 (file)
@@ -11,7 +11,7 @@ import org.opendaylight.yangtools.concepts.Mutable;
 import org.opendaylight.yangtools.concepts.Path;
 
 public interface MutableRoutingTable<C, P extends Path<P>, T> extends RoutingTable<C,P,T>, Mutable {
-    
+
     void setDefaultRoute(T target);
     void updateRoute(P path,T target);
     void removeRoute(P path);
index fbf735fa754e1d6ecba56fc406daeb9cbe97a486..4bfb30f828ed2b0d7eb61ca8951c4063e620bb79 100644 (file)
@@ -12,6 +12,6 @@ import org.opendaylight.yangtools.concepts.Immutable;
 public interface Route<C,P> extends Immutable {
 
     C getType();
-    
+
     P getPath();
 }
index 4402f69a5f73896f8f905c190a7743f3f0b28e80..9e72b68cd63624d65840d19e6eaca4cc5de1260b 100644 (file)
@@ -14,10 +14,10 @@ import org.opendaylight.yangtools.concepts.Path;
 public interface RoutingTable<C, P extends Path<P>, T> {
 
     C getIdentifier();
-    
+
     T getDefaultRoute();
-    
+
     Map<P,T> getRoutes();
-    
+
     T getRoute(P path);
 }
index 9fd9bc80423e88400aaa06651d47fc7e9d8f7b5a..6b387b5a61cd206559e2cb11e43e53e3fe0d9ff5 100644 (file)
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.eclipse.xtend</groupId>
-      <artifactId>org.eclipse.xtend.lib</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-common-api</artifactId>
           </instructions>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.eclipse.xtend</groupId>
-        <artifactId>xtend-maven-plugin</artifactId>
-      </plugin>
     </plugins>
   </build>
   <scm>
index 4d395267dd8db5f59ba65d7802d8eade7184f921..ee9af6cb80d91ccc4083a61e3e6a01604769a757 100644 (file)
@@ -24,7 +24,7 @@ import com.google.common.collect.Multimaps;
 /**
  * Base abstract implementation of DataReadRouter, which performs
  * a read operation on multiple data readers and then merges result.
- * 
+ *
  * @param <P>
  * @param <D>
  */
@@ -50,7 +50,7 @@ public abstract class AbstractDataReadRouter<P extends Path<P>, D> implements Da
 
     /**
      * Merges data readed by reader instances from specified path
-     * 
+     *
      * @param path Path on which read was performed
      * @param data Data which was returned by read operation.
      * @return Merged result.
@@ -59,11 +59,11 @@ public abstract class AbstractDataReadRouter<P extends Path<P>, D> implements Da
 
     /**
      * Returns a function which performs configuration read for supplied path
-     * 
+     *
      * @param path
      * @return function which performs configuration read for supplied path
      */
-    
+
     private Function<DataReader<P, D>, D> configurationRead(final P path) {
         return new Function<DataReader<P, D>, D>() {
             @Override
@@ -75,7 +75,7 @@ public abstract class AbstractDataReadRouter<P extends Path<P>, D> implements Da
 
     /**
      * Returns a function which performs operational read for supplied path
-     * 
+     *
      * @param path
      * @return function which performs operational read for supplied path
      */
@@ -92,10 +92,10 @@ public abstract class AbstractDataReadRouter<P extends Path<P>, D> implements Da
 
     /**
      * Register's a reader for operational data.
-     * 
+     *
      * @param path Path which is served by this reader
      * @param reader Reader instance which is responsible for reading particular subpath.
-     * @return 
+     * @return
      */
     public Registration<DataReader<P, D>> registerOperationalReader(P path, DataReader<P, D> reader) {
         OperationalDataReaderRegistration<P, D> ret = new OperationalDataReaderRegistration<>(path, reader);
@@ -142,15 +142,15 @@ public abstract class AbstractDataReadRouter<P extends Path<P>, D> implements Da
     }
 
     private Predicate<? super Entry<P, DataReaderRegistration<P, D>>> affects(final P path) {
-        
+
         return new Predicate<Entry<P, DataReaderRegistration<P, D>>>() {
-            
+
             @Override
             public boolean apply(Entry<P, DataReaderRegistration<P, D>> input) {
                 final P key = input.getKey();
                 return key.contains(path) || ((P) path).contains(key);
             }
-            
+
         };
     }
 
index 691c30368866963abd9137888a17182ce2b6a035..c86aec96d13ad711870ad0b248695be5bffb1ed6 100644 (file)
@@ -24,9 +24,9 @@ public class DataChangeEventImpl<P extends Path<P>, D> implements DataChangeEven
     private final D updatedOperationalSubtree;
     private final D updatedConfigurationSubtree;
 
-    
-    
-    
+
+
+
     public DataChangeEventImpl(DataChange<P, D> dataChange, D originalConfigurationSubtree,
             D originalOperationalSubtree, D updatedOperationalSubtree, D updatedConfigurationSubtree) {
         super();
index d90442750226fb7f155fded5545db22876084acf..f35d6dc6af29e2780a4d090d44984eb6ec6d3f97 100644 (file)
@@ -28,24 +28,24 @@ public class InitialDataChangeEventImpl<P extends Path<P>,D> implements DataChan
         updatedConfigurationData = Collections.emptyMap();
         updatedOperationalData = Collections.emptyMap();
     }
-    
+
     public InitialDataChangeEventImpl(D configTree, D operTree, Map<P, D> updatedCfgData, Map<P, D> updatedOperData) {
         updatedConfigurationTree = configTree;
         updatedOperationalTree = operTree;
         updatedConfigurationData = updatedCfgData;
         updatedOperationalData = updatedOperData;
     }
-    
+
     @Override
     public Map<P, D> getCreatedConfigurationData() {
         return Collections.emptyMap();
     }
-    
+
     @Override
     public Map<P, D> getCreatedOperationalData() {
         return Collections.emptyMap();
     }
-    
+
     @Override
     public Map<P, D> getOriginalConfigurationData() {
         return Collections.emptyMap();
@@ -66,7 +66,7 @@ public class InitialDataChangeEventImpl<P extends Path<P>,D> implements DataChan
     public Map<P, D> getUpdatedConfigurationData() {
         return updatedConfigurationData;
     }
-    
+
     @Override
     public D getUpdatedConfigurationSubtree() {
         return updatedConfigurationTree;
@@ -75,21 +75,21 @@ public class InitialDataChangeEventImpl<P extends Path<P>,D> implements DataChan
     public D getUpdatedOperationalSubtree() {
         return updatedOperationalTree;
     }
-    
+
     @Override
     public D getOriginalConfigurationSubtree() {
         return updatedConfigurationTree;
     }
-    
+
     @Override
     public D getOriginalOperationalSubtree() {
         return updatedOperationalTree;
     }
-    
+
     @Override
     public Map<P, D> getUpdatedOperationalData() {
         return updatedOperationalData;
     }
-    
+
 
 }
index f7a15b614e26d03877a682b44565c465eb3879e5..daecfdb59ba8243cd8e00650d6cc9da50e639e1b 100644 (file)
@@ -8,13 +8,13 @@
 package org.opendaylight.controller.md.sal.common.impl.util.compat;
 
 public class DataNormalizationException extends Exception {
-       private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-       public DataNormalizationException(String message) {
-               super(message);
-       }
+    public DataNormalizationException(String message) {
+        super(message);
+    }
 
-       public DataNormalizationException(String message, Throwable cause) {
-               super(message, cause);
-       }
+    public DataNormalizationException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }
index 5d73b1eefb3343b43e3547e7d754f0900ab2bb31..1af7ccc79ad2de55b1f26a3b53b11b6b44bfadea 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 public class CommitHandlerTransactions {
 
     private static class AllwaysSuccessfulTransaction<P extends Path<P>,D> implements DataCommitTransaction<P, D> {
-        
+
         private final  DataModification<P, D> modification;
 
         public AllwaysSuccessfulTransaction(DataModification<P, D> modification) {
@@ -32,13 +32,13 @@ public class CommitHandlerTransactions {
         public RpcResult<Void> finish() throws IllegalStateException {
             return Rpcs.<Void>getRpcResult(true, null, Collections.<RpcError>emptyList());
         }
-        
+
         @Override
         public DataModification<P, D> getModification() {
             return modification;
         }
     }
-    
+
     public static final <P extends Path<P>,D> AllwaysSuccessfulTransaction<P, D> allwaysSuccessfulTransaction(DataModification<P, D> modification)  {
         return new AllwaysSuccessfulTransaction<>(modification);
     }
index 86dcba9596debc92e8618518120596ac57fa9279..4d41249b4d5600e7932d9b56dd34bbaaf80f8854 100644 (file)
@@ -16,20 +16,20 @@ import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
  *
  */
 public class RpcErrors {
-    
+
     /**
      * @param applicationTag
      * @param tag
      * @param info
      * @param severity
      * @param message
-     * @param errorType 
-     * @param cause 
+     * @param errorType
+     * @param cause
      * @return {@link RpcError} implementation
      */
     public static RpcError getRpcError(String applicationTag, String tag, String info,
             ErrorSeverity severity, String message, ErrorType errorType, Throwable cause) {
-        RpcErrorTO ret = new RpcErrorTO(applicationTag, tag, info, severity, message, 
+        RpcErrorTO ret = new RpcErrorTO(applicationTag, tag, info, severity, message,
                 errorType, cause);
         return ret;
     }
@@ -94,7 +94,7 @@ public class RpcErrors {
         public Throwable getCause() {
             return cause;
         }
-        
+
         @Override
         public ErrorType getErrorType() {
             return errorType;
index ff9f037f5aeb62883dfc90eb0cd360937b86de65..3894fbe200dba709fae9b297d8313575ee8d34a0 100644 (file)
@@ -7,43 +7,42 @@
  */
 package org.opendaylight.controller.sal.compability;
 
-import org.opendaylight.controller.sal.core.*;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 
 public class ToSalPropertyClassUtils {
     public static Bandwidth salAdvertisedBandwidthFrom(NodeConnector nodeConnector) {
-        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
+        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
         PortFeatures portFeatures = flowCapNodeConn.getAdvertisedFeatures();
         return new AdvertisedBandwidth(resolveBandwidth(portFeatures));
     }
 
     public static Bandwidth salPeerBandwidthFrom(NodeConnector nodeConnector) {
-        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
+        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
         PortFeatures portFeatures = flowCapNodeConn.getPeerFeatures();
         return new PeerBandwidth(resolveBandwidth(portFeatures));
     }
 
     public static Bandwidth salSupportedBandwidthFrom(NodeConnector nodeConnector) {
-        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
+        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
         PortFeatures portFeatures = flowCapNodeConn.getSupported();
         return new SupportedBandwidth(resolveBandwidth(portFeatures));
     }
 
     public static MacAddress salMacAddressFrom(NodeConnector nodeConnector) {
-        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
+        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
         String hwAddress = flowCapNodeConn.getHardwareAddress().getValue();
-        return new MacAddress(bytesFrom(hwAddress));        
+        return new MacAddress(bytesFrom(hwAddress));
     }
-    
-    
+
+
     public static Name salNameFrom(NodeConnector nodeConnector) {
-        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
+        FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
         return new Name(flowCapNodeConn.getName());
     }
-    
-    
+
+
 
     private static byte[] bytesFrom(String hwAddress) {
         String[] mac = hwAddress.split(":");
index a1d573db08240ad4deca1b1f7ddb67bb9e20454c..cf59eb4a9063fbd531749727143927cc26dd47d4 100644 (file)
@@ -53,8 +53,8 @@ public interface BindingAwareRpcRouter extends RpcRouter<String, String, String,
 
         /**
          * Java class name of Rpc Context
-         * 
-         * 
+         *
+         *
          */
         @Override
         public String getContext() {
@@ -63,7 +63,7 @@ public interface BindingAwareRpcRouter extends RpcRouter<String, String, String,
 
         /**
          * String representation of route e.g. node-id
-         * 
+         *
          */
         @Override
         public String getRoute() {
@@ -72,7 +72,7 @@ public interface BindingAwareRpcRouter extends RpcRouter<String, String, String,
 
         /**
          * Java class name of Rpc Type e.g org.opendaylight.AddFlowInput
-         * 
+         *
          */
         @Override
         public String getType() {
index ac7120ffdb1a6c0ea0343529e340fcf8bf4f9028..71d56a7c0eba32828df97f06891bb81c110779dc 100644 (file)
@@ -12,7 +12,7 @@ import java.util.concurrent.Future;
 public class BindingAwareZeroMqRpcRouter implements BindingAwareRpcRouter {
 
     BindingAwareRpcRouter mdSalRouter;
-    
+
     public BindingAwareRpcRouter getMdSalRouter() {
         return mdSalRouter;
     }
@@ -28,10 +28,10 @@ public class BindingAwareZeroMqRpcRouter implements BindingAwareRpcRouter {
         // Write message down to the wire
         return null;
     }
-    
+
     // Receiver part - invoked when request is received and deserialized
     private Future<RpcReply<byte[]>> receivedRequest(RpcRequest<String, String, String, byte[]> input) {
-        
+
         return mdSalRouter.sendRpc(input);
     }
 
index efa24d099f589f77db327ee0f06951237375d599..519d21bf4fe6aea0fd3e0cdeda94132d7ce8b113 100644 (file)
@@ -15,11 +15,11 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
 public interface Connector extends RpcImplementation, NotificationListener {
 
-    
-    
+
+
     Set<InstanceIdentifier> getConfigurationPrefixes();
     Set<InstanceIdentifier> getRuntimePrefixes();
-    
+
     void registerListener(ConnectorListener listener);
     void unregisterListener(ConnectorListener listener);
 }
index f161644f6dccad55fdc7151dc6a898335745af97..fa4c8048fac87e1e218b45d6508f78274b14a75c 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.controller.sal.connector.api;
 import java.util.concurrent.Future;
 
 /**
- * 
+ *
  * @author ttkacik
  *
  * @param <C> Routing Context Identifier
@@ -20,14 +20,14 @@ import java.util.concurrent.Future;
  */
 public interface RpcRouter<C,T,R,D> {
 
-    
-    
+
+
     Future<RpcReply<D>> sendRpc(RpcRequest<C, T, R, D> input);
-    
-    
+
+
     /**
-     * 
-     * @author 
+     *
+     * @author
      *
      * @param <C> Routing Context Identifier
         * @param <R> Route Type
@@ -39,14 +39,14 @@ public interface RpcRouter<C,T,R,D> {
         RouteIdentifier<C,T,R> getRoutingInformation();
         D getPayload();
     }
-    
+
     public interface RouteIdentifier<C,T,R> {
-        
+
         C getContext(); // defines a routing table (e.g. NodeContext)
         T getType(); // rpc type
         R getRoute(); // e.g. (node identity)
     }
-    
+
     public interface RpcReply<D> {
         D getPayload();
     }
index 99a38ca43a5be68fd3c9bad328e20ab98d0578a4..c14d5a679cf8c2f8bcb2172f520273fac160ea50 100644 (file)
@@ -18,9 +18,9 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
 public abstract class AbstractConsumer implements Consumer, BundleActivator,ServiceTrackerCustomizer<Broker, Broker> {
 
-    
-    
-    
+
+
+
     private BundleContext context;
     private ServiceTracker<Broker, Broker> tracker;
     private Broker broker;
@@ -54,7 +54,7 @@ public abstract class AbstractConsumer implements Consumer, BundleActivator,Serv
         return Collections.emptySet();
     }
 
-    
+
     @Override
     public Broker addingService(ServiceReference<Broker> reference) {
         if(broker == null) {
@@ -62,15 +62,15 @@ public abstract class AbstractConsumer implements Consumer, BundleActivator,Serv
             broker.registerConsumer(this, context);
             return broker;
         }
-        
+
         return null;
     }
-    
+
     @Override
     public void modifiedService(ServiceReference<Broker> reference, Broker service) {
         // NOOP
     }
-    
+
     @Override
     public void removedService(ServiceReference<Broker> reference, Broker service) {
         stopImpl(context);
index 72df8cb55348cb08fec5a4bad8d35daa125e2ecf..724cbe75f420e41ccfcfbe041f4b2854e2e1d616 100644 (file)
@@ -11,10 +11,6 @@ import java.util.Set;
 import java.util.concurrent.Future;
 
 import org.opendaylight.controller.md.sal.common.api.routing.RoutedRegistration;
-import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
-import org.opendaylight.controller.sal.core.api.data.DataProviderService;
-import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService;
-import org.opendaylight.controller.sal.core.api.notify.NotificationService;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -39,11 +35,11 @@ import org.osgi.framework.BundleContext;
  * <li>RPC Invocation - see {@link ConsumerSession#rpc(QName, CompositeNode)},
  * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)} and
  * {@link RpcImplementation}
- * <li>Notification Service - see {@link NotificationService} and
- * {@link NotificationPublishService}
+ * <li>Notification Service - see {@link org.opendaylight.controller.sal.core.api.notify.NotificationService} and
+ * {@link org.opendaylight.controller.sal.core.api.notify.NotificationPublishService}
  * <li>Functionality and Data model
- * <li>Data Store access and modification - see {@link DataBrokerService} and
- * {@link DataProviderService}
+ * <li>Data Store access and modification - see {@link org.opendaylight.controller.sal.core.api.data.DataBrokerService} and
+ * {@link org.opendaylight.controller.sal.core.api.data.DataProviderService}
  * </ul>
  *
  * The services are exposed via session.
@@ -227,7 +223,7 @@ public interface Broker {
          * functionality of the provider from the system.
          */
         @Override
-        public void close();
+        void close();
 
         @Override
         boolean isClosed();
@@ -244,7 +240,6 @@ public interface Broker {
         void close();
     }
 
-    public interface RoutedRpcRegistration extends RpcRegistration,
-            RoutedRegistration<QName, InstanceIdentifier, RpcImplementation> {
+    public interface RoutedRpcRegistration extends RpcRegistration, RoutedRegistration<QName, InstanceIdentifier, RpcImplementation> {
     }
 }
index c1518b1ec64757136b42a2cc8f92193c6902beb2..7c00c9c2bbae2a1c229ac79d4b483c33f6327238 100644 (file)
@@ -7,31 +7,29 @@
  */
 package org.opendaylight.controller.sal.core.api;
 
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
-
 /**
- * 
+ *
  * Session-specific instance of the broker functionality.
- * 
+ *
  * <p>
  * BrokerService is marker interface for infrastructure services provided by the
  * SAL. These services are session-specific, each {@link Provider} and
  * {@link Consumer} usually has own instance of the service with it's own
  * context.
- * 
+ *
  * <p>
  * The consumer's (or provider's) instance of specific service could be obtained
- * by invoking {@link ConsumerSession#getService(Class)} method on session
+ * by invoking {@link org.opendaylight.controller.sal.core.api.Broker.ConsumerSession#getService(Class)} method on session
  * assigned to the consumer.
- * 
+ *
  * <p>
  * {@link BrokerService} and {@link Provider} may seem similar, but provider
  * provides YANG model-based functionality and {@link BrokerService} exposes the
  * necessary supporting functionality to implement specific functionality of
  * YANG and to reuse it in the development of {@link Consumer}s and
  * {@link Provider}s.
- * 
- * 
+ *
+ *
  */
 public interface BrokerService {
 
index 3127df521f72547a0567f00f60e07101c247f5dc..a693cd6c49b475bc5f046cbb48c465f37858729f 100644 (file)
@@ -12,26 +12,26 @@ import java.util.Collection;
 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
 
 /**
- * 
+ *
  * Defines the component of controller and supplies additional metadata. A
  * component of the controller or application supplies a concrete implementation
  * of this interface.
- * 
+ *
  * A user-implemented component (application) which facilitates the SAL and SAL
  * services to access infrastructure services or providers' functionality.
- * 
- * 
+ *
+ *
  */
 public interface Consumer {
 
     /**
      * Callback signaling initialization of the consumer session to the SAL.
-     * 
+     *
      * The consumer MUST use the session for all communication with SAL or
      * retrieving SAL infrastructure services.
-     * 
+     *
      * This method is invoked by {@link Broker#registerConsumer(Consumer)}
-     * 
+     *
      * @param session
      *            Unique session between consumer and SAL.
      */
@@ -40,9 +40,9 @@ public interface Consumer {
     /**
      * Get a set of implementations of consumer functionality to be registered
      * into system during the consumer registration to the SAL.
-     * 
+     *
      * This method is invoked by {@link Broker#registerConsumer(Consumer)}.
-     * 
+     *
      * @return Set of consumer functionality.
      */
     public Collection<ConsumerFunctionality> getConsumerFunctionality();
@@ -50,8 +50,8 @@ public interface Consumer {
     /**
      * The marker interface for the interfaces describing the consumer
      * functionality contracts.
-     * 
-     * 
+     *
+     *
      */
     public interface ConsumerFunctionality {
 
index fef8618b2c450d4a4a6f095d35d7939d2edfd70e..0a57d12579239ae29e9fff251651db8483f1ee16 100644 (file)
@@ -12,30 +12,30 @@ import java.util.Collection;
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 
 /**
- * 
+ *
  * Defines the component of controller and supplies additional metadata. A
  * component of the controller or application supplies a concrete implementation
  * of this interface.
- * 
+ *
  * <p>
  * A user-implemented component (application) which facilitates the SAL and SAL
  * services to access infrastructure services and to provide functionality to
  * {@link Consumer}s and other providers.
- * 
- * 
+ *
+ *
  */
 public interface Provider {
 
     /**
      * Callback signaling initialization of the provider session to the SAL.
-     * 
+     *
      * <p>
      * The provider <b>MUST use the session</b> for all communication with SAL
      * or retrieving SAL infrastructure services.
-     * 
+     *
      * <p>
      * This method is invoked by {@link Broker#registerConsumer(Consumer)}
-     * 
+     *
      * @param session
      *            Unique session between provider and SAL.
      */
@@ -44,24 +44,24 @@ public interface Provider {
     /**
      * Gets a set of implementations of provider functionality to be registered
      * into system during the provider registration to the SAL.
-     * 
+     *
      * <p>
      * This method is invoked by {@link Broker#registerProvider(Provider)} to
      * learn the initial provided functionality
-     * 
+     *
      * @return Set of provider's functionality.
      */
     public Collection<ProviderFunctionality> getProviderFunctionality();
 
     /**
      * Functionality provided by the {@link Provider}
-     * 
+     *
      * <p>
      * Marker interface used to mark the interfaces describing specific
      * functionality which could be exposed by providers to other components.
-     * 
+     *
 
-     * 
+     *
      */
     public interface ProviderFunctionality {
 
index 665a50f9ca2881690a05a29a3779a974ce0b6ac9..da592e9b22689704b393f6b2f7d4b9588ddb9bed 100644 (file)
@@ -16,7 +16,7 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 public interface RpcConsumptionRegistry {
     /**
      * Sends an RPC to other components registered to the broker.
-     * 
+     *
      * @see RpcImplementation
      * @param rpc
      *            Name of RPC
index 38b33d5d2a509f228a3fcc88a28c3b4f64a11dad..d14910055b6a8ff2f72805599588060dc7f663c6 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.controller.sal.core.api;
 
 import java.util.Set;
 
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
@@ -29,14 +27,14 @@ import com.google.common.util.concurrent.ListenableFuture;
  * {@link Provider#getProviderFunctionality()}
  * <li>passing an instance of implementation and {@link QName} of rpc as
  * arguments to the
- * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}
+ * {@link org.opendaylight.controller.sal.core.api.Broker.ProviderSession#addRpcImplementation(QName, RpcImplementation)}
  * </ul>
  *
  * The simplified process of the invocation of rpc is following:
  *
  * <ol>
  * <li> {@link Consumer} invokes
- * {@link ConsumerSession#rpc(QName, CompositeNode)}
+ * {@link org.opendaylight.controller.sal.core.api.Broker.ConsumerSession#rpc(QName, CompositeNode)}
  * <li> {@link Broker} finds registered {@link RpcImplementation}s
  * <li> {@link Broker} invokes
  * {@link RpcImplementation#invokeRpc(QName, CompositeNode)}
index f43dcd6b43565692136eda0eecac5354b29681ac..a22a6ef75e6be7d25461071b1c8290d1a13c0be4 100644 (file)
@@ -18,17 +18,17 @@ public interface RpcProvisionRegistry extends RpcImplementation, BrokerService,
 
     /**
      * Registers an implementation of the rpc.
-     * 
+     *
      * <p>
      * The registered rpc functionality will be available to all other
      * consumers and providers registered to the broker, which are aware of
      * the {@link QName} assigned to the rpc.
-     * 
+     *
      * <p>
      * There is no assumption that rpc type is in the set returned by
      * invoking {@link RpcImplementation#getSupportedRpcs()}. This allows
      * for dynamic rpc implementations.
-     * 
+     *
      * @param rpcType
      *            Name of Rpc
      * @param implementation
@@ -38,7 +38,7 @@ public interface RpcProvisionRegistry extends RpcImplementation, BrokerService,
      */
     RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation)
             throws IllegalArgumentException;
-    
+
     ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener);
 
     RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation);
index 2ba5c4ba20377323f165542301d97153135df17b..a0be886b24d7c10e892c598c4e8072fea7835a81 100644 (file)
@@ -12,8 +12,8 @@ import java.util.EventListener;
 import org.opendaylight.yangtools.yang.common.QName;
 
 public interface RpcRegistrationListener extends EventListener {
-    
+
     public void onRpcImplementationAdded(QName name);
-    
+
     public void onRpcImplementationRemoved(QName name);
 }
index 64195303e80b1ab6883acef8d12bd8c7940b501a..66d290f531aa41f5346d970c92bba1963094f28f 100644 (file)
@@ -15,20 +15,20 @@ import org.opendaylight.yangtools.yang.common.QName;
 public class RpcRoutingContext implements Immutable, Serializable {
 
     /**
-     * 
+     *
      */
     private static final long serialVersionUID = -9079324728075883325L;
-    
+
     private final QName context;
     private final QName rpc;
-    
-    
+
+
     private RpcRoutingContext(QName context, QName rpc) {
         super();
         this.context = context;
         this.rpc = rpc;
     }
-    
+
     public static final RpcRoutingContext create(QName context, QName rpc) {
         return new RpcRoutingContext(context, rpc);
     }
index 2d5f4b2a550d0c6412a3fe3ac604baef7d2d4656..266b6976afbde367ecca294a90023253d903b0ff 100644 (file)
@@ -18,12 +18,12 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 /**
  * DataBrokerService provides unified access to the data stores available in the
  * system.
- * 
- * 
+ *
+ *
  * @see DataProviderService
- * 
+ *
  */
-public interface DataBrokerService extends 
+public interface DataBrokerService extends
     BrokerService, //
     DataReader<InstanceIdentifier, CompositeNode>, //
     DataModificationTransactionFactory<InstanceIdentifier, CompositeNode>, //
index 20fa29dceb7cd807ca78c2650d357f5a30bb0cb1..0538660fd79eea473d705ae588ce83035683941e 100644 (file)
@@ -15,14 +15,14 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;;
 
-public interface DataProviderService extends 
+public interface DataProviderService extends
     DataBrokerService, //
     DataProvisionService<InstanceIdentifier, CompositeNode>
     {
 
     /**
      * Adds {@link DataValidator} for specified Data Store
-     * 
+     *
      * @param store
      *            Data Store
      * @param validator
@@ -32,7 +32,7 @@ public interface DataProviderService extends
 
     /**
      * Removes {@link DataValidator} from specified Data Store
-     * 
+     *
      * @param store
      * @param validator
      *            Validator
@@ -42,7 +42,7 @@ public interface DataProviderService extends
 
     /**
      * Adds {@link DataRefresher} for specified data store
-     * 
+     *
      * @param store
      * @param refresher
      */
@@ -50,22 +50,22 @@ public interface DataProviderService extends
 
     /**
      * Removes {@link DataRefresher} from specified data store
-     * 
+     *
      * @param store
      * @param refresher
      */
     void removeRefresher(DataStoreIdentifier store, DataRefresher refresher);
 
-    
+
     Registration<DataReader<InstanceIdentifier, CompositeNode>> registerConfigurationReader(InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader);
 
     Registration<DataReader<InstanceIdentifier, CompositeNode>> registerOperationalReader(InstanceIdentifier path, DataReader<InstanceIdentifier, CompositeNode> reader);
-    
+
     public interface DataRefresher extends Provider.ProviderFunctionality {
 
         /**
          * Fired when some component explicitly requested the data refresh.
-         * 
+         *
          * The provider which exposed the {@link DataRefresher} should republish
          * its provided data by editing the data in all affected data stores.
          */
index 8bdd0618716558494ed7bcacec5214bfb886d34e..58ffb38365c0d6673fa10ef9f1ccd229cdb26bcd 100644 (file)
@@ -15,11 +15,11 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 public interface DataStore extends //
     DataReader<InstanceIdentifier, CompositeNode>,
     DataCommitHandler<InstanceIdentifier, CompositeNode> {
-    
-    
+
+
     Iterable<InstanceIdentifier> getStoredConfigurationPaths();
     Iterable<InstanceIdentifier> getStoredOperationalPaths();
-    
+
     boolean containsConfigurationPath(InstanceIdentifier path);
     boolean containsOperationalPath(InstanceIdentifier path);
 
index 2bcb84be34f375486f4791dab794ff58d168c4d7..286770b0482d36d600f9f2eeebe5ed24cf928a43 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 /**
  * {@link Provider}-supplied Validator of the data.
- * 
+ *
  * <p>
  * The registration could be done by :
  * <ul>
@@ -27,25 +27,25 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
  * as arguments to the
  * {@link DataProviderService#addValidator(DataStoreIdentifier, DataValidator)}
  * </ul>
- * 
+ *
  **/
 public interface DataValidator extends Provider.ProviderFunctionality {
 
     /**
      * A set of Data Stores supported by implementation.
-     * 
+     *
      * The set of {@link DataStoreIdentifier}s which identifies target data
      * stores which are supported by this implementation. This set is used, when
      * {@link Provider} is registered to the SAL, to register and expose the
      * validation functionality to affected data stores.
-     * 
+     *
      * @return Set of Data Store identifiers
      */
     Set<DataStoreIdentifier> getSupportedDataStores();
 
     /**
      * Performs validation on supplied data.
-     * 
+     *
      * @param toValidate
      *            Data to validate
      * @return Validation result. The
index f87fee5bce27732ee71b482d4fc9251ed2e68536..7dc8cb36c5b266c20f3521efc16e93ba3676553f 100644 (file)
@@ -21,21 +21,21 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 public interface NotificationListener extends Consumer.ConsumerFunctionality, EventListener {
     /**
      * A set of notification types supported by listeners.
-     * 
+     *
      * The set of notification {@link QName}s which are supported by this
      * listener. This set is used, when {@link Consumer} is registered to the
      * SAL, to automatically register the listener.
-     * 
+     *
      * @return Set of QNames identifying supported notifications.
      */
     Set<QName> getSupportedNotifications();
 
     /**
      * Fired when the notification occurs.
-     * 
+     *
      * The type of the notification could be learned by
      * <code>QName type = notification.getNodeType();</code>
-     * 
+     *
      * @param notification
      *            Notification content
      */
index aa22b90f65478092374d53d06961e6c09f5fbcd7..f1156c39642af935a0d0a88d5d4d55bc6f40077f 100644 (file)
@@ -7,32 +7,30 @@
  */
 package org.opendaylight.controller.sal.core.api.notify;
 
-import org.opendaylight.controller.sal.core.api.Broker;
-import org.opendaylight.controller.sal.core.api.Provider;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 /**
  * Notification Publishing Service
- * 
+ *
  * The simplified process of the notification publishing is following:
- * 
+ *
  * <ol>
- * <li> {@link Provider} invokes {@link #sendNotification(CompositeNode)}
- * <li> {@link Broker} finds {@link NotificationListener}s which subscribed for
+ * <li> {@link org.opendaylight.controller.sal.core.api.Provider} invokes {@link #sendNotification(CompositeNode)}
+ * <li> {@link org.opendaylight.controller.sal.core.api.Broker} finds {@link NotificationListener}s which subscribed for
  * the notification type.
- * 
- * <li>For each subscriber {@link Broker} invokes
+ *
+ * <li>For each subscriber {@link org.opendaylight.controller.sal.core.api.Broker} invokes
  * {@link NotificationListener#onNotification(CompositeNode)}
  * </ol>
  */
 public interface NotificationPublishService extends NotificationService {
     /**
      * Publishes a notification.
-     * 
+     *
      * Notification type is determined by the
      * {@link CompositeNode#getNodeType()} of the
      * <code>notification<code> parameter.
-     * 
+     *
      * @param notification
      *            Notification to publish
      */
index f654ca9ad6c87ee3c9e0c4b5bcb58ab0004d0708..1d67ca08241af4489c9582fdb5e39a576f67afca 100644 (file)
@@ -8,9 +8,6 @@
 package org.opendaylight.controller.sal.core.api.notify;
 
 import org.opendaylight.controller.sal.core.api.BrokerService;
-import org.opendaylight.controller.sal.core.api.Provider;
-import org.opendaylight.controller.sal.core.api.RpcImplementation;
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.opendaylight.yangtools.yang.common.QName;
 
@@ -18,26 +15,26 @@ import org.opendaylight.yangtools.yang.common.QName;
 /**
  * NotificationService provides access to the notification functionality of the
  * SAL.
- * 
+ *
  * NotificationService allows for consumption of notifications by registering
  * implementations of NotificationListener.
- * 
+ *
  * The registration of notification listeners could be done by:
  * <ul>
  * <li>returning an instance of implementation in the return value of
- * {@link Provider#getProviderFunctionality()}
- * <li>passing an instance of implementation and {@link QName} of rpc as an
- * arguments to the
- * {@link ProviderSession#addRpcImplementation(QName, RpcImplementation)}
+ * {@link org.opendaylight.controller.sal.core.api.Provider#getProviderFunctionality()}
+ * <li>passing an instance of implementation and {@link QName} of an RPC as an
+ * argument to
+ * {@link org.opendaylight.controller.sal.core.api.Broker.ProviderSession#addRpcImplementation(QName, org.opendaylight.controller.sal.core.api.RpcImplementation)}
  * </ul>
- * 
- * 
+ *
+ *
  */
 public interface NotificationService extends BrokerService {
 
     /**
      * Registers a notification listener for supplied notification type.
-     * 
+     *
      * @param notification
      * @param listener
      */
index 692a0babdfcaaa43d2601fc1f065dee1dcaa45b3..8e2a11184c973504c7784b8c748a9cf7a347937c 100644 (file)
@@ -14,13 +14,13 @@ import org.opendaylight.controller.sal.dom.broker.DataBrokerImpl;
 
 public class DomBrokerRuntimeMXBeanImpl implements
         DomBrokerImplRuntimeMXBean {
-    
+
     private final DataBrokerImpl dataService;
     private final Transactions transactions = new Transactions();
     private final Data data = new Data();
-    
+
     public DomBrokerRuntimeMXBeanImpl(DataBrokerImpl dataService) {
-        this.dataService = dataService; 
+        this.dataService = dataService;
     }
 
     public Transactions getTransactions() {
index 2495146aa64d290460ab83c1c681a781e760f720..10b838a2c6122a2d8e629f7ce02f3698fe90703c 100644 (file)
@@ -13,6 +13,8 @@ import java.util.Collections;
 import java.util.concurrent.Callable;
 import java.util.concurrent.atomic.AtomicLong;
 
+import javax.annotation.concurrent.GuardedBy;
+
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
 import org.opendaylight.controller.md.sal.dom.store.impl.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
@@ -41,6 +43,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.ListeningExecutorService;
@@ -48,13 +51,14 @@ import com.google.common.util.concurrent.ListeningExecutorService;
 /**
  * In-memory DOM Data Store
  *
- * Implementation of {@link DOMStore} which uses {@link DataTree}
- * and other classes such as {@link SnapshotBackedWriteTransaction}.
+ * Implementation of {@link DOMStore} which uses {@link DataTree} and other
+ * classes such as {@link SnapshotBackedWriteTransaction}.
  * {@link SnapshotBackedReadTransaction} and {@link ResolveDataChangeEventsTask}
  * to implement {@link DOMStore} contract.
  *
  */
-public class InMemoryDOMDataStore implements DOMStore, Identifiable<String>, SchemaContextListener, TransactionReadyPrototype {
+public class InMemoryDOMDataStore implements DOMStore, Identifiable<String>, SchemaContextListener,
+        TransactionReadyPrototype {
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataStore.class);
     private final DataTree dataTree = InMemoryDataTreeFactory.getInstance().create();
     private final ListenerTree listenerTree = ListenerTree.create();
@@ -148,14 +152,22 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable<String>, Sch
 
     private class DOMStoreTransactionChainImpl implements DOMStoreTransactionChain, TransactionReadyPrototype {
 
-        private SnapshotBackedWriteTransaction previousOutstandingTx;
+        @GuardedBy("this")
+        private SnapshotBackedWriteTransaction latestOutstandingTx;
+
+        private boolean chainFailed = false;
+
+        private void checkFailed() {
+            Preconditions.checkState(!chainFailed, "Transaction chain is failed.");
+        }
 
         @Override
         public synchronized DOMStoreReadTransaction newReadOnlyTransaction() {
             final DataTreeSnapshot snapshot;
-            if(previousOutstandingTx != null) {
-                checkState(previousOutstandingTx.isReady(), "Previous transaction in chain must be ready.");
-                snapshot = previousOutstandingTx.getMutatedView();
+            checkFailed();
+            if (latestOutstandingTx != null) {
+                checkState(latestOutstandingTx.isReady(), "Previous transaction in chain must be ready.");
+                snapshot = latestOutstandingTx.getMutatedView();
             } else {
                 snapshot = dataTree.takeSnapshot();
             }
@@ -165,42 +177,112 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable<String>, Sch
         @Override
         public synchronized DOMStoreReadWriteTransaction newReadWriteTransaction() {
             final DataTreeSnapshot snapshot;
-            if(previousOutstandingTx != null) {
-                checkState(previousOutstandingTx.isReady(), "Previous transaction in chain must be ready.");
-                snapshot = previousOutstandingTx.getMutatedView();
+            checkFailed();
+            if (latestOutstandingTx != null) {
+                checkState(latestOutstandingTx.isReady(), "Previous transaction in chain must be ready.");
+                snapshot = latestOutstandingTx.getMutatedView();
             } else {
-                snapshot = dataTree.takeSnapshot().newModification();
+                snapshot = dataTree.takeSnapshot();
             }
-            SnapshotBackedReadWriteTransaction ret = new SnapshotBackedReadWriteTransaction(nextIdentifier(), snapshot,this);
+            final SnapshotBackedReadWriteTransaction ret = new SnapshotBackedReadWriteTransaction(nextIdentifier(),
+                    snapshot, this);
+            latestOutstandingTx = ret;
             return ret;
         }
 
         @Override
         public synchronized DOMStoreWriteTransaction newWriteOnlyTransaction() {
             final DataTreeSnapshot snapshot;
-            if(previousOutstandingTx != null) {
-                checkState(previousOutstandingTx.isReady(), "Previous transaction in chain must be ready.");
-                snapshot = previousOutstandingTx.getMutatedView();
+            checkFailed();
+            if (latestOutstandingTx != null) {
+                checkState(latestOutstandingTx.isReady(), "Previous transaction in chain must be ready.");
+                snapshot = latestOutstandingTx.getMutatedView();
             } else {
-                snapshot = dataTree.takeSnapshot().newModification();
+                snapshot = dataTree.takeSnapshot();
             }
-            SnapshotBackedWriteTransaction ret =new SnapshotBackedWriteTransaction(nextIdentifier(), snapshot,this);
+            final SnapshotBackedWriteTransaction ret = new SnapshotBackedWriteTransaction(nextIdentifier(), snapshot,
+                    this);
+            latestOutstandingTx = ret;
             return ret;
         }
 
         @Override
         public DOMStoreThreePhaseCommitCohort ready(final SnapshotBackedWriteTransaction tx) {
             DOMStoreThreePhaseCommitCohort storeCohort = InMemoryDOMDataStore.this.ready(tx);
-            // FIXME: We probably want to add Transaction Chain cohort
-            return storeCohort;
+            return new ChainedTransactionCommitImpl(tx, storeCohort, this);
         }
 
         @Override
         public void close() {
-            // TODO Auto-generated method stub
 
         }
 
+        protected synchronized void onTransactionFailed(final SnapshotBackedWriteTransaction transaction,
+                final Throwable t) {
+            chainFailed = true;
+
+        }
+
+        public synchronized void onTransactionCommited(final SnapshotBackedWriteTransaction transaction) {
+            // If commited transaction is latestOutstandingTx we clear
+            // latestOutstandingTx
+            // field in order to base new transactions on Datastore Data Tree
+            // directly.
+            if (transaction.equals(latestOutstandingTx)) {
+                latestOutstandingTx = null;
+            }
+        }
+
+    }
+
+    private static class ChainedTransactionCommitImpl implements DOMStoreThreePhaseCommitCohort {
+
+        private final SnapshotBackedWriteTransaction transaction;
+        private final DOMStoreThreePhaseCommitCohort delegate;
+
+        private final DOMStoreTransactionChainImpl txChain;
+
+        protected ChainedTransactionCommitImpl(final SnapshotBackedWriteTransaction transaction,
+                final DOMStoreThreePhaseCommitCohort delegate, final DOMStoreTransactionChainImpl txChain) {
+            super();
+            this.transaction = transaction;
+            this.delegate = delegate;
+            this.txChain = txChain;
+        }
+
+        @Override
+        public ListenableFuture<Boolean> canCommit() {
+            return delegate.canCommit();
+        }
+
+        @Override
+        public ListenableFuture<Void> preCommit() {
+            return delegate.preCommit();
+        }
+
+        @Override
+        public ListenableFuture<Void> abort() {
+            return delegate.abort();
+        }
+
+        @Override
+        public ListenableFuture<Void> commit() {
+            ListenableFuture<Void> commitFuture = delegate.commit();
+            Futures.addCallback(commitFuture, new FutureCallback<Void>() {
+                @Override
+                public void onFailure(final Throwable t) {
+                    txChain.onTransactionFailed(transaction, t);
+                }
+
+                @Override
+                public void onSuccess(final Void result) {
+                    txChain.onTransactionCommited(transaction);
+                }
+
+            });
+            return commitFuture;
+        }
+
     }
 
     private class ThreePhaseCommitImpl implements DOMStoreThreePhaseCommitCohort {
@@ -226,7 +308,8 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable<String>, Sch
                         LOG.debug("Store Transaction: {} can be committed", transaction.getIdentifier());
                         return true;
                     } catch (DataPreconditionFailedException e) {
-                        LOG.warn("Store Tx: {} Data Precondition failed for {}.",transaction.getIdentifier(),e.getPath(),e);
+                        LOG.warn("Store Tx: {} Data Precondition failed for {}.", transaction.getIdentifier(),
+                                e.getPath(), e);
                         return false;
                     }
                 }
index 717fb11987b8a1754581123687555fa1b2b701e4..534ee64b8af9b77591a1b20a5d63f2985cc332e1 100644 (file)
@@ -26,7 +26,7 @@ import com.google.common.base.Throwables;
  * Implementation of Write transaction which is backed by
  * {@link DataTreeSnapshot} and executed according to
  * {@link TransactionReadyPrototype}.
- * 
+ *
  */
 class SnapshotBackedWriteTransaction extends AbstractDOMStoreTransaction implements DOMStoreWriteTransaction {
 
@@ -37,7 +37,7 @@ class SnapshotBackedWriteTransaction extends AbstractDOMStoreTransaction impleme
 
     /**
      * Creates new write-only transaction.
-     * 
+     *
      * @param identifier
      *            transaction Identifier
      * @param snapshot
@@ -140,19 +140,19 @@ class SnapshotBackedWriteTransaction extends AbstractDOMStoreTransaction impleme
     /**
      * Prototype implementation of
      * {@link #ready(SnapshotBackedWriteTransaction)}
-     * 
+     *
      * This class is intended to be implemented by Transaction factories
      * responsible for allocation of {@link SnapshotBackedWriteTransaction} and
      * providing underlying logic for applying implementation.
-     * 
+     *
      */
     public static interface TransactionReadyPrototype {
 
         /**
          * Returns a commit coordinator associated with supplied transactions.
-         * 
+         *
          * This call must not fail.
-         * 
+         *
          * @param tx
          *            Transaction on which ready was invoked.
          * @return DOMStoreThreePhaseCommitCohort associated with transaction
index 7422c116ef0484e72ce182024a76cff51ef56c5c..c6dd25c76bae32d8bad58980577841b8ad051484 100644 (file)
@@ -11,10 +11,10 @@ package org.opendaylight.controller.md.sal.dom.store.impl.tree;
  * Factory interface for creating data trees.
  */
 public interface DataTreeFactory {
-       /**
-        * Create a new data tree.
-        *
-        * @return A data tree instance.
-        */
-       DataTree create();
+    /**
+     * Create a new data tree.
+     *
+     * @return A data tree instance.
+     */
+    DataTree create();
 }
index 99982d318cf5487699d2db60549e4ee194ed0540..fe98468b5cf370b4dddb003aeb04ee308382d58c 100644 (file)
@@ -13,7 +13,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 
@@ -23,7 +22,7 @@ import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 
 /**
- * A set of utility methods for interacting with {@link TreeNode} objects.
+ * A set of utility methods for interacting with {@link org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.TreeNode} objects.
  */
 public final class TreeNodeUtils {
     private TreeNodeUtils() {
index f7e95b84bd4df38c214c32f10c1b01df61fb4798..39ff4f0aa03f9b0ad1d3ccdce080b4cf7c7989a2 100644 (file)
@@ -12,6 +12,7 @@ import java.util.Map.Entry;
 import javax.annotation.concurrent.GuardedBy;
 
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataTreeModification;
+import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationType;
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.TreeNodeUtils;
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
@@ -151,7 +152,27 @@ final class InMemoryDataTreeModification implements DataTreeModification {
     public synchronized DataTreeModification newModification() {
         Preconditions.checkState(sealed, "Attempted to chain on an unsealed modification");
 
-        // FIXME: transaction chaining
-        throw new UnsupportedOperationException("Implement this as part of transaction chaining");
+        if(rootNode.getType() == ModificationType.UNMODIFIED) {
+            return snapshot.newModification();
+        }
+
+        /*
+         *  FIXME: Add advanced transaction chaining for modification of not rebased
+         *  modification.
+         *
+         *  Current computation of tempRoot may yeld incorrect subtree versions
+         *  if there are multiple concurrent transactions, which may break
+         *  versioning preconditions for modification of previously occured write,
+         *  directly nested under parent node, since node version is derived from
+         *  subtree version.
+         *
+         *  For deeper nodes subtree version is derived from their respective metadata
+         *  nodes, so this incorrect root subtree version is not affecting us.
+         */
+        TreeNode originalSnapshotRoot = snapshot.getRootNode();
+        Optional<TreeNode> tempRoot = strategyTree.apply(rootNode, Optional.of(originalSnapshotRoot), originalSnapshotRoot.getSubtreeVersion().next());
+
+        InMemoryDataTreeSnapshot tempTree = new InMemoryDataTreeSnapshot(snapshot.getSchemaContext(), tempRoot.get(), strategyTree);
+        return tempTree.newModification();
     }
 }
index 7f834351d3e20bd59b0a72e2ce2c46672c1b7e2e..3291afa0616908b6e1512679141b990e1fad77bf 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
index ba3dcc8c866f833fe18cb1ebe9e32061a947f521..69f518bb32f5c57f467285f0a32056240893043b 100644 (file)
@@ -27,16 +27,16 @@ public class DataBrokerImpl extends AbstractDataBroker<InstanceIdentifier, Compo
 
     private AtomicLong nextTransaction = new AtomicLong();
     private final AtomicLong createdTransactionsCount = new AtomicLong();
-    
+
     public DataBrokerImpl() {
         setDataReadRouter(new DataReaderRouter());
         setExecutor(MoreExecutors.sameThreadExecutor());
     }
-    
+
     public AtomicLong getCreatedTransactionsCount() {
         return createdTransactionsCount;
     }
-    
+
     @Override
     public DataTransactionImpl beginTransaction() {
         String transactionId = "DOM-" + nextTransaction.getAndIncrement();
@@ -83,7 +83,7 @@ public class DataBrokerImpl extends AbstractDataBroker<InstanceIdentifier, Compo
 
     @Override
     public void close() throws Exception {
-        
+
     }
 
 }
index 39008b48f169fe3901f90de3eb31216da90849a5..65aa99deea9e70b62a0a86d6b108a10048ea1a30 100644 (file)
@@ -15,12 +15,12 @@ import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
-public class DataTransactionImpl extends AbstractDataTransaction<InstanceIdentifier, CompositeNode> 
+public class DataTransactionImpl extends AbstractDataTransaction<InstanceIdentifier, CompositeNode>
     implements DataModificationTransaction {
     private final ListenerRegistry<DataTransactionListener> listeners = new ListenerRegistry<DataTransactionListener>();
-    
-    
-    
+
+
+
     public DataTransactionImpl(Object identifier,DataBrokerImpl dataBroker) {
         super(identifier,dataBroker);
     }
index a2c43d0c73ba402f13bd7b604a9629b617637732..8fc6fe229500ecc39506fcc5b215b82cfdd9cb5e 100644 (file)
@@ -229,7 +229,6 @@ public class SchemaAwareRpcBroker implements RpcRouter, Identifiable<String>, Ro
             if (CONTEXT_REFERENCE.equals(extension.getNodeType())) {
                 return Optional.fromNullable(extension.getQName());
             }
-            ;
         }
         return Optional.absent();
     }
index cfaf481e721361b605f50d2b7a8a34cb50ac072b..853e3e391f591a8b3d6c5aad72d5d62da0093471 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.controller.sal.dom.broker.osgi;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -14,14 +17,13 @@ import java.util.Set;
 import org.opendaylight.controller.sal.core.api.BrokerService;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.osgi.framework.ServiceReference;
-import static com.google.common.base.Preconditions.*;
 
 public abstract class AbstractBrokerServiceProxy<T extends BrokerService> implements AutoCloseable, BrokerService {
 
     private T delegate;
     private final ServiceReference<T> reference;
 
-    public AbstractBrokerServiceProxy(ServiceReference<T> ref, T delegate) {
+    public AbstractBrokerServiceProxy(final ServiceReference<T> ref, final T delegate) {
         this.delegate = checkNotNull(delegate, "Delegate should not be null.");
         this.reference = checkNotNull(ref, "Reference should not be null.");
     }
@@ -35,9 +37,9 @@ public abstract class AbstractBrokerServiceProxy<T extends BrokerService> implem
         return reference;
     }
 
-    private Set<Registration<?>> registrations = Collections.synchronizedSet(new HashSet<Registration<?>>());
+    private final Set<Registration<?>> registrations = Collections.synchronizedSet(new HashSet<Registration<?>>());
 
-    protected <R extends Registration<?>> R addRegistration(R registration) {
+    protected <R extends Registration<?>> R addRegistration(final R registration) {
         if (registration != null) {
             registrations.add(registration);
         }
index 5839db46ca745bc8ac6da65c852cca6796ea7395..30027ec929b2529d366de9c7fd5c6d0fe25f5d7d 100644 (file)
@@ -37,6 +37,6 @@ public class DataBrokerServiceProxy extends AbstractBrokerServiceProxy<DataBroke
     public DataModificationTransaction beginTransaction() {
         return getDelegate().beginTransaction();
     }
-    
-    
+
+
 }
index 1793c53a56546b7262a6ba12d6fad8d9d7252919..caae2971f8bf8eaba5cc392f7252aa123c086fa4 100644 (file)
@@ -83,7 +83,7 @@ public class DataProviderServiceProxy extends AbstractBrokerServiceProxy<DataPro
     public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
         getDelegate().removeValidator(store, validator);
     }
-    
+
     @Override
     public ListenerRegistration<RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>>> registerCommitHandlerListener(
             RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier, CompositeNode>> commitHandlerListener) {
index 6e44cba494eda0d29d333ba89492aea18cba55f6..7193a5317709e1b3494eef90bd563b628b6dadec 100644 (file)
@@ -11,7 +11,12 @@ 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.controller.sal.core.api.Broker;
+import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation;
+import org.opendaylight.controller.sal.core.api.RpcImplementation;
+import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
+import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
+import org.opendaylight.controller.sal.core.api.RpcRoutingContext;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -21,35 +26,34 @@ import org.osgi.framework.ServiceReference;
 
 import com.google.common.util.concurrent.ListenableFuture;
 
-public class RpcProvisionRegistryProxy extends AbstractBrokerServiceProxy<RpcProvisionRegistry>
-                                       implements RpcProvisionRegistry {
+public class RpcProvisionRegistryProxy extends AbstractBrokerServiceProxy<RpcProvisionRegistry> implements RpcProvisionRegistry {
 
-    public RpcProvisionRegistryProxy(ServiceReference<RpcProvisionRegistry> ref, RpcProvisionRegistry delegate) {
+    public RpcProvisionRegistryProxy(final ServiceReference<RpcProvisionRegistry> ref, final RpcProvisionRegistry delegate) {
         super(ref, delegate);
     }
 
     @Override
-    public Broker.RpcRegistration addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
+    public Broker.RpcRegistration addRpcImplementation(final QName rpcType, final RpcImplementation implementation) throws IllegalArgumentException {
         return getDelegate().addRpcImplementation(rpcType, implementation);
     }
 
     @Override
-    public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(RpcRegistrationListener listener) {
+    public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(final RpcRegistrationListener listener) {
         return getDelegate().addRpcRegistrationListener(listener);
     }
 
     @Override
-    public Broker.RoutedRpcRegistration addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
+    public Broker.RoutedRpcRegistration addRoutedRpcImplementation(final QName rpcType, final RpcImplementation implementation) {
         return getDelegate().addRoutedRpcImplementation(rpcType, implementation);
     }
 
     @Override
-    public void setRoutedRpcDefaultDelegate(RoutedRpcDefaultImplementation defaultImplementation) {
+    public void setRoutedRpcDefaultDelegate(final RoutedRpcDefaultImplementation defaultImplementation) {
         getDelegate().setRoutedRpcDefaultDelegate(defaultImplementation);
     }
 
     @Override
-    public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(L listener) {
+    public <L extends RouteChangeListener<RpcRoutingContext, InstanceIdentifier>> ListenerRegistration<L> registerRouteChangeListener(final L listener) {
         return getDelegate().registerRouteChangeListener(listener);
     }
 
@@ -59,7 +63,7 @@ public class RpcProvisionRegistryProxy extends AbstractBrokerServiceProxy<RpcPro
     }
 
     @Override
-    public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(QName rpc, CompositeNode input) {
+    public ListenableFuture<RpcResult<CompositeNode>> invokeRpc(final QName rpc, final CompositeNode input) {
         return getDelegate().invokeRpc(rpc, input);
     }
 }
index 74923dd8b8626d9f4a1b8175b95b95d7b666d7c0..ebe95d6eb5589624536c887f7b8802898b0e7384 100644 (file)
@@ -18,7 +18,7 @@ public interface NotificationRouter {
 
     /**
      * Registers a notification listener for supplied notification type.
-     * 
+     *
      * @param notification
      * @param listener
      */
index 8b78b83e2f23c6122cadfaf1a042cbc85bed3087..0444fad65c7cd7a795fa1cdfd0b9c218eae487c7 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.sal.dom.broker.util;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -16,17 +18,13 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
 
-import static com.google.common.base.Preconditions.*;
-
-public class YangDataUtils {
+public final class YangDataUtils {
 
-    public YangDataUtils() {
-        // TODO Auto-generated constructor stub
+    private YangDataUtils() {
+        throw new UnsupportedOperationException("Utility class");
     }
 
-    
-    
-    public static Map<Map<QName,Object>,CompositeNode> toIndexMap(List<CompositeNode> nodes,List<QName> keys) {
+    public static Map<Map<QName,Object>,CompositeNode> toIndexMap(final List<CompositeNode> nodes,final List<QName> keys) {
         ConcurrentHashMap<Map<QName,Object>,CompositeNode> ret = new ConcurrentHashMap<>();
         for(CompositeNode node : nodes) {
             Map<QName, Object> key = getKeyMap(node,keys);
@@ -35,16 +33,14 @@ public class YangDataUtils {
         return ret;
     }
 
-
-
-    public static Map<QName,Object> getKeyMap(CompositeNode node, List<QName> keys) {
+    public static Map<QName,Object> getKeyMap(final CompositeNode node, final List<QName> keys) {
         Map<QName,Object> map = new HashMap<>();
         for(QName key : keys) {
             SimpleNode<?> keyNode = node.getFirstSimpleByName(QName.create(node.getNodeType(), key.getLocalName()));
             checkArgument(keyNode != null,"Node must contains all keys.");
             Object value = keyNode.getValue();
             map.put(key, value);
-            
+
         }
         return map;
     }
index 7f6918f2a1e7d7fbf89d8533f4b2719da9d6093c..306cd34a69502187084bec2a33643cac5231e979 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.controller.sal.dom.broker.util;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
 
 import java.util.Iterator;
 import java.util.List;
@@ -32,17 +34,15 @@ import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;
 
-import static com.google.common.base.Preconditions.*;
-
 import com.google.common.base.Function;
 import com.google.common.collect.FluentIterable;
 
-public class YangSchemaUtils {
+public final class YangSchemaUtils {
 
     private static final Function<PathArgument, QName> QNAME_FROM_PATH_ARGUMENT = new Function<PathArgument, QName>(){
-        
+
         @Override
-        public QName apply(PathArgument input) {
+        public QName apply(final PathArgument input) {
             if(input == null) {
                 return null;
             }
@@ -50,29 +50,28 @@ public class YangSchemaUtils {
         }
     };
 
-    private  YangSchemaUtils() {
+    private YangSchemaUtils() {
         throw new UnsupportedOperationException("Utility class.");
     }
-    
-    
-    public static DataSchemaNode getSchemaNode(SchemaContext schema,InstanceIdentifier path) {
+
+    public static DataSchemaNode getSchemaNode(final SchemaContext schema,final InstanceIdentifier path) {
         checkArgument(schema != null,"YANG Schema must not be null.");
         checkArgument(path != null,"Path must not be null.");
         return getSchemaNode(schema, FluentIterable.from(path.getPath()).transform(QNAME_FROM_PATH_ARGUMENT));
     }
-    
-    public static DataSchemaNode getSchemaNode(SchemaContext schema,Iterable<QName> path) {
+
+    public static DataSchemaNode getSchemaNode(final SchemaContext schema,final Iterable<QName> path) {
         checkArgument(schema != null,"YANG Schema must not be null.");
         checkArgument(path != null,"Path must not be null.");
         if(!path.iterator().hasNext()){
             return toRootDataNode(schema);
         }
-        
+
         QName firstNode = path.iterator().next();
         DataNodeContainer previous = schema.findModuleByNamespaceAndRevision(firstNode.getNamespace(),
                 firstNode.getRevision());
         Iterator<QName> iterator = path.iterator();
-        
+
         while (iterator.hasNext()) {
             checkArgument(previous!= null, "Supplied path does not resolve into valid schema node.");
             QName arg = iterator.next();
@@ -92,7 +91,7 @@ public class YangSchemaUtils {
         return (DataSchemaNode) previous;
     }
 
-    private static DataSchemaNode searchInChoices(DataNodeContainer node, QName arg) {
+    private static DataSchemaNode searchInChoices(final DataNodeContainer node, final QName arg) {
         Set<DataSchemaNode> children = node.getChildNodes();
         for (DataSchemaNode child : children) {
             if (child instanceof ChoiceNode) {
@@ -106,7 +105,7 @@ public class YangSchemaUtils {
         return null;
     }
 
-    private static DataSchemaNode searchInCases(ChoiceNode choiceNode, QName arg) {
+    private static DataSchemaNode searchInCases(final ChoiceNode choiceNode, final QName arg) {
         Set<ChoiceCaseNode> cases = choiceNode.getCases();
         for (ChoiceCaseNode caseNode : cases) {
             DataSchemaNode node = caseNode.getDataChildByName(arg);
@@ -117,124 +116,124 @@ public class YangSchemaUtils {
         return null;
     }
 
-    private static ContainerSchemaNode toRootDataNode(SchemaContext schema) {
+    private static ContainerSchemaNode toRootDataNode(final SchemaContext schema) {
         return new NetconfDataRootNode(schema);
     }
 
     private static final class NetconfDataRootNode implements ContainerSchemaNode {
-    
-        public NetconfDataRootNode(SchemaContext schema) {
+
+        public NetconfDataRootNode(final SchemaContext schema) {
             // TODO Auto-generated constructor stub
         }
-    
+
         @Override
         public Set<TypeDefinition<?>> getTypeDefinitions() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public Set<DataSchemaNode> getChildNodes() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public Set<GroupingDefinition> getGroupings() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
-        public DataSchemaNode getDataChildByName(QName name) {
+        public DataSchemaNode getDataChildByName(final QName name) {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
-        public DataSchemaNode getDataChildByName(String name) {
+        public DataSchemaNode getDataChildByName(final String name) {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public Set<UsesNode> getUses() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public Set<AugmentationSchema> getAvailableAugmentations() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public boolean isAugmenting() {
             // TODO Auto-generated method stub
             return false;
         }
-    
+
         @Override
         public boolean isAddedByUses() {
             // TODO Auto-generated method stub
             return false;
         }
-    
+
         @Override
         public boolean isConfiguration() {
             // TODO Auto-generated method stub
             return false;
         }
-    
+
         @Override
         public ConstraintDefinition getConstraints() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public QName getQName() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public SchemaPath getPath() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public String getDescription() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public String getReference() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public Status getStatus() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public List<UnknownSchemaNode> getUnknownSchemaNodes() {
             // TODO Auto-generated method stub
             return null;
         }
-    
+
         @Override
         public boolean isPresenceContainer() {
             // TODO Auto-generated method stub
             return false;
         }
-    
+
     }
 
 }
index c0f0a35565db16558354096d27ea75189cd60873..413d81d0295694ae0e670c7297a0c77c155e9738 100644 (file)
@@ -12,6 +12,7 @@ import org.junit.Test;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -25,7 +26,6 @@ public class InMemoryDataStoreTest {
     private SchemaContext schemaContext;
     private InMemoryDOMDataStore domStore;
 
-
     @Before
     public void setupStore() {
         domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor());
@@ -34,13 +34,11 @@ public class InMemoryDataStoreTest {
 
     }
 
-
     @Test
     public void testTransactionIsolation() throws InterruptedException, ExecutionException {
 
         assertNotNull(domStore);
 
-
         DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
         assertNotNull(readTx);
 
@@ -55,19 +53,17 @@ public class InMemoryDataStoreTest {
 
         /**
          *
-         * Reads /test from writeTx
-         * Read should return container.
+         * Reads /test from writeTx Read should return container.
          *
          */
         ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
         assertTrue(writeTxContainer.get().isPresent());
 
         /**
-        *
-        * Reads /test from readTx
-        * Read should return Absent.
-        *
-        */
+         *
+         * Reads /test from readTx Read should return Absent.
+         *
+         */
         ListenableFuture<Optional<NormalizedNode<?, ?>>> readTxContainer = readTx.read(TestModel.TEST_PATH);
         assertFalse(readTxContainer.get().isPresent());
     }
@@ -86,8 +82,7 @@ public class InMemoryDataStoreTest {
 
         /**
          *
-         * Reads /test from writeTx
-         * Read should return container.
+         * Reads /test from writeTx Read should return container.
          *
          */
         ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
@@ -97,7 +92,8 @@ public class InMemoryDataStoreTest {
 
         assertThreePhaseCommit(cohort);
 
-        Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+        Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)
+                .get();
         assertTrue(afterCommitRead.isPresent());
     }
 
@@ -115,10 +111,91 @@ public class InMemoryDataStoreTest {
         cohort.preCommit().get();
         cohort.abort().get();
 
-        Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+        Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)
+                .get();
         assertFalse(afterCommitRead.isPresent());
     }
 
+    @Test
+    public void testTransactionChain() throws InterruptedException, ExecutionException {
+        DOMStoreTransactionChain txChain = domStore.createTransactionChain();
+        assertNotNull(txChain);
+
+        /**
+         * We alocate new read-write transaction and write /test
+         *
+         *
+         */
+        DOMStoreReadWriteTransaction firstTx = txChain.newReadWriteTransaction();
+        assertTestContainerWrite(firstTx);
+
+        /**
+         * First transaction is marked as ready, we are able to allocate chained
+         * transactions
+         */
+        DOMStoreThreePhaseCommitCohort firstWriteTxCohort = firstTx.ready();
+
+        /**
+         * We alocate chained transaction - read transaction, note first one is
+         * still not commited to datastore.
+         */
+        DOMStoreReadTransaction secondReadTx = txChain.newReadOnlyTransaction();
+
+        /**
+         *
+         * We test if we are able to read data from tx, read should not fail
+         * since we are using chained transaction.
+         *
+         *
+         */
+        assertTestContainerExists(secondReadTx);
+
+        /**
+         *
+         * We alocate next transaction, which is still based on first one, but
+         * is read-write.
+         *
+         */
+        DOMStoreReadWriteTransaction thirdDeleteTx = txChain.newReadWriteTransaction();
+
+        /**
+         * We test existence of /test in third transaction container should
+         * still be visible from first one (which is still uncommmited).
+         *
+         *
+         */
+        assertTestContainerExists(thirdDeleteTx);
+
+        /**
+         * We delete node in third transaction
+         */
+        thirdDeleteTx.delete(TestModel.TEST_PATH);
+
+        /**
+         * third transaction is sealed.
+         */
+        DOMStoreThreePhaseCommitCohort thirdDeleteTxCohort = thirdDeleteTx.ready();
+
+        /**
+         * We commit first transaction
+         *
+         */
+        assertThreePhaseCommit(firstWriteTxCohort);
+
+        // Alocates store transacion
+        DOMStoreReadTransaction storeReadTx = domStore.newReadOnlyTransaction();
+        /**
+         * We verify transaction is commited to store, container should exists
+         * in datastore.
+         */
+        assertTestContainerExists(storeReadTx);
+        /**
+         * We commit third transaction
+         *
+         */
+        assertThreePhaseCommit(thirdDeleteTxCohort);
+    }
+
     @Test
     @Ignore
     public void testTransactionConflict() throws InterruptedException, ExecutionException {
@@ -138,32 +215,36 @@ public class InMemoryDataStoreTest {
         assertFalse(txTwo.ready().canCommit().get());
     }
 
-
-
-    private static void assertThreePhaseCommit(final DOMStoreThreePhaseCommitCohort cohort) throws InterruptedException, ExecutionException {
+    private static void assertThreePhaseCommit(final DOMStoreThreePhaseCommitCohort cohort)
+            throws InterruptedException, ExecutionException {
         assertTrue(cohort.canCommit().get().booleanValue());
         cohort.preCommit().get();
         cohort.commit().get();
     }
 
-
-    private static Optional<NormalizedNode<?, ?>> assertTestContainerWrite(final DOMStoreReadWriteTransaction writeTx) throws InterruptedException, ExecutionException {
+    private static Optional<NormalizedNode<?, ?>> assertTestContainerWrite(final DOMStoreReadWriteTransaction writeTx)
+            throws InterruptedException, ExecutionException {
         /**
-        *
-        * Writes /test in writeTx
-        *
-        */
-       writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+         *
+         * Writes /test in writeTx
+         *
+         */
+        writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-       /**
-        *
-        * Reads /test from writeTx
-        * Read should return container.
-        *
-        */
-       ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
-       assertTrue(writeTxContainer.get().isPresent());
-       return writeTxContainer.get();
+        return assertTestContainerExists(writeTx);
+    }
+
+    /**
+     *
+     * Reads /test from readTx Read should return container.
+     *
+     */
+    private static Optional<NormalizedNode<?, ?>> assertTestContainerExists(DOMStoreReadTransaction readTx)
+            throws InterruptedException, ExecutionException {
+
+        ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = readTx.read(TestModel.TEST_PATH);
+        assertTrue(writeTxContainer.get().isPresent());
+        return writeTxContainer.get();
     }
 
 }
index 138b726edb0dcfa6b0cdb4cdeab9ebf7c103be7d..ab47d1034f884307a58a9453db55420ad9fd1947 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.controller.sal.core.spi.data;
 
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.DataChangeListener;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -25,13 +23,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
  * Read and write access to stored data is provided only via transactions
  * created using {@link #newReadOnlyTransaction()},
  * {@link #newWriteOnlyTransaction()} and {@link #newReadWriteTransaction()}, or
- * by creating {@link TransactionChain}.
+ * by creating {@link org.opendaylight.controller.md.sal.common.api.data.TransactionChain}.
  *
  */
 public interface DOMStore extends DOMStoreTransactionFactory {
 
     /**
-     * Registers {@link DataChangeListener} for Data Change callbacks which will
+     * Registers {@link org.opendaylight.controller.md.sal.common.api.data.DataChangeListener} for Data Change callbacks which will
      * be triggered on the change of provided subpath. What constitutes a change
      * depends on the @scope parameter.
      *
index 733c10926cce352ccfbe79168a22e92776a7c8ae..b546f2e77d20c93b215ea5305c1f0bd56ffa3fc0 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.controller.sal.core.spi.data;
 
-import java.util.concurrent.Future;
-
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -27,10 +25,10 @@ public interface DOMStoreReadTransaction extends DOMStoreTransaction {
      *            read
      * @return Listenable Future which contains read result
      *         <ul>
-     *         <li>If data at supplied path exists the {@link Future#get()}
+     *         <li>If data at supplied path exists the {@link java.util.concurrent.Future#get()}
      *         returns Optional object containing data
      *         <li>If data at supplied path does not exists the
-     *         {@link Future#get()} returns {@link Optional#absent()}.
+     *         {@link java.util.concurrent.Future#get()} returns {@link Optional#absent()}.
      *         </ul>
      */
     ListenableFuture<Optional<NormalizedNode<?,?>>> read(InstanceIdentifier path);
index ddabbc6c030f3f8ef098d207b2b250f737288ddc..19bb0538c26023c2819f4cff2fa52964ed7056cb 100644 (file)
@@ -7,8 +7,6 @@
  */
 package org.opendaylight.controller.sal.core.spi.data;
 
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.yangtools.concepts.Path;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -20,7 +18,7 @@ public interface DOMStoreWriteTransaction extends DOMStoreTransaction {
      * specified path.
      *
      * If you need add or merge of current object with specified use
-     * {@link #merge(LogicalDatastoreType, Path, Object)}
+     * {@link #merge(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType, org.opendaylight.yangtools.concepts.Path, Object)}
      *
      *
      * @param path
@@ -39,7 +37,7 @@ public interface DOMStoreWriteTransaction extends DOMStoreTransaction {
      * specified path.
      *
      * If you need add or merge of current object with specified use
-     * {@link #merge(LogicalDatastoreType, Path, Object)}
+     * {@link #merge(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType, org.opendaylight.yangtools.concepts.Path, Object)}
      *
      *
      * @param path
index 7037231c5fa2b7cad54d8c79775ae43e3195013f..04c5c54184e364eb957cd35b2fff6b98acf282f4 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.controller.sal.connect.api;
 
-import org.opendaylight.controller.sal.connect.netconf.sal.NetconfDeviceRpc;
 import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.yangtools.yang.model.util.repo.SchemaSourceProvider;
 
index fa6e2522938cf40bbce4c759ea9c43871317c1f1..e78f2b32df0cbc338bad5b28ac1d5063084b9b96 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.controller.netconf.api.NetconfTerminationReason;
 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.conf.NetconfClientConfiguration;
 import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.controller.netconf.util.xml.XmlElement;
 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
index 927d41861a67321039c7c058502b27d558af7e50..6a62b1e20bba755367111924f78a49a6e2de7d5c 100644 (file)
@@ -11,10 +11,6 @@ import com.google.common.base.Function;
 import com.google.common.util.concurrent.Futures;
 import java.util.Collections;
 import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
 
 import javax.annotation.Nullable;
 import org.opendaylight.controller.netconf.api.NetconfMessage;
index 9f844fde3fe440f6857f59c680f768e6b1f57fee..e7d64646ead9713c27ace15a1c1935d2ade363e4 100644 (file)
@@ -12,11 +12,8 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
-import javax.annotation.concurrent.ThreadSafe;
-
 import org.opendaylight.controller.sal.connect.api.SchemaContextProviderFactory;
 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
index b43e03bef7ea910ff32b09bfaa72b0282a9c8cc8..44ff2ef985394f3d60055ae8d7c2db6c1c27422a 100644 (file)
@@ -69,13 +69,11 @@ public final class NetconfRemoteSchemaSourceProvider implements SchemaSourceProv
 
     private ImmutableCompositeNode createGetSchemaRequest(final String moduleName, final Optional<String> revision) {
         final CompositeNodeBuilder<ImmutableCompositeNode> request = ImmutableCompositeNode.builder();
-        request.setQName(GET_SCHEMA_QNAME)
-                .addLeaf("format", "yang")
-                .addLeaf("identifier", moduleName);
-
+        request.setQName(GET_SCHEMA_QNAME).addLeaf("identifier", moduleName);
         if (revision.isPresent()) {
             request.addLeaf("version", revision.get());
         }
+        request.addLeaf("format", "yang");
         return request.toInstance();
     }
 
index c85a52909d441350ab69536ed3b29fb3ec9c38e7..2adc1be79e65b35b4bc52312e56d6653b2d7551f 100644 (file)
@@ -7,12 +7,11 @@
  */
 package org.opendaylight.controller.sal.connect.netconf.schema.mapping;
 
+import com.google.common.base.Optional;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
-
 import javax.activation.UnsupportedDataTypeException;
-
 import org.opendaylight.controller.netconf.api.NetconfMessage;
 import org.opendaylight.controller.sal.common.util.Rpcs;
 import org.opendaylight.controller.sal.connect.api.MessageTransformer;
@@ -24,15 +23,15 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
+import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider;
 import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils;
 import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Optional;
-
 public class NetconfMessageTransformer implements MessageTransformer<NetconfMessage> {
 
     public static final String MESSAGE_ID_PREFIX = "m";
@@ -65,7 +64,17 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
                 NetconfMessageTransformUtil.NETCONF_RPC_QNAME, NetconfMessageTransformUtil.flattenInput(node));
         final Document w3cPayload;
         try {
-            w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, XmlDocumentUtils.defaultValueCodecProvider());
+            final XmlCodecProvider codecProvider = XmlDocumentUtils.defaultValueCodecProvider();
+            if(schemaContext.isPresent()) {
+                if (NetconfMessageTransformUtil.isDataEditOperation(rpc)) {
+                    final DataNodeContainer schemaForEdit = NetconfMessageTransformUtil.createSchemaForEdit(schemaContext.get());
+                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaForEdit, codecProvider);
+                } else {
+                    w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), codecProvider);
+                }
+            } else {
+                w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, codecProvider);
+            }
         } catch (final UnsupportedDataTypeException e) {
             throw new IllegalArgumentException("Unable to create message", e);
         }
index 0c6ad45fbb86eda0631e5cf2b1465079fd2df183..1284d6d1ce3cd67d8b9355622873db46a46754b5 100644 (file)
@@ -11,8 +11,8 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-
 import java.util.Map;
+
 import javax.annotation.Nullable;
 
 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
@@ -26,8 +26,10 @@ import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
 import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
 import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl;
-import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlDocumentUtils;
 import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -35,6 +37,7 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 
 public class NetconfMessageTransformUtil {
 
@@ -149,11 +152,41 @@ public class NetconfMessageTransformUtil {
     }
 
     public static boolean isDataRetrievalOperation(final QName rpc) {
-        return NETCONF_URI == rpc.getNamespace()
+        return NETCONF_URI.equals(rpc.getNamespace())
                 && (rpc.getLocalName().equals(NETCONF_GET_CONFIG_QNAME.getLocalName()) || rpc.getLocalName().equals(
                         NETCONF_GET_QNAME.getLocalName()));
     }
 
+    public static boolean isDataEditOperation(final QName rpc) {
+        return NETCONF_URI.equals(rpc.getNamespace())
+                && rpc.getLocalName().equals(NETCONF_EDIT_CONFIG_QNAME.getLocalName());
+    }
+
+    /**
+     * Creates artificial schema node for edit-config rpc. This artificial schema looks like:
+     * <pre>
+     * {@code
+     * rpc
+     *   edit-config
+     *     config
+     *         // All schema nodes from remote schema
+     *     config
+     *   edit-config
+     * rpc
+     * }
+     * </pre>
+     *
+     * This makes the translation of rpc edit-config request(especially the config node)
+     * to xml use schema which is crucial for some types of nodes e.g. identity-ref.
+     */
+    public static DataNodeContainer createSchemaForEdit(final SchemaContext schemaContext) {
+        final QName config = QName.create(NETCONF_EDIT_CONFIG_QNAME, "config");
+        final QName editConfig = QName.create(NETCONF_EDIT_CONFIG_QNAME, "edit-config");
+        final NodeContainerProxy configProxy = new NodeContainerProxy(config, schemaContext.getChildNodes());
+        final NodeContainerProxy editConfigProxy = new NodeContainerProxy(editConfig, Sets.<DataSchemaNode>newHashSet(configProxy));
+        return new NodeContainerProxy(NETCONF_RPC_QNAME, Sets.<DataSchemaNode>newHashSet(editConfigProxy));
+    }
+
     public static CompositeNodeTOImpl wrap(final QName name, final Node<?> node) {
         if (node != null) {
             return new CompositeNodeTOImpl(name, null, Collections.<Node<?>> singletonList(node));
diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NodeContainerProxy.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NodeContainerProxy.java
new file mode 100644 (file)
index 0000000..bd075d0
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * 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.util;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+
+class NodeContainerProxy implements ContainerSchemaNode {
+
+    private final Map<QName, DataSchemaNode> childNodes;
+    private final QName qName;
+
+    public NodeContainerProxy(final QName qName, final Map<QName, DataSchemaNode> childNodes) {
+        this.childNodes = Preconditions.checkNotNull(childNodes, "childNodes");
+        this.qName = Preconditions.checkNotNull(qName, "qName");
+    }
+
+    public NodeContainerProxy(final QName qName, final Set<DataSchemaNode> childNodes) {
+        this(qName, asMap(childNodes));
+    }
+
+    private static Map<QName, DataSchemaNode> asMap(final Set<DataSchemaNode> childNodes) {
+        final Map<QName, DataSchemaNode> mapped = Maps.newHashMap();
+        for (final DataSchemaNode childNode : childNodes) {
+            mapped.put(childNode.getQName(), childNode);
+        }
+        return mapped;
+    }
+
+    @Override
+    public Set<TypeDefinition<?>> getTypeDefinitions() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public Set<DataSchemaNode> getChildNodes() {
+        return Sets.newHashSet(childNodes.values());
+    }
+
+    @Override
+    public Set<GroupingDefinition> getGroupings() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public DataSchemaNode getDataChildByName(final QName qName) {
+        return childNodes.get(qName);
+    }
+
+    @Override
+    public DataSchemaNode getDataChildByName(final String s) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Set<UsesNode> getUses() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public boolean isPresenceContainer() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Set<AugmentationSchema> getAvailableAugmentations() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isAugmenting() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isAddedByUses() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isConfiguration() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public ConstraintDefinition getConstraints() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public QName getQName() {
+        return qName;
+    }
+
+    @Override
+    public SchemaPath getPath() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String getDescription() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String getReference() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public Status getStatus() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+        return Collections.emptyList();
+    }
+}
index f55566acc37ca9c4eac03ab87642c77db28a1f69..e3ac9bab300b2ff3c0e0e0e04b3c10f27e5d28a7 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.controller.config.yang.md.sal.remote.rpc;
 
-import org.opendaylight.controller.sal.connector.remoterpc.*;
+import org.opendaylight.controller.sal.connector.remoterpc.ClientImpl;
+import org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcProvider;
+import org.opendaylight.controller.sal.connector.remoterpc.RoutingTableProvider;
+import org.opendaylight.controller.sal.connector.remoterpc.ServerImpl;
 import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
 import org.osgi.framework.BundleContext;
@@ -16,51 +19,51 @@ import org.osgi.framework.BundleContext;
  *
  */
 public final class ZeroMQServerModule
-    extends org.opendaylight.controller.config.yang.md.sal.remote.rpc.AbstractZeroMQServerModule {
+extends org.opendaylight.controller.config.yang.md.sal.remote.rpc.AbstractZeroMQServerModule {
 
-  private static final Integer ZEROMQ_ROUTER_PORT = 5554;
-  private BundleContext bundleContext;
+    private static final Integer ZEROMQ_ROUTER_PORT = 5554;
+    private BundleContext bundleContext;
 
-  public ZeroMQServerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
-                            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
-    super(identifier, dependencyResolver);
-  }
+    public ZeroMQServerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+            final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
 
-  public ZeroMQServerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
-                            org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
-                            ZeroMQServerModule oldModule, java.lang.AutoCloseable oldInstance) {
+    public ZeroMQServerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+            final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+            final ZeroMQServerModule oldModule, final java.lang.AutoCloseable oldInstance) {
 
-    super(identifier, dependencyResolver, oldModule, oldInstance);
-  }
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
 
-  @Override
-  protected void customValidation() {
-    // Add custom validation for module attributes here.
-  }
+    @Override
+    protected void customValidation() {
+        // Add custom validation for module attributes here.
+    }
 
-  @Override
-  public java.lang.AutoCloseable createInstance() {
+    @Override
+    public java.lang.AutoCloseable createInstance() {
 
-    Broker broker = getDomBrokerDependency();
+        Broker broker = getDomBrokerDependency();
 
-    final int port = getPort() != null ? getPort() : ZEROMQ_ROUTER_PORT;
+        final int port = getPort() != null ? getPort() : ZEROMQ_ROUTER_PORT;
 
-    ServerImpl serverImpl = new ServerImpl(port);
+        ServerImpl serverImpl = new ServerImpl(port);
 
-    ClientImpl clientImpl = new ClientImpl();
+        ClientImpl clientImpl = new ClientImpl();
 
-    RoutingTableProvider provider = new RoutingTableProvider(bundleContext);//,serverImpl);
+        RoutingTableProvider provider = new RoutingTableProvider(bundleContext);//,serverImpl);
 
-    RemoteRpcProvider facade = new RemoteRpcProvider(serverImpl, clientImpl);
-    facade.setRoutingTableProvider(provider);
-    facade.setContext(bundleContext);
-    facade.setRpcProvisionRegistry((RpcProvisionRegistry) broker);
+        RemoteRpcProvider facade = new RemoteRpcProvider(serverImpl, clientImpl);
+        facade.setRoutingTableProvider(provider);
+        facade.setContext(bundleContext);
+        facade.setRpcProvisionRegistry((RpcProvisionRegistry) broker);
 
-    broker.registerProvider(facade, bundleContext);
-    return facade;
-  }
+        broker.registerProvider(facade, bundleContext);
+        return facade;
+    }
 
-  public void setBundleContext(BundleContext bundleContext) {
-    this.bundleContext = bundleContext;
-  }
+    public void setBundleContext(final BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
 }
index c8d6806344214f533d9cb93d0594e67fe6c5af26..0c2a370e069d48e1de827fd0c811282cdd04d0a5 100644 (file)
@@ -24,7 +24,7 @@ public class ZeroMQServerModuleFactory extends org.opendaylight.controller.confi
         module.setBundleContext(bundleContext);
         return module;
     }
-    
+
     @Override
     public Module createModule(String instanceName, DependencyResolver dependencyResolver,
             DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception {
index e721084763732900a1820e83e4b7d7d92f051d0e..200ebaee6a5a0fc2b34b7d97c52ce2350b8ee3a1 100644 (file)
@@ -26,7 +26,6 @@ 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.dto.RouteIdentifierImpl;
 import org.opendaylight.controller.sal.connector.remoterpc.util.XmlUtils;
-import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -41,7 +40,7 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 
 /**
- * An implementation of {@link RpcImplementation} that makes
+ * An implementation of {@link org.opendaylight.controller.sal.core.api.RpcImplementation} that makes
  * remote RPC calls
  */
 public class ClientImpl implements RemoteRpcClient {
index 8d2198c365967b2f1751a9d47940a07912a4f346..85f4113663c3d952771d03f2ff8500ad125c7a05 100644 (file)
@@ -16,7 +16,7 @@ public class MessageWrapper {
 
   private Message _message;
   private ZMQ.Socket _receiveSocket;
-  
+
   public MessageWrapper(Message message, ZMQ.Socket receiveSocket) {
     this._message = message;
     this._receiveSocket = receiveSocket;
index dd216c0881f1d09e0e6377830c5c9493abfd080b..89695c124a86e57f4ba5c8a8137551d3a7cbbd07 100644 (file)
@@ -1,85 +1,83 @@
-<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>sal-remoterpc-connector-test-parent</artifactId>
-        <groupId>org.opendaylight.controller.tests</groupId>
-        <version>1.0-SNAPSHOT</version>
-    </parent>
-    <artifactId>sal-remoterpc-connector-test-consumer</artifactId>
-    <packaging>bundle</packaging>
-    <scm>
-        <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
-        <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
-        <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>
-    </scm>
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+    <groupId>org.opendaylight.controller.tests</groupId>
+    <artifactId>sal-remoterpc-connector-test-parent</artifactId>
+    <version>1.1-SNAPSHOT</version>
+  </parent>
+  <artifactId>sal-remoterpc-connector-test-consumer</artifactId>
+  <packaging>bundle</packaging>
 
+  <dependencies>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <configuration>
-                    <instructions>
-                        <Bundle-Activator>org.opendaylight.controller.sample.zeromq.consumer.ExampleConsumer</Bundle-Activator>
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>containermanager</artifactId>
+      <version>0.5.2-SNAPSHOT</version>
+    </dependency>
 
-    <dependencies>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-binding-api</artifactId>
-            <version>1.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-common-util</artifactId>
-            <version>1.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-core-api</artifactId>
-            <version>1.0-SNAPSHOT</version>
-        </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal</artifactId>
+      <version>0.8.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-api</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-common-util</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-common-util</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-core-api</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-binding</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-common</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-data-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-data-impl</artifactId>
+      <version>${yangtools.version}</version>
+    </dependency>
+  </dependencies>
 
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>containermanager</artifactId>
-            <version>0.5.1-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal</artifactId>
-            <version>0.5.1-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-binding</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-common</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-data-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.yangtools</groupId>
-            <artifactId>yang-data-impl</artifactId>
-            <version>${yangtools.version}</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-common-util</artifactId>
-            <version>1.0-SNAPSHOT</version>
-        </dependency>
-    </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            <Bundle-Activator>org.opendaylight.controller.sample.zeromq.consumer.ExampleConsumer</Bundle-Activator>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>
+  </scm>
 </project>
index 7119a661132907342e19643e30ad7c1c77d42725..aac6da47bab3e5b1cdc2e8e99df1b1ed23021886 100644 (file)
@@ -11,7 +11,7 @@ import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.net.URI;
 import java.util.Hashtable;
-import java.util.concurrent.*;
+import java.util.concurrent.Future;
 
 import org.opendaylight.controller.sal.core.api.AbstractConsumer;
 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
@@ -25,7 +25,6 @@ import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.opendaylight.yangtools.yang.data.impl.XmlTreeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl;
 
 import javax.xml.stream.XMLStreamException;
 
index 5bfbcba5f8522da0fed52b3c2f63d0f660499a80..3f47700f8d34c346397d2954ac3b674c63420590 100644 (file)
@@ -1,20 +1,15 @@
-<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">
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
     <groupId>org.opendaylight.controller</groupId>
     <artifactId>sal-parent</artifactId>
-    <version>1.0-SNAPSHOT</version>
+    <version>1.1-SNAPSHOT</version>
     <relativePath>../..</relativePath>
   </parent>
-  <packaging>pom</packaging>
   <groupId>org.opendaylight.controller.tests</groupId>
   <artifactId>sal-remoterpc-connector-test-parent</artifactId>
-  <scm>
-    <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
-    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
-    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>
-  </scm>
+  <packaging>pom</packaging>
 
   <modules>
     <module>consumer-service</module>
     <module>test-it</module>
     <module>test-nb</module>
   </modules>
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL</url>
+  </scm>
 
 </project>
index a13a5aeba08bfaa15f3ef8713ab0b93fdc411af6..bd0e43bada99c229fc5041029f7db5a46af2ef5a 100644 (file)
@@ -4,7 +4,7 @@
   <parent>
         <artifactId>sal-remoterpc-connector-test-parent</artifactId>
         <groupId>org.opendaylight.controller.tests</groupId>
-        <version>1.0-SNAPSHOT</version>
+        <version>1.1-SNAPSHOT</version>
   </parent>
   <artifactId>sal-remoterpc-connector-test-provider</artifactId>
   <packaging>bundle</packaging>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-binding-api</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-common-util</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-core-api</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
     </dependency>
 
 
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>containermanager</artifactId>
-      <version>0.5.1-SNAPSHOT</version>
+      <version>0.5.2-SNAPSHOT</version>
     </dependency>
 
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal</artifactId>
-      <version>0.5.1-SNAPSHOT</version>
+      <version>0.8.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-common-util</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-remoterpc-connector</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>1.1-SNAPSHOT</version>
     </dependency>
 
   </dependencies>
index e33011b92b4255327a54cfa82de036c78542d557..ff930db6fde780eb57195dc1dac3262fbbf99f62 100644 (file)
@@ -26,7 +26,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.net.URI;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 public class ExampleProvider extends AbstractProvider implements RpcImplementation {
 
@@ -91,7 +95,7 @@ public class ExampleProvider extends AbstractProvider implements RpcImplementati
     }
     return false;
   }
-  
+
   // Adds a child SimpleNode containing the value "success" to the input CompositeNode
   private CompositeNode addSuccessNode(CompositeNode input) {
     List<Node<?>> list = new ArrayList<Node<?>>(input.getChildren());
index 4c7e15dbb033f127518564a47e7c8db0743acc62..84e9d29c72ab80bba8d36e971c45d82ee932f99b 100644 (file)
@@ -4,7 +4,7 @@
     <parent>
         <artifactId>sal-remoterpc-connector-test-parent</artifactId>
         <groupId>org.opendaylight.controller.tests</groupId>
-        <version>1.0-SNAPSHOT</version>
+        <version>1.1-SNAPSHOT</version>
     </parent>
     <artifactId>sal-remoterpc-connector-test-it</artifactId>
     <scm>
         <dependency>
             <groupId>org.opendaylight.controller.tests</groupId>
             <artifactId>sal-remoterpc-connector-test-provider</artifactId>
-            <version>1.0-SNAPSHOT</version>
+            <version>1.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.controller.tests</groupId>
             <artifactId>sal-remoterpc-connector-test-consumer</artifactId>
-            <version>1.0-SNAPSHOT</version>
+            <version>1.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-broker-impl</artifactId>
-            <version>1.0-SNAPSHOT</version>
+            <version>1.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.ops4j.pax.exam</groupId>
         <dependency>
           <groupId>org.opendaylight.controller</groupId>
           <artifactId>ietf-netconf-monitoring</artifactId>
+          <version>0.2.5-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
index 5ee982009e53e5b1492af9811ddf9336a821acfc..e02e290a29696a5cc8cd28000386132481917171 100644 (file)
@@ -9,8 +9,6 @@ package org.opendaylight.controller.sample.zeromq.test.it;
 
 import junit.framework.Assert;
 
-import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -42,12 +40,11 @@ import javax.inject.Inject;
 
 import java.io.IOException;
 import java.net.URI;
-import java.util.Hashtable;
 
 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.ops4j.pax.exam.CoreOptions.*;
+//import static org.ops4j.pax.exam.CoreOptions.*;
 
 @RunWith(PaxExam.class)
 public class RouterTest {
@@ -67,7 +64,7 @@ public class RouterTest {
   @Inject
   @Filter(timeout=60*1000)
   Broker broker;
-  
+
   private ZMQ.Context zmqCtx = ZMQ.context(1);
   //private Server router;
   //private ExampleProvider provider;
@@ -336,7 +333,7 @@ public class RouterTest {
     return msg;
   }
 
-  
+
   private void printState(){
     Bundle[] b = ctx.getBundles();
     _logger.debug("\n\nNumber of bundles [{}]\n\n]", b.length);
index a6bbe31684008c00722482b6e4eb2078d60fa4d4..b041cb430a6eff183ff7ab5a29e4cd0a42bbe838 100644 (file)
@@ -5,7 +5,7 @@
   <parent>
     <artifactId>sal-remoterpc-connector-test-parent</artifactId>
     <groupId>org.opendaylight.controller.tests</groupId>
-    <version>1.0-SNAPSHOT</version>
+    <version>1.1-SNAPSHOT</version>
   </parent>
 
   <artifactId>sal-remoterpc-connector-test-nb</artifactId>
index edd49485af813276d8dba45083d34fcffaf3ae88..e97be52f3d1b422ed8bd540c625a0a77654ad86b 100644 (file)
@@ -19,7 +19,8 @@ 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;
-import org.osgi.framework.*;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index 067b7d96ec8c94f0af3bef597621c1c7d62586f7..4d9b198795f093c53834f6977447191f2b122136 100644 (file)
@@ -31,12 +31,12 @@ import org.opendaylight.yangtools.yang.data.api.CompositeNode;
  *   <ul>
  *    <li><b>/restconf</b> - {@link #getRoot()}
  *     <ul>
- *      <li><b>/config</b> - {@link #readConfigurationData(String)} 
+ *      <li><b>/config</b> - {@link #readConfigurationData(String)}
  *                              {@link #updateConfigurationData(String, CompositeNode)}
  *                              {@link #createConfigurationData(CompositeNode)}
  *                              {@link #createConfigurationData(String, CompositeNode)}
  *                              {@link #deleteConfigurationData(String)}
- *      <li><b>/operational</b> - {@link #readOperationalData(String)} 
+ *      <li><b>/operational</b> - {@link #readOperationalData(String)}
  *      <li>/modules - {@link #getModules()}
  *       <ul>
  *        <li>/module
@@ -95,41 +95,41 @@ public interface RestconfService {
                Draft02.MediaTypes.DATA+JSON, Draft02.MediaTypes.DATA+XML,
                MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
     public StructuredData invokeRpc(@Encoded @PathParam("identifier") String identifier, CompositeNode payload);
-    
+
     @POST
     @Path("/operations/{identifier:.+}")
     @Produces({Draft02.MediaTypes.OPERATION+JSON, Draft02.MediaTypes.OPERATION+XML,
                Draft02.MediaTypes.DATA+JSON, Draft02.MediaTypes.DATA+XML,
                MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
     public StructuredData invokeRpc(@Encoded @PathParam("identifier") String identifier, @DefaultValue("") String noPayload);
-    
+
     @GET
     @Path("/config/{identifier:.+}")
-    @Produces({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML, 
+    @Produces({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML,
                MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
     public StructuredData readConfigurationData(@Encoded @PathParam("identifier") String identifier);
 
     @GET
     @Path("/operational/{identifier:.+}")
-    @Produces({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML, 
+    @Produces({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML,
                MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
     public StructuredData readOperationalData(@Encoded @PathParam("identifier") String identifier);
 
     @PUT
     @Path("/config/{identifier:.+}")
-    @Consumes({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML, 
+    @Consumes({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML,
                MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
     public Response updateConfigurationData(@Encoded @PathParam("identifier") String identifier, CompositeNode payload);
 
     @POST
     @Path("/config/{identifier:.+}")
-    @Consumes({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML, 
+    @Consumes({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML,
                MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
     public Response createConfigurationData(@Encoded @PathParam("identifier") String identifier, CompositeNode payload);
 
     @POST
     @Path("/config")
-    @Consumes({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML, 
+    @Consumes({Draft02.MediaTypes.DATA+JSON,Draft02.MediaTypes.DATA+XML,
                MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML})
     public Response createConfigurationData(CompositeNode payload);
 
index ba3e315e72728d9e0b9f7aa2c4ee78ff892ea428..290d976b2857c493e7c638592e2715e963a03277 100644 (file)
@@ -20,7 +20,7 @@ import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO.Predicate
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
 public final class RestUtil {
-    
+
     public static final String SQUOTE = "'";
     public static final String DQUOTE = "\"";
     private static final Pattern PREDICATE_PATTERN = Pattern.compile("\\[(.*?)\\]");
@@ -45,29 +45,29 @@ public final class RestUtil {
         IdentityValuesDTO identityValuesDTO = new IdentityValuesDTO(value);
         for (int i = 1; i < xPathParts.length; i++) {
             String xPathPartTrimmed = xPathParts[i].trim();
-            
+
             String xPathPartStr = getIdAndPrefixAsStr(xPathPartTrimmed);
             IdentityValue identityValue = toIdentity(xPathPartStr, prefixMap);
             if (identityValue == null) {
                 return null;
             }
-            
+
             List<Predicate> predicates = toPredicates(xPathPartTrimmed, prefixMap);
             if (predicates == null) {
                 return null;
             }
             identityValue.setPredicates(predicates);
-            
+
             identityValuesDTO.add(identityValue);
         }
         return identityValuesDTO.getValuesWithNamespaces().isEmpty() ? null : identityValuesDTO;
     }
-    
+
     private static String getIdAndPrefixAsStr(String pathPart) {
         int predicateStartIndex = pathPart.indexOf("[");
         return predicateStartIndex == -1 ? pathPart : pathPart.substring(0, predicateStartIndex);
     }
-    
+
     private static IdentityValue toIdentity(String xPathPart, PrefixesMaping prefixMap) {
         String xPathPartTrimmed = xPathPart.trim();
         if (xPathPartTrimmed.isEmpty()) {
index c13d593a8e9ed4cac3d525026de291a5e2d7d08a..5f6909cea8e3e15d2b7887fe975d2d3e613163b5 100644 (file)
@@ -8,6 +8,15 @@
 
 package org.opendaylight.controller.sal.rest.impl;
 
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERRORS_CONTAINER_QNAME;
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_APP_TAG_QNAME;
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_INFO_QNAME;
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_LIST_QNAME;
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_MESSAGE_QNAME;
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_TAG_QNAME;
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_TYPE_QNAME;
+import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.NAMESPACE;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -33,8 +42,6 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
-import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.*;
-
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError;
@@ -70,7 +77,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
     private HttpHeaders headers;
 
     @Override
-    public Response toResponse( RestconfDocumentedException exception ) {
+    public Response toResponse( final RestconfDocumentedException exception ) {
 
         LOG.debug( "In toResponse: {}", exception.getMessage() );
 
@@ -95,8 +102,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
             // single space char in the entity.
 
             return Response.status( exception.getStatus() )
-                                    .type( MediaType.TEXT_PLAIN_TYPE )
-                                    .entity( " " ).build();
+                    .type( MediaType.TEXT_PLAIN_TYPE )
+                    .entity( " " ).build();
         }
 
         int status = errors.iterator().next().getErrorTag().getStatusCode();
@@ -106,8 +113,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
 
         if( errorsSchemaNode == null ) {
             return Response.status( status )
-                           .type( MediaType.TEXT_PLAIN_TYPE )
-                           .entity( exception.getMessage() ).build();
+                    .type( MediaType.TEXT_PLAIN_TYPE )
+                    .entity( exception.getMessage() ).build();
         }
 
         ImmutableList.Builder<Node<?>> errorNodes = ImmutableList.<Node<?>> builder();
@@ -116,7 +123,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         }
 
         ImmutableCompositeNode errorsNode =
-                         ImmutableCompositeNode.create( ERRORS_CONTAINER_QNAME, errorNodes.build() );
+                ImmutableCompositeNode.create( ERRORS_CONTAINER_QNAME, errorNodes.build() );
 
         Object responseBody;
         if( mediaType.getSubtype().endsWith( "json" ) ) {
@@ -129,8 +136,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         return Response.status( status ).type( mediaType ).entity( responseBody ).build();
     }
 
-    private Object toJsonResponseBody( ImmutableCompositeNode errorsNode,
-                                       DataNodeContainer errorsSchemaNode ) {
+    private Object toJsonResponseBody( final ImmutableCompositeNode errorsNode,
+            final DataNodeContainer errorsSchemaNode ) {
 
         JsonMapper jsonMapper = new JsonMapper();
 
@@ -152,8 +159,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         return responseBody;
     }
 
-    private Object toXMLResponseBody( ImmutableCompositeNode errorsNode,
-                                      DataNodeContainer errorsSchemaNode ) {
+    private Object toXMLResponseBody( final ImmutableCompositeNode errorsNode,
+            final DataNodeContainer errorsSchemaNode ) {
 
         XmlMapper xmlMapper = new XmlMapper();
 
@@ -170,7 +177,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         return responseBody;
     }
 
-    private String documentToString( Document doc ) throws TransformerException, UnsupportedEncodingException {
+    private String documentToString( final Document doc ) throws TransformerException, UnsupportedEncodingException {
         Transformer transformer = createTransformer();
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
 
@@ -180,7 +187,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
     }
 
     private Transformer createTransformer() throws TransformerFactoryConfigurationError,
-        TransformerConfigurationException {
+    TransformerConfigurationException {
         TransformerFactory tf = TransformerFactory.newInstance();
         Transformer transformer = tf.newTransformer();
         transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "no" );
@@ -191,7 +198,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         return transformer;
     }
 
-    private Node<?> toDomNode( RestconfError error ) {
+    private Node<?> toDomNode( final RestconfError error ) {
 
         CompositeNodeBuilder<ImmutableCompositeNode> builder = ImmutableCompositeNode.builder();
         builder.setQName( ERROR_LIST_QNAME );
@@ -209,7 +216,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         return builder.toInstance();
     }
 
-    private Node<?> parseErrorInfo( String errorInfo ) {
+    private Node<?> parseErrorInfo( final String errorInfo ) {
         if( Strings.isNullOrEmpty( errorInfo ) ) {
             return null;
         }
@@ -226,19 +233,19 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
 
         String errorInfoWithRoot =
                 new StringBuilder( "<error-info xmlns=\"" ).append( NAMESPACE ).append( "\">" )
-                        .append( errorInfo ).append( "</error-info>" ).toString();
+                .append( errorInfo ).append( "</error-info>" ).toString();
 
         Document doc = null;
         try {
             doc = factory.newDocumentBuilder().parse(
-                                 new InputSource( new StringReader( errorInfoWithRoot ) ) );
+                    new InputSource( new StringReader( errorInfoWithRoot ) ) );
         }
         catch( Exception e ) {
             // TODO: what if the content is text that happens to contain invalid markup? Could
             // wrap in CDATA and try again.
 
             LOG.warn( "Error parsing restconf error-info, \"" + errorInfo + "\", as XML: " +
-                      e.toString() );
+                    e.toString() );
             return null;
         }
 
@@ -263,8 +270,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper<Restco
         return errorInfoNode;
     }
 
-    private void addLeaf( CompositeNodeBuilder<ImmutableCompositeNode> builder, QName qname,
-                          String value ) {
+    private void addLeaf( final CompositeNodeBuilder<ImmutableCompositeNode> builder, final QName qname,
+            final String value ) {
         if( !Strings.isNullOrEmpty( value ) ) {
             builder.addLeaf( qname, value );
         }
index 86ed13a2802bc98b4ddd9a259aa5ac1c329118e2..b0916f4500d65d9dfb3291f4435e7c2aad31cc1b 100644 (file)
@@ -7,19 +7,6 @@
  */
 package org.opendaylight.controller.sal.restconf.impl;
 
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.HashBiMap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
 import java.io.UnsupportedEncodingException;
 import java.net.URI;
 import java.net.URLDecoder;
@@ -40,8 +27,6 @@ import org.opendaylight.controller.sal.core.api.mount.MountInstance;
 import org.opendaylight.controller.sal.core.api.mount.MountService;
 import org.opendaylight.controller.sal.rest.api.Draft02;
 import org.opendaylight.controller.sal.rest.impl.RestUtil;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
-import org.opendaylight.controller.sal.restconf.impl.RestCodec;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.yangtools.concepts.Codec;
@@ -69,6 +54,19 @@ import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.HashBiMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
 public class ControllerContext implements SchemaContextListener {
     private final static Logger LOG = LoggerFactory.getLogger( ControllerContext.class );
 
@@ -127,7 +125,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private InstanceIdWithSchemaNode toIdentifier( final String restconfInstance,
-                                                   final boolean toMountPointIdentifier ) {
+            final boolean toMountPointIdentifier ) {
         this.checkPreconditions();
 
         Iterable<String> split = Splitter.on( "/" ).split( restconfInstance );
@@ -149,7 +147,7 @@ public class ControllerContext implements SchemaContextListener {
         InstanceIdentifierBuilder builder = InstanceIdentifier.builder();
         Module latestModule = this.getLatestModule( globalSchema, startModule );
         InstanceIdWithSchemaNode iiWithSchemaNode = this.collectPathArguments( builder, pathArgs,
-                                                           latestModule, null, toMountPointIdentifier );
+                latestModule, null, toMountPointIdentifier );
 
         if( iiWithSchemaNode == null ) {
             throw new RestconfDocumentedException(
@@ -187,7 +185,7 @@ public class ControllerContext implements SchemaContextListener {
 
         Predicate<Module> filter = new Predicate<Module>() {
             @Override
-            public boolean apply( Module m ) {
+            public boolean apply( final Module m ) {
                 return Objects.equal( m.getName(), moduleName );
             }
         };
@@ -232,14 +230,14 @@ public class ControllerContext implements SchemaContextListener {
 
         final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
         Set<Module> moduleSchemas = mountPointSchema == null ? null :
-                                                mountPointSchema.findModuleByNamespace( namespace );
+            mountPointSchema.findModuleByNamespace( namespace );
         return moduleSchemas == null ? null : this.filterLatestModule( moduleSchemas );
     }
 
     public Module findModuleByNameAndRevision( final QName module ) {
         this.checkPreconditions();
         Preconditions.checkArgument( module != null && module.getLocalName() != null &&
-                                     module.getRevision() != null );
+                module.getRevision() != null );
 
         return globalSchema.findModuleByName( module.getLocalName(), module.getRevision() );
     }
@@ -247,11 +245,11 @@ public class ControllerContext implements SchemaContextListener {
     public Module findModuleByNameAndRevision( final MountInstance mountPoint, final QName module ) {
         this.checkPreconditions();
         Preconditions.checkArgument( module != null && module.getLocalName() != null &&
-                                     module.getRevision() != null && mountPoint != null );
+                module.getRevision() != null && mountPoint != null );
 
         SchemaContext schemaContext = mountPoint.getSchemaContext();
         return schemaContext == null ? null :
-                       schemaContext.findModuleByName( module.getLocalName(), module.getRevision() );
+            schemaContext.findModuleByName( module.getLocalName(), module.getRevision() );
     }
 
     public DataNodeContainer getDataNodeContainerFor( final InstanceIdentifier path ) {
@@ -354,7 +352,7 @@ public class ControllerContext implements SchemaContextListener {
         String module = this.uriToModuleName.get( qname.getNamespace() );
         if( module == null ) {
             final Module moduleSchema = globalSchema.findModuleByNamespaceAndRevision(
-                                                       qname.getNamespace(), qname.getRevision() );
+                    qname.getNamespace(), qname.getRevision() );
             if( moduleSchema == null ) {
                 return null;
             }
@@ -378,7 +376,7 @@ public class ControllerContext implements SchemaContextListener {
         SchemaContext schemaContext = mountPoint.getSchemaContext();
 
         final Module moduleSchema = schemaContext.findModuleByNamespaceAndRevision(
-                                                       qname.getNamespace(), qname.getRevision() );
+                qname.getNamespace(), qname.getRevision() );
         if( moduleSchema == null ) {
             return null;
         }
@@ -406,7 +404,7 @@ public class ControllerContext implements SchemaContextListener {
             @Override
             public boolean apply(final GroupingDefinition g) {
                 return Objects.equal(g.getQName().getLocalName(),
-                                     Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE);
+                        Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE);
             }
         };
 
@@ -416,12 +414,12 @@ public class ControllerContext implements SchemaContextListener {
 
         List<DataSchemaNode> instanceDataChildrenByName =
                 this.findInstanceDataChildrenByName(restconfGrouping,
-                                                    Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE);
+                        Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE);
         return Iterables.getFirst(instanceDataChildrenByName, null);
     }
 
-    public DataSchemaNode getRestconfModuleRestConfSchemaNode( Module inRestconfModule,
-                                                               String schemaNodeName ) {
+    public DataSchemaNode getRestconfModuleRestConfSchemaNode( final Module inRestconfModule,
+            final String schemaNodeName ) {
         Module restconfModule = inRestconfModule;
         if( restconfModule == null ) {
             restconfModule = getRestconfModule();
@@ -437,7 +435,7 @@ public class ControllerContext implements SchemaContextListener {
             @Override
             public boolean apply(final GroupingDefinition g) {
                 return Objects.equal(g.getQName().getLocalName(),
-                                     Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE);
+                        Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE);
             }
         };
 
@@ -447,49 +445,49 @@ public class ControllerContext implements SchemaContextListener {
 
         List<DataSchemaNode> instanceDataChildrenByName =
                 this.findInstanceDataChildrenByName(restconfGrouping,
-                                                            Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE);
+                        Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE);
         final DataSchemaNode restconfContainer = Iterables.getFirst(instanceDataChildrenByName, null);
 
         if (Objects.equal(schemaNodeName, Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                    Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                   Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                   Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             final DataSchemaNode modules = Iterables.getFirst(instances, null);
             instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules),
-                                                               Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
+                    Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                         Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                         Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
             final DataSchemaNode modules = Iterables.getFirst(instances, null);
             instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules),
-                                                                 Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
+                    Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
         else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) {
             List<DataSchemaNode> instances =
                     this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
-                                                   Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+                            Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
             return Iterables.getFirst(instances, null);
         }
 
@@ -545,7 +543,7 @@ public class ControllerContext implements SchemaContextListener {
 
     private String toUriString( final Object object ) throws UnsupportedEncodingException {
         return object == null ? "" :
-                       URLEncoder.encode( object.toString(), ControllerContext.URI_ENCODING_CHAR_SET );
+            URLEncoder.encode( object.toString(), ControllerContext.URI_ENCODING_CHAR_SET );
     }
 
     private InstanceIdWithSchemaNode collectPathArguments( final InstanceIdentifierBuilder builder,
@@ -559,7 +557,7 @@ public class ControllerContext implements SchemaContextListener {
 
         if( strings.isEmpty() ) {
             return new InstanceIdWithSchemaNode( builder.toInstance(),
-                                                 ((DataSchemaNode) parentNode), mountPoint );
+                    ((DataSchemaNode) parentNode), mountPoint );
         }
 
         String head = strings.iterator().next();
@@ -569,7 +567,7 @@ public class ControllerContext implements SchemaContextListener {
         DataSchemaNode targetNode = null;
         if( !Strings.isNullOrEmpty( moduleName ) ) {
             if( Objects.equal( moduleName, ControllerContext.MOUNT_MODULE ) &&
-                Objects.equal( nodeName, ControllerContext.MOUNT_NODE ) ) {
+                    Objects.equal( nodeName, ControllerContext.MOUNT_NODE ) ) {
                 if( mountPoint != null ) {
                     throw new RestconfDocumentedException(
                             "Restconf supports just one mount point in URI.",
@@ -587,7 +585,7 @@ public class ControllerContext implements SchemaContextListener {
                 if( mount == null ) {
                     LOG.debug( "Instance identifier to missing mount point: {}", partialPath );
                     throw new RestconfDocumentedException(
-                         "Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT );
+                            "Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT );
                 }
 
                 final SchemaContext mountPointSchema = mount.getSchemaContext();
@@ -610,12 +608,12 @@ public class ControllerContext implements SchemaContextListener {
                 final String moduleNameBehindMountPoint = toModuleName(  strings.get( 1 ) );
                 if( moduleNameBehindMountPoint == null ) {
                     throw new RestconfDocumentedException(
-                        "First node after mount point in URI has to be in format \"moduleName:nodeName\"",
-                        ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+                            "First node after mount point in URI has to be in format \"moduleName:nodeName\"",
+                            ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
                 }
 
                 final Module moduleBehindMountPoint = this.getLatestModule( mountPointSchema,
-                                                                            moduleNameBehindMountPoint );
+                        moduleNameBehindMountPoint );
                 if( moduleBehindMountPoint == null ) {
                     throw new RestconfDocumentedException(
                             "\"" +moduleName + "\" module does not exist in mount point.",
@@ -624,7 +622,7 @@ public class ControllerContext implements SchemaContextListener {
 
                 List<String> subList = strings.subList( 1, strings.size() );
                 return this.collectPathArguments( InstanceIdentifier.builder(), subList, moduleBehindMountPoint,
-                                                  mount, returnJustMountPoint );
+                        mount, returnJustMountPoint );
             }
 
             Module module = null;
@@ -639,7 +637,7 @@ public class ControllerContext implements SchemaContextListener {
             else {
                 SchemaContext schemaContext = mountPoint.getSchemaContext();
                 module = schemaContext == null ? null :
-                                          this.getLatestModule( schemaContext, moduleName );
+                    this.getLatestModule( schemaContext, moduleName );
                 if( module == null ) {
                     throw new RestconfDocumentedException(
                             "\"" + moduleName + "\" module does not exist in mount point.",
@@ -648,23 +646,23 @@ public class ControllerContext implements SchemaContextListener {
             }
 
             targetNode = this.findInstanceDataChildByNameAndNamespace(
-                                          parentNode, nodeName, module.getNamespace() );;
+                    parentNode, nodeName, module.getNamespace() );
             if( targetNode == null ) {
                 throw new RestconfDocumentedException(
                         "URI has bad format. Possible reasons:\n" +
-                        " 1. \"" + head + "\" was not found in parent data node.\n" +
-                        " 2. \"" + head + "\" is behind mount point. Then it should be in format \"/" +
-                        MOUNT + "/" + head + "\".", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+                                " 1. \"" + head + "\" was not found in parent data node.\n" +
+                                " 2. \"" + head + "\" is behind mount point. Then it should be in format \"/" +
+                                MOUNT + "/" + head + "\".", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
             }
         } else {
             final List<DataSchemaNode> potentialSchemaNodes =
-                                          this.findInstanceDataChildrenByName( parentNode, nodeName );
+                    this.findInstanceDataChildrenByName( parentNode, nodeName );
             if( potentialSchemaNodes.size() > 1 ) {
                 final StringBuilder strBuilder = new StringBuilder();
                 for( final DataSchemaNode potentialNodeSchema : potentialSchemaNodes ) {
                     strBuilder.append( "   " )
-                              .append( potentialNodeSchema.getQName().getNamespace() )
-                              .append( "\n" );
+                    .append( potentialNodeSchema.getQName().getNamespace() )
+                    .append( "\n" );
                 }
 
                 throw new RestconfDocumentedException(
@@ -714,7 +712,7 @@ public class ControllerContext implements SchemaContextListener {
                     }
 
                     this.addKeyValue( keyValues, listNode.getDataChildByName( key ),
-                                      uriKeyValue, mountPoint );
+                            uriKeyValue, mountPoint );
                     i++;
                 }
             }
@@ -729,7 +727,7 @@ public class ControllerContext implements SchemaContextListener {
         if( (targetNode instanceof DataNodeContainer) ) {
             final List<String> remaining = strings.subList( consumed, strings.size() );
             return this.collectPathArguments( builder, remaining,
-                              ((DataNodeContainer) targetNode), mountPoint, returnJustMountPoint );
+                    ((DataNodeContainer) targetNode), mountPoint, returnJustMountPoint );
         }
 
         return new InstanceIdWithSchemaNode( builder.toInstance(), targetNode, mountPoint );
@@ -743,7 +741,7 @@ public class ControllerContext implements SchemaContextListener {
 
         Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
             @Override
-            public boolean apply( DataSchemaNode node ) {
+            public boolean apply( final DataSchemaNode node ) {
                 return Objects.equal( node.getQName().getNamespace(), namespace );
             }
         };
@@ -753,7 +751,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     public List<DataSchemaNode> findInstanceDataChildrenByName( final DataNodeContainer container,
-                                                                final String name ) {
+            final String name ) {
         Preconditions.<DataNodeContainer> checkNotNull( container );
         Preconditions.<String> checkNotNull( name );
 
@@ -769,7 +767,7 @@ public class ControllerContext implements SchemaContextListener {
 
         Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
             @Override
-            public boolean apply( DataSchemaNode node ) {
+            public boolean apply( final DataSchemaNode node ) {
                 return Objects.equal( node.getQName().getLocalName(), name );
             }
         };
@@ -785,7 +783,7 @@ public class ControllerContext implements SchemaContextListener {
         }
 
         Iterable<ChoiceNode> choiceNodes = Iterables.<ChoiceNode> filter( container.getChildNodes(),
-                                                                          ChoiceNode.class );
+                ChoiceNode.class );
 
         final Function<ChoiceNode, Set<ChoiceCaseNode>> choiceFunction =
                 new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
@@ -796,7 +794,7 @@ public class ControllerContext implements SchemaContextListener {
         };
 
         Iterable<Set<ChoiceCaseNode>> map = Iterables.<ChoiceNode, Set<ChoiceCaseNode>> transform(
-                                                                           choiceNodes, choiceFunction );
+                choiceNodes, choiceFunction );
 
         final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat( map );
         for( final ChoiceCaseNode caze : allCases ) {
@@ -806,11 +804,11 @@ public class ControllerContext implements SchemaContextListener {
 
     public boolean isInstantiatedDataSchema( final DataSchemaNode node ) {
         return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode ||
-               node instanceof ContainerSchemaNode || node instanceof ListSchemaNode;
+                node instanceof ContainerSchemaNode || node instanceof ListSchemaNode;
     }
 
     private void addKeyValue( final HashMap<QName, Object> map, final DataSchemaNode node,
-                              final String uriValue, final MountInstance mountPoint ) {
+            final String uriValue, final MountInstance mountPoint ) {
         Preconditions.<String> checkNotNull( uriValue );
         Preconditions.checkArgument( (node instanceof LeafSchemaNode) );
 
@@ -830,8 +828,8 @@ public class ControllerContext implements SchemaContextListener {
 
         if( decoded == null ) {
             throw new RestconfDocumentedException(
-                            uriValue + " from URI can't be resolved. " + additionalInfo,
-                            ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+                    uriValue + " from URI can't be resolved. " + additionalInfo,
+                    ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
         }
 
         map.put( node.getQName(), decoded );
@@ -888,8 +886,8 @@ public class ControllerContext implements SchemaContextListener {
         };
 
         Optional<QName> namespace = FluentIterable.from( sorted )
-                                                  .transform( transform )
-                                                  .firstMatch( findFirst );
+                .transform( transform )
+                .firstMatch( findFirst );
         return namespace.isPresent() ? QName.create( namespace.get(), node ) : null;
     }
 
@@ -948,7 +946,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private CharSequence convertToRestconfIdentifier( final PathArgument argument,
-                                                      final DataNodeContainer node ) {
+            final DataNodeContainer node ) {
         if( argument instanceof NodeIdentifier && node instanceof ContainerSchemaNode ) {
             return convertToRestconfIdentifier( (NodeIdentifier) argument, (ContainerSchemaNode) node );
         }
@@ -957,7 +955,7 @@ public class ControllerContext implements SchemaContextListener {
         }
         else if( argument != null && node != null ) {
             throw new IllegalArgumentException(
-                                     "Conversion of generic path argument is not supported" );
+                    "Conversion of generic path argument is not supported" );
         }
         else {
             throw new IllegalArgumentException( "Unhandled parameter types: "
@@ -966,7 +964,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private CharSequence convertToRestconfIdentifier( final NodeIdentifier argument,
-                                                      final ContainerSchemaNode node ) {
+            final ContainerSchemaNode node ) {
         StringBuilder builder = new StringBuilder();
         builder.append( "/" );
         QName nodeType = argument.getNodeType();
@@ -975,7 +973,7 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private CharSequence convertToRestconfIdentifier( final NodeIdentifierWithPredicates argument,
-                                                      final ListSchemaNode node ) {
+            final ListSchemaNode node ) {
         QName nodeType = argument.getNodeType();
         final CharSequence nodeIdentifier = this.toRestconfIdentifier( nodeType );
         final Map<QName, Object> keyValues = argument.getKeyValues();
index f7f70e8d87ca697b5050144c56bb165976c2551c..934d4434c38a3e724279405da05198099eba2f70 100644 (file)
@@ -18,9 +18,9 @@ import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
 import com.google.common.base.Preconditions;
 
 public final class EmptyNodeWrapper implements NodeWrapper<Node<?>>, Node<Void> {
-    
+
     private Node<?> unwrapped;
-    
+
     private String localName;
     private URI namespace;
     private QName name;
@@ -30,27 +30,27 @@ public final class EmptyNodeWrapper implements NodeWrapper<Node<?>>, Node<Void>
     public boolean isComposite() {
         return composite;
     }
-    
+
     public void setComposite(boolean composite) {
         this.composite = composite;
     }
-    
+
     public EmptyNodeWrapper(URI namespace, String localName) {
         this.localName = Preconditions.checkNotNull(localName);
         this.namespace = namespace;
     }
-    
+
     @Override
     public void setQname(QName name) {
         Preconditions.checkState(unwrapped == null, "Cannot change the object, due to data inconsistencies.");
         this.name = name;
     }
-    
+
     @Override
     public QName getQname() {
         return name;
     }
-    
+
     @Override
     public String getLocalName() {
         if (unwrapped != null) {
@@ -58,7 +58,7 @@ public final class EmptyNodeWrapper implements NodeWrapper<Node<?>>, Node<Void>
         }
         return localName;
     }
-    
+
     @Override
     public URI getNamespace() {
         if (unwrapped != null) {
index 14a558967d2081a18e045192712ab0988cde6efa..d66e1610a58e62b07a1834b0c7b61197f49b2ab4 100644 (file)
@@ -20,11 +20,11 @@ public final class IdentityValuesDTO {
         elementData.add(new IdentityValue(namespace, value, prefix));
         this.originValue = originValue;
     }
-    
+
     public IdentityValuesDTO(String originValue) {
         this.originValue = originValue;
     }
-    
+
     public IdentityValuesDTO() {
         originValue = null;
     }
@@ -32,21 +32,21 @@ public final class IdentityValuesDTO {
     public void add(String namespace, String value, String prefix) {
         elementData.add(new IdentityValue(namespace, value, prefix));
     }
-    
+
     public void add(IdentityValue identityValue) {
         elementData.add(identityValue);
     }
-    
+
 
     public List<IdentityValue> getValuesWithNamespaces() {
         return Collections.unmodifiableList(elementData);
     }
-    
+
     @Override
     public String toString() {
         return elementData.toString();
     }
-    
+
     public String getOriginValue() {
         return originValue;
     }
@@ -86,7 +86,7 @@ public final class IdentityValuesDTO {
         public void setPredicates(List<Predicate> predicates) {
             this.predicates = predicates;
         }
-        
+
         @Override
         public String toString() {
             StringBuilder sb = new StringBuilder();
@@ -110,22 +110,22 @@ public final class IdentityValuesDTO {
         }
 
     }
-    
+
     public static final class Predicate {
-        
+
         private final IdentityValue name;
         private final String value;
-        
+
         public Predicate(IdentityValue name, String value) {
             super();
             this.name = name;
             this.value = value;
         }
-        
+
         public IdentityValue getName() {
             return name;
         }
-        
+
         public String getValue() {
             return value;
         }
@@ -141,10 +141,10 @@ public final class IdentityValuesDTO {
             }
             return sb.toString();
         }
-        
+
         public boolean isLeafList() {
             return name == null ? true : false;
         }
-        
+
     }
 }
index f9bd7d7aaa4edf0fa4d46a995ee5ce83b61dc138..48fd1a3dfc49e4abf6d22ae040cf504781ff0bc8 100644 (file)
@@ -15,16 +15,16 @@ import org.opendaylight.yangtools.yang.data.api.Node;
 public interface NodeWrapper<T extends Node<?>> {
 
     void setQname(QName name);
-    
+
     QName getQname();
-    
+
     T unwrap();
-    
+
     boolean isChangeAllowed();
-    
+
     URI getNamespace();
 
     void setNamespace(URI namespace);
-    
+
     String getLocalName();
 }
index 42658d79f1468b97eaead0e852b57a125ee528b9..265cc5db4536c96ecbf51bf4005ff4ced54e8c14 100644 (file)
@@ -41,7 +41,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class RestCodec {
-    
+
     private static final Logger logger = LoggerFactory.getLogger(RestCodec.class);
 
     private RestCodec() {
@@ -180,7 +180,7 @@ public class RestCodec {
                 logger.info("Idenetityref will be translated as NULL for data - {}", String.valueOf(valueWithNamespace));
                 return null;
             }
-            
+
             return QName.create(module.getNamespace(), module.getRevision(), valueWithNamespace.getValue());
         }
 
@@ -292,7 +292,7 @@ public class RestCodec {
                     }
                 }
             }
-            
+
             return result.isEmpty() ? null : new InstanceIdentifier(result);
         }
 
@@ -312,7 +312,7 @@ public class RestCodec {
             return null;
         }
     }
-    
+
     private static Module getModuleByNamespace(String namespace, MountInstance mountPoint) {
         URI validNamespace = resolveValidNamespace(namespace, mountPoint);
 
@@ -328,7 +328,7 @@ public class RestCodec {
         }
         return module;
     }
-    
+
     private static URI resolveValidNamespace(String namespace, MountInstance mountPoint) {
         URI validNamespace;
         if (mountPoint != null) {
index 4d22bfa73adce9106ff3ebc59a8a2f9227d4dda7..3131668ed9ed23ae8fb8f0edb75076c8635a235d 100644 (file)
@@ -19,9 +19,9 @@ import org.opendaylight.yangtools.yang.data.impl.NodeFactory;
 import com.google.common.base.Preconditions;
 
 public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, SimpleNode<Object> {
-    
+
     private SimpleNode<Object> simpleNode;
-    
+
     private String localName;
     private Object value;
     private URI namespace;
@@ -31,23 +31,23 @@ public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, Simp
         this.localName = Preconditions.checkNotNull(localName);
         this.value = value;
     }
-    
+
     public SimpleNodeWrapper(URI namespace, String localName, Object value) {
         this(localName, value);
         this.namespace = namespace;
     }
-    
+
     @Override
     public void setQname(QName name) {
         Preconditions.checkState(simpleNode == null, "Cannot change the object, due to data inconsistencies.");
         this.name = name;
     }
-    
+
     @Override
     public QName getQname() {
         return name;
     }
-    
+
     @Override
     public String getLocalName() {
         if (simpleNode != null) {
@@ -55,7 +55,7 @@ public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, Simp
         }
         return localName;
     }
-    
+
     @Override
     public URI getNamespace() {
         if (simpleNode != null) {
@@ -83,7 +83,7 @@ public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, Simp
                 name = new QName(namespace, localName);
             }
             simpleNode = NodeFactory.createImmutableSimpleNode(name, null, value);
-            
+
             value = null;
             namespace = null;
             localName = null;
@@ -126,7 +126,7 @@ public final class SimpleNodeWrapper implements NodeWrapper<SimpleNode<?>>, Simp
     public Object setValue(Object value) {
         return unwrap().setValue(value);
     }
-    
+
 
 
 }
index 8c344a79dad8cde5a8cdffa522d02c128d6a9851..231fe7e02eedfdee29d2996a7d0ebc4839f73646 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.controller.sal.restconf.impl;
 
 import org.opendaylight.controller.sal.core.api.mount.MountInstance;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
 public class StructuredData {
 
@@ -17,7 +17,7 @@ public class StructuredData {
     private final DataSchemaNode schema;
     private final MountInstance mountPoint;
 
-    public StructuredData(CompositeNode data, DataSchemaNode schema, MountInstance mountPoint) {
+    public StructuredData(final CompositeNode data, final DataSchemaNode schema, final MountInstance mountPoint) {
         this.data = data;
         this.schema = schema;
         this.mountPoint = mountPoint;
index f2a0d48e0a18e67f5708da3becc0876ed679ba87..6282f37602be8236a737fe3e8ef42852816756bc 100644 (file)
@@ -64,611 +64,611 @@ import com.google.common.eventbus.Subscribe;
  */
 public class ListenerAdapter implements DataChangeListener {
 
-       private static final Logger logger = LoggerFactory
-                       .getLogger(ListenerAdapter.class);
-       private final XmlMapper xmlMapper = new XmlMapper();
-       private final SimpleDateFormat rfc3339 = new SimpleDateFormat(
-                       "yyyy-MM-dd'T'hh:mm:ssZ");
-
-       private final InstanceIdentifier path;
-       private ListenerRegistration<DataChangeListener> registration;
-       private final String streamName;
-       private Set<Channel> subscribers = new ConcurrentSet<>();
-       private final EventBus eventBus;
-       private final EventBusChangeRecorder eventBusChangeRecorder;
-
-       /**
-        * Creates new {@link ListenerAdapter} listener specified by path and stream
-        * name.
-        * 
-        * @param path
-        *            Path to data in data store.
-        * @param streamName
-        *            The name of the stream.
-        */
-       ListenerAdapter(InstanceIdentifier path, String streamName) {
-               Preconditions.checkNotNull(path);
-               Preconditions
-                               .checkArgument(streamName != null && !streamName.isEmpty());
-               this.path = path;
-               this.streamName = streamName;
-               eventBus = new AsyncEventBus(Executors.newSingleThreadExecutor());
-               eventBusChangeRecorder = new EventBusChangeRecorder();
-               eventBus.register(eventBusChangeRecorder);
-       }
-
-       @Override
-       public void onDataChanged(
-                       DataChangeEvent<InstanceIdentifier, CompositeNode> change) {
-               if (!change.getCreatedConfigurationData().isEmpty()
-                               || !change.getCreatedOperationalData().isEmpty()
-                               || !change.getUpdatedConfigurationData().isEmpty()
-                               || !change.getUpdatedOperationalData().isEmpty()
-                               || !change.getRemovedConfigurationData().isEmpty()
-                               || !change.getRemovedOperationalData().isEmpty()) {
-                       String xml = prepareXmlFrom(change);
-                       Event event = new Event(EventType.NOTIFY);
-                       event.setData(xml);
-                       eventBus.post(event);
-               }
-       }
-
-       /**
-        * Tracks events of data change by customer.
-        */
-       private final class EventBusChangeRecorder {
-               @Subscribe
-               public void recordCustomerChange(Event event) {
-                       if (event.getType() == EventType.REGISTER) {
-                               Channel subscriber = event.getSubscriber();
-                               if (!subscribers.contains(subscriber)) {
-                                       subscribers.add(subscriber);
-                               }
-                       } else if (event.getType() == EventType.DEREGISTER) {
-                               subscribers.remove(event.getSubscriber());
-                               Notificator
-                                               .removeListenerIfNoSubscriberExists(ListenerAdapter.this);
-                       } else if (event.getType() == EventType.NOTIFY) {
-                               for (Channel subscriber : subscribers) {
-                                       if (subscriber.isActive()) {
-                                               logger.debug("Data are sent to subscriber {}:",
-                                                               subscriber.remoteAddress());
-                                               subscriber.writeAndFlush(new TextWebSocketFrame(event
-                                                               .getData()));
-                                       } else {
-                                               logger.debug(
-                                                               "Subscriber {} is removed - channel is not active yet.",
-                                                               subscriber.remoteAddress());
-                                               subscribers.remove(subscriber);
-                                       }
-                               }
-                       }
-               }
-       }
-
-       /**
-        * Represents event of specific {@link EventType} type, holds data and
-        * {@link Channel} subscriber.
-        */
-       private final class Event {
-               private final EventType type;
-               private Channel subscriber;
-               private String data;
-
-               /**
-                * Creates new event specified by {@link EventType} type.
-                * 
-                * @param type
-                *            EventType
-                */
-               public Event(EventType type) {
-                       this.type = type;
-               }
-
-               /**
-                * Gets the {@link Channel} subscriber.
-                * 
-                * @return Channel
-                */
-               public Channel getSubscriber() {
-                       return subscriber;
-               }
-
-               /**
-                * Sets subscriber for event.
-                * 
-                * @param subscriber
-                *            Channel
-                */
-               public void setSubscriber(Channel subscriber) {
-                       this.subscriber = subscriber;
-               }
-
-               /**
-                * Gets event data.
-                * 
-                * @return String representation of event data.
-                */
-               public String getData() {
-                       return data;
-               }
-
-               /**
-                * Sets event data.
-                * 
-                * @param String
-                *            data.
-                */
-               public void setData(String data) {
-                       this.data = data;
-               }
-
-               /**
-                * Gets event type.
-                * 
-                * @return The type of the event.
-                */
-               public EventType getType() {
-                       return type;
-               }
-       }
-
-       /**
-        * Type of the event.
-        */
-       private enum EventType {
-               REGISTER, DEREGISTER, NOTIFY;
-       }
-
-       /**
-        * Prepare data in printable form and transform it to String.
-        * 
-        * @param change
-        *            DataChangeEvent
-        * @return Data in printable form.
-        */
-       private String prepareXmlFrom(
-                       DataChangeEvent<InstanceIdentifier, CompositeNode> change) {
-               Document doc = createDocument();
-               Element notificationElement = doc.createElementNS(
-                               "urn:ietf:params:xml:ns:netconf:notification:1.0",
-                               "notification");
-               doc.appendChild(notificationElement);
-
-               Element eventTimeElement = doc.createElement("eventTime");
-               eventTimeElement.setTextContent(toRFC3339(new Date()));
-               notificationElement.appendChild(eventTimeElement);
-
-               Element dataChangedNotificationEventElement = doc.createElementNS(
-                               "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote",
-                               "data-changed-notification");
-               addValuesToDataChangedNotificationEventElement(doc,
-                               dataChangedNotificationEventElement, change);
-               notificationElement.appendChild(dataChangedNotificationEventElement);
-
-               try {
-                       ByteArrayOutputStream out = new ByteArrayOutputStream();
-                       TransformerFactory tf = TransformerFactory.newInstance();
-                       Transformer transformer = tf.newTransformer();
-                       transformer
-                                       .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
-                       transformer.setOutputProperty(OutputKeys.METHOD, "xml");
-                       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-                       transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
-                       transformer.setOutputProperty(
-                                       "{http://xml.apache.org/xslt}indent-amount", "4");
-                       transformer.transform(new DOMSource(doc), new StreamResult(
-                                       new OutputStreamWriter(out, "UTF-8")));
-                       byte[] charData = out.toByteArray();
-                       return new String(charData, "UTF-8");
-               } catch (TransformerException | UnsupportedEncodingException e) {
-                       String msg = "Error during transformation of Document into String";
-                       logger.error(msg, e);
-                       return msg;
-               }
-       }
-
-       /**
-        * Formats data specified by RFC3339.
-        * 
-        * @param d
-        *            Date
-        * @return Data specified by RFC3339.
-        */
-       private String toRFC3339(Date d) {
-               return rfc3339.format(d).replaceAll("(\\d\\d)(\\d\\d)$", "$1:$2");
-       }
-
-       /**
-        * Creates {@link Document} document.
-        * 
-        * @return {@link Document} document.
-        */
-       private Document createDocument() {
-               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-               Document doc = null;
-               try {
-                       DocumentBuilder bob = dbf.newDocumentBuilder();
-                       doc = bob.newDocument();
-               } catch (ParserConfigurationException e) {
-                       return null;
-               }
-               return doc;
-       }
-
-       /**
-        * Adds values to data changed notification event element.
-        * 
-        * @param doc
-        *            {@link Document}
-        * @param dataChangedNotificationEventElement
-        *            {@link Element}
-        * @param change
-        *            {@link DataChangeEvent}
-        */
-       private void addValuesToDataChangedNotificationEventElement(Document doc,
-                       Element dataChangedNotificationEventElement,
-                       DataChangeEvent<InstanceIdentifier, CompositeNode> change) {
-               addValuesFromDataToElement(doc, change.getCreatedConfigurationData(),
-                               dataChangedNotificationEventElement, Store.CONFIG,
-                               Operation.CREATED);
-               addValuesFromDataToElement(doc, change.getCreatedOperationalData(),
-                               dataChangedNotificationEventElement, Store.OPERATION,
-                               Operation.CREATED);
-               if (change.getCreatedConfigurationData().isEmpty()) {
-                       addValuesFromDataToElement(doc,
-                                       change.getUpdatedConfigurationData(),
-                                       dataChangedNotificationEventElement, Store.CONFIG,
-                                       Operation.UPDATED);
-               }
-               if (change.getCreatedOperationalData().isEmpty()) {
-                       addValuesFromDataToElement(doc, change.getUpdatedOperationalData(),
-                                       dataChangedNotificationEventElement, Store.OPERATION,
-                                       Operation.UPDATED);
-               }
-               addValuesFromDataToElement(doc, change.getRemovedConfigurationData(),
-                               dataChangedNotificationEventElement, Store.CONFIG,
-                               Operation.DELETED);
-               addValuesFromDataToElement(doc, change.getRemovedOperationalData(),
-                               dataChangedNotificationEventElement, Store.OPERATION,
-                               Operation.DELETED);
-       }
-
-       /**
-        * Adds values from data to element.
-        * 
-        * @param doc
-        *            {@link Document}
-        * @param data
-        *            Set of {@link InstanceIdentifier}.
-        * @param element
-        *            {@link Element}
-        * @param store
-        *            {@link Store}
-        * @param operation
-        *            {@link Operation}
-        */
-       private void addValuesFromDataToElement(Document doc,
-                       Set<InstanceIdentifier> data, Element element, Store store,
-                       Operation operation) {
-               if (data == null || data.isEmpty()) {
-                       return;
-               }
-               for (InstanceIdentifier path : data) {
-                       Node node = createDataChangeEventElement(doc, path, null, store,
-                                       operation);
-                       element.appendChild(node);
-               }
-       }
-
-       /**
-        * Adds values from data to element.
-        * 
-        * @param doc
-        *            {@link Document}
-        * @param data
-        *            Map of {@link InstanceIdentifier} and {@link CompositeNode}.
-        * @param element
-        *            {@link Element}
-        * @param store
-        *            {@link Store}
-        * @param operation
-        *            {@link Operation}
-        */
-       private void addValuesFromDataToElement(Document doc,
-                       Map<InstanceIdentifier, CompositeNode> data, Element element,
-                       Store store, Operation operation) {
-               if (data == null || data.isEmpty()) {
-                       return;
-               }
-               for (Entry<InstanceIdentifier, CompositeNode> entry : data.entrySet()) {
-                       Node node = createDataChangeEventElement(doc, entry.getKey(),
-                                       entry.getValue(), store, operation);
-                       element.appendChild(node);
-               }
-       }
-
-       /**
-        * Creates changed event element from data.
-        * 
-        * @param doc
-        *            {@link Document}
-        * @param path
-        *            Path to data in data store.
-        * @param data
-        *            {@link CompositeNode}
-        * @param store
-        *            {@link Store}
-        * @param operation
-        *            {@link Operation}
-        * @return {@link Node} node represented by changed event element.
-        */
-       private Node createDataChangeEventElement(Document doc,
-                       InstanceIdentifier path, CompositeNode data, Store store,
-                       Operation operation) {
-               Element dataChangeEventElement = doc.createElement("data-change-event");
-
-               Element pathElement = doc.createElement("path");
-               addPathAsValueToElement(path, pathElement);
-               dataChangeEventElement.appendChild(pathElement);
-
-               Element storeElement = doc.createElement("store");
-               storeElement.setTextContent(store.value);
-               dataChangeEventElement.appendChild(storeElement);
-
-               Element operationElement = doc.createElement("operation");
-               operationElement.setTextContent(operation.value);
-               dataChangeEventElement.appendChild(operationElement);
-
-               if (data != null) {
-                       Element dataElement = doc.createElement("data");
-                       Node dataAnyXml = translateToXml(path, data);
-                       Node adoptedNode = doc.adoptNode(dataAnyXml);
-                       dataElement.appendChild(adoptedNode);
-                       dataChangeEventElement.appendChild(dataElement);
-               }
-
-               return dataChangeEventElement;
-       }
-
-       /**
-        * Translates {@link CompositeNode} data to XML format.
-        * 
-        * @param path
-        *            Path to data in data store.
-        * @param data
-        *            {@link CompositeNode}
-        * @return Data in XML format.
-        */
-       private Node translateToXml(InstanceIdentifier path, CompositeNode data) {
-               DataNodeContainer schemaNode = ControllerContext.getInstance()
-                               .getDataNodeContainerFor(path);
-               if (schemaNode == null) {
-                       logger.info(
-                                       "Path '{}' contains node with unsupported type (supported type is Container or List) or some node was not found.",
-                                       path);
-                       return null;
-               }
-               try {
-                       Document xml = xmlMapper.write(data, schemaNode);
-                       return xml.getFirstChild();
-               } catch (UnsupportedDataTypeException e) {
-                       logger.error(
-                                       "Error occured during translation of notification to XML.",
-                                       e);
-                       return null;
-               }
-       }
-
-       /**
-        * Adds path as value to element.
-        * 
-        * @param path
-        *            Path to data in data store.
-        * @param element
-        *            {@link Element}
-        */
-       private void addPathAsValueToElement(InstanceIdentifier path,
-                       Element element) {
-               // Map< key = namespace, value = prefix>
-               Map<String, String> prefixes = new HashMap<>();
-               InstanceIdentifier instanceIdentifier = path;
-               StringBuilder textContent = new StringBuilder();
-               for (PathArgument pathArgument : instanceIdentifier.getPath()) {
-                       textContent.append("/");
-                       writeIdentifierWithNamespacePrefix(element, textContent,
-                                       pathArgument.getNodeType(), prefixes);
-                       if (pathArgument instanceof NodeIdentifierWithPredicates) {
-                               Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArgument)
-                                               .getKeyValues();
-                               for (QName keyValue : predicates.keySet()) {
-                                       String predicateValue = String.valueOf(predicates
-                                                       .get(keyValue));
-                                       textContent.append("[");
-                                       writeIdentifierWithNamespacePrefix(element, textContent,
-                                                       keyValue, prefixes);
-                                       textContent.append("='");
-                                       textContent.append(predicateValue);
-                                       textContent.append("'");
-                                       textContent.append("]");
-                               }
-                       } else if (pathArgument instanceof NodeWithValue) {
-                               textContent.append("[.='");
-                               textContent.append(((NodeWithValue) pathArgument).getValue());
-                               textContent.append("'");
-                               textContent.append("]");
-                       }
-               }
-               element.setTextContent(textContent.toString());
-       }
-
-       /**
-        * Writes identifier that consists of prefix and QName.
-        * 
-        * @param element
-        *            {@link Element}
-        * @param textContent
-        *            StringBuilder
-        * @param qName
-        *            QName
-        * @param prefixes
-        *            Map of namespaces and prefixes.
-        */
-       private static void writeIdentifierWithNamespacePrefix(Element element,
-                       StringBuilder textContent, QName qName, Map<String, String> prefixes) {
-               String namespace = qName.getNamespace().toString();
-               String prefix = prefixes.get(namespace);
-               if (prefix == null) {
-                       prefix = qName.getPrefix();
-                       if (prefix == null || prefix.isEmpty()
-                                       || prefixes.containsValue(prefix)) {
-                               prefix = generateNewPrefix(prefixes.values());
-                       }
-               }
-
-               element.setAttribute("xmlns:" + prefix, namespace);
-               textContent.append(prefix);
-               prefixes.put(namespace, prefix);
-
-               textContent.append(":");
-               textContent.append(qName.getLocalName());
-       }
-
-       /**
-        * Generates new prefix which consists of four random characters <a-z>.
-        * 
-        * @param prefixes
-        *            Collection of prefixes.
-        * @return New prefix which consists of four random characters <a-z>.
-        */
-       private static String generateNewPrefix(Collection<String> prefixes) {
-               StringBuilder result = null;
-               Random random = new Random();
-               do {
-                       result = new StringBuilder();
-                       for (int i = 0; i < 4; i++) {
-                               int randomNumber = 0x61 + (Math.abs(random.nextInt()) % 26);
-                               result.append(Character.toChars(randomNumber));
-                       }
-               } while (prefixes.contains(result.toString()));
-
-               return result.toString();
-       }
-
-       /**
-        * Gets path pointed to data in data store.
-        * 
-        * @return Path pointed to data in data store.
-        */
-       public InstanceIdentifier getPath() {
-               return path;
-       }
-
-       /**
-        * Sets {@link ListenerRegistration} registration.
-        * 
-        * @param registration
-        *            ListenerRegistration<DataChangeListener>
-        */
-       public void setRegistration(
-                       ListenerRegistration<DataChangeListener> registration) {
-               this.registration = registration;
-       }
-
-       /**
-        * Gets the name of the stream.
-        * 
-        * @return The name of the stream.
-        */
-       public String getStreamName() {
-               return streamName;
-       }
-
-       /**
-        * Removes all subscribers and unregisters event bus change recorder form
-        * event bus.
-        */
-       public void close() throws Exception {
-               subscribers = new ConcurrentSet<>();
-               registration.close();
-               registration = null;
-               eventBus.unregister(eventBusChangeRecorder);
-       }
-
-       /**
-        * Checks if {@link ListenerRegistration} registration exist.
-        * 
-        * @return True if exist, false otherwise.
-        */
-       public boolean isListening() {
-               return registration == null ? false : true;
-       }
-
-       /**
-        * Creates event of type {@link EventType#REGISTER}, set {@link Channel}
-        * subscriber to the event and post event into event bus.
-        * 
-        * @param subscriber
-        *            Channel
-        */
-       public void addSubscriber(Channel subscriber) {
-               if (!subscriber.isActive()) {
-                       logger.debug("Channel is not active between websocket server and subscriber {}"
-                                       + subscriber.remoteAddress());
-               }
-               Event event = new Event(EventType.REGISTER);
-               event.setSubscriber(subscriber);
-               eventBus.post(event);
-       }
-
-       /**
-        * Creates event of type {@link EventType#DEREGISTER}, sets {@link Channel}
-        * subscriber to the event and posts event into event bus.
-        * 
-        * @param subscriber
-        */
-       public void removeSubscriber(Channel subscriber) {
-               logger.debug("Subscriber {} is removed.", subscriber.remoteAddress());
-               Event event = new Event(EventType.DEREGISTER);
-               event.setSubscriber(subscriber);
-               eventBus.post(event);
-       }
-
-       /**
-        * Checks if exists at least one {@link Channel} subscriber.
-        * 
-        * @return True if exist at least one {@link Channel} subscriber, false
-        *         otherwise.
-        */
-       public boolean hasSubscribers() {
-               return !subscribers.isEmpty();
-       }
-
-       /**
-        * Consists of two types {@link Store#CONFIG} and {@link Store#OPERATION}.
-        */
-       private static enum Store {
-               CONFIG("config"), OPERATION("operation");
-
-               private final String value;
-
-               private Store(String value) {
-                       this.value = value;
-               }
-       }
-
-       /**
-        * Consists of three types {@link Operation#CREATED},
-        * {@link Operation#UPDATED} and {@link Operation#DELETED}.
-        */
-       private static enum Operation {
-               CREATED("created"), UPDATED("updated"), DELETED("deleted");
-
-               private final String value;
-
-               private Operation(String value) {
-                       this.value = value;
-               }
-       }
+    private static final Logger logger = LoggerFactory
+            .getLogger(ListenerAdapter.class);
+    private final XmlMapper xmlMapper = new XmlMapper();
+    private final SimpleDateFormat rfc3339 = new SimpleDateFormat(
+            "yyyy-MM-dd'T'hh:mm:ssZ");
+
+    private final InstanceIdentifier path;
+    private ListenerRegistration<DataChangeListener> registration;
+    private final String streamName;
+    private Set<Channel> subscribers = new ConcurrentSet<>();
+    private final EventBus eventBus;
+    private final EventBusChangeRecorder eventBusChangeRecorder;
+
+    /**
+     * Creates new {@link ListenerAdapter} listener specified by path and stream
+     * name.
+     *
+     * @param path
+     *            Path to data in data store.
+     * @param streamName
+     *            The name of the stream.
+     */
+    ListenerAdapter(InstanceIdentifier path, String streamName) {
+        Preconditions.checkNotNull(path);
+        Preconditions
+                .checkArgument(streamName != null && !streamName.isEmpty());
+        this.path = path;
+        this.streamName = streamName;
+        eventBus = new AsyncEventBus(Executors.newSingleThreadExecutor());
+        eventBusChangeRecorder = new EventBusChangeRecorder();
+        eventBus.register(eventBusChangeRecorder);
+    }
+
+    @Override
+    public void onDataChanged(
+            DataChangeEvent<InstanceIdentifier, CompositeNode> change) {
+        if (!change.getCreatedConfigurationData().isEmpty()
+                || !change.getCreatedOperationalData().isEmpty()
+                || !change.getUpdatedConfigurationData().isEmpty()
+                || !change.getUpdatedOperationalData().isEmpty()
+                || !change.getRemovedConfigurationData().isEmpty()
+                || !change.getRemovedOperationalData().isEmpty()) {
+            String xml = prepareXmlFrom(change);
+            Event event = new Event(EventType.NOTIFY);
+            event.setData(xml);
+            eventBus.post(event);
+        }
+    }
+
+    /**
+     * Tracks events of data change by customer.
+     */
+    private final class EventBusChangeRecorder {
+        @Subscribe
+        public void recordCustomerChange(Event event) {
+            if (event.getType() == EventType.REGISTER) {
+                Channel subscriber = event.getSubscriber();
+                if (!subscribers.contains(subscriber)) {
+                    subscribers.add(subscriber);
+                }
+            } else if (event.getType() == EventType.DEREGISTER) {
+                subscribers.remove(event.getSubscriber());
+                Notificator
+                        .removeListenerIfNoSubscriberExists(ListenerAdapter.this);
+            } else if (event.getType() == EventType.NOTIFY) {
+                for (Channel subscriber : subscribers) {
+                    if (subscriber.isActive()) {
+                        logger.debug("Data are sent to subscriber {}:",
+                                subscriber.remoteAddress());
+                        subscriber.writeAndFlush(new TextWebSocketFrame(event
+                                .getData()));
+                    } else {
+                        logger.debug(
+                                "Subscriber {} is removed - channel is not active yet.",
+                                subscriber.remoteAddress());
+                        subscribers.remove(subscriber);
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Represents event of specific {@link EventType} type, holds data and
+     * {@link Channel} subscriber.
+     */
+    private final class Event {
+        private final EventType type;
+        private Channel subscriber;
+        private String data;
+
+        /**
+         * Creates new event specified by {@link EventType} type.
+         *
+         * @param type
+         *            EventType
+         */
+        public Event(EventType type) {
+            this.type = type;
+        }
+
+        /**
+         * Gets the {@link Channel} subscriber.
+         *
+         * @return Channel
+         */
+        public Channel getSubscriber() {
+            return subscriber;
+        }
+
+        /**
+         * Sets subscriber for event.
+         *
+         * @param subscriber
+         *            Channel
+         */
+        public void setSubscriber(Channel subscriber) {
+            this.subscriber = subscriber;
+        }
+
+        /**
+         * Gets event data.
+         *
+         * @return String representation of event data.
+         */
+        public String getData() {
+            return data;
+        }
+
+        /**
+         * Sets event data.
+         *
+         * @param String
+         *            data.
+         */
+        public void setData(String data) {
+            this.data = data;
+        }
+
+        /**
+         * Gets event type.
+         *
+         * @return The type of the event.
+         */
+        public EventType getType() {
+            return type;
+        }
+    }
+
+    /**
+     * Type of the event.
+     */
+    private enum EventType {
+        REGISTER, DEREGISTER, NOTIFY;
+    }
+
+    /**
+     * Prepare data in printable form and transform it to String.
+     *
+     * @param change
+     *            DataChangeEvent
+     * @return Data in printable form.
+     */
+    private String prepareXmlFrom(
+            DataChangeEvent<InstanceIdentifier, CompositeNode> change) {
+        Document doc = createDocument();
+        Element notificationElement = doc.createElementNS(
+                "urn:ietf:params:xml:ns:netconf:notification:1.0",
+                "notification");
+        doc.appendChild(notificationElement);
+
+        Element eventTimeElement = doc.createElement("eventTime");
+        eventTimeElement.setTextContent(toRFC3339(new Date()));
+        notificationElement.appendChild(eventTimeElement);
+
+        Element dataChangedNotificationEventElement = doc.createElementNS(
+                "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote",
+                "data-changed-notification");
+        addValuesToDataChangedNotificationEventElement(doc,
+                dataChangedNotificationEventElement, change);
+        notificationElement.appendChild(dataChangedNotificationEventElement);
+
+        try {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            TransformerFactory tf = TransformerFactory.newInstance();
+            Transformer transformer = tf.newTransformer();
+            transformer
+                    .setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+            transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+            transformer.setOutputProperty(
+                    "{http://xml.apache.org/xslt}indent-amount", "4");
+            transformer.transform(new DOMSource(doc), new StreamResult(
+                    new OutputStreamWriter(out, "UTF-8")));
+            byte[] charData = out.toByteArray();
+            return new String(charData, "UTF-8");
+        } catch (TransformerException | UnsupportedEncodingException e) {
+            String msg = "Error during transformation of Document into String";
+            logger.error(msg, e);
+            return msg;
+        }
+    }
+
+    /**
+     * Formats data specified by RFC3339.
+     *
+     * @param d
+     *            Date
+     * @return Data specified by RFC3339.
+     */
+    private String toRFC3339(Date d) {
+        return rfc3339.format(d).replaceAll("(\\d\\d)(\\d\\d)$", "$1:$2");
+    }
+
+    /**
+     * Creates {@link Document} document.
+     *
+     * @return {@link Document} document.
+     */
+    private Document createDocument() {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        Document doc = null;
+        try {
+            DocumentBuilder bob = dbf.newDocumentBuilder();
+            doc = bob.newDocument();
+        } catch (ParserConfigurationException e) {
+            return null;
+        }
+        return doc;
+    }
+
+    /**
+     * Adds values to data changed notification event element.
+     *
+     * @param doc
+     *            {@link Document}
+     * @param dataChangedNotificationEventElement
+     *            {@link Element}
+     * @param change
+     *            {@link DataChangeEvent}
+     */
+    private void addValuesToDataChangedNotificationEventElement(Document doc,
+            Element dataChangedNotificationEventElement,
+            DataChangeEvent<InstanceIdentifier, CompositeNode> change) {
+        addValuesFromDataToElement(doc, change.getCreatedConfigurationData(),
+                dataChangedNotificationEventElement, Store.CONFIG,
+                Operation.CREATED);
+        addValuesFromDataToElement(doc, change.getCreatedOperationalData(),
+                dataChangedNotificationEventElement, Store.OPERATION,
+                Operation.CREATED);
+        if (change.getCreatedConfigurationData().isEmpty()) {
+            addValuesFromDataToElement(doc,
+                    change.getUpdatedConfigurationData(),
+                    dataChangedNotificationEventElement, Store.CONFIG,
+                    Operation.UPDATED);
+        }
+        if (change.getCreatedOperationalData().isEmpty()) {
+            addValuesFromDataToElement(doc, change.getUpdatedOperationalData(),
+                    dataChangedNotificationEventElement, Store.OPERATION,
+                    Operation.UPDATED);
+        }
+        addValuesFromDataToElement(doc, change.getRemovedConfigurationData(),
+                dataChangedNotificationEventElement, Store.CONFIG,
+                Operation.DELETED);
+        addValuesFromDataToElement(doc, change.getRemovedOperationalData(),
+                dataChangedNotificationEventElement, Store.OPERATION,
+                Operation.DELETED);
+    }
+
+    /**
+     * Adds values from data to element.
+     *
+     * @param doc
+     *            {@link Document}
+     * @param data
+     *            Set of {@link InstanceIdentifier}.
+     * @param element
+     *            {@link Element}
+     * @param store
+     *            {@link Store}
+     * @param operation
+     *            {@link Operation}
+     */
+    private void addValuesFromDataToElement(Document doc,
+            Set<InstanceIdentifier> data, Element element, Store store,
+            Operation operation) {
+        if (data == null || data.isEmpty()) {
+            return;
+        }
+        for (InstanceIdentifier path : data) {
+            Node node = createDataChangeEventElement(doc, path, null, store,
+                    operation);
+            element.appendChild(node);
+        }
+    }
+
+    /**
+     * Adds values from data to element.
+     *
+     * @param doc
+     *            {@link Document}
+     * @param data
+     *            Map of {@link InstanceIdentifier} and {@link CompositeNode}.
+     * @param element
+     *            {@link Element}
+     * @param store
+     *            {@link Store}
+     * @param operation
+     *            {@link Operation}
+     */
+    private void addValuesFromDataToElement(Document doc,
+            Map<InstanceIdentifier, CompositeNode> data, Element element,
+            Store store, Operation operation) {
+        if (data == null || data.isEmpty()) {
+            return;
+        }
+        for (Entry<InstanceIdentifier, CompositeNode> entry : data.entrySet()) {
+            Node node = createDataChangeEventElement(doc, entry.getKey(),
+                    entry.getValue(), store, operation);
+            element.appendChild(node);
+        }
+    }
+
+    /**
+     * Creates changed event element from data.
+     *
+     * @param doc
+     *            {@link Document}
+     * @param path
+     *            Path to data in data store.
+     * @param data
+     *            {@link CompositeNode}
+     * @param store
+     *            {@link Store}
+     * @param operation
+     *            {@link Operation}
+     * @return {@link Node} node represented by changed event element.
+     */
+    private Node createDataChangeEventElement(Document doc,
+            InstanceIdentifier path, CompositeNode data, Store store,
+            Operation operation) {
+        Element dataChangeEventElement = doc.createElement("data-change-event");
+
+        Element pathElement = doc.createElement("path");
+        addPathAsValueToElement(path, pathElement);
+        dataChangeEventElement.appendChild(pathElement);
+
+        Element storeElement = doc.createElement("store");
+        storeElement.setTextContent(store.value);
+        dataChangeEventElement.appendChild(storeElement);
+
+        Element operationElement = doc.createElement("operation");
+        operationElement.setTextContent(operation.value);
+        dataChangeEventElement.appendChild(operationElement);
+
+        if (data != null) {
+            Element dataElement = doc.createElement("data");
+            Node dataAnyXml = translateToXml(path, data);
+            Node adoptedNode = doc.adoptNode(dataAnyXml);
+            dataElement.appendChild(adoptedNode);
+            dataChangeEventElement.appendChild(dataElement);
+        }
+
+        return dataChangeEventElement;
+    }
+
+    /**
+     * Translates {@link CompositeNode} data to XML format.
+     *
+     * @param path
+     *            Path to data in data store.
+     * @param data
+     *            {@link CompositeNode}
+     * @return Data in XML format.
+     */
+    private Node translateToXml(InstanceIdentifier path, CompositeNode data) {
+        DataNodeContainer schemaNode = ControllerContext.getInstance()
+                .getDataNodeContainerFor(path);
+        if (schemaNode == null) {
+            logger.info(
+                    "Path '{}' contains node with unsupported type (supported type is Container or List) or some node was not found.",
+                    path);
+            return null;
+        }
+        try {
+            Document xml = xmlMapper.write(data, schemaNode);
+            return xml.getFirstChild();
+        } catch (UnsupportedDataTypeException e) {
+            logger.error(
+                    "Error occured during translation of notification to XML.",
+                    e);
+            return null;
+        }
+    }
+
+    /**
+     * Adds path as value to element.
+     *
+     * @param path
+     *            Path to data in data store.
+     * @param element
+     *            {@link Element}
+     */
+    private void addPathAsValueToElement(InstanceIdentifier path,
+            Element element) {
+        // Map< key = namespace, value = prefix>
+        Map<String, String> prefixes = new HashMap<>();
+        InstanceIdentifier instanceIdentifier = path;
+        StringBuilder textContent = new StringBuilder();
+        for (PathArgument pathArgument : instanceIdentifier.getPath()) {
+            textContent.append("/");
+            writeIdentifierWithNamespacePrefix(element, textContent,
+                    pathArgument.getNodeType(), prefixes);
+            if (pathArgument instanceof NodeIdentifierWithPredicates) {
+                Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArgument)
+                        .getKeyValues();
+                for (QName keyValue : predicates.keySet()) {
+                    String predicateValue = String.valueOf(predicates
+                            .get(keyValue));
+                    textContent.append("[");
+                    writeIdentifierWithNamespacePrefix(element, textContent,
+                            keyValue, prefixes);
+                    textContent.append("='");
+                    textContent.append(predicateValue);
+                    textContent.append("'");
+                    textContent.append("]");
+                }
+            } else if (pathArgument instanceof NodeWithValue) {
+                textContent.append("[.='");
+                textContent.append(((NodeWithValue) pathArgument).getValue());
+                textContent.append("'");
+                textContent.append("]");
+            }
+        }
+        element.setTextContent(textContent.toString());
+    }
+
+    /**
+     * Writes identifier that consists of prefix and QName.
+     *
+     * @param element
+     *            {@link Element}
+     * @param textContent
+     *            StringBuilder
+     * @param qName
+     *            QName
+     * @param prefixes
+     *            Map of namespaces and prefixes.
+     */
+    private static void writeIdentifierWithNamespacePrefix(Element element,
+            StringBuilder textContent, QName qName, Map<String, String> prefixes) {
+        String namespace = qName.getNamespace().toString();
+        String prefix = prefixes.get(namespace);
+        if (prefix == null) {
+            prefix = qName.getPrefix();
+            if (prefix == null || prefix.isEmpty()
+                    || prefixes.containsValue(prefix)) {
+                prefix = generateNewPrefix(prefixes.values());
+            }
+        }
+
+        element.setAttribute("xmlns:" + prefix, namespace);
+        textContent.append(prefix);
+        prefixes.put(namespace, prefix);
+
+        textContent.append(":");
+        textContent.append(qName.getLocalName());
+    }
+
+    /**
+     * Generates new prefix which consists of four random characters <a-z>.
+     *
+     * @param prefixes
+     *            Collection of prefixes.
+     * @return New prefix which consists of four random characters <a-z>.
+     */
+    private static String generateNewPrefix(Collection<String> prefixes) {
+        StringBuilder result = null;
+        Random random = new Random();
+        do {
+            result = new StringBuilder();
+            for (int i = 0; i < 4; i++) {
+                int randomNumber = 0x61 + (Math.abs(random.nextInt()) % 26);
+                result.append(Character.toChars(randomNumber));
+            }
+        } while (prefixes.contains(result.toString()));
+
+        return result.toString();
+    }
+
+    /**
+     * Gets path pointed to data in data store.
+     *
+     * @return Path pointed to data in data store.
+     */
+    public InstanceIdentifier getPath() {
+        return path;
+    }
+
+    /**
+     * Sets {@link ListenerRegistration} registration.
+     *
+     * @param registration
+     *            ListenerRegistration<DataChangeListener>
+     */
+    public void setRegistration(
+            ListenerRegistration<DataChangeListener> registration) {
+        this.registration = registration;
+    }
+
+    /**
+     * Gets the name of the stream.
+     *
+     * @return The name of the stream.
+     */
+    public String getStreamName() {
+        return streamName;
+    }
+
+    /**
+     * Removes all subscribers and unregisters event bus change recorder form
+     * event bus.
+     */
+    public void close() throws Exception {
+        subscribers = new ConcurrentSet<>();
+        registration.close();
+        registration = null;
+        eventBus.unregister(eventBusChangeRecorder);
+    }
+
+    /**
+     * Checks if {@link ListenerRegistration} registration exist.
+     *
+     * @return True if exist, false otherwise.
+     */
+    public boolean isListening() {
+        return registration == null ? false : true;
+    }
+
+    /**
+     * Creates event of type {@link EventType#REGISTER}, set {@link Channel}
+     * subscriber to the event and post event into event bus.
+     *
+     * @param subscriber
+     *            Channel
+     */
+    public void addSubscriber(Channel subscriber) {
+        if (!subscriber.isActive()) {
+            logger.debug("Channel is not active between websocket server and subscriber {}"
+                    + subscriber.remoteAddress());
+        }
+        Event event = new Event(EventType.REGISTER);
+        event.setSubscriber(subscriber);
+        eventBus.post(event);
+    }
+
+    /**
+     * Creates event of type {@link EventType#DEREGISTER}, sets {@link Channel}
+     * subscriber to the event and posts event into event bus.
+     *
+     * @param subscriber
+     */
+    public void removeSubscriber(Channel subscriber) {
+        logger.debug("Subscriber {} is removed.", subscriber.remoteAddress());
+        Event event = new Event(EventType.DEREGISTER);
+        event.setSubscriber(subscriber);
+        eventBus.post(event);
+    }
+
+    /**
+     * Checks if exists at least one {@link Channel} subscriber.
+     *
+     * @return True if exist at least one {@link Channel} subscriber, false
+     *         otherwise.
+     */
+    public boolean hasSubscribers() {
+        return !subscribers.isEmpty();
+    }
+
+    /**
+     * Consists of two types {@link Store#CONFIG} and {@link Store#OPERATION}.
+     */
+    private static enum Store {
+        CONFIG("config"), OPERATION("operation");
+
+        private final String value;
+
+        private Store(String value) {
+            this.value = value;
+        }
+    }
+
+    /**
+     * Consists of three types {@link Operation#CREATED},
+     * {@link Operation#UPDATED} and {@link Operation#DELETED}.
+     */
+    private static enum Operation {
+        CREATED("created"), UPDATED("updated"), DELETED("deleted");
+
+        private final String value;
+
+        private Operation(String value) {
+            this.value = value;
+        }
+    }
 
 }
index 6f154f8affa66ed57dd6a4f6fa1952f99b31bb59..a576eed26978fb0380cd8a28613712409bf6ce53 100644 (file)
@@ -21,11 +21,11 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 public class Notificator {
 
     private static Map<String, ListenerAdapter> listenersByStreamName = new ConcurrentHashMap<>();
-       private static Map<InstanceIdentifier, ListenerAdapter> listenersByInstanceIdentifier = new ConcurrentHashMap<>();
-       private static final Lock lock = new ReentrantLock();
+    private static Map<InstanceIdentifier, ListenerAdapter> listenersByInstanceIdentifier = new ConcurrentHashMap<>();
+    private static final Lock lock = new ReentrantLock();
 
-       private Notificator() {
-       }
+    private Notificator() {
+    }
 
     /**
      * Returns list of all stream names
@@ -35,152 +35,152 @@ public class Notificator {
     }
 
 
-       /**
-        * Gets {@link ListenerAdapter} specified by stream name.
-        * 
-        * @param streamName
-        *            The name of the stream.
-        * @return {@link ListenerAdapter} specified by stream name.
-        */
-       public static ListenerAdapter getListenerFor(String streamName) {
-               return listenersByStreamName.get(streamName);
-       }
-
-       /**
-        * Gets {@link ListenerAdapter} listener specified by
-        * {@link InstanceIdentifier} path.
-        * 
-        * @param path
-        *            Path to data in data repository.
-        * @return ListenerAdapter
-        */
-       public static ListenerAdapter getListenerFor(InstanceIdentifier path) {
-               return listenersByInstanceIdentifier.get(path);
-       }
-
-       /**
-        * Checks if the listener specified by {@link InstanceIdentifier} path
-        * exist.
-        * 
-        * @param path
-        *            Path to data in data repository.
-        * @return True if the listener exist, false otherwise.
-        */
-       public static boolean existListenerFor(InstanceIdentifier path) {
-               return listenersByInstanceIdentifier.containsKey(path);
-       }
-
-       /**
-        * Creates new {@link ListenerAdapter} listener from
-        * {@link InstanceIdentifier} path and stream name.
-        * 
-        * @param path
-        *            Path to data in data repository.
-        * @param streamName
-        *            The name of the stream.
-        * @return New {@link ListenerAdapter} listener from
-        *         {@link InstanceIdentifier} path and stream name.
-        */
-       public static ListenerAdapter createListener(InstanceIdentifier path,
-                       String streamName) {
-               ListenerAdapter listener = new ListenerAdapter(path, streamName);
-               try {
-                       lock.lock();
-                       listenersByInstanceIdentifier.put(path, listener);
-                       listenersByStreamName.put(streamName, listener);
-               } finally {
-                       lock.unlock();
-               }
-               return listener;
-       }
-
-       /**
-        * Looks for listener determined by {@link InstanceIdentifier} path and
-        * removes it.
-        * 
-        * @param path
-        *            InstanceIdentifier
-        */
-       public static void removeListener(InstanceIdentifier path) {
-               ListenerAdapter listener = listenersByInstanceIdentifier.get(path);
-               deleteListener(listener);
-       }
-
-       /**
-        * Creates String representation of stream name from URI. Removes slash from
-        * URI in start and end position.
-        * 
-        * @param uri
-        *            URI for creation stream name.
-        * @return String representation of stream name.
-        */
-       public static String createStreamNameFromUri(String uri) {
-               if (uri == null) {
-                       return null;
-               }
-               String result = uri;
-               if (result.startsWith("/")) {
-                       result = result.substring(1);
-               }
-               if (result.endsWith("/")) {
-                       result = result.substring(0, result.length());
-               }
-               return result;
-       }
-
-       /**
-        * Removes all listeners.
-        */
-       public static void removeAllListeners() {
-               for (ListenerAdapter listener : listenersByInstanceIdentifier.values()) {
-                       try {
-                               listener.close();
-                       } catch (Exception e) {
-                       }
-               }
-               try {
-                       lock.lock();
-                       listenersByStreamName = new ConcurrentHashMap<>();
-                       listenersByInstanceIdentifier = new ConcurrentHashMap<>();
-               } finally {
-                       lock.unlock();
-               }
-       }
-
-       /**
-        * Checks if listener has at least one subscriber. In case it doesn't have any, delete
-        * listener.
-        * 
-        * @param listener
-        *            ListenerAdapter
-        */
-       public static void removeListenerIfNoSubscriberExists(
-                       ListenerAdapter listener) {
-               if (!listener.hasSubscribers()) {
-                       deleteListener(listener);
-               }
-       }
-
-       /**
-        * Delete {@link ListenerAdapter} listener specified in parameter.
-        * 
-        * @param listener
-        *            ListenerAdapter
-        */
-       private static void deleteListener(ListenerAdapter listener) {
-               if (listener != null) {
-                       try {
-                               listener.close();
-                       } catch (Exception e) {
-                       }
-                       try {
-                               lock.lock();
-                               listenersByInstanceIdentifier.remove(listener.getPath());
-                               listenersByStreamName.remove(listener.getStreamName());
-                       } finally {
-                               lock.unlock();
-                       }
-               }
-       }
+    /**
+     * Gets {@link ListenerAdapter} specified by stream name.
+     *
+     * @param streamName
+     *            The name of the stream.
+     * @return {@link ListenerAdapter} specified by stream name.
+     */
+    public static ListenerAdapter getListenerFor(String streamName) {
+        return listenersByStreamName.get(streamName);
+    }
+
+    /**
+     * Gets {@link ListenerAdapter} listener specified by
+     * {@link InstanceIdentifier} path.
+     *
+     * @param path
+     *            Path to data in data repository.
+     * @return ListenerAdapter
+     */
+    public static ListenerAdapter getListenerFor(InstanceIdentifier path) {
+        return listenersByInstanceIdentifier.get(path);
+    }
+
+    /**
+     * Checks if the listener specified by {@link InstanceIdentifier} path
+     * exist.
+     *
+     * @param path
+     *            Path to data in data repository.
+     * @return True if the listener exist, false otherwise.
+     */
+    public static boolean existListenerFor(InstanceIdentifier path) {
+        return listenersByInstanceIdentifier.containsKey(path);
+    }
+
+    /**
+     * Creates new {@link ListenerAdapter} listener from
+     * {@link InstanceIdentifier} path and stream name.
+     *
+     * @param path
+     *            Path to data in data repository.
+     * @param streamName
+     *            The name of the stream.
+     * @return New {@link ListenerAdapter} listener from
+     *         {@link InstanceIdentifier} path and stream name.
+     */
+    public static ListenerAdapter createListener(InstanceIdentifier path,
+            String streamName) {
+        ListenerAdapter listener = new ListenerAdapter(path, streamName);
+        try {
+            lock.lock();
+            listenersByInstanceIdentifier.put(path, listener);
+            listenersByStreamName.put(streamName, listener);
+        } finally {
+            lock.unlock();
+        }
+        return listener;
+    }
+
+    /**
+     * Looks for listener determined by {@link InstanceIdentifier} path and
+     * removes it.
+     *
+     * @param path
+     *            InstanceIdentifier
+     */
+    public static void removeListener(InstanceIdentifier path) {
+        ListenerAdapter listener = listenersByInstanceIdentifier.get(path);
+        deleteListener(listener);
+    }
+
+    /**
+     * Creates String representation of stream name from URI. Removes slash from
+     * URI in start and end position.
+     *
+     * @param uri
+     *            URI for creation stream name.
+     * @return String representation of stream name.
+     */
+    public static String createStreamNameFromUri(String uri) {
+        if (uri == null) {
+            return null;
+        }
+        String result = uri;
+        if (result.startsWith("/")) {
+            result = result.substring(1);
+        }
+        if (result.endsWith("/")) {
+            result = result.substring(0, result.length());
+        }
+        return result;
+    }
+
+    /**
+     * Removes all listeners.
+     */
+    public static void removeAllListeners() {
+        for (ListenerAdapter listener : listenersByInstanceIdentifier.values()) {
+            try {
+                listener.close();
+            } catch (Exception e) {
+            }
+        }
+        try {
+            lock.lock();
+            listenersByStreamName = new ConcurrentHashMap<>();
+            listenersByInstanceIdentifier = new ConcurrentHashMap<>();
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    /**
+     * Checks if listener has at least one subscriber. In case it doesn't have any, delete
+     * listener.
+     *
+     * @param listener
+     *            ListenerAdapter
+     */
+    public static void removeListenerIfNoSubscriberExists(
+            ListenerAdapter listener) {
+        if (!listener.hasSubscribers()) {
+            deleteListener(listener);
+        }
+    }
+
+    /**
+     * Delete {@link ListenerAdapter} listener specified in parameter.
+     *
+     * @param listener
+     *            ListenerAdapter
+     */
+    private static void deleteListener(ListenerAdapter listener) {
+        if (listener != null) {
+            try {
+                listener.close();
+            } catch (Exception e) {
+            }
+            try {
+                lock.lock();
+                listenersByInstanceIdentifier.remove(listener.getPath());
+                listenersByStreamName.remove(listener.getStreamName());
+            } finally {
+                lock.unlock();
+            }
+        }
+    }
 
 }
index 16400354205a68cbf6993760f9dfa3fee04ec37a..fcfa8858ee940065baee9f4c8c4df2fb3a73089c 100644 (file)
@@ -16,45 +16,45 @@ import org.slf4j.LoggerFactory;
  */
 public class WebSocketServer implements Runnable {
 
-       private static final Logger logger = LoggerFactory
-                       .getLogger(WebSocketServer.class);
-
-       public static final int PORT = 8181;
-       private EventLoopGroup bossGroup;
-       private EventLoopGroup workerGroup;
-
-       @Override
-       public void run() {
-               bossGroup = new NioEventLoopGroup();
-               workerGroup = new NioEventLoopGroup();
-               try {
-                       ServerBootstrap b = new ServerBootstrap();
-                       b.group(bossGroup, workerGroup)
-                                       .channel(NioServerSocketChannel.class)
-                                       .childHandler(new WebSocketServerInitializer());
-
-                       Channel ch = b.bind(PORT).sync().channel();
-                       logger.info("Web socket server started at port {}.", PORT);
-
-                       ch.closeFuture().sync();
-               } catch (InterruptedException e) {
-                       // NOOP
-               } finally {
-                       stop();
-               }
-       }
-
-       /**
-        * Stops the web socket server and removes all listeners.
-        */
-       private void stop() {
-               Notificator.removeAllListeners();
-               if (bossGroup != null) {
-                       bossGroup.shutdownGracefully();
-               }
-               if (workerGroup != null) {
-                       workerGroup.shutdownGracefully();
-               }
-       }
+    private static final Logger logger = LoggerFactory
+            .getLogger(WebSocketServer.class);
+
+    public static final int PORT = 8181;
+    private EventLoopGroup bossGroup;
+    private EventLoopGroup workerGroup;
+
+    @Override
+    public void run() {
+        bossGroup = new NioEventLoopGroup();
+        workerGroup = new NioEventLoopGroup();
+        try {
+            ServerBootstrap b = new ServerBootstrap();
+            b.group(bossGroup, workerGroup)
+                    .channel(NioServerSocketChannel.class)
+                    .childHandler(new WebSocketServerInitializer());
+
+            Channel ch = b.bind(PORT).sync().channel();
+            logger.info("Web socket server started at port {}.", PORT);
+
+            ch.closeFuture().sync();
+        } catch (InterruptedException e) {
+            // NOOP
+        } finally {
+            stop();
+        }
+    }
+
+    /**
+     * Stops the web socket server and removes all listeners.
+     */
+    private void stop() {
+        Notificator.removeAllListeners();
+        if (bossGroup != null) {
+            bossGroup.shutdownGracefully();
+        }
+        if (workerGroup != null) {
+            workerGroup.shutdownGracefully();
+        }
+    }
 
 }
index bf899a0b2521297603b5d538e0c5158e31dba2d7..b5d6a6ea9be647d22c1dc8a75609506433e850f6 100644 (file)
@@ -40,147 +40,147 @@ import org.slf4j.LoggerFactory;
  */
 public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object> {
 
-       private static final Logger logger = LoggerFactory
-                       .getLogger(WebSocketServerHandler.class);
-
-       private WebSocketServerHandshaker handshaker;
-
-       @Override
-       protected void channelRead0(ChannelHandlerContext ctx, Object msg)
-                       throws Exception {
-               if (msg instanceof FullHttpRequest) {
-                       handleHttpRequest(ctx, (FullHttpRequest) msg);
-               } else if (msg instanceof WebSocketFrame) {
-                       handleWebSocketFrame(ctx, (WebSocketFrame) msg);
-               }
-       }
-
-       /**
-        * Checks if HTTP request method is GET and if is possible to decode HTTP
-        * result of request.
-        * 
-        * @param ctx
-        *            ChannelHandlerContext
-        * @param req
-        *            FullHttpRequest
-        */
-       private void handleHttpRequest(ChannelHandlerContext ctx,
-                       FullHttpRequest req) throws Exception {
-               // Handle a bad request.
-               if (!req.getDecoderResult().isSuccess()) {
-                       sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
-                                       BAD_REQUEST));
-                       return;
-               }
-
-               // Allow only GET methods.
-               if (req.getMethod() != GET) {
-                       sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
-                                       FORBIDDEN));
-                       return;
-               }
-
-               String streamName = Notificator.createStreamNameFromUri(req.getUri());
-               ListenerAdapter listener = Notificator.getListenerFor(streamName);
-               if (listener != null) {
-                       listener.addSubscriber(ctx.channel());
-                       logger.debug("Subscriber successfully registered.");
-               } else {
-                       logger.error("Listener for stream with name '{}' was not found.",
-                                       streamName);
-                       sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
-                                       INTERNAL_SERVER_ERROR));
-               }
-
-               // Handshake
-               WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
-                               getWebSocketLocation(req), null, false);
-               handshaker = wsFactory.newHandshaker(req);
-               if (handshaker == null) {
-                       WebSocketServerHandshakerFactory
-                                       .sendUnsupportedWebSocketVersionResponse(ctx.channel());
-               } else {
-                       handshaker.handshake(ctx.channel(), req);
-               }
-
-       }
-
-       /**
-        * Checks response status, send response and close connection if necessary
-        * 
-        * @param ctx
-        *            ChannelHandlerContext
-        * @param req
-        *            HttpRequest
-        * @param res
-        *            FullHttpResponse
-        */
-       private static void sendHttpResponse(ChannelHandlerContext ctx,
-                       HttpRequest req, FullHttpResponse res) {
-               // Generate an error page if response getStatus code is not OK (200).
-               if (res.getStatus().code() != 200) {
-                       ByteBuf buf = Unpooled.copiedBuffer(res.getStatus().toString(),
-                                       CharsetUtil.UTF_8);
-                       res.content().writeBytes(buf);
-                       buf.release();
-                       setContentLength(res, res.content().readableBytes());
-               }
-
-               // Send the response and close the connection if necessary.
-               ChannelFuture f = ctx.channel().writeAndFlush(res);
-               if (!isKeepAlive(req) || res.getStatus().code() != 200) {
-                       f.addListener(ChannelFutureListener.CLOSE);
-               }
-       }
-
-       /**
-        * Handles web socket frame.
-        * 
-        * @param ctx
-        *            {@link ChannelHandlerContext}
-        * @param frame
-        *            {@link WebSocketFrame}
-        */
-       private void handleWebSocketFrame(ChannelHandlerContext ctx,
-                       WebSocketFrame frame) throws IOException {
-               if (frame instanceof CloseWebSocketFrame) {
-                       handshaker.close(ctx.channel(),
-                                       (CloseWebSocketFrame) frame.retain());
-                       String streamName = Notificator
-                                       .createStreamNameFromUri(((CloseWebSocketFrame) frame)
-                                                       .reasonText());
-                       ListenerAdapter listener = Notificator.getListenerFor(streamName);
-                       if (listener != null) {
-                               listener.removeSubscriber(ctx.channel());
-                               logger.debug("Subscriber successfully registered.");
-                       }
-                       Notificator.removeListenerIfNoSubscriberExists(listener);
-                       return;
-               } else if (frame instanceof PingWebSocketFrame) {
-                       ctx.channel().write(
-                                       new PongWebSocketFrame(frame.content().retain()));
-                       return;
-               }
-       }
-
-       @Override
-       public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
-                       throws Exception {
-               if (cause instanceof java.nio.channels.ClosedChannelException == false) {
-                       // cause.printStackTrace();
-               }
-               ctx.close();
-       }
-
-       /**
-        * Get web socket location from HTTP request.
-        * 
-        * @param req
-        *            HTTP request from which the location will be returned
-        * @return String representation of web socket location.
-        */
-       private static String getWebSocketLocation(HttpRequest req) {
-               return "http://" + req.headers().get(HOST) + req.getUri();
-       }
+    private static final Logger logger = LoggerFactory
+            .getLogger(WebSocketServerHandler.class);
+
+    private WebSocketServerHandshaker handshaker;
+
+    @Override
+    protected void channelRead0(ChannelHandlerContext ctx, Object msg)
+            throws Exception {
+        if (msg instanceof FullHttpRequest) {
+            handleHttpRequest(ctx, (FullHttpRequest) msg);
+        } else if (msg instanceof WebSocketFrame) {
+            handleWebSocketFrame(ctx, (WebSocketFrame) msg);
+        }
+    }
+
+    /**
+     * Checks if HTTP request method is GET and if is possible to decode HTTP
+     * result of request.
+     *
+     * @param ctx
+     *            ChannelHandlerContext
+     * @param req
+     *            FullHttpRequest
+     */
+    private void handleHttpRequest(ChannelHandlerContext ctx,
+            FullHttpRequest req) throws Exception {
+        // Handle a bad request.
+        if (!req.getDecoderResult().isSuccess()) {
+            sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
+                    BAD_REQUEST));
+            return;
+        }
+
+        // Allow only GET methods.
+        if (req.getMethod() != GET) {
+            sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
+                    FORBIDDEN));
+            return;
+        }
+
+        String streamName = Notificator.createStreamNameFromUri(req.getUri());
+        ListenerAdapter listener = Notificator.getListenerFor(streamName);
+        if (listener != null) {
+            listener.addSubscriber(ctx.channel());
+            logger.debug("Subscriber successfully registered.");
+        } else {
+            logger.error("Listener for stream with name '{}' was not found.",
+                    streamName);
+            sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
+                    INTERNAL_SERVER_ERROR));
+        }
+
+        // Handshake
+        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
+                getWebSocketLocation(req), null, false);
+        handshaker = wsFactory.newHandshaker(req);
+        if (handshaker == null) {
+            WebSocketServerHandshakerFactory
+                    .sendUnsupportedWebSocketVersionResponse(ctx.channel());
+        } else {
+            handshaker.handshake(ctx.channel(), req);
+        }
+
+    }
+
+    /**
+     * Checks response status, send response and close connection if necessary
+     *
+     * @param ctx
+     *            ChannelHandlerContext
+     * @param req
+     *            HttpRequest
+     * @param res
+     *            FullHttpResponse
+     */
+    private static void sendHttpResponse(ChannelHandlerContext ctx,
+            HttpRequest req, FullHttpResponse res) {
+        // Generate an error page if response getStatus code is not OK (200).
+        if (res.getStatus().code() != 200) {
+            ByteBuf buf = Unpooled.copiedBuffer(res.getStatus().toString(),
+                    CharsetUtil.UTF_8);
+            res.content().writeBytes(buf);
+            buf.release();
+            setContentLength(res, res.content().readableBytes());
+        }
+
+        // Send the response and close the connection if necessary.
+        ChannelFuture f = ctx.channel().writeAndFlush(res);
+        if (!isKeepAlive(req) || res.getStatus().code() != 200) {
+            f.addListener(ChannelFutureListener.CLOSE);
+        }
+    }
+
+    /**
+     * Handles web socket frame.
+     *
+     * @param ctx
+     *            {@link ChannelHandlerContext}
+     * @param frame
+     *            {@link WebSocketFrame}
+     */
+    private void handleWebSocketFrame(ChannelHandlerContext ctx,
+            WebSocketFrame frame) throws IOException {
+        if (frame instanceof CloseWebSocketFrame) {
+            handshaker.close(ctx.channel(),
+                    (CloseWebSocketFrame) frame.retain());
+            String streamName = Notificator
+                    .createStreamNameFromUri(((CloseWebSocketFrame) frame)
+                            .reasonText());
+            ListenerAdapter listener = Notificator.getListenerFor(streamName);
+            if (listener != null) {
+                listener.removeSubscriber(ctx.channel());
+                logger.debug("Subscriber successfully registered.");
+            }
+            Notificator.removeListenerIfNoSubscriberExists(listener);
+            return;
+        } else if (frame instanceof PingWebSocketFrame) {
+            ctx.channel().write(
+                    new PongWebSocketFrame(frame.content().retain()));
+            return;
+        }
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
+            throws Exception {
+        if (cause instanceof java.nio.channels.ClosedChannelException == false) {
+            // cause.printStackTrace();
+        }
+        ctx.close();
+    }
+
+    /**
+     * Get web socket location from HTTP request.
+     *
+     * @param req
+     *            HTTP request from which the location will be returned
+     * @return String representation of web socket location.
+     */
+    private static String getWebSocketLocation(HttpRequest req) {
+        return "http://" + req.headers().get(HOST) + req.getUri();
+    }
 
 }
index 65ae5d6fab1af08b9aaabaed03e1cd824513fa7f..d188a029e7582a7672a67af0a956f978df79cc1b 100644 (file)
@@ -1,6 +1,5 @@
 package org.opendaylight.controller.sal.streams.websockets;
 
-import io.netty.channel.Channel;
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelPipeline;
 import io.netty.channel.socket.SocketChannel;
@@ -9,17 +8,16 @@ import io.netty.handler.codec.http.HttpServerCodec;
 
 /**
  * {@link WebSocketServerInitializer} is used to setup the
- * {@link ChannelPipeline} of a {@link Channel}.
+ * {@link ChannelPipeline} of a {@link io.netty.channel.Channel}.
  */
-public class WebSocketServerInitializer extends
-               ChannelInitializer<SocketChannel> {
+public class WebSocketServerInitializer extends ChannelInitializer<SocketChannel> {
 
-       @Override
-       protected void initChannel(SocketChannel ch) throws Exception {
-               ChannelPipeline pipeline = ch.pipeline();
-               pipeline.addLast("codec-http", new HttpServerCodec());
-               pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
-               pipeline.addLast("handler", new WebSocketServerHandler());
-       }
+    @Override
+    protected void initChannel(final SocketChannel ch) throws Exception {
+        ChannelPipeline pipeline = ch.pipeline();
+        pipeline.addLast("codec-http", new HttpServerCodec());
+        pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
+        pipeline.addLast("handler", new WebSocketServerHandler());
+    }
 
 }
index 840887ecec60920372b9d343283e4fd852c68dd4..f39eae45424941355b2d9a7291d62eea744048a4 100644 (file)
         <url-pattern>/*</url-pattern>
     </servlet-mapping>
 
-    <filter>
-        <filter-name>CorsFilter</filter-name>
-        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
-        <init-param>
-            <param-name>cors.allowed.origins</param-name>
-            <param-value>*</param-value>
-        </init-param>
-        <init-param>
-            <param-name>cors.allowed.methods</param-name>
-            <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
-        </init-param>
-        <init-param>
-            <param-name>cors.allowed.headers</param-name>
-            <param-value>Content-Type,X-Requested-With,accept,authorization, 
-        origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
-        </init-param>
-        <init-param>
-            <param-name>cors.exposed.headers</param-name>
-            <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
-        </init-param>
-        <init-param>
-            <param-name>cors.support.credentials</param-name>
-            <param-value>true</param-value>
-        </init-param>
-        <init-param>
-            <param-name>cors.preflight.maxage</param-name>
-            <param-value>10</param-value>
-        </init-param>
-    </filter>
-    <filter-mapping>
-        <filter-name>CorsFilter</filter-name>
-        <url-pattern>/*</url-pattern>
-    </filter-mapping>
     <security-constraint>
         <web-resource-collection>
             <web-resource-name>NB api</web-resource-name>
index 8abf366bf7153dea82055de0ded4c816accffebd..21590ecb335fa81c309012bc34b92c1975da169c 100644 (file)
@@ -32,7 +32,7 @@ public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
      * Test when some data are in one case node and other in another. This isn't
      * correct. Next Json validator should return error because nodes has to be
      * from one case below concrete choice.
-     * 
+     *
      */
     @Test
     public void nodeSchemasOnVariousChoiceCasePathTest() {
@@ -44,7 +44,7 @@ public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
      * Additionally data are loadef from various choices. This isn't correct.
      * Next Json validator should return error because nodes has to be from one
      * case below concrete choice.
-     * 
+     *
      */
     @Test
     public void nodeSchemasOnVariousChoiceCasePathAndMultipleChoicesTest() {
@@ -95,7 +95,7 @@ public class CnSnJsonChoiceCaseTest extends YangAndXmlAndDataSchemaLoader {
     }
 
     /**
-     * 
+     *
      */
     @Test
     public void nodeSchemasInMultipleChoicesTest() {
index 4e32e7058ca6cce63f9a38760764b0b0c137ddf7..1ec7253b8d595dea9ef3e62a05decbd224178975 100644 (file)
@@ -221,7 +221,7 @@ public class CnSnToJsonBasicDataTypesTest extends YangAndXmlAndDataSchemaLoader
                 assertEquals( "Json token type for key " + keyName, expToken, peek );
             }
 
-            verifier.verify( jReader, keyName );;
+            verifier.verify( jReader, keyName );
         }
 
         if( !expectedMap.isEmpty() ) {
index 12555bc9a2501074741307db4bd7323c919be86d..21a46a6cc32b60de0e3db3c9c74e71c96e5385ec 100644 (file)
@@ -25,9 +25,9 @@ import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchem
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 /**
- * 
+ *
  * All tests are commented now because leafref isn't supported now
- * 
+ *
  */
 
 public class CnSnToJsonLeafrefType extends YangAndXmlAndDataSchemaLoader {
index 92de14bba4a730406f4a58b4e738b618cc05bf3b..086e648097294354cb8a34baca155581397dad15 100644 (file)
@@ -25,14 +25,14 @@ import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchem
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 
 /**
- * 
+ *
  * CnSn = Composite node and Simple node data structure Class contains test of
  * serializing simple nodes data values according data types from YANG schema to
  * XML file
- * 
+ *
  */
 public class CnSnInstanceIdentifierToXmlTest extends YangAndXmlAndDataSchemaLoader {
-    
+
     @BeforeClass
     public static void initialization() throws URISyntaxException {
         dataLoad("/instanceidentifier/yang", 4, "instance-identifier-module", "cont");
index 155ee9d5908ab7ac6c285278542e976f11374d9a..9318af529b74c6ec4097331f6e374b7aa7038e9b 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.controller.sal.restconf.impl.cnsn.to.xml.test;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.io.IOException;
 import java.util.List;
@@ -18,9 +20,6 @@ import javax.xml.transform.TransformerFactoryConfigurationError;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
-
-import static org.mockito.Mockito.*;
-
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
 import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
 import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
@@ -166,9 +165,9 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader {
         serializeToXml(
                 prepareCnStructForYangData(
                         TypeDefinitionAwareCodec.from(BinaryType.getInstance())
-                                .deserialize("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"),
+                        .deserialize("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567"),
                         elName), "<" + elName + ">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567</"
-                        + elName + ">");
+                                + elName + ">");
     }
 
     @Test
@@ -182,9 +181,9 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader {
         String elName = "lfBits";
         serializeToXml(
                 prepareCnStructForYangData(TypeDefinitionAwareCodec.from(
-                                BitsType.create( mock( SchemaPath.class ), bitList ) )
-                                                               .deserialize("one two"), elName),
-                "<" + elName + ">one two</" + elName + ">", "<" + elName + ">two one</" + elName + ">");
+                        BitsType.create( mock( SchemaPath.class ), bitList ) )
+                        .deserialize("one two"), elName),
+                        "<" + elName + ">one two</" + elName + ">", "<" + elName + ">two one</" + elName + ">");
     }
 
     @Test
@@ -196,10 +195,10 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader {
         String elName = "lfEnumeration";
         serializeToXml(
                 prepareCnStructForYangData(TypeDefinitionAwareCodec.from(
-                    EnumerationType.create( mock( SchemaPath.class ), enumList,
-                                            Optional.<EnumTypeDefinition.EnumPair>absent() ) )
-                                                                                    .deserialize("enum2"),
-                        elName), "<" + elName + ">enum2</" + elName + ">");
+                        EnumerationType.create( mock( SchemaPath.class ), enumList,
+                                Optional.<EnumTypeDefinition.EnumPair>absent() ) )
+                                .deserialize("enum2"),
+                                elName), "<" + elName + ">enum2</" + elName + ">");
     }
 
     @Test
@@ -231,9 +230,9 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader {
         List<BitsTypeDefinition.Bit> bitList = Lists.newArrayList( mockBit1, mockBit2 );
 
         List<TypeDefinition<?>> types = Lists.<TypeDefinition<?>>newArrayList(
-                                                            Int8.getInstance(),
-                                                            BitsType.create( mock( SchemaPath.class ) , bitList ),
-                                                            BooleanType.getInstance() );
+                Int8.getInstance(),
+                BitsType.create( mock( SchemaPath.class ) , bitList ),
+                BooleanType.getInstance() );
         UnionType unionType = UnionType.create( types );
 
         String elName = "lfUnion";
@@ -253,7 +252,7 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader {
                         + elName + ">str</" + elName + ">");
     }
 
-    private void serializeToXml(CompositeNode compositeNode, String... xmlRepresentation)
+    private void serializeToXml(final CompositeNode compositeNode, final String... xmlRepresentation)
             throws TransformerFactoryConfigurationError {
         String xmlString = "";
         try {
@@ -275,7 +274,7 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader {
 
     }
 
-    private CompositeNode prepareIdentityrefData(String prefix, boolean valueAsQName) {
+    private CompositeNode prepareIdentityrefData(final String prefix, final boolean valueAsQName) {
         MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
                 TestUtils.buildQName("cont", "basic:module", "2013-12-2"), null, null, ModifyAction.CREATE, null);
         MutableCompositeNode cont1 = NodeFactory.createMutableCompositeNode(
@@ -298,11 +297,11 @@ public class CnSnToXmlTest extends YangAndXmlAndDataSchemaLoader {
     }
 
     private CompositeNode prepareCnStructForYangData(final Object data, final String leafName) {
-        MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(TestUtils.buildQName("cont"), null, null,
-                ModifyAction.CREATE, null);
+        MutableCompositeNode cont = NodeFactory.createMutableCompositeNode(
+                TestUtils.buildQName("cont", "basic:module", "2013-12-2"), null, null, ModifyAction.CREATE, null);
 
-        MutableSimpleNode<Object> lf1 = NodeFactory.createMutableSimpleNode(TestUtils.buildQName(leafName), cont, data,
-                ModifyAction.CREATE, null);
+        MutableSimpleNode<Object> lf1 = NodeFactory.createMutableSimpleNode(
+                TestUtils.buildQName(leafName, "basic:module", "2013-12-2"), cont, data, ModifyAction.CREATE, null);
         cont.getValue().add(lf1);
         cont.init();
 
index b7a58886dc056e797f667ca7ef7b1ecfd451418c..f8d04c157f2e9d1678da36c6636bd872e05e4cc7 100644 (file)
@@ -42,10 +42,10 @@ public class CnSnToXmlWithDataFromSeveralModulesTest extends YangAndXmlAndDataSc
 
 //         String output =
 //         String.format("<data>" +
-//                      "\n<cont_m1>" +
-//                             "\n\t<lf1_m1>" +
-//                                 "\n\t\tlf1 m1 value" +
-//                                     "\n\t</lf1_m1>" +
+//                  "\n<cont_m1>" +
+//                         "\n\t<lf1_m1>" +
+//                             "\n\t\tlf1 m1 value" +
+//                             "\n\t</lf1_m1>" +
 //                         "\n</cont_m1>" +
 //                         "\n<cont_m2>" +
 //                             "\n\t<lf1_m2>" +
@@ -60,8 +60,8 @@ public class CnSnToXmlWithDataFromSeveralModulesTest extends YangAndXmlAndDataSc
         regex.append(".*<data.*");
         regex.append(".*xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"");
         regex.append(".*>");
-        
-        
+
+
         regex.append(".*<contB_m1.*\\/>");
         regex.append(".*xmlns=\"module:one\"");
         regex.append(".*>");
@@ -97,7 +97,7 @@ public class CnSnToXmlWithDataFromSeveralModulesTest extends YangAndXmlAndDataSc
         SimpleNodeWrapper lf1_m1 = new SimpleNodeWrapper(uriModule1, "lf1_m1", "lf1 m1 value");
         cont_m1.addValue(lf1_m1);
         CompositeNodeWrapper contB_m1 = new CompositeNodeWrapper(uriModule1, "contB_m1");
-        
+
         data.addValue(contB_m1);
         data.addValue(cont_m1);
 
index 67b5b8c93a0aaa2994b5c640df52c3bc48bce4d9..22b34a44203e0ba67384f6635e7b55bb0dc4e2e5 100644 (file)
@@ -7,38 +7,41 @@
  */
 package org.opendaylight.controller.sal.restconf.impl.test;
 
-import java.util.concurrent.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class DummyFuture implements Future<RpcResult<TransactionStatus>> {
-    
+
     private final boolean cancel;
     private final boolean isCancelled;
     private final boolean isDone;
     private final RpcResult<TransactionStatus> result;
-    
+
     public DummyFuture() {
         cancel = false;
         isCancelled = false;
         isDone = false;
         result = null;
     }
-    
-    private DummyFuture(Builder builder) {
+
+    private DummyFuture(final Builder builder) {
         cancel = builder.cancel;
         isCancelled = builder.isCancelled;
         isDone = builder.isDone;
         result = builder.result;
     }
-    
+
     public static Builder builder() {
         return new DummyFuture.Builder();
     }
 
     @Override
-    public boolean cancel(boolean mayInterruptIfRunning) {
+    public boolean cancel(final boolean mayInterruptIfRunning) {
         return cancel;
     }
 
@@ -58,38 +61,38 @@ public class DummyFuture implements Future<RpcResult<TransactionStatus>> {
     }
 
     @Override
-    public RpcResult<TransactionStatus> get(long timeout, TimeUnit unit) throws InterruptedException,
-            ExecutionException, TimeoutException {
+    public RpcResult<TransactionStatus> get(final long timeout, final TimeUnit unit) throws InterruptedException,
+    ExecutionException, TimeoutException {
         return result;
     }
-    
+
     public static class Builder {
-        
+
         private boolean cancel;
         private boolean isCancelled;
         private boolean isDone;
         private RpcResult<TransactionStatus> result;
 
-        public Builder cancel(boolean cancel) {
+        public Builder cancel(final boolean cancel) {
             this.cancel = cancel;
             return this;
         }
-        
-        public Builder isCancelled(boolean isCancelled) {
+
+        public Builder isCancelled(final boolean isCancelled) {
             this.isCancelled = isCancelled;
             return this;
         }
-        
-        public Builder isDone(boolean isDone) {
+
+        public Builder isDone(final boolean isDone) {
             this.isDone = isDone;
             return this;
         }
-        
-        public Builder rpcResult(RpcResult<TransactionStatus> result) {
+
+        public Builder rpcResult(final RpcResult<TransactionStatus> result) {
             this.result = result;
             return this;
         }
-        
+
         public Future<RpcResult<TransactionStatus>> build() {
             return new DummyFuture(this);
         }
index acc5c009350ef946e01c0366fbe462d0ce13576c..16d14842db3c2cc02684e244a219f7d20da03daf 100644 (file)
@@ -9,7 +9,8 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 
 import java.util.Collection;
 
-import org.opendaylight.yangtools.yang.common.*;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
 
 public class DummyRpcResult<T> implements RpcResult<T> {
 
@@ -23,7 +24,7 @@ public class DummyRpcResult<T> implements RpcResult<T> {
         errors = null;
     }
 
-    private DummyRpcResult(Builder<T> builder) {
+    private DummyRpcResult(final Builder<T> builder) {
         isSuccessful = builder.isSuccessful;
         result = builder.result;
         errors = builder.errors;
@@ -49,17 +50,17 @@ public class DummyRpcResult<T> implements RpcResult<T> {
         private T result;
         private Collection<RpcError> errors;
 
-        public Builder<T> isSuccessful(boolean isSuccessful) {
+        public Builder<T> isSuccessful(final boolean isSuccessful) {
             this.isSuccessful = isSuccessful;
             return this;
         }
 
-        public Builder<T> result(T result) {
+        public Builder<T> result(final T result) {
             this.result = result;
             return this;
         }
 
-        public Builder<T> errors(Collection<RpcError> errors) {
+        public Builder<T> errors(final Collection<RpcError> errors) {
             this.errors = errors;
             return this;
         }
index 9caaf6b83a44fe84ba372fd33fef38003292360d..d90e9539c83cbbeeff51726967370dc1f6e53724 100644 (file)
@@ -10,7 +10,10 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 import java.util.List;
 
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 
 public class DummyType implements TypeDefinition<DummyType> {
     QName dummyQName = TestUtils.buildQName("dummy type", "simple:uri", "2012-12-17");
index f5aa453fa245d2e4f9273350f35dcb1c47cfbd47..158569af7386eb35081ba046af00d96b0de08d96 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.controller.sal.restconf.impl.test;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
 
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -50,7 +50,7 @@ public class NormalizeNodeTest extends YangAndXmlAndDataSchemaLoader {
         TestUtils.normalizeCompositeNode(prepareCnSn("normalize-node-module"), modules, schemaNodePath);
     }
 
-    private CompositeNode prepareCnSn(String namespace) {
+    private CompositeNode prepareCnSn(final String namespace) {
         URI uri = null;
         if (namespace != null) {
             try {
index 408b14acfe8e67d93fb45c31a55fd0700f9b23a5..56a58eeadd1f5d80f4dc4f2926c48a9968fbe3c8 100644 (file)
@@ -76,13 +76,13 @@ public class RestDeleteOperationTest extends JerseyTest {
         when(brokerFacade.commitConfigurationDataDelete(any(InstanceIdentifier.class))).thenReturn(dummyFuture);
         Response response = target(uri).request(MediaType.APPLICATION_XML).delete();
         assertEquals(200, response.getStatus());
-        
+
         dummyFuture = createFuture(TransactionStatus.FAILED);
         when(brokerFacade.commitConfigurationDataDelete(any(InstanceIdentifier.class))).thenReturn(dummyFuture);
         response = target(uri).request(MediaType.APPLICATION_XML).delete();
         assertEquals(500, response.getStatus());
     }
-    
+
     private Future<RpcResult<TransactionStatus>> createFuture(TransactionStatus statusName) {
         RpcResult<TransactionStatus> rpcResult = new DummyRpcResult.Builder<TransactionStatus>().result(statusName).build();
         return DummyFuture.builder().rpcResult(rpcResult).build();
index fc5d7be724d9c9fee4438834bbf45d9e8cf3c9bf..3f984c293b333563de6d696065e26645d1940982 100644 (file)
@@ -8,9 +8,15 @@
 
 package org.opendaylight.controller.sal.restconf.impl.test;
 
-import static org.junit.Assert.*;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.when;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -21,8 +27,8 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
+import java.util.Set;
 
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
@@ -48,9 +54,9 @@ import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError;
-import org.opendaylight.controller.sal.restconf.impl.StructuredData;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.controller.sal.restconf.impl.StructuredData;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -79,12 +85,12 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         Map<String, String> expErrorInfo;
 
-        public ComplexErrorInfoVerifier( Map<String, String> expErrorInfo ) {
+        public ComplexErrorInfoVerifier( final Map<String, String> expErrorInfo ) {
             this.expErrorInfo = expErrorInfo;
         }
 
         @Override
-        public void verifyXML( Node errorInfoNode ) {
+        public void verifyXML( final Node errorInfoNode ) {
 
             Map<String, String> mutableExpMap = Maps.newHashMap( expErrorInfo );
             NodeList childNodes = errorInfoNode.getChildNodes();
@@ -93,9 +99,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
                 if( child  instanceof Element ) {
                     String expValue = mutableExpMap.remove( child.getNodeName() );
                     assertNotNull( "Found unexpected \"error-info\" child node: " +
-                                   child.getNodeName(), expValue );
+                            child.getNodeName(), expValue );
                     assertEquals( "Text content for \"error-info\" child node " +
-                                   child.getNodeName(), expValue, child.getTextContent() );
+                            child.getNodeName(), expValue, child.getTextContent() );
                 }
             }
 
@@ -105,7 +111,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         }
 
         @Override
-        public void verifyJson( JsonElement errorInfoElement ) {
+        public void verifyJson( final JsonElement errorInfoElement ) {
 
             assertTrue( "\"error-info\" Json element is not an Object",
                     errorInfoElement.isJsonObject() );
@@ -121,9 +127,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
             for( Entry<String,String> actual: actualErrorInfo.entrySet() ) {
                 String expValue = mutableExpMap.remove( actual.getKey() );
                 assertNotNull( "Found unexpected \"error-info\" child node: " +
-                                actual.getKey(), expValue );
+                        actual.getKey(), expValue );
                 assertEquals( "Text content for \"error-info\" child node " +
-                              actual.getKey(), expValue, actual.getValue() );
+                        actual.getKey(), expValue, actual.getValue() );
             }
 
             if( !mutableExpMap.isEmpty() ) {
@@ -136,22 +142,22 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         String expTextContent;
 
-        public SimpleErrorInfoVerifier( String expErrorInfo ) {
+        public SimpleErrorInfoVerifier( final String expErrorInfo ) {
             this.expTextContent = expErrorInfo;
         }
 
-        void verifyContent( String actualContent ) {
+        void verifyContent( final String actualContent ) {
             assertNotNull( "Actual \"error-info\" text content is null", actualContent );
             assertTrue( "", actualContent.contains( expTextContent ) );
         }
 
         @Override
-        public void verifyXML( Node errorInfoNode ) {
+        public void verifyXML( final Node errorInfoNode ) {
             verifyContent( errorInfoNode.getTextContent() );
         }
 
         @Override
-        public void verifyJson( JsonElement errorInfoElement ) {
+        public void verifyJson( final JsonElement errorInfoElement ) {
             verifyContent( errorInfoElement.getAsString() );
         }
     }
@@ -172,17 +178,17 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         NamespaceContext nsContext = new NamespaceContext() {
             @Override
-            public Iterator getPrefixes( String namespaceURI ) {
+            public Iterator<?> getPrefixes( final String namespaceURI ) {
                 return null;
             }
 
             @Override
-            public String getPrefix( String namespaceURI ) {
+            public String getPrefix( final String namespaceURI ) {
                 return null;
             }
 
             @Override
-            public String getNamespaceURI( String prefix ) {
+            public String getNamespaceURI( final String prefix ) {
                 return "ietf-restconf".equals( prefix ) ? Draft02.RestConfModule.NAMESPACE : null;
             }
         };
@@ -207,19 +213,19 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
     protected Application configure() {
         ResourceConfig resourceConfig = new ResourceConfig();
         resourceConfig = resourceConfig.registerInstances( mockRestConf, StructuredDataToXmlProvider.INSTANCE,
-                                                           StructuredDataToJsonProvider.INSTANCE );
+                StructuredDataToJsonProvider.INSTANCE );
         resourceConfig.registerClasses( RestconfDocumentedExceptionMapper.class );
         return resourceConfig;
     }
 
-    void stageMockEx( RestconfDocumentedException ex ) {
+    void stageMockEx( final RestconfDocumentedException ex ) {
         reset( mockRestConf );
         when( mockRestConf.readOperationalData( any( String.class ) ) ).thenThrow( ex );
     }
 
-    void testJsonResponse( RestconfDocumentedException ex, Status expStatus, ErrorType expErrorType,
-                           ErrorTag expErrorTag, String expErrorMessage, String expErrorAppTag,
-                           ErrorInfoVerifier errorInfoVerifier ) throws Exception {
+    void testJsonResponse( final RestconfDocumentedException ex, final Status expStatus, final ErrorType expErrorType,
+            final ErrorTag expErrorTag, final String expErrorMessage, final String expErrorAppTag,
+            final ErrorInfoVerifier errorInfoVerifier ) throws Exception {
 
         stageMockEx( ex );
 
@@ -228,51 +234,51 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         InputStream stream = verifyResponse( resp, MediaType.APPLICATION_JSON, expStatus );
 
         verifyJsonResponseBody( stream, expErrorType, expErrorTag, expErrorMessage,
-                                expErrorAppTag, errorInfoVerifier );
+                expErrorAppTag, errorInfoVerifier );
     }
 
     @Test
     public void testToJsonResponseWithMessageOnly() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error" ), Status.INTERNAL_SERVER_ERROR,
-                          ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null );
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null );
 
         // To test verification code
-//        String json =
-//            "{ errors: {" +
-//            "    error: [{" +
-//            "      error-tag : \"operation-failed\"" +
-//            "      ,error-type : \"application\"" +
-//            "      ,error-message : \"An error occurred\"" +
-//            "      ,error-info : {" +
-//            "        session-id: \"123\"" +
-//            "        ,address: \"1.2.3.4\"" +
-//            "      }" +
-//            "    }]" +
-//            "  }" +
-//            "}";
-//
-//        verifyJsonResponseBody( new java.io.StringBufferInputStream(json ), ErrorType.APPLICATION,
-//            ErrorTag.OPERATION_FAILED, "An error occurred", null,
-//            com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) );
+        //        String json =
+        //            "{ errors: {" +
+        //            "    error: [{" +
+        //            "      error-tag : \"operation-failed\"" +
+        //            "      ,error-type : \"application\"" +
+        //            "      ,error-message : \"An error occurred\"" +
+        //            "      ,error-info : {" +
+        //            "        session-id: \"123\"" +
+        //            "        ,address: \"1.2.3.4\"" +
+        //            "      }" +
+        //            "    }]" +
+        //            "  }" +
+        //            "}";
+        //
+        //        verifyJsonResponseBody( new java.io.StringBufferInputStream(json ), ErrorType.APPLICATION,
+        //            ErrorTag.OPERATION_FAILED, "An error occurred", null,
+        //            com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) );
     }
 
     @Test
     public void testToJsonResponseWithInUseErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.IN_USE ),
-                          Status.CONFLICT, ErrorType.PROTOCOL,
-                          ErrorTag.IN_USE, "mock error", null, null );
+                ErrorTag.IN_USE ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.IN_USE, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithInvalidValueErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.RPC,
-                                                           ErrorTag.INVALID_VALUE ),
-                          Status.BAD_REQUEST, ErrorType.RPC,
-                          ErrorTag.INVALID_VALUE, "mock error", null, null );
+                ErrorTag.INVALID_VALUE ),
+                Status.BAD_REQUEST, ErrorType.RPC,
+                ErrorTag.INVALID_VALUE, "mock error", null, null );
 
     }
 
@@ -280,9 +286,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
     public void testToJsonResponseWithTooBigErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.TRANSPORT,
-                                                           ErrorTag.TOO_BIG ),
-                          Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT,
-                          ErrorTag.TOO_BIG, "mock error", null, null );
+                ErrorTag.TOO_BIG ),
+                Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT,
+                ErrorTag.TOO_BIG, "mock error", null, null );
 
     }
 
@@ -290,153 +296,153 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
     public void testToJsonResponseWithMissingAttributeErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.MISSING_ATTRIBUTE ),
-                          Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                          ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null );
+                ErrorTag.MISSING_ATTRIBUTE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithBadAttributeErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.BAD_ATTRIBUTE ),
-                          Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                          ErrorTag.BAD_ATTRIBUTE, "mock error", null, null );
+                ErrorTag.BAD_ATTRIBUTE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.BAD_ATTRIBUTE, "mock error", null, null );
     }
     @Test
     public void testToJsonResponseWithUnknownAttributeErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.UNKNOWN_ATTRIBUTE ),
-                          Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                          ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null );
+                ErrorTag.UNKNOWN_ATTRIBUTE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithBadElementErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.BAD_ELEMENT ),
-                          Status.BAD_REQUEST,
-                          ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, "mock error", null, null );
+                ErrorTag.BAD_ELEMENT ),
+                Status.BAD_REQUEST,
+                ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithUnknownElementErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.UNKNOWN_ELEMENT ),
-                          Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                          ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null );
+                ErrorTag.UNKNOWN_ELEMENT ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithUnknownNamespaceErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.UNKNOWN_NAMESPACE ),
-                          Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                          ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null );
+                ErrorTag.UNKNOWN_NAMESPACE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithMalformedMessageErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.MALFORMED_MESSAGE ),
-                          Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                          ErrorTag.MALFORMED_MESSAGE, "mock error", null, null );
+                ErrorTag.MALFORMED_MESSAGE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.MALFORMED_MESSAGE, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithAccessDeniedErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.ACCESS_DENIED ),
-                          Status.FORBIDDEN, ErrorType.PROTOCOL,
-                          ErrorTag.ACCESS_DENIED, "mock error", null, null );
+                ErrorTag.ACCESS_DENIED ),
+                Status.FORBIDDEN, ErrorType.PROTOCOL,
+                ErrorTag.ACCESS_DENIED, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithLockDeniedErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.LOCK_DENIED ),
-                          Status.CONFLICT, ErrorType.PROTOCOL,
-                          ErrorTag.LOCK_DENIED, "mock error", null, null );
+                ErrorTag.LOCK_DENIED ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.LOCK_DENIED, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithResourceDeniedErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.RESOURCE_DENIED ),
-                          Status.CONFLICT, ErrorType.PROTOCOL,
-                          ErrorTag.RESOURCE_DENIED, "mock error", null, null );
+                ErrorTag.RESOURCE_DENIED ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.RESOURCE_DENIED, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithRollbackFailedErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.ROLLBACK_FAILED ),
-                          Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
-                          ErrorTag.ROLLBACK_FAILED, "mock error", null, null );
+                ErrorTag.ROLLBACK_FAILED ),
+                Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
+                ErrorTag.ROLLBACK_FAILED, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithDataExistsErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.DATA_EXISTS ),
-                          Status.CONFLICT, ErrorType.PROTOCOL,
-                          ErrorTag.DATA_EXISTS, "mock error", null, null );
+                ErrorTag.DATA_EXISTS ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.DATA_EXISTS, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithDataMissingErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.DATA_MISSING ),
-                          Status.CONFLICT, ErrorType.PROTOCOL,
-                          ErrorTag.DATA_MISSING, "mock error", null, null );
+                ErrorTag.DATA_MISSING ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.DATA_MISSING, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithOperationNotSupportedErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.OPERATION_NOT_SUPPORTED ),
-                          Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL,
-                          ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null );
+                ErrorTag.OPERATION_NOT_SUPPORTED ),
+                Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL,
+                ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithOperationFailedErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.OPERATION_FAILED ),
-                          Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
-                          ErrorTag.OPERATION_FAILED, "mock error", null, null );
+                ErrorTag.OPERATION_FAILED ),
+                Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
+                ErrorTag.OPERATION_FAILED, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithPartialOperationErrorTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.PARTIAL_OPERATION ),
-                          Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
-                          ErrorTag.PARTIAL_OPERATION, "mock error", null, null );
+                ErrorTag.PARTIAL_OPERATION ),
+                Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
+                ErrorTag.PARTIAL_OPERATION, "mock error", null, null );
     }
 
     @Test
     public void testToJsonResponseWithErrorAppTag() throws Exception {
 
         testJsonResponse( new RestconfDocumentedException( new RestconfError(
-                                   ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
-                                   "mock error", "mock-app-tag" ) ),
-                          Status.BAD_REQUEST, ErrorType.APPLICATION,
-                          ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null );
+                ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
+                "mock error", "mock-app-tag" ) ),
+                Status.BAD_REQUEST, ErrorType.APPLICATION,
+                ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null );
     }
 
     @Test
@@ -456,10 +462,10 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         assertEquals( "\"error\" Json array element length", 2, arrayElement.size() );
 
         verifyJsonErrorNode( arrayElement.get( 0 ), ErrorType.APPLICATION, ErrorTag.LOCK_DENIED,
-                             "mock error1", null, null );
+                "mock error1", null, null );
 
         verifyJsonErrorNode( arrayElement.get( 1 ), ErrorType.RPC, ErrorTag.ROLLBACK_FAILED,
-                             "mock error2", null, null );
+                "mock error2", null, null );
     }
 
     @Test
@@ -467,12 +473,12 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         String errorInfo = "<address>1.2.3.4</address> <session-id>123</session-id>";
         testJsonResponse( new RestconfDocumentedException( new RestconfError(
-                                               ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
-                                               "mock error", "mock-app-tag", errorInfo ) ),
-                          Status.BAD_REQUEST, ErrorType.APPLICATION,
-                          ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag",
-                          new ComplexErrorInfoVerifier( ImmutableMap.of(
-                                                "session-id", "123", "address", "1.2.3.4" ) ) );
+                ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
+                "mock error", "mock-app-tag", errorInfo ) ),
+                Status.BAD_REQUEST, ErrorType.APPLICATION,
+                ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag",
+                new ComplexErrorInfoVerifier( ImmutableMap.of(
+                        "session-id", "123", "address", "1.2.3.4" ) ) );
     }
 
     @Test
@@ -480,14 +486,14 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         Exception cause = new Exception( "mock exception cause" );
         testJsonResponse( new RestconfDocumentedException( "mock error", cause ),
-                          Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION,
-                          ErrorTag.OPERATION_FAILED, "mock error", null,
-                          new SimpleErrorInfoVerifier( cause.getMessage() ) );
+                Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION,
+                ErrorTag.OPERATION_FAILED, "mock error", null,
+                new SimpleErrorInfoVerifier( cause.getMessage() ) );
     }
 
-    void testXMLResponse( RestconfDocumentedException ex, Status expStatus, ErrorType expErrorType,
-                          ErrorTag expErrorTag, String expErrorMessage,
-                          String expErrorAppTag, ErrorInfoVerifier errorInfoVerifier ) throws Exception
+    void testXMLResponse( final RestconfDocumentedException ex, final Status expStatus, final ErrorType expErrorType,
+            final ErrorTag expErrorTag, final String expErrorMessage,
+            final String expErrorAppTag, final ErrorInfoVerifier errorInfoVerifier ) throws Exception
     {
         stageMockEx( ex );
 
@@ -496,212 +502,212 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         InputStream stream = verifyResponse( resp, MediaType.APPLICATION_XML, expStatus );
 
         verifyXMLResponseBody( stream, expErrorType, expErrorTag, expErrorMessage,
-                               expErrorAppTag, errorInfoVerifier );
+                expErrorAppTag, errorInfoVerifier );
     }
 
     @Test
     public void testToXMLResponseWithMessageOnly() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error" ), Status.INTERNAL_SERVER_ERROR,
-                         ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null );
+                ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null );
 
         // To test verification code
-//        String xml =
-//            "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">"+
-//            "  <error>" +
-//            "    <error-type>application</error-type>"+
-//            "    <error-tag>operation-failed</error-tag>"+
-//            "    <error-message>An error occurred</error-message>"+
-//            "    <error-info>" +
-//            "      <session-id>123</session-id>" +
-//            "      <address>1.2.3.4</address>" +
-//            "    </error-info>" +
-//            "  </error>" +
-//            "</errors>";
-//
-//        verifyXMLResponseBody( new java.io.StringBufferInputStream(xml), ErrorType.APPLICATION,
-//                ErrorTag.OPERATION_FAILED, "An error occurred", null,
-//                com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) );
+        //        String xml =
+        //            "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">"+
+        //            "  <error>" +
+        //            "    <error-type>application</error-type>"+
+        //            "    <error-tag>operation-failed</error-tag>"+
+        //            "    <error-message>An error occurred</error-message>"+
+        //            "    <error-info>" +
+        //            "      <session-id>123</session-id>" +
+        //            "      <address>1.2.3.4</address>" +
+        //            "    </error-info>" +
+        //            "  </error>" +
+        //            "</errors>";
+        //
+        //        verifyXMLResponseBody( new java.io.StringBufferInputStream(xml), ErrorType.APPLICATION,
+        //                ErrorTag.OPERATION_FAILED, "An error occurred", null,
+        //                com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) );
     }
 
     @Test
     public void testToXMLResponseWithInUseErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.IN_USE ),
-                         Status.CONFLICT, ErrorType.PROTOCOL,
-                         ErrorTag.IN_USE, "mock error", null, null );
+                ErrorTag.IN_USE ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.IN_USE, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithInvalidValueErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.RPC,
-                                                           ErrorTag.INVALID_VALUE ),
-                         Status.BAD_REQUEST, ErrorType.RPC,
-                         ErrorTag.INVALID_VALUE, "mock error", null, null );
+                ErrorTag.INVALID_VALUE ),
+                Status.BAD_REQUEST, ErrorType.RPC,
+                ErrorTag.INVALID_VALUE, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithTooBigErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.TRANSPORT,
-                                                           ErrorTag.TOO_BIG ),
-                         Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT,
-                         ErrorTag.TOO_BIG, "mock error", null, null );
+                ErrorTag.TOO_BIG ),
+                Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT,
+                ErrorTag.TOO_BIG, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithMissingAttributeErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.MISSING_ATTRIBUTE ),
-                         Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                         ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null );
+                ErrorTag.MISSING_ATTRIBUTE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithBadAttributeErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.BAD_ATTRIBUTE ),
-                         Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                         ErrorTag.BAD_ATTRIBUTE, "mock error", null, null );
+                ErrorTag.BAD_ATTRIBUTE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.BAD_ATTRIBUTE, "mock error", null, null );
     }
     @Test
     public void testToXMLResponseWithUnknownAttributeErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.UNKNOWN_ATTRIBUTE ),
-                         Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                         ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null );
+                ErrorTag.UNKNOWN_ATTRIBUTE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithBadElementErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.BAD_ELEMENT ),
-                         Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                         ErrorTag.BAD_ELEMENT, "mock error", null, null );
+                ErrorTag.BAD_ELEMENT ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.BAD_ELEMENT, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithUnknownElementErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.UNKNOWN_ELEMENT ),
-                         Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                         ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null );
+                ErrorTag.UNKNOWN_ELEMENT ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithUnknownNamespaceErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.UNKNOWN_NAMESPACE ),
-                         Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                         ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null );
+                ErrorTag.UNKNOWN_NAMESPACE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithMalformedMessageErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.MALFORMED_MESSAGE ),
-                         Status.BAD_REQUEST, ErrorType.PROTOCOL,
-                         ErrorTag.MALFORMED_MESSAGE, "mock error", null, null );
+                ErrorTag.MALFORMED_MESSAGE ),
+                Status.BAD_REQUEST, ErrorType.PROTOCOL,
+                ErrorTag.MALFORMED_MESSAGE, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithAccessDeniedErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.ACCESS_DENIED ),
-                         Status.FORBIDDEN, ErrorType.PROTOCOL,
-                         ErrorTag.ACCESS_DENIED, "mock error", null, null );
+                ErrorTag.ACCESS_DENIED ),
+                Status.FORBIDDEN, ErrorType.PROTOCOL,
+                ErrorTag.ACCESS_DENIED, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithLockDeniedErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.LOCK_DENIED ),
-                          Status.CONFLICT, ErrorType.PROTOCOL,
-                          ErrorTag.LOCK_DENIED, "mock error", null, null );
+                ErrorTag.LOCK_DENIED ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.LOCK_DENIED, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithResourceDeniedErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.RESOURCE_DENIED ),
-                         Status.CONFLICT, ErrorType.PROTOCOL,
-                         ErrorTag.RESOURCE_DENIED, "mock error", null, null );
+                ErrorTag.RESOURCE_DENIED ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.RESOURCE_DENIED, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithRollbackFailedErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.ROLLBACK_FAILED ),
-                         Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
-                         ErrorTag.ROLLBACK_FAILED, "mock error", null, null );
+                ErrorTag.ROLLBACK_FAILED ),
+                Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
+                ErrorTag.ROLLBACK_FAILED, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithDataExistsErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.DATA_EXISTS ),
-                         Status.CONFLICT, ErrorType.PROTOCOL,
-                         ErrorTag.DATA_EXISTS, "mock error", null, null );
+                ErrorTag.DATA_EXISTS ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.DATA_EXISTS, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithDataMissingErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.DATA_MISSING ),
-                         Status.CONFLICT, ErrorType.PROTOCOL,
-                         ErrorTag.DATA_MISSING, "mock error", null, null );
+                ErrorTag.DATA_MISSING ),
+                Status.CONFLICT, ErrorType.PROTOCOL,
+                ErrorTag.DATA_MISSING, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithOperationNotSupportedErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.OPERATION_NOT_SUPPORTED ),
-                         Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL,
-                         ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null );
+                ErrorTag.OPERATION_NOT_SUPPORTED ),
+                Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL,
+                ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithOperationFailedErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.OPERATION_FAILED ),
-                         Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
-                         ErrorTag.OPERATION_FAILED, "mock error", null, null );
+                ErrorTag.OPERATION_FAILED ),
+                Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
+                ErrorTag.OPERATION_FAILED, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithPartialOperationErrorTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL,
-                                                           ErrorTag.PARTIAL_OPERATION ),
-                         Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
-                         ErrorTag.PARTIAL_OPERATION, "mock error", null, null );
+                ErrorTag.PARTIAL_OPERATION ),
+                Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL,
+                ErrorTag.PARTIAL_OPERATION, "mock error", null, null );
     }
 
     @Test
     public void testToXMLResponseWithErrorAppTag() throws Exception {
 
         testXMLResponse( new RestconfDocumentedException( new RestconfError(
-                                              ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
-                                              "mock error", "mock-app-tag" ) ),
-                         Status.BAD_REQUEST, ErrorType.APPLICATION,
-                         ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null );
+                ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
+                "mock error", "mock-app-tag" ) ),
+                Status.BAD_REQUEST, ErrorType.APPLICATION,
+                ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null );
     }
 
     @Test
@@ -709,12 +715,12 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         String errorInfo = "<address>1.2.3.4</address> <session-id>123</session-id>";
         testXMLResponse( new RestconfDocumentedException( new RestconfError(
-                                               ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
-                                               "mock error", "mock-app-tag", errorInfo ) ),
-                         Status.BAD_REQUEST, ErrorType.APPLICATION,
-                         ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag",
-                         new ComplexErrorInfoVerifier( ImmutableMap.of(
-                                              "session-id", "123", "address", "1.2.3.4" ) ) );
+                ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
+                "mock error", "mock-app-tag", errorInfo ) ),
+                Status.BAD_REQUEST, ErrorType.APPLICATION,
+                ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag",
+                new ComplexErrorInfoVerifier( ImmutableMap.of(
+                        "session-id", "123", "address", "1.2.3.4" ) ) );
     }
 
     @Test
@@ -722,9 +728,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         Exception cause = new Exception( "mock exception cause" );
         testXMLResponse( new RestconfDocumentedException( "mock error", cause ),
-                         Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION,
-                         ErrorTag.OPERATION_FAILED, "mock error", null,
-                         new SimpleErrorInfoVerifier( cause.getMessage() ) );
+                Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION,
+                ErrorTag.OPERATION_FAILED, "mock error", null,
+                new SimpleErrorInfoVerifier( cause.getMessage() ) );
     }
 
     @Test
@@ -744,10 +750,10 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         NodeList children = getXMLErrorList( doc, 2 );
 
         verifyXMLErrorNode( children.item( 0 ), ErrorType.APPLICATION, ErrorTag.LOCK_DENIED,
-                            "mock error1", null, null );
+                "mock error1", null, null );
 
         verifyXMLErrorNode( children.item( 1 ), ErrorType.RPC, ErrorTag.ROLLBACK_FAILED,
-                            "mock error2", null, null );
+                "mock error2", null, null );
     }
 
     @Test
@@ -756,13 +762,13 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         stageMockEx( new RestconfDocumentedException( "mock error" ) );
 
         Response resp = target("/operational/foo")
-                                  .request().header( "Accept", MediaType.APPLICATION_JSON ).get();
+                .request().header( "Accept", MediaType.APPLICATION_JSON ).get();
 
         InputStream stream = verifyResponse( resp, MediaType.APPLICATION_JSON,
-                                             Status.INTERNAL_SERVER_ERROR );
+                Status.INTERNAL_SERVER_ERROR );
 
         verifyJsonResponseBody( stream, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error",
-                                null, null );
+                null, null );
     }
 
     @Test
@@ -771,14 +777,14 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         // The StructuredDataToJsonProvider should throw a RestconfDocumentedException with no data
 
         when( mockRestConf.readOperationalData( any( String.class ) ) )
-            .thenReturn( new StructuredData( null, null, null ) );
+        .thenReturn( new StructuredData( null, null, null ) );
 
         Response resp = target("/operational/foo").request( MediaType.APPLICATION_JSON ).get();
 
         verifyResponse( resp, MediaType.TEXT_PLAIN, Status.NOT_FOUND );
     }
 
-    InputStream verifyResponse( Response resp, String expMediaType, Status expStatus ) {
+    InputStream verifyResponse( final Response resp, final String expMediaType, final Status expStatus ) {
         assertEquals( "getMediaType", MediaType.valueOf( expMediaType ), resp.getMediaType() );
         assertEquals( "getStatus", expStatus.getStatusCode(), resp.getStatus() );
 
@@ -788,19 +794,19 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         return stream;
     }
 
-    void verifyJsonResponseBody( InputStream stream, ErrorType expErrorType, ErrorTag expErrorTag,
-                                 String expErrorMessage, String expErrorAppTag,
-                                 ErrorInfoVerifier errorInfoVerifier ) throws Exception {
+    void verifyJsonResponseBody( final InputStream stream, final ErrorType expErrorType, final ErrorTag expErrorTag,
+            final String expErrorMessage, final String expErrorAppTag,
+            final ErrorInfoVerifier errorInfoVerifier ) throws Exception {
 
         JsonArray arrayElement = parseJsonErrorArrayElement( stream );
 
         assertEquals( "\"error\" Json array element length", 1, arrayElement.size() );
 
         verifyJsonErrorNode( arrayElement.get( 0 ),  expErrorType, expErrorTag, expErrorMessage,
-                             expErrorAppTag, errorInfoVerifier );
+                expErrorAppTag, errorInfoVerifier );
     }
 
-    private JsonArray parseJsonErrorArrayElement( InputStream stream ) throws IOException {
+    private JsonArray parseJsonErrorArrayElement( final InputStream stream ) throws IOException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         ByteStreams.copy( stream, bos );
 
@@ -811,7 +817,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         try {
             rootElement = parser.parse(
-                          new InputStreamReader( new ByteArrayInputStream( bos.toByteArray() ) ) );
+                    new InputStreamReader( new ByteArrayInputStream( bos.toByteArray() ) ) );
         }
         catch( Exception e ) {
             throw new IllegalArgumentException( "Invalid JSON response:\n" + bos.toString(), e );
@@ -832,15 +838,15 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
 
         JsonElement errorListElement = errorListEntrySet.iterator().next().getValue();
         assertEquals( "\"errors\" child Json element name", "error",
-                      errorListEntrySet.iterator().next().getKey() );
+                errorListEntrySet.iterator().next().getKey() );
         assertTrue( "\"error\" Json element is not an Array", errorListElement.isJsonArray() );
 
         return errorListElement.getAsJsonArray();
     }
 
-    void verifyJsonErrorNode( JsonElement errorEntryElement, ErrorType expErrorType, ErrorTag expErrorTag,
-                              String expErrorMessage, String expErrorAppTag,
-                              ErrorInfoVerifier errorInfoVerifier ) {
+    void verifyJsonErrorNode( final JsonElement errorEntryElement, final ErrorType expErrorType, final ErrorTag expErrorTag,
+            final String expErrorMessage, final String expErrorAppTag,
+            final ErrorInfoVerifier errorInfoVerifier ) {
 
         JsonElement errorInfoElement = null;
         Map<String, String> actualErrorInfo = null;
@@ -855,7 +861,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
             }
             else {
                 assertTrue( "\"error\" leaf Json element " + leafName +
-                            " is not a Primitive", leafElement.isJsonPrimitive() );
+                        " is not a Primitive", leafElement.isJsonPrimitive() );
 
                 leafMap.put( leafName, leafElement.getAsString() );
             }
@@ -877,7 +883,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         }
     }
 
-    void verifyOptionalJsonLeaf( String actualValue, String expValue, String tagName ) {
+    void verifyOptionalJsonLeaf( final String actualValue, final String expValue, final String tagName ) {
         if( expValue != null ) {
             assertEquals( tagName, expValue, actualValue );
         }
@@ -886,20 +892,20 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         }
     }
 
-    void verifyXMLResponseBody( InputStream stream, ErrorType expErrorType, ErrorTag expErrorTag,
-                                String expErrorMessage, String expErrorAppTag,
-                                ErrorInfoVerifier errorInfoVerifier )
-                                                                    throws Exception {
+    void verifyXMLResponseBody( final InputStream stream, final ErrorType expErrorType, final ErrorTag expErrorTag,
+            final String expErrorMessage, final String expErrorAppTag,
+            final ErrorInfoVerifier errorInfoVerifier )
+                    throws Exception {
 
         Document doc = parseXMLDocument( stream );
 
         NodeList children = getXMLErrorList( doc, 1 );
 
         verifyXMLErrorNode( children.item( 0 ), expErrorType, expErrorTag, expErrorMessage,
-                            expErrorAppTag, errorInfoVerifier );
+                expErrorAppTag, errorInfoVerifier );
     }
 
-    private Document parseXMLDocument( InputStream stream ) throws IOException {
+    private Document parseXMLDocument( final InputStream stream ) throws IOException {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setNamespaceAware(true);
         factory.setCoalescing(true);
@@ -921,9 +927,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         return doc;
     }
 
-    void verifyXMLErrorNode( Node errorNode, ErrorType expErrorType, ErrorTag expErrorTag,
-                             String expErrorMessage, String expErrorAppTag,
-                             ErrorInfoVerifier errorInfoVerifier ) throws Exception {
+    void verifyXMLErrorNode( final Node errorNode, final ErrorType expErrorType, final ErrorTag expErrorTag,
+            final String expErrorMessage, final String expErrorAppTag,
+            final ErrorInfoVerifier errorInfoVerifier ) throws Exception {
 
         String errorType = (String)ERROR_TYPE.evaluate( errorNode, XPathConstants.STRING );
         assertEquals( "error-type", expErrorType.getErrorTypeTag(), errorType );
@@ -945,19 +951,19 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
         }
     }
 
-    void verifyOptionalXMLLeaf( Node fromNode, XPathExpression xpath, String expValue,
-                                String tagName ) throws Exception {
+    void verifyOptionalXMLLeaf( final Node fromNode, final XPathExpression xpath, final String expValue,
+            final String tagName ) throws Exception {
         if( expValue != null ) {
             String actual = (String)xpath.evaluate( fromNode, XPathConstants.STRING );
             assertEquals( tagName, expValue, actual );
         }
         else {
             assertNull( "Found unexpected \"error\" leaf entry for: " + tagName,
-                        xpath.evaluate( fromNode, XPathConstants.NODE ) );
+                    xpath.evaluate( fromNode, XPathConstants.NODE ) );
         }
     }
 
-    NodeList getXMLErrorList( Node fromNode, int count ) throws Exception {
+    NodeList getXMLErrorList( final Node fromNode, final int count ) throws Exception {
         NodeList errorList = (NodeList)ERROR_LIST.evaluate( fromNode, XPathConstants.NODESET );
         assertNotNull( "Root errors node is empty", errorList );
         assertEquals( "Root errors node child count", count, errorList.getLength() );
index eb623096de6828f709c44ffc04affd9732db905b..853c19f93530c16449840b1043ac07d30edaab4f 100644 (file)
@@ -147,7 +147,7 @@ public final class TestUtils {
     }
 
     /**
-     * 
+     *
      * Fill missing data (namespaces) and build correct data type in
      * {@code compositeNode} according to {@code dataSchemaNode}. The method
      * {@link RestconfImpl#createConfigurationData createConfigurationData} is
@@ -165,7 +165,7 @@ public final class TestUtils {
      * Searches module with name {@code searchedModuleName} in {@code modules}.
      * If module name isn't specified and module set has only one element then
      * this element is returned.
-     * 
+     *
      */
     public static Module resolveModule(String searchedModuleName, Set<Module> modules) {
         assertNotNull("Modules can't be null.", modules);
index e935a268a2d54f73a7263818dc52c9a2a942ce0d..12ab0732025a2d1fdada1f58f6cf9bceba67d52b 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.controller.sal.restconf.impl.test.structures;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 
@@ -19,7 +20,7 @@ public class CompareLf {
         Lf lf2 = new Lf("name", "value");
         Lf lf3 = new Lf("name1", "value");
         Lf lf4 = new Lf("name", "value1");
-        
+
         assertTrue(lf1.equals(lf2));
         assertFalse(lf1.equals(lf3));
         assertFalse(lf1.equals(lf4));
index d4c7671c4539bb6455b70bb15760b2bf8e355e56..8eccf373b9e3b8fd40283517303540517412b97d 100644 (file)
@@ -7,17 +7,18 @@
  */
 package org.opendaylight.controller.sal.restconf.impl.test.structures;
 
-import java.util.*;
+import java.util.HashSet;
+import java.util.Set;
 
 public class Lst extends YangElement {
-    private Set<LstItem> lstItems;
+    private final Set<LstItem> lstItems;
 
-    public Lst(String name) {
+    public Lst(final String name) {
         super(name);
         lstItems = new HashSet<>();
     }
 
-    public Lst addLstItem(LstItem lstItem) {
+    public Lst addLstItem(final LstItem lstItem) {
         lstItem.setLstName(name);
         while (this.lstItems.contains(lstItem)) {
             lstItem.incNumOfEqualItems();
@@ -31,7 +32,7 @@ public class Lst extends YangElement {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -59,5 +60,4 @@ public class Lst extends YangElement {
         result = prime * result + ((lstItems == null) ? 0 : lstItems.hashCode());
         return result;
     }
-
 }
index ffddb00485c6ac165ab558d4ff254c7f5d48c9ed..62159ccad6c0edf76e4e8ac75282935e80c06450 100644 (file)
@@ -24,7 +24,7 @@ public class XmlAugmentedElementToCnSnTest {
         loadAndNormalizeData("/common/augment/xml/dataa.xml", "/common/augment/yang", "main","cont");
         loadAndNormalizeData("/common/augment/xml/datab.xml", "/common/augment/yang", "main","cont");
     }
-    
+
     private void loadAndNormalizeData(String xmlPath, String yangPath, String topLevelElementName, String moduleName) {
         CompositeNode compNode = TestUtils.readInputToCnSn(xmlPath, false,
                 XmlToCompositeNodeProvider.INSTANCE);
index 08cdb3429077c60b5d458c63b4247d4d0f5998a5..5b1c8324acf603ec2dd2e5d10aa69ca940bc723c 100644 (file)
@@ -1,16 +1,16 @@
 <cont>
-       <lf1>lf1</lf1>
-       <lf2>lf2</lf2>
-       <cont1>
-               <lf11>lf11</lf11>
-       </cont1>
-       <lst1>
-               <lf11>lf1_1</lf11>
-       </lst1>
-       <lst1>
-               <lf11>lf1_2</lf11>
-       </lst1>
-       <lflst1>lflst1_1</lflst1>
-       <lflst1>lflst1_2</lflst1>
-       <lflst1>lflst1_3</lflst1>
+    <lf1>lf1</lf1>
+    <lf2>lf2</lf2>
+    <cont1>
+        <lf11>lf11</lf11>
+    </cont1>
+    <lst1>
+        <lf11>lf1_1</lf11>
+    </lst1>
+    <lst1>
+        <lf11>lf1_2</lf11>
+    </lst1>
+    <lflst1>lflst1_1</lflst1>
+    <lflst1>lflst1_2</lflst1>
+    <lflst1>lflst1_3</lflst1>
 </cont>
\ No newline at end of file
index 9c751949d0a68657869e7df19c6cfaaaec6b12d4..0d5fa4a5147c4a13016f8a32af54923c26852200 100644 (file)
@@ -1,5 +1,5 @@
 <cont>
-       <cont1c>
-               <lf11c>lf11c val</lf11c>
-       </cont1c>
+    <cont1c>
+        <lf11c>lf11c val</lf11c>
+    </cont1c>
 </cont>
\ No newline at end of file
index 6cebb6424af1e83152945716e4cd77b2fcd4423f..0278389d73521eb1679c36b2277925f9e91badd9 100644 (file)
@@ -1,4 +1,4 @@
 <cont>
-       <lflst1d>lflst1d_1 val</lflst1d>
-       <lflst1d>lflst1d_2 val</lflst1d>
+    <lflst1d>lflst1d_1 val</lflst1d>
+    <lflst1d>lflst1d_2 val</lflst1d>
 </cont>
\ No newline at end of file
index 710da55de661a2bcb073f0859c09d2962c5fb39a..488873d5efe83ec76e03864d79ff231e40a086df 100644 (file)
@@ -1,8 +1,8 @@
 <cont>
-       <lst1b>
-               <lf11b>lf11b_1 val</lf11b>
-       </lst1b>
-       <lst1b>
-               <lf11b>lf11b_2 val</lf11b>
-       </lst1b>
+    <lst1b>
+        <lf11b>lf11b_1 val</lf11b>
+    </lst1b>
+    <lst1b>
+        <lf11b>lf11b_2 val</lf11b>
+    </lst1b>
 </cont>
\ No newline at end of file
index 97e219736fa1eb906a32d250699c07d4fd409da4..f21d83f8f04b0d92eed343baa536794aae87e7dd 100644 (file)
@@ -1,6 +1,6 @@
 <cont>
-       <cont1c>
-               <lf11c>lf11c val</lf11c>
-       </cont1c>
-       <lf2b>lf2b value</lf2b>
+    <cont1c>
+        <lf11c>lf11c val</lf11c>
+    </cont1c>
+    <lf2b>lf2b value</lf2b>
 </cont>
\ No newline at end of file
index 331c8aec085a048f3369b85e2ba6fb09eb3a3d7a..9e28730355a4474f4ff1254857a8a3f209e94094 100644 (file)
@@ -1,7 +1,7 @@
 <cont>
-       <cont1c>
-               <lf11c>lf11c val</lf11c>
-       </cont1c>
-       <lf2b>lf2b value</lf2b>
-       <lf2a>lf2b value</lf2a>
+    <cont1c>
+        <lf11c>lf11c val</lf11c>
+    </cont1c>
+    <lf2b>lf2b value</lf2b>
+    <lf2a>lf2b value</lf2a>
 </cont>
\ No newline at end of file
index 43e9974a2c9725b5e8a58ce8274a505dfeff700e..dbd2684526f9c1311eb31ab7c3337179bc273338 100644 (file)
@@ -1,5 +1,5 @@
 <cont>
-       <lf1>lf1 val</lf1>
-       <lf1a>121</lf1a>
-       <lf1ab>lf1ab val</lf1ab>
+    <lf1>lf1 val</lf1>
+    <lf1a>121</lf1a>
+    <lf1ab>lf1ab val</lf1ab>
 </cont>
\ No newline at end of file
index b1b78e474481bfd1ad4f152eccf7d5e7d05949a6..e3e66b78e65ee6a44c256f71425406f656358cf0 100644 (file)
@@ -1,6 +1,6 @@
 <cont>
-       <lf1aa>lf1aa val</lf1aa>
-       <lf1>lf1 val</lf1>
-       <lf1a>121</lf1a>
-       <lf1aaa>lf1aaa val</lf1aaa>
+    <lf1aa>lf1aa val</lf1aa>
+    <lf1>lf1 val</lf1>
+    <lf1a>121</lf1a>
+    <lf1aaa>lf1aaa val</lf1aaa>
 </cont>
\ No newline at end of file
index ecc0caae5613e815135370344279aa24582fa10a..49b4143a2e44fb5898c7ad7691cf338d5af46ed1 100644 (file)
@@ -1,13 +1,13 @@
 <cont>
-       <lf1aaa>lf1aaa value</lf1aaa>
-       <lf2b>lf2b value</lf2b>
-       <lst4a>
-               <lf4ab>33</lf4ab>
-       </lst4a>
-       <lst4a>
-               <lf4ab>33</lf4ab>
-       </lst4a>
-       <lst4a>
-               <lf4ab>37</lf4ab>
-       </lst4a>
+    <lf1aaa>lf1aaa value</lf1aaa>
+    <lf2b>lf2b value</lf2b>
+    <lst4a>
+        <lf4ab>33</lf4ab>
+    </lst4a>
+    <lst4a>
+        <lf4ab>33</lf4ab>
+    </lst4a>
+    <lst4a>
+        <lf4ab>37</lf4ab>
+    </lst4a>
 </cont>
\ No newline at end of file
index c43dab60c0bc196672c32d6a8482816964f10cd5..e8634682cd524fb7c9adef64dc42605c7f49c775 100644 (file)
@@ -1,6 +1,6 @@
 <cont>
-       <lf1aa>lf1aa val</lf1aa>
-       <lf1>lf1 val</lf1>
-       <lf1a>121</lf1a>
-       <lf1ab>lf1ab value</lf1ab>      
+    <lf1aa>lf1aa val</lf1aa>
+    <lf1>lf1 val</lf1>
+    <lf1a>121</lf1a>
+    <lf1ab>lf1ab value</lf1ab>
 </cont>
\ No newline at end of file
index bbebabec4edb21b87ec882ec761cb79c7cd6399f..6bb975947b0c774951aa277be57f3fb8eeea61da 100644 (file)
@@ -1,6 +1,6 @@
 <cont>
-       <cont1>
-               <lf11>true</lf11>
-       </cont1>
-       <lf3>true</lf3>
+    <cont1>
+        <lf11>true</lf11>
+    </cont1>
+    <lf3>true</lf3>
 </cont>
\ No newline at end of file
index 0d8cf660ac3c056257a3053c5e629e653b894fcf..49d2dc39aa8688df339a65e476b535c093b36540 100644 (file)
@@ -1,5 +1,5 @@
 <cont>
-       <lflst1>345</lflst1>
-       <lflst1>346</lflst1>
-       <lflst1>347</lflst1>
+    <lflst1>345</lflst1>
+    <lflst1>346</lflst1>
+    <lflst1>347</lflst1>
 </cont>
\ No newline at end of file
index f73ce1b65c38a154a8ae2067318c1b261e012c36..28d355dbab0a44375559dad7e57670f87cc7b047 100644 (file)
@@ -1,42 +1,42 @@
 <cont>
-       <lfnint8Min>-128</lfnint8Min>
-       <lfnint8Max>127</lfnint8Max>
-       <lfnint16Min>-32768</lfnint16Min>
-       <lfnint16Max>32767</lfnint16Max>
-       <lfnint32Min>-2147483648</lfnint32Min>
-       <lfnint32Max>2147483647</lfnint32Max>
-       <lfnint64Min>-9223372036854775808</lfnint64Min>
-       <lfnint64Max>9223372036854775807</lfnint64Max>  
-       <lfnuint8Max>255</lfnuint8Max>
-       <lfnuint16Max>65535</lfnuint16Max>
-       <lfnuint32Max>4294967295</lfnuint32Max>
-       <lfstr>lfstr</lfstr>
-       <lfstr1></lfstr1>
-       <lfbool1>true</lfbool1>
-       <lfbool2>false</lfbool2>
-       <lfbool3>bla</lfbool3>
-       <lfdecimal1>43.32</lfdecimal1>
-       <lfdecimal2>-0.43</lfdecimal2>
-       <lfdecimal3>43</lfdecimal3>
-       <lfdecimal4>43E3</lfdecimal4>
-       <lfdecimal6>33.12345</lfdecimal6>
-       <lfenum>enum3</lfenum>
-       <lfbits>bit3 bit2</lfbits>      
-       <lfbinary>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</lfbinary>
-       <lfempty />
-       <lfunion1>324</lfunion1>
-       <lfunion2>33.3</lfunion2>
-       <lfunion3>55</lfunion3>
-       <lfunion4>true</lfunion4>
-       <lfunion5>true</lfunion5>
-       <lfunion6>10</lfunion6>
-       <lfunion7></lfunion7>
-       <lfunion8></lfunion8>
-       <lfunion9></lfunion9>
-       <lfunion10>bt1</lfunion10>
-       <lfunion11>33</lfunion11>
-       <lfunion12>false</lfunion12>
-       <lfunion13>b1</lfunion13>
-       <lfunion14>zero</lfunion14>
-       <identityref1 xmlns:x="simple:data:types">x:iden</identityref1>
+    <lfnint8Min>-128</lfnint8Min>
+    <lfnint8Max>127</lfnint8Max>
+    <lfnint16Min>-32768</lfnint16Min>
+    <lfnint16Max>32767</lfnint16Max>
+    <lfnint32Min>-2147483648</lfnint32Min>
+    <lfnint32Max>2147483647</lfnint32Max>
+    <lfnint64Min>-9223372036854775808</lfnint64Min>
+    <lfnint64Max>9223372036854775807</lfnint64Max>
+    <lfnuint8Max>255</lfnuint8Max>
+    <lfnuint16Max>65535</lfnuint16Max>
+    <lfnuint32Max>4294967295</lfnuint32Max>
+    <lfstr>lfstr</lfstr>
+    <lfstr1></lfstr1>
+    <lfbool1>true</lfbool1>
+    <lfbool2>false</lfbool2>
+    <lfbool3>bla</lfbool3>
+    <lfdecimal1>43.32</lfdecimal1>
+    <lfdecimal2>-0.43</lfdecimal2>
+    <lfdecimal3>43</lfdecimal3>
+    <lfdecimal4>43E3</lfdecimal4>
+    <lfdecimal6>33.12345</lfdecimal6>
+    <lfenum>enum3</lfenum>
+    <lfbits>bit3 bit2</lfbits>
+    <lfbinary>ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</lfbinary>
+    <lfempty />
+    <lfunion1>324</lfunion1>
+    <lfunion2>33.3</lfunion2>
+    <lfunion3>55</lfunion3>
+    <lfunion4>true</lfunion4>
+    <lfunion5>true</lfunion5>
+    <lfunion6>10</lfunion6>
+    <lfunion7></lfunion7>
+    <lfunion8></lfunion8>
+    <lfunion9></lfunion9>
+    <lfunion10>bt1</lfunion10>
+    <lfunion11>33</lfunion11>
+    <lfunion12>false</lfunion12>
+    <lfunion13>b1</lfunion13>
+    <lfunion14>zero</lfunion14>
+    <identityref1 xmlns:x="simple:data:types">x:iden</identityref1>
 </cont>
\ No newline at end of file
index 17dc2657b05932cf5a0b3685534545c7afa9e24b..61858d28b6042f64d669924de0b839318b910c6c 100644 (file)
@@ -1,63 +1,63 @@
 <cont1>
-       <lf11>lf</lf11>
-       <lflst11>56</lflst11>
-       <lflst11>55</lflst11>
-       <lflst11>57</lflst11>
-       <lflst12>lflst12 str3</lflst12>
-       <lst11>
-               <lst112>
-                       <lf1121>lf1121 str22</lf1121>
-               </lst112>       
-               <lf111>141</lf111>
-               <lf112>lf112 str2</lf112>
-               <lst111>
-                       <lf1111>55</lf1111>
-               </lst111>       
-               <cont111>
-                       <lflst1111>4097</lflst1111>
-                       <lflst1111>2049</lflst1111>
-                       <lflst1111>1025</lflst1111>
-                       <lst1111>
-                               <lf1111A>lf1111A str22</lf1111A>
-                               <lf1111B>8</lf1111B>
-                       </lst1111>
-                       <lf1111>lf1111 str2</lf1111>
-                       <lst1111>
-                               <lf1111B>5</lf1111B>
-                               <lf1111A>lf1111A str21</lf1111A>
-                       </lst1111>
-               </cont111>
-               <lst111>
-                       <lf1111>56</lf1111>
-               </lst111>       
-               <lst112>
-                       <lf1121>lf1121 str21</lf1121>
-               </lst112>       
-       </lst11>
-       <lflst12>lflst12 str1</lflst12> 
-       <lst11>
-               <lf111>140</lf111>
-               <lf112>lf112 str</lf112>
-               <cont111>
-                       <lf1111>lf1111 str</lf1111>
-                       <lflst1111>2048</lflst1111>
-                       <lflst1111>1024</lflst1111>
-                       <lflst1111>4096</lflst1111>
-                       <lst1111>
-                               <lf1111A>lf1111A str11</lf1111A>
-                               <lf1111B>4</lf1111B>
-                       </lst1111>
-                       <lst1111>
-                               <lf1111A>lf1111A str12</lf1111A>
-                               <lf1111B>7</lf1111B>
-                       </lst1111>
-               </cont111>
-               <lst111>
-                       <lf1111>65</lf1111>
-               </lst111>       
-               <lst112>
-                       <lf1121>lf1121 str11</lf1121>
-               </lst112>
-       </lst11>
-       <lflst12>lflst12 str2</lflst12> 
+    <lf11>lf</lf11>
+    <lflst11>56</lflst11>
+    <lflst11>55</lflst11>
+    <lflst11>57</lflst11>
+    <lflst12>lflst12 str3</lflst12>
+    <lst11>
+        <lst112>
+            <lf1121>lf1121 str22</lf1121>
+        </lst112>
+        <lf111>141</lf111>
+        <lf112>lf112 str2</lf112>
+        <lst111>
+            <lf1111>55</lf1111>
+        </lst111>
+        <cont111>
+            <lflst1111>4097</lflst1111>
+            <lflst1111>2049</lflst1111>
+            <lflst1111>1025</lflst1111>
+            <lst1111>
+                <lf1111A>lf1111A str22</lf1111A>
+                <lf1111B>8</lf1111B>
+            </lst1111>
+            <lf1111>lf1111 str2</lf1111>
+            <lst1111>
+                <lf1111B>5</lf1111B>
+                <lf1111A>lf1111A str21</lf1111A>
+            </lst1111>
+        </cont111>
+        <lst111>
+            <lf1111>56</lf1111>
+        </lst111>
+        <lst112>
+            <lf1121>lf1121 str21</lf1121>
+        </lst112>
+    </lst11>
+    <lflst12>lflst12 str1</lflst12>
+    <lst11>
+        <lf111>140</lf111>
+        <lf112>lf112 str</lf112>
+        <cont111>
+            <lf1111>lf1111 str</lf1111>
+            <lflst1111>2048</lflst1111>
+            <lflst1111>1024</lflst1111>
+            <lflst1111>4096</lflst1111>
+            <lst1111>
+                <lf1111A>lf1111A str11</lf1111A>
+                <lf1111B>4</lf1111B>
+            </lst1111>
+            <lst1111>
+                <lf1111A>lf1111A str12</lf1111A>
+                <lf1111B>7</lf1111B>
+            </lst1111>
+        </cont111>
+        <lst111>
+            <lf1111>65</lf1111>
+        </lst111>
+        <lst112>
+            <lf1121>lf1121 str11</lf1121>
+        </lst112>
+    </lst11>
+    <lflst12>lflst12 str2</lflst12>
 </cont1>
index 68470eab26ad9f19955f58a6a8fb458e4707d7e2..9cd503e09b4c5960686fc4555e2cbc4048318c10 100644 (file)
@@ -1,40 +1,40 @@
 <cont1>
-       <lst11>
-               <lf111>1</lf111>
-               <lst111></lst111>       
-               <lst111></lst111>       
-               <lst111>
-                       <lf1111></lf1111>
-               </lst111>       
-               <lst111>
-                       <lf1111>35</lf1111>
-               </lst111>       
-               <cont111></cont111>             
-       </lst11>
-       <lst11>
-               <lf111>2</lf111>
-               <cont111>
-                       <lf1111></lf1111>
-                       <lflst1111></lflst1111>
-                       <lflst1111>1024</lflst1111>
-                       <lflst1111>4096</lflst1111>
-                       <lst1111>
-                               <lf1111B>4</lf1111B>
-                       </lst1111>
-                       <lst1111>
-                               <lf1111A>lf1111A str12</lf1111A>
-                       </lst1111>
-               </cont111>
-               <lst112></lst112>
-       </lst11>
-       <lst11>
-               <lf111>3</lf111>
-               <cont111>
-                       <lf1111></lf1111>
-                       <lflst1111></lflst1111>
-                       <lflst1111></lflst1111>
-                       <lst1111></lst1111>
-                       <lst1111></lst1111>
-               </cont111>
-       </lst11>
+    <lst11>
+        <lf111>1</lf111>
+        <lst111></lst111>
+        <lst111></lst111>
+        <lst111>
+            <lf1111></lf1111>
+        </lst111>
+        <lst111>
+            <lf1111>35</lf1111>
+        </lst111>
+        <cont111></cont111>
+    </lst11>
+    <lst11>
+        <lf111>2</lf111>
+        <cont111>
+            <lf1111></lf1111>
+            <lflst1111></lflst1111>
+            <lflst1111>1024</lflst1111>
+            <lflst1111>4096</lflst1111>
+            <lst1111>
+                <lf1111B>4</lf1111B>
+            </lst1111>
+            <lst1111>
+                <lf1111A>lf1111A str12</lf1111A>
+            </lst1111>
+        </cont111>
+        <lst112></lst112>
+    </lst11>
+    <lst11>
+        <lf111>3</lf111>
+        <cont111>
+            <lf1111></lf1111>
+            <lflst1111></lflst1111>
+            <lflst1111></lflst1111>
+            <lst1111></lst1111>
+            <lst1111></lst1111>
+        </cont111>
+    </lst11>
 </cont1>
index 5954c091e32e86686dbc8de327e6011bd845b4b1..fb9726d5b1f228e38001f008b1890ecf11c5b5f2 100644 (file)
@@ -1,8 +1,8 @@
 <input xmlns="test:module">
-       <cont>
-           <cont1>
-               <lf11>lf1 data</lf11>
-               <lf12>lf2 data</lf12>
-           </cont1>
-       </cont>
+    <cont>
+        <cont1>
+            <lf11>lf1 data</lf11>
+            <lf12>lf2 data</lf12>
+        </cont1>
+    </cont>
 </input>
\ No newline at end of file
index 768cb663ebd4a53dc4898297d0f17b7c79c49987..bd558fb6b912a4e657d2420138d48818b76079c5 100644 (file)
@@ -1,10 +1,10 @@
 <cont xmlns="instance:identifier:module">
     <cont1>
-           <lst11 xmlns="augment:module" xmlns:c="augment:augment:module">
-               <keyvalue111>value1</keyvalue111>
-               <keyvalue112>value2</keyvalue112>
-               <lf111 xmlns="augment:augment:module" xmlns:a="instance:identifier:module" xmlns:b="augment:module" >/a:cont/a:cont1/b:lst11[b:keyvalue111="value1"][b:keyvalue112="value2"]/c:lf112</lf111>
-               <lf112 xmlns="augment:augment:module">lf112 value</lf112>
-           </lst11>
+        <lst11 xmlns="augment:module" xmlns:c="augment:augment:module">
+            <keyvalue111>value1</keyvalue111>
+            <keyvalue112>value2</keyvalue112>
+            <lf111 xmlns="augment:augment:module" xmlns:a="instance:identifier:module" xmlns:b="augment:module" >/a:cont/a:cont1/b:lst11[b:keyvalue111="value1"][b:keyvalue112="value2"]/c:lf112</lf111>
+            <lf112 xmlns="augment:augment:module">lf112 value</lf112>
+        </lst11>
     </cont1>
 </cont>
index 7e3aa97987544bb94a95a680670ceaf670ee1a2b..313f32dce1626d5c43e1fe26edffcd42ba849b69 100644 (file)
@@ -1,8 +1,8 @@
 <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces" >
-       <interface>
-         <name>eth0</name>
-         <type>ethernetCsmacd</type>
-         <enabled>false</enabled>
-         <description>some interface</description>
-       </interface>
+    <interface>
+      <name>eth0</name>
+      <type>ethernetCsmacd</type>
+      <enabled>false</enabled>
+      <description>some interface</description>
+    </interface>
 </interfaces>
\ No newline at end of file
index ce97dd1715c51e8f96b54ca90da5a4d9f6d88ef7..841d351049b5dccb19a58ceb47dcafac3af020bd 100644 (file)
@@ -1,14 +1,14 @@
 <cont>
-       <lf1>str0</lf1>
-       <lf2></lf2>
-       <lf3/>
-       <lflst1>121</lflst1>
-       <lflst1>131</lflst1>
-       <lflst1>str1</lflst1>
-       <lst1>
-               <lf11>str2</lf11>
-       </lst1>                 
-       <cont1>
-               <lf11>100</lf11>
-       </cont1>
+    <lf1>str0</lf1>
+    <lf2></lf2>
+    <lf3/>
+    <lflst1>121</lflst1>
+    <lflst1>131</lflst1>
+    <lflst1>str1</lflst1>
+    <lst1>
+        <lf11>str2</lf11>
+    </lst1>
+    <cont1>
+        <lf11>100</lf11>
+    </cont1>
 </cont>
index cab23c656e7293329b7fd8d9073cc82f0723ce8f..9c4256a50c270a5b5c47580856c0ab9a5042fece 100644 (file)
@@ -1,21 +1,21 @@
 <cont>
-       <lst1>
-               <lf11>str0</lf11>
-               <lflst11>121</lflst11>
-               <lflst11>131</lflst11>
-               <lflst11>str1</lflst11>
-               <lst11>
-                       <lf111>str2</lf111>
-               </lst11>                        
-               <cont11>
-                       <lf111>100</lf111>
-               </cont11>
-       </lst1>
-       <lst1>
-               <lflst11>221</lflst11>
-               <cont11>
-                       <lf111>100</lf111>
-               </cont11>
-       </lst1> 
-       <lf1>lf1</lf1>
+    <lst1>
+        <lf11>str0</lf11>
+        <lflst11>121</lflst11>
+        <lflst11>131</lflst11>
+        <lflst11>str1</lflst11>
+        <lst11>
+            <lf111>str2</lf111>
+        </lst11>
+        <cont11>
+            <lf111>100</lf111>
+        </cont11>
+    </lst1>
+    <lst1>
+        <lflst11>221</lflst11>
+        <cont11>
+            <lf111>100</lf111>
+        </cont11>
+    </lst1>
+    <lf1>lf1</lf1>
 </cont>
index 162a5568877d471e3e489ed6fab1adb0845abc09..7d62b9e24d04f855f04af0044a3ae7236d65857b 100644 (file)
@@ -1,8 +1,8 @@
 <cont>
-       <lf1></lf1>
-       <lflst1></lflst1>
-       <lflst1></lflst1>
-       <lst1>          
-               <lf11></lf11>
-       </lst1>                 
+    <lf1></lf1>
+    <lflst1></lflst1>
+    <lflst1></lflst1>
+    <lst1>
+        <lf11></lf11>
+    </lst1>
 </cont>
index aae2af36d1049922aac169c15f4cdb407b6240d9..ebf7ac61ea3530d290c028e321ab62c01d0359b9 100644 (file)
@@ -1,5 +1,5 @@
 <cont xmlns="general:module" xmlns:x="x:namespace" xmlns:y="y:namespace">
-    <cont1 xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">        
-        <lf11 xmlns="identityref:module" xmlns:c="c:namespace">iden</lf11>  
+    <cont1 xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+        <lf11 xmlns="identityref:module" xmlns:c="c:namespace">iden</lf11>
     </cont1>
 </cont>
\ No newline at end of file
index 621d2bc84c8273bb3d08d70aadcd759e98d6c88c..3fe1e4bf488ea79b9da843e67f1c7706cb354603 100644 (file)
@@ -1,5 +1,5 @@
 <cont xmlns:x="x:namespace" xmlns:y="y:namespace">
-    <cont1 xmlns="identityref:module" xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">        
-        <lf11 xmlns:c="c:namespace">iden</lf11>  
+    <cont1 xmlns="identityref:module" xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+        <lf11 xmlns:c="c:namespace">iden</lf11>
     </cont1>
 </cont>
\ No newline at end of file
index 497c35f2fc6127f5cd6fcd4eeb818ceadad3f924..30a54185ff2d95d7f3bb0ee05712c40c39229174 100644 (file)
@@ -1,5 +1,5 @@
 <cont xmlns="identityref:module" xmlns:x="x:namespace" xmlns:y="y:namespace">
-    <cont1 xmlns:c="identity:module" xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">        
-        <lf11>z:iden</lf11>  
+    <cont1 xmlns:c="identity:module" xmlns:z="z:namespace" xmlns:a="a:namespace" xmlns:b="b:namespace">
+        <lf11>z:iden</lf11>
     </cont1>
 </cont>
\ No newline at end of file
index 9c180014d7f3092d036f213cda23fdc899acb5e2..934412d95af1dce17b281e1b6c6e0f1e0a380bb7 100644 (file)
@@ -7,11 +7,13 @@
  */
 package org.opendaylight.controller.sal.rest.doc;
 
+import java.util.Collection;
+import java.util.Collections;
+
 import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.controller.sal.core.api.Provider;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.controller.sal.rest.doc.impl.ApiDocGenerator;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -20,74 +22,69 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collection;
-import java.util.Collections;
-
-
-public class DocProvider implements BundleActivator,
-                                    ServiceTrackerCustomizer<Broker, Broker>,
-                                    Provider,
-                                    AutoCloseable {
-
-  private Logger _logger = LoggerFactory.getLogger(DocProvider.class);
-
-  private ServiceTracker<Broker, Broker> brokerServiceTracker;
-  private BundleContext bundleContext;
-  private Broker.ProviderSession session;
-
-  @Override
-  public void close() throws Exception {
-    stop(bundleContext);
-  }
-
-  @Override
-  public void onSessionInitiated(Broker.ProviderSession providerSession) {
-    SchemaService schemaService = providerSession.getService(SchemaService.class);
-    ApiDocGenerator.getInstance().setSchemaService(schemaService);
-
-    _logger.debug("Restconf API Explorer started");
-
-  }
-
-  @Override
-  public Collection<ProviderFunctionality> getProviderFunctionality() {
-    return Collections.emptySet();
-  }
-
-  @Override
-  public void start(BundleContext context) throws Exception {
-    bundleContext = context;
-    brokerServiceTracker = new ServiceTracker(context, Broker.class, this);
-    brokerServiceTracker.open();
-  }
-
-  @Override
-  public void stop(BundleContext context) throws Exception {
-    if (brokerServiceTracker != null)
-      brokerServiceTracker.close();
-
-    if (session != null)
-      session.close();
-  }
-
-  @Override
-  public Broker addingService(ServiceReference<Broker> reference) {
-    Broker broker = bundleContext.getService(reference);
-    session = broker.registerProvider(this, bundleContext);
-    return broker;
-  }
-
-  @Override
-  public void modifiedService(ServiceReference<Broker> reference, Broker service) {
-    if (session != null)
-      session.close();
-
-    Broker broker = bundleContext.getService(reference);
-    session = broker.registerProvider(this, bundleContext);
-  }
-
-  @Override
-  public void removedService(ServiceReference<Broker> reference, Broker service) {
-    bundleContext.ungetService(reference);
-  }
+public class DocProvider implements BundleActivator, ServiceTrackerCustomizer<Broker, Broker>, Provider, AutoCloseable {
+
+    private static final Logger _logger = LoggerFactory.getLogger(DocProvider.class);
+
+    private ServiceTracker<Broker, Broker> brokerServiceTracker;
+    private BundleContext bundleContext;
+    private Broker.ProviderSession session;
+
+    @Override
+    public void close() throws Exception {
+        stop(bundleContext);
+    }
+
+    @Override
+    public void onSessionInitiated(final Broker.ProviderSession providerSession) {
+        SchemaService schemaService = providerSession.getService(SchemaService.class);
+        ApiDocGenerator.getInstance().setSchemaService(schemaService);
+
+        _logger.debug("Restconf API Explorer started");
+    }
+
+    @Override
+    public Collection<ProviderFunctionality> getProviderFunctionality() {
+        return Collections.emptySet();
+    }
+
+    @Override
+    public void start(final BundleContext context) throws Exception {
+        bundleContext = context;
+        brokerServiceTracker = new ServiceTracker<>(context, Broker.class, this);
+        brokerServiceTracker.open();
+    }
+
+    @Override
+    public void stop(final BundleContext context) throws Exception {
+        if (brokerServiceTracker != null) {
+            brokerServiceTracker.close();
+        }
+
+        if (session != null) {
+            session.close();
+        }
+    }
+
+    @Override
+    public Broker addingService(final ServiceReference<Broker> reference) {
+        Broker broker = bundleContext.getService(reference);
+        session = broker.registerProvider(this, bundleContext);
+        return broker;
+    }
+
+    @Override
+    public void modifiedService(final ServiceReference<Broker> reference, final Broker service) {
+        if (session != null) {
+            session.close();
+        }
+
+        Broker broker = bundleContext.getService(reference);
+        session = broker.registerProvider(this, bundleContext);
+    }
+
+    @Override
+    public void removedService(final ServiceReference<Broker> reference, final Broker service) {
+        bundleContext.ungetService(reference);
+    }
 }
index 3662090b87895d98a8b3d2a1dab3b0000fc6adfc..bcd11bcb06633bd939de00a2af513353cf1b1f2d 100644 (file)
  */
 package org.opendaylight.controller.sal.rest.doc.impl;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
-import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.core.UriInfo;
+
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.controller.sal.rest.doc.model.builder.OperationBuilder;
-import org.opendaylight.controller.sal.rest.doc.swagger.*;
+import org.opendaylight.controller.sal.rest.doc.swagger.Api;
+import org.opendaylight.controller.sal.rest.doc.swagger.ApiDeclaration;
+import org.opendaylight.controller.sal.rest.doc.swagger.Operation;
+import org.opendaylight.controller.sal.rest.doc.swagger.Parameter;
+import org.opendaylight.controller.sal.rest.doc.swagger.Resource;
+import org.opendaylight.controller.sal.rest.doc.swagger.ResourceList;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.ws.rs.core.UriInfo;
-import java.io.IOException;
-import java.net.URI;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
+import com.google.common.base.Preconditions;
 
 /**
  * This class gathers all yang defined {@link Module}s and generates Swagger compliant documentation.
  */
 public class ApiDocGenerator {
 
-  private static Logger _logger = LoggerFactory.getLogger(ApiDocGenerator.class);
-
-  private static final ApiDocGenerator INSTANCE = new ApiDocGenerator();
-  private ObjectMapper mapper = new ObjectMapper();
-  private final ModelGenerator jsonConverter = new ModelGenerator();
-
-  private SchemaService schemaService;
-
-  private final String API_VERSION = "1.0.0";
-  private final String SWAGGER_VERSION = "1.2";
-  private final String RESTCONF_CONTEXT_ROOT = "restconf";
-  private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
-
-  //For now its {@link HashMap}. It will be changed to thread-safe Map when schema change listener is implemented.
-  private final Map<String, ApiDeclaration> MODULE_DOC_CACHE = new HashMap<String, ApiDeclaration>();
-
-  private ApiDocGenerator(){
-    mapper.registerModule(new JsonOrgModule());
-    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
-  }
-
-  /**
-   * Returns singleton instance
-   * @return
-   */
-  public static ApiDocGenerator getInstance() {
-    return INSTANCE;
-  }
-
-  /**
-   *
-   * @param schemaService
-   */
-  public void setSchemaService(SchemaService schemaService) {
-    this.schemaService = schemaService;
-  }
-  /**
-   *
-   * @param uriInfo
-   * @return  list of modules converted to swagger compliant resource list.
-   */
-  public ResourceList getResourceListing(UriInfo uriInfo) {
-
-    Preconditions.checkState(schemaService != null);
-    SchemaContext schemaContext = schemaService.getGlobalContext();
-    Preconditions.checkState(schemaContext != null);
-
-    Set<Module> modules = schemaContext.getModules();
-
-    ResourceList resourceList = new ResourceList();
-    resourceList.setApiVersion(API_VERSION);
-    resourceList.setSwaggerVersion(SWAGGER_VERSION);
-
-    List<Resource> resources = new ArrayList<>(modules.size());
-    _logger.info("Modules found [{}]", modules.size());
-
-    for (Module module : modules) {
-      Resource resource = new Resource();
-      String revisionString = SIMPLE_DATE_FORMAT.format(module.getRevision());
-
-      _logger.debug("Working on [{},{}]...", module.getName(), revisionString);
-      ApiDeclaration doc = getApiDeclaration(module.getName(), revisionString, uriInfo);
-
-      if (doc != null) {
-        URI uri = uriInfo.getRequestUriBuilder().
-            path(generateCacheKey(module.getName(), revisionString)).
-            build();
-
-        resource.setPath(uri.toASCIIString());
-        resources.add(resource);
-      } else {
-        _logger.debug("Could not generate doc for {},{}", module.getName(), revisionString);
-      }
-    }
+    private static final Logger _logger = LoggerFactory.getLogger(ApiDocGenerator.class);
 
-    resourceList.setApis(resources);
+    private static final ApiDocGenerator INSTANCE = new ApiDocGenerator();
+    private final ObjectMapper mapper = new ObjectMapper();
+    private final ModelGenerator jsonConverter = new ModelGenerator();
 
-    return resourceList;
-  }
+    private SchemaService schemaService;
 
-  public ApiDeclaration getApiDeclaration(String module, String revision, UriInfo uriInfo) {
+    private static final String API_VERSION = "1.0.0";
+    private static final String SWAGGER_VERSION = "1.2";
+    private static final String RESTCONF_CONTEXT_ROOT = "restconf";
+    private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
 
-    //Lookup cache
-    String cacheKey = generateCacheKey(module, revision);
+    //For now its {@link HashMap}. It will be changed to thread-safe Map when schema change listener is implemented.
+    private final Map<String, ApiDeclaration> MODULE_DOC_CACHE = new HashMap<String, ApiDeclaration>();
 
-    if (MODULE_DOC_CACHE.containsKey(cacheKey)) {
-      _logger.debug("Serving from cache for {}", cacheKey);
-      return MODULE_DOC_CACHE.get(cacheKey);
+    private ApiDocGenerator(){
+        mapper.registerModule(new JsonOrgModule());
+        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
     }
 
-    Date rev = null;
-    try {
-      rev = SIMPLE_DATE_FORMAT.parse(revision);
-    } catch (ParseException e) {
-      throw new IllegalArgumentException(e);
+    /**
+     * Returns singleton instance
+     * @return
+     */
+    public static ApiDocGenerator getInstance() {
+        return INSTANCE;
     }
 
-    SchemaContext schemaContext = schemaService.getGlobalContext();
-    Preconditions.checkState(schemaContext != null);
+    /**
+     *
+     * @param schemaService
+     */
+    public void setSchemaService(final SchemaService schemaService) {
+        this.schemaService = schemaService;
+    }
+    /**
+     *
+     * @param uriInfo
+     * @return  list of modules converted to swagger compliant resource list.
+     */
+    public ResourceList getResourceListing(final UriInfo uriInfo) {
+
+        Preconditions.checkState(schemaService != null);
+        SchemaContext schemaContext = schemaService.getGlobalContext();
+        Preconditions.checkState(schemaContext != null);
+
+        Set<Module> modules = schemaContext.getModules();
+
+        ResourceList resourceList = new ResourceList();
+        resourceList.setApiVersion(API_VERSION);
+        resourceList.setSwaggerVersion(SWAGGER_VERSION);
+
+        List<Resource> resources = new ArrayList<>(modules.size());
+        _logger.info("Modules found [{}]", modules.size());
+
+        for (Module module : modules) {
+            Resource resource = new Resource();
+            String revisionString = SIMPLE_DATE_FORMAT.format(module.getRevision());
+
+            _logger.debug("Working on [{},{}]...", module.getName(), revisionString);
+            ApiDeclaration doc = getApiDeclaration(module.getName(), revisionString, uriInfo);
+
+            if (doc != null) {
+                URI uri = uriInfo.getRequestUriBuilder().
+                        path(generateCacheKey(module.getName(), revisionString)).
+                        build();
+
+                resource.setPath(uri.toASCIIString());
+                resources.add(resource);
+            } else {
+                _logger.debug("Could not generate doc for {},{}", module.getName(), revisionString);
+            }
+        }
+
+        resourceList.setApis(resources);
+
+        return resourceList;
+    }
+
+    public ApiDeclaration getApiDeclaration(final String module, final String revision, final UriInfo uriInfo) {
+
+        //Lookup cache
+        String cacheKey = generateCacheKey(module, revision);
 
-    Module m = schemaContext.findModuleByName(module, rev);
-    Preconditions.checkArgument(m != null, "Could not find module by name,revision: " + module + "," + revision);
+        if (MODULE_DOC_CACHE.containsKey(cacheKey)) {
+            _logger.debug("Serving from cache for {}", cacheKey);
+            return MODULE_DOC_CACHE.get(cacheKey);
+        }
+
+        Date rev = null;
+        try {
+            rev = SIMPLE_DATE_FORMAT.parse(revision);
+        } catch (ParseException e) {
+            throw new IllegalArgumentException(e);
+        }
 
-    String basePath = new StringBuilder(uriInfo.getBaseUri().getScheme())
+        SchemaContext schemaContext = schemaService.getGlobalContext();
+        Preconditions.checkState(schemaContext != null);
+
+        Module m = schemaContext.findModuleByName(module, rev);
+        Preconditions.checkArgument(m != null, "Could not find module by name,revision: " + module + "," + revision);
+
+        String basePath = new StringBuilder(uriInfo.getBaseUri().getScheme())
         .append("://")
         .append(uriInfo.getBaseUri().getHost())
         .append(":")
@@ -146,161 +166,161 @@ public class ApiDocGenerator {
         .append(RESTCONF_CONTEXT_ROOT)
         .toString();
 
-    ApiDeclaration doc = getSwaggerDocSpec(m, basePath);
-    MODULE_DOC_CACHE.put(cacheKey, doc);
-    return doc;
-  }
+        ApiDeclaration doc = getSwaggerDocSpec(m, basePath);
+        MODULE_DOC_CACHE.put(cacheKey, doc);
+        return doc;
+    }
 
-  public ApiDeclaration getSwaggerDocSpec(Module m, String basePath) {
-    ApiDeclaration doc = new ApiDeclaration();
-    doc.setApiVersion(API_VERSION);
-    doc.setSwaggerVersion(SWAGGER_VERSION);
-    doc.setBasePath(basePath);
-    doc.setProduces(Arrays.asList("application/json", "application/xml"));
+    public ApiDeclaration getSwaggerDocSpec(final Module m, final String basePath) {
+        ApiDeclaration doc = new ApiDeclaration();
+        doc.setApiVersion(API_VERSION);
+        doc.setSwaggerVersion(SWAGGER_VERSION);
+        doc.setBasePath(basePath);
+        doc.setProduces(Arrays.asList("application/json", "application/xml"));
 
-    List<Api> apis = new ArrayList<Api>();
+        List<Api> apis = new ArrayList<Api>();
 
-    Set<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
-    _logger.debug("child nodes size [{}]", dataSchemaNodes.size());
-    for (DataSchemaNode node : dataSchemaNodes) {
-      if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
+        Set<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
+        _logger.debug("child nodes size [{}]", dataSchemaNodes.size());
+        for (DataSchemaNode node : dataSchemaNodes) {
+            if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
 
-        _logger.debug("Is Configuration node [{}] [{}]", node.isConfiguration(), node.getQName().getLocalName());
+                _logger.debug("Is Configuration node [{}] [{}]", node.isConfiguration(), node.getQName().getLocalName());
 
-        List<Parameter> pathParams = null;
-        if (node.isConfiguration()) {
-          pathParams = new ArrayList<Parameter>();
-          String resourcePath = "/config/" + m.getName() + ":";
-          addApis(node, apis, resourcePath, pathParams, true);
+                List<Parameter> pathParams = null;
+                if (node.isConfiguration()) {
+                    pathParams = new ArrayList<Parameter>();
+                    String resourcePath = "/config/" + m.getName() + ":";
+                    addApis(node, apis, resourcePath, pathParams, true);
 
+                }
+
+                pathParams = new ArrayList<Parameter>();
+                String resourcePath = "/operational/" + m.getName() + ":";
+                addApis(node, apis, resourcePath, pathParams, false);
+            }
         }
 
-        pathParams = new ArrayList<Parameter>();
-        String resourcePath = "/operational/" + m.getName() + ":";
-        addApis(node, apis, resourcePath, pathParams, false);
-      }
-    }
+        Set<RpcDefinition> rpcs = m.getRpcs();
+        for (RpcDefinition rpcDefinition : rpcs) {
+            String resourcePath = "/operations/" + m.getName() + ":";
+            addRpcs(rpcDefinition, apis, resourcePath);
 
-    Set<RpcDefinition> rpcs = m.getRpcs();
-    for (RpcDefinition rpcDefinition : rpcs) {
-      String resourcePath = "/operations/" + m.getName() + ":";
-      addRpcs(rpcDefinition, apis, resourcePath);
+        }
+        _logger.debug("Number of APIs found [{}]", apis.size());
+        doc.setApis(apis);
+        JSONObject models = null;
+
+        try {
+            models = jsonConverter.convertToJsonSchema(m);
+            doc.setModels(models);
+            _logger.debug(mapper.writeValueAsString(doc));
+        } catch (IOException | JSONException e) {
+            e.printStackTrace();
+        }
 
+        return doc;
     }
-    _logger.debug("Number of APIs found [{}]", apis.size());
-    doc.setApis(apis);
-    JSONObject models = null;
-
-    try {
-      models = jsonConverter.convertToJsonSchema(m);
-      doc.setModels(models);
-      _logger.debug(mapper.writeValueAsString(doc));
-    } catch (IOException | JSONException e) {
-      e.printStackTrace();
+
+    private String generateCacheKey(final Module m) {
+        return generateCacheKey(m.getName(), SIMPLE_DATE_FORMAT.format(m.getRevision()));
     }
 
-    return doc;
-  }
-
-  private String generateCacheKey(Module m) {
-    return generateCacheKey(m.getName(), SIMPLE_DATE_FORMAT.format(m.getRevision()));
-  }
-
-  private String generateCacheKey(String module, String revision) {
-    return module + "," + revision;
-  }
-
-  private void addApis(DataSchemaNode node,
-                       List<Api> apis,
-                       String parentPath,
-                       List<Parameter> parentPathParams,
-                       boolean addConfigApi) {
-
-    Api api = new Api();
-    List<Parameter> pathParams = new ArrayList<Parameter>(parentPathParams);
-
-    String resourcePath = parentPath + createPath(node, pathParams) + "/";
-    _logger.debug("Adding path: [{}]", resourcePath);
-    api.setPath(resourcePath);
-    api.setOperations(operations(node, pathParams, addConfigApi));
-    apis.add(api);
-    if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
-      DataNodeContainer schemaNode = (DataNodeContainer) node;
-      Set<DataSchemaNode> dataSchemaNodes = schemaNode.getChildNodes();
-
-      for (DataSchemaNode childNode : dataSchemaNodes) {
-        addApis(childNode, apis, resourcePath, pathParams, addConfigApi);
-      }
+    private String generateCacheKey(final String module, final String revision) {
+        return module + "," + revision;
     }
 
-  }
+    private void addApis(final DataSchemaNode node,
+            final List<Api> apis,
+            final String parentPath,
+            final List<Parameter> parentPathParams,
+            final boolean addConfigApi) {
+
+        Api api = new Api();
+        List<Parameter> pathParams = new ArrayList<Parameter>(parentPathParams);
+
+        String resourcePath = parentPath + createPath(node, pathParams) + "/";
+        _logger.debug("Adding path: [{}]", resourcePath);
+        api.setPath(resourcePath);
+        api.setOperations(operations(node, pathParams, addConfigApi));
+        apis.add(api);
+        if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
+            DataNodeContainer schemaNode = (DataNodeContainer) node;
+            Set<DataSchemaNode> dataSchemaNodes = schemaNode.getChildNodes();
+
+            for (DataSchemaNode childNode : dataSchemaNodes) {
+                addApis(childNode, apis, resourcePath, pathParams, addConfigApi);
+            }
+        }
 
-  private void addRpcs(RpcDefinition rpcDefn, List<Api> apis, String parentPath) {
-    Api rpc = new Api();
-    String resourcePath = parentPath + rpcDefn.getQName().getLocalName();
-    rpc.setPath(resourcePath);
+    }
+
+    private void addRpcs(final RpcDefinition rpcDefn, final List<Api> apis, final String parentPath) {
+        Api rpc = new Api();
+        String resourcePath = parentPath + rpcDefn.getQName().getLocalName();
+        rpc.setPath(resourcePath);
 
-    Operation operationSpec = new Operation();
-    operationSpec.setMethod("POST");
-    operationSpec.setNotes(rpcDefn.getDescription());
-    operationSpec.setNickname(rpcDefn.getQName().getLocalName());
-    rpc.setOperations(Arrays.asList(operationSpec));
+        Operation operationSpec = new Operation();
+        operationSpec.setMethod("POST");
+        operationSpec.setNotes(rpcDefn.getDescription());
+        operationSpec.setNickname(rpcDefn.getQName().getLocalName());
+        rpc.setOperations(Arrays.asList(operationSpec));
 
-    apis.add(rpc);
-  }
+        apis.add(rpc);
+    }
 
-  /**
-   * @param node
-   * @param pathParams
-   * @return
-   */
-  private List<Operation> operations(DataSchemaNode node, List<Parameter> pathParams, boolean isConfig) {
-    List<Operation> operations = new ArrayList<>();
+    /**
+     * @param node
+     * @param pathParams
+     * @return
+     */
+    private List<Operation> operations(final DataSchemaNode node, final List<Parameter> pathParams, final boolean isConfig) {
+        List<Operation> operations = new ArrayList<>();
 
-    OperationBuilder.Get getBuilder = new OperationBuilder.Get(node);
-    operations.add(getBuilder.pathParams(pathParams).build());
+        OperationBuilder.Get getBuilder = new OperationBuilder.Get(node);
+        operations.add(getBuilder.pathParams(pathParams).build());
 
-    if (isConfig) {
-      OperationBuilder.Post postBuilder = new OperationBuilder.Post(node);
-      operations.add(postBuilder.pathParams(pathParams).build());
+        if (isConfig) {
+            OperationBuilder.Post postBuilder = new OperationBuilder.Post(node);
+            operations.add(postBuilder.pathParams(pathParams).build());
 
-      OperationBuilder.Put putBuilder = new OperationBuilder.Put(node);
-      operations.add(putBuilder.pathParams(pathParams).build());
+            OperationBuilder.Put putBuilder = new OperationBuilder.Put(node);
+            operations.add(putBuilder.pathParams(pathParams).build());
 
-      OperationBuilder.Delete deleteBuilder = new OperationBuilder.Delete(node);
-      operations.add(deleteBuilder.pathParams(pathParams).build());
+            OperationBuilder.Delete deleteBuilder = new OperationBuilder.Delete(node);
+            operations.add(deleteBuilder.pathParams(pathParams).build());
+        }
+        return operations;
     }
-    return operations;
-  }
-
-  private String createPath(final DataSchemaNode schemaNode, List<Parameter> pathParams) {
-    ArrayList<LeafSchemaNode> pathListParams = new ArrayList<LeafSchemaNode>();
-    StringBuilder path = new StringBuilder();
-    QName _qName = schemaNode.getQName();
-    String localName = _qName.getLocalName();
-    path.append(localName);
-
-    if ((schemaNode instanceof ListSchemaNode)) {
-      final List<QName> listKeys = ((ListSchemaNode) schemaNode).getKeyDefinition();
-      for (final QName listKey : listKeys) {
-        {
-          DataSchemaNode _dataChildByName = ((DataNodeContainer) schemaNode).getDataChildByName(listKey);
-          pathListParams.add(((LeafSchemaNode) _dataChildByName));
-
-          String pathParamIdentifier = new StringBuilder("/{").append(listKey.getLocalName()).append("}").toString();
-          path.append(pathParamIdentifier);
-
-          Parameter pathParam = new Parameter();
-          pathParam.setName(listKey.getLocalName());
-          pathParam.setDescription(_dataChildByName.getDescription());
-          pathParam.setType("string");
-          pathParam.setParamType("path");
-
-          pathParams.add(pathParam);
+
+    private String createPath(final DataSchemaNode schemaNode, final List<Parameter> pathParams) {
+        ArrayList<LeafSchemaNode> pathListParams = new ArrayList<LeafSchemaNode>();
+        StringBuilder path = new StringBuilder();
+        QName _qName = schemaNode.getQName();
+        String localName = _qName.getLocalName();
+        path.append(localName);
+
+        if ((schemaNode instanceof ListSchemaNode)) {
+            final List<QName> listKeys = ((ListSchemaNode) schemaNode).getKeyDefinition();
+            for (final QName listKey : listKeys) {
+                {
+                    DataSchemaNode _dataChildByName = ((DataNodeContainer) schemaNode).getDataChildByName(listKey);
+                    pathListParams.add(((LeafSchemaNode) _dataChildByName));
+
+                    String pathParamIdentifier = new StringBuilder("/{").append(listKey.getLocalName()).append("}").toString();
+                    path.append(pathParamIdentifier);
+
+                    Parameter pathParam = new Parameter();
+                    pathParam.setName(listKey.getLocalName());
+                    pathParam.setDescription(_dataChildByName.getDescription());
+                    pathParam.setType("string");
+                    pathParam.setParamType("path");
+
+                    pathParams.add(pathParam);
+                }
+            }
         }
-      }
+        return path.toString();
     }
-    return path.toString();
-  }
 
 }
index 597051ed300549a2c38e5d239706468612a127aa..719dd78064fbee1815078866de80f2f90809ef85 100644 (file)
  */
 package org.opendaylight.controller.sal.rest.doc.impl;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
-import org.opendaylight.yangtools.yang.model.api.*;
-import org.opendaylight.yangtools.yang.model.api.type.*;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
-import org.opendaylight.yangtools.yang.model.util.*;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BooleanType;
+import org.opendaylight.yangtools.yang.model.util.Decimal64;
+import org.opendaylight.yangtools.yang.model.util.EnumerationType;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.Int16;
+import org.opendaylight.yangtools.yang.model.util.Int32;
+import org.opendaylight.yangtools.yang.model.util.Int64;
+import org.opendaylight.yangtools.yang.model.util.Int8;
+import org.opendaylight.yangtools.yang.model.util.StringType;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.model.util.Uint32;
+import org.opendaylight.yangtools.yang.model.util.Uint64;
+import org.opendaylight.yangtools.yang.model.util.Uint8;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
-import java.util.*;
-
 /**
  * Generates JSON Schema for data defined in Yang
  */
 public class ModelGenerator {
 
-  private static Logger _logger = LoggerFactory.getLogger(ModelGenerator.class);
-
-  private static final String BASE_64 = "base64";
-  private static final String BINARY_ENCODING_KEY = "binaryEncoding";
-  private static final String MEDIA_KEY = "media";
-  private static final String ONE_OF_KEY = "oneOf";
-  private static final String UNIQUE_ITEMS_KEY = "uniqueItems";
-  private static final String MAX_ITEMS = "maxItems";
-  private static final String MIN_ITEMS = "minItems";
-  private static final String SCHEMA_URL = "http://json-schema.org/draft-04/schema";
-  private static final String SCHEMA_KEY = "$schema";
-  private static final String MAX_LENGTH_KEY = "maxLength";
-  private static final String MIN_LENGTH_KEY = "minLength";
-  private static final String REQUIRED_KEY = "required";
-  private static final String REF_KEY = "$ref";
-  private static final String ITEMS_KEY = "items";
-  private static final String TYPE_KEY = "type";
-  private static final String PROPERTIES_KEY = "properties";
-  private static final String DESCRIPTION_KEY = "description";
-  private static final String OBJECT_TYPE = "object";
-  private static final String ARRAY_TYPE = "array";
-  private static final String ENUM = "enum";
-  private static final String INTEGER = "integer";
-  private static final String NUMBER = "number";
-  private static final String BOOLEAN = "boolean";
-  private static final String STRING = "string";
-
-  private static final Map<Class<? extends TypeDefinition<?>>, String> YANG_TYPE_TO_JSON_TYPE_MAPPING;
-
-  static {
-    Map<Class<? extends TypeDefinition<?>>, String> tempMap1 = new HashMap<Class<? extends TypeDefinition<?>>, String>(10);
-    tempMap1.put(StringType.class , STRING);
-    tempMap1.put(BooleanType.class , BOOLEAN);
-    tempMap1.put(Int8.class , INTEGER);
-    tempMap1.put(Int16.class , INTEGER);
-    tempMap1.put(Int32.class , INTEGER);
-    tempMap1.put(Int64.class , INTEGER);
-    tempMap1.put(Uint16.class , INTEGER);
-    tempMap1.put(Uint32.class , INTEGER);
-    tempMap1.put(Uint64.class , INTEGER);
-    tempMap1.put(Uint8.class , INTEGER);
-    tempMap1.put(Decimal64.class , NUMBER);
-    tempMap1.put(EnumerationType.class , ENUM);
-    //TODO: Binary type
-
-    YANG_TYPE_TO_JSON_TYPE_MAPPING = Collections.unmodifiableMap(tempMap1);
-  }
-
-  public ModelGenerator(){
-  }
-
-  public JSONObject convertToJsonSchema(Module module) throws IOException, JSONException {
-    JSONObject models = new JSONObject();
-    processContainers(module, models);
-    processRPCs(module, models);
-
-    return models;
-  }
-
-
-
-  private void processContainers(Module module, JSONObject models) throws IOException, JSONException {
-
-    String moduleName = module.getName();
-    Set<DataSchemaNode> childNodes =  module.getChildNodes();
-
-    for(DataSchemaNode childNode : childNodes){
-      JSONObject moduleJSON=null;
-      String filename = childNode.getQName().getLocalName();
-                       /*
-                        * For every container in the module
-                        */
-      if(childNode instanceof ContainerSchemaNode) {
-        moduleJSON = processContainer((ContainerSchemaNode)childNode, moduleName, true, models);
-      }
-
-      if(moduleJSON!=null) {
-        _logger.debug("Adding model for [{}]", filename);
-        moduleJSON.put("id", filename);
-        models.put(filename, moduleJSON);
-      }
+    private static final Logger _logger = LoggerFactory.getLogger(ModelGenerator.class);
+
+    private static final String BASE_64 = "base64";
+    private static final String BINARY_ENCODING_KEY = "binaryEncoding";
+    private static final String MEDIA_KEY = "media";
+    private static final String ONE_OF_KEY = "oneOf";
+    private static final String UNIQUE_ITEMS_KEY = "uniqueItems";
+    private static final String MAX_ITEMS = "maxItems";
+    private static final String MIN_ITEMS = "minItems";
+    private static final String SCHEMA_URL = "http://json-schema.org/draft-04/schema";
+    private static final String SCHEMA_KEY = "$schema";
+    private static final String MAX_LENGTH_KEY = "maxLength";
+    private static final String MIN_LENGTH_KEY = "minLength";
+    private static final String REQUIRED_KEY = "required";
+    private static final String REF_KEY = "$ref";
+    private static final String ITEMS_KEY = "items";
+    private static final String TYPE_KEY = "type";
+    private static final String PROPERTIES_KEY = "properties";
+    private static final String DESCRIPTION_KEY = "description";
+    private static final String OBJECT_TYPE = "object";
+    private static final String ARRAY_TYPE = "array";
+    private static final String ENUM = "enum";
+    private static final String INTEGER = "integer";
+    private static final String NUMBER = "number";
+    private static final String BOOLEAN = "boolean";
+    private static final String STRING = "string";
+
+    private static final Map<Class<? extends TypeDefinition<?>>, String> YANG_TYPE_TO_JSON_TYPE_MAPPING;
+
+    static {
+        Map<Class<? extends TypeDefinition<?>>, String> tempMap1 = new HashMap<Class<? extends TypeDefinition<?>>, String>(10);
+        tempMap1.put(StringType.class , STRING);
+        tempMap1.put(BooleanType.class , BOOLEAN);
+        tempMap1.put(Int8.class , INTEGER);
+        tempMap1.put(Int16.class , INTEGER);
+        tempMap1.put(Int32.class , INTEGER);
+        tempMap1.put(Int64.class , INTEGER);
+        tempMap1.put(Uint16.class , INTEGER);
+        tempMap1.put(Uint32.class , INTEGER);
+        tempMap1.put(Uint64.class , INTEGER);
+        tempMap1.put(Uint8.class , INTEGER);
+        tempMap1.put(Decimal64.class , NUMBER);
+        tempMap1.put(EnumerationType.class , ENUM);
+        //TODO: Binary type
+
+        YANG_TYPE_TO_JSON_TYPE_MAPPING = Collections.unmodifiableMap(tempMap1);
+    }
+
+    public ModelGenerator(){
+    }
+
+    public JSONObject convertToJsonSchema(final Module module) throws IOException, JSONException {
+        JSONObject models = new JSONObject();
+        processContainers(module, models);
+        processRPCs(module, models);
+
+        return models;
+    }
+
+
+
+    private void processContainers(final Module module, final JSONObject models) throws IOException, JSONException {
+
+        String moduleName = module.getName();
+        Set<DataSchemaNode> childNodes =  module.getChildNodes();
+
+        for(DataSchemaNode childNode : childNodes){
+            JSONObject moduleJSON=null;
+            String filename = childNode.getQName().getLocalName();
+            /*
+             * For every container in the module
+             */
+            if(childNode instanceof ContainerSchemaNode) {
+                moduleJSON = processContainer((ContainerSchemaNode)childNode, moduleName, true, models);
+            }
+
+            if(moduleJSON!=null) {
+                _logger.debug("Adding model for [{}]", filename);
+                moduleJSON.put("id", filename);
+                models.put(filename, moduleJSON);
+            }
+        }
+
+    }
+
+
+    /**
+     * Process the RPCs for a Module
+     * Spits out a file each of the name <rpcName>-input.json
+     * and <rpcName>-output.json for each RPC that contains
+     * input & output elements
+     *
+     * @param module
+     * @throws JSONException
+     * @throws IOException
+     */
+    private void processRPCs(final Module module, final JSONObject models) throws JSONException, IOException {
+
+        Set<RpcDefinition> rpcs =  module.getRpcs();
+        String moduleName = module.getName();
+        for(RpcDefinition rpc: rpcs) {
+
+            ContainerSchemaNode input = rpc.getInput();
+            if(input!=null) {
+                JSONObject inputJSON = processContainer(input, moduleName, true, models);
+                String filename = rpc.getQName().getLocalName() + "-input";
+                inputJSON.put("id", filename);
+                //writeToFile(filename, inputJSON.toString(2), moduleName);
+                models.put(filename, inputJSON);
+            }
+
+            ContainerSchemaNode output = rpc.getOutput();
+            if(output!=null) {
+                JSONObject outputJSON = processContainer(output, moduleName, true, models);
+                String filename = rpc.getQName().getLocalName() + "-output";
+                outputJSON.put("id", filename);
+                models.put(filename, outputJSON);
+            }
+        }
+    }
+
+
+    /**
+     * Processes the container node and populates the moduleJSON
+     *
+     * @param container
+     * @param moduleName
+     * @throws JSONException
+     * @throws IOException
+     */
+    private JSONObject processContainer(final ContainerSchemaNode container, final String moduleName, final boolean addSchemaStmt, final JSONObject models) throws JSONException, IOException{
+        JSONObject moduleJSON = getSchemaTemplate();
+        if(addSchemaStmt) {
+            moduleJSON = getSchemaTemplate();
+        } else {
+            moduleJSON = new JSONObject();
+        }
+        moduleJSON.put(TYPE_KEY, OBJECT_TYPE);
+
+        String containerDescription = container.getDescription();
+        moduleJSON.put(DESCRIPTION_KEY, containerDescription);
+
+        Set<DataSchemaNode> containerChildren = container.getChildNodes();
+        JSONObject properties = processChildren(containerChildren, moduleName, models);
+        moduleJSON.put(PROPERTIES_KEY, properties);
+        return moduleJSON;
+    }
+
+    /**
+     * Processes the nodes
+     * @param nodes
+     * @param moduleName
+     * @return
+     * @throws JSONException
+     * @throws IOException
+     */
+    private JSONObject processChildren(final Set<DataSchemaNode> nodes, final String moduleName, final JSONObject models) throws JSONException, IOException {
+
+        JSONObject properties = new JSONObject();
+
+        for(DataSchemaNode node : nodes){
+            String name = node.getQName().getLocalName();
+            JSONObject property = null;
+            if(node instanceof LeafSchemaNode) {
+                property = processLeafNode((LeafSchemaNode)node);
+            } else if (node instanceof ListSchemaNode) {
+                property = processListSchemaNode((ListSchemaNode)node, moduleName, models);
+
+            } else if (node instanceof LeafListSchemaNode) {
+                property = processLeafListNode((LeafListSchemaNode)node);
+
+            } else if (node instanceof ChoiceNode) {
+                property = processChoiceNode((ChoiceNode)node, moduleName, models);
+
+            } else if (node instanceof AnyXmlSchemaNode) {
+                property = processAnyXMLNode((AnyXmlSchemaNode)node);
+
+            } else if (node instanceof ContainerSchemaNode) {
+                property = processContainer((ContainerSchemaNode)node, moduleName, false, models);
+
+            } else {
+                throw new IllegalArgumentException("Unknown DataSchemaNode type: " + node.getClass());
+            }
+
+            property.putOpt(DESCRIPTION_KEY, node.getDescription());
+            properties.put(name, property);
+        }
+        return properties;
+    }
+
+    /**
+     *
+     * @param listNode
+     * @throws JSONException
+     */
+    private JSONObject processLeafListNode(final LeafListSchemaNode listNode) throws JSONException {
+        JSONObject props = new JSONObject();
+        props.put(TYPE_KEY, ARRAY_TYPE);
+
+        JSONObject itemsVal = new JSONObject();
+        processTypeDef(listNode.getType(), itemsVal);
+        props.put(ITEMS_KEY, itemsVal);
+
+        ConstraintDefinition constraints = listNode.getConstraints();
+        processConstraints(constraints, props);
+
+        return props;
     }
 
-  }
-
-
-  /**
-   * Process the RPCs for a Module
-   * Spits out a file each of the name <rpcName>-input.json
-   * and <rpcName>-output.json for each RPC that contains
-   * input & output elements
-   *
-   * @param module
-   * @throws JSONException
-   * @throws IOException
-   */
-  private void processRPCs(Module module, JSONObject models) throws JSONException, IOException {
-
-    Set<RpcDefinition> rpcs =  module.getRpcs();
-    String moduleName = module.getName();
-    for(RpcDefinition rpc: rpcs) {
-
-      ContainerSchemaNode input = rpc.getInput();
-      if(input!=null) {
-        JSONObject inputJSON = processContainer(input, moduleName, true, models);
-        String filename = rpc.getQName().getLocalName() + "-input";
-        inputJSON.put("id", filename);
-        //writeToFile(filename, inputJSON.toString(2), moduleName);
-        models.put(filename, inputJSON);
-      }
-
-      ContainerSchemaNode output = rpc.getOutput();
-      if(output!=null) {
-        JSONObject outputJSON = processContainer(output, moduleName, true, models);
-        String filename = rpc.getQName().getLocalName() + "-output";
-        outputJSON.put("id", filename);
-        models.put(filename, outputJSON);
-      }
+    /**
+     *
+     * @param choiceNode
+     * @param moduleName
+     * @throws JSONException
+     * @throws IOException
+     */
+    private JSONObject processChoiceNode(final ChoiceNode choiceNode, final String moduleName, final JSONObject models) throws JSONException, IOException {
+
+        Set<ChoiceCaseNode> cases = choiceNode.getCases();
+
+        JSONArray choiceProps = new JSONArray();
+        for(ChoiceCaseNode choiceCase: cases) {
+            String choiceName = choiceCase.getQName().getLocalName();
+            JSONObject choiceProp = processChildren(choiceCase.getChildNodes(), moduleName, models);
+            JSONObject choiceObj = new JSONObject();
+            choiceObj.put(choiceName, choiceProp);
+            choiceObj.put(TYPE_KEY, OBJECT_TYPE);
+            choiceProps.put(choiceObj);
+        }
+
+        JSONObject oneOfProps = new JSONObject();
+        oneOfProps.put(ONE_OF_KEY, choiceProps);
+        oneOfProps.put(TYPE_KEY, OBJECT_TYPE);
+
+        return oneOfProps;
     }
-  }
-
-
-  /**
-   * Processes the container node and populates the moduleJSON
-   *
-   * @param container
-   * @param moduleName
-   * @throws JSONException
-   * @throws IOException
-   */
-  private JSONObject processContainer(ContainerSchemaNode container, String moduleName, boolean addSchemaStmt, JSONObject models) throws JSONException, IOException{
-    JSONObject moduleJSON = getSchemaTemplate();
-    if(addSchemaStmt) {
-      moduleJSON = getSchemaTemplate();
-    } else {
-      moduleJSON = new JSONObject();
+
+
+    /**
+     *
+     * @param constraints
+     * @param props
+     * @throws JSONException
+     */
+    private void processConstraints(final ConstraintDefinition constraints, final JSONObject props) throws JSONException {
+        boolean isMandatory = constraints.isMandatory();
+        props.put(REQUIRED_KEY, isMandatory);
+
+        Integer minElements = constraints.getMinElements();
+        Integer maxElements = constraints.getMaxElements();
+        if(minElements !=null) {
+            props.put(MIN_ITEMS, minElements);
+        }
+        if(maxElements !=null) {
+            props.put(MAX_ITEMS, maxElements);
+        }
     }
-    moduleJSON.put(TYPE_KEY, OBJECT_TYPE);
-
-    String containerDescription = container.getDescription();
-    moduleJSON.put(DESCRIPTION_KEY, containerDescription);
-
-    Set<DataSchemaNode> containerChildren = ((ContainerSchemaNode)container).getChildNodes();
-    JSONObject properties = processChildren(containerChildren, moduleName, models);
-    moduleJSON.put(PROPERTIES_KEY, properties);
-    return moduleJSON;
-  }
-
-  /**
-   * Processes the nodes
-   * @param nodes
-   * @param moduleName
-   * @return
-   * @throws JSONException
-   * @throws IOException
-   */
-  private JSONObject processChildren(Set<DataSchemaNode> nodes, String moduleName, JSONObject models) throws JSONException, IOException {
-
-    JSONObject properties = new JSONObject();
-
-    for(DataSchemaNode node : nodes){
-      String name = node.getQName().getLocalName();
-      JSONObject property = null;
-      if(node instanceof LeafSchemaNode) {
-        property = processLeafNode((LeafSchemaNode)node);
-      } else if (node instanceof ListSchemaNode) {
-        property = processListSchemaNode((ListSchemaNode)node, moduleName, models);
-
-      } else if (node instanceof LeafListSchemaNode) {
-        property = processLeafListNode((LeafListSchemaNode)node);
-
-      } else if (node instanceof ChoiceNode) {
-        property = processChoiceNode((ChoiceNode)node, moduleName, models);
-
-      } else if (node instanceof AnyXmlSchemaNode) {
-        property = processAnyXMLNode((AnyXmlSchemaNode)node);
-
-      } else if (node instanceof ContainerSchemaNode) {
-        property = processContainer((ContainerSchemaNode)node, moduleName, false, models);
-
-      } else {
-        throw new IllegalArgumentException("Unknown DataSchemaNode type: " + node.getClass());
-      }
-
-      property.putOpt(DESCRIPTION_KEY, node.getDescription());
-      properties.put(name, property);
+
+    /**
+     * Parses a ListSchema node.
+     *
+     * Due to a limitation of the RAML--->JAX-RS tool, sub-properties
+     * must be in a separate JSON schema file. Hence, we have to write
+     * some properties to a new file, while continuing to process the rest.
+     *
+     * @param listNode
+     * @param moduleName
+     * @return
+     * @throws JSONException
+     * @throws IOException
+     */
+    private JSONObject processListSchemaNode(final ListSchemaNode listNode, final String moduleName, final JSONObject models) throws JSONException, IOException {
+
+        Set<DataSchemaNode> listChildren = listNode.getChildNodes();
+        String fileName = listNode.getQName().getLocalName();
+
+        JSONObject childSchemaProperties = processChildren(listChildren, moduleName, models);
+        JSONObject childSchema = getSchemaTemplate();
+        childSchema.put(TYPE_KEY, OBJECT_TYPE);
+        childSchema.put(PROPERTIES_KEY, childSchemaProperties);
+
+        /*
+         * Due to a limitation of the RAML--->JAX-RS tool, sub-properties
+         * must be in a separate JSON schema file. Hence, we have to write
+         * some properties to a new file, while continuing to process the rest.
+         */
+        //writeToFile(fileName, childSchema.toString(2), moduleName);
+        childSchema.put("id", fileName);
+        models.put(fileName, childSchema);
+
+
+        JSONObject listNodeProperties = new JSONObject();
+        listNodeProperties.put(TYPE_KEY, ARRAY_TYPE);
+
+        JSONObject items = new JSONObject();
+        items.put(REF_KEY,fileName );
+        listNodeProperties.put(ITEMS_KEY, items);
+
+        return listNodeProperties;
+
     }
-    return properties;
-  }
-
-  /**
-   *
-   * @param listNode
-   * @throws JSONException
-   */
-  private JSONObject processLeafListNode(LeafListSchemaNode listNode) throws JSONException {
-    JSONObject props = new JSONObject();
-    props.put(TYPE_KEY, ARRAY_TYPE);
-
-    JSONObject itemsVal = new JSONObject();
-    processTypeDef(listNode.getType(), itemsVal);
-    props.put(ITEMS_KEY, itemsVal);
-
-    ConstraintDefinition constraints = listNode.getConstraints();
-    processConstraints(constraints, props);
-
-    return props;
-  }
-
-  /**
-   *
-   * @param choiceNode
-   * @param moduleName
-   * @throws JSONException
-   * @throws IOException
-   */
-  private JSONObject processChoiceNode(ChoiceNode choiceNode, String moduleName, JSONObject models) throws JSONException, IOException {
-
-    Set<ChoiceCaseNode> cases = choiceNode.getCases();
-
-    JSONArray choiceProps = new JSONArray();
-    for(ChoiceCaseNode choiceCase: cases) {
-      String choiceName = choiceCase.getQName().getLocalName();
-      JSONObject choiceProp = processChildren(choiceCase.getChildNodes(), moduleName, models);
-      JSONObject choiceObj = new JSONObject();
-      choiceObj.put(choiceName, choiceProp);
-      choiceObj.put(TYPE_KEY, OBJECT_TYPE);
-      choiceProps.put(choiceObj);
+
+    /**
+     *
+     * @param leafNode
+     * @return
+     * @throws JSONException
+     */
+    private JSONObject processLeafNode(final LeafSchemaNode leafNode) throws JSONException {
+        JSONObject property = new JSONObject();
+
+        String leafDescription = leafNode.getDescription();
+        property.put(DESCRIPTION_KEY, leafDescription);
+
+        processConstraints(leafNode.getConstraints(), property);
+        processTypeDef(leafNode.getType(), property);
+
+        return property;
     }
 
-    JSONObject oneOfProps = new JSONObject();
-    oneOfProps.put(ONE_OF_KEY, choiceProps);
-    oneOfProps.put(TYPE_KEY, OBJECT_TYPE);
+    /**
+     *
+     * @param leafNode
+     * @return
+     * @throws JSONException
+     */
+    private JSONObject processAnyXMLNode(final AnyXmlSchemaNode leafNode) throws JSONException {
+        JSONObject property = new JSONObject();
 
-    return oneOfProps;
-  }
+        String leafDescription = leafNode.getDescription();
+        property.put(DESCRIPTION_KEY, leafDescription);
 
+        processConstraints(leafNode.getConstraints(), property);
 
-  /**
-   *
-   * @param constraints
-   * @param props
-   * @throws JSONException
-   */
-  private void processConstraints(ConstraintDefinition constraints, JSONObject props) throws JSONException {
-    boolean isMandatory = constraints.isMandatory();
-    props.put(REQUIRED_KEY, isMandatory);
+        return property;
+    }
 
-    Integer minElements = constraints.getMinElements();
-    Integer maxElements = constraints.getMaxElements();
-    if(minElements !=null) {
-      props.put(MIN_ITEMS, minElements);
+    /**
+     * @param property
+     * @throws JSONException
+     */
+    private void processTypeDef(final TypeDefinition<?> leafTypeDef, final JSONObject property) throws JSONException {
+
+        if(leafTypeDef instanceof ExtendedType){
+            processExtendedType(leafTypeDef, property);
+        } else if (leafTypeDef instanceof EnumerationType) {
+            processEnumType((EnumerationType)leafTypeDef, property);
+
+        } else if (leafTypeDef instanceof BitsTypeDefinition) {
+            processBitsType((BitsTypeDefinition)leafTypeDef, property);
+
+        } else if (leafTypeDef instanceof UnionTypeDefinition) {
+            processUnionType((UnionTypeDefinition)leafTypeDef, property);
+
+        } else if (leafTypeDef instanceof IdentityrefTypeDefinition) {
+            property.putOpt(TYPE_KEY, "object");
+        } else if (leafTypeDef instanceof BinaryTypeDefinition) {
+            processBinaryType((BinaryTypeDefinition)leafTypeDef, property);
+        } else {
+            //System.out.println("In else: " + leafTypeDef.getClass());
+            String jsonType = YANG_TYPE_TO_JSON_TYPE_MAPPING.get(leafTypeDef.getClass());
+            if(jsonType==null) {
+                jsonType = "object";
+            }
+            property.putOpt(TYPE_KEY, jsonType);
+        }
     }
-    if(maxElements !=null) {
-      props.put(MAX_ITEMS, maxElements);
+
+    /**
+     *
+     * @param leafTypeDef
+     * @param property
+     * @throws JSONException
+     */
+    private void processExtendedType(final TypeDefinition<?> leafTypeDef, final JSONObject property) throws JSONException {
+        Object leafBaseType = leafTypeDef.getBaseType();
+        if(leafBaseType instanceof ExtendedType){
+            //recursively process an extended type until we hit a base type
+            processExtendedType((TypeDefinition<?>)leafBaseType, property);
+        } else {
+            List<LengthConstraint> lengthConstraints = ((ExtendedType) leafTypeDef).getLengthConstraints();
+            for(LengthConstraint lengthConstraint: lengthConstraints) {
+                Number min = lengthConstraint.getMin();
+                Number max = lengthConstraint.getMax();
+                property.putOpt(MIN_LENGTH_KEY, min);
+                property.putOpt(MAX_LENGTH_KEY, max);
+            }
+            String jsonType = YANG_TYPE_TO_JSON_TYPE_MAPPING.get(leafBaseType.getClass());
+            property.putOpt(TYPE_KEY,jsonType );
+        }
+
     }
-  }
-
-  /**
-   * Parses a ListSchema node.
-   *
-   * Due to a limitation of the RAML--->JAX-RS tool, sub-properties
-   * must be in a separate JSON schema file. Hence, we have to write
-   * some properties to a new file, while continuing to process the rest.
-   *
-   * @param listNode
-   * @param moduleName
-   * @return
-   * @throws JSONException
-   * @throws IOException
-   */
-  private JSONObject processListSchemaNode(ListSchemaNode listNode, String moduleName, JSONObject models) throws JSONException, IOException {
-
-    Set<DataSchemaNode> listChildren = listNode.getChildNodes();
-    String fileName = listNode.getQName().getLocalName();
-
-    JSONObject childSchemaProperties = processChildren(listChildren, moduleName, models);
-    JSONObject childSchema = getSchemaTemplate();
-    childSchema.put(TYPE_KEY, OBJECT_TYPE);
-    childSchema.put(PROPERTIES_KEY, childSchemaProperties);
-
-               /*
-                * Due to a limitation of the RAML--->JAX-RS tool, sub-properties
-                * must be in a separate JSON schema file. Hence, we have to write
-                * some properties to a new file, while continuing to process the rest.
-                */
-    //writeToFile(fileName, childSchema.toString(2), moduleName);
-    childSchema.put("id", fileName);
-    models.put(fileName, childSchema);
-
-
-    JSONObject listNodeProperties = new JSONObject();
-    listNodeProperties.put(TYPE_KEY, ARRAY_TYPE);
-
-    JSONObject items = new JSONObject();
-    items.put(REF_KEY,fileName );
-    listNodeProperties.put(ITEMS_KEY, items);
-
-    return listNodeProperties;
-
-  }
-
-  /**
-   *
-   * @param leafNode
-   * @return
-   * @throws JSONException
-   */
-  private JSONObject processLeafNode(LeafSchemaNode leafNode) throws JSONException {
-    JSONObject property = new JSONObject();
-
-    String leafDescription = leafNode.getDescription();
-    property.put(DESCRIPTION_KEY, leafDescription);
-
-    processConstraints(leafNode.getConstraints(), property);
-    processTypeDef(leafNode.getType(), property);
-
-    return property;
-  }
-
-  /**
-   *
-   * @param leafNode
-   * @return
-   * @throws JSONException
-   */
-  private JSONObject processAnyXMLNode(AnyXmlSchemaNode leafNode) throws JSONException {
-    JSONObject property = new JSONObject();
-
-    String leafDescription = leafNode.getDescription();
-    property.put(DESCRIPTION_KEY, leafDescription);
-
-    processConstraints(leafNode.getConstraints(), property);
-
-    return property;
-  }
-
-  /**
-   * @param property
-   * @throws JSONException
-   */
-  private void processTypeDef(TypeDefinition<?> leafTypeDef, JSONObject property) throws JSONException {
-
-    if(leafTypeDef instanceof ExtendedType){
-      processExtendedType(leafTypeDef, property);
-    } else if (leafTypeDef instanceof EnumerationType) {
-      processEnumType((EnumerationType)leafTypeDef, property);
-
-    } else if (leafTypeDef instanceof BitsTypeDefinition) {
-      processBitsType((BitsTypeDefinition)leafTypeDef, property);
-
-    } else if (leafTypeDef instanceof UnionTypeDefinition) {
-      processUnionType((UnionTypeDefinition)leafTypeDef, property);
-
-    } else if (leafTypeDef instanceof IdentityrefTypeDefinition) {
-      property.putOpt(TYPE_KEY, "object");
-    } else if (leafTypeDef instanceof BinaryTypeDefinition) {
-      processBinaryType((BinaryTypeDefinition)leafTypeDef, property);
-    } else {
-      //System.out.println("In else: " + leafTypeDef.getClass());
-      String jsonType = YANG_TYPE_TO_JSON_TYPE_MAPPING.get(leafTypeDef.getClass());
-      if(jsonType==null) {
-        jsonType = "object";
-      }
-      property.putOpt(TYPE_KEY, jsonType);
+
+    /*
+     *
+     */
+    private void processBinaryType(final BinaryTypeDefinition binaryType, final JSONObject property) throws JSONException {
+        property.put(TYPE_KEY, STRING);
+        JSONObject media = new JSONObject();
+        media.put(BINARY_ENCODING_KEY, BASE_64);
+        property.put(MEDIA_KEY, media);
     }
-  }
-
-  /**
-   *
-   * @param leafTypeDef
-   * @param property
-   * @throws JSONException
-   */
-  private void processExtendedType(TypeDefinition<?> leafTypeDef, JSONObject property) throws JSONException {
-    Object leafBaseType = leafTypeDef.getBaseType();
-    if(leafBaseType instanceof ExtendedType){
-      //recursively process an extended type until we hit a base type
-      processExtendedType((TypeDefinition<?>)leafBaseType, property);
-    } else {
-      List<LengthConstraint> lengthConstraints = ((ExtendedType) leafTypeDef).getLengthConstraints();
-      for(LengthConstraint lengthConstraint: lengthConstraints) {
-        Number min = lengthConstraint.getMin();
-        Number max = lengthConstraint.getMax();
-        property.putOpt(MIN_LENGTH_KEY, min);
-        property.putOpt(MAX_LENGTH_KEY, max);
-      }
-      String jsonType = YANG_TYPE_TO_JSON_TYPE_MAPPING.get(leafBaseType.getClass());
-      property.putOpt(TYPE_KEY,jsonType );
+
+    /**
+     *
+     * @param enumLeafType
+     * @param property
+     * @throws JSONException
+     */
+    private void processEnumType(final EnumerationType enumLeafType, final JSONObject property) throws JSONException {
+        List<EnumPair> enumPairs = enumLeafType.getValues();
+        List<String> enumNames = new ArrayList<String>();
+        for(EnumPair enumPair: enumPairs) {
+            enumNames.add(enumPair.getName());
+        }
+        property.putOpt(ENUM, new JSONArray(enumNames));
     }
 
-  }
-
-  /*
-   *
-   */
-  private void processBinaryType(BinaryTypeDefinition binaryType, JSONObject property) throws JSONException {
-    property.put(TYPE_KEY, STRING);
-    JSONObject media = new JSONObject();
-    media.put(BINARY_ENCODING_KEY, BASE_64);
-    property.put(MEDIA_KEY, media);
-  }
-
-  /**
-   *
-   * @param enumLeafType
-   * @param property
-   * @throws JSONException
-   */
-  private void processEnumType(EnumerationType enumLeafType, JSONObject property) throws JSONException {
-    List<EnumPair> enumPairs = enumLeafType.getValues();
-    List<String> enumNames = new ArrayList<String>();
-    for(EnumPair enumPair: enumPairs) {
-      enumNames.add(enumPair.getName());
+    /**
+     *
+     * @param bitsType
+     * @param property
+     * @throws JSONException
+     */
+    private void processBitsType(final BitsTypeDefinition bitsType, final JSONObject property) throws JSONException{
+        property.put(TYPE_KEY, ARRAY_TYPE);
+        property.put(MIN_ITEMS, 0);
+        property.put(UNIQUE_ITEMS_KEY, true);
+        JSONArray enumValues = new JSONArray();
+
+        List<Bit> bits = bitsType.getBits();
+        for(Bit bit: bits) {
+            enumValues.put(bit.getName());
+        }
+        JSONObject itemsValue = new JSONObject();
+        itemsValue.put(ENUM, enumValues);
+        property.put(ITEMS_KEY, itemsValue);
     }
-    property.putOpt(ENUM, new JSONArray(enumNames));
-  }
-
-  /**
-   *
-   * @param bitsType
-   * @param property
-   * @throws JSONException
-   */
-  private void processBitsType(BitsTypeDefinition bitsType, JSONObject property) throws JSONException{
-    property.put(TYPE_KEY, ARRAY_TYPE);
-    property.put(MIN_ITEMS, 0);
-    property.put(UNIQUE_ITEMS_KEY, true);
-    JSONArray enumValues = new JSONArray();
-
-    List<Bit> bits = bitsType.getBits();
-    for(Bit bit: bits) {
-      enumValues.put(bit.getName());
+
+
+    /**
+     *
+     * @param unionType
+     * @param property
+     * @throws JSONException
+     */
+    private void processUnionType(final UnionTypeDefinition unionType, final JSONObject property) throws JSONException{
+
+        List<TypeDefinition<?>> unionTypes = unionType.getTypes();
+        JSONArray unionArray = new JSONArray();
+        for(TypeDefinition<?> typeDef: unionTypes) {
+            unionArray.put(YANG_TYPE_TO_JSON_TYPE_MAPPING.get(typeDef.getClass()));
+        }
+        property.put(TYPE_KEY, unionArray);
     }
-    JSONObject itemsValue = new JSONObject();
-    itemsValue.put(ENUM, enumValues);
-    property.put(ITEMS_KEY, itemsValue);
-  }
-
-
-  /**
-   *
-   * @param unionType
-   * @param property
-   * @throws JSONException
-   */
-  private void processUnionType(UnionTypeDefinition unionType, JSONObject property) throws JSONException{
-
-    List<TypeDefinition<?>> unionTypes = unionType.getTypes();
-    JSONArray unionArray = new JSONArray();
-    for(TypeDefinition<?> typeDef: unionTypes) {
-      unionArray.put(YANG_TYPE_TO_JSON_TYPE_MAPPING.get(typeDef.getClass()));
+
+
+    /**
+     * Helper method to generate a pre-filled
+     * JSON schema object.
+     * @return
+     * @throws JSONException
+     */
+    private JSONObject getSchemaTemplate() throws JSONException {
+        JSONObject schemaJSON = new JSONObject();
+        schemaJSON.put(SCHEMA_KEY, SCHEMA_URL);
+
+        return schemaJSON;
     }
-    property.put(TYPE_KEY, unionArray);
-  }
-
-
-  /**
-   * Helper method to generate a pre-filled
-   * JSON schema object.
-   * @return
-   * @throws JSONException
-   */
-  private JSONObject getSchemaTemplate() throws JSONException {
-    JSONObject schemaJSON = new JSONObject();
-    schemaJSON.put(SCHEMA_KEY, SCHEMA_URL);
-
-    return schemaJSON;
-  }
 }
index 356a395b97ba81200dc59ad9fc40adeb4a864c94..2a778180d4448dd33ce7cabb17f911e77151df9f 100644 (file)
@@ -31,7 +31,7 @@
         </init-param>
         <init-param>
             <param-name>cors.allowed.headers</param-name>
-            <param-value>Content-Type,X-Requested-With,accept,authorization, 
+            <param-value>Content-Type,X-Requested-With,accept,authorization,
         origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
         </init-param>
         <init-param>
index 4dc3645131106a03d115c66be98b73b5c47c23e8..a23def6262a0af8e6938f59c4f7a92e3c14b0eb7 100644 (file)
@@ -1,15 +1,14 @@
 /**
-* Generated file
+ * Generated file
 
-* Generated from: yang module name: toaster-consumer-impl  yang module local name: toaster-consumer-impl
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Wed Feb 05 11:31:30 CET 2014
-*
-* Do not modify this file unless it is present under src/main directory
-*/
+ * Generated from: yang module name: toaster-consumer-impl  yang module local name: toaster-consumer-impl
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Feb 05 11:31:30 CET 2014
+ *
+ * Do not modify this file unless it is present under src/main directory
+ */
 package org.opendaylight.controller.config.yang.config.kitchen_service.impl;
 
-import org.opendaylight.controller.config.yang.config.kitchen_service.impl.AbstractKitchenServiceModule;
 import org.opendaylight.controller.sample.kitchen.api.EggsType;
 import org.opendaylight.controller.sample.kitchen.api.KitchenService;
 import org.opendaylight.controller.sample.kitchen.impl.KitchenServiceImpl;
@@ -21,17 +20,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
-*
-*/
+ *
+ */
 public final class KitchenServiceModule extends AbstractKitchenServiceModule {
     private static final Logger log = LoggerFactory.getLogger(KitchenServiceModule.class);
 
-    public KitchenServiceModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+    public KitchenServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public KitchenServiceModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
-            KitchenServiceModule oldModule, java.lang.AutoCloseable oldInstance) {
+    public KitchenServiceModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+            final KitchenServiceModule oldModule, final java.lang.AutoCloseable oldInstance) {
 
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
@@ -64,7 +63,7 @@ public final class KitchenServiceModule extends AbstractKitchenServiceModule {
             }
 
             @Override
-            public boolean makeBreakfast( EggsType eggs, Class<? extends ToastType> toast, int toastDoneness ) {
+            public boolean makeBreakfast( final EggsType eggs, final Class<? extends ToastType> toast, final int toastDoneness ) {
                 return kitchenService.makeBreakfast( eggs, toast, toastDoneness );
             }
         }
index 2d6e7f326265a61ee18714a0d8384485c34510e2..0c68cd22540797c8ad493cdc9c1222c9ff757ab3 100644 (file)
@@ -1,21 +1,17 @@
 /**
-* Generated file
+ * Generated file
 
-* Generated from: yang module name: toaster-consumer-impl  yang module local name: toaster-consumer-impl
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Wed Feb 05 11:31:30 CET 2014
-*
-* Do not modify this file unless it is present under src/main directory
-*/
+ * Generated from: yang module name: toaster-consumer-impl  yang module local name: toaster-consumer-impl
+ * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ * Generated at: Wed Feb 05 11:31:30 CET 2014
+ *
+ * Do not modify this file unless it is present under src/main directory
+ */
 package org.opendaylight.controller.config.yang.config.kitchen_service.impl;
 
-import org.opendaylight.controller.config.yang.config.kitchen_service.impl.AbstractKitchenServiceModuleFactory;
-
 /**
-*
-*/
-public class KitchenServiceModuleFactory extends AbstractKitchenServiceModuleFactory
-{
-
+ *
+ */
+public class KitchenServiceModuleFactory extends AbstractKitchenServiceModuleFactory {
 
 }
index c5a2a0d340cfbfb982d62da396bc7bda2c48b178..61c24c6b6413cae9012916bf93001af11fc77f92 100644 (file)
@@ -55,7 +55,7 @@
                               <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-data-broker</type>
                               <name>ref_binding-data-broker</name>
                             </data-broker>
-                    
+
                             <notification-service>
                                 <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">
                                     binding:binding-notification-service
index 7d9cc7ecbd789634e96ddbf32153e534d594dbc4..db216237d01f7f8fe40523c2c62c6b6ecb88abde 100644 (file)
@@ -103,7 +103,7 @@ public final class NodeStatisticsHandler implements AutoCloseable, FlowCapableCo
             final OpendaylightGroupStatisticsService groupStatsService,
             final OpendaylightMeterStatisticsService meterStatsService,
             final OpendaylightPortStatisticsService portStatsService,
-            final OpendaylightQueueStatisticsService queueStatsService, 
+            final OpendaylightQueueStatisticsService queueStatsService,
             final StatisticsRequestScheduler srScheduler) {
         this.dps = Preconditions.checkNotNull(dps);
         this.targetNodeKey = Preconditions.checkNotNull(nodeKey);
@@ -274,20 +274,20 @@ public final class NodeStatisticsHandler implements AutoCloseable, FlowCapableCo
         this.srScheduler.addRequestToSchedulerQueue(flowTableStats);
 
         this.srScheduler.addRequestToSchedulerQueue(flowStats);
-        
+
         this.srScheduler.addRequestToSchedulerQueue(nodeConnectorStats);
-        
+
         this.srScheduler.addRequestToSchedulerQueue(groupStats);
-        
+
         this.srScheduler.addRequestToSchedulerQueue(groupDescStats);
-        
+
         this.srScheduler.addRequestToSchedulerQueue(meterStats);
-        
+
         this.srScheduler.addRequestToSchedulerQueue(meterConfigStats);
-        
+
         this.srScheduler.addRequestToSchedulerQueue(queueStats);
     }
-    
+
     public synchronized void start(final Timer timer) {
         flowStats.start(dps);
         groupDescStats.start(dps);
@@ -313,7 +313,7 @@ public final class NodeStatisticsHandler implements AutoCloseable, FlowCapableCo
         meterStats.close();
         queueStats.close();
 
-        //Clean up queued statistics request from scheduler queue 
+        //Clean up queued statistics request from scheduler queue
         srScheduler.removeRequestsFromSchedulerQueue(this.getNodeRef());
 
         logger.debug("Statistics handler for {} shut down", targetNodeKey.getId());
index d8bea7c63a4606fffaed51a9dce5fe889dca2d36..b96d2be47e11b5f66fda9bc2d4df156e1b08c421 100644 (file)
@@ -66,7 +66,7 @@ public class StatisticsProvider implements AutoCloseable {
     private OpendaylightFlowTableStatisticsService flowTableStatsService;
 
     private OpendaylightQueueStatisticsService queueStatsService;
-    
+
     private final StatisticsRequestScheduler srScheduler;
 
     public StatisticsProvider(final DataProviderService dataService) {
@@ -90,7 +90,7 @@ public class StatisticsProvider implements AutoCloseable {
         flowTableStatsService = rpcRegistry.getRpcService(OpendaylightFlowTableStatisticsService.class);
         queueStatsService = rpcRegistry.getRpcService(OpendaylightQueueStatisticsService.class);
         this.srScheduler.start();
-        
+
         // Start receiving notifications
         this.listenerRegistration = nps.registerNotificationListener(this.updateCommiter);
 
index bea43ef68a05c1000d7a7d904d0c36f6fccc1b4a..0ae33b8c71fa93add1914d79c595c14538b0737f 100644 (file)
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Main responsibility of the class is to check the MD-SAL data store read/write
- * transaction accumulation level and send statistics request if number of pending 
+ * transaction accumulation level and send statistics request if number of pending
  * read/write transactions are zero.
  * @author avishnoi@in.ibm.com
  *
@@ -36,15 +36,15 @@ public class StatisticsRequestScheduler implements DataTransactionListener {
     private final Timer timer = new Timer("request-monitor", true);
 
     // We need ordered retrieval, and O(1) contains operation
-    private final Map<AbstractStatsTracker,Integer> requestQueue = 
+    private final Map<AbstractStatsTracker,Integer> requestQueue =
             Collections.synchronizedMap(new LinkedHashMap<AbstractStatsTracker,Integer>());
-    
+
     private Long PendingTransactions;
-    
+
     private long lastRequestTime = System.nanoTime();
-    
+
     private static final long REQUEST_MONITOR_INTERVAL = 1000;
-    
+
     private final TimerTask task = new TimerTask() {
         @Override
         public void run() {
@@ -58,11 +58,11 @@ public class StatisticsRequestScheduler implements DataTransactionListener {
     public StatisticsRequestScheduler(){
         PendingTransactions = (long) 0;
     }
-    
+
     public void addRequestToSchedulerQueue(AbstractStatsTracker statsRequest){
         requestQueue.put(statsRequest, null);
     }
-    
+
     public void removeRequestsFromSchedulerQueue(NodeRef node){
         AbstractStatsTracker stats = null;
         synchronized(requestQueue){
@@ -97,7 +97,7 @@ public class StatisticsRequestScheduler implements DataTransactionListener {
     }
     @Override
     public void onStatusUpdated(DataModificationTransaction transaction, TransactionStatus status) {
-        
+
         AbstractStatsTracker stats = null;
         synchronized(PendingTransactions){
             switch(status){
@@ -119,7 +119,7 @@ public class StatisticsRequestScheduler implements DataTransactionListener {
         }
         sendStatsRequest(stats);
     }
-    
+
     private void sendStatsRequest(AbstractStatsTracker stats){
         if(stats != null){
             try{
index ed96e3aa0cba19e138537791ceea9a50deb18a45..c539ac81d47b949bfc00edbc973b5df971e471f2 100644 (file)
@@ -24,7 +24,7 @@ class LLDPDiscoveryListener implements PacketProcessingListener {
     LLDPDiscoveryListener(LLDPDiscoveryProvider manager) {
         this.manager = manager;
     }
-    
+
     public void onPacketReceived(PacketReceived lldp) {
         NodeConnectorRef src = LLDPDiscoveryUtils.lldpToNodeConnectorRef(lldp.getPayload());
         if(src != null) {
@@ -32,10 +32,10 @@ class LLDPDiscoveryListener implements PacketProcessingListener {
             ldb.setDestination(lldp.getIngress());
             ldb.setSource(new NodeConnectorRef(src));
             LinkDiscovered ld = ldb.build();
-            
+
             manager.getNotificationService().publish(ld);
             LLDPLinkAger.getInstance().put(ld);
         }
     }
-    
+
 }
index 7d2570551d00a1dac716d7f9de4f02a3a2897527..face5967c247e3f2c073f8100f2489e6cf2e7014 100644 (file)
@@ -37,17 +37,17 @@ public class LLDPLinkAger {
     public static LLDPLinkAger getInstance() {
         return instance;
     }
-    
+
     public void put(LinkDiscovered link) {
         Date expires = new Date();
         expires.setTime(expires.getTime() + LLDPDiscoveryUtils.LLDP_EXPIRATION_TIME);
         linkToDate.put(link, expires);
     }
-    
+
     public void close() {
         timer.cancel();
     }
-    
+
     private class LLDPAgingTask extends TimerTask {
 
         @Override
@@ -64,9 +64,9 @@ public class LLDPLinkAger {
                     }
                 }
             }
-            
+
         }
-        
+
     }
 }
 
index ce42283ebe85eb02bfa67eeb4e3e8a565fca22a3..82ab4432462af79fbbc6fe611f06175fa5cb93e9 100644 (file)
@@ -27,10 +27,10 @@ import org.slf4j.LoggerFactory;
 
 public class LLDPDiscoveryUtils {
     static Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryUtils.class);
-    
+
     public static final Long LLDP_INTERVAL = (long) (1000*5); // Send LLDP every five seconds
     public static final Long LLDP_EXPIRATION_TIME = LLDP_INTERVAL*3; // Let up to three intervals pass before we decide we are expired.
-    
+
     public static String macToString(byte[] mac) {
         StringBuilder b = new StringBuilder();
         for (int i = 0; i < mac.length; i++) {
@@ -39,7 +39,7 @@ public class LLDPDiscoveryUtils {
 
         return b.toString();
     }
-    
+
     public static NodeConnectorRef lldpToNodeConnectorRef(byte[] payload)  {
         Ethernet ethPkt = new Ethernet();
         try {
@@ -50,7 +50,7 @@ public class LLDPDiscoveryUtils {
 
         if (ethPkt.getPayload() instanceof LLDP) {
             LLDP lldp = (LLDP) ethPkt.getPayload();
-    
+
             try {
                 NodeId srcNodeId = null;
                 NodeConnectorId srcNodeConnectorId = null;
index 542e972deb2d7585348876219b5f82dab6ceca14..6dbfd7225b81fe7651881e21f954dee73c729a7f 100644 (file)
@@ -15,12 +15,8 @@ import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMap
 import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNode;
 import static org.opendaylight.md.controller.topology.manager.FlowCapableNodeMapping.toTopologyNodeId;
 
-import java.util.concurrent.Future;
-
 import org.opendaylight.controller.md.sal.binding.util.TypeSafeDataReader;
-import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryListener;
@@ -36,146 +32,128 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRem
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
-
-class FlowCapableTopologyExporter implements //
-        FlowTopologyDiscoveryListener, //
-        OpendaylightInventoryListener //
-{
 
-    protected final static Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyExporter.class);
-    public static TopologyKey topology = new TopologyKey(new TopologyId("flow:1"));
+import com.google.common.base.Preconditions;
 
-    // FIXME: Flow capable topology exporter should use transaction chaining API
-    private DataProviderService dataService;
+class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, OpendaylightInventoryListener {
+    private final InstanceIdentifier<Topology> topology;
+    private final OperationProcessor processor;
 
-    public DataProviderService getDataService() {
-        return dataService;
-    }
-
-    public void setDataService(final DataProviderService dataService) {
-        this.dataService = dataService;
-    }
-
-    private InstanceIdentifier<Topology> topologyPath;
-
-    public void start() {
-        TopologyBuilder tb = new TopologyBuilder();
-        tb.setKey(topology);
-        topologyPath = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, topology).build();
-        Topology top = tb.build();
-        DataModificationTransaction tx = dataService.beginTransaction();
-        tx.putOperationalData(topologyPath, top);
-        listenOnTransactionState(tx.getIdentifier(),tx.commit());
+    FlowCapableTopologyExporter(final OperationProcessor processor, final InstanceIdentifier<Topology> topology) {
+        this.processor = Preconditions.checkNotNull(processor);
+        this.topology = Preconditions.checkNotNull(topology);
     }
 
     @Override
-    public synchronized void onNodeRemoved(final NodeRemoved notification) {
-        NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeRef()).getId());
-        InstanceIdentifier<Node> nodeInstance = toNodeIdentifier(notification.getNodeRef());
-
-        DataModificationTransaction tx = dataService.beginTransaction();
-        tx.removeOperationalData(nodeInstance);
-        removeAffectedLinks(tx, nodeId);
-        listenOnTransactionState(tx.getIdentifier(),tx.commit());
+    public void onNodeRemoved(final NodeRemoved notification) {
+        processor.enqueueOperation(new TopologyOperation() {
+            @Override
+            public void applyOperation(final DataModificationTransaction transaction) {
+                NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeRef()).getId());
+                InstanceIdentifier<Node> nodeInstance = toNodeIdentifier(notification.getNodeRef());
+                transaction.removeOperationalData(nodeInstance);
+                removeAffectedLinks(transaction, nodeId);
+            }
+        });
     }
 
     @Override
-    public synchronized void onNodeUpdated(final NodeUpdated notification) {
+    public void onNodeUpdated(final NodeUpdated notification) {
         FlowCapableNodeUpdated fcnu = notification.getAugmentation(FlowCapableNodeUpdated.class);
         if (fcnu != null) {
-            Node node = toTopologyNode(toTopologyNodeId(notification.getId()), notification.getNodeRef());
-            InstanceIdentifier<Node> path = getNodePath(toTopologyNodeId(notification.getId()));
-            DataModificationTransaction tx = dataService.beginTransaction();
-            tx.putOperationalData(path, node);
-            listenOnTransactionState(tx.getIdentifier(),tx.commit());
+            processor.enqueueOperation(new TopologyOperation() {
+                @Override
+                public void applyOperation(final DataModificationTransaction transaction) {
+                    Node node = toTopologyNode(toTopologyNodeId(notification.getId()), notification.getNodeRef());
+                    InstanceIdentifier<Node> path = getNodePath(toTopologyNodeId(notification.getId()));
+                    transaction.putOperationalData(path, node);
+                }
+            });
         }
     }
 
     @Override
-    public synchronized void onNodeConnectorRemoved(final NodeConnectorRemoved notification) {
-        InstanceIdentifier<TerminationPoint> tpInstance = toTerminationPointIdentifier(notification
-                .getNodeConnectorRef());
-        TpId tpId = toTerminationPointId(getNodeConnectorKey(notification.getNodeConnectorRef()).getId());
-        DataModificationTransaction tx = dataService.beginTransaction();
-        tx.removeOperationalData(tpInstance);
-        removeAffectedLinks(tx, tpId);
-        listenOnTransactionState(tx.getIdentifier(),tx.commit());
+    public void onNodeConnectorRemoved(final NodeConnectorRemoved notification) {
+        processor.enqueueOperation(new TopologyOperation() {
+            @Override
+            public void applyOperation(final DataModificationTransaction transaction) {
+                InstanceIdentifier<TerminationPoint> tpInstance = toTerminationPointIdentifier(notification
+                        .getNodeConnectorRef());
+                TpId tpId = toTerminationPointId(getNodeConnectorKey(notification.getNodeConnectorRef()).getId());
 
+                transaction.removeOperationalData(tpInstance);
+                removeAffectedLinks(transaction, tpId);
+            }
+        });
     }
 
     @Override
-    public synchronized void onNodeConnectorUpdated(final NodeConnectorUpdated notification) {
-        FlowCapableNodeConnectorUpdated fcncu = notification.getAugmentation(FlowCapableNodeConnectorUpdated.class);
+    public void onNodeConnectorUpdated(final NodeConnectorUpdated notification) {
+        final FlowCapableNodeConnectorUpdated fcncu = notification.getAugmentation(FlowCapableNodeConnectorUpdated.class);
         if (fcncu != null) {
-            NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeConnectorRef()).getId());
-            TerminationPoint point = toTerminationPoint(toTerminationPointId(notification.getId()),
-                    notification.getNodeConnectorRef());
-            InstanceIdentifier<TerminationPoint> path = tpPath(nodeId, point.getKey().getTpId());
-
-            DataModificationTransaction tx = dataService.beginTransaction();
-            tx.putOperationalData(path, point);
-            if ((fcncu.getState() != null && fcncu.getState().isLinkDown())
-                    || (fcncu.getConfiguration() != null && fcncu.getConfiguration().isPORTDOWN())) {
-                removeAffectedLinks(tx, point.getTpId());
-            }
-            listenOnTransactionState(tx.getIdentifier(),tx.commit());
+            processor.enqueueOperation(new TopologyOperation() {
+                @Override
+                public void applyOperation(final DataModificationTransaction transaction) {
+                    NodeId nodeId = toTopologyNodeId(getNodeKey(notification.getNodeConnectorRef()).getId());
+                    TerminationPoint point = toTerminationPoint(toTerminationPointId(notification.getId()),
+                            notification.getNodeConnectorRef());
+                    InstanceIdentifier<TerminationPoint> path = tpPath(nodeId, point.getKey().getTpId());
+
+                    transaction.putOperationalData(path, point);
+                    if ((fcncu.getState() != null && fcncu.getState().isLinkDown())
+                            || (fcncu.getConfiguration() != null && fcncu.getConfiguration().isPORTDOWN())) {
+                        removeAffectedLinks(transaction, point.getTpId());
+                    }
+                }
+            });
         }
     }
 
     @Override
-    public synchronized void onLinkDiscovered(final LinkDiscovered notification) {
-        Link link = toTopologyLink(notification);
-        InstanceIdentifier<Link> path = linkPath(link);
-        DataModificationTransaction tx = dataService.beginTransaction();
-        tx.putOperationalData(path, link);
-        listenOnTransactionState(tx.getIdentifier(),tx.commit());
-
+    public void onLinkDiscovered(final LinkDiscovered notification) {
+        processor.enqueueOperation(new TopologyOperation() {
+            @Override
+            public void applyOperation(final DataModificationTransaction transaction) {
+                Link link = toTopologyLink(notification);
+                InstanceIdentifier<Link> path = linkPath(link);
+                transaction.putOperationalData(path, link);
+            }
+        });
     }
 
     @Override
-    public synchronized void onLinkOverutilized(final LinkOverutilized notification) {
+    public void onLinkOverutilized(final LinkOverutilized notification) {
         // NOOP
     }
 
     @Override
-    public synchronized void onLinkRemoved(final LinkRemoved notification) {
-        InstanceIdentifier<Link> path = linkPath(toTopologyLink(notification));
-        DataModificationTransaction tx = dataService.beginTransaction();
-        tx.removeOperationalData(path);
-        listenOnTransactionState(tx.getIdentifier(),tx.commit());
+    public void onLinkRemoved(final LinkRemoved notification) {
+        processor.enqueueOperation(new TopologyOperation() {
+            @Override
+            public void applyOperation(final DataModificationTransaction transaction) {
+                transaction.removeOperationalData(linkPath(toTopologyLink(notification)));
+            }
+        });
     }
 
     @Override
-    public synchronized void onLinkUtilizationNormal(final LinkUtilizationNormal notification) {
+    public void onLinkUtilizationNormal(final LinkUtilizationNormal notification) {
         // NOOP
     }
 
-    private static InstanceIdentifier<Node> toNodeIdentifier(final NodeRef ref) {
+    private InstanceIdentifier<Node> toNodeIdentifier(final NodeRef ref) {
         org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey invNodeKey = getNodeKey(ref);
-
         NodeKey nodeKey = new NodeKey(toTopologyNodeId(invNodeKey.getId()));
-        return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, topology)
-                .child(Node.class, nodeKey).build();
+        return topology.child(Node.class, nodeKey);
     }
 
     private InstanceIdentifier<TerminationPoint> toTerminationPointIdentifier(final NodeConnectorRef ref) {
@@ -186,71 +164,39 @@ class FlowCapableTopologyExporter implements //
 
     private void removeAffectedLinks(final DataModificationTransaction transaction, final NodeId id) {
         TypeSafeDataReader reader = TypeSafeDataReader.forReader(transaction);
-
-        Topology topologyData = reader.readOperationalData(topologyPath);
-        if (topologyData == null) {
-            return;
-        }
-        for (Link link : topologyData.getLink()) {
-            if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
-                InstanceIdentifier<Link> path = topologyPath.child(Link.class, link.getKey());
-                transaction.removeOperationalData(path);
+        Topology topologyData = reader.readOperationalData(topology);
+        if (topologyData != null) {
+            for (Link link : topologyData.getLink()) {
+                if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) {
+                    transaction.removeOperationalData(linkPath(link));
+                }
             }
         }
     }
 
     private void removeAffectedLinks(final DataModificationTransaction transaction, final TpId id) {
         TypeSafeDataReader reader = TypeSafeDataReader.forReader(transaction);
-        Topology topologyData = reader.readOperationalData(topologyPath);
-        if (topologyData == null) {
-            return;
-        }
-        for (Link link : topologyData.getLink()) {
-            if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) {
-                InstanceIdentifier<Link> path = topologyPath.child(Link.class, link.getKey());
-                transaction.removeOperationalData(path);
+        Topology topologyData = reader.readOperationalData(topology);
+        if (topologyData != null) {
+            for (Link link : topologyData.getLink()) {
+                if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) {
+                    transaction.removeOperationalData(linkPath(link));
+                }
             }
         }
     }
 
     private InstanceIdentifier<Node> getNodePath(final NodeId nodeId) {
-        NodeKey nodeKey = new NodeKey(nodeId);
-        return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, topology)
-                .child(Node.class, nodeKey).build();
+        return topology.child(Node.class, new NodeKey(nodeId));
     }
 
     private InstanceIdentifier<TerminationPoint> tpPath(final NodeId nodeId, final TpId tpId) {
         NodeKey nodeKey = new NodeKey(nodeId);
         TerminationPointKey tpKey = new TerminationPointKey(tpId);
-        return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, topology)
-                .child(Node.class, nodeKey).child(TerminationPoint.class, tpKey).build();
+        return topology.child(Node.class, nodeKey).child(TerminationPoint.class, tpKey);
     }
 
     private InstanceIdentifier<Link> linkPath(final Link link) {
-        InstanceIdentifier<Link> linkInstanceId = InstanceIdentifier.builder(NetworkTopology.class)
-                .child(Topology.class, topology).child(Link.class, link.getKey()).build();
-        return linkInstanceId;
-    }
-
-    /**
-     * @param txId transaction identificator
-     * @param future transaction result
-     */
-    private static void listenOnTransactionState(final Object txId, Future<RpcResult<TransactionStatus>> future) {
-        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future),new FutureCallback<RpcResult<TransactionStatus>>() {
-
-            @Override
-            public void onFailure(Throwable t) {
-                LOG.error("Topology export failed for Tx:{}", txId, t);
-
-            }
-
-            @Override
-            public void onSuccess(RpcResult<TransactionStatus> result) {
-                if(!result.isSuccessful()) {
-                    LOG.error("Topology export failed for Tx:{}", txId);
-                }
-            }
-        });
+        return topology.child(Link.class, link.getKey());
     }
 }
index e77ba8769cbcdbd0f51b65820855e5beb7687f0a..d656bda932f2251e18ea7f71f6c19500115456d3 100644 (file)
@@ -7,11 +7,20 @@
  */
 package org.opendaylight.md.controller.topology.manager;
 
+import java.util.concurrent.ExecutionException;
+
 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
@@ -19,58 +28,60 @@ import org.slf4j.LoggerFactory;
 
 public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider implements AutoCloseable {
     private final static Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyProvider.class);
+    private Registration<NotificationListener> listenerRegistration;
+    private Thread thread;
 
-    private DataProviderService dataService;
-
-    public DataProviderService getDataService() {
-        return this.dataService;
-    }
+    /**
+     * Gets called on start of a bundle.
+     *
+     * @param session
+     */
+    @Override
+    public synchronized void onSessionInitiated(final ProviderContext session) {
+        final DataProviderService dataService = session.getSALService(DataProviderService.class);
+        final NotificationProviderService notificationService = session.getSALService(NotificationProviderService.class);
 
-    public void setDataService(final DataProviderService dataService) {
-        this.dataService = dataService;
-    }
+        final String name = "flow:1";
+        final TopologyKey key = new TopologyKey(new TopologyId(name));
+        final InstanceIdentifier<Topology> path = InstanceIdentifier
+                .builder(NetworkTopology.class)
+                .child(Topology.class, key)
+                .build();
 
-    private NotificationProviderService notificationService;
+        final OperationProcessor processor = new OperationProcessor(dataService);
+        final FlowCapableTopologyExporter listener = new FlowCapableTopologyExporter(processor, path);
+        this.listenerRegistration = notificationService.registerNotificationListener(listener);
 
-    public NotificationProviderService getNotificationService() {
-        return this.notificationService;
-    }
+        final DataModificationTransaction tx = dataService.beginTransaction();
+        tx.putOperationalData(path, new TopologyBuilder().setKey(key).build());
+        try {
+            tx.commit().get();
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.warn("Initial topology export failed, continuing anyway", e);
+        }
 
-    public void setNotificationService(final NotificationProviderService notificationService) {
-        this.notificationService = notificationService;
+        thread = new Thread(processor);
+        thread.setDaemon(true);
+        thread.setName("FlowCapableTopologyExporter-" + name);
+        thread.start();
     }
 
-    private final FlowCapableTopologyExporter exporter = new FlowCapableTopologyExporter();
-    private Registration<NotificationListener> listenerRegistration;
-
     @Override
-    public void close() {
-
-        FlowCapableTopologyProvider.LOG.info("FlowCapableTopologyProvider stopped.");
-        dataService = null;
-        notificationService = null;
+    public synchronized void close() throws InterruptedException {
+        LOG.info("FlowCapableTopologyProvider stopped.");
         if (this.listenerRegistration != null) {
             try {
                 this.listenerRegistration.close();
             } catch (Exception e) {
-                throw new IllegalStateException("Exception during close of listener registration.",e);
+                LOG.error("Failed to close listener registration", e);
             }
+            listenerRegistration = null;
+        }
+        if (thread != null) {
+            thread.interrupt();
+            thread.join();
+            thread = null;
         }
-    }
-
-    /**
-     * Gets called on start of a bundle.
-     *
-     * @param session
-     */
-    @Override
-    public void onSessionInitiated(final ProviderContext session) {
-        dataService = session.getSALService(DataProviderService.class);
-        notificationService = session.getSALService(NotificationProviderService.class);
-        this.exporter.setDataService(dataService);
-        this.exporter.start();
-        this.listenerRegistration = notificationService.registerNotificationListener(this.exporter);
-        ;
     }
 
     /**
@@ -81,6 +92,10 @@ public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider im
      */
     @Override
     public void stopImpl(final BundleContext context) {
-        this.close();
+        try {
+            this.close();
+        } catch (InterruptedException e) {
+            LOG.error("Failed to stop provider", e);
+        }
     }
 }
diff --git a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java
new file mode 100644 (file)
index 0000000..d60c880
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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.md.controller.topology.manager;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+
+final class OperationProcessor implements Runnable {
+    private static final Logger LOG = LoggerFactory.getLogger(OperationProcessor.class);
+    private static final int MAX_TRANSACTION_OPERATIONS = 100;
+    private static final int OPERATION_QUEUE_DEPTH = 500;
+
+    private final BlockingQueue<TopologyOperation> queue = new LinkedBlockingQueue<>(OPERATION_QUEUE_DEPTH);
+    // FIXME: Flow capable topology exporter should use transaction chaining API
+    private final DataProviderService dataService;
+
+    OperationProcessor(final DataProviderService dataService) {
+        this.dataService = Preconditions.checkNotNull(dataService);
+    }
+
+    void enqueueOperation(final TopologyOperation task) {
+        try {
+            queue.put(task);
+        } catch (InterruptedException e) {
+            LOG.warn("Interrupted while submitting task {}", task, e);
+        }
+    }
+
+    @Override
+    public void run() {
+        try {
+            for (;;) {
+                TopologyOperation op = queue.take();
+
+                LOG.debug("New operations available, starting transaction");
+                final DataModificationTransaction tx = dataService.beginTransaction();
+
+                int ops = 0;
+                do {
+                    op.applyOperation(tx);
+
+                    ops++;
+                    if (ops < MAX_TRANSACTION_OPERATIONS) {
+                        op = queue.poll();
+                    } else {
+                        op = null;
+                    }
+                } while (op != null);
+
+                LOG.debug("Processed {} operations, submitting transaction", ops);
+
+                try {
+                    final RpcResult<TransactionStatus> s = tx.commit().get();
+                    if (!s.isSuccessful()) {
+                        LOG.error("Topology export failed for Tx:{}", tx.getIdentifier());
+                    }
+                } catch (ExecutionException e) {
+                    LOG.error("Topology export transaction {} failed", tx.getIdentifier(), e.getCause());
+                }
+            }
+        } catch (InterruptedException e) {
+            LOG.info("Interrupted processing, terminating", e);
+        }
+
+        // Drain all events, making sure any blocked threads are unblocked
+        while (!queue.isEmpty()) {
+            queue.poll();
+        }
+    }
+}
diff --git a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/TopologyOperation.java b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/TopologyOperation.java
new file mode 100644 (file)
index 0000000..29d06be
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.md.controller.topology.manager;
+
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+
+/**
+ * Internal interface for submitted operations. Implementations of this
+ * interface are enqueued and batched into data store transactions.
+ */
+interface TopologyOperation {
+    /**
+     * Execute the operation on top of the transaction.
+     *
+     * @param transaction Datastore transaction
+     */
+    void applyOperation(DataModificationTransaction transaction);
+}
\ No newline at end of file
index 799674487f4de5d936067b51b3f9ae392caee897..829ac304bd667f680d813e32ff58ed9f9b0b6f37 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.controller.netconf.client;
 
-import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
 import java.io.IOException;
 import org.opendaylight.controller.netconf.nettyutil.AbstractChannelInitializer;
@@ -31,7 +31,7 @@ final class SshClientChannelInitializer extends AbstractChannelInitializer<Netco
     }
 
     @Override
-    public void initialize(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
+    public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) {
         try {
             final Invoker invoker = Invoker.subsystem("netconf");
             ch.pipeline().addFirst(new SshHandler(authenticationHandler, invoker));
@@ -42,7 +42,7 @@ final class SshClientChannelInitializer extends AbstractChannelInitializer<Netco
     }
 
     @Override
-    protected void initializeSessionNegotiator(final SocketChannel ch,
+    protected void initializeSessionNegotiator(final Channel ch,
                                                final Promise<NetconfClientSession> promise) {
         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER,  AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
                 negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
index 4a0a089fae97e1ff3d1c8b969f6da077e3584cb7..ee8f8baf0151c4cdeb820878ca9c440e60c9b64b 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.controller.netconf.client;
 
-import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
 import org.opendaylight.controller.netconf.nettyutil.AbstractChannelInitializer;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
@@ -24,12 +24,7 @@ class TcpClientChannelInitializer extends AbstractChannelInitializer<NetconfClie
     }
 
     @Override
-    public void initialize(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
-        super.initialize(ch, promise);
-    }
-
-    @Override
-    protected void initializeSessionNegotiator(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
+    protected void initializeSessionNegotiator(final Channel ch, final Promise<NetconfClientSession> promise) {
         ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
                 negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() {
                     @Override
index 60d8f3044aee5667ea04858377d31b109ca88ef0..afa17532d55ce6628b1659db90e666acf1e97250 100644 (file)
@@ -8,24 +8,35 @@
 
 package org.opendaylight.controller.netconf.client.test;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GlobalEventExecutor;
 import java.io.Closeable;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
 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.NetconfClientDispatcherImpl;
 import org.opendaylight.controller.netconf.client.NetconfClientSession;
 import org.opendaylight.controller.netconf.client.NetconfClientSessionListener;
 import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener;
 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
-import io.netty.util.concurrent.Future;
+import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration.NetconfClientProtocol;
+import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder;
+import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
+import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword;
+import org.opendaylight.protocol.framework.NeverReconnectStrategy;
 
 
 /**
@@ -95,4 +106,29 @@ public class TestingNetconfClient implements Closeable {
         Preconditions.checkState(clientSession != null, "Client was not initialized successfully");
         return Sets.newHashSet(clientSession.getServerCapabilities());
     }
+
+    public static void main(String[] args) throws Exception {
+        HashedWheelTimer hashedWheelTimer = new HashedWheelTimer();
+        NioEventLoopGroup nettyGroup = new NioEventLoopGroup();
+        NetconfClientDispatcherImpl netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer);
+        LoginPassword authHandler = new LoginPassword("admin", "admin");
+        TestingNetconfClient client = new TestingNetconfClient("client", netconfClientDispatcher, getClientConfig("127.0.0.1", 1830, true, Optional.of(authHandler)));
+        System.out.println(client.getCapabilities());
+    }
+
+    private static NetconfClientConfiguration getClientConfig(String host ,int port, boolean ssh, Optional<? extends AuthenticationHandler> maybeAuthHandler) throws UnknownHostException {
+        InetSocketAddress netconfAddress = new InetSocketAddress(InetAddress.getByName(host), port);
+        final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
+        b.withAddress(netconfAddress);
+        b.withSessionListener(new SimpleNetconfClientSessionListener());
+        b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE,
+                NetconfClientConfigurationBuilder.DEFAULT_CONNECTION_TIMEOUT_MILLIS));
+        if (ssh) {
+            b.withProtocol(NetconfClientProtocol.SSH);
+            b.withAuthHandler(maybeAuthHandler.get());
+        } else {
+            b.withProtocol(NetconfClientProtocol.TCP);
+        }
+        return b.build();
+    }
 }
index 1d94517152f45215cc7481a963a290a2870640d2..c60506ef447d821d5458dbb399c30a1ab0e94325 100644 (file)
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
         <configuration>
           <instructions>
             <Bundle-Activator>org.opendaylight.controller.netconf.impl.osgi.NetconfImplActivator</Bundle-Activator>
                             io.netty.buffer,
                             io.netty.handler.codec,
                             io.netty.channel.nio,
+                            io.netty.channel.local,
                             javax.annotation,
                             javax.management,
                             javax.net.ssl,
index de3dee14437b804fd18819bb20302a962fd213e2..4dfb7498184af4e7a71f7c40744821e258e00966 100644 (file)
@@ -8,8 +8,13 @@
 
 package org.opendaylight.controller.netconf.impl;
 
+import com.google.common.annotations.VisibleForTesting;
+import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.local.LocalChannel;
+import io.netty.channel.local.LocalServerChannel;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Promise;
 import java.net.InetSocketAddress;
@@ -27,6 +32,7 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSes
         this.initializer = serverChannelInitializer;
     }
 
+    @VisibleForTesting
     public ChannelFuture createServer(InetSocketAddress address) {
 
         return super.createServer(address, new PipelineInitializer<NetconfServerSession>() {
@@ -37,6 +43,15 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSes
         });
     }
 
+    public ChannelFuture createLocalServer(LocalAddress address) {
+        return super.createServer(address, LocalServerChannel.class, new ChannelPipelineInitializer<LocalChannel, NetconfServerSession>() {
+            @Override
+            public void initializeChannel(final LocalChannel ch, final Promise<NetconfServerSession> promise) {
+                initializer.initialize(ch, promise);
+            }
+        });
+    }
+
     public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
 
         public static final String DESERIALIZER_EX_HANDLER_KEY = "deserializerExHandler";
@@ -50,16 +65,15 @@ public class NetconfServerDispatcher extends AbstractDispatcher<NetconfServerSes
         }
 
         @Override
-        protected void initializeMessageDecoder(SocketChannel ch) {
+        protected void initializeMessageDecoder(Channel ch) {
             super.initializeMessageDecoder(ch);
             ch.pipeline().addLast(DESERIALIZER_EX_HANDLER_KEY, new DeserializerExceptionHandler());
         }
 
         @Override
-        protected void initializeSessionNegotiator(SocketChannel ch, Promise<NetconfServerSession> promise) {
+        protected void initializeSessionNegotiator(Channel ch, Promise<NetconfServerSession> promise) {
             ch.pipeline().addAfter(DESERIALIZER_EX_HANDLER_KEY, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR,
                     negotiatorFactory.getSessionNegotiator(null, ch, promise));
         }
     }
-
 }
index 7130dc350134578372348ce829bda08243a5303c..6ab62ef29a82037cd12e01c5f71d88e34a32a5bd 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.controller.netconf.impl.osgi;
 
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.util.HashedWheelTimer;
 import java.lang.management.ManagementFactory;
-import java.net.InetSocketAddress;
 import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.concurrent.TimeUnit;
-
 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
@@ -26,9 +27,6 @@ import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.util.HashedWheelTimer;
-
 public class NetconfImplActivator implements BundleActivator {
 
     private static final Logger logger = LoggerFactory.getLogger(NetconfImplActivator.class);
@@ -40,17 +38,16 @@ public class NetconfImplActivator implements BundleActivator {
     private ServiceRegistration<NetconfMonitoringService> regMonitoring;
 
     @Override
-    public void start(final BundleContext context) {
-        final InetSocketAddress address = NetconfConfigUtil.extractTCPNetconfServerAddress(context,
-                NetconfConfigUtil.DEFAULT_NETCONF_TCP_ADDRESS);
-        final NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
+    public void start(final BundleContext context)  {
+
+        NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
         startOperationServiceFactoryTracker(context, factoriesListener);
 
-        final SessionIdProvider idProvider = new SessionIdProvider();
+        SessionIdProvider idProvider = new SessionIdProvider();
         timer = new HashedWheelTimer();
-
         long connectionTimeoutMillis = NetconfConfigUtil.extractTimeoutMillis(context);
 
+
         commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
 
         SessionMonitoringService monitoringService = startMonitoringService(context, factoriesListener);
@@ -62,24 +59,24 @@ public class NetconfImplActivator implements BundleActivator {
 
         NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer(
                 serverNegotiatorFactory);
+        NetconfServerDispatcher dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup, eventLoopGroup);
 
-        NetconfServerDispatcher dispatch = new NetconfServerDispatcher(serverChannelInitializer, eventLoopGroup,
-                eventLoopGroup);
-
-        logger.info("Starting TCP netconf server at {}", address);
-        dispatch.createServer(address);
+        LocalAddress address = NetconfConfigUtil.getNetconfLocalAddress();
+        logger.trace("Starting local netconf server at {}", address);
+        dispatch.createLocalServer(address);
 
         context.registerService(NetconfOperationProvider.class, factoriesListener, null);
+
     }
 
-    private void startOperationServiceFactoryTracker(final BundleContext context, final NetconfOperationServiceFactoryListenerImpl factoriesListener) {
+    private void startOperationServiceFactoryTracker(BundleContext context, NetconfOperationServiceFactoryListenerImpl factoriesListener) {
         factoriesTracker = new NetconfOperationServiceFactoryTracker(context, factoriesListener);
         factoriesTracker.open();
     }
 
-    private NetconfMonitoringServiceImpl startMonitoringService(final BundleContext context, final NetconfOperationServiceFactoryListenerImpl factoriesListener) {
-        final NetconfMonitoringServiceImpl netconfMonitoringServiceImpl = new NetconfMonitoringServiceImpl(factoriesListener);
-        final Dictionary<String, ?> dic = new Hashtable<>();
+    private NetconfMonitoringServiceImpl startMonitoringService(BundleContext context, NetconfOperationServiceFactoryListenerImpl factoriesListener) {
+        NetconfMonitoringServiceImpl netconfMonitoringServiceImpl = new NetconfMonitoringServiceImpl(factoriesListener);
+        Dictionary<String, ?> dic = new Hashtable<>();
         regMonitoring = context.registerService(NetconfMonitoringService.class, netconfMonitoringServiceImpl, dic);
 
         return netconfMonitoringServiceImpl;
index 140284e4ee1946ab2cc579fba0cf08362440e580..0969bd92a59a7cb6132a2b3b6cb5ad713af5077e 100644 (file)
@@ -16,13 +16,13 @@ import static org.mockito.Mockito.mock;
 
 import ch.ethz.ssh2.Connection;
 import io.netty.channel.ChannelFuture;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.GlobalEventExecutor;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.management.ManagementFactory;
 import java.net.InetSocketAddress;
-import java.nio.file.Files;
 import java.util.Collection;
 import java.util.List;
 import junit.framework.Assert;
@@ -50,16 +50,14 @@ import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
 import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
 import org.opendaylight.controller.netconf.ssh.authentication.PEMGenerator;
 import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
 import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
-import org.opendaylight.controller.sal.authorization.AuthResultEnum;
-import org.opendaylight.controller.usermanager.IUserManager;
 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
 
 public class NetconfITSecureTest extends AbstractNetconfConfigTest {
 
     private static final InetSocketAddress tlsAddress = new InetSocketAddress("127.0.0.1", 12024);
-    private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 12023);
 
     private DefaultCommitNotificationProducer commitNot;
     private NetconfSSHServer sshServer;
@@ -79,13 +77,10 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest {
 
 
         final NetconfServerDispatcher dispatchS = createDispatcher(factoriesListener);
-        ChannelFuture s = dispatchS.createServer(tcpAddress);
+        ChannelFuture s = dispatchS.createLocalServer(NetconfConfigUtil.getNetconfLocalAddress());
         s.await();
-
-        sshServer = NetconfSSHServer.start(tlsAddress.getPort(), tcpAddress, getAuthProvider());
-        Thread thread = new Thread(sshServer);
-        thread.setDaemon(true);
-        thread.start();
+        EventLoopGroup bossGroup  = new NioEventLoopGroup();
+        sshServer = NetconfSSHServer.start(tlsAddress.getPort(), NetconfConfigUtil.getNetconfLocalAddress(), getAuthProvider(), bossGroup);
     }
 
     private NetconfServerDispatcher createDispatcher(NetconfOperationServiceFactoryListenerImpl factoriesListener) {
@@ -140,13 +135,10 @@ public class NetconfITSecureTest extends AbstractNetconfConfigTest {
     }
 
     public AuthProvider getAuthProvider() throws Exception {
-        final IUserManager userManager = mock(IUserManager.class);
-        doReturn(AuthResultEnum.AUTH_ACCEPT).when(userManager).authenticate(anyString(), anyString());
-
-        final File privateKeyFile = Files.createTempFile("tmp-netconf-test", "pk").toFile();
-        privateKeyFile.deleteOnExit();
-        String privateKeyPEMString = PEMGenerator.generateTo(privateKeyFile);
-        return new AuthProvider(userManager, privateKeyPEMString);
+        AuthProvider mock = mock(AuthProvider.class);
+        doReturn(true).when(mock).authenticated(anyString(), anyString());
+        doReturn(PEMGenerator.generate().toCharArray()).when(mock).getPEMAsCharArray();
+        return mock;
     }
 
     public AuthenticationHandler getAuthHandler() throws IOException {
index fd43f67c056407c15dc0692d938b4fad7c30586b..60a5207daa2e74b54cbc5a1a2b1ec9dd423a3f2b 100644 (file)
@@ -8,7 +8,6 @@
 
 package org.opendaylight.controller.netconf.it;
 
-import static java.util.Collections.emptyList;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
@@ -17,6 +16,10 @@ import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
+import com.google.common.base.Throwables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import io.netty.channel.ChannelFuture;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.management.ManagementFactory;
@@ -29,10 +32,8 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeoutException;
-
 import javax.management.ObjectName;
 import javax.xml.parsers.ParserConfigurationException;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -66,32 +67,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2;
 import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
 import org.opendaylight.yangtools.yang.data.impl.codec.IdentityCodec;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import io.netty.channel.ChannelFuture;
-
 public class NetconfITTest extends AbstractNetconfConfigTest {
 
     // TODO refactor, pull common code up to AbstractNetconfITTest
 
-    private static final Logger logger = LoggerFactory.getLogger(NetconfITTest.class);
-
     private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 12023);
-    private static final InetSocketAddress sshAddress = new InetSocketAddress("127.0.0.1", 10830);
-    private static final String USERNAME = "netconf";
-    private static final String PASSWORD = "netconf";
 
-    private NetconfMessage getConfig, getConfigCandidate, editConfig,
-            closeSession, startExi, stopExi;
+
+    private NetconfMessage getConfig, getConfigCandidate, editConfig, closeSession;
     private DefaultCommitNotificationProducer commitNot;
     private NetconfServerDispatcher dispatch;
 
@@ -139,10 +128,6 @@ public class NetconfITTest extends AbstractNetconfConfigTest {
         this.editConfig = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/edit_config.xml");
         this.getConfig = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml");
         this.getConfigCandidate = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig_candidate.xml");
-        this.startExi = XmlFileLoader
-                .xmlFileToNetconfMessage("netconfMessages/startExi.xml");
-        this.stopExi = XmlFileLoader
-                .xmlFileToNetconfMessage("netconfMessages/stopExi.xml");
         this.closeSession = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/closeSession.xml");
     }
 
@@ -166,7 +151,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest {
                 yangDependencies.add(resourceAsStream);
             }
         }
-        assertEquals("Some yang files were not found", emptyList(), failedToFind);
+        assertEquals("Some yang files were not found", Collections.<String>emptyList(), failedToFind);
         return yangDependencies;
     }
 
@@ -198,6 +183,7 @@ public class NetconfITTest extends AbstractNetconfConfigTest {
     public void testTwoSessions() throws Exception {
         try (TestingNetconfClient netconfClient = new TestingNetconfClient("1", clientDispatcher, getClientConfiguration(tcpAddress, 10000)))  {
             try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("2", clientDispatcher, getClientConfiguration(tcpAddress, 10000))) {
+                assertNotNull(netconfClient2.getCapabilities());
             }
         }
     }
index e88bf53ae0a7ccfc95d091521e0587a55fc1ef71..7897666ddc6763cff64f8e7f6dd225f411c9eb54 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.opendaylight.controller.netconf.nettyutil;
 
-import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
 import org.opendaylight.controller.netconf.api.NetconfSession;
 import org.opendaylight.controller.netconf.nettyutil.handler.FramingMechanismHandlerFactory;
@@ -25,7 +25,7 @@ public abstract class AbstractChannelInitializer<S extends NetconfSession> {
     public static final String NETCONF_MESSAGE_FRAME_ENCODER = "frameEncoder";
     public static final String NETCONF_SESSION_NEGOTIATOR = "negotiator";
 
-    public void initialize(SocketChannel ch, Promise<S> promise) {
+    public void initialize(Channel ch, Promise<S> promise) {
         ch.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator());
         initializeMessageDecoder(ch);
         ch.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
@@ -34,13 +34,13 @@ public abstract class AbstractChannelInitializer<S extends NetconfSession> {
         initializeSessionNegotiator(ch, promise);
     }
 
-    protected void initializeMessageEncoder(SocketChannel ch) {
+    protected void initializeMessageEncoder(Channel ch) {
         // Special encoding handler for hello message to include additional header if available,
         // it is thrown away after successful negotiation
         ch.pipeline().addLast(NETCONF_MESSAGE_ENCODER, new NetconfHelloMessageToXMLEncoder());
     }
 
-    protected void initializeMessageDecoder(SocketChannel ch) {
+    protected void initializeMessageDecoder(Channel ch) {
         // Special decoding handler for hello message to parse additional header if available,
         // it is thrown away after successful negotiation
         ch.pipeline().addLast(NETCONF_MESSAGE_DECODER, new NetconfXMLToHelloMessageDecoder());
@@ -50,6 +50,6 @@ public abstract class AbstractChannelInitializer<S extends NetconfSession> {
      * Insert session negotiator into the pipeline. It must be inserted after message decoder
      * identified by {@link AbstractChannelInitializer#NETCONF_MESSAGE_DECODER}, (or any other custom decoder processor)
      */
-    protected abstract void initializeSessionNegotiator(SocketChannel ch, Promise<S> promise);
+    protected abstract void initializeSessionNegotiator(Channel ch, Promise<S> promise);
 
 }
index 622881352eef102119eed81a74f32ee0db2ed76a..cbd3efc57f7bc0abfd27e77bec63334087265fab 100644 (file)
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
         <configuration>
           <instructions>
             <Bundle-Activator>org.opendaylight.controller.netconf.ssh.osgi.NetconfSSHActivator</Bundle-Activator>
             <Import-Package>com.google.common.base,
-                            ch.ethz.ssh2,
-                            ch.ethz.ssh2.signature,
-                            org.apache.commons.io,
-                            org.opendaylight.controller.netconf.util.osgi,
-                            org.opendaylight.controller.usermanager,
-                            org.opendaylight.controller.sal.authorization,
-                            org.opendaylight.controller.sal.utils,
-                            org.osgi.framework,
-                            org.osgi.util.tracker,
-                            org.slf4j,
-                            org.bouncycastle.openssl</Import-Package>
+              ch.ethz.ssh2,
+              ch.ethz.ssh2.signature,
+              org.apache.commons.io,
+              org.opendaylight.controller.netconf.util.osgi,
+              org.opendaylight.controller.usermanager,
+              org.opendaylight.controller.sal.authorization,
+              org.opendaylight.controller.sal.utils,
+              org.osgi.framework,
+              org.osgi.util.tracker,
+              org.slf4j,
+              org.bouncycastle.openssl,
+              io.netty.bootstrap, io.netty.buffer, io.netty.channel, io.netty.channel.local, io.netty.channel.nio,
+              io.netty.handler.stream, io.netty.util.concurrent, org.apache.commons.lang3,
+              org.opendaylight.controller.netconf.util.messages</Import-Package>
           </instructions>
         </configuration>
       </plugin>
index c6974d4982db051f1cb6a66d3f67394ee2d57817..08bf9836b22135a295f2e54d68fa6c73ffeadf57 100644 (file)
@@ -7,79 +7,94 @@
  */
 package org.opendaylight.controller.netconf.ssh;
 
-import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
-import org.opendaylight.controller.netconf.ssh.threads.SocketThread;
-import org.opendaylight.controller.usermanager.IUserManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.concurrent.ThreadSafe;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicLong;
+import javax.annotation.concurrent.ThreadSafe;
+import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
+import org.opendaylight.controller.netconf.ssh.threads.Handshaker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+/**
+ * Thread that accepts client connections. Accepted socket is forwarded to {@link org.opendaylight.controller.netconf.ssh.threads.Handshaker},
+ * which is executed in {@link #handshakeExecutor}.
+ */
 @ThreadSafe
-public final class NetconfSSHServer implements Runnable {
+public final class NetconfSSHServer extends Thread implements AutoCloseable {
 
-    private ServerSocket ss = null;
-    private static final Logger logger =  LoggerFactory.getLogger(NetconfSSHServer.class);
-    private static final AtomicLong sesssionId = new AtomicLong();
-    private final InetSocketAddress clientAddress;
-    private final AuthProvider authProvider;
-    private volatile boolean up = false;
+    private static final Logger logger = LoggerFactory.getLogger(NetconfSSHServer.class);
+    private static final AtomicLong sessionIdCounter = new AtomicLong();
 
-    private NetconfSSHServer(int serverPort,InetSocketAddress clientAddress, AuthProvider authProvider) throws IllegalStateException, IOException {
+    private final ServerSocket serverSocket;
+    private final LocalAddress localAddress;
+    private final EventLoopGroup bossGroup;
+    private final AuthProvider authProvider;
+    private final ExecutorService handshakeExecutor;
+    private volatile boolean up;
 
-        logger.trace("Creating SSH server socket on port {}",serverPort);
-        this.ss = new ServerSocket(serverPort);
-        if (!ss.isBound()){
-            throw new IllegalStateException("Socket can't be bound to requested port :"+serverPort);
+    private NetconfSSHServer(int serverPort, LocalAddress localAddress, AuthProvider authProvider, EventLoopGroup bossGroup) throws IOException {
+        super(NetconfSSHServer.class.getSimpleName());
+        this.bossGroup = bossGroup;
+        logger.trace("Creating SSH server socket on port {}", serverPort);
+        this.serverSocket = new ServerSocket(serverPort);
+        if (serverSocket.isBound() == false) {
+            throw new IllegalStateException("Socket can't be bound to requested port :" + serverPort);
         }
         logger.trace("Server socket created.");
-        this.clientAddress = clientAddress;
+        this.localAddress = localAddress;
         this.authProvider = authProvider;
         this.up = true;
+        handshakeExecutor = Executors.newFixedThreadPool(10);
     }
 
-    public static NetconfSSHServer start(int serverPort, InetSocketAddress clientAddress,AuthProvider authProvider) throws IllegalStateException, IOException {
-        return new NetconfSSHServer(serverPort, clientAddress,authProvider);
+    public static NetconfSSHServer start(int serverPort, LocalAddress localAddress, AuthProvider authProvider, EventLoopGroup bossGroup) throws IOException {
+        NetconfSSHServer netconfSSHServer = new NetconfSSHServer(serverPort, localAddress, authProvider, bossGroup);
+        netconfSSHServer.start();
+        return netconfSSHServer;
     }
 
-    public void stop() throws IOException {
+    @Override
+    public void close() throws IOException {
         up = false;
         logger.trace("Closing SSH server socket.");
-        ss.close();
+        serverSocket.close();
+        bossGroup.shutdownGracefully();
         logger.trace("SSH server socket closed.");
     }
 
-    public void removeUserManagerService(){
-        this.authProvider.removeUserManagerService();
-    }
-
-    public void addUserManagerService(IUserManager userManagerService){
-        this.authProvider.addUserManagerService(userManagerService);
-    }
-    public boolean isUp(){
-        return this.up;
-    }
     @Override
     public void run() {
         while (up) {
-            logger.trace("Starting new socket thread.");
+            Socket acceptedSocket = null;
             try {
-                SocketThread.start(ss.accept(), clientAddress, sesssionId.incrementAndGet(), authProvider);
-            }
-            catch (IOException e) {
-                if( up ) {
-                    logger.error("Exception occurred during socket thread initialization", e);
+                acceptedSocket = serverSocket.accept();
+            } catch (IOException e) {
+                if (up == false) {
+                    logger.trace("Exiting server thread", e);
+                } else {
+                    logger.warn("Exception occurred during socket.accept", e);
                 }
-                else {
-                    // We're shutting down so an exception is expected as the socket's been closed.
-                    // Log to debug.
-                    logger.debug("Shutting down - got expected exception: " + e);
+            }
+            if (acceptedSocket != null) {
+                try {
+                    Handshaker task = new Handshaker(acceptedSocket, localAddress, sessionIdCounter.incrementAndGet(), authProvider, bossGroup);
+                    handshakeExecutor.submit(task);
+                } catch (IOException e) {
+                    logger.warn("Cannot set PEMHostKey, closing connection", e);
+                    try {
+                        acceptedSocket.close();
+                    } catch (IOException e1) {
+                        logger.warn("Ignoring exception while closing socket", e);
+                    }
                 }
             }
         }
+        logger.debug("Server thread is exiting");
     }
 }
index 2e9a0b9d8bbd256154ff82689e85e556b60c9e90..5d39dd1eb8adad115e030c0136cbae702d2bde65 100644 (file)
@@ -7,41 +7,75 @@
  */
 package org.opendaylight.controller.netconf.ssh.authentication;
 
-import java.io.IOException;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.annotations.VisibleForTesting;
 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
 import org.opendaylight.controller.usermanager.IUserManager;
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-public class AuthProvider implements AuthProviderInterface {
+public class AuthProvider {
+    private static final Logger logger = LoggerFactory.getLogger(AuthProvider.class);
 
-    private IUserManager um;
     private final String pem;
+    private IUserManager nullableUserManager;
 
-    public AuthProvider(IUserManager ium, String pemCertificate) throws IllegalArgumentException, IOException {
+    public AuthProvider(String pemCertificate, final BundleContext bundleContext) {
         checkNotNull(pemCertificate, "Parameter 'pemCertificate' is null");
-        checkNotNull(ium, "No user manager service available.");
-        this.um = ium;
         pem = pemCertificate;
+
+        ServiceTrackerCustomizer<IUserManager, IUserManager> customizer = new ServiceTrackerCustomizer<IUserManager, IUserManager>() {
+            @Override
+            public IUserManager addingService(final ServiceReference<IUserManager> reference) {
+                logger.trace("Service {} added", reference);
+                nullableUserManager = bundleContext.getService(reference);
+                return nullableUserManager;
+            }
+
+            @Override
+            public void modifiedService(final ServiceReference<IUserManager> reference, final IUserManager service) {
+                logger.trace("Replacing modified service {} in netconf SSH.", reference);
+                nullableUserManager = service;
+            }
+
+            @Override
+            public void removedService(final ServiceReference<IUserManager> reference, final IUserManager service) {
+                logger.trace("Removing service {} from netconf SSH. " +
+                        "SSH won't authenticate users until IUserManager service will be started.", reference);
+                synchronized (AuthProvider.this) {
+                    nullableUserManager = null;
+                }
+            }
+        };
+        ServiceTracker<IUserManager, IUserManager> listenerTracker = new ServiceTracker<>(bundleContext, IUserManager.class, customizer);
+        listenerTracker.open();
     }
 
-    @Override
-    public boolean authenticated(String username, String password) {
-        AuthResultEnum authResult = this.um.authenticate(username, password);
+    /**
+     * Authenticate user. This implementation tracks IUserManager and delegates the decision to it. If the service is not
+     * available, IllegalStateException is thrown.
+     */
+    public synchronized boolean authenticated(String username, String password) {
+        if (nullableUserManager == null) {
+            logger.warn("Cannot authenticate user '{}', user manager service is missing", username);
+            throw new IllegalStateException("User manager service is not available");
+        }
+        AuthResultEnum authResult = nullableUserManager.authenticate(username, password);
+        logger.debug("Authentication result for user '{}' : {}", username, authResult);
         return authResult.equals(AuthResultEnum.AUTH_ACCEPT) || authResult.equals(AuthResultEnum.AUTH_ACCEPT_LOC);
     }
 
-    @Override
     public char[] getPEMAsCharArray() {
         return pem.toCharArray();
     }
 
-    @Override
-    public void removeUserManagerService() {
-        this.um = null;
-    }
-
-    @Override
-    public void addUserManagerService(IUserManager userManagerService) {
-        this.um = userManagerService;
+    @VisibleForTesting
+    void setNullableUserManager(IUserManager nullableUserManager) {
+        this.nullableUserManager = nullableUserManager;
     }
 }
diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProviderInterface.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProviderInterface.java
deleted file mode 100644 (file)
index fad0f79..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.netconf.ssh.authentication;
-
-import org.opendaylight.controller.usermanager.IUserManager;
-
-public interface AuthProviderInterface {
-
-    public boolean authenticated(String username, String password) throws IllegalStateException;
-    public char[] getPEMAsCharArray() throws Exception;
-    public void removeUserManagerService();
-    public void addUserManagerService(IUserManager userManagerService);
-}
index 348fe006f3a7d4cfefcb8c502a9115da422a0a61..53ab8219ee9c2a9f98e144f8c125f45b86edb002 100644 (file)
@@ -8,8 +8,11 @@
 
 package org.opendaylight.controller.netconf.ssh.authentication;
 
+import com.google.common.annotations.VisibleForTesting;
+import java.io.FileInputStream;
 import java.security.NoSuchAlgorithmException;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.bouncycastle.openssl.PEMWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,17 +29,55 @@ public class PEMGenerator {
     private static final Logger logger = LoggerFactory.getLogger(PEMGenerator.class);
     private static final int KEY_SIZE = 4096;
 
+
+    public static String readOrGeneratePK(File privateKeyFile) throws IOException {
+        if (privateKeyFile.exists() == false) {
+            // generate & save to file
+            try {
+                return generateTo(privateKeyFile);
+            } catch (Exception e) {
+                logger.error("Exception occurred while generating PEM string to {}", privateKeyFile, e);
+                throw new IllegalStateException("Error generating RSA key from file " + privateKeyFile);
+            }
+        } else {
+            // read from file
+            try (FileInputStream fis = new FileInputStream(privateKeyFile)) {
+                return IOUtils.toString(fis);
+            } catch (final IOException e) {
+                logger.error("Error reading RSA key from file {}", privateKeyFile, e);
+                throw new IOException("Error reading RSA key from file " + privateKeyFile, e);
+            }
+        }
+    }
+
+    /**
+     * Generate private key to a file and return its content as string.
+     *
+     * @param privateFile path where private key should be generated
+     * @return String representation of private key
+     * @throws IOException
+     * @throws NoSuchAlgorithmException
+     */
+    @VisibleForTesting
     public static String generateTo(File privateFile) throws IOException, NoSuchAlgorithmException {
+        logger.info("Generating private key to {}", privateFile.getAbsolutePath());
+        String privatePEM = generate();
+        FileUtils.write(privateFile, privatePEM);
+        return privatePEM;
+    }
+
+    @VisibleForTesting
+    public static String generate() throws NoSuchAlgorithmException, IOException {
         KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
         SecureRandom sr = new SecureRandom();
         keyGen.initialize(KEY_SIZE, sr);
         KeyPair keypair = keyGen.generateKeyPair();
-        logger.info("Generating private key to {}", privateFile.getAbsolutePath());
-        String privatePEM = toString(keypair.getPrivate());
-        FileUtils.write(privateFile, privatePEM);
-        return privatePEM;
+        return toString(keypair.getPrivate());
     }
 
+    /**
+     * Get string representation of a key.
+     */
     private static String toString(Key key) throws IOException {
         try (StringWriter writer = new StringWriter()) {
             try (PEMWriter pemWriter = new PEMWriter(writer)) {
@@ -45,4 +86,5 @@ public class PEMGenerator {
             return writer.toString();
         }
     }
+
 }
index d74308cfadbae8e658e58f9b189d93baaea83c2e..a26843fae17a97621b48221a932eb9b823a6ce83 100644 (file)
@@ -7,24 +7,24 @@
  */
 package org.opendaylight.controller.netconf.ssh.osgi;
 
-import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
 
+import com.google.common.base.Optional;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.nio.NioEventLoopGroup;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
 import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
 import org.opendaylight.controller.netconf.ssh.authentication.PEMGenerator;
 import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
-import org.opendaylight.controller.usermanager.IUserManager;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.InfixProp;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,112 +32,56 @@ import org.slf4j.LoggerFactory;
  * Activator for netconf SSH bundle which creates SSH bridge between netconf client and netconf server. Activator
  * starts SSH Server in its own thread. This thread is closed when activator calls stop() method. Server opens socket
  * and listens for client connections. Each client connection creation is handled in separate
- * {@link org.opendaylight.controller.netconf.ssh.threads.SocketThread} thread.
+ * {@link org.opendaylight.controller.netconf.ssh.threads.Handshaker} thread.
  * This thread creates two additional threads {@link org.opendaylight.controller.netconf.ssh.threads.IOThread}
  * forwarding data from/to client.IOThread closes servers session and server connection when it gets -1 on input stream.
  * {@link org.opendaylight.controller.netconf.ssh.threads.IOThread}'s run method waits for -1 on input stream to finish.
  * All threads are daemons.
- **/
-public class NetconfSSHActivator implements BundleActivator{
+ */
+public class NetconfSSHActivator implements BundleActivator {
+    private static final Logger logger = LoggerFactory.getLogger(NetconfSSHActivator.class);
 
     private NetconfSSHServer server;
-    private static final Logger logger =  LoggerFactory.getLogger(NetconfSSHActivator.class);
-    private IUserManager iUserManager;
-    private BundleContext context = null;
-
-    private ServiceTrackerCustomizer<IUserManager, IUserManager> customizer = new ServiceTrackerCustomizer<IUserManager, IUserManager>(){
-        @Override
-        public IUserManager addingService(final ServiceReference<IUserManager> reference) {
-            logger.trace("Service {} added, let there be SSH bridge.", reference);
-            iUserManager =  context.getService(reference);
-            try {
-                onUserManagerFound(iUserManager);
-            } catch (final Exception e) {
-                logger.trace("Can't start SSH server due to {}",e);
-            }
-            return iUserManager;
-        }
-        @Override
-        public void modifiedService(final ServiceReference<IUserManager> reference, final IUserManager service) {
-            logger.trace("Replacing modified service {} in netconf SSH.", reference);
-            server.addUserManagerService(service);
-        }
-        @Override
-        public void removedService(final ServiceReference<IUserManager> reference, final IUserManager service) {
-            logger.trace("Removing service {} from netconf SSH. " +
-                    "SSH won't authenticate users until IUserManager service will be started.", reference);
-            removeUserManagerService();
-        }
-    };
-
 
     @Override
-    public void start(final BundleContext context) {
-        this.context = context;
-        listenForManagerService();
+    public void start(final BundleContext bundleContext) throws IOException {
+        server = startSSHServer(bundleContext);
     }
 
     @Override
     public void stop(BundleContext context) throws IOException {
-        if (server != null){
-            server.stop();
-            logger.trace("Netconf SSH bridge is down ...");
+        if (server != null) {
+            server.close();
         }
     }
-    private void startSSHServer() throws IOException {
-        checkNotNull(this.iUserManager, "No user manager service available.");
-        logger.trace("Starting netconf SSH  bridge.");
-        final InetSocketAddress sshSocketAddress = NetconfConfigUtil.extractSSHNetconfAddress(context,
-                NetconfConfigUtil.DEFAULT_NETCONF_SSH_ADDRESS);
-        final InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfClientAddress(context,
-               NetconfConfigUtil.DEFAULT_NETCONF_TCP_ADDRESS);
 
-        String path =  FilenameUtils.separatorsToSystem(NetconfConfigUtil.getPrivateKeyPath(context));
+    private static NetconfSSHServer startSSHServer(BundleContext bundleContext) throws IOException {
+        Optional<InetSocketAddress> maybeSshSocketAddress = NetconfConfigUtil.extractNetconfServerAddress(bundleContext,
+                InfixProp.ssh);
 
-        if (path.isEmpty()) {
-            throw new IllegalStateException("Missing netconf.ssh.pk.path key in configuration file.");
+        if (maybeSshSocketAddress.isPresent() == false) {
+            logger.trace("SSH bridge not configured");
+            return null;
         }
+        InetSocketAddress sshSocketAddress = maybeSshSocketAddress.get();
+        logger.trace("Starting netconf SSH  bridge at {}", sshSocketAddress);
 
-        final File privateKeyFile = new File(path);
-        final String privateKeyPEMString;
-        if (privateKeyFile.exists() == false) {
-            // generate & save to file
-            try {
-                privateKeyPEMString = PEMGenerator.generateTo(privateKeyFile);
-            } catch (Exception e) {
-                logger.error("Exception occurred while generating PEM string {}", e);
-                throw new IllegalStateException("Error generating RSA key from file " + path);
-            }
-        } else {
-            // read from file
-            try (FileInputStream fis = new FileInputStream(path)) {
-                privateKeyPEMString = IOUtils.toString(fis);
-            } catch (final IOException e) {
-                logger.error("Error reading RSA key from file '{}'", path);
-                throw new IOException("Error reading RSA key from file " + path, e);
-            }
-        }
-        final AuthProvider authProvider = new AuthProvider(iUserManager, privateKeyPEMString);
-        this.server = NetconfSSHServer.start(sshSocketAddress.getPort(), tcpSocketAddress, authProvider);
+        LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();
+
+        String path = FilenameUtils.separatorsToSystem(NetconfConfigUtil.getPrivateKeyPath(bundleContext));
+        checkState(StringUtils.isNotBlank(path), "Path to ssh private key is blank. Reconfigure %s", NetconfConfigUtil.getPrivateKeyKey());
+        String privateKeyPEMString = PEMGenerator.readOrGeneratePK(new File(path));
+
+        final AuthProvider authProvider = new AuthProvider(privateKeyPEMString, bundleContext);
+        EventLoopGroup bossGroup  = new NioEventLoopGroup();
+        NetconfSSHServer server = NetconfSSHServer.start(sshSocketAddress.getPort(), localAddress, authProvider, bossGroup);
 
         final Thread serverThread = new Thread(server, "netconf SSH server thread");
         serverThread.setDaemon(true);
         serverThread.start();
         logger.trace("Netconf SSH  bridge up and running.");
+        return server;
     }
 
-    private void onUserManagerFound(final IUserManager userManager) throws Exception{
-        if (server!=null && server.isUp()){
-           server.addUserManagerService(userManager);
-        } else {
-           startSSHServer();
-        }
-    }
-    private void removeUserManagerService(){
-        this.server.removeUserManagerService();
-    }
-    private void listenForManagerService(){
-        final ServiceTracker<IUserManager, IUserManager> listenerTracker = new ServiceTracker<>(context, IUserManager.class,customizer);
-        listenerTracker.open();
-    }
+
 }
diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/Handshaker.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/Handshaker.java
new file mode 100644 (file)
index 0000000..d999d37
--- /dev/null
@@ -0,0 +1,406 @@
+/*
+ * 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.ssh.threads;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+
+import ch.ethz.ssh2.AuthenticationResult;
+import ch.ethz.ssh2.PtySettings;
+import ch.ethz.ssh2.ServerAuthenticationCallback;
+import ch.ethz.ssh2.ServerConnection;
+import ch.ethz.ssh2.ServerConnectionCallback;
+import ch.ethz.ssh2.ServerSession;
+import ch.ethz.ssh2.ServerSessionCallback;
+import ch.ethz.ssh2.SimpleServerSessionCallback;
+import com.google.common.base.Supplier;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufProcessor;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.local.LocalChannel;
+import io.netty.handler.stream.ChunkedStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import javax.annotation.concurrent.NotThreadSafe;
+import javax.annotation.concurrent.ThreadSafe;
+import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
+import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * One instance represents per connection, responsible for ssh handshake.
+ * Once auth succeeds and correct subsystem is chosen, backend connection with
+ * netty netconf server is made. This task finishes right after negotiation is done.
+ */
+@ThreadSafe
+public class Handshaker implements Runnable {
+    private static final Logger logger = LoggerFactory.getLogger(Handshaker.class);
+
+    private final ServerConnection ganymedConnection;
+    private final String session;
+
+
+    public Handshaker(Socket socket, LocalAddress localAddress, long sessionId, AuthProvider authProvider,
+                      EventLoopGroup bossGroup) throws IOException {
+
+        this.session = "Session " + sessionId;
+
+        String remoteAddressWithPort = socket.getRemoteSocketAddress().toString().replace("/", "");
+        logger.debug("{} started with {}", session, remoteAddressWithPort);
+        String remoteAddress, remotePort;
+        if (remoteAddressWithPort.contains(":")) {
+            String[] split = remoteAddressWithPort.split(":");
+            remoteAddress = split[0];
+            remotePort = split[1];
+        } else {
+            remoteAddress = remoteAddressWithPort;
+            remotePort = "";
+        }
+        ServerAuthenticationCallbackImpl serverAuthenticationCallback = new ServerAuthenticationCallbackImpl(
+                authProvider, session);
+
+        ganymedConnection = new ServerConnection(socket);
+
+        ServerConnectionCallbackImpl serverConnectionCallback = new ServerConnectionCallbackImpl(
+                serverAuthenticationCallback, remoteAddress, remotePort, session,
+                getGanymedAutoCloseable(ganymedConnection), localAddress, bossGroup);
+
+        // initialize ganymed
+        ganymedConnection.setPEMHostKey(authProvider.getPEMAsCharArray(), null);
+        ganymedConnection.setAuthenticationCallback(serverAuthenticationCallback);
+        ganymedConnection.setServerConnectionCallback(serverConnectionCallback);
+    }
+
+
+    private static AutoCloseable getGanymedAutoCloseable(final ServerConnection ganymedConnection) {
+        return new AutoCloseable() {
+            @Override
+            public void close() throws Exception {
+                ganymedConnection.close();
+            }
+        };
+    }
+
+    @Override
+    public void run() {
+        // let ganymed process handshake
+        logger.trace("{} SocketThread is started", session);
+        try {
+            // TODO this should be guarded with a timer to prevent resource exhaustion
+            ganymedConnection.connect();
+        } catch (IOException e) {
+            logger.warn("{} SocketThread error ", session, e);
+        }
+        logger.trace("{} SocketThread is exiting", session);
+    }
+}
+
+/**
+ * Netty client handler that forwards bytes from backed server to supplied output stream.
+ * When backend server closes the connection, remoteConnection.close() is called to tear
+ * down ssh connection.
+ */
+class SSHClientHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger logger = LoggerFactory.getLogger(SSHClientHandler.class);
+    private final AutoCloseable remoteConnection;
+    private final OutputStream remoteOutputStream;
+    private final String session;
+    private ChannelHandlerContext channelHandlerContext;
+
+    public SSHClientHandler(AutoCloseable remoteConnection, OutputStream remoteOutputStream,
+                            String session) {
+        this.remoteConnection = remoteConnection;
+        this.remoteOutputStream = remoteOutputStream;
+        this.session = session;
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) {
+        this.channelHandlerContext = ctx;
+        logger.debug("{} Client active", session);
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+        ByteBuf bb = (ByteBuf) msg;
+        // we can block the server here so that slow client does not cause memory pressure
+        try {
+            bb.forEachByte(new ByteBufProcessor() {
+                @Override
+                public boolean process(byte value) throws Exception {
+                    remoteOutputStream.write(value);
+                    return true;
+                }
+            });
+        } finally {
+            bb.release();
+        }
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) throws IOException {
+        logger.trace("{} Flushing", session);
+        remoteOutputStream.flush();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        logger.warn("{} Unexpected exception from downstream", session, cause);
+        ctx.close();
+    }
+
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
+        logger.trace("{} channelInactive() called, closing remote client ctx", session);
+        remoteConnection.close();//this should close socket and all threads created for this client
+        this.channelHandlerContext = null;
+    }
+
+    public ChannelHandlerContext getChannelHandlerContext() {
+        return checkNotNull(channelHandlerContext, "Channel is not active");
+    }
+}
+
+/**
+ * Ganymed handler that gets unencrypted input and output streams, connects them to netty.
+ * Checks that 'netconf' subsystem is chosen by user.
+ * Launches new ClientInputStreamPoolingThread thread once session is established.
+ * Writes custom header to netty server, to inform it about IP address and username.
+ */
+class ServerConnectionCallbackImpl implements ServerConnectionCallback {
+    private static final Logger logger = LoggerFactory.getLogger(ServerConnectionCallbackImpl.class);
+    public static final String NETCONF_SUBSYSTEM = "netconf";
+
+    private final Supplier<String> currentUserSupplier;
+    private final String remoteAddress;
+    private final String remotePort;
+    private final String session;
+    private final AutoCloseable ganymedConnection;
+    private final LocalAddress localAddress;
+    private final EventLoopGroup bossGroup;
+
+    ServerConnectionCallbackImpl(Supplier<String> currentUserSupplier, String remoteAddress, String remotePort, String session,
+                                 AutoCloseable ganymedConnection, LocalAddress localAddress, EventLoopGroup bossGroup) {
+        this.currentUserSupplier = currentUserSupplier;
+        this.remoteAddress = remoteAddress;
+        this.remotePort = remotePort;
+        this.session = session;
+        this.ganymedConnection = ganymedConnection;
+        // initialize netty local connection
+        this.localAddress = localAddress;
+        this.bossGroup = bossGroup;
+    }
+
+    private static ChannelFuture initializeNettyConnection(LocalAddress localAddress, EventLoopGroup bossGroup,
+                                                           final SSHClientHandler sshClientHandler) {
+        Bootstrap clientBootstrap = new Bootstrap();
+        clientBootstrap.group(bossGroup).channel(LocalChannel.class);
+
+        clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
+            @Override
+            public void initChannel(LocalChannel ch) throws Exception {
+                ch.pipeline().addLast(sshClientHandler);
+            }
+        });
+        // asynchronously initialize local connection to netconf server
+        return clientBootstrap.connect(localAddress);
+    }
+
+    @Override
+    public ServerSessionCallback acceptSession(final ServerSession serverSession) {
+        String currentUser = currentUserSupplier.get();
+        final String additionalHeader = new NetconfHelloMessageAdditionalHeader(currentUser, remoteAddress,
+                remotePort, "ssh", "client").toFormattedString();
+
+
+        return new SimpleServerSessionCallback() {
+            @Override
+            public Runnable requestSubsystem(final ServerSession ss, final String subsystem) throws IOException {
+                return new Runnable() {
+                    @Override
+                    public void run() {
+                        if (NETCONF_SUBSYSTEM.equals(subsystem)) {
+                            // connect
+                            final SSHClientHandler sshClientHandler = new SSHClientHandler(ganymedConnection, ss.getStdin(), session);
+                            ChannelFuture clientChannelFuture = initializeNettyConnection(localAddress, bossGroup, sshClientHandler);
+                            // get channel
+                            final Channel channel = clientChannelFuture.awaitUninterruptibly().channel();
+                            new ClientInputStreamPoolingThread(session, ss.getStdout(), channel, new AutoCloseable() {
+                                @Override
+                                public void close() throws Exception {
+                                    logger.trace("Closing both ganymed and local connection");
+                                    try {
+                                        ganymedConnection.close();
+                                    } catch (Exception e) {
+                                        logger.warn("Ignoring exception while closing ganymed", e);
+                                    }
+                                    try {
+                                        channel.close();
+                                    } catch (Exception e) {
+                                        logger.warn("Ignoring exception while closing channel", e);
+                                    }
+                                }
+                            }, sshClientHandler.getChannelHandlerContext()).start();
+
+                            // write additional header
+                            channel.writeAndFlush(Unpooled.copiedBuffer(additionalHeader.getBytes()));
+                        } else {
+                            logger.debug("{} Wrong subsystem requested:'{}', closing ssh session", serverSession, subsystem);
+                            String reason = "Only netconf subsystem is supported, requested:" + subsystem;
+                            closeSession(ss, reason);
+                        }
+                    }
+                };
+            }
+
+            public void closeSession(ServerSession ss, String reason) {
+                logger.trace("{} Closing session - {}", serverSession, reason);
+                try {
+                    ss.getStdin().write(reason.getBytes());
+                } catch (IOException e) {
+                    logger.warn("{} Exception while closing session", serverSession, e);
+                }
+                ss.close();
+            }
+
+            @Override
+            public Runnable requestPtyReq(final ServerSession ss, final PtySettings pty) throws IOException {
+                return new Runnable() {
+                    @Override
+                    public void run() {
+                        closeSession(ss, "PTY request not supported");
+                    }
+                };
+            }
+
+            @Override
+            public Runnable requestShell(final ServerSession ss) throws IOException {
+                return new Runnable() {
+                    @Override
+                    public void run() {
+                        closeSession(ss, "Shell not supported");
+                    }
+                };
+            }
+        };
+    }
+}
+
+/**
+ * Only thread that is required during ssh session, forwards client's input to netty.
+ * When user closes connection, onEndOfInput.close() is called to tear down the local channel.
+ */
+class ClientInputStreamPoolingThread extends Thread {
+    private static final Logger logger = LoggerFactory.getLogger(ClientInputStreamPoolingThread.class);
+
+    private final InputStream fromClientIS;
+    private final Channel serverChannel;
+    private final AutoCloseable onEndOfInput;
+    private final ChannelHandlerContext channelHandlerContext;
+
+    ClientInputStreamPoolingThread(String session, InputStream fromClientIS, Channel serverChannel, AutoCloseable onEndOfInput,
+                                   ChannelHandlerContext channelHandlerContext) {
+        super(ClientInputStreamPoolingThread.class.getSimpleName() + " " + session);
+        this.fromClientIS = fromClientIS;
+        this.serverChannel = serverChannel;
+        this.onEndOfInput = onEndOfInput;
+        this.channelHandlerContext = channelHandlerContext;
+    }
+
+    @Override
+    public void run() {
+        ChunkedStream chunkedStream = new ChunkedStream(fromClientIS);
+        try {
+            ByteBuf byteBuf;
+            while ((byteBuf = chunkedStream.readChunk(channelHandlerContext/*only needed for ByteBuf alloc */)) != null) {
+                serverChannel.writeAndFlush(byteBuf);
+            }
+        } catch (Exception e) {
+            logger.warn("Exception", e);
+        } finally {
+            logger.trace("End of input");
+            // tear down connection
+            try {
+                onEndOfInput.close();
+            } catch (Exception e) {
+                logger.warn("Ignoring exception while closing socket", e);
+            }
+        }
+    }
+}
+
+/**
+ * Authentication handler for ganymed.
+ * Provides current user name after authenticating using supplied AuthProvider.
+ */
+@NotThreadSafe
+class ServerAuthenticationCallbackImpl implements ServerAuthenticationCallback, Supplier<String> {
+    private static final Logger logger = LoggerFactory.getLogger(ServerAuthenticationCallbackImpl.class);
+    private final AuthProvider authProvider;
+    private final String session;
+    private String currentUser;
+
+    ServerAuthenticationCallbackImpl(AuthProvider authProvider, String session) {
+        this.authProvider = authProvider;
+        this.session = session;
+    }
+
+    @Override
+    public String initAuthentication(ServerConnection sc) {
+        logger.trace("{} Established connection", session);
+        return "Established connection" + "\r\n";
+    }
+
+    @Override
+    public String[] getRemainingAuthMethods(ServerConnection sc) {
+        return new String[]{ServerAuthenticationCallback.METHOD_PASSWORD};
+    }
+
+    @Override
+    public AuthenticationResult authenticateWithNone(ServerConnection sc, String username) {
+        return AuthenticationResult.FAILURE;
+    }
+
+    @Override
+    public AuthenticationResult authenticateWithPassword(ServerConnection sc, String username, String password) {
+        checkState(currentUser == null);
+        try {
+            if (authProvider.authenticated(username, password)) {
+                currentUser = username;
+                logger.trace("{} user {} authenticated", session, currentUser);
+                return AuthenticationResult.SUCCESS;
+            }
+        } catch (Exception e) {
+            logger.warn("{} Authentication failed", session, e);
+        }
+        return AuthenticationResult.FAILURE;
+    }
+
+    @Override
+    public AuthenticationResult authenticateWithPublicKey(ServerConnection sc, String username, String algorithm,
+                                                          byte[] publicKey, byte[] signature) {
+        return AuthenticationResult.FAILURE;
+    }
+
+    @Override
+    public String get() {
+        return currentUser;
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/IOThread.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/IOThread.java
deleted file mode 100644 (file)
index c53a625..0000000
+++ /dev/null
@@ -1,70 +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.ssh.threads;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-import org.apache.commons.io.IOUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import ch.ethz.ssh2.ServerConnection;
-import ch.ethz.ssh2.ServerSession;
-
-@ThreadSafe
-public class IOThread extends Thread {
-
-    private static final Logger logger =  LoggerFactory.getLogger(IOThread.class);
-
-    private final InputStream inputStream;
-    private final OutputStream outputStream;
-    private final ServerSession servSession;
-    private final ServerConnection servconnection;
-    private String customHeader;
-
-
-    public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn){
-        this.inputStream = is;
-        this.outputStream = os;
-        this.servSession = ss;
-        this.servconnection = conn;
-        super.setName(id);
-        logger.trace("IOThread {} created", super.getName());
-    }
-
-    public IOThread (InputStream is, OutputStream os, String id,ServerSession ss, ServerConnection conn,String header){
-        this.inputStream = is;
-        this.outputStream = os;
-        this.servSession = ss;
-        this.servconnection = conn;
-        this.customHeader = header;
-        super.setName(id);
-        logger.trace("IOThread {} created", super.getName());
-    }
-
-    @Override
-    public void run() {
-        logger.trace("thread {} started", super.getName());
-        try {
-            if (this.customHeader!=null && !this.customHeader.equals("")){
-                this.outputStream.write(this.customHeader.getBytes());
-                logger.trace("adding {} header", this.customHeader);
-            }
-            IOUtils.copy(this.inputStream, this.outputStream);
-        } catch (Exception e) {
-            logger.error("inputstream -> outputstream copy error ",e);
-        }
-        logger.trace("closing server session");
-        servSession.close();
-        servconnection.close();
-        logger.trace("thread {} is closing",super.getName());
-    }
-}
diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/threads/SocketThread.java
deleted file mode 100644 (file)
index 04639cb..0000000
+++ /dev/null
@@ -1,208 +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.ssh.threads;
-
-
-import ch.ethz.ssh2.AuthenticationResult;
-import ch.ethz.ssh2.PtySettings;
-import ch.ethz.ssh2.ServerAuthenticationCallback;
-import ch.ethz.ssh2.ServerConnection;
-import ch.ethz.ssh2.ServerConnectionCallback;
-import ch.ethz.ssh2.ServerSession;
-import ch.ethz.ssh2.ServerSessionCallback;
-import ch.ethz.ssh2.SimpleServerSessionCallback;
-import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.concurrent.ThreadSafe;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-
-@ThreadSafe
-public class SocketThread implements Runnable, ServerAuthenticationCallback, ServerConnectionCallback {
-    private static final Logger logger = LoggerFactory.getLogger(SocketThread.class);
-
-    private final Socket socket;
-    private final InetSocketAddress clientAddress;
-    private ServerConnection conn = null;
-    private final long sessionId;
-    private String currentUser;
-    private final String remoteAddressWithPort;
-    private final AuthProvider authProvider;
-
-
-    public static void start(Socket socket,
-                             InetSocketAddress clientAddress,
-                             long sessionId,
-                             AuthProvider authProvider) throws IOException {
-        Thread netconf_ssh_socket_thread = new Thread(new SocketThread(socket, clientAddress, sessionId, authProvider));
-        netconf_ssh_socket_thread.setDaemon(true);
-        netconf_ssh_socket_thread.start();
-    }
-
-    private SocketThread(Socket socket,
-                         InetSocketAddress clientAddress,
-                         long sessionId,
-                         AuthProvider authProvider) throws IOException {
-
-        this.socket = socket;
-        this.clientAddress = clientAddress;
-        this.sessionId = sessionId;
-        this.remoteAddressWithPort = socket.getRemoteSocketAddress().toString().replaceFirst("/", "");
-        this.authProvider = authProvider;
-
-    }
-
-    @Override
-    public void run() {
-        conn = new ServerConnection(socket);
-        try {
-            conn.setPEMHostKey(authProvider.getPEMAsCharArray(), "netconf");
-        } catch (Exception e) {
-            logger.warn("Server authentication setup failed.", e);
-        }
-        conn.setAuthenticationCallback(this);
-        conn.setServerConnectionCallback(this);
-        try {
-            conn.connect();
-        } catch (IOException e) {
-            logger.error("SocketThread error ", e);
-        }
-    }
-
-    @Override
-    public ServerSessionCallback acceptSession(final ServerSession session) {
-        SimpleServerSessionCallback cb = new SimpleServerSessionCallback() {
-            @Override
-            public Runnable requestSubsystem(final ServerSession ss, final String subsystem) throws IOException {
-                return new Runnable() {
-                    @Override
-                    public void run() {
-                        if (subsystem.equals("netconf")) {
-                            IOThread netconf_ssh_input = null;
-                            IOThread netconf_ssh_output = null;
-                            try {
-                                String hostName = clientAddress.getHostName();
-                                int portNumber = clientAddress.getPort();
-                                final Socket echoSocket = new Socket(hostName, portNumber);
-                                logger.trace("echo socket created");
-
-                                logger.trace("starting netconf_ssh_input thread");
-                                netconf_ssh_input = new IOThread(echoSocket.getInputStream(), ss.getStdin(), "input_thread_" + sessionId, ss, conn);
-                                netconf_ssh_input.setDaemon(false);
-                                netconf_ssh_input.start();
-
-                                logger.trace("starting netconf_ssh_output thread");
-                                final String customHeader = "[" + currentUser + ";" + remoteAddressWithPort + ";ssh;;;;;;]\n";
-                                netconf_ssh_output = new IOThread(ss.getStdout(), echoSocket.getOutputStream(), "output_thread_" + sessionId, ss, conn, customHeader);
-                                netconf_ssh_output.setDaemon(false);
-                                netconf_ssh_output.start();
-
-                            } catch (Exception t) {
-                                logger.error("SSH bridge could not create echo socket: {}", t.getMessage(), t);
-
-                                try {
-                                    if (netconf_ssh_input != null) {
-                                        netconf_ssh_input.join();
-                                    }
-                                } catch (InterruptedException e1) {
-                                    Thread.currentThread().interrupt();
-                                    logger.error("netconf_ssh_input join error ", e1);
-                                }
-
-                                try {
-                                    if (netconf_ssh_output != null) {
-                                        netconf_ssh_output.join();
-                                    }
-                                } catch (InterruptedException e2) {
-                                    Thread.currentThread().interrupt();
-                                    logger.error("netconf_ssh_output join error ", e2);
-                                }
-                            }
-                        } else {
-                            String reason = "Only netconf subsystem is supported, requested:" + subsystem;
-                            closeSession(ss, reason);
-                        }
-                    }
-                };
-            }
-
-            public void closeSession(ServerSession ss, String reason) {
-                logger.trace("Closing session - {}", reason);
-                try {
-                    ss.getStdin().write(reason.getBytes());
-                } catch (IOException e) {
-                    logger.debug("Exception while closing session", e);
-                }
-                ss.close();
-            }
-
-            @Override
-            public Runnable requestPtyReq(final ServerSession ss, final PtySettings pty) throws IOException {
-                return new Runnable() {
-                    @Override
-                    public void run() {
-                        closeSession(ss, "PTY request not supported");
-                    }
-                };
-            }
-
-            @Override
-            public Runnable requestShell(final ServerSession ss) throws IOException {
-                return new Runnable() {
-                    @Override
-                    public void run() {
-                        closeSession(ss, "Shell not supported");
-                    }
-                };
-            }
-        };
-
-        return cb;
-    }
-
-    @Override
-    public String initAuthentication(ServerConnection sc) {
-        logger.trace("Established connection with host {}", remoteAddressWithPort);
-        return "Established connection with host " + remoteAddressWithPort + "\r\n";
-    }
-
-    @Override
-    public String[] getRemainingAuthMethods(ServerConnection sc) {
-        return new String[]{ServerAuthenticationCallback.METHOD_PASSWORD};
-    }
-
-    @Override
-    public AuthenticationResult authenticateWithNone(ServerConnection sc, String username) {
-        return AuthenticationResult.FAILURE;
-    }
-
-    @Override
-    public AuthenticationResult authenticateWithPassword(ServerConnection sc, String username, String password) {
-
-        try {
-            if (authProvider.authenticated(username, password)) {
-                currentUser = username;
-                logger.trace("user {}@{} authenticated", currentUser, remoteAddressWithPort);
-                return AuthenticationResult.SUCCESS;
-            }
-        } catch (Exception e) {
-            logger.warn("Authentication failed due to :" + e.getLocalizedMessage());
-        }
-        return AuthenticationResult.FAILURE;
-    }
-
-    @Override
-    public AuthenticationResult authenticateWithPublicKey(ServerConnection sc, String username, String algorithm,
-                                                          byte[] publickey, byte[] signature) {
-        return AuthenticationResult.FAILURE;
-    }
-
-}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/KeyGeneratorTest.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/KeyGeneratorTest.java
deleted file mode 100644 (file)
index 298f91c..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.netconf;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
-import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
-import org.opendaylight.controller.netconf.ssh.authentication.PEMGenerator;
-import org.opendaylight.controller.usermanager.IUserManager;
-import org.opendaylight.controller.usermanager.UserConfig;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.Inet4Address;
-import java.net.InetSocketAddress;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doReturn;
-
-// This test is intended to be verified using ssh
-@Ignore
-public class KeyGeneratorTest {
-
-    @Mock
-    private IUserManager iUserManager;
-    File tempFile;
-
-    @Before
-    public void setUp() throws IOException {
-        MockitoAnnotations.initMocks(this);
-        doReturn(null).when(iUserManager).addLocalUser(any(UserConfig.class));
-        tempFile = File.createTempFile("odltest", ".tmp");
-        tempFile.deleteOnExit();
-    }
-
-    @After
-    public void tearDown() {
-        assertTrue(tempFile.delete());
-    }
-
-    @Test
-    public void test() throws Exception {
-        String pem = PEMGenerator.generateTo(tempFile);
-
-        AuthProvider authProvider = new AuthProvider(iUserManager, pem);
-        InetSocketAddress inetSocketAddress = new InetSocketAddress(Inet4Address.getLoopbackAddress().getHostAddress(), 8383);
-        NetconfSSHServer server = NetconfSSHServer.start(1830, inetSocketAddress, authProvider);
-
-        Thread serverThread = new  Thread(server,"netconf SSH server thread");
-        serverThread.start();
-        serverThread.join();
-    }
-}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/SSHServerTest.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/SSHServerTest.java
deleted file mode 100644 (file)
index 663a0b4..0000000
+++ /dev/null
@@ -1,68 +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;
-
-import ch.ethz.ssh2.Connection;
-import junit.framework.Assert;
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
-import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.InputStream;
-import java.net.InetSocketAddress;
-
-
-public class SSHServerTest {
-
-    private static final String USER = "netconf";
-    private static final String PASSWORD  = "netconf";
-    private static final String HOST = "127.0.0.1";
-    private static final int PORT = 1830;
-    private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 8383);
-    private static final Logger logger =  LoggerFactory.getLogger(SSHServerTest.class);
-    private Thread sshServerThread;
-
-
-
-
-    public void startSSHServer() throws Exception{
-        logger.info("Creating SSH server");
-        StubUserManager um = new StubUserManager(USER,PASSWORD);
-        String pem;
-        try(InputStream is = getClass().getResourceAsStream("/RSA.pk")) {
-            pem = IOUtils.toString(is);
-        }
-        AuthProvider ap = new AuthProvider(um, pem);
-        NetconfSSHServer server = NetconfSSHServer.start(PORT,tcpAddress,ap);
-        sshServerThread = new Thread(server);
-        sshServerThread.setDaemon(true);
-        sshServerThread.start();
-        logger.info("SSH server on");
-    }
-
-    @Test
-    public void connect(){
-        try {
-            this.startSSHServer();
-            Connection conn = new Connection(HOST,PORT);
-            Assert.assertNotNull(conn);
-            logger.info("connecting to SSH server");
-            conn.connect();
-            logger.info("authenticating ...");
-            boolean isAuthenticated = conn.authenticateWithPassword(USER,PASSWORD);
-            Assert.assertTrue(isAuthenticated);
-        } catch (Exception e) {
-            logger.error("Error while starting SSH server.", e);
-        }
-
-    }
-
-}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClient.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClient.java
new file mode 100644 (file)
index 0000000..5d0c71a
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.netconf.netty;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.local.LocalChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Sends one message when a connection is open and echoes back any received
+ * data to the server.  Simply put, the echo client initiates the ping-pong
+ * traffic between the echo client and server by sending the first message to
+ * the server.
+ */
+public class EchoClient implements Runnable {
+    private static final Logger logger = LoggerFactory.getLogger(EchoClient.class);
+
+    private final ChannelHandler clientHandler;
+
+
+    public EchoClient(ChannelHandler clientHandler) {
+        this.clientHandler = clientHandler;
+    }
+
+    public void run() {
+        // Configure the client.
+        EventLoopGroup group = new NioEventLoopGroup();
+        try {
+            Bootstrap b = new Bootstrap();
+            b.group(group)
+                    .channel(LocalChannel.class)
+                    .handler(new ChannelInitializer<LocalChannel>() {
+                        @Override
+                        public void initChannel(LocalChannel ch) throws Exception {
+                            ch.pipeline().addLast(clientHandler);
+                        }
+                    });
+
+            // Start the client.
+            LocalAddress localAddress = new LocalAddress("foo");
+            ChannelFuture f = b.connect(localAddress).sync();
+
+            // Wait until the connection is closed.
+            f.channel().closeFuture().sync();
+        } catch (Exception e) {
+            logger.error("Error in client", e);
+            throw new RuntimeException("Error in client", e);
+        } finally {
+            // Shut down the event loop to terminate all threads.
+            logger.info("Client is shutting down");
+            group.shutdownGracefully();
+        }
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClientHandler.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoClientHandler.java
new file mode 100644 (file)
index 0000000..81182a5
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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.netconf.netty;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import com.google.common.base.Charsets;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handler implementation for the echo client.  It initiates the ping-pong
+ * traffic between the echo client and server by sending the first message to
+ * the server.
+ */
+public class EchoClientHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger logger = LoggerFactory.getLogger(EchoClientHandler.class);
+
+    private ChannelHandlerContext ctx;
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) {
+        checkState(this.ctx == null);
+        logger.info("client active");
+        this.ctx = ctx;
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+        ByteBuf bb = (ByteBuf) msg;
+        logger.info(">{}", bb.toString(Charsets.UTF_8));
+        bb.release();
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        logger.warn("Unexpected exception from downstream.", cause);
+        checkState(this.ctx.equals(ctx));
+        ctx.close();
+        this.ctx = null;
+    }
+
+    public void write(String message) {
+        ByteBuf byteBuf = Unpooled.copiedBuffer(message.getBytes());
+        ctx.writeAndFlush(byteBuf);
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoServer.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoServer.java
new file mode 100644 (file)
index 0000000..ec89d75
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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.netconf.netty;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.local.LocalChannel;
+import io.netty.channel.local.LocalServerChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Echoes back any received data from a client.
+ */
+public class EchoServer implements Runnable {
+    private static final Logger logger = LoggerFactory.getLogger(EchoServer.class);
+
+    public void run() {
+        // Configure the server.
+        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
+        EventLoopGroup workerGroup = new NioEventLoopGroup();
+        try {
+            ServerBootstrap b = new ServerBootstrap();
+            b.group(bossGroup, workerGroup)
+                    .channel(LocalServerChannel.class)
+                    .option(ChannelOption.SO_BACKLOG, 100)
+                    .handler(new LoggingHandler(LogLevel.INFO))
+                    .childHandler(new ChannelInitializer<LocalChannel>() {
+                        @Override
+                        public void initChannel(LocalChannel ch) throws Exception {
+                            ch.pipeline().addLast(new EchoServerHandler());
+                        }
+                    });
+
+            // Start the server.
+            LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();
+            ChannelFuture f = b.bind(localAddress).sync();
+
+            // Wait until the server socket is closed.
+            f.channel().closeFuture().sync();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            // Shut down all event loops to terminate all threads.
+            bossGroup.shutdownGracefully();
+            workerGroup.shutdownGracefully();
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        new Thread(new EchoServer()).start();
+        Thread.sleep(1000);
+        EchoClientHandler clientHandler = new EchoClientHandler();
+        EchoClient echoClient = new EchoClient(clientHandler);
+        new Thread(echoClient).start();
+
+        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+        do {
+            String message = reader.readLine();
+            if (message == null ||  "exit".equalsIgnoreCase(message)) {
+                break;
+            }
+            logger.debug("Got '{}'", message);
+            clientHandler.write(message);
+        } while (true);
+        System.exit(0);
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoServerHandler.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/EchoServerHandler.java
new file mode 100644 (file)
index 0000000..1286ec6
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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.netconf.netty;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Splitter;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandler.Sharable;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handler implementation for the echo server.
+ */
+@Sharable
+public class EchoServerHandler extends ChannelInboundHandlerAdapter {
+
+    private static final Logger logger = LoggerFactory.getLogger(EchoServerHandler.class.getName());
+    private String fromLastNewLine = "";
+    private final Splitter splitter = Splitter.onPattern("\r?\n");
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) throws Exception {
+        logger.debug("sleep start");
+        Thread.sleep(1000);
+        logger.debug("sleep done");
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+        ByteBuf byteBuf = (ByteBuf) msg;
+        String message = byteBuf.toString(Charsets.UTF_8);
+        logger.info("writing back '{}'", message);
+        ctx.write(msg);
+        fromLastNewLine += message;
+        for (String line : splitter.split(fromLastNewLine)) {
+            if ("quit".equals(line)) {
+                logger.info("closing server ctx");
+                ctx.flush();
+                ctx.close();
+                break;
+            }
+            fromLastNewLine = line; // last line should be preserved
+        }
+
+        // do not release byteBuf as it is handled back
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+        logger.debug("flushing");
+        ctx.flush();
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/ProxyServer.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/ProxyServer.java
new file mode 100644 (file)
index 0000000..8f2c502
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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.netconf.netty;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import java.net.InetSocketAddress;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
+
+public class ProxyServer implements Runnable {
+    private final ProxyHandlerFactory proxyHandlerFactory;
+
+    public ProxyServer(ProxyHandlerFactory proxyHandlerFactory) {
+        this.proxyHandlerFactory = proxyHandlerFactory;
+    }
+
+    public void run() {
+        // Configure the server.
+        final EventLoopGroup bossGroup = new NioEventLoopGroup();
+        EventLoopGroup workerGroup = new NioEventLoopGroup();
+        try {
+            final LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();
+            ServerBootstrap serverBootstrap = new ServerBootstrap();
+            serverBootstrap.group(bossGroup, workerGroup)
+                    .channel(NioServerSocketChannel.class)
+                    .option(ChannelOption.SO_BACKLOG, 100)
+                    .handler(new LoggingHandler(LogLevel.INFO))
+                    .childHandler(new ChannelInitializer<SocketChannel>() {
+                        @Override
+                        public void initChannel(SocketChannel ch) throws Exception {
+                            ch.pipeline().addLast(proxyHandlerFactory.create(bossGroup, localAddress));
+                        }
+                    });
+
+            // Start the server.
+            InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8080);
+            ChannelFuture f = serverBootstrap.bind(address).sync();
+
+            // Wait until the server socket is closed.
+            f.channel().closeFuture().sync();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            // Shut down all event loops to terminate all threads.
+            bossGroup.shutdownGracefully();
+            workerGroup.shutdownGracefully();
+        }
+    }
+    public static interface ProxyHandlerFactory {
+        ChannelHandler create(EventLoopGroup bossGroup, LocalAddress localAddress);
+    }
+
+    public static void main(String[] args) {
+        ProxyHandlerFactory proxyHandlerFactory = new ProxyHandlerFactory() {
+            @Override
+            public ChannelHandler create(EventLoopGroup bossGroup, LocalAddress localAddress) {
+                return new ProxyServerHandler(bossGroup, localAddress);
+            }
+        };
+        start(proxyHandlerFactory);
+    }
+
+    public static void start(ProxyHandlerFactory proxyHandlerFactory) {
+        new Thread(new EchoServer()).start();
+        new Thread(new ProxyServer(proxyHandlerFactory)).start();
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/ProxyServerHandler.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/ProxyServerHandler.java
new file mode 100644 (file)
index 0000000..ecab212
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * 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.netconf.netty;
+
+import com.google.common.base.Charsets;
+import io.netty.bootstrap.Bootstrap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.local.LocalChannel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProxyServerHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger logger = LoggerFactory.getLogger(ProxyServerHandler.class.getName());
+    private final Bootstrap clientBootstrap;
+    private final LocalAddress localAddress;
+
+
+    private Channel clientChannel;
+
+    public ProxyServerHandler(EventLoopGroup bossGroup, LocalAddress localAddress) {
+        clientBootstrap = new Bootstrap();
+        clientBootstrap.group(bossGroup).channel(LocalChannel.class);
+        this.localAddress = localAddress;
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext remoteCtx) {
+        final ProxyClientHandler clientHandler = new ProxyClientHandler(remoteCtx);
+        clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
+            @Override
+            public void initChannel(LocalChannel ch) throws Exception {
+                ch.pipeline().addLast(clientHandler);
+            }
+        });
+        ChannelFuture clientChannelFuture = clientBootstrap.connect(localAddress).awaitUninterruptibly();
+        clientChannel = clientChannelFuture.channel();
+        clientChannel.writeAndFlush(Unpooled.copiedBuffer("connected\n".getBytes()));
+    }
+
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) {
+        logger.info("channelInactive - closing client connection");
+        clientChannel.close();
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, final Object msg) {
+        logger.debug("Writing to client {}", msg);
+        clientChannel.write(msg);
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) {
+        logger.debug("flushing");
+        clientChannel.flush();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        logger.warn("Unexpected exception from downstream.", cause);
+        ctx.close();
+    }
+}
+
+class ProxyClientHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger logger = LoggerFactory.getLogger(ProxyClientHandler.class);
+
+    private final ChannelHandlerContext remoteCtx;
+
+
+    public ProxyClientHandler(ChannelHandlerContext remoteCtx) {
+        this.remoteCtx = remoteCtx;
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) {
+        logger.info("client active");
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+        ByteBuf bb = (ByteBuf) msg;
+        logger.info(">{}", bb.toString(Charsets.UTF_8));
+        remoteCtx.write(msg);
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) {
+        logger.debug("Flushing server ctx");
+        remoteCtx.flush();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        logger.warn("Unexpected exception from downstream", cause);
+        ctx.close();
+    }
+
+    // called both when local or remote connection dies
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) {
+        logger.debug("channelInactive() called, closing remote client ctx");
+        remoteCtx.close();
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/netty/SSHTest.java
new file mode 100644 (file)
index 0000000..4e32e82
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.netconf.netty;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import io.netty.channel.nio.NioEventLoopGroup;
+import org.junit.Test;
+import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
+import org.opendaylight.controller.netconf.ssh.authentication.AuthProvider;
+import org.opendaylight.controller.netconf.ssh.authentication.PEMGenerator;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SSHTest {
+    public static final Logger logger = LoggerFactory.getLogger(SSHTest.class);
+
+    @Test
+    public void test() throws Exception {
+        new Thread(new EchoServer(), "EchoServer").start();
+        AuthProvider authProvider = mock(AuthProvider.class);
+        doReturn(PEMGenerator.generate().toCharArray()).when(authProvider).getPEMAsCharArray();
+        doReturn(true).when(authProvider).authenticated(anyString(), anyString());
+        NetconfSSHServer thread = NetconfSSHServer.start(1831, NetconfConfigUtil.getNetconfLocalAddress(), authProvider, new NioEventLoopGroup());
+        Thread.sleep(2000);
+        logger.info("Closing socket");
+        thread.close();
+        thread.join();
+    }
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/ssh/authentication/SSHServerTest.java b/opendaylight/netconf/netconf-ssh/src/test/java/org/opendaylight/controller/netconf/ssh/authentication/SSHServerTest.java
new file mode 100644 (file)
index 0000000..5e368bc
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 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.ssh.authentication;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+
+import ch.ethz.ssh2.Connection;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import junit.framework.Assert;
+import org.apache.commons.io.IOUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.netconf.StubUserManager;
+import org.opendaylight.controller.netconf.ssh.NetconfSSHServer;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class SSHServerTest {
+
+    private static final String USER = "netconf";
+    private static final String PASSWORD = "netconf";
+    private static final String HOST = "127.0.0.1";
+    private static final int PORT = 1830;
+    private static final InetSocketAddress tcpAddress = new InetSocketAddress("127.0.0.1", 8383);
+    private static final Logger logger = LoggerFactory.getLogger(SSHServerTest.class);
+    private Thread sshServerThread;
+
+    @Mock
+    private BundleContext mockedContext;
+
+
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+        doReturn(null).when(mockedContext).createFilter(anyString());
+        doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), anyString());
+        doReturn(new ServiceReference[0]).when(mockedContext).getServiceReferences(anyString(), anyString());
+
+        logger.info("Creating SSH server");
+        StubUserManager um = new StubUserManager(USER, PASSWORD);
+        String pem;
+        try (InputStream is = getClass().getResourceAsStream("/RSA.pk")) {
+            pem = IOUtils.toString(is);
+        }
+        AuthProvider ap = new AuthProvider(pem, mockedContext);
+        ap.setNullableUserManager(um);
+        EventLoopGroup bossGroup = new NioEventLoopGroup();
+        NetconfSSHServer server = NetconfSSHServer.start(PORT, NetconfConfigUtil.getNetconfLocalAddress(),
+                ap, bossGroup);
+
+        sshServerThread = new Thread(server);
+        sshServerThread.setDaemon(true);
+        sshServerThread.start();
+        logger.info("SSH server on " + PORT);
+    }
+
+    @Test
+    public void connect() {
+        try {
+            Connection conn = new Connection(HOST, PORT);
+            Assert.assertNotNull(conn);
+            logger.info("connecting to SSH server");
+            conn.connect();
+            logger.info("authenticating ...");
+            boolean isAuthenticated = conn.authenticateWithPassword(USER, PASSWORD);
+            Assert.assertTrue(isAuthenticated);
+        } catch (Exception e) {
+            logger.error("Error while starting SSH server.", e);
+        }
+
+    }
+
+}
diff --git a/opendaylight/netconf/netconf-ssh/src/test/resources/logback-test.xml b/opendaylight/netconf/netconf-ssh/src/test/resources/logback-test.xml
new file mode 100644 (file)
index 0000000..324c234
--- /dev/null
@@ -0,0 +1,13 @@
+<configuration>
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%date{"yyyy-MM-dd HH:mm:ss.SSS z"} [%thread] %-5level %logger{36} - %msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <root level="error">
+    <appender-ref ref="STDOUT" />
+  </root>
+  <logger name="org.opendaylight.controller.netconf" level="TRACE"/>
+</configuration>
diff --git a/opendaylight/netconf/netconf-tcp/pom.xml b/opendaylight/netconf/netconf-tcp/pom.xml
new file mode 100644 (file)
index 0000000..65da6e9
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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
+  -->
+<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>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>netconf-subsystem</artifactId>
+    <version>0.2.5-SNAPSHOT</version>
+    <relativePath>../</relativePath>
+  </parent>
+  <artifactId>netconf-tcp</artifactId>
+  <packaging>bundle</packaging>
+  <name>${project.artifactId}</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>netconf-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>netconf-util</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>mockito-configuration</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
+        <configuration>
+          <instructions>
+            <Bundle-Activator>org.opendaylight.controller.netconf.tcp.osgi.NetconfTCPActivator</Bundle-Activator>
+            <Import-Package>com.google.common.base, io.netty.bootstrap, io.netty.channel, io.netty.channel.local,
+              io.netty.channel.nio, io.netty.channel.socket, io.netty.channel.socket.nio, io.netty.handler.logging,
+              io.netty.util.concurrent, org.opendaylight.controller.netconf.util.osgi, org.osgi.framework, org.slf4j</Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/netty/ProxyServer.java b/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/netty/ProxyServer.java
new file mode 100644 (file)
index 0000000..2e0022c
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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.netconf.tcp.netty;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.local.LocalChannel;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import java.net.InetSocketAddress;
+
+public class ProxyServer implements AutoCloseable {
+    private final EventLoopGroup bossGroup = new NioEventLoopGroup();
+    private final EventLoopGroup workerGroup = new NioEventLoopGroup();
+    private final ChannelFuture channelFuture;
+
+    public ProxyServer(InetSocketAddress address, final LocalAddress localAddress) {
+        // Configure the server.
+        final Bootstrap clientBootstrap = new Bootstrap();
+        clientBootstrap.group(bossGroup).channel(LocalChannel.class);
+
+        ServerBootstrap serverBootstrap = new ServerBootstrap();
+        serverBootstrap.group(bossGroup, workerGroup)
+                .channel(NioServerSocketChannel.class)
+                .handler(new LoggingHandler(LogLevel.DEBUG))
+                .childHandler(new ChannelInitializer<SocketChannel>() {
+                    @Override
+                    public void initChannel(SocketChannel ch) throws Exception {
+                        ch.pipeline().addLast(new ProxyServerHandler(clientBootstrap, localAddress));
+                    }
+                });
+
+        // Start the server.
+        channelFuture = serverBootstrap.bind(address).syncUninterruptibly();
+    }
+
+    @Override
+    public void close() {
+        channelFuture.channel().close();
+        bossGroup.shutdownGracefully();
+        workerGroup.shutdownGracefully();
+    }
+}
diff --git a/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/netty/ProxyServerHandler.java b/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/netty/ProxyServerHandler.java
new file mode 100644 (file)
index 0000000..fa88928
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * 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.netconf.tcp.netty;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelInboundHandlerAdapter;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.local.LocalAddress;
+import io.netty.channel.local.LocalChannel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProxyServerHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger logger = LoggerFactory.getLogger(ProxyServerHandler.class.getName());
+    private final Bootstrap clientBootstrap;
+    private final LocalAddress localAddress;
+
+    private Channel clientChannel;
+
+    public ProxyServerHandler(Bootstrap clientBootstrap, LocalAddress localAddress) {
+        this.clientBootstrap = clientBootstrap;
+        this.localAddress = localAddress;
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext remoteCtx) {
+        final ProxyClientHandler clientHandler = new ProxyClientHandler(remoteCtx);
+        clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
+            @Override
+            public void initChannel(LocalChannel ch) throws Exception {
+                ch.pipeline().addLast(clientHandler);
+            }
+        });
+        ChannelFuture clientChannelFuture = clientBootstrap.connect(localAddress).awaitUninterruptibly();
+        clientChannel = clientChannelFuture.channel();
+    }
+
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) {
+        logger.trace("channelInactive - closing client channel");
+        clientChannel.close();
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, final Object msg) {
+        logger.trace("Writing to client channel");
+        clientChannel.write(msg);
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) {
+        logger.trace("Flushing client channel");
+        clientChannel.flush();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        logger.warn("Unexpected exception from downstream.", cause);
+        ctx.close();
+    }
+}
+
+class ProxyClientHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger logger = LoggerFactory.getLogger(ProxyClientHandler.class);
+
+    private final ChannelHandlerContext remoteCtx;
+    private ChannelHandlerContext localCtx;
+
+    public ProxyClientHandler(ChannelHandlerContext remoteCtx) {
+        this.remoteCtx = remoteCtx;
+    }
+
+    @Override
+    public void channelActive(ChannelHandlerContext ctx) {
+        checkState(this.localCtx == null);
+        logger.trace("Client channel active");
+        this.localCtx = ctx;
+    }
+
+    @Override
+    public void channelRead(ChannelHandlerContext ctx, Object msg) {
+        logger.trace("Forwarding message");
+        remoteCtx.write(msg);
+    }
+
+    @Override
+    public void channelReadComplete(ChannelHandlerContext ctx) {
+        logger.trace("Flushing remote ctx");
+        remoteCtx.flush();
+    }
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
+        // Close the connection when an exception is raised.
+        logger.warn("Unexpected exception from downstream", cause);
+        checkState(this.localCtx.equals(ctx));
+        ctx.close();
+    }
+
+    // called both when local or remote connection dies
+    @Override
+    public void channelInactive(ChannelHandlerContext ctx) {
+        logger.trace("channelInactive() called, closing remote client ctx");
+        remoteCtx.close();
+    }
+
+}
diff --git a/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/osgi/NetconfTCPActivator.java b/opendaylight/netconf/netconf-tcp/src/main/java/org/opendaylight/controller/netconf/tcp/osgi/NetconfTCPActivator.java
new file mode 100644 (file)
index 0000000..bc94e59
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.netconf.tcp.osgi;
+
+import com.google.common.base.Optional;
+import java.net.InetSocketAddress;
+import org.opendaylight.controller.netconf.tcp.netty.ProxyServer;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil;
+import org.opendaylight.controller.netconf.util.osgi.NetconfConfigUtil.InfixProp;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Opens TCP port specified in config.ini, creates bridge between this port and local netconf server.
+ */
+public class NetconfTCPActivator implements BundleActivator {
+    private static final Logger logger = LoggerFactory.getLogger(NetconfTCPActivator.class);
+    private ProxyServer proxyServer;
+
+    @Override
+    public void start(BundleContext context) {
+        final Optional<InetSocketAddress> maybeAddress = NetconfConfigUtil.extractNetconfServerAddress(context, InfixProp.tcp);
+        if (maybeAddress.isPresent() == false) {
+            logger.debug("Netconf tcp server is not configured to start");
+            return;
+        }
+        InetSocketAddress address = maybeAddress.get();
+        if (address.getAddress().isAnyLocalAddress()) {
+            logger.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. " +
+                    "Consider changing {} to 127.0.0.1", NetconfConfigUtil.getNetconfServerAddressKey(InfixProp.tcp));
+        }
+        logger.info("Starting TCP netconf server at {}", address);
+        proxyServer = new ProxyServer(address, NetconfConfigUtil.getNetconfLocalAddress());
+    }
+
+    @Override
+    public void stop(BundleContext context) {
+        if (proxyServer != null) {
+            proxyServer.close();
+        }
+    }
+}
index dcbdcabbba2683b260b003624c189561a134de2a..d9d957c663766ccb847cc57a3cde920b19d6cfd2 100644 (file)
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
         <configuration>
           <instructions>
             <Import-Package>com.google.common.base, com.google.common.collect, io.netty.channel,
               io.netty.util.concurrent, javax.annotation, javax.xml.namespace, javax.xml.parsers, javax.xml.transform,
               javax.xml.transform.dom, javax.xml.transform.stream, javax.xml.validation, javax.xml.xpath,
               org.opendaylight.controller.netconf.api, org.opendaylight.controller.netconf.mapping.api,
-              org.osgi.framework, org.slf4j, org.w3c.dom, org.xml.sax</Import-Package>
+              org.osgi.framework, org.slf4j, org.w3c.dom, org.xml.sax,io.netty.channel.local</Import-Package>
             <Export-Package>org.opendaylight.controller.netconf.util.*</Export-Package>
           </instructions>
         </configuration>
index 0993b8ad0c7038e5b86b0fee0e5cb4d30fd701f8..333fea3493172286fdba2c807eff105760741411 100644 (file)
@@ -9,36 +9,35 @@
 package org.opendaylight.controller.netconf.util.osgi;
 
 import com.google.common.base.Optional;
+import io.netty.channel.local.LocalAddress;
+import java.net.InetSocketAddress;
 import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.net.InetSocketAddress;
-
 public final class NetconfConfigUtil {
     private static final Logger logger = LoggerFactory.getLogger(NetconfConfigUtil.class);
 
-    public static final InetSocketAddress DEFAULT_NETCONF_TCP_ADDRESS
-            = new InetSocketAddress("127.0.0.1", 8383);
-    public static final InetSocketAddress DEFAULT_NETCONF_SSH_ADDRESS
-            = new InetSocketAddress("0.0.0.0", 1830);
-
     private static final String PREFIX_PROP = "netconf.";
 
     private NetconfConfigUtil() {
     }
 
-    private enum InfixProp {
+    public enum InfixProp {
         tcp, ssh
     }
 
     private static final String PORT_SUFFIX_PROP = ".port";
     private static final String ADDRESS_SUFFIX_PROP = ".address";
-    private static final String CLIENT_PROP = ".client";
     private static final String PRIVATE_KEY_PATH_PROP = ".pk.path";
 
     private static final String CONNECTION_TIMEOUT_MILLIS_PROP = "connectionTimeoutMillis";
     private static final long DEFAULT_TIMEOUT_MILLIS = 5000;
+    private static final LocalAddress netconfLocalAddress = new LocalAddress("netconf");
+
+    public static LocalAddress getNetconfLocalAddress() {
+        return netconfLocalAddress;
+    }
 
     public static long extractTimeoutMillis(final BundleContext bundleContext) {
         final String key = PREFIX_PROP + CONNECTION_TIMEOUT_MILLIS_PROP;
@@ -54,22 +53,6 @@ public final class NetconfConfigUtil {
         }
     }
 
-    public static InetSocketAddress extractTCPNetconfServerAddress(final BundleContext context, final InetSocketAddress defaultAddress) {
-        final Optional<InetSocketAddress> extracted = extractNetconfServerAddress(context, InfixProp.tcp);
-        final InetSocketAddress netconfTcpAddress = getNetconfAddress(defaultAddress, extracted, InfixProp.tcp);
-        logger.debug("Using {} as netconf tcp address", netconfTcpAddress);
-        if (netconfTcpAddress.getAddress().isAnyLocalAddress()) {
-            logger.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. " +
-                    "Consider changing {} to 127.0.0.1", PREFIX_PROP + InfixProp.tcp + ADDRESS_SUFFIX_PROP);
-        }
-        return netconfTcpAddress;
-    }
-
-    public static InetSocketAddress extractTCPNetconfClientAddress(final BundleContext context, final InetSocketAddress defaultAddress) {
-        final Optional<InetSocketAddress> extracted = extractNetconfClientAddress(context, InfixProp.tcp);
-        return getNetconfAddress(defaultAddress, extracted, InfixProp.tcp);
-    }
-
     /**
      * Get extracted address or default.
      *
@@ -93,15 +76,12 @@ public final class NetconfConfigUtil {
         return inetSocketAddress;
     }
 
-    public static InetSocketAddress extractSSHNetconfAddress(final BundleContext context, final InetSocketAddress defaultAddress) {
-        Optional<InetSocketAddress> extractedAddress = extractNetconfServerAddress(context, InfixProp.ssh);
-        InetSocketAddress netconfSSHAddress = getNetconfAddress(defaultAddress, extractedAddress, InfixProp.ssh);
-        logger.debug("Using {} as netconf SSH address", netconfSSHAddress);
-        return netconfSSHAddress;
+    public static String getPrivateKeyPath(final BundleContext context) {
+        return getPropertyValue(context, getPrivateKeyKey());
     }
 
-    public static String getPrivateKeyPath(final BundleContext context) {
-        return getPropertyValue(context, PREFIX_PROP + InfixProp.ssh + PRIVATE_KEY_PATH_PROP);
+    public static String getPrivateKeyKey() {
+        return PREFIX_PROP + InfixProp.ssh + PRIVATE_KEY_PATH_PROP;
     }
 
     private static String getPropertyValue(final BundleContext context, final String propertyName) {
@@ -112,16 +92,20 @@ public final class NetconfConfigUtil {
         return propertyValue;
     }
 
+    public static String getNetconfServerAddressKey(InfixProp infixProp) {
+        return PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP;
+    }
+
     /**
      * @param context   from which properties are being read.
      * @param infixProp either tcp or ssh
      * @return value if address and port are present and valid, Optional.absent otherwise.
      * @throws IllegalStateException if address or port are invalid, or configuration is missing
      */
-    private static Optional<InetSocketAddress> extractNetconfServerAddress(final BundleContext context,
+    public static Optional<InetSocketAddress> extractNetconfServerAddress(final BundleContext context,
                                                                            final InfixProp infixProp) {
 
-        final Optional<String> address = getProperty(context, PREFIX_PROP + infixProp + ADDRESS_SUFFIX_PROP);
+        final Optional<String> address = getProperty(context, getNetconfServerAddressKey(infixProp));
         final Optional<String> port = getProperty(context, PREFIX_PROP + infixProp + PORT_SUFFIX_PROP);
 
         if (address.isPresent() && port.isPresent()) {
@@ -140,24 +124,6 @@ public final class NetconfConfigUtil {
         return new InetSocketAddress(address.get(), portNumber);
     }
 
-    private static Optional<InetSocketAddress> extractNetconfClientAddress(final BundleContext context,
-                                                                           final InfixProp infixProp) {
-        final Optional<String> address = getProperty(context,
-                PREFIX_PROP + infixProp + CLIENT_PROP + ADDRESS_SUFFIX_PROP);
-        final Optional<String> port = getProperty(context,
-                PREFIX_PROP + infixProp + CLIENT_PROP + PORT_SUFFIX_PROP);
-
-        if (address.isPresent() && port.isPresent()) {
-            try {
-                return Optional.of(parseAddress(address, port));
-            } catch (final RuntimeException e) {
-                logger.warn("Unable to parse client {} netconf address from {}:{}, fallback to server address",
-                        infixProp, address, port, e);
-            }
-        }
-        return extractNetconfServerAddress(context, infixProp);
-    }
-
     private static Optional<String> getProperty(final BundleContext context, final String propKey) {
         String value = context.getProperty(propKey);
         if (value != null && value.isEmpty()) {
index 4f87fd8626b2d1cfd98925c0e3be5015808b41a3..d26fcf987e5469388b5c01bac3a391b805a46536 100644 (file)
@@ -27,6 +27,7 @@
     <module>netconf-mapping-api</module>
     <module>netconf-client</module>
     <module>netconf-ssh</module>
+    <module>netconf-tcp</module>
     <module>netconf-monitoring</module>
     <module>ietf-netconf-monitoring</module>
     <module>ietf-netconf-monitoring-extension</module>
 
     </pluginManagement>
     <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>2.12</version>
+        <configuration>
+          <failsOnError>false</failsOnError>
+          <failOnViolation>false</failOnViolation>
+          <configLocation>checkstyle-logging.xml</configLocation>
+          <consoleOutput>true</consoleOutput>
+          <includeTestSourceDirectory>true</includeTestSourceDirectory>
+          <sourceDirectory>${project.basedir}</sourceDirectory>
+          <includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat,**\/*.yang</includes>
+          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,**\/${jmxGeneratorPath}\/,**\/${salGeneratorPath}\/</excludes>
+        </configuration>
+        <dependencies>
+          <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>checkstyle-logging</artifactId>
+            <version>${yangtools.version}</version>
+          </dependency>
+        </dependencies>
+        <executions>
+          <execution>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
index ebf623b7b00ff8bcf9dd784530b61de735bb0839..468313c164384befcc5f9477f4a5670609d95caf 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.controller.sal.action.SetNwDst;
 import org.opendaylight.controller.sal.action.SetNwSrc;
 import org.opendaylight.controller.sal.action.SetTpDst;
 import org.opendaylight.controller.sal.action.SetTpSrc;
+import org.opendaylight.controller.sal.action.SetVlanId;
 import org.opendaylight.controller.sal.flowprogrammer.Flow;
 import org.opendaylight.controller.sal.match.Match;
 import org.opendaylight.controller.sal.match.MatchType;
@@ -54,18 +55,23 @@ public class ContainerFlow implements Serializable {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         ContainerFlow other = (ContainerFlow) obj;
         if (match == null) {
-            if (other.match != null)
+            if (other.match != null) {
                 return false;
-        } else if (!match.equals(other.match))
+            }
+        } else if (!match.equals(other.match)) {
             return false;
+        }
         return true;
     }
 
@@ -95,6 +101,11 @@ public class ContainerFlow implements Serializable {
         Match actionMatch = new Match();
         for (Action action : flow.getActions()) {
             switch (action.getType()) {
+            case SET_VLAN_ID:
+                actionMatch.setField(MatchType.DL_VLAN,
+                        ((Integer) ((SetVlanId) action).getVlanId())
+                                .shortValue());
+                break;
             case SET_DL_TYPE:
                 actionMatch.setField(MatchType.DL_TYPE,
                         ((Integer) ((SetDlType) action).getDlType())
diff --git a/pom.xml b/pom.xml
index 2a9da6c1ec69b2b282c1641bb4a2d6ea7bfc220a..8ad038763c8f2909ff95974b888c281adbcf44ae 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <module>opendaylight/commons/opendaylight</module>
     <module>opendaylight/commons/parent</module>
     <module>opendaylight/commons/logback_settings</module>
+    <module>opendaylight/commons/filter-valve</module>
 
     <!-- Karaf Distribution -->
     <module>features/base</module>