Merge "Fixed netconf monitoring."
authorEd Warnicke <eaw@cisco.com>
Mon, 16 Dec 2013 15:52:41 +0000 (15:52 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 16 Dec 2013 15:52:41 +0000 (15:52 +0000)
155 files changed:
opendaylight/commons/controller-maven-plugin/pom.xml [deleted file]
opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/AbstractControllerMojo.java [deleted file]
opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/StartControllerMojo.java [deleted file]
opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/StopControllerMojo.java [deleted file]
opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/JavaProcess.java [deleted file]
opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/JpsProcessMonitor.java [deleted file]
opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/ProcessMonitor.java [deleted file]
opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/VMProcessMonitor.java [deleted file]
opendaylight/commons/integrationtest/pom.xml
opendaylight/commons/opendaylight/pom.xml
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/ConfigRegistry.java
opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/LookupRegistry.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionLookupRegistry.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/ServiceReferenceRegistryImpl.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/factoriesresolver/HierarchicalConfigMBeanFactoriesHolder.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/osgi/ConfigManagerActivator.java
opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/ModuleQNameUtil.java [new file with mode: 0644]
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/ConfigRegistryImplTest.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigRegistryImplLookupTest.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/ConfigTransactionControllerImplTest.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/AbstractTestingFixedThreadPoolModuleFactory.java [new file with mode: 0644]
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/TestingFixedThreadPoolModuleFactory.java
opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/test/SimpleConfigurationTest.java
opendaylight/config/config-persister-directory-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/DirectoryPersister.java
opendaylight/config/config-persister-directory-xml-adapter/pom.xml [new file with mode: 0644]
opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryPersister.java [new file with mode: 0644]
opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryStorageAdapter.java [new file with mode: 0644]
opendaylight/config/config-persister-directory-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/xml/DirectoryStorageAdapterTest.java [new file with mode: 0644]
opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/oneFile/controller.config.xml [new file with mode: 0644]
opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/twoFiles/controller.config1.xml [new file with mode: 0644]
opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/twoFiles/controller.config2.xml [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/pom.xml [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/CapabilityHandler.java [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/PersistException.java [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java [new file with mode: 0644]
opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java [new file with mode: 0644]
opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigRegistryJMXClient.java
opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigTransactionJMXClient.java
opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigRegistry.java
opendaylight/config/config-util/src/test/java/org/opendaylight/controller/config/util/TestingConfigTransactionController.java
opendaylight/config/pom.xml
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/AbstractFactoryTemplate.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/model/Annotation.java
opendaylight/config/yang-jmx-generator-plugin/src/main/resources/freeMarker/factory_abs_template.ftl
opendaylight/config/yang-jmx-generator/pom.xml
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleMXBeanEntry.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleUtil.java [new file with mode: 0644]
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ServiceInterfaceEntry.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/TypeProviderWrapper.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/JavaAttribute.java
opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/attribute/SimpleTypeResolver.java
opendaylight/config/yang-test/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/test/types/rev131127/UnionTestBuilder.java [new file with mode: 0644]
opendaylight/config/yang-test/src/main/yang/config-test-impl.yang
opendaylight/config/yang-test/src/main/yang/types/test-types.yang
opendaylight/distribution/opendaylight/pom.xml
opendaylight/distribution/opendaylight/runsanity.bat [new file with mode: 0644]
opendaylight/distribution/opendaylight/runsanity.sh [new file with mode: 0755]
opendaylight/distribution/opendaylight/src/assemble/bin.xml
opendaylight/distribution/opendaylight/src/main/resources/configuration/config.ini
opendaylight/distribution/opendaylight/src/main/resources/run.bat
opendaylight/distribution/sanitytest/pom.xml
opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java [new file with mode: 0644]
opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java [new file with mode: 0644]
opendaylight/distribution/sanitytest/src/test/java/org/opendaylight/controller/distribution/test/SanityIT.java [deleted file]
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/adsal/FlowStatisticsAdapter.java
opendaylight/md-sal/model/model-flow-base/src/main/yang/match-types.yang
opendaylight/md-sal/model/model-flow-base/src/main/yang/opendaylight-action-types.yang
opendaylight/md-sal/model/model-flow-base/src/main/yang/opendaylight-flow-types.yang
opendaylight/md-sal/model/model-flow-base/src/main/yang/table-types.yang
opendaylight/md-sal/model/model-flow-service/src/main/yang/flow-node-inventory.yang
opendaylight/md-sal/model/model-flow-statistics/src/main/yang/flow-statistics.yang
opendaylight/md-sal/model/model-flow-statistics/src/main/yang/flow-table-statistics.yang [new file with mode: 0644]
opendaylight/md-sal/model/model-flow-statistics/src/main/yang/port-statistics.yang [new file with mode: 0644]
opendaylight/md-sal/model/model-flow-statistics/src/main/yang/statistics-types.yang
opendaylight/md-sal/pom.xml
opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/RpcAvailabilityListener.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/pom.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/DataBrokerImplModule.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/binding/impl/RuntimeMappingModule.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/RuntimeCodeHelper.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.xtend [deleted file]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.xtend [deleted file]
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/SingletonHolder.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/LazyGeneratedCodecRegistry.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/RuntimeGeneratedMappingServiceImpl.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/dom/serializer/impl/TransformerGenerator.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/NotificationBrokerImpl.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/OsgiConsumerContext.xtend
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentConnector.java [moved from opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentDataServiceConnector.java with 58% similarity]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/BindingIndependentMappingService.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/util/ClassLoaderUtils.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/spi/RoutingContext.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/spi/RpcContextIdentifier.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/spi/RpcRouter.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/AbstractDataServiceTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/RuntimeCodeGeneratorTest.java
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/UnionSerializationTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java
opendaylight/md-sal/sal-binding-dom-it/pom.xml
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/CrossBrokerRpcTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/connect/dom/MessageCapturingFlowService.java [new file with mode: 0644]
opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/routing/RouteChangePublisher.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/routing/RoutingUtils.java [new file with mode: 0644]
opendaylight/md-sal/sal-common-util/pom.xml
opendaylight/md-sal/sal-common-util/src/main/java/org/opendaylight/controller/sal/common/util/Rpcs.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerImpl.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/RpcRouterImpl.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/SchemaAwareDataStoreAdapter.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/yangtools/yang/util/YangSchemaUtils.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/MultipartMessageManager.java [new file with mode: 0644]
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatistics.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/StatisticsUpdateCommiter.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/AttributeIfcSwitchStatement.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/AttributesConstants.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/ObjectXmlReader.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/SimpleUnionAttributeReadingStrategy.java [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/mapping/CompositeAttributeMappingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/mapping/ObjectMapper.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/mapping/UnionCompositeAttributeMappingStrategy.java [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/resolving/CompositeAttributeResolvingStrategy.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/resolving/ObjectResolver.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/resolving/UnionCompositeAttributeResolvingStrategy.java [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/toxml/ObjectXmlWriter.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/toxml/SimpleUnionAttributeWritingStrategy.java [new file with mode: 0644]
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java
opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/util/Util.java
opendaylight/netconf/config-netconf-connector/src/test/java/org/opendaylight/controller/netconf/confignetconfconnector/NetconfMappingTest.java
opendaylight/netconf/config-persister-impl/pom.xml
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/PersisterAggregator.java
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/PropertiesProviderAdapterImpl.java
opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/PersisterAggregatorTest.java
opendaylight/netconf/config-persister-impl/src/test/resources/test2.properties
opendaylight/netconf/config-persister-impl/src/test/resources/test3.properties
opendaylight/netconf/ietf-netconf-monitoring/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/netconf/monitoring/rev101004/netconf/state/schemas/LocationBuilder.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/src/test/resources/netconfMessages/editConfig_setUnions.xml [new file with mode: 0644]
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDP.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/packet/LLDPTLV.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/utils/NodeConnectorCreator.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java
opendaylight/topologymanager/integrationtest/pom.xml
pom.xml

diff --git a/opendaylight/commons/controller-maven-plugin/pom.xml b/opendaylight/commons/controller-maven-plugin/pom.xml
deleted file mode 100644 (file)
index 1ab4e70..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-
-  <parent>
-    <groupId>org.opendaylight.controller</groupId>
-    <artifactId>commons.opendaylight</artifactId>
-    <version>1.4.1-SNAPSHOT</version>
-    <relativePath>../../commons/opendaylight</relativePath>
-  </parent>
-
-  <artifactId>controller-maven-plugin</artifactId>
-  <version>0.1.0-SNAPSHOT</version>
-  <packaging>maven-plugin</packaging>
-
-  <name>controller-maven-plugin</name>
-  <description>Maven Plugin for controlling the launch of the controller.</description>
-  <url>http://maven.apache.org</url>
-
-  <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-  </properties>
-
-  <dependencies>
-    <dependency>
-      <!-- controller mojos depend on the api module -->
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-plugin-api</artifactId>
-      <version>2.0</version>
-    </dependency>
-    <dependency>
-      <!-- controller mojos use the annotations defined in this module -->
-      <groupId>org.apache.maven.plugin-tools</groupId>
-      <artifactId>maven-plugin-annotations</artifactId>
-      <version>3.2</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <!-- needed for handling processes -->
-      <groupId>com.sun</groupId>
-      <artifactId>tools</artifactId>
-      <scope>system</scope>
-      <version>7</version>
-      <systemPath>${java.home}/../lib/tools.jar</systemPath>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.8.1</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <!-- plugin builder -->
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-plugin-plugin</artifactId>
-        <version>3.2</version>
-        <configuration>
-          <goalPrefix>controller-maven-plugin</goalPrefix>
-          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
-        </configuration>
-        <executions>
-          <execution>
-            <id>mojo-descriptor</id>
-            <goals>
-              <goal>descriptor</goal>
-            </goals>
-          </execution>
-          <execution>
-            <id>help-goal</id>
-            <goals>
-              <goal>helpmojo</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-
-</project>
diff --git a/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/AbstractControllerMojo.java b/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/AbstractControllerMojo.java
deleted file mode 100644 (file)
index 39ca71c..0000000
+++ /dev/null
@@ -1,228 +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.maven.plugin;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Parameter;
-
-import org.opendaylight.controller.maven.plugin.util.JavaProcess;
-import org.opendaylight.controller.maven.plugin.util.ProcessMonitor;
-
-/**
- * Base controller mojo which handles common operations
- */
-public abstract class AbstractControllerMojo extends AbstractMojo {
-    public static final String OS_NAME = System.getProperty("os.name");
-    public static final boolean WIN = OS_NAME.toUpperCase().contains("WINDOWS");
-    public static final String JAVA_HOME = "JAVA_HOME";
-    public static final boolean skip = Boolean.getBoolean("controller.startup.skip");
-    public static final String MAIN_CLASS = "org.eclipse.equinox.launcher.Main";
-    public static final String CTRL_PROP = "opendaylight.controller";
-
-    /**
-     * The home directory where controller is installed
-     */
-    @Parameter( required = false )
-    protected File controllerHome;
-
-    /**
-     * The address on which controller is listening
-     */
-    @Parameter( defaultValue = "localhost")
-    protected String controllerHost;
-
-    /**
-     * The admin web port
-     */
-    @Parameter( defaultValue = "8080")
-    protected int controllerWebPort;
-
-    /**
-     * The openflow port
-     */
-    @Parameter( defaultValue = "6633")
-    protected int controllerOFPort;
-
-    /**
-     * Additional environment variables passed when starting the controller
-     * process.
-     */
-    @Parameter(required = false)
-    protected Properties controllerShellVariables;
-
-    /**
-     * The script name to invoke
-     */
-    @Parameter(required = false)
-    protected String controllerStartScriptName;
-
-    /**
-     * The username
-     */
-    @Parameter(required = false)
-    protected String controllerUsername;
-
-    /**
-     * The password
-     */
-    @Parameter(required = false)
-    protected String controllerPassword;
-
-    /**
-     * pidFile location
-     */
-    @Parameter(required = false)
-    protected File pidFile;
-
-    protected final ProcessMonitor procMon = ProcessMonitor.load();
-
-    public abstract void start() throws MojoExecutionException, MojoFailureException;
-
-    public void execute() throws MojoExecutionException, MojoFailureException {
-        if (skip) return;
-        validateArgs();
-        start();
-    }
-
-    protected URL getWebUrl() {
-      try {
-        return new URL("http", controllerHost, controllerWebPort, "/");
-      } catch (MalformedURLException e) {
-        throw new IllegalArgumentException(
-            "controller host:port is Malformed: " + controllerHost + " " + controllerWebPort, e);
-      }
-
-    }
-
-    protected void validateArgs() throws IllegalArgumentException {
-        // System property and environment variable override the default setting
-        String odlHome = System.getProperty("controllerHome");
-        if (odlHome != null) {
-          controllerHome = new File(odlHome);
-        }
-        if (controllerHome == null) {
-            getLog().error("controllerHome cannot be determined from controllerHome "
-                + "property or ONE_HOME env variable");
-            throw new IllegalArgumentException("controllerHome cannot be determined.");
-        }
-        if (!controllerHome.exists()) {
-            throw new IllegalArgumentException(
-                    "controllerHome does not exist: " + controllerHome);
-        }
-       if (controllerUsername == null) {
-            controllerUsername = System.getProperty("controllerUsername");
-        }
-        if (controllerPassword == null) {
-            controllerPassword= System.getProperty("controllerPassword");
-        }
-        URL u = getWebUrl();
-        getLog().info("Controller Home       : " + controllerHome);
-        getLog().info("Controller Url        : " + u);
-        getLog().info("Controller credentials: " + controllerUsername
-                + "/" + controllerPassword);
-    }
-
-    protected Process invokeScript(List<String> args, String log)
-            throws MojoFailureException, MojoExecutionException
-    {
-        ProcessBuilder pb = new ProcessBuilder();
-        List<String> cmd = new ArrayList<String>();
-        cmd.add(getScript());
-        if (args != null) {
-            for (String s : args) {
-                // on windows args containing equals symbols need to be quoted
-                if (WIN && s.contains("=") && !s.startsWith("\"")) {
-                  cmd.add("\"" + s + "\"");
-                } else {
-                  cmd.add(s);
-                }
-            }
-        }
-        pb.command(cmd);
-        pb.directory(controllerHome);
-        pb.redirectErrorStream(true);
-        pb.inheritIO();
-        Map<String,String> env = pb.environment();
-        if (controllerShellVariables != null) {
-            for (Enumeration e = controllerShellVariables.propertyNames(); e.hasMoreElements();) {
-                String n = (String) e.nextElement();
-                env.put(n, controllerShellVariables.getProperty(n));
-            }
-        }
-        String jh = env.get(JAVA_HOME);
-        if (jh == null) env.put(JAVA_HOME, System.getProperty("java.home"));
-        try {
-            getLog().info("Invoking process " + pb.command());
-            return pb.start();
-        } catch (IOException e) {
-            throw new MojoExecutionException(e.getMessage());
-        }
-    }
-
-    private String getScript() throws MojoFailureException {
-        File script = null;
-        if (controllerStartScriptName != null && !"".equals(controllerStartScriptName) ) {
-            script = new File(controllerStartScriptName);
-            if (!script.exists()) {
-                // try relative path
-                script = new File(controllerHome, controllerStartScriptName);
-            }
-            if (script.exists()) return script.getAbsolutePath();
-            throw new MojoFailureException("Script not found: " + controllerStartScriptName);
-        }
-        // try default
-        script = new File(controllerHome, "run." + (WIN ? "bat" : "sh") );
-        if (script.exists()) return script.getAbsolutePath();
-        throw new MojoFailureException("Cannot find a default script to launch.");
-    }
-
-    protected boolean canConnect() {
-        try {
-            URL url = getWebUrl();
-            HttpURLConnection con;
-            con = (HttpURLConnection) url.openConnection();
-            return (con.getResponseCode() > 0);
-        } catch (IOException e) {
-            return false;
-        }
-    }
-
-    public void killControllers() {
-        getLog().info("Checking environment for stray processes.");
-        List<JavaProcess> jvms = procMon.getProcesses(MAIN_CLASS, CTRL_PROP);
-        for (JavaProcess j : jvms) {
-            getLog().info("Killing running process: " + j);
-            ProcessMonitor.kill(j.getPid());
-        }
-        // cleanup pid files
-        getLog().info("Checking left over pid file: " + pidFile);
-        if (pidFile != null && pidFile.exists()) {
-            getLog().info("Cleaning up pid file : " + pidFile);
-            pidFile.delete();
-        }
-    }
-
-    public boolean isControllerRunning() {
-        return !procMon.getProcesses(MAIN_CLASS, CTRL_PROP).isEmpty();
-    }
-
-}
diff --git a/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/StartControllerMojo.java b/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/StartControllerMojo.java
deleted file mode 100644 (file)
index 0a3bee4..0000000
+++ /dev/null
@@ -1,94 +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.maven.plugin;
-
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-
-
-/**
- * Starts the controller
- */
-@Mojo( name = "run", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST )
-public class StartControllerMojo extends AbstractControllerMojo {
-    public static final String REDIRECT_LOG = "controller.out";
-
-    /**
-     * The timeout value for starting the controller. Defaults to 60 secs
-     */
-    @Parameter(defaultValue = "60")
-    public int timeoutSecs = 60;
-
-    /**
-     * The startArgs for starting the controller
-     */
-    @Parameter(required = false)
-    protected List<String> startArgs = new ArrayList<String>();
-
-    /**
-     * The time to wait after successfully connecting to the controller and
-     * before returning from execution.
-     */
-    @Parameter(required = false)
-    protected int warmupTimeSecs = 10;
-
-
-    @Override
-    public void start() throws MojoExecutionException, MojoFailureException {
-        killControllers();
-        // if we can still connect to a controller, bail out
-        if (canConnect()) {
-            getLog().error("A controller is already running. Shutdown and retry.");
-            throw new MojoFailureException("Controller is already running.");
-        }
-        startArgs.add("-D" + CTRL_PROP);
-        Process process = invokeScript(startArgs, REDIRECT_LOG);
-        getLog().info("Controller starting... (waiting for open ports)");
-        try {
-            waitForListening(process);
-            getLog().info("Controller port open. Waiting for warmup: "
-                    + warmupTimeSecs);
-            Thread.sleep(warmupTimeSecs*1000);
-        } catch (Exception e) {
-            throw new MojoExecutionException(e.getMessage());
-        }
-        getLog().info("Controller started successfully.");
-    }
-
-    protected boolean waitForListening(Process process)
-            throws MalformedURLException, InterruptedException, MojoExecutionException
-    {
-        long timeElapsedMillis = 0L;
-        long sleepTimeMillis = 2000L; // 2 secs
-        long timeoutMillis = timeoutSecs * 1000;
-
-        while (timeElapsedMillis < timeoutMillis) {
-            long timeRemaining = timeoutMillis - timeElapsedMillis;
-            sleepTimeMillis *= 2;
-            long toSleep = (sleepTimeMillis > timeRemaining)
-                    ? timeRemaining : sleepTimeMillis;
-            Thread.sleep(toSleep);
-            timeElapsedMillis += toSleep;
-            if (canConnect()) {
-                return true;
-            }
-            if (!isControllerRunning()) {
-                throw new MojoExecutionException("Process seems to have exited prematurely.");
-            }
-        }
-        return false;
-    }
-}
diff --git a/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/StopControllerMojo.java b/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/StopControllerMojo.java
deleted file mode 100644 (file)
index 579778d..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.maven.plugin;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-
-/**
- * Stop controller
- */
-@Mojo( name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST )
-public class StopControllerMojo extends AbstractControllerMojo {
-    private static final boolean SKIP_STOP = Boolean.getBoolean("skipControllerStop");
-
-    @Override
-    public void start() throws MojoExecutionException, MojoFailureException {
-        if (SKIP_STOP) {
-            getLog().info("Controller STOP is skipped per configuration " +
-                    "(-DskipControllerStop=true).");
-            return;
-        }
-        if (canConnect()) {
-            List<String> args = new ArrayList<String>();
-            args.add("-stop");
-            Process proc = invokeScript(args, null);
-            try {
-                int status = proc.waitFor();
-                if (status == 0) {
-                    getLog().info("Controller stopped.");
-                } else {
-                    getLog().error("Error stopping controller. See stdout log for details.");
-                }
-            } catch (InterruptedException ie) {
-                throw new MojoExecutionException("Error stopping controller : " + ie.getMessage());
-            }
-        } else {
-            getLog().info("Controller not running.");
-        }
-        // cleanup for any hung processes
-        killControllers();
-    }
-
-}
diff --git a/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/JavaProcess.java b/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/JavaProcess.java
deleted file mode 100644 (file)
index 95da34f..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.maven.plugin.util;
-
-import java.util.Properties;
-
-public class JavaProcess {
-    private final int pid;
-    private final String mainClass;
-    private final Properties systemProperties = new Properties();
-
-    public JavaProcess(int id, String cls) {
-        this.pid = id;
-        this.mainClass = cls;
-    }
-
-    public void setSystemProperties(String line) {
-        if (line == null || line.length() == 0) return;
-        String[] tokens = line.split("\\s");
-        for (String t : tokens) setSystemProperty(t);
-    }
-
-    public void setSystemProperty(String line) {
-        if (line.startsWith("-D")) {
-            int x = line.indexOf('=');
-            if (x > -1) {
-                systemProperties.put(line.substring(2, x), line.substring(x+1));
-            } else {
-                systemProperties.put(line.substring(2), "");
-            }
-        }
-    }
-
-    public int getPid() {
-        return pid;
-    }
-
-    public String getMainClass() {
-        return mainClass;
-    }
-
-    public Properties getSystemProperties() {
-        return systemProperties;
-    }
-
-    @Override
-    public String toString() {
-        return "pid:" + pid + " class:" + mainClass +
-                " system-properties:" + systemProperties.toString();
-    }
-}
diff --git a/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/JpsProcessMonitor.java b/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/JpsProcessMonitor.java
deleted file mode 100644 (file)
index 8474266..0000000
+++ /dev/null
@@ -1,79 +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.maven.plugin.util;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Uses JPS tool to monitor java local processes
- */
-public class JpsProcessMonitor extends ProcessMonitor {
-    private final String jpsTool;
-
-    public JpsProcessMonitor() {
-        String jh = System.getProperty("java.home");
-        File jps = new File(jh + SEP + "bin" + SEP + "jps");
-        if (!jps.exists()) {
-            // try one dir above
-            jps = new File(jh + SEP + ".." + SEP + "bin" + SEP + "jps");
-            if (!jps.exists()) {
-                throw new IllegalStateException("jps tool cannot be located.");
-            }
-        }
-        jpsTool = jps.getAbsolutePath();
-    }
-
-    @Override
-    public List<JavaProcess> getProcesses() {
-        if (jpsTool == null) return super.getProcesses();
-        List<JavaProcess> jvms = new ArrayList<JavaProcess>();
-        try {
-            ProcessBuilder pb = new ProcessBuilder();
-            pb.command(new String[] { jpsTool, "-mlvV"} );
-            pb.redirectErrorStream(true);
-            Process process = pb.start();
-            BufferedReader br = new BufferedReader(
-                    new InputStreamReader(process.getInputStream()));
-            String line = null;
-            while ( (line = br.readLine()) != null) {
-                JavaProcess j = parseLine(line);
-                if (j != null) jvms.add(j);
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return jvms;
-    }
-
-    public static JavaProcess parseLine(String line) {
-        String[] tokens = line.split("\\s");
-        if (tokens.length < 2) {
-            System.out.println("Unable to parse line: " + line);
-            return null;
-        }
-        int idx = 0;
-        int pid = Integer.parseInt(tokens[idx++]);
-        String mainClass = "";
-        if (!tokens[idx].startsWith("-")) {
-            mainClass = tokens[idx++];
-        }
-        JavaProcess proc = new JavaProcess(pid, mainClass);
-        for (int i=idx; i<tokens.length; i++) {
-            if (tokens[i].startsWith("-D")) {
-                proc.setSystemProperty(tokens[i]);
-            }
-        }
-        return proc;
-    }
-
-}
diff --git a/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/ProcessMonitor.java b/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/ProcessMonitor.java
deleted file mode 100644 (file)
index 5c3c69f..0000000
+++ /dev/null
@@ -1,101 +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.maven.plugin.util;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class ProcessMonitor {
-    public static final String SEP = File.pathSeparator;
-    public static final boolean WIN =
-            System.getProperty("os.name").toLowerCase().indexOf("windows") > -1;
-
-
-
-    public void log(String msg) {
-        System.out.println("" + msg);
-    }
-
-    public List<JavaProcess> getProcesses() {
-        return Collections.emptyList();
-    }
-
-    public List<JavaProcess> getProcesses(String mainClass, String systemPropertyKey) {
-        List<JavaProcess> result = new ArrayList<JavaProcess>();
-         for (JavaProcess info : getProcesses()) {
-            if (info.getMainClass().equals(mainClass)) {
-                if (info.getSystemProperties().containsKey(systemPropertyKey)) {
-                    result.add(info);
-                }
-            }
-        }
-        return result;
-    }
-
-    public int kill(String mainClass) {
-        for (JavaProcess info : getProcesses()) {
-            if (info.getMainClass().equals(mainClass)) {
-                log("Killing process matching class: " + mainClass);
-                return kill(info.getPid());
-            }
-        }
-        return -1;
-    }
-
-    public static int kill(int pid)  {
-        String cmd = WIN ? "TASKKILL /F /PID " + pid : "kill -SIGTERM " + pid;
-        try {
-            Process p = Runtime.getRuntime().exec(cmd);
-            p.waitFor();
-            return p.exitValue();
-        } catch (Exception e) {
-            e.printStackTrace();
-            return -1;
-        }
-    }
-
-    public static ProcessMonitor load() {
-        // load the providers dynamically to allow error handling
-        ProcessMonitor pm = load("org.opendaylight.controller.maven.plugin.util.VMProcessMonitor");
-        if (pm == null) {
-            pm = load("org.opendaylight.controller.maven.plugin.util.JpsProcessMonitor");
-        }
-        return (pm == null ? new ProcessMonitor() : pm);
-    }
-
-    private static ProcessMonitor load(String clz) {
-        try {
-            Class c = Class.forName(clz);
-            return (ProcessMonitor) c.newInstance();
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
-
-    // simple driver for basic manual testing
-    public static void main(String[] args) throws Exception {
-        ProcessMonitor pm = ProcessMonitor.load();
-        System.out.println("==== " + pm);
-        for (JavaProcess info : pm.getProcesses()) {
-            System.out.println(info.toString());
-        }
-        pm.kill("Foo");
-        System.out.println("==== controller processses ");
-        for (JavaProcess info : pm.getProcesses(
-                "org.eclipse.equinox.launcher.Main", "opendaylight.controller"))
-        {
-            System.out.println(info.toString());
-            pm.kill(info.getPid());
-        }
-    }
-
-}
diff --git a/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/VMProcessMonitor.java b/opendaylight/commons/controller-maven-plugin/src/main/java/org/opendaylight/controller/maven/plugin/util/VMProcessMonitor.java
deleted file mode 100644 (file)
index fdf232a..0000000
+++ /dev/null
@@ -1,59 +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.maven.plugin.util;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import sun.jvmstat.monitor.HostIdentifier;
-import sun.jvmstat.monitor.MonitoredHost;
-import sun.jvmstat.monitor.MonitoredVm;
-import sun.jvmstat.monitor.MonitoredVmUtil;
-import sun.jvmstat.monitor.VmIdentifier;
-
-public class VMProcessMonitor extends ProcessMonitor {
-
-    @Override
-    public List<JavaProcess> getProcesses() {
-        Set<Integer> activeVmPids = null;
-        List<JavaProcess> result = new ArrayList<JavaProcess>();
-        MonitoredHost monitoredHost = null;
-        MonitoredVm mvm = null;
-        try {
-            monitoredHost = MonitoredHost.getMonitoredHost(
-                    new HostIdentifier((String) null));
-            activeVmPids = monitoredHost.activeVms();
-        } catch (Exception e) {
-            throw new IllegalStateException("Error accessing VM", e);
-        }
-        for (Integer vmPid : activeVmPids) {
-            try {
-                mvm = monitoredHost.getMonitoredVm(
-                        new VmIdentifier(vmPid.toString()));
-                JavaProcess proc = new JavaProcess(vmPid,
-                        MonitoredVmUtil.mainClass(mvm, true));
-                proc.setSystemProperties(MonitoredVmUtil.jvmArgs(mvm));
-                proc.setSystemProperties(MonitoredVmUtil.jvmFlags(mvm));
-                result.add(proc);
-            } catch(Exception e2) {
-                log("Error connecting to pid: " + vmPid + " reason:"
-                    + e2.getMessage());
-                e2.printStackTrace();
-            } finally {
-                if (mvm != null) {
-                    mvm.detach();
-                }
-            }
-        }
-        return result;
-    }
-
-
-}
index 5e101eb..fe5aa47 100644 (file)
       <artifactId>junit</artifactId>
     </dependency>
     <!-- Add Pax Exam -->
-    <dependency>
-      <groupId>org.ops4j.pax.exam</groupId>
-      <artifactId>pax-exam-container-native</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.ops4j.pax.exam</groupId>
       <artifactId>pax-exam-junit4</artifactId>
index 07c8916..5183165 100644 (file)
@@ -70,8 +70,6 @@
     <jacoco.version>0.5.3.201107060350</jacoco.version>
     <enforcer.version>1.3.1</enforcer.version>
     <bundle.plugin.version>2.3.7</bundle.plugin.version>
-    <install.plugin.version>2.5</install.plugin.version>
-    <enforcer.plugin.version>1.3.1</enforcer.plugin.version>
     <junit.version>4.8.1</junit.version>
     <bgpcep.version>0.3.0-SNAPSHOT</bgpcep.version>
     <yangtools.version>0.5.9-SNAPSHOT</yangtools.version>
           <includeTestSourceDirectory>true</includeTestSourceDirectory>
           <sourceDirectory>${project.basedir}</sourceDirectory>
           <includes>**\/*.java,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat</includes>
-          <excludes>**\/target\/,**\/bin\/</excludes>
+          <excludes>**\/target\/,**\/bin\/,**\/target-ide\/</excludes>
         </configuration>
       </plugin>
       <plugin>
index 56b96e9..d81c48a 100644 (file)
@@ -62,8 +62,13 @@ public interface ConfigRegistry extends LookupRegistry, ServiceReferenceReadable
      */
     boolean isHealthy();
 
+    /**
+     * @return module factory names available in the system
+     */
     Set<String> getAvailableModuleNames();
 
+
+
     /**
      * Find all runtime beans
      *
index 8975471..772617e 100644 (file)
@@ -65,4 +65,9 @@ public interface LookupRegistry {
      */
     void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException;
 
+    /**
+     * @return qnames of all ModuleFactory instances in the system
+     */
+    Set<String> getAvailableModuleFactoryQNames();
+
 }
index 18326d9..e3311c7 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.controller.config.manager.impl.jmx.TransactionJMXRegistr
 import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager;
 import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration;
 import org.opendaylight.controller.config.manager.impl.util.LookupBeansUtil;
+import org.opendaylight.controller.config.manager.impl.util.ModuleQNameUtil;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.osgi.framework.BundleContext;
@@ -61,9 +62,6 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
     private final ModuleFactoriesResolver resolver;
     private final MBeanServer configMBeanServer;
 
-    @GuardedBy("this")
-    private final BundleContext bundleContext;
-
     @GuardedBy("this")
     private long version = 0;
     @GuardedBy("this")
@@ -101,6 +99,7 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
     // internal jmx server shared by all transactions
     private final MBeanServer transactionsMBeanServer;
 
+    // Used for finding new factory instances for default module functionality
     @GuardedBy("this")
     private List<ModuleFactory> lastListOfFactories = Collections.emptyList();
 
@@ -109,18 +108,17 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
 
     // constructor
     public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
-            BundleContext bundleContext, MBeanServer configMBeanServer) {
-        this(resolver, bundleContext, configMBeanServer,
+            MBeanServer configMBeanServer) {
+        this(resolver, configMBeanServer,
                 new BaseJMXRegistrator(configMBeanServer));
     }
 
     // constructor
     public ConfigRegistryImpl(ModuleFactoriesResolver resolver,
-            BundleContext bundleContext, MBeanServer configMBeanServer,
+            MBeanServer configMBeanServer,
             BaseJMXRegistrator baseJMXRegistrator) {
         this.resolver = resolver;
         this.beanToOsgiServiceManager = new BeanToOsgiServiceManager();
-        this.bundleContext = bundleContext;
         this.configMBeanServer = configMBeanServer;
         this.baseJMXRegistrator = baseJMXRegistrator;
         this.registryMBeanServer = MBeanServerFactory
@@ -156,10 +154,10 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
             }
         };
 
-        ConfigTransactionLookupRegistry txLookupRegistry = new ConfigTransactionLookupRegistry(new TransactionIdentifier(
-                transactionName), factory);
         Map<String, Map.Entry<ModuleFactory, BundleContext>> allCurrentFactories = Collections.unmodifiableMap(
                 resolver.getAllFactories());
+        ConfigTransactionLookupRegistry txLookupRegistry = new ConfigTransactionLookupRegistry(new TransactionIdentifier(
+                transactionName), factory, allCurrentFactories);
         ServiceReferenceWritableRegistry writableRegistry = ServiceReferenceRegistryImpl.createSRWritableRegistry(
                 readableSRRegistry, txLookupRegistry, allCurrentFactories);
 
@@ -550,6 +548,12 @@ public class ConfigRegistryImpl implements AutoCloseable, ConfigRegistryImplMXBe
     public synchronized String getServiceInterfaceName(String namespace, String localName) {
         return readableSRRegistry.getServiceInterfaceName(namespace, localName);
     }
+
+    @Override
+    public Set<String> getAvailableModuleFactoryQNames() {
+        return ModuleQNameUtil.getQNames(resolver.getAllFactories());
+    }
+
 }
 
 /**
@@ -607,6 +611,8 @@ class ConfigHolder {
         Collections.sort(result);
         return result;
     }
+
+
 }
 
 /**
index 36485b1..17ce078 100644 (file)
@@ -33,13 +33,13 @@ import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import static java.lang.String.format;
@@ -576,4 +576,9 @@ class ConfigTransactionControllerImpl implements
         return txLookupRegistry.getTransactionIdentifier();
     }
 
+    @Override
+    public Set<String> getAvailableModuleFactoryQNames() {
+        return txLookupRegistry.getAvailableModuleFactoryQNames();
+    }
+
 }
index 5d1f0b3..12db6c8 100644 (file)
@@ -12,11 +12,16 @@ import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
 import org.opendaylight.controller.config.manager.impl.jmx.TransactionJMXRegistrator;
 import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator;
 import org.opendaylight.controller.config.manager.impl.util.LookupBeansUtil;
+import org.opendaylight.controller.config.manager.impl.util.ModuleQNameUtil;
+import org.opendaylight.controller.config.spi.ModuleFactory;
+import org.osgi.framework.BundleContext;
 
 import javax.management.InstanceAlreadyExistsException;
 import javax.management.InstanceNotFoundException;
 import javax.management.ObjectName;
 import java.io.Closeable;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
 /**
@@ -27,12 +32,14 @@ class ConfigTransactionLookupRegistry  implements LookupRegistry, Closeable {
     private final TransactionJMXRegistrator transactionJMXRegistrator;
     private final TransactionIdentifier transactionIdentifier;
     private final TransactionModuleJMXRegistrator txModuleJMXRegistrator;
+    private final Map<String, Map.Entry<ModuleFactory, BundleContext>> allCurrentFactories;
 
     ConfigTransactionLookupRegistry(TransactionIdentifier transactionIdentifier,
-                                    TransactionJMXRegistratorFactory factory) {
+                                    TransactionJMXRegistratorFactory factory, Map<String, Entry<ModuleFactory, BundleContext>> allCurrentFactories) {
         this.transactionIdentifier = transactionIdentifier;
         this.transactionJMXRegistrator = factory.create();
         this.txModuleJMXRegistrator = transactionJMXRegistrator.createTransactionModuleJMXRegistrator();
+        this.allCurrentFactories = allCurrentFactories;
     }
 
     private void checkTransactionName(ObjectName objectName) {
@@ -104,6 +111,12 @@ class ConfigTransactionLookupRegistry  implements LookupRegistry, Closeable {
     public void registerMBean(ConfigTransactionControllerInternal transactionController, ObjectName controllerObjectName) throws InstanceAlreadyExistsException {
         transactionJMXRegistrator.registerMBean(transactionController, controllerObjectName);
     }
+
+    @Override
+    public Set<String> getAvailableModuleFactoryQNames() {
+        return ModuleQNameUtil.getQNames(allCurrentFactories);
+    }
+
 }
 
 interface TransactionJMXRegistratorFactory {
index 2fd1ca6..7fedcdf 100644 (file)
@@ -75,6 +75,11 @@ public class ServiceReferenceRegistryImpl implements ServiceReferenceReadableReg
             public void checkConfigBeanExists(ObjectName objectName) throws InstanceNotFoundException {
                 throw new InstanceNotFoundException("Cannot find " + objectName);
             }
+
+            @Override
+            public Set<String> getAvailableModuleFactoryQNames() {
+                throw new UnsupportedOperationException();
+            }
         };
         return new ServiceReferenceRegistryImpl(Collections.<String, ModuleFactory>emptyMap(), lookupRegistry,
                 Collections.<String /* qName */, Map<String /* refName */, ModuleIdentifier>>emptyMap());
index f82a729..16f7cf0 100644 (file)
@@ -13,6 +13,7 @@ import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.List;
 import java.util.Map;
@@ -76,4 +77,7 @@ public class HierarchicalConfigMBeanFactoriesHolder {
         return moduleFactories;
     }
 
+    public Map<String, Entry<ModuleFactory, BundleContext>> getModuleNamesToConfigBeanFactories() {
+        return moduleNamesToConfigBeanFactories;
+    }
 }
index ab81143..1ee6cca 100644 (file)
@@ -36,8 +36,7 @@ public class ConfigManagerActivator implements BundleActivator {
                 new BundleContextBackedModuleFactoriesResolver(context);
         MBeanServer configMBeanServer = ManagementFactory.getPlatformMBeanServer();
         configRegistry = new ConfigRegistryImpl(
-                bundleContextBackedModuleFactoriesResolver, context,
-                configMBeanServer);
+                bundleContextBackedModuleFactoriesResolver, configMBeanServer);
 
         // register config registry to OSGi
         configRegistryServiceRegistration = context.registerService(ConfigRegistryImpl.class, configRegistry, null);
diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/ModuleQNameUtil.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/ModuleQNameUtil.java
new file mode 100644 (file)
index 0000000..e843377
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.manager.impl.util;
+
+import org.opendaylight.controller.config.spi.ModuleFactory;
+import org.opendaylight.yangtools.yang.binding.annotations.ModuleQName;
+import org.osgi.framework.BundleContext;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+public class ModuleQNameUtil {
+
+    public static Set<String> getQNames(Map<String, Entry<ModuleFactory, BundleContext>> resolved) {
+        Set<String> result = new HashSet<>();
+        for (Entry<ModuleFactory, BundleContext> entry : resolved.values()) {
+            Class<?> inspected = entry.getKey().getClass();
+            if (inspected.isInterface()) {
+                throw new IllegalArgumentException("Unexpected interface " + inspected);
+            }
+            ModuleQName annotation = null;
+            while(annotation == null && inspected != null) {
+                annotation = inspected.getAnnotation(ModuleQName.class);
+                inspected = inspected.getSuperclass();
+            }
+            if (annotation != null) {
+                // FIXME
+                String qName = "(" + annotation.namespace() + "?revision=" + annotation.revision() + ")" + annotation.name();
+                result.add(qName);
+            }
+        }
+        return result;
+    }
+
+}
index ccb67d3..e6b07ba 100644 (file)
@@ -40,7 +40,7 @@ public class ConfigRegistryImplTest extends
                     factory, factory);
 
             configRegistry = new ConfigRegistryImpl(resolver,
-                    context, ManagementFactory.getPlatformMBeanServer());
+                    ManagementFactory.getPlatformMBeanServer());
 
             configRegistry.beginConfig();
             fail();
index 5ed56bd..a7e3fa6 100644 (file)
@@ -70,7 +70,7 @@ public abstract class AbstractConfigTest extends
         internalJmxRegistrator = new InternalJMXRegistrator(platformMBeanServer);
         baseJmxRegistrator = new BaseJMXRegistrator(internalJmxRegistrator);
 
-        configRegistry = new ConfigRegistryImpl(resolver, mockedContext,
+        configRegistry = new ConfigRegistryImpl(resolver,
                 platformMBeanServer, baseJmxRegistrator);
         try {
             configRegistryJMXRegistrator.registerToJMX(configRegistry);
index 6dddc62..a522356 100644 (file)
@@ -66,7 +66,7 @@ public class ConfigRegistryImplLookupTest extends
 
     @Before
     public void setUp() throws Exception {
-        configRegistryImpl = new ConfigRegistryImpl(null, null,
+        configRegistryImpl = new ConfigRegistryImpl(null,
                 ManagementFactory.getPlatformMBeanServer());
         Field field = configRegistryImpl.getClass().getDeclaredField(
                 "baseJMXRegistrator");
index 43c75ef..50f5742 100644 (file)
@@ -68,7 +68,7 @@ public class ConfigTransactionControllerImplTest extends
             public TransactionJMXRegistrator create() {
                 return baseJMXRegistrator.createTransactionJMXRegistrator(transactionName123);
             }
-        });
+        }, currentlyRegisteredFactories);
 
         ServiceReferenceWritableRegistry writableRegistry = ServiceReferenceRegistryImpl.createSRWritableRegistry(
                 ServiceReferenceRegistryImpl.createInitialSRLookupRegistry(), txLookupRegistry, currentlyRegisteredFactories);
diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/AbstractTestingFixedThreadPoolModuleFactory.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/threadpool/AbstractTestingFixedThreadPoolModuleFactory.java
new file mode 100644 (file)
index 0000000..0286400
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.manager.testingservices.threadpool;
+
+import org.opendaylight.yangtools.yang.binding.annotations.ModuleQName;
+
+@ModuleQName(namespace = "namespace", revision = "revision", name = "name")
+public abstract class AbstractTestingFixedThreadPoolModuleFactory {
+}
index b749ea7..bec2868 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
-public class TestingFixedThreadPoolModuleFactory implements ModuleFactory {
+public class TestingFixedThreadPoolModuleFactory extends AbstractTestingFixedThreadPoolModuleFactory implements ModuleFactory {
     public static final String NAME = "fixed";
 
     private static Set<Class<? extends AbstractServiceInterface>> ifc = Collections.unmodifiableSet(Sets.newHashSet(
index 13bb840..441de36 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.controller.config.manager.testingservices.threadpool.test;
 
+import com.google.common.collect.Sets;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -34,6 +35,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ThreadPoolExecutor;
 
 import static org.junit.Assert.assertEquals;
@@ -384,4 +386,11 @@ public class SimpleConfigurationTest extends AbstractConfigTest {
     }
 
 
+    @Test
+    public void testQNames() {
+        Set<String> availableModuleFactoryQNames = configRegistryClient.getAvailableModuleFactoryQNames();
+        String expected = "(namespace?revision=revision)name";
+        assertEquals(Sets.newHashSet(expected), availableModuleFactoryQNames);
+    }
+
 }
index 39595ed..a123eb9 100644 (file)
@@ -139,7 +139,7 @@ class MyLineProcessor implements com.google.common.io.LineProcessor<String> {
     }
 
     private void checkFileConsistency(){
-        checkState(inCapabilities, "File {} is missing delimiters in this order: {}", fileNameForReporting,
+        checkState(inCapabilities, "File %s is missing delimiters in this order: %s", fileNameForReporting,
                 Arrays.asList(DirectoryPersister.MODULES_START,
                         DirectoryPersister.SERVICES_START,
                         DirectoryPersister.CAPABILITIES_START));
diff --git a/opendaylight/config/config-persister-directory-xml-adapter/pom.xml b/opendaylight/config/config-persister-directory-xml-adapter/pom.xml
new file mode 100644 (file)
index 0000000..b2ea632
--- /dev/null
@@ -0,0 +1,115 @@
+<?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>
+        <artifactId>config-subsystem</artifactId>
+        <groupId>org.opendaylight.controller</groupId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+    <artifactId>config-persister-directory-xml-adapter</artifactId>
+    <name>${project.artifactId}</name>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <!-- compile dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>config-persister-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>config-persister-file-xml-adapter</artifactId>
+            <version>${config.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.persistence</groupId>
+            <artifactId>org.eclipse.persistence.moxy</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.persistence</groupId>
+            <artifactId>org.eclipse.persistence.core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
+
+        <!-- test dependencies -->
+        <dependency>
+            <groupId>org.opendaylight.bgpcep</groupId>
+            <artifactId>mockito-configuration</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- workaround for creating version according to OSGi specification (major.minor.micro[.qualifier] -->
+            <plugin>
+                <groupId>org.codehaus.groovy.maven</groupId>
+                <artifactId>gmaven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>execute</goal>
+                        </goals>
+                        <configuration>
+                            <source>
+                                System.setProperty("osgiversion", "${project.version}".replace('-', '.'))
+                            </source>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Fragment-Host>${project.groupId}.config-persister-impl;bundle-version=${osgiversion}
+                        </Fragment-Host>
+                        <Provide-Capability>org.opendaylight.controller.config.persister.storage.adapter
+                        </Provide-Capability>
+                        <Import-Package>
+                            com.google.common.base,
+                            com.google.common.io,
+                            org.apache.commons.io,
+                            org.opendaylight.controller.config.persist.api,
+                            org.slf4j,
+                            com.google.common.collect,
+                            javax.xml.bind,
+                            javax.xml.bind.annotation,
+                            javax.xml.transform,
+                            javax.xml.transform.stream,
+                            org.eclipse.persistence.jaxb,
+                            org.apache.commons.lang3
+                        </Import-Package>
+                        <Private-Package>
+                            org.opendaylight.controller.config.persist.storage.file.xml.model,
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryPersister.java b/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryPersister.java
new file mode 100644 (file)
index 0000000..f6f6de9
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.persist.storage.directory.xml;
+
+import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+import org.opendaylight.controller.config.persist.api.Persister;
+import org.opendaylight.controller.config.persist.storage.file.xml.model.ConfigSnapshot;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.SortedSet;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+public class XmlDirectoryPersister implements Persister {
+    private static final Logger logger = LoggerFactory.getLogger(XmlDirectoryPersister.class);
+
+    private final File storage;
+
+    public XmlDirectoryPersister(File storage) {
+        checkArgument(storage.exists() && storage.isDirectory(), "Storage directory does not exist: " + storage);
+        this.storage = storage;
+    }
+
+    @Override
+    public void persistConfig(ConfigSnapshotHolder holder) throws IOException {
+        throw new UnsupportedOperationException("This adapter is read only. Please set readonly=true on " + getClass());
+    }
+
+    @Override
+    public List<ConfigSnapshotHolder> loadLastConfigs() throws IOException {
+        File[] filesArray = storage.listFiles();
+        if (filesArray == null || filesArray.length == 0) {
+            return Collections.emptyList();
+        }
+        List<File> sortedFiles = new ArrayList<>(Arrays.asList(filesArray));
+        Collections.sort(sortedFiles);
+        // combine all found files
+        logger.debug("Reading files in following order: {}", sortedFiles);
+
+        List<ConfigSnapshotHolder> result = new ArrayList<>();
+        for (File file : sortedFiles) {
+            logger.trace("Adding file '{}' to combined result", file);
+            ConfigSnapshotHolder h = fromXmlSnapshot(file);
+            result.add(h);
+        }
+        return result;
+    }
+
+    private ConfigSnapshotHolder fromXmlSnapshot(File file) {
+        try {
+            JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class);
+            Unmarshaller um = jaxbContext.createUnmarshaller();
+
+            return asHolder((ConfigSnapshot) um.unmarshal(file));
+        } catch (JAXBException e) {
+            logger.warn("Unable to restore configuration snapshot from {}", file, e);
+            throw new IllegalStateException("Unable to restore configuration snapshot from " + file, e);
+        }
+    }
+
+    private ConfigSnapshotHolder asHolder(final ConfigSnapshot unmarshalled) {
+        return new ConfigSnapshotHolder() {
+            @Override
+            public String getConfigSnapshot() {
+                return unmarshalled.getConfigSnapshot();
+            }
+
+            @Override
+            public SortedSet<String> getCapabilities() {
+                return unmarshalled.getCapabilities();
+            }
+
+            @Override
+            public String toString() {
+                return unmarshalled.toString();
+            }
+        };
+    }
+
+
+    @Override
+    public void close() {
+
+    }
+
+    @Override
+    public String toString() {
+        final StringBuffer sb = new StringBuffer("XmlDirectoryPersister{");
+        sb.append("storage=").append(storage);
+        sb.append('}');
+        return sb.toString();
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryStorageAdapter.java b/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryStorageAdapter.java
new file mode 100644 (file)
index 0000000..ab6fb15
--- /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.config.persist.storage.directory.xml;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.config.persist.api.Persister;
+import org.opendaylight.controller.config.persist.api.PropertiesProvider;
+import org.opendaylight.controller.config.persist.api.StorageAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+
+/**
+ * StorageAdapter that retrieves initial configuration from a directory. If multiple files are present, snapshot and
+ * required capabilities will be merged together. Writing to this persister is not supported.
+ */
+public class XmlDirectoryStorageAdapter implements StorageAdapter {
+    private static final Logger logger = LoggerFactory.getLogger(XmlDirectoryStorageAdapter.class);
+
+    public static final String DIRECTORY_STORAGE_PROP = "directoryStorage";
+
+
+    @Override
+    public Persister instantiate(PropertiesProvider propertiesProvider) {
+        String fileStorageProperty = propertiesProvider.getProperty(DIRECTORY_STORAGE_PROP);
+        Preconditions.checkNotNull(fileStorageProperty, "Unable to find " + propertiesProvider.getFullKeyForReporting(DIRECTORY_STORAGE_PROP));
+        File storage  = new File(fileStorageProperty);
+        logger.debug("Using {}", storage);
+        return new XmlDirectoryPersister(storage);
+    }
+
+}
diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/xml/DirectoryStorageAdapterTest.java b/opendaylight/config/config-persister-directory-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/xml/DirectoryStorageAdapterTest.java
new file mode 100644 (file)
index 0000000..73061f8
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.config.persist.storage.directory.xml;
+
+import org.junit.Test;
+import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.List;
+import java.util.SortedSet;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class DirectoryStorageAdapterTest {
+    XmlDirectoryPersister tested;
+
+    @Test
+    public void testEmptyDirectory() throws Exception {
+        File folder = new File("target/emptyFolder");
+        folder.mkdir();
+        tested = new XmlDirectoryPersister((folder));
+        assertEquals(Collections.<ConfigSnapshotHolder>emptyList(), tested.loadLastConfigs());
+
+        try {
+            tested.persistConfig(new ConfigSnapshotHolder() {
+                @Override
+                public String getConfigSnapshot() {
+                    throw new RuntimeException();
+                }
+
+                @Override
+                public SortedSet<String> getCapabilities() {
+                    throw new RuntimeException();
+                }
+            });
+            fail();
+        } catch (UnsupportedOperationException e) {
+
+        }
+    }
+
+    private File getFolder(String folderName) {
+        File result = new File(("src/test/resources/" +
+                folderName).replace("/", File.separator));
+        assertTrue(result + " is not a directory", result.isDirectory());
+        return result;
+    }
+
+    @Test
+    public void testOneFile() throws Exception {
+        File folder = getFolder("oneFile");
+        tested = new XmlDirectoryPersister((folder));
+        List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
+        assertEquals(1, results.size());
+        ConfigSnapshotHolder result = results.get(0);
+        assertResult(result, "<config>1</config>", "cap1&rev", "cap2", "capa a");
+    }
+
+    private void assertResult(ConfigSnapshotHolder result, String s, String... caps) {
+        assertEquals(s, result.getConfigSnapshot().replaceAll("\\s", ""));
+        int i = 0;
+        for (String capFromSnapshot : result.getCapabilities()) {
+            assertEquals(capFromSnapshot, caps[i++]);
+        }
+    }
+
+    @Test
+    public void testTwoFiles() throws Exception {
+        File folder = getFolder("twoFiles");
+        tested = new XmlDirectoryPersister((folder));
+        List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
+        assertEquals(2, results.size());
+
+        assertResult(results.get(0), "<config>1</config>", "cap1-a", "cap2-a", "capa a-a");
+        assertResult(results.get(1), "<config>2</config>", "cap1-b", "cap2-b", "capa a-b");
+
+    }
+
+}
diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/oneFile/controller.config.xml b/opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/oneFile/controller.config.xml
new file mode 100644 (file)
index 0000000..aa8b14c
--- /dev/null
@@ -0,0 +1,10 @@
+<snapshot>
+    <required-capabilities>
+        <capability>cap1&amp;rev</capability>
+        <capability>cap2</capability>
+        <capability>capa a</capability>
+    </required-capabilities>
+    <configuration>
+        <config>1</config>
+    </configuration>
+</snapshot>
\ No newline at end of file
diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/twoFiles/controller.config1.xml b/opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/twoFiles/controller.config1.xml
new file mode 100644 (file)
index 0000000..28f112e
--- /dev/null
@@ -0,0 +1,10 @@
+<snapshot>
+    <required-capabilities>
+        <capability>cap1-a</capability>
+        <capability>cap2-a</capability>
+        <capability>capa a-a</capability>
+    </required-capabilities>
+    <configuration>
+        <config>1</config>
+    </configuration>
+</snapshot>
\ No newline at end of file
diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/twoFiles/controller.config2.xml b/opendaylight/config/config-persister-directory-xml-adapter/src/test/resources/twoFiles/controller.config2.xml
new file mode 100644 (file)
index 0000000..8fed29d
--- /dev/null
@@ -0,0 +1,10 @@
+<snapshot>
+    <required-capabilities>
+        <capability>cap1-b</capability>
+        <capability>cap2-b</capability>
+        <capability>capa a-b</capability>
+    </required-capabilities>
+    <configuration>
+        <config>2</config>
+    </configuration>
+</snapshot>
\ No newline at end of file
diff --git a/opendaylight/config/config-persister-file-xml-adapter/pom.xml b/opendaylight/config/config-persister-file-xml-adapter/pom.xml
new file mode 100644 (file)
index 0000000..abbec38
--- /dev/null
@@ -0,0 +1,87 @@
+<?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>
+        <artifactId>config-subsystem</artifactId>
+        <groupId>org.opendaylight.controller</groupId>
+        <version>0.2.3-SNAPSHOT</version>
+        <relativePath>..</relativePath>
+    </parent>
+    <artifactId>config-persister-file-xml-adapter</artifactId>
+    <name>${project.artifactId}</name>
+    <packaging>bundle</packaging>
+
+    <dependencies>
+        <!-- compile dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>config-persister-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.eclipse.persistence</groupId>
+            <artifactId>org.eclipse.persistence.moxy</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.persistence</groupId>
+            <artifactId>org.eclipse.persistence.core</artifactId>
+        </dependency>
+
+        <!-- test dependencies -->
+        <dependency>
+            <groupId>org.opendaylight.bgpcep</groupId>
+            <artifactId>mockito-configuration</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- workaround for creating version according to OSGi specification (major.minor.micro[.qualifier] -->
+            <plugin>
+                <groupId>org.codehaus.groovy.maven</groupId>
+                <artifactId>gmaven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>execute</goal>
+                        </goals>
+                        <configuration>
+                            <source>
+                                System.setProperty("osgiversion", "${project.version}".replace('-', '.'))
+                            </source>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Fragment-Host>${project.groupId}.config-persister-impl;bundle-version=${osgiversion}
+                        </Fragment-Host>
+                        <Provide-Capability>org.opendaylight.controller.config.persister.storage.adapter
+                        </Provide-Capability>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/XmlFileStorageAdapter.java
new file mode 100644 (file)
index 0000000..e75c62b
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.config.persist.storage.file.xml;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+import org.opendaylight.controller.config.persist.api.Persister;
+import org.opendaylight.controller.config.persist.api.PropertiesProvider;
+import org.opendaylight.controller.config.persist.api.StorageAdapter;
+import org.opendaylight.controller.config.persist.storage.file.xml.model.Config;
+import org.opendaylight.controller.config.persist.storage.file.xml.model.ConfigSnapshot;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import java.util.SortedSet;
+
+/**
+ * StorageAdapter that stores configuration in an xml file.
+ */
+public class XmlFileStorageAdapter implements StorageAdapter, Persister {
+    private static final Logger logger = LoggerFactory.getLogger(XmlFileStorageAdapter.class);
+
+    public static final String FILE_STORAGE_PROP = "fileStorage";
+    public static final String NUMBER_OF_BACKUPS = "numberOfBackups";
+
+    private static Integer numberOfStoredBackups;
+    private File storage;
+
+    @Override
+    public Persister instantiate(PropertiesProvider propertiesProvider) {
+        File storage = extractStorageFileFromProperties(propertiesProvider);
+        logger.debug("Using file {}", storage.getAbsolutePath());
+        // Create file if it does not exist
+        File parentFile = storage.getAbsoluteFile().getParentFile();
+        if (parentFile.exists() == false) {
+            logger.debug("Creating parent folders {}", parentFile);
+            parentFile.mkdirs();
+        }
+        if (storage.exists() == false) {
+            logger.debug("Storage file does not exist, creating empty file");
+            try {
+                boolean result = storage.createNewFile();
+                if (result == false)
+                    throw new RuntimeException("Unable to create storage file " + storage);
+            } catch (IOException e) {
+                throw new RuntimeException("Unable to create storage file " + storage, e);
+            }
+        }
+        if (numberOfStoredBackups == 0) {
+            throw new RuntimeException(NUMBER_OF_BACKUPS
+                    + " property should be either set to positive value, or ommited. Can not be set to 0.");
+        }
+        setFileStorage(storage);
+        return this;
+    }
+
+    @VisibleForTesting
+    public void setFileStorage(File storage) {
+        this.storage = storage;
+    }
+
+    @VisibleForTesting
+    public void setNumberOfBackups(Integer numberOfBackups) {
+        numberOfStoredBackups = numberOfBackups;
+    }
+
+    private static File extractStorageFileFromProperties(PropertiesProvider propertiesProvider) {
+        String fileStorageProperty = propertiesProvider.getProperty(FILE_STORAGE_PROP);
+        Preconditions.checkNotNull(fileStorageProperty, "Unable to find " + propertiesProvider.getFullKeyForReporting(FILE_STORAGE_PROP));
+        File result = new File(fileStorageProperty);
+        String numberOfBackupsAsString = propertiesProvider.getProperty(NUMBER_OF_BACKUPS);
+        if (numberOfBackupsAsString != null) {
+            numberOfStoredBackups = Integer.valueOf(numberOfBackupsAsString);
+        } else {
+            numberOfStoredBackups = Integer.MAX_VALUE;
+        }
+        logger.trace("Property {} set to {}", NUMBER_OF_BACKUPS, numberOfStoredBackups);
+        return result;
+    }
+
+    @Override
+    public void persistConfig(ConfigSnapshotHolder holder) throws IOException {
+        Preconditions.checkNotNull(storage, "Storage file is null");
+
+        Config cfg = Config.fromXml(storage);
+        cfg.addConfigSnapshot(ConfigSnapshot.fromConfigSnapshot(holder), numberOfStoredBackups);
+        cfg.toXml(storage);
+    }
+
+    @Override
+    public List<ConfigSnapshotHolder> loadLastConfigs() throws IOException {
+        Preconditions.checkNotNull(storage, "Storage file is null");
+
+        if (!storage.exists()) {
+            return Collections.emptyList();
+        }
+
+        Optional<ConfigSnapshot> lastSnapshot = Config.fromXml(storage).getLastSnapshot();
+
+        if (lastSnapshot.isPresent())
+            return Lists.newArrayList(toConfigSnapshot(lastSnapshot.get()));
+        else
+            return Collections.emptyList();
+    }
+
+
+    public ConfigSnapshotHolder toConfigSnapshot(final ConfigSnapshot configSnapshot) {
+        return new ConfigSnapshotHolder() {
+            @Override
+            public String getConfigSnapshot() {
+                return configSnapshot.getConfigSnapshot();
+            }
+
+            @Override
+            public SortedSet<String> getCapabilities() {
+                return configSnapshot.getCapabilities();
+            }
+
+            @Override
+            public String toString() {
+                return configSnapshot.toString();
+            }
+        };
+    }
+
+    @Override
+    public void close() {
+
+    }
+
+    @Override
+    public String toString() {
+        return "XmlFileStorageAdapter [storage=" + storage + "]";
+    }
+
+}
diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/CapabilityHandler.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/CapabilityHandler.java
new file mode 100644 (file)
index 0000000..d384df6
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.persist.storage.file.xml.model;
+
+import javax.xml.bind.ValidationEventHandler;
+import javax.xml.bind.annotation.DomHandler;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+class CapabilityHandler implements DomHandler<String, StreamResult> {
+
+    private static final String START_TAG = "<capability>";
+    private static final String END_TAG = "</capability>";
+
+    private StringWriter xmlWriter = new StringWriter();
+
+    public StreamResult createUnmarshaller(ValidationEventHandler errorHandler) {
+        xmlWriter.getBuffer().setLength(0);
+        return new StreamResult(xmlWriter);
+    }
+
+    public String getElement(StreamResult rt) {
+        String xml = rt.getWriter().toString();
+        int beginIndex = xml.indexOf(START_TAG) + START_TAG.length();
+        int endIndex = xml.indexOf(END_TAG);
+        return xml.substring(beginIndex, endIndex);
+    }
+
+    public Source marshal(String n, ValidationEventHandler errorHandler) {
+        try {
+            String xml = START_TAG + n.trim() + END_TAG;
+            StringReader xmlReader = new StringReader(xml);
+            return new StreamSource(xmlReader);
+        } catch(Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}
diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java
new file mode 100644 (file)
index 0000000..fb84651
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.persist.storage.file.xml.model;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.io.Files;
+import org.apache.commons.lang3.StringUtils;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+@XmlRootElement(name = "persisted-snapshots")
+public final class Config {
+
+    private List<ConfigSnapshot> snapshots;
+
+    Config(List<ConfigSnapshot> snapshots) {
+        this.snapshots = snapshots;
+    }
+
+    public Config() {
+        this.snapshots = Lists.newArrayList();
+    }
+
+    @XmlElement(name = "snapshot")
+    @XmlElementWrapper(name = "snapshots")
+    public List<ConfigSnapshot> getSnapshots() {
+        return snapshots;
+    }
+
+    public void setSnapshots(List<ConfigSnapshot> snapshots) {
+        this.snapshots = snapshots;
+    }
+
+    public void toXml(File to) {
+        try {
+
+            // TODO Moxy has to be used instead of default jaxb impl due to a bug
+            // default implementation has a bug that prevents from serializing xml in a string
+            JAXBContext jaxbContext = org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(new Class[]{Config.class}, null);
+
+            Marshaller marshaller = jaxbContext.createMarshaller();
+
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+
+            marshaller.marshal(this, to);
+        } catch (JAXBException e) {
+            throw new PersistException("Unable to persist configuration", e);
+        }
+    }
+
+    public static Config fromXml(File from) {
+        if(isEmpty(from))
+            return new Config();
+
+        try {
+            JAXBContext jaxbContext = JAXBContext.newInstance(Config.class);
+            Unmarshaller um = jaxbContext.createUnmarshaller();
+
+            return (Config) um.unmarshal(from);
+        } catch (JAXBException e) {
+            throw new PersistException("Unable to restore configuration", e);
+        }
+    }
+
+    private static boolean isEmpty(File from) {
+        return from.length() == 0 || isBlank(from);
+    }
+
+    private static boolean isBlank(File from) {
+        try {
+            return StringUtils.isBlank(Files.toString(from, Charsets.UTF_8));
+        } catch (IOException e) {
+            throw new IllegalStateException("Unexpected error reading file" + from, e);
+        }
+    }
+
+    public Optional<ConfigSnapshot> getLastSnapshot() {
+        ConfigSnapshot last = Iterables.getLast(snapshots, null);
+        return last == null ? Optional.<ConfigSnapshot>absent() : Optional.of(last);
+    }
+
+    public void addConfigSnapshot(ConfigSnapshot snap, int numberOfStoredBackups) {
+        if(shouldReplaceLast(numberOfStoredBackups) && snapshots.isEmpty() == false) {
+            snapshots.remove(0);
+        }
+        snapshots.add(snap);
+    }
+
+    private boolean shouldReplaceLast(int numberOfStoredBackups) {
+        return numberOfStoredBackups == snapshots.size();
+    }
+}
diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/ConfigSnapshot.java
new file mode 100644 (file)
index 0000000..4197600
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.persist.storage.file.xml.model;
+
+import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+
+import javax.xml.bind.annotation.XmlAnyElement;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.SortedSet;
+
+@XmlRootElement(name = "snapshot")
+public class ConfigSnapshot {
+
+    private String configSnapshot;
+    private SortedSet<String> capabilities;
+
+    ConfigSnapshot(String configXml, SortedSet<String> capabilities) {
+        this.configSnapshot = configXml;
+        this.capabilities = capabilities;
+    }
+
+    public ConfigSnapshot() {
+    }
+
+    public static ConfigSnapshot fromConfigSnapshot(ConfigSnapshotHolder cfg) {
+        return new ConfigSnapshot(cfg.getConfigSnapshot(), cfg.getCapabilities());
+    }
+
+    @XmlAnyElement(SnapshotHandler.class)
+    public String getConfigSnapshot() {
+        return configSnapshot;
+    }
+
+    public void setConfigSnapshot(String configSnapshot) {
+        this.configSnapshot = configSnapshot;
+    }
+
+    @XmlElement(name = "capability")
+    @XmlElementWrapper(name = "required-capabilities")
+    public SortedSet<String> getCapabilities() {
+        return capabilities;
+    }
+
+    public void setCapabilities(SortedSet<String> capabilities) {
+        this.capabilities = capabilities;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuffer sb = new StringBuffer("ConfigSnapshot{");
+        sb.append("configSnapshot='").append(configSnapshot).append('\'');
+        sb.append(", capabilities=").append(capabilities);
+        sb.append('}');
+        return sb.toString();
+    }
+}
diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/PersistException.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/PersistException.java
new file mode 100644 (file)
index 0000000..29d6232
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.persist.storage.file.xml.model;
+
+final class PersistException extends RuntimeException {
+
+    public PersistException(String s, Exception e) {
+        super(s, e);
+    }
+}
diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/SnapshotHandler.java
new file mode 100644 (file)
index 0000000..dd39410
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.persist.storage.file.xml.model;
+
+import javax.xml.bind.ValidationEventHandler;
+import javax.xml.bind.annotation.DomHandler;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+class SnapshotHandler implements DomHandler<String, StreamResult> {
+
+    private static final String START_TAG = "<configuration>";
+    private static final String END_TAG = "</configuration>";
+
+    private StringWriter xmlWriter = new StringWriter();
+
+    public StreamResult createUnmarshaller(ValidationEventHandler errorHandler) {
+        xmlWriter.getBuffer().setLength(0);
+        return new StreamResult(xmlWriter);
+    }
+
+    public String getElement(StreamResult rt) {
+        String xml = rt.getWriter().toString();
+        int beginIndex = xml.indexOf(START_TAG) + START_TAG.length();
+        int endIndex = xml.indexOf(END_TAG);
+        return xml.substring(beginIndex, endIndex);
+    }
+
+    public Source marshal(String n, ValidationEventHandler errorHandler) {
+        try {
+            String xml = START_TAG + n.trim() + END_TAG;
+            StringReader xmlReader = new StringReader(xml);
+            return new StreamSource(xmlReader);
+        } catch(Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}
diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java b/opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java
new file mode 100644 (file)
index 0000000..d6bbeb3
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.config.persist.storage.file.xml;
+
+import com.google.common.base.Charsets;
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import static junit.framework.Assert.assertFalse;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+public class FileStorageAdapterTest {
+
+    private static int i;
+    private File file;
+
+    @Before
+    public void setUp() throws Exception {
+        file = Files.createTempFile("testFilePersist", ".txt").toFile();
+        if (!file.exists())
+            return;
+        com.google.common.io.Files.write("", file, Charsets.UTF_8);
+        i = 1;
+    }
+
+    @Test
+    public void testFileAdapter() throws Exception {
+        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
+        storage.setFileStorage(file);
+        storage.setNumberOfBackups(Integer.MAX_VALUE);
+        final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {
+            @Override
+            public String getConfigSnapshot() {
+                return createConfig();
+            }
+
+            @Override
+            public SortedSet<String> getCapabilities() {
+                return createCaps();
+            }
+        };
+        storage.persistConfig(holder);
+
+        storage.persistConfig(holder);
+
+        assertEquals(27, com.google.common.io.Files.readLines(file, Charsets.UTF_8).size());
+        List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
+        assertEquals(1, lastConf.size());
+        ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
+        assertEquals("<config>2</config>",
+                configSnapshotHolder.getConfigSnapshot().replaceAll("\\s", ""));
+        assertEquals(createCaps(), configSnapshotHolder.getCapabilities());
+
+        storage = new XmlFileStorageAdapter();
+        storage.setFileStorage(file);
+        storage.setNumberOfBackups(Integer.MAX_VALUE);
+
+        List<ConfigSnapshotHolder> last = storage.loadLastConfigs();
+        Assert.assertEquals(createCaps(), last.get(0).getCapabilities());
+    }
+
+    private SortedSet<String> createCaps() {
+        SortedSet<String> caps = new TreeSet<>();
+
+        caps.add("cap1" + i);
+        caps.add("cap2" + i);
+        caps.add("urn:opendaylight:params:xml:ns:yang:controller:netty?module=netty&revision=2013-11-19" + i);
+        caps.add("capaaaa as dasfasdf s2" + i);
+        return caps;
+    }
+
+    @Test
+    public void testFileAdapterOneBackup() throws Exception {
+        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
+        storage.setFileStorage(file);
+        storage.setNumberOfBackups(1);
+        final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {
+            @Override
+            public String getConfigSnapshot() {
+                return createConfig();
+            }
+
+            @Override
+            public SortedSet<String> getCapabilities() {
+                return createCaps();
+            }
+        };
+        storage.persistConfig(holder);
+
+        storage.persistConfig(holder);
+
+        assertEquals(16, com.google.common.io.Files.readLines(file, Charsets.UTF_8).size());
+
+        List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
+        assertEquals(1, lastConf.size());
+        ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
+        assertEquals("<config>2</config>",
+                configSnapshotHolder.getConfigSnapshot().replaceAll("\\s", ""));
+    }
+
+    @Test
+    public void testFileAdapterOnlyTwoBackups() throws Exception {
+        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
+        storage.setFileStorage(file);
+        storage.setNumberOfBackups(2);
+        final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {
+            @Override
+            public String getConfigSnapshot() {
+                return createConfig();
+            }
+
+            @Override
+            public SortedSet<String> getCapabilities() {
+                return createCaps();
+            }
+        };
+        storage.persistConfig(holder);
+
+        storage.persistConfig(holder);
+        storage.persistConfig(holder);
+
+        List<String> readLines = com.google.common.io.Files.readLines(file, Charsets.UTF_8);
+        assertEquals(27, readLines.size());
+
+        List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
+        assertEquals(1, lastConf.size());
+        ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
+        assertEquals("<config>3</config>",
+                configSnapshotHolder.getConfigSnapshot().replaceAll("\\s", ""));
+        assertFalse(readLines.contains(holder.getConfigSnapshot()));
+    }
+
+    @Test
+    public void testNoLastConfig() throws Exception {
+        File file = Files.createTempFile("testFilePersist", ".txt").toFile();
+        if (!file.exists())
+            return;
+        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
+        storage.setFileStorage(file);
+
+        List<ConfigSnapshotHolder> elementOptional = storage.loadLastConfigs();
+        assertThat(elementOptional.size(), is(0));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testNoProperties() throws Exception {
+        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
+        storage.loadLastConfigs();
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testNoProperties2() throws Exception {
+        XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
+        storage.persistConfig(new ConfigSnapshotHolder() {
+            @Override
+            public String getConfigSnapshot() {
+                return Mockito.mock(String.class);
+            }
+
+            @Override
+            public SortedSet<String> getCapabilities() {
+                return new TreeSet<>();
+            }
+        } );
+    }
+
+    static String createConfig() {
+        return "<config>" + i++ + "</config>";
+    }
+
+}
index 4ecc7c3..8badb75 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.controller.config.util;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.config.api.ValidationException;
+import org.opendaylight.controller.config.api.jmx.CommitStatus;
+import org.opendaylight.controller.config.api.jmx.ConfigRegistryMXBean;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
 
 import javax.management.AttributeNotFoundException;
 import javax.management.InstanceNotFoundException;
@@ -21,12 +22,10 @@ import javax.management.MBeanServer;
 import javax.management.ObjectInstance;
 import javax.management.ObjectName;
 import javax.management.ReflectionException;
-
-import org.opendaylight.controller.config.api.ConflictingVersionException;
-import org.opendaylight.controller.config.api.ValidationException;
-import org.opendaylight.controller.config.api.jmx.CommitStatus;
-import org.opendaylight.controller.config.api.jmx.ConfigRegistryMXBean;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 public class ConfigRegistryJMXClient implements ConfigRegistryClient {
     private final ConfigRegistryMXBean configRegistryMXBeanProxy;
@@ -198,4 +197,8 @@ public class ConfigRegistryJMXClient implements ConfigRegistryClient {
         }
     }
 
+    @Override
+    public Set<String> getAvailableModuleFactoryQNames() {
+        return configRegistryMXBeanProxy.getAvailableModuleFactoryQNames();
+    }
 }
index bd6f6fa..0db1e5b 100644 (file)
@@ -233,4 +233,9 @@ public class ConfigTransactionJMXClient implements ConfigTransactionClient {
                     + attrName + " for " + on, e);
         }
     }
+
+    @Override
+    public Set<String> getAvailableModuleFactoryQNames() {
+        return configTransactionControllerMXBeanProxy.getAvailableModuleFactoryQNames();
+    }
 }
index ba62627..6534171 100644 (file)
@@ -173,4 +173,9 @@ public class TestingConfigRegistry implements ConfigRegistryMXBean {
     public String getServiceInterfaceName(String namespace, String localName) {
         throw new UnsupportedOperationException();
     }
+
+    @Override
+    public Set<String> getAvailableModuleFactoryQNames() {
+        throw new UnsupportedOperationException();
+    }
 }
index 1c522f1..44eb73a 100644 (file)
@@ -160,4 +160,9 @@ public class TestingConfigTransactionController implements
     public boolean removeServiceReferences(ObjectName objectName) throws InstanceNotFoundException {
         throw new UnsupportedOperationException();
     }
+
+    @Override
+    public Set<String> getAvailableModuleFactoryQNames() {
+        throw new UnsupportedOperationException();
+    }
 }
index 9f0145f..eba5e07 100644 (file)
@@ -26,6 +26,7 @@
         <module>config-util</module>
         <module>config-persister-api</module>
         <module>config-persister-file-adapter</module>
+        <module>config-persister-file-xml-adapter</module>
         <module>yang-jmx-generator</module>
         <module>yang-jmx-generator-plugin</module>
         <module>yang-store-api</module>
@@ -39,6 +40,7 @@
         <module>netty-event-executor-config</module>
         <module>netty-timer-config</module>
         <module>config-persister-directory-adapter</module>
+        <module>config-persister-directory-xml-adapter</module>
         <module>yang-test-plugin</module>
     </modules>
 
index 47b68eb..35dc7a3 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
 import org.opendaylight.controller.config.spi.Module;
 import org.opendaylight.controller.config.spi.ModuleFactory;
+import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Constructor;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Field;
 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Header;
@@ -33,11 +34,12 @@ public class AbstractFactoryTemplate extends GeneralClassTemplate {
 
     private final String globallyUniqueName, moduleInstanceType;
     private final List<String> providedServices;
+    private final ModuleMXBeanEntry mbe;
 
     public AbstractFactoryTemplate(Header header, String packageName,
-            String abstractFactoryName, String globallyUniqueName,
-            String moduleInstanceType, List<Field> fields,
-            List<String> providedServices) {
+                                   String abstractFactoryName, String globallyUniqueName,
+                                   String moduleInstanceType, List<Field> fields,
+                                   List<String> providedServices, ModuleMXBeanEntry mbe) {
         super(header, packageName, abstractFactoryName, Collections
                 .<String> emptyList(), implementedIfcs, fields, Collections
                 .<MethodDefinition> emptyList(), true, false, Collections
@@ -45,6 +47,7 @@ public class AbstractFactoryTemplate extends GeneralClassTemplate {
         this.globallyUniqueName = globallyUniqueName;
         this.moduleInstanceType = moduleInstanceType;
         this.providedServices = providedServices;
+        this.mbe = mbe;
     }
 
     public String getGloballyUniqueName() {
@@ -92,4 +95,7 @@ public class AbstractFactoryTemplate extends GeneralClassTemplate {
         return "factory_abs_template.ftl";
     }
 
+    public ModuleMXBeanEntry getMbe() {
+        return mbe;
+    }
 }
index 115bb85..28e0256 100644 (file)
@@ -210,8 +210,7 @@ public class TemplateFactory {
             sieTemplate.getAnnotations().add(
                     Annotation.createDescriptionAnnotation(sie
                             .getNullableDescription()));
-        sieTemplate.getAnnotations().add(Annotation.createSieAnnotation(sie.getQName(), sie.getExportedOsgiClassName
-                ()));
+        sieTemplate.getAnnotations().addAll(Annotation.createSieAnnotations(sie));
 
         return sieTemplate;
     }
@@ -236,7 +235,7 @@ public class TemplateFactory {
                 mbe.getPackageName(), mbe.getAbstractFactoryName(),
                 mbe.getGloballyUniqueName(), mbe.getFullyQualifiedName(mbe
                         .getStubModuleName()), attrProcessor.getFields(),
-                Lists.newArrayList(transformed));
+                Lists.newArrayList(transformed), mbe);
     }
 
     public static AbstractModuleTemplate abstractModuleTemplateFromMbe(
index 59368e8..7cf2417 100644 (file)
@@ -7,13 +7,15 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.opendaylight.controller.config.api.annotations.Description;
 import org.opendaylight.controller.config.api.annotations.RequireInterface;
 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
+import org.opendaylight.yangtools.yang.binding.annotations.ModuleQName;
 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
-import org.opendaylight.yangtools.yang.common.QName;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
@@ -42,22 +44,36 @@ public class Annotation {
                 Lists.newArrayList(new Parameter("value", q(description))));
     }
 
-    public static Annotation createSieAnnotation(QName qname,
-            String exportedClassName) {
-        Preconditions.checkNotNull(qname,
+    public static Collection<Annotation> createSieAnnotations(ServiceInterfaceEntry sie){
+
+        String exportedClassName = sie.getExportedOsgiClassName();
+        Preconditions.checkNotNull(sie.getQName(),
                 "Cannot create annotation from null qname");
         Preconditions.checkNotNull(exportedClassName,
                 "Cannot create annotation from null exportedClassName");
+        List<Annotation> result = new ArrayList<>();
+        {
+            List<Parameter> params = Lists.newArrayList(new Parameter("value", q(sie.getQName().toString())));
+            params.add(new Parameter("osgiRegistrationType", exportedClassName + ".class"));
 
-        List<Parameter> params = Lists.newArrayList(new Parameter("value", q(qname.toString())));
-        params.add(new Parameter("osgiRegistrationType", exportedClassName + ".class"));
+            params.add(new Parameter("namespace", q(sie.getQName().getNamespace().toString())));
+            params.add(new Parameter("revision", q(sie.getQName().getFormattedRevision())));
+            params.add(new Parameter("localName", q(sie.getQName().getLocalName())));
 
-        params.add(new Parameter("namespace", q(qname.getNamespace().toString())));
-        params.add(new Parameter("revision", q(qname.getFormattedRevision())));
-        params.add(new Parameter("localName", q(qname.getLocalName())));
+            Annotation sieAnnotation = new Annotation(ServiceInterfaceAnnotation.class.getCanonicalName(), params);
+            result.add(sieAnnotation);
 
-        return new Annotation(
-                ServiceInterfaceAnnotation.class.getCanonicalName(), params);
+        }
+        {
+            List<Parameter> params = new ArrayList<>();
+            params.add(new Parameter("namespace", q(sie.getYangModuleQName().getNamespace().toString())));
+            params.add(new Parameter("revision", q(sie.getYangModuleQName().getFormattedRevision())));
+            params.add(new Parameter("name", q(sie.getYangModuleQName().getLocalName())));
+
+            Annotation moduleQNameAnnotation = new Annotation(ModuleQName.class.getCanonicalName(), params);
+            result.add(moduleQNameAnnotation);
+        }
+        return result;
     }
 
     public static Annotation createRequireIfcAnnotation(
index 37fd05b..b9bbf1f 100644 (file)
@@ -2,6 +2,7 @@
 package ${packageName};
 
 <@javadocD object=javadoc/>
+@org.opendaylight.yangtools.yang.binding.annotations.ModuleQName(namespace="${mbe.getYangModuleQName().getNamespace().toString()}",revision="${mbe.getYangModuleQName().getFormattedRevision()}",name="${mbe.getYangModuleQName().getLocalName()}")
 <@typeDeclarationD object=typeDeclaration/>
 {
 
index c312cc8..c66b112 100644 (file)
             <artifactId>commons-lang3</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>binding-type-provider</artifactId>
+        </dependency>
     </dependencies>
 
     <build>
index 4eba739..869488e 100644 (file)
@@ -136,11 +136,13 @@ public class ModuleMXBeanEntry extends AbstractEntry {
     private final Map<String, QName> providedServices;
 
     private Collection<RuntimeBeanEntry> runtimeBeans;
+    private final QName yangModuleQName;
 
     public ModuleMXBeanEntry(IdentitySchemaNode id,
             Map<String, AttributeIfc> yangToAttributes, String packageName,
             Map<String, QName> providedServices2, String javaNamePrefix,
-            String namespace, Collection<RuntimeBeanEntry> runtimeBeans) {
+            String namespace, Collection<RuntimeBeanEntry> runtimeBeans,
+            QName yangModuleQName) {
         this.globallyUniqueName = id.getQName().getLocalName();
         this.yangToAttributes = yangToAttributes;
         this.nullableDescription = id.getDescription();
@@ -149,6 +151,7 @@ public class ModuleMXBeanEntry extends AbstractEntry {
         this.namespace = checkNotNull(namespace);
         this.providedServices = Collections.unmodifiableMap(providedServices2);
         this.runtimeBeans = runtimeBeans;
+        this.yangModuleQName = yangModuleQName;
     }
 
     public String getMXBeanInterfaceName() {
@@ -395,7 +398,8 @@ public class ModuleMXBeanEntry extends AbstractEntry {
                                 moduleIdentity, yangToAttributes, packageName,
                                 providedServices, javaNamePrefix, currentModule
                                         .getNamespace().toString(),
-                                runtimeBeans);
+                                runtimeBeans,
+                                ModuleUtil.getQName(currentModule));
                         moduleMXBeanEntry.setYangModuleName(currentModule
                                 .getName());
                         moduleMXBeanEntry
@@ -730,6 +734,10 @@ public class ModuleMXBeanEntry extends AbstractEntry {
         return nullableDescription;
     }
 
+    public QName getYangModuleQName() {
+        return yangModuleQName;
+    }
+
     @Override
     public String toString() {
         return "ModuleMXBeanEntry{" + "globallyUniqueName='"
diff --git a/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleUtil.java b/opendaylight/config/yang-jmx-generator/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/ModuleUtil.java
new file mode 100644 (file)
index 0000000..5fea8fd
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.config.yangjmxgenerator;
+
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.Module;
+
+public class ModuleUtil {
+
+    public static QName getQName(Module currentModule){
+        return new QName(currentModule.getNamespace(), currentModule.getRevision(), currentModule.getName());
+    }
+}
index 71cd090..aa2d6a5 100644 (file)
@@ -57,13 +57,14 @@ public class ServiceInterfaceEntry extends AbstractEntry {
     private final String exportedOsgiClassName;
     private final QName qName;
     private final String nullableDescription, packageName, typeName;
+    private final QName yangModuleQName;
 
-    private ServiceInterfaceEntry(IdentitySchemaNode id, String packageName) {
-        this(Optional.<ServiceInterfaceEntry> absent(), id, packageName);
+    private ServiceInterfaceEntry(IdentitySchemaNode id, String packageName, QName yangModuleQName) {
+        this(Optional.<ServiceInterfaceEntry> absent(), id, packageName, yangModuleQName);
     }
 
     private ServiceInterfaceEntry(Optional<ServiceInterfaceEntry> base,
-            IdentitySchemaNode id, String packageName) {
+            IdentitySchemaNode id, String packageName, QName yangModuleQName) {
         checkNotNull(base);
         this.maybeBaseCache = base;
         List<UnknownSchemaNode> unknownSchemaNodes = id.getUnknownSchemaNodes();
@@ -93,6 +94,7 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         nullableDescription = id.getDescription();
         typeName = getSimpleName(exportedOsgiClassName) + CLASS_NAME_SUFFIX;
         this.packageName = packageName;
+        this.yangModuleQName = yangModuleQName;
     }
 
     private static final String getSimpleName(String fullyQualifiedName) {
@@ -120,14 +122,14 @@ public class ServiceInterfaceEntry extends AbstractEntry {
      * @return Map of QNames as keys and ServiceInterfaceEntry instances as
      *         values
      */
-    public static Map<QName, ServiceInterfaceEntry> create(Module module,
+    public static Map<QName, ServiceInterfaceEntry> create(Module currentModule,
             String packageName) {
         logger.debug("Generating ServiceInterfaces from {} to package {}",
-                module.getNamespace(), packageName);
+                currentModule.getNamespace(), packageName);
 
         Map<IdentitySchemaNode, ServiceInterfaceEntry> identitiesToSIs = new HashMap<>();
         Set<IdentitySchemaNode> notVisited = new HashSet<>(
-                module.getIdentities());
+                currentModule.getIdentities());
         int lastSize = notVisited.size() + 1;
         while (notVisited.size() > 0) {
             if (notVisited.size() == lastSize) {
@@ -148,18 +150,18 @@ public class ServiceInterfaceEntry extends AbstractEntry {
                 } else if (identity.getBaseIdentity().getQName()
                         .equals(SERVICE_TYPE_Q_NAME)) {
                     // this is a base type
-                    created = new ServiceInterfaceEntry(identity, packageName);
+                    created = new ServiceInterfaceEntry(identity, packageName, ModuleUtil.getQName(currentModule));
                 } else {
                     ServiceInterfaceEntry foundBase = identitiesToSIs
                             .get(identity.getBaseIdentity());
                     // derived type, did we convert the parent?
                     if (foundBase != null) {
                         created = new ServiceInterfaceEntry(
-                                Optional.of(foundBase), identity, packageName);
+                                Optional.of(foundBase), identity, packageName, ModuleUtil.getQName(currentModule));
                     }
                 }
                 if (created != null) {
-                    created.setYangModuleName(module.getName());
+                    created.setYangModuleName(currentModule.getName());
                     // TODO how to get local name
                     created.setYangModuleLocalname(identity.getQName()
                             .getLocalName());
@@ -190,6 +192,10 @@ public class ServiceInterfaceEntry extends AbstractEntry {
         return typeName;
     }
 
+    public QName getYangModuleQName() {
+        return yangModuleQName;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o)
index 764ecd3..c43fead 100644 (file)
@@ -64,4 +64,8 @@ public class TypeProviderWrapper {
     public String getJMXParamForBaseType(TypeDefinition<?> baseType) {
         return typeProvider.getConstructorPropertyName(baseType);
     }
+
+    public String getJMXParamForUnionInnerType(TypeDefinition<?> unionInnerType) {
+        return typeProvider.getParamNameFromType(unionInnerType);
+    }
 }
index 3e20e4a..e01063e 100644 (file)
@@ -7,20 +7,26 @@
  */
 package org.opendaylight.controller.config.yangjmxgenerator.attribute;
 
+import com.google.common.base.Preconditions;
 import org.opendaylight.controller.config.yangjmxgenerator.TypeProviderWrapper;
 import org.opendaylight.yangtools.sal.binding.model.api.Type;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 
 import javax.management.openmbean.ArrayType;
 import javax.management.openmbean.CompositeType;
 import javax.management.openmbean.OpenDataException;
 import javax.management.openmbean.OpenType;
 import javax.management.openmbean.SimpleType;
+import java.util.Arrays;
+import java.util.List;
 
 public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
 
+    public static final String DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION = "valueOfArtificialUnionProperty";
+
     private final Type type;
     private final String nullableDescription, nullableDefault, nullableDefaultWrappedForCode;
     private final TypeProviderWrapper typeProviderWrapper;
@@ -47,6 +53,11 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
         this.nullableDescription = leaf.getDescription();
     }
 
+    public boolean isUnion() {
+        TypeDefinition<?> base = getBaseType(typeProviderWrapper, typeDefinition);
+        return base instanceof UnionTypeDefinition;
+    }
+
     public TypeDefinition<?> getTypeDefinition() {
         return typeDefinition;
     }
@@ -132,13 +143,70 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
             return getArrayType();
         } else if (isEnum(baseType)) {
             return getSimpleType(baseType);
-        } else if (isDerivedType(baseType)) {
+        } else if (isUnion()) {
+            return getCompositeTypeForUnion(baseTypeDefinition);
+        } else if (isDerivedType(baseType, getType())) {
             return getCompositeType(baseType, baseTypeDefinition);
         }
 
         return getSimpleType(getType());
     }
 
+    private OpenType<?> getCompositeTypeForUnion(TypeDefinition<?> baseTypeDefinition) {
+        Preconditions.checkArgument(baseTypeDefinition instanceof UnionTypeDefinition,
+                "Expected %s instance but was %s", UnionTypeDefinition.class, baseTypeDefinition);
+
+        List<TypeDefinition<?>> types = ((UnionTypeDefinition) baseTypeDefinition).getTypes();
+
+        String[] itemNames = new String[types.size()+1];
+        OpenType<?>[] itemTypes = new OpenType[itemNames.length];
+
+        addArtificialPropertyToUnionCompositeType(baseTypeDefinition, itemNames, itemTypes);
+
+        String description = getNullableDescription() == null ? getAttributeYangName() : getNullableDescription();
+
+        int i = 1;
+        for (TypeDefinition<?> innerTypeDefinition : types) {
+
+            Type innerType = typeProviderWrapper.getType(innerTypeDefinition, innerTypeDefinition);
+
+            TypeDefinition<?> baseInnerTypeDefinition = getBaseType(typeProviderWrapper, innerTypeDefinition);
+            Type innerTypeBaseType = typeProviderWrapper.getType(baseInnerTypeDefinition, baseInnerTypeDefinition);
+
+            OpenType<?> innerCompositeType;
+
+            if(isDerivedType(innerTypeBaseType, innerType)) {
+                innerCompositeType = getCompositeType(innerTypeBaseType, baseInnerTypeDefinition);
+            } else {
+                innerCompositeType = SimpleTypeResolver.getSimpleType(innerType);
+            }
+
+            itemNames[i] = typeProviderWrapper.getJMXParamForUnionInnerType(innerTypeDefinition);
+            itemTypes[i++] = innerCompositeType;
+        }
+
+        String[] descriptions = Arrays.copyOf(itemNames, itemNames.length);
+        descriptions[0] = DESCRIPTION_OF_VALUE_ATTRIBUTE_FOR_UNION;
+
+        try {
+            return new CompositeType(getUpperCaseCammelCase(), description, itemNames, descriptions, itemTypes);
+        } catch (OpenDataException e) {
+            throw new RuntimeException("Unable to create " + CompositeType.class + " with inner elements "
+                    + Arrays.toString(itemTypes), e);
+        }
+    }
+
+    public static final Class<Character> TYPE_OF_ARTIFICIAL_UNION_PROPERTY = char.class;
+
+    private void addArtificialPropertyToUnionCompositeType(TypeDefinition<?> baseTypeDefinition, String[] itemNames, OpenType<?>[] itemTypes) {
+        String artificialPropertyName = typeProviderWrapper.getJMXParamForBaseType(baseTypeDefinition);
+        itemNames[0] = artificialPropertyName;
+
+        OpenType<?> artificialPropertyType = getArrayOpenTypeForSimpleType(TYPE_OF_ARTIFICIAL_UNION_PROPERTY.getName(),
+                SimpleTypeResolver.getSimpleType(TYPE_OF_ARTIFICIAL_UNION_PROPERTY.getName()));
+        itemTypes[0] = artificialPropertyType;
+    }
+
     private boolean isEnum(Type baseType) {
         return baseType.getFullyQualifiedName().equals(Enum.class.getName());
     }
@@ -163,12 +231,15 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
             throw new RuntimeException("Unable to create " + CompositeType.class + " with inner element of type "
                     + itemTypes, e);
         }
-
     }
 
     private OpenType<?> getArrayType() {
         String innerTypeFullyQName = getInnerType(getType());
         SimpleType<?> innerSimpleType = SimpleTypeResolver.getSimpleType(innerTypeFullyQName);
+        return getArrayOpenTypeForSimpleType(innerTypeFullyQName, innerSimpleType);
+    }
+
+    private OpenType<?> getArrayOpenTypeForSimpleType(String innerTypeFullyQName, SimpleType<?> innerSimpleType) {
         try {
             ArrayType<Object> arrayType = isPrimitive(innerTypeFullyQName) ? new ArrayType<>(innerSimpleType, true)
                     : new ArrayType<>(1, innerSimpleType);
@@ -191,8 +262,8 @@ public class JavaAttribute extends AbstractAttribute implements TypedAttribute {
         return type.getName().endsWith("[]");
     }
 
-    private boolean isDerivedType(Type baseType) {
-        return  baseType.equals(getType()) == false;
+    private boolean isDerivedType(Type baseType, Type currentType) {
+        return  baseType.equals(currentType) == false;
     }
 
     private static String getInnerType(Type type) {
index 87b55f3..f4bd979 100644 (file)
@@ -59,6 +59,8 @@ public class SimpleTypeResolver {
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Date.class.getName(), SimpleType.DATE);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(Double.class.getName(), SimpleType.DOUBLE);
         JAVA_TYPE_TO_SIMPLE_TYPE.put(double.class.getName(), SimpleType.DOUBLE);
+
+        JAVA_TYPE_TO_SIMPLE_TYPE.put(char.class.getName(), SimpleType.CHARACTER);
     }
 
 }
diff --git a/opendaylight/config/yang-test/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/test/types/rev131127/UnionTestBuilder.java b/opendaylight/config/yang-test/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/controller/config/test/types/rev131127/UnionTestBuilder.java
new file mode 100644 (file)
index 0000000..c49319b
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127;
+
+
+/**
+**/
+public class UnionTestBuilder {
+
+    public static UnionTest getDefaultInstance(String defaultValue) {
+        try {
+            int i = Integer.valueOf(defaultValue);
+            return new UnionTest(new ExtendTwice(i));
+        } catch (NumberFormatException e) {
+            return new UnionTest(defaultValue);
+        }
+    }
+
+}
index 9ad7a44..f7cea0a 100644 (file)
@@ -61,10 +61,6 @@ module config-test-impl {
                     default 127.0.0.1;
                 }
 
-                leaf ip {
-                    type inet:ip-address;
-                    // TODO defaults for union default 0:0:0:0:0:0:0:1;
-                }
             }
 
             leaf as-number {
@@ -136,6 +132,16 @@ module config-test-impl {
                 default ONE;
             }
 
+            leaf ip {
+                type inet:ip-address;
+                default 0:0:0:0:0:0:0:1;
+            }
+
+            leaf union-test-attr {
+                type tt:unionTest;
+                default 456;
+            }
+
             leaf sleep-factor {
                 type decimal64 {
                     fraction-digits 2;
index 84fbcb0..8c086d8 100644 (file)
@@ -23,4 +23,12 @@ module test-types {
         }
     }
 
+      typedef unionTest {
+        type union {
+          type string;
+          type uint32;
+          type extend-twice;
+        }
+      }
+
 }
index 4296048..35e160e 100644 (file)
           <artifactId>config-persister-file-adapter</artifactId>
           <version>${config.version}</version>
         </dependency>
-          <dependency>
-              <groupId>org.opendaylight.controller</groupId>
-              <artifactId>config-persister-directory-adapter</artifactId>
-              <version>${config.version}</version>
-          </dependency>
+        <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>config-persister-file-xml-adapter</artifactId>
+          <version>${config.version}</version>
+        </dependency>
+        <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>config-persister-directory-adapter</artifactId>
+          <version>${config.version}</version>
+        </dependency>
+        <dependency>
+          <groupId>org.opendaylight.controller</groupId>
+          <artifactId>config-persister-directory-xml-adapter</artifactId>
+          <version>${config.version}</version>
+        </dependency>
 
        <!-- Netconf -->
         <dependency>
       </dependencies>
     </profile>
     <profile>
-      <!-- sanitytests are only enabled with this profile -->
       <id>integrationtests</id>
       <activation>
         <activeByDefault>false</activeByDefault>
         <plugins>
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
-            <artifactId>maven-invoker-plugin</artifactId>
-            <version>1.5</version>
+            <artifactId>maven-dependency-plugin</artifactId>
+            <version>2.8</version>
+            <executions>
+              <execution>
+                <id>copy</id>
+                <phase>package</phase>
+                <goals>
+                  <goal>copy</goal>
+                </goals>
+              </execution>
+            </executions>
             <configuration>
-              <debug>false</debug>
-              <projectsDirectory>../sanitytest</projectsDirectory>
-              <pomIncludes>
-                <pomInclude>pom.xml</pomInclude>
-              </pomIncludes>
-              <streamLogs>true</streamLogs>
-              <noLog>true</noLog>
-              <goals>
-                <goal>clean</goal>
-                <goal>verify</goal>
-              </goals>
-              </configuration>
-              <executions>
-                <execution>
-                  <id>integration-test</id>
-                    <goals>
-                      <goal>install</goal>
-                      <goal>run</goal>
-                    </goals>
-                </execution>
-              </executions>
-           </plugin>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.opendaylight.controller</groupId>
+                  <artifactId>sanitytest</artifactId>
+                  <version>${controller.version}</version>
+                  <type>jar</type>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </plugin>
+          <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>exec-maven-plugin</artifactId>
+            <version>1.2.1</version>
+            <executions>
+              <execution>
+                <id>sanity-test</id>
+                <phase>package</phase>
+                <goals>
+                  <goal>exec</goal>
+                </goals>
+              </execution>
+            </executions>
+            <configuration>
+              <executable>${java.home}/bin/java</executable>
+              <arguments>
+                <argument>-cp</argument>
+                <argument>./target/dependency/*</argument>
+                <argument>org.opendaylight.controller.distribution.Sanity</argument>
+              </arguments>
+              <environmentVariables>
+                <JAVA_HOME>
+                  ${java.home}
+                </JAVA_HOME>
+              </environmentVariables>
+            </configuration>
+          </plugin>
         </plugins>
       </build>
-
-      <dependencies>
-        <dependency>
-         <groupId>org.opendaylight.controller</groupId>
-         <artifactId>controller-maven-plugin</artifactId>
-         <version>0.1.0-SNAPSHOT</version>
-        </dependency>
-      </dependencies>
     </profile>
   </profiles>
 
      <version>${commons.httpclient.version}</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sanitytest</artifactId>
+      <version>${controller.version}</version>
+    </dependency>
+
+
   </dependencies>
 
 
           </execution>
         </executions>
       </plugin>
-
     </plugins>
   </build>
-
 </project>
diff --git a/opendaylight/distribution/opendaylight/runsanity.bat b/opendaylight/distribution/opendaylight/runsanity.bat
new file mode 100644 (file)
index 0000000..f219828
--- /dev/null
@@ -0,0 +1,23 @@
+rem Inject the sanitytest jar as a controller plugin
+copy .\target\dependency\sanitytest*.jar .\target\distribution.opendaylight-osgipackage\opendaylight\plugins
+
+rem Store the current working directory in a variable so that we can get back to it later
+set cwd=%cd%
+
+rem Switch to the distribution folder
+cd .\target\distribution.opendaylight-osgipackage\opendaylight
+
+rem Run the controller
+cmd.exe /c run.bat
+
+rem Store the exit value of the controller in a variable
+set success=%ERRORLEVEL%
+
+rem Switch back to the directory from which this script was invoked
+cd %cwd%
+
+rem Remove the sanitytest jar from the plugins directory
+del .\target\distribution.opendaylight-osgipackage\opendaylight\plugins\sanitytest*.jar
+
+rem Exit using the exit code that we had captured earlier after running the controller
+exit /b %SUCCESS%
\ No newline at end of file
diff --git a/opendaylight/distribution/opendaylight/runsanity.sh b/opendaylight/distribution/opendaylight/runsanity.sh
new file mode 100755 (executable)
index 0000000..4ee9555
--- /dev/null
@@ -0,0 +1,24 @@
+# Inject the sanitytest jar as a controller plugin
+cp ./target/dependency/sanitytest*.jar ./target/distribution.opendaylight-osgipackage/opendaylight/plugins
+
+# Store the current working directory in a variable so that we can get back to it later
+cwd=`pwd`
+
+# Switch to the distribution folder
+cd ./target/distribution.opendaylight-osgipackage/opendaylight/
+
+# Run the controller
+./run.sh
+
+# Store the exit value of the controller in a variable
+success=`echo $?`
+
+# Switch back to the directory from which this script was invoked
+cd $cwd
+
+# Remove the sanitytest jar from the plugins directory
+rm ./target/distribution.opendaylight-osgipackage/opendaylight/plugins/sanitytest*.jar
+
+# Exit using the exit code that we had captured earlier after running the controller
+exit $success
+
index 1e8f34e..8fea175 100644 (file)
@@ -27,6 +27,7 @@
         <exclude>com.sun.jersey:jersey-json</exclude>
         <exclude>com.sun.jersey:jersey-server</exclude>
         <exclude>org.opendaylight.controller:logging.bridge</exclude>
+        <exclude>org.opendaylight.controller:sanitytest</exclude>
       </excludes>
       <outputFileNameMapping>
         ${artifact.groupId}.${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}
index 7d57e60..ba5d862 100644 (file)
@@ -29,8 +29,16 @@ netconf.config.persister.1.storageAdapterClass=org.opendaylight.controller.confi
 netconf.config.persister.1.properties.directoryStorage=configuration/initial/
 netconf.config.persister.1.readonly=true
 
-netconf.config.persister.2.storageAdapterClass=org.opendaylight.controller.config.persist.storage.file.FileStorageAdapter
-netconf.config.persister.2.properties.fileStorage=configuration/current/controller.currentconfig.txt
+#netconf.config.persister.3.storageAdapterClass=org.opendaylight.controller.config.persist.storage.directory.xml.XmlDirectoryStorageAdapter
+#netconf.config.persister.3.properties.directoryStorage=configuration/initialXml/
+#netconf.config.persister.3.readonly=true
+
+#netconf.config.persister.4.storageAdapterClass=org.opendaylight.controller.config.persist.storage.file.FileStorageAdapter
+#netconf.config.persister.4.properties.fileStorage=configuration/current/controller.currentconfig.txt
+#netconf.config.persister.4.properties.numberOfBackups=1
+
+netconf.config.persister.2.storageAdapterClass=org.opendaylight.controller.config.persist.storage.file.xml.XmlFileStorageAdapter
+netconf.config.persister.2.properties.fileStorage=configuration/current/controller.currentconfig.xml
 netconf.config.persister.2.properties.numberOfBackups=1
 
 
index a8e33d2..9d6ac8d 100644 (file)
@@ -140,7 +140,7 @@ SET RUN_CMD="%JAVA_HOME%\bin\java.exe" -Dopendaylight.controller %extraJVMOpts%
 ECHO %RUN_CMD%
 
 if "%startEnabled%" NEQ "" (
-    START /B cmd /C CALL %RUN_CMD%
+    START /B cmd /C CALL %RUN_CMD% > %basedir%\logs\controller.out 2>&1
     ECHO Running controller in the background.
 ) else (
     %RUN_CMD%
index ce710d1..9d5ba5c 100644 (file)
 
   <artifactId>sanitytest</artifactId>
   <version>0.4.1-SNAPSHOT</version>
-  <packaging>jar</packaging>
-
-  <properties>
-    <distro.dir>${project.basedir}/../opendaylight/target/distribution.opendaylight-osgipackage/opendaylight</distro.dir>
-    <distro.script>${distro.dir}/run.bat</distro.script>
-    <!-- the address is passed to both the controller & the test to establish the connection -->
-    <sanitytest.bind.address>127.0.0.1</sanitytest.bind.address>
-    <sanitytest.timeout>300</sanitytest.timeout>
-  </properties>
-
-  <profiles>
-    <profile>
-      <id>non-windows</id>
-      <activation>
-        <os>
-          <family>!windows</family>
-        </os>
-      </activation>
-      <properties>
-        <distro.script>${distro.dir}/run.sh</distro.script>
-        <distro.pid>/tmp/opendaylight.PID</distro.pid>
-      </properties>
-    </profile>
-  </profiles>
-
+  <packaging>bundle</packaging>
   <dependencies>
     <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>org.osgi.core</artifactId>
       <scope>provided</scope>
     </dependency>
-
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>org.ow2.chameleon.management</groupId>
-      <artifactId>chameleon-mbeans</artifactId>
-      <scope>test</scope>
-    </dependency>
-
   </dependencies>
-
   <build>
     <plugins>
       <plugin>
-        <!-- disable the install plugin -->
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-install-plugin</artifactId>
-        <version>${install.plugin.version}</version>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>${bundle.plugin.version}</version>
+        <extensions>true</extensions>
         <configuration>
-          <skip>true</skip>
+          <instructions>
+            <Export-Package>
+              org.opendaylight.controller.sanitytest
+            </Export-Package>
+            <Import-Package>
+              javax.xml.bind.annotation,
+              org.osgi.service.component,
+              org.slf4j,
+              org.eclipse.osgi.framework.console,
+              org.osgi.framework,
+              org.eclipse.osgi.baseadaptor,
+              org.eclipse.osgi.framework.adaptor,
+              org.osgi.framework.wiring
+            </Import-Package>
+            <Bundle-Activator>
+              org.opendaylight.controller.sanitytest.internal.Activator
+            </Bundle-Activator>
+          </instructions>
+          <manifestLocation>${project.basedir}/META-INF</manifestLocation>
         </configuration>
-        <executions>
-          <execution>
-            <id>default-install</id>
-            <phase>none</phase>
-          </execution>
-        </executions>
       </plugin>
-
-      <plugin>
-        <!--  ensure that the distro installation is already built -->
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-enforcer-plugin</artifactId>
-        <version>${enforcer.plugin.version}</version>
-        <executions>
-          <execution>
-            <id>enforce-files-exist</id>
-            <phase>pre-integration-test</phase>
-            <goals>
-              <goal>enforce</goal>
-            </goals>
-            <configuration>
-              <rules>
-                <requireFilesExist>
-                  <files>
-                    <file>${distro.script}</file>
-                  </files>
-                </requireFilesExist>
-              </rules>
-              <fail>true</fail>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-
-      <plugin>
-        <groupId>org.opendaylight.controller</groupId>
-        <artifactId>controller-maven-plugin</artifactId>
-        <version>0.1.0-SNAPSHOT</version>
-          <configuration>
-              <controllerHome>${distro.dir}</controllerHome>
-              <controllerHost>localhost</controllerHost>
-              <controllerWebPort>8080</controllerWebPort>
-              <controllerUsername>admin</controllerUsername>
-              <controllerPassword>admin</controllerPassword>
-              <controllerStartScriptName>${distro.script}</controllerStartScriptName>
-              <pidFile>${distro.pid}</pidFile>
-          </configuration>
-        <executions>
-          <execution>
-            <!-- ensure controller is started in pre-integration phase -->
-            <id>start-controller</id>
-            <phase>pre-integration-test</phase>
-            <configuration>
-              <startArgs>
-                <param>-start</param>
-                <param>-jmx</param>
-                <param>-Djava.rmi.server.hostname=${sanitytest.bind.address} </param>
-              </startArgs>
-              <warmupTimeSecs> 60 </warmupTimeSecs>
-            </configuration>
-            <goals>
-              <goal>run</goal>
-            </goals>
-          </execution>
-          <execution>
-            <!-- ensure controller is stopped in post-integration phase -->
-            <id>stop-controller</id>
-            <phase>post-integration-test</phase>
-            <goals>
-              <goal>stop</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-
-      <plugin>
-        <!--  run the test -->
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-failsafe-plugin</artifactId>
-        <version>${failsafe.version}</version>
-        <configuration>
-          <systemPropertyVariables>
-            <ctrl.home>${distro.dir}</ctrl.home>
-            <ctrl.host>${sanitytest.bind.address}</ctrl.host>
-            <ctrl.start.timeout>${sanitytest.timeout}</ctrl.start.timeout>
-          </systemPropertyVariables>
-        </configuration>
-      </plugin>
-
     </plugins>
-
-
   </build>
 </project>
diff --git a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/distribution/Sanity.java
new file mode 100644 (file)
index 0000000..7fc25e2
--- /dev/null
@@ -0,0 +1,48 @@
+package org.opendaylight.controller.distribution;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Sanity {
+
+    static void copy(InputStream in, OutputStream out) throws IOException {
+      while (true) {
+        int c = in.read();
+        if (c == -1) break;
+        out.write((char)c);
+      }
+    }
+
+    public static void main(String[] args) throws IOException, InterruptedException {
+        String cwd = System.getProperty("user.dir");
+
+        System.out.println("Current working directory = " + cwd);
+
+        String os = System.getProperty("os.name").toLowerCase();
+        List<String> script = new ArrayList<String>();
+
+        if(os.contains("windows")){
+            script.add("cmd.exe");
+            script.add("/c");
+            script.add("runsanity.bat");
+        } else {
+            script.add("./runsanity.sh");
+        }
+
+        ProcessBuilder processBuilder = new ProcessBuilder();
+        processBuilder.inheritIO().command(script);
+        Process p = processBuilder.start();
+
+        copy(p.getInputStream(), System.out);
+
+        p.waitFor();
+
+        System.out.println("Test exited with exitValue = " + p.exitValue());
+
+        System.exit(p.exitValue());
+    }
+}
diff --git a/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java b/opendaylight/distribution/sanitytest/src/main/java/org/opendaylight/controller/sanitytest/internal/Activator.java
new file mode 100644 (file)
index 0000000..08f0700
--- /dev/null
@@ -0,0 +1,101 @@
+package org.opendaylight.controller.sanitytest.internal;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.wiring.BundleRevision;
+
+public class Activator implements BundleActivator {
+    //10 Second initial, 1 second subsequent
+    private static final int INITIAL_DELAY = 10000;
+    private static final int SUBSEQUENT_DELAY = 1000;
+    private static final int MAX_ATTEMPTS = 120;
+
+
+    private String stateToString(int state) {
+        switch (state) {
+        case Bundle.ACTIVE:
+            return "ACTIVE";
+        case Bundle.INSTALLED:
+            return "INSTALLED";
+        case Bundle.RESOLVED:
+            return "RESOLVED";
+        case Bundle.UNINSTALLED:
+            return "UNINSTALLED";
+        case Bundle.STARTING:
+            return "STARTING";
+        default:
+            return "Not CONVERTED: state value is " + state;
+        }
+    }
+
+    public void start(final BundleContext bundleContext) throws Exception {
+        Timer monitorTimer = new Timer("monitor timer", true);
+        monitorTimer.schedule(new TimerTask() {
+            @Override
+            public void run() {
+                int countup = 0;
+                boolean failed = false;
+                boolean resolved = false;
+                while (!resolved) {
+                    resolved = true;
+                    failed = false;
+                    for(Bundle bundle : bundleContext.getBundles()){
+                        /*
+                         * A bundle should be ACTIVE, unless it a fragment, in which case it should be RESOLVED
+                         */
+                        int state = bundle.getState();
+                        if ((bundle.adapt(BundleRevision.class).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+                            //fragment
+                            if (state != Bundle.RESOLVED) {
+                                System.out.println("------ Failed to activate/resolve fragment = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
+                                failed = true;
+                                if (state == Bundle.STARTING)
+                                    resolved = false;
+                            }
+                        } else {
+                            if(state != Bundle.ACTIVE) {
+                                System.out.println("------ Failed to activate/resolve bundle = " + bundle.getSymbolicName() + " state = " + stateToString(bundle.getState()));
+                                failed = true;
+                                if (state == Bundle.STARTING)
+                                    resolved = false;
+                            }
+                        }
+                    }
+                    if (!resolved) {
+                        countup++;
+                        if (countup < MAX_ATTEMPTS) {
+                            System.out.println("all bundles haven't finished starting, will repeat");
+                            try {
+                                Thread.sleep(SUBSEQUENT_DELAY);
+                            } catch (Exception e) {
+                                System.out.println("Thread.sleep interuptted.");
+                                break;
+                            }
+                        } else
+                            resolved = true;
+                    }
+                }
+
+                if(failed){
+                    System.out.flush();
+                    System.out.println("exiting with 1 as failed");
+                    System.out.close();
+                    Runtime.getRuntime().exit(1);
+                } else {
+                    System.out.flush();
+                    System.out.println("exiting with 0 as succeeded");
+                    System.out.close();
+                    Runtime.getRuntime().exit(0);
+                }
+            }
+        }, INITIAL_DELAY);
+    }
+
+    public void stop(BundleContext bundleContext) throws Exception {
+
+    }
+}
diff --git a/opendaylight/distribution/sanitytest/src/test/java/org/opendaylight/controller/distribution/test/SanityIT.java b/opendaylight/distribution/sanitytest/src/test/java/org/opendaylight/controller/distribution/test/SanityIT.java
deleted file mode 100644 (file)
index 931e88f..0000000
+++ /dev/null
@@ -1,329 +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.distribution.test;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.Socket;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.ow2.chameleon.management.beans.BundleMXBean;
-import org.ow2.chameleon.management.beans.OSGiPlatformMXBean;
-
-/**
- * This integration test assumes a running local controller. The test does the
- * following:
- * 1) Wait for HTTP, JMX and OF ports to open
- * 2) Establishes a JMX connection and registers a bundle notification listener
- * 3) Waits till all bundles reach expected states or the timeout period elapses
- */
-public class SanityIT {
-  private static final int OF_PORT = Integer.getInteger("ctrl.of.port", 6633);
-  private static final int HTTP_PORT = Integer.getInteger("ctrl.http.port", 8080);
-  private static final int JMX_PORT = Integer.getInteger("ctrl.jmx.port", 1088);
-  private static final int RMI_PORT = Integer.getInteger("ctrl.rmi.port", 1099);
-  private static final String CTRL_HOST = System.getProperty("ctrl.host", "127.0.0.1");
-  private static final String CTRL_HOME = System.getProperty("ctrl.home");
-  private static final long TIMEOUT_MILLIS =
-          Integer.getInteger("ctrl.start.timeout", 3*60) * 1000L;
-  private static final String JMX_URL =
-          "service:jmx:rmi:///jndi/rmi://" + CTRL_HOST + ":" + JMX_PORT + "/jmxrmi";
-
-  private static final Set<String> bundles =
-          Collections.synchronizedSet(new HashSet<String>());
-  private static final Set<String> fragments =
-          Collections.synchronizedSet(new HashSet<String>());
-
-  @BeforeClass
-  public static void loadBundles() throws IOException {
-      log("         ctrl.home: " + CTRL_HOME);
-      log("         ctrl.host: " + CTRL_HOST);
-      log("ctrl.start.timeout: " + TIMEOUT_MILLIS);
-      log("           jmx.url: " + JMX_URL);
-
-      Assert.assertNotNull(CTRL_HOME);
-      File ctrlHome = new File(CTRL_HOME);
-      Assert.assertTrue(ctrlHome.exists() && ctrlHome.isDirectory());
-      File configDir = new File(ctrlHome, "configuration");
-      Assert.assertTrue(configDir.exists() && configDir.isDirectory());
-      File configIni = new File(configDir, "config.ini");
-      Assert.assertTrue(configIni.exists());
-      Properties config = new Properties();
-      config.load(new FileInputStream(configIni));
-      processBundles(configDir, config.getProperty("osgi.bundles"));
-      processBundles(new File(ctrlHome, "plugins"));
-      log("Bundles found in installation:   " + bundles.size());
-      log("Fragments found in installation: " + fragments.size());
-  }
-
-@Test
-  public void sanityTest() throws Exception {
-    // wait for http, jmx & of ports to open
-    long startTime = System.currentTimeMillis();
-    waitForListening(OF_PORT, false, startTime);
-    waitForListening(JMX_PORT, false, startTime);
-    waitForListening(HTTP_PORT, false, startTime);
-
-    // open jmx connection
-    JMXServiceURL serviceUrl = new JMXServiceURL(JMX_URL);
-    JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
-    final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
-
-    ObjectName fmkName = new ObjectName("org.ow2.chameleon:type=framework");
-    OSGiPlatformMXBean fmkBean= JMX.newMBeanProxy(conn, fmkName,
-              OSGiPlatformMXBean.class, true);
-    conn.addNotificationListener(fmkName, new NotificationListener() {
-
-        @Override
-        public void handleNotification(Notification n, Object handback) {
-            try {
-                //log("Notification: source: " + n.getSource());
-                ObjectName bundleName = new ObjectName(
-                        "org.ow2.chameleon:type=bundle,id=" + n.getUserData());
-                BundleMXBean bundleBean = JMX.newMXBeanProxy(conn,
-                        bundleName, BundleMXBean.class, true);
-                log("Bundle state change: " + bundleBean.getSymbolicName() +
-                        " : " + stateToString(bundleBean.getState()));
-                handleBundleEvent(bundleBean);
-                // if its a system bundle, notify the main thread
-                if (bundleBean.getBundleId() == 0 &&
-                        bundleBean.getState() == Bundle.ACTIVE)
-                {
-                    synchronized(SanityIT.this) {
-                        SanityIT.this.notify();
-                    }
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-    }, null, null);
-
-    if (checkAllBundles(conn) > 0) {
-        log("Waiting for system bundle to start... (times out in: " + TIMEOUT_MILLIS + "ms)");
-        long timeElapsed = System.currentTimeMillis() - startTime;
-        synchronized(this) {
-            this.wait(TIMEOUT_MILLIS - timeElapsed);
-        }
-        log("System bundle started. Revalidating bundle states for all bundles...");
-
-        // Sometimes, the system bundle starts earlier than other bundles(?). The
-        // following loop will cover that case.
-        do {
-            Thread.sleep(2000); // 2s seems appropriate given the default timeout
-            if (checkAllBundles(conn) == 0) {
-                break;
-            }
-        } while(System.currentTimeMillis() - startTime < TIMEOUT_MILLIS);
-    }
-    try {
-        jmxConnector.close();
-    } catch (Exception ignore) {
-        // dont want the tests to fail in case we can't close jmx connection
-        ignore.printStackTrace();
-    }
-    if (bundles.size() + fragments.size() == 0) {
-        log("All bundles have reached expected state");
-    } else {
-        log("The following bundles did not reach expected state: ");
-        for (String s : bundles) log("Bundle: " + s);
-        for (String s : fragments) log("Fragment: " + s);
-
-    }
-    Assert.assertTrue(bundles.size() == 0 && fragments.size() == 0);
-  }
-
-  private static int checkAllBundles(MBeanServerConnection conn) throws Exception {
-      ObjectName allBundlesName = new ObjectName("org.ow2.chameleon:*");
-      Set<ObjectName> bundleNames = conn.queryNames(allBundlesName, null);
-      for (ObjectName bundleName : bundleNames) {
-          if ("bundle".equals(bundleName.getKeyProperty("type"))) {
-              BundleMXBean bundleBean = JMX.newMBeanProxy(conn, bundleName,
-                      BundleMXBean.class, true);
-              handleBundleEvent(bundleBean);
-          }
-      }
-      int remaining = bundles.size() + fragments.size();
-      if (remaining > 0) {
-        log("Bundles not in expected states: " + remaining + " Waiting...");
-      }
-      return remaining;
-  }
-
-  private synchronized static void handleBundleEvent(BundleMXBean bundleBean) {
-      String name = bundleBean.getSymbolicName();
-      int state = bundleBean.getState();
-      // BUG in BundleMXBeanImpl - can't get bundle headers :(
-      // String fragHost = bundleBean.getBundleHeaders().get(Constants.FRAGMENT_HOST);
-      if (bundles.contains(name) && (state == Bundle.RESOLVED || state == Bundle.ACTIVE)) {
-          bundles.remove(name);
-      } else if (fragments.contains(name) && state == Bundle.RESOLVED) {
-          fragments.remove(name);
-      }
-      //log("Bundles to be started: " + bundles.size());
-  }
-
-
-  //    reference\:file\:../lib/org.apache.felix.fileinstall-3.1.6.jar@1:start,\
-  private static void processBundles(File dir, String property) {
-      Assert.assertTrue(property == null || property.length() > 0);
-      for(String s : property.split(",")) {
-          int idx = s.indexOf("@");
-          s = s.substring(15, (idx == -1 ? s.length() : idx));
-          if (!s.endsWith(".jar")) s = s + ".jar";
-          processJar(new File(dir, s));
-      }
-  }
-
-  public static void processBundles(File dir) throws IOException {
-      if (!dir.exists()) throw new FileNotFoundException("Cannot find dir:" + dir);
-      dir.listFiles(new FileFilter() {
-
-        @Override
-        public boolean accept(File file) {
-            //p("---- " + file);
-            if (file.getName().endsWith(".jar")) {
-                return processJar(file);
-            }
-            return false;
-        }
-      });
-  }
-
-  public static boolean processJar(File file) {
-      try {
-          //log("----" + file);
-          JarFile jar = new JarFile(file, false);
-          Attributes jarAttributes = jar.getManifest().getMainAttributes();
-          String bundleName = jarAttributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
-          String fragHost = jarAttributes.getValue(Constants.FRAGMENT_HOST);
-          if (bundleName == null) {
-              log("Found a non bundle file:" + file);
-              return false;
-          } else {
-              int idx = bundleName.indexOf(';');
-              if (idx > -1) {
-                  bundleName = bundleName.substring(0, idx);
-              }
-          }
-
-          if (fragHost == null) {
-              if (!bundles.add(bundleName)) {
-                  throw new IllegalStateException(
-                          "Found duplicate bundles with same symbolic name: "
-                                  + bundleName);
-              }
-          } else {
-              // fragments attaching to framework can't be detected
-              if (fragHost.contains("extension:=\"framework\"")) return false;
-              if (!fragments.add(bundleName)) {
-                  throw new IllegalStateException(
-                          "Found duplicate fragments with same symbolic name: "
-                                  + bundleName);
-              }
-          }
-      } catch (IOException e) {
-          throw new IllegalStateException("Error processing jar: " + file , e);
-      }
-      return true;
-  }
-
-    public static long waitForListening(int port, boolean isHTTP, long beginTime)
-            throws InterruptedException {
-        long timeElapsedMillis = System.currentTimeMillis() - beginTime;
-        long sleepTimeMillis = 500L; // 0.5 secs
-
-        while (timeElapsedMillis < TIMEOUT_MILLIS) {
-            long timeRemaining = TIMEOUT_MILLIS - timeElapsedMillis;
-            sleepTimeMillis *= 2; // exponential backoff
-            long toSleep = (sleepTimeMillis > timeRemaining)
-                    ? timeRemaining : sleepTimeMillis;
-            Thread.sleep(toSleep);
-            timeElapsedMillis = System.currentTimeMillis() - beginTime;
-            if (isHTTP ? connectHTTP(port) : connectTCP(port)) {
-              log("Port is open: " + port);
-              return timeElapsedMillis;
-            }
-        }
-        throw new IllegalStateException("Timeout waiting for port: " + port);
-    }
-
-    private static void log(String msg) {
-        System.out.format("[SanityIT] [%s] %s %s", new Date().toString(), msg,
-                System.lineSeparator());
-    }
-
-    public static boolean connectTCP(int port) {
-      String host = CTRL_HOST.length() == 0 ? null : CTRL_HOST;
-      try {
-        Socket sock = new Socket(host, port);
-        sock.getPort();
-        try {
-          sock.close();
-        } catch (IOException ignore) {
-          // Can't close socket. Ingore and let downstream validate health
-        }
-        return true;
-      } catch (IOException ioe) {
-        return false;
-      }
-    }
-
-    public static boolean connectHTTP(int port) {
-        String host = CTRL_HOST.length() == 0 ? "localhost" : CTRL_HOST;
-        try {
-            URL url = new URL("http", host, port, "/");
-            HttpURLConnection con;
-            con = (HttpURLConnection) url.openConnection();
-            return (con.getResponseCode() > 0);
-        } catch (IOException e) {
-            return false;
-        }
-    }
-
-    private String stateToString(int state) {
-        switch (state) {
-            case Bundle.ACTIVE: return "ACTIVE";
-            case Bundle.INSTALLED: return "INSTALLED";
-            case Bundle.RESOLVED: return "RESOLVED";
-            case Bundle.UNINSTALLED: return "UNINSTALLED";
-            case Bundle.STARTING: return "STARTING";
-            case Bundle.STOPPING: return "STOPPING";
-            default: return "UNKNOWN: " + state;
-        }
-    }
-
-
-
-
-}
index f5c5620..09585d6 100644 (file)
@@ -21,12 +21,22 @@ import org.opendaylight.controller.sal.reader.NodeDescription;
 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsUpdatedBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsFromFlowTableOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowStatisticsOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllFlowsStatisticsFromAllFlowTablesOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAllNodeConnectorStatisticsOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsFromFlowTableOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetFlowStatisticsOutputBuilder;
@@ -292,4 +302,39 @@ public class FlowStatisticsAdapter implements OpendaylightFlowStatisticsService,
         return builder.build();
     }
 
+    @Override
+    public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForAllFlowsOutput>> getAggregateFlowStatisticsFromFlowTableForAllFlows(
+            GetAggregateFlowStatisticsFromFlowTableForAllFlowsInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> getAggregateFlowStatisticsFromFlowTableForGivenMatch(
+            GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> getAllFlowStatisticsFromFlowTable(
+            GetAllFlowStatisticsFromFlowTableInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> getAllFlowsStatisticsFromAllFlowTables(
+            GetAllFlowsStatisticsFromAllFlowTablesInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public Future<RpcResult<GetFlowStatisticsFromFlowTableOutput>> getFlowStatisticsFromFlowTable(
+            GetFlowStatisticsFromFlowTableInput input) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
 }
index 7dcd254..1ed1b68 100644 (file)
@@ -9,7 +9,7 @@ module opendaylight-match-types {
     revision "2013-10-26" {
         description "Initial revision of macth types";
     }
-
+    
     grouping "mac-address-filter" {
         leaf address {
             mandatory true;
@@ -61,14 +61,14 @@ module opendaylight-match-types {
         container vlan-id {
             description "VLAN id.";
             presence "Match field is active and set";
-            
+
+            leaf vlan-id-present {
+                type boolean;
+            }
+                        
             leaf vlan-id {
-                mandatory true;
                 type l2t:vlan-id; 
             }
-            leaf mask {
-                type binary;
-            }
         }
         leaf vlan-pcp {
             description "VLAN priority.";
index 81303d6..43754a1 100644 (file)
@@ -332,7 +332,11 @@ module opendaylight-action-types {
                  }            
              }
             }
-             
+
+           case strip-vlan-action-case {
+                container strip-vlan-action {
+                }
+             }
 
             case sw-path-action-case {            
                 container sw-path-action {
@@ -340,4 +344,4 @@ module opendaylight-action-types {
              }  
          }
      }
-}
\ No newline at end of file
+}
index e83306d..2bcd405 100644 (file)
@@ -12,6 +12,41 @@ module opendaylight-flow-types {
         description "Initial revision of flow service";
     }
     
+    typedef output-port-values {
+        type enumeration {
+            enum MAX {
+                value 1;
+            }
+            enum IN_PORT {
+                value 2;
+            }
+            enum TABLE {
+                value 3;
+            }
+            enum NORMAL {
+                value 4;
+            }
+            enum FLOOD {
+                value 5;
+            }
+            enum ALL {
+                value 6;
+            }
+            enum CONTROLLER {
+                value 7;
+            }
+            enum LOCAL {
+                value 8;
+            }
+            enum ANY {
+                value 9;
+            }
+            enum NONE {
+                value 10;
+            }
+
+        }
+    }
     grouping instruction-list {
         list instruction {
             key "order";
@@ -227,4 +262,4 @@ module opendaylight-flow-types {
             uses match:match;
         }
     }
-}
\ No newline at end of file
+}
index 3774f95..5e747e4 100644 (file)
@@ -11,6 +11,10 @@ module opendaylight-table-types {
         description "Initial revision of table service";
     }
 
+    typedef table-id {
+       type uint8;
+    }
+
     typedef table-ref {
         type instance-identifier;
     }
index d717e87..e55c50f 100644 (file)
@@ -15,7 +15,60 @@ module flow-node-inventory {
     revision "2013-08-19" {
         description "Flow Capable Node extensions to the Inventory model";
     }
-
+    
+    identity feature-capability {
+    }
+    
+    identity flow-feature-capability-flow-stats {
+        description "Flow statistics"; 
+        base feature-capability;      
+    }
+    
+    identity flow-feature-capability-table-stats {
+        description "Table statistics";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-port-stats {
+        description "Port statistics";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-stp {
+        description "802.1d spanning tree";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-reserved {
+        description "Reserved, must be zero";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-ip-reasm {
+        description "Can reassemble IP fragments";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-queue-stats {
+        description "Queue statistics";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-arp-match-ip {
+        description "Match IP addresses in ARP pkts";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-group-stats {
+        description "Group statistics";
+        base feature-capability;        
+    }
+    
+    identity flow-feature-capability-port-blocked {
+        description "Switch will block looping ports";
+        base feature-capability;        
+    }
+    
     grouping feature {
         leaf support-state {
             type inv:support-type;
@@ -70,7 +123,8 @@ module flow-node-inventory {
             uses meter:meter;
         }
     }
-
+    
+    
     grouping flow-node {
 
         leaf manufacturer {
@@ -122,6 +176,24 @@ module flow-node-inventory {
                 }
             }
         }
+        
+        container switch-features {
+            
+            leaf max_buffers {
+                type uint32;
+            }
+            
+            leaf max_tables {
+                type uint8;
+            }
+            
+            leaf-list capabilities {
+                type identityref {
+                    base feature-capability;
+                }
+            }
+            
+        }
     }
     
     grouping flow-node-connector {
@@ -149,9 +221,10 @@ module flow-node-inventory {
         ext:augment-identifier "flow-capable-node-connector-update-fields";
         uses flow-node-connector;
     }
-
+    
     augment "/inv:node-connector-updated" {
         ext:augment-identifier "flow-capable-node-connector-updated";
         uses flow-node-connector;
     }
+
 }
\ No newline at end of file
index 87d1559..3bd37bc 100644 (file)
@@ -3,28 +3,156 @@ module opendaylight-flow-statistics {
     prefix flowstat;
 
     import yang-ext {prefix ext; revision-date "2013-07-09";}
+    import ietf-yang-types {prefix yang; revision-date "2010-09-24";}   
     import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
     import opendaylight-flow-types {prefix flow-types;revision-date "2013-10-26";}
-    import sal-flow {prefix flow;}
     import opendaylight-statistics-types {prefix stat-types;revision-date "2013-09-25";}
+    import opendaylight-table-types {prefix table-types;revision-date "2013-10-26";}
+    import flow-node-inventory {prefix flow-node;revision-date "2013-08-19";}
+    import flow-capable-transaction {prefix tr;}
+    import sal-flow {prefix flow;}
+    
 
     revision "2013-08-19" {
-        description "Initial revision of flow service";
+        description "Initial revision of flow statistics service";
+    }
+       
+       //Augment flow statistics data to the flow-capable-node->table->flow
+       augment "/inv:nodes/inv:node/flow-node:table/flow-node:flow" {
+        ext:augment-identifier "flow-statistics-data";
+        uses flow-statistics;
+    }
+       
+       grouping flow-statistics {
+        container flow-statistics {
+            //config "false";
+               uses flow-types:flow;
+               uses stat-types:generic-statistics;
+        }
+       }    
+       
+       typedef flow-id {
+               description "flow id";
+               type yang:counter32;
+       }
+       
+       grouping flow-and-statistics-map-list {
+               description "List of flow and statistics map";
+               list flow-and-statistics-map-list {
+                       key "flow-id";
+                       leaf flow-id {
+                               type flow-id;
+                       }
+                       uses flow-and-statistics-map;
+               }
+       }
+       
+       grouping flow-and-statistics-map{
+               description "Mapping between flow and its statistics";
+               uses flow-types:flow;
+               uses stat-types:generic-statistics;
+       }
+       
+    // RPC calls to fetch flow statistics
+    rpc get-all-flows-statistics-from-all-flow-tables {
+       description "Fetch statistics of all the flow present in all the flow tables of the switch"; 
+        input {
+            uses inv:node-context-ref;
+        }
+        output {
+            uses flow-and-statistics-map-list;
+            uses tr:transaction-aware;
+        }
+    
     }
 
-    rpc get-node-connector-statistics {
+    rpc get-all-flow-statistics-from-flow-table {
+       description "Fetch statistics of all the flow present in the specific flow table of the switch"; 
         input {
             uses inv:node-context-ref;
-            leaf node-connector {
-                type inv:node-connector-ref;
+            leaf table-id {
+               type table-types:table-id;
             }
         }
         output {
-            uses stat-types:node-connector-statistics;
+            uses flow-and-statistics-map-list;
+            uses tr:transaction-aware;
         }
     }
 
-    rpc get-flow-statistics {
+    rpc get-flow-statistics-from-flow-table {
+       description "Fetch statistics of the specific flow present in the specific flow table of the switch"; 
+        input {
+            uses inv:node-context-ref;
+            uses flow-types:flow;
+        }
+        output {
+            uses flow-and-statistics-map-list;
+            uses tr:transaction-aware;
+        }
+    }
+
+    notification flows-statistics-update {
+       description "Flows statistics sent by switch";
+               leaf moreReplies {
+            type boolean;
+        }
+        uses inv:node;
+               uses flow-and-statistics-map-list;
+               uses tr:transaction-aware;
+    }
+
+       //Models for aggregate flow statistics collection
+       augment "/inv:nodes/inv:node/flow-node:table" {
+        ext:augment-identifier "aggregate-flow-statistics-data";
+        uses aggregate-flow-statistics;
+    }
+       
+       grouping aggregate-flow-statistics {
+        container aggregate-flow-statistics {
+            //config "false";
+               uses stat-types:aggregate-flow-statistics;
+        }
+       }    
+       
+    // RPC calls to fetch flow statistics
+    rpc get-aggregate-flow-statistics-from-flow-table-for-all-flows {
+       description "Fetch aggregate statistics for all the flows present in the specific flow table of the switch"; 
+        input {
+            uses inv:node-context-ref;
+            leaf table-id {
+               type table-types:table-id;
+            }
+        }
+        output {
+               uses stat-types:aggregate-flow-statistics;
+            uses tr:transaction-aware;
+        }
+    }
+    rpc get-aggregate-flow-statistics-from-flow-table-for-given-match {
+       description "Fetch aggregate statistics for all the flow matches to the given match from the given table of the switch"; 
+        input {
+            uses inv:node-context-ref;
+            uses flow-types:flow;
+        }
+        output {
+               uses stat-types:aggregate-flow-statistics;
+            uses tr:transaction-aware;
+        }
+    }
+
+    notification aggregate-flow-statistics-update {
+       description "Aggregate flow statistics for a table, sent by switch";
+               leaf moreReplies {
+            type boolean;
+        }
+        uses inv:node;
+               uses stat-types:aggregate-flow-statistics;
+               uses tr:transaction-aware;
+    }
+       
+       //Keeping flow statistics RPC call for backward compatibility for sal-compatibility layer --START
+       rpc get-flow-statistics {
         input {
             uses inv:node-context-ref;
             uses flow-types:flow;
@@ -45,6 +173,25 @@ module opendaylight-flow-statistics {
         }
     }
 
+    notification flow-statistics-updated {
+        uses flow-types:flow-statistics;
+    }
+       
+       //Keeping flow statistics RPC call for backward compatibility for sal-compatibility layer --END
+       
+       //RPC call to fetch node connector statistics
+    rpc get-node-connector-statistics {
+        input {
+            uses inv:node-context-ref;
+            leaf node-connector {
+                type inv:node-connector-ref;
+            }
+        }
+        output {
+            uses stat-types:node-connector-statistics;
+        }
+    }
+
     rpc get-all-node-connector-statistics {
         input {
             uses inv:node-context-ref;
@@ -56,10 +203,6 @@ module opendaylight-flow-statistics {
         }
     }
 
-    notification flow-statistics-updated {
-        uses flow-types:flow-statistics;
-    }
-
     rpc get-flow-table-statistics {
         input {
             uses inv:node-context-ref;
@@ -79,6 +222,4 @@ module opendaylight-flow-statistics {
     notification node-connector-statistics-updated {
         uses stat-types:node-connector-statistics;
     }
-
-
 }
diff --git a/opendaylight/md-sal/model/model-flow-statistics/src/main/yang/flow-table-statistics.yang b/opendaylight/md-sal/model/model-flow-statistics/src/main/yang/flow-table-statistics.yang
new file mode 100644 (file)
index 0000000..b823354
--- /dev/null
@@ -0,0 +1,69 @@
+module opendaylight-flow-table-statistics {
+    namespace "urn:opendaylight:flow:table:statistics";
+    prefix flowtablestat;
+
+       import flow-capable-transaction {prefix tr;}
+    import yang-ext {prefix ext; revision-date "2013-07-09";}
+    import ietf-yang-types {prefix yang; revision-date "2010-09-24";}
+    import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
+    import flow-node-inventory {prefix flow-node;revision-date "2013-08-19";}
+    import opendaylight-table-types {prefix table-types;revision-date "2013-10-26";}
+    import opendaylight-statistics-types {prefix stat-types;revision-date "2013-09-25";}
+    
+
+    contact
+        "Anilkumar Vishnoi
+        Email: avishnoi@in.ibm.com";
+
+    revision "2013-12-15" {
+        description "Initial revision of flow table statistics model";
+    }
+    
+    //Augment flow table statistics data to the table
+       augment "/inv:nodes/inv:node/flow-node:table" {
+        ext:augment-identifier "flow-table-statistics-data";
+        uses flow-table-statistics;
+    }
+       
+       grouping flow-table-statistics {
+        container flow-table-statistics {
+            //config "false";
+               uses stat-types:generic-table-statistics;
+        }
+       }    
+    
+    //RPC calls to fetch flow table statistics
+    grouping flow-table-and-statistics-map {
+       list flow-table-and-statistics-map {
+               key "table-id";
+               leaf table-id {
+                       type table-types:table-id;
+               }
+               uses stat-types:generic-table-statistics;
+       }
+    }
+    
+    rpc get-flow-tables-statistics {
+       description "Fetch statistics of all the flow tables present on the tarnet node";
+       input {
+               uses inv:node-context-ref;
+       }
+       output {
+               uses flow-table-and-statistics-map;
+               uses tr:transaction-aware;
+       }
+    }
+    
+    //Notification to receive table statistics update
+    
+    notification flow-table-statistics-update {
+       description "Receive flow table statistics update";
+       
+               leaf moreReplies {
+            type boolean;
+        }
+        uses inv:node;
+               uses flow-table-and-statistics-map;
+               uses tr:transaction-aware;
+    }
+}
diff --git a/opendaylight/md-sal/model/model-flow-statistics/src/main/yang/port-statistics.yang b/opendaylight/md-sal/model/model-flow-statistics/src/main/yang/port-statistics.yang
new file mode 100644 (file)
index 0000000..0cb6a60
--- /dev/null
@@ -0,0 +1,78 @@
+module opendaylight-port-statistics {
+    namespace "urn:opendaylight:port:statistics";
+    prefix portstat;
+
+       import flow-capable-transaction {prefix tr;}
+    import yang-ext {prefix ext; revision-date "2013-07-09";}
+    import ietf-yang-types {prefix yang; revision-date "2010-09-24";}   
+    import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
+    import opendaylight-statistics-types {prefix stat-types;revision-date "2013-09-25";}
+
+    contact
+        "Anilkumar Vishnoi
+        Email: avishnoi@in.ibm.com";
+
+    revision "2013-12-14" {
+        description "Initial revision of port statistics model";
+    }
+    
+    //Augment port statistics data to the flow-capable-node-connector
+       augment "/inv:nodes/inv:node/inv:node-connector" {
+        ext:augment-identifier "flow-capable-node-connector-statistics-data";
+        uses flow-capable-node-connector-statistics;
+    }
+       
+       grouping flow-capable-node-connector-statistics {
+        container flow-capable-node-connector-statistics {
+            //config "false";
+            uses stat-types:node-connector-statistics;
+        }
+       }    
+       
+    // RPC calls
+    rpc get-all-ports-statistics {
+       description "Get statistics for all the ports from the node";
+        input {
+            uses inv:node-context-ref;
+        }
+        output {
+            uses stat-types:node-connector-statistics;
+            uses tr:transaction-aware;
+        }
+    }
+    
+    rpc get-port-statistics {
+       description "Get statistics for given port from the node";
+       input {
+               uses inv:node-context-ref;
+               leaf node-connector-id {
+                       type inv:node-connector-id;
+               }
+       }
+       output {
+            uses stat-types:node-connector-statistics;
+            uses tr:transaction-aware;
+       }
+    }
+    
+    //Notification for port statistics update
+       grouping node-connector-statistics-and-port-number-map {
+               description "List of flow and statistics map";
+               list node-connector-statistics-and-port-number-map {
+                       key "node-connector-id";
+                       leaf node-connector-id {
+                               type inv:node-connector-id;
+                       }
+                       uses stat-types:node-connector-statistics;
+               }
+       }
+
+       notification port-statistics-update {
+        leaf moreReplies {
+            type boolean;
+        }
+        uses inv:node;
+               uses node-connector-statistics-and-port-number-map;
+        uses tr:transaction-aware;
+    }
+}
index d0b2e6a..6d5bec1 100644 (file)
@@ -60,4 +60,52 @@ module opendaylight-statistics-types {
             }
         }
     }
+    
+    grouping generic-statistics {
+       description "Generic grouping for statistics";
+        leaf packet-count {
+            type yang:counter64;
+        }
+
+        leaf byte-count {
+            type yang:counter64;
+        }
+
+        container duration {
+            leaf second {
+                type yang:counter64;
+            }
+            leaf nanosecond {
+                type yang:counter64;
+            }
+        }
+    }
+    
+    grouping generic-table-statistics {
+       description "Generic grouping holding generic statistics related to switch table";
+       leaf active-flows {
+            type yang:counter32;
+       }
+       leaf packets-looked-up {
+               type yang:counter64;
+       }
+       leaf packets-matched {
+               type yang:counter64;
+       }
+    }
+    
+    grouping aggregate-flow-statistics {
+       description "Aggregate flow statistics";
+        leaf packet-count {
+            type yang:counter64;
+        }
+
+        leaf byte-count {
+            type yang:counter64;
+        }
+        leaf flow-count {
+            type yang:counter32;
+        }
+    }
+    
 }
\ No newline at end of file
index b34621d..4f2b255 100644 (file)
         <sonar.host.url>https://sonar.opendaylight.org/</sonar.host.url>
         <sonar.branch>${user.name}-private-view</sonar.branch>
         <sonar.language>java</sonar.language>
+        <exam.version>3.0.0</exam.version>
     </properties>
 
     <pluginRepositories>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <version>1.8</version>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>${project.build.directory}/generated-sources/config</source>
+                                <source>${project.build.directory}/generated-sources/sal</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
diff --git a/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/RpcAvailabilityListener.java b/opendaylight/md-sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/RpcAvailabilityListener.java
new file mode 100644 (file)
index 0000000..e25b939
--- /dev/null
@@ -0,0 +1,5 @@
+package org.opendaylight.controller.sal.binding.api;
+
+public interface RpcAvailabilityListener {
+
+}
index f9f7209..1b0f783 100644 (file)
             <artifactId>ietf-inet-types</artifactId>
             <version>2010.09.24.2-SNAPSHOT</version>
         </dependency>
+        <dependency>
+        <groupId>org.opendaylight.yangtools.model</groupId>
+        <artifactId>ietf-topology-l3-unicast-igp</artifactId>
+        <version>2013.10.21.0-SNAPSHOT</version>
+        <scope>test</scope>
+        </dependency>
         <dependency>
                <groupId>org.opendaylight.controller.model</groupId>
                <artifactId>model-flow-base</artifactId>
index 74b6ad8..01dc6b8 100644 (file)
@@ -16,7 +16,7 @@ import java.util.concurrent.ScheduledExecutorService;
 import org.opendaylight.controller.config.yang.md.sal.binding.statistics.DataBrokerRuntimeMXBeanImpl;\r
 import org.opendaylight.controller.md.sal.common.impl.routing.AbstractDataReadRouter;\r
 import org.opendaylight.controller.sal.binding.impl.DataBrokerImpl;\r
-import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentDataServiceConnector;\r
+import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentConnector;\r
 import org.opendaylight.controller.sal.binding.impl.connect.dom.BindingIndependentMappingService;\r
 import org.opendaylight.controller.sal.core.api.Broker;\r
 import org.opendaylight.controller.sal.core.api.data.DataProviderService;\r
@@ -63,7 +63,7 @@ public final class DataBrokerImplModule extends
         BindingIndependentMappingService mappingService = getMappingServiceDependency();\r
         \r
         if (domBroker != null && mappingService != null) {\r
-            BindingIndependentDataServiceConnector runtimeMapping = new BindingIndependentDataServiceConnector();\r
+            BindingIndependentConnector runtimeMapping = new BindingIndependentConnector();\r
             runtimeMapping.setMappingService(mappingService);\r
             runtimeMapping.setBaDataService(dataBindingBroker);\r
             domBroker.registerProvider(runtimeMapping, getBundleContext());\r
index 1bf15c1..99b7ed8 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.config.yang.md.sal.binding.impl;
 
 import javassist.ClassPool;
 
+import org.opendaylight.controller.sal.binding.codegen.impl.SingletonHolder;
 import org.opendaylight.controller.sal.binding.dom.serializer.impl.RuntimeGeneratedMappingServiceImpl;
 import org.osgi.framework.BundleContext;
 
@@ -50,8 +51,7 @@ public final class RuntimeMappingModule extends
     @Override
     public java.lang.AutoCloseable createInstance() {
         RuntimeGeneratedMappingServiceImpl service = new RuntimeGeneratedMappingServiceImpl();
-        ClassPool pool = new ClassPool(); // Should be default singleton
-        service.setPool(pool);
+        service.setPool(SingletonHolder.CLASS_POOL);
         service.start(getBundleContext());
         return service;
     }
index f0f92da..dff0d21 100644 (file)
@@ -76,7 +76,6 @@ class RuntimeCodeHelper {
         if (field == null) throw new UnsupportedOperationException(
             "Unable to set routing table. Table field does not exists");
         field.set(target,routingTable);
-        
     }
 
 }
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.java
new file mode 100644 (file)
index 0000000..780d0bd
--- /dev/null
@@ -0,0 +1,161 @@
+package org.opendaylight.controller.sal.binding.codegen.impl;
+
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.controller.sal.binding.spi.RpcRouter;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import static org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.*;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.HashMap;
+
+import org.opendaylight.controller.sal.binding.spi.RpcRoutingTable;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.RpcImplementation;
+import org.opendaylight.controller.md.sal.common.api.routing.MutableRoutingTable;
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChange;
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
+import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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<?>> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RpcRouterCodegenInstance.class);
+
+    private T defaultService;
+
+    private final Class<T> serviceType;
+
+    private final T invocationProxy;
+
+    private final Set<Class<? extends BaseIdentity>> contexts;
+
+    private final ListenerRegistry<RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>>> listeners;
+
+    private final Map<Class<? extends BaseIdentity>, RpcRoutingTableImpl<? extends BaseIdentity, T>> routingTables;
+
+    public RpcRouterCodegenInstance(Class<T> type, T routerImpl, Set<Class<? extends BaseIdentity>> contexts,
+            Set<Class<? extends DataContainer>> inputs) {
+        this.listeners = ListenerRegistry.create();
+        this.serviceType = type;
+        this.invocationProxy = routerImpl;
+        this.contexts = ImmutableSet.copyOf(contexts);
+        Map<Class<? extends BaseIdentity>, RpcRoutingTableImpl<? extends BaseIdentity, T>> mutableRoutingTables = new HashMap<>();
+        for (Class<? extends BaseIdentity> ctx : contexts) {
+            RpcRoutingTableImpl<? extends BaseIdentity, T> table = new RpcRoutingTableImpl<>(ctx);
+            Map invokerView = table.getRoutes();
+            setRoutingTable((RpcService) invocationProxy, ctx, invokerView);
+            mutableRoutingTables.put(ctx, table);
+            table.registerRouteChangeListener(this);
+        }
+        this.routingTables = ImmutableMap.copyOf(mutableRoutingTables);
+    }
+
+    @Override
+    public Class<T> getServiceType() {
+        return serviceType;
+    }
+
+    @Override
+    public T getInvocationProxy() {
+        return invocationProxy;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <C extends BaseIdentity> RpcRoutingTable<C, T> getRoutingTable(Class<C> routeContext) {
+        return (RpcRoutingTable<C, T>) routingTables.get(routeContext);
+    }
+
+    @Override
+    public T getDefaultService() {
+        return defaultService;
+    }
+
+    @Override
+    public Set<Class<? extends BaseIdentity>> getContexts() {
+        return contexts;
+    }
+
+    @Override
+    public <L extends RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
+            L listener) {
+        return listeners.registerWithType(listener);
+    }
+
+    @Override
+    public void onRouteChange(RouteChange<Class<? extends BaseIdentity>, InstanceIdentifier<?>> change) {
+        for (ListenerRegistration<RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>>> listener : listeners) {
+            try {
+                listener.getInstance().onRouteChange(change);
+            } catch (Exception e) {
+                LOG.error("Error occured during invoker listener {}", listener.getInstance(), e);
+            }
+        }
+    }
+
+    @Override
+    public T getService(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+        return routingTables.get(context).getRoute(path);
+    }
+
+    @Override
+    public RoutedRpcRegistration<T> addRoutedRpcImplementation(T service) {
+        return new RoutedRpcRegistrationImpl(service);
+    }
+
+    @Override
+    public RpcRegistration<T> registerDefaultService(T service) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    private class RoutedRpcRegistrationImpl extends AbstractObjectRegistration<T> implements RoutedRpcRegistration<T> {
+
+        public RoutedRpcRegistrationImpl(T instance) {
+            super(instance);
+        }
+
+        @Override
+        public Class<T> getServiceType() {
+            return serviceType;
+        }
+
+        @Override
+        public void registerPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+            routingTables.get(context).updateRoute(path, getInstance());
+        }
+
+        @Override
+        public void unregisterPath(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
+            routingTables.get(context).removeRoute(path, getInstance());
+
+        }
+
+        @Override
+        public void registerInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance) {
+            registerPath(context, instance);
+        }
+
+        @Override
+        public void unregisterInstance(Class<? extends BaseIdentity> context, InstanceIdentifier<?> instance) {
+            unregisterPath(context, instance);
+        }
+
+        @Override
+        protected void removeRegistration() {
+
+        }
+    }
+}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRouterCodegenInstance.xtend
deleted file mode 100644 (file)
index b6dcde1..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.opendaylight.controller.sal.binding.codegen.impl
-
-import org.opendaylight.yangtools.yang.binding.RpcService
-import org.opendaylight.controller.sal.binding.spi.RpcRouter
-import org.opendaylight.yangtools.yang.binding.BaseIdentity
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import static extension org.opendaylight.controller.sal.binding.codegen.RuntimeCodeHelper.*
-import java.util.Set
-import java.util.HashMap
-import org.opendaylight.controller.sal.binding.spi.RpcRoutingTable
-import org.opendaylight.yangtools.yang.binding.DataContainer
-import org.opendaylight.yangtools.yang.binding.RpcImplementation
-
-class RpcRouterCodegenInstance<T extends RpcService> implements RpcRouter<T> {
-
-    @Property
-    val T invocationProxy
-
-    @Property
-    val RpcImplementation invokerDelegate;
-
-    @Property
-    val Class<T> serviceType
-
-    @Property
-    val Set<Class<? extends BaseIdentity>> contexts
-
-    @Property
-    val Set<Class<? extends DataContainer>> supportedInputs;
-
-    val routingTables = new HashMap<Class<? extends BaseIdentity>, RpcRoutingTableImpl<? extends BaseIdentity, ? extends RpcService>>;
-
-    @Property
-    var T defaultService
-
-    new(Class<T> type, T routerImpl, Set<Class<? extends BaseIdentity>> contexts,
-        Set<Class<? extends DataContainer>> inputs) {
-        _serviceType = type
-        _invocationProxy = routerImpl
-        _invokerDelegate = routerImpl as RpcImplementation
-        _contexts = contexts
-        _supportedInputs = inputs;
-
-        for (ctx : contexts) {
-            val table = XtendHelper.createRoutingTable(ctx)
-            invocationProxy.setRoutingTable(ctx, table.routes);
-            routingTables.put(ctx, table);
-        }
-    }
-
-    override <C extends BaseIdentity> getRoutingTable(Class<C> table) {
-        routingTables.get(table) as RpcRoutingTable<C,T>
-    }
-
-    override getService(Class<? extends BaseIdentity> context, InstanceIdentifier<?> path) {
-        val table = getRoutingTable(context);
-        return table.getRoute(path);
-    }
-
-    override <T extends DataContainer> invoke(Class<T> type, T input) {
-        return invokerDelegate.invoke(type, input);
-    }
-
-}
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.java
new file mode 100644 (file)
index 0000000..f959235
--- /dev/null
@@ -0,0 +1,125 @@
+package org.opendaylight.controller.sal.binding.codegen.impl;
+
+import org.opendaylight.controller.sal.binding.spi.RpcRoutingTable;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChangePublisher;
+import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener;
+import org.opendaylight.controller.md.sal.common.impl.routing.RoutingUtils;
+import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Mutable;
+
+class RpcRoutingTableImpl<C extends BaseIdentity, S extends RpcService> //
+implements //
+        Mutable, //
+        RpcRoutingTable<C, S>, //
+        RouteChangePublisher<Class<? extends BaseIdentity>, InstanceIdentifier<?>> {
+
+    private final Class<C> identifier;
+    private final ConcurrentMap<InstanceIdentifier<?>, S> routes;
+    private final Map<InstanceIdentifier<?>, S> unmodifiableRoutes;
+
+    private RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>> listener;
+    private S defaultRoute;
+
+    public RpcRoutingTableImpl(Class<C> identifier) {
+        super();
+        this.identifier = identifier;
+        this.routes = new ConcurrentHashMap<>();
+        this.unmodifiableRoutes = Collections.unmodifiableMap(routes);
+    }
+
+    @Override
+    public void setDefaultRoute(S target) {
+        defaultRoute = target;
+    }
+
+    @Override
+    public S getDefaultRoute() {
+        return defaultRoute;
+    }
+
+    @Override
+    public <L extends RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener(
+            L listener) {
+        return (ListenerRegistration<L>) new SingletonListenerRegistration<L>(listener);
+    }
+        
+    @Override
+    public Class<C> getIdentifier() {
+        return identifier;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void updateRoute(InstanceIdentifier<?> path, S service) {
+        S previous = this.routes.put(path, service);
+        @SuppressWarnings("rawtypes")
+        RouteChangeListener listenerCapture = listener;
+        if (previous == null && listenerCapture != null) {
+            listenerCapture.onRouteChange(RoutingUtils.announcementChange(identifier, path));
+        }
+    }
+
+    
+    @Override
+    @SuppressWarnings("unchecked")
+    public void removeRoute(InstanceIdentifier<?> path) {
+        S previous = this.routes.remove(path);
+        @SuppressWarnings("rawtypes")
+        RouteChangeListener listenerCapture = listener;
+        if (previous != null && listenerCapture != null) {
+            listenerCapture.onRouteChange(RoutingUtils.removalChange(identifier, path));
+        }
+    }
+    
+    public void removeRoute(InstanceIdentifier<?> path, S service) {
+        @SuppressWarnings("rawtypes")
+        RouteChangeListener listenerCapture = listener;
+        if (routes.remove(path, service) && listenerCapture != null) {
+            listenerCapture.onRouteChange(RoutingUtils.removalChange(identifier, path));
+        }
+    }
+
+    @Override
+    public S getRoute(InstanceIdentifier<?> nodeInstance) {
+        S route = routes.get(nodeInstance);
+        if (route != null) {
+            return route;
+        }
+        return getDefaultRoute();
+    }
+
+    @Override
+    public Map<InstanceIdentifier<?>, S> getRoutes() {
+        return unmodifiableRoutes;
+    }
+    
+    protected void removeAllReferences(S service) {
+        
+    }
+
+    private class SingletonListenerRegistration<L extends RouteChangeListener<Class<? extends BaseIdentity>, InstanceIdentifier<?>>> extends
+            AbstractObjectRegistration<L>
+            implements ListenerRegistration<L> {
+
+        public SingletonListenerRegistration(L instance) {
+            super(instance);
+            listener = instance;
+        }
+
+        @Override
+        protected void removeRegistration() {
+            listener = null;
+        }
+    }
+}
\ 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/RpcRoutingTableImpl.xtend b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/RpcRoutingTableImpl.xtend
deleted file mode 100644 (file)
index 116a817..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.opendaylight.controller.sal.binding.codegen.impl
-
-import org.opendaylight.controller.sal.binding.spi.RpcRoutingTable
-import org.opendaylight.yangtools.yang.binding.BaseIdentity
-import org.opendaylight.yangtools.yang.binding.RpcService
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
-import java.util.Map
-import org.opendaylight.yangtools.yang.binding.DataObject
-import java.util.HashMap
-
-class RpcRoutingTableImpl<C extends BaseIdentity,S extends RpcService> implements RpcRoutingTable<C,S>{
-    
-    @Property
-    val Class<C> identifier;
-    
-    @Property
-    var S defaultRoute;
-    
-    @Property
-    val Map<InstanceIdentifier<? extends DataObject>,S> routes;
-    
-    new(Class<C> ident, Map<InstanceIdentifier<? extends DataObject>,S> route) {
-        _identifier = ident
-        _routes = route
-    }
-    
-    new(Class<C> ident) {
-        _identifier = ident
-        _routes = new HashMap
-    }
-    
-    
-    override getRoute(InstanceIdentifier<? extends Object> nodeInstance) {
-        val ret = routes.get(nodeInstance);
-        if(ret !== null) {
-            return ret;
-        }
-        return defaultRoute;
-    }
-    
-    override removeRoute(InstanceIdentifier<? extends Object> path) {
-        routes.remove(path);
-    }
-    
-    @SuppressWarnings("rawtypes")
-    override updateRoute(InstanceIdentifier<? extends Object> path, S service) {
-        routes.put(path as InstanceIdentifier<? extends DataObject>,service);
-    }
-}
\ No newline at end of file
index 90fcbd9..7ebcf02 100644 (file)
@@ -27,7 +27,7 @@ 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.controller.sal.binding.impl.util.ClassLoaderUtils.*
+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
@@ -37,6 +37,8 @@ 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.controller.sal.binding.codegen.util.JavassistUtils
+import org.opendaylight.controller.sal.binding.impl.util.ClassLoaderUtils
+import javassist.LoaderClassPath
 
 class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator, NotificationInvokerFactory {
 
@@ -45,40 +47,70 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
     val extension JavassistUtils utils;
     val Map<Class<? extends NotificationListener>, RuntimeGeneratedInvokerPrototype> invokerClasses;
 
-    public new(ClassPool pool) {
+
+    new(ClassPool pool) {
         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));
     }
 
     override <T extends RpcService> getDirectProxyFor(Class<T> iface) {
-        val supertype = iface.asCtClass
-        val targetCls = createClass(iface.directProxyName, supertype) [
-            field(DELEGATE_FIELD, iface);
-            implementMethodsFrom(supertype) [
-                body = '''
-                {
-                    if(«DELEGATE_FIELD» == null) {
+        val T instance =  withClassLoaderAndLock(iface.classLoader,lock) [|
+            val proxyName = iface.directProxyName;
+            val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(proxyName)
+            if(potentialClass != null) {
+                return potentialClass.newInstance as T;
+            }
+            val supertype = iface.asCtClass
+            val createdCls = createClass(iface.directProxyName, supertype) [
+                field(DELEGATE_FIELD, iface);
+                implementsType(RpcImplementation.asCtClass)
+                implementMethodsFrom(supertype) [
+                    body = '''
+                    {
+                        if(«DELEGATE_FIELD» == null) {
+                            throw new java.lang.IllegalStateException("No provider is processing supplied message");
+                        }
+                        return ($r) «DELEGATE_FIELD».«it.name»($$);
+                    }
+                    '''
+                ]
+                implementMethodsFrom(RpcImplementation.asCtClass) [
+                    body = '''
+                    {
                         throw new java.lang.IllegalStateException("No provider is processing supplied message");
+                        return ($r) null;
                     }
-                    return ($r) «DELEGATE_FIELD».«it.name»($$);
-                }
-                '''
+                    '''
+                ]
             ]
+            return createdCls.toClass(iface.classLoader).newInstance as T
         ]
-        return targetCls.toClass(iface.classLoader).newInstance as T
+        return instance;
     }
 
     override <T extends RpcService> getRouterFor(Class<T> iface) {
-        val instance = <RpcRouterCodegenInstance<T>>withClassLoaderAndLock(iface.classLoader,lock) [ |
+        val metadata = withClassLoader(iface.classLoader) [|
+            val supertype = iface.asCtClass
+            return supertype.rpcMetadata;
+        ]
+        
+        val instance = <T>withClassLoaderAndLock(iface.classLoader,lock) [ |
             val supertype = iface.asCtClass
-            val metadata = supertype.rpcMetadata;
+            val routerName = iface.routerName;
+            val potentialClass = ClassLoaderUtils.tryToLoadClassWithTCCL(routerName)
+            if(potentialClass != null) {
+                return potentialClass.newInstance as T;
+            }
+            
             val targetCls = createClass(iface.routerName, supertype) [
-                addInterface(RpcImplementation.asCtClass)
+                
                 
                 field(DELEGATE_FIELD, iface)
                 //field(REMOTE_INVOKER_FIELD,iface);
+                implementsType(RpcImplementation.asCtClass)
                 
                 for (ctx : metadata.contexts) {
                     field(ctx.routingTableField, Map)
@@ -105,35 +137,18 @@ class RuntimeCodeGenerator implements org.opendaylight.controller.sal.binding.co
                     }
                 ]
                 implementMethodsFrom(RpcImplementation.asCtClass) [
-                    switch (name) {
-                        case "getSupportedInputs":
-                            body = '''
-                            {
-                                throw new java.lang.UnsupportedOperationException("Not implemented yet");
-                                return ($r) null;
-                            }'''
-                        case "invoke": {
-                            val tmpBody = '''
-                            {
-                                «FOR input : metadata.supportedInputs SEPARATOR " else "»
-                                «val rpcMetadata = metadata.rpcInputs.get(input)»
-                                if(«input.name».class.equals($1)) {
-                                    return ($r) this.«rpcMetadata.methodName»((«input.name») $2);
-                                }
-                                «ENDFOR»
-                                throw new java.lang.IllegalArgumentException("Not supported message type");
-                                return ($r) null;
-                            }
-                            '''
-                            body = tmpBody
-                        }
+                    body = '''
+                    {
+                        throw new java.lang.IllegalStateException("No provider is processing supplied message");
+                        return ($r) null;
                     }
+                    '''
                 ]
             ]
-            val instance = targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance as T
-            return new RpcRouterCodegenInstance(iface, instance, metadata.contexts,metadata.supportedInputs);
+            return targetCls.toClass(iface.classLoader,iface.protectionDomain).newInstance as T
+            
         ];
-        return instance;
+        return new RpcRouterCodegenInstance(iface, instance, metadata.contexts,metadata.supportedInputs);
     }
 
     private def RpcServiceMetadata getRpcMetadata(CtClass iface) {
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/SingletonHolder.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/codegen/impl/SingletonHolder.java
new file mode 100644 (file)
index 0000000..266293f
--- /dev/null
@@ -0,0 +1,14 @@
+package org.opendaylight.controller.sal.binding.codegen.impl;
+
+import org.opendaylight.controller.sal.binding.codegen.RuntimeCodeGenerator;
+import org.opendaylight.controller.sal.binding.spi.NotificationInvokerFactory;
+
+import javassist.ClassPool;
+
+public class SingletonHolder {
+
+    public static final ClassPool CLASS_POOL = new ClassPool(); 
+    public static final org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator RPC_GENERATOR_IMPL = new org.opendaylight.controller.sal.binding.codegen.impl.RuntimeCodeGenerator(CLASS_POOL);
+    public static final RuntimeCodeGenerator RPC_GENERATOR = RPC_GENERATOR_IMPL;
+    public static final NotificationInvokerFactory INVOKER_FACTORY = RPC_GENERATOR_IMPL.getInvokerFactory();
+}
index 4b672f1..f1ba584 100644 (file)
@@ -175,7 +175,7 @@ public class LazyGeneratedCodecRegistry implements //
                     });
             return ret;
         } catch (Exception e) {
-            LOG.error("Could not find augmentable for {}", augmentation, e);
+            LOG.debug("Could not find augmentable for {} using {}", augmentation, augmentation.getClassLoader(), e);
             return null;
         }
     }
index 853e62a..1b3acf7 100644 (file)
@@ -43,6 +43,11 @@ import java.util.ArrayList
 import org.opendaylight.yangtools.yang.data.api.Node
 import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl
 import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl
+import org.opendaylight.yangtools.yang.binding.RpcService
+import java.util.Set
+import org.opendaylight.yangtools.yang.common.QName
+import com.google.common.collect.FluentIterable
+import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
 
 class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingService, SchemaServiceListener, AutoCloseable {
 
@@ -65,6 +70,9 @@ class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingSer
 
     @Property
     val ConcurrentMap<Type, SchemaNode> typeToSchemaNode = new ConcurrentHashMap();
+    
+    @Property
+    val ConcurrentMap<Type,Set<QName>> serviceTypeToRpc = new ConcurrentHashMap(); 
 
     val promisedTypeDefinitions = HashMultimap.<Type, SettableFuture<GeneratedTypeBuilder>>create;
 
@@ -85,10 +93,17 @@ class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingSer
 
             registry.onModuleContextAdded(schemaContext, entry.key, entry.value);
             binding.pathToType.putAll(entry.value.childNodes)
-            //val module = entry.key;
+            val module = entry.key;
             val context = entry.value;
             updateBindingFor(context.childNodes, schemaContext);
             updateBindingFor(context.cases, schemaContext);
+            val namespace = BindingGeneratorUtil.moduleNamespaceToPackageName(module);
+            
+            if(!module.rpcs.empty) {
+            val rpcs = FluentIterable.from(module.rpcs).transform[QName].toSet
+            val serviceClass = new ReferencedTypeImpl(namespace,BindingGeneratorUtil.parseToClassName(module.name)+"Service");
+                serviceTypeToRpc.put(serviceClass,rpcs);
+            }
 
             val typedefs = context.typedefs;
             for (typedef : typedefs.entrySet) {
@@ -186,15 +201,7 @@ class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingSer
     }
 
     override dataObjectFromDataDom(InstanceIdentifier<? extends DataObject> path, CompositeNode node) {
-        return tryDeserialization[ |
-            if (node == null) {
-                return null;
-            }
-            val targetType = path.targetType
-            val transformer = registry.getCodecForDataObject(targetType);
-            val ret = transformer.deserialize(node)?.value as DataObject;
-            return ret;
-        ]
+         dataObjectFromDataDom(path.targetType,node) as DataObject;
     }
 
     override fromDataDom(org.opendaylight.yangtools.yang.data.api.InstanceIdentifier entry) {
@@ -243,6 +250,10 @@ class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingSer
             listenerRegistration = ctx.registerService(SchemaServiceListener, this, new Hashtable<String, String>());
         }
     }
+    
+    override getRpcQNamesFor(Class<? extends RpcService> service) {
+        return serviceTypeToRpc.get(new ReferencedTypeImpl(service.package.name,service.simpleName));
+    }
 
     private def getSchemaWithRetry(Type type) {
         val typeDef = typeToSchemaNode.get(type);
@@ -274,5 +285,16 @@ class RuntimeGeneratedMappingServiceImpl implements BindingIndependentMappingSer
     override close() throws Exception {
         listenerRegistration?.unregister();
     }
+    
+    override dataObjectFromDataDom(Class<? extends DataContainer> container, CompositeNode domData) {
+        return tryDeserialization[ |
+            if (domData == null) {
+                return null;
+            }
+            val transformer = registry.getCodecForDataObject(container);
+            val ret = transformer.deserialize(domData)?.value as DataObject;
+            return ret;
+        ]
+    }
 
 }
index 87c3286..4271ef9 100644 (file)
@@ -827,6 +827,11 @@ class TransformerGenerator {
                 val ret = ctCls.toClassImpl(inputType.classLoader, inputType.protectionDomain)
                 return ret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;
             }
+            if (returnType.name == 'char[]') {
+                val ctCls = createUnionImplementation(inputType, typeSpec);
+                val ret = ctCls.toClassImpl(inputType.classLoader, inputType.protectionDomain)
+                return ret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;
+            }
 
             val ctCls = createClass(typeSpec.codecClassName) [
                 //staticField(Map,"AUGMENTATION_SERIALIZERS");
@@ -897,6 +902,73 @@ class TransformerGenerator {
 
     }
 
+    def createUnionImplementation(Class<?> inputType, GeneratedTransferObject typeSpec) {
+        return createClass(typeSpec.codecClassName) [
+            val properties = typeSpec.allProperties;
+            //staticField(Map,"AUGMENTATION_SERIALIZERS");
+            if (inputType.isYangBindingAvailable) {
+                implementsType(BINDING_CODEC)
+                staticField(it, INSTANCE_IDENTIFIER_CODEC, BindingCodec)
+                staticField(it, IDENTITYREF_CODEC, BindingCodec)
+                implementsType(BindingDeserializer.asCtClass)
+            }
+            method(Object, "toDomValue", Object) [
+                modifiers = PUBLIC + FINAL + STATIC
+                val ctSpec = inputType.asCtClass;
+                bodyChecked = '''
+                    {
+                        //System.out.println("«inputType.simpleName»#toDomValue: "+$1);
+                        
+                        if($1 == null) {
+                            return null;
+                        }
+                        «typeSpec.resolvedName» _value = («typeSpec.resolvedName») $1;
+                        «FOR property : properties.entrySet»
+                            «IF property.key != "getValue"»
+                                «property.value.resolvedName» «property.key» = («property.value.resolvedName») _value.«property.key»();
+                                if(«property.key» != null) { 
+                                    return «serializeValue(property.value, property.key)»;
+                                }
+                            «ENDIF»
+                        «ENDFOR»
+                        
+                        return null;
+                    }
+                '''
+            ]
+            method(Object, "serialize", Object) [
+                bodyChecked = '''
+                    {
+                        return toDomValue($1);
+                    }
+                '''
+            ]
+            method(Object, "fromDomValue", Object) [
+                modifiers = PUBLIC + FINAL + STATIC
+                bodyChecked = '''
+                    {
+                        //System.out.println("«inputType.simpleName»#fromDomValue: "+$1);
+                        
+                        if($1 == null) {
+                            return null;
+                        }
+                        if($1 instanceof String) {
+                            String _simpleValue = (String) $1;
+                            return new «typeSpec.resolvedName»(_simpleValue.toCharArray());
+                        }
+                        return null;
+                    }
+                '''
+            ]
+            method(Object, "deserialize", Object) [
+                bodyChecked = '''{
+                            return fromDomValue($1);
+                    }
+                    '''
+            ]
+        ]
+    }
+
     def boolean isYangBindingAvailable(Class<?> class1) {
         try {
             val bindingCodecClass = class1.classLoader.loadClass(BINDING_CODEC.name);
@@ -1221,6 +1293,9 @@ class TransformerGenerator {
         } else if (CLASS_TYPE.equals(signature)) {
             return '''(«QName.resolvedName») «IDENTITYREF_CODEC».serialize(«property»)'''
         }
+        if ("char[]" == signature.name) {
+            return '''new String(«property»)''';
+        }
         return '''«property»''';
     }
 
index 9381a5a..8d3545f 100644 (file)
@@ -13,7 +13,6 @@ import org.opendaylight.yangtools.yang.binding.RpcService
 import javassist.ClassPool
 import org.osgi.framework.BundleContext
 import java.util.Map
-import java.util.HashMap
 import javassist.LoaderClassPath
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
 import java.util.Hashtable
@@ -49,29 +48,14 @@ import java.util.concurrent.Callable
 import java.util.WeakHashMap
 import javax.annotation.concurrent.GuardedBy
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry
+import org.opendaylight.yangtools.concepts.ListenerRegistration
+import org.opendaylight.yangtools.concepts.util.ListenerRegistry
 
-class BindingAwareBrokerImpl implements BindingAwareBroker, RpcProviderRegistry, AutoCloseable {
+class BindingAwareBrokerImpl extends RpcProviderRegistryImpl implements BindingAwareBroker, AutoCloseable {
     private static val log = LoggerFactory.getLogger(BindingAwareBrokerImpl)
 
     private InstanceIdentifier<? extends DataObject> root = InstanceIdentifier.builder().toInstance();
 
-    private static val clsPool = ClassPool.getDefault()
-    public static var RuntimeCodeGenerator generator;
-
-    /**
-     * Map of all Managed Direct Proxies
-     * 
-     */
-    private val Map<Class<? extends RpcService>, RpcProxyContext> managedProxies = new ConcurrentHashMap();
-
-    /**
-     * 
-     * Map of all available Rpc Routers
-     * 
-     * 
-     */
-    private val Map<Class<? extends RpcService>, RpcRouter<? extends RpcService>> rpcRouters = new WeakHashMap();
-
     @Property
     private var NotificationProviderService notifyBroker
 
@@ -81,43 +65,15 @@ class BindingAwareBrokerImpl implements BindingAwareBroker, RpcProviderRegistry,
     @Property
     var BundleContext brokerBundleContext
 
-    ServiceRegistration<NotificationProviderService> notifyProviderRegistration
-
-    ServiceRegistration<NotificationService> notifyConsumerRegistration
-
-    ServiceRegistration<DataProviderService> dataProviderRegistration
-
-    ServiceRegistration<DataBrokerService> dataConsumerRegistration
-
-    private val proxyGenerationLock = new ReentrantLock;
-
-    private val routerGenerationLock = new ReentrantLock;
-
     public new(BundleContext bundleContext) {
         _brokerBundleContext = bundleContext;<