import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- * Every time factory is added or removed, blank transaction is triggered to handle
- * {@link org.opendaylight.controller.config.spi.ModuleFactory#getDefaultModules(org.opendaylight.controller.config.api.DependencyResolverFactory, org.osgi.framework.BundleContext)}
- * functionality.
- */
public class BindingIndependentMappingServiceTracker implements ServiceTrackerCustomizer<BindingIndependentMappingService, BindingIndependentMappingService> {
private static final Logger logger = LoggerFactory.getLogger(BindingIndependentMappingServiceTracker.class);
BindingIndependentMappingService service = ctx.getService(moduleFactoryServiceReference);
this.service = service;
CodecRegistry codecRegistry = service.getCodecRegistry();
- logger.warn("Codec registry acquired {}", codecRegistry);
+ logger.debug("Codec registry acquired {}", codecRegistry);
activator.initConfigManager(ctx, codecRegistry);
return service;
}
}
@Override
- public void removedService(ServiceReference<BindingIndependentMappingService> moduleFactoryServiceReference, BindingIndependentMappingService o) {
+ public void removedService(ServiceReference<BindingIndependentMappingService> moduleFactoryServiceReference, BindingIndependentMappingService o) {
// TODO crash
}
}
return mock(CodecRegistry.class);
}
-
public static interface BundleContextServiceRegistrationHandler {
void handleServiceRegistration(Object serviceInstance);
--- /dev/null
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-subsystem</artifactId>
+ <version>0.2.4-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>config-module-archetype</artifactId>
+ <name>config-module-archetype</name>
+ <description>Archetype for new module managed by configuration subsystem</description>
+
+</project>
--- /dev/null
+<archetype>
+ <id>config-module-archetype</id>
+
+ <allowPartial>true</allowPartial>
+
+ <requiredProperties>
+ <requiredProperty key="module-name">
+ </requiredProperty>
+ <requiredProperty key="module-name-java-prefix">
+ </requiredProperty>
+ <requiredProperty key="module-implementation-name">
+ <defaultValue>impl</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="config-api-yang-revision">
+ <defaultValue>2013-04-05</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="config-api-version">
+ <defaultValue>0.2.4-SNAPSHOT</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="yang-maven-plugin-version">
+ <defaultValue>0.6.2-SNAPSHOT</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="revision">
+ <defaultValue>2014-01-31</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="service-java-class">
+ <defaultValue>java.lang.AutoCloseable</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="maven-bundle-plugin-version">
+ <defaultValue>2.4.0</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="yang-namespace-mapping-from">
+ <defaultValue>urn:opendaylight:params:xml:ns:yang:controller</defaultValue>
+ </requiredProperty>
+ <requiredProperty key="yang-namespace-mapping-to">
+ <defaultValue>org.opendaylight.controller.config.yang</defaultValue>
+ </requiredProperty>
+
+ </requiredProperties>
+
+ <fileSets>
+ <fileSet filtered="true" encoding="UTF-8">
+ <directory>src/main/yang</directory>
+ </fileSet>
+ </fileSets>
+</archetype>
--- /dev/null
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>${groupId}</groupId>
+ <artifactId>${artifactId}</artifactId>
+ <version>${version}</version>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <jmxGeneratorPath>${project.build.directory}/generated-sources/config</jmxGeneratorPath>
+ <config.version>${config-api-version}</config.version>
+ <maven.bundle.version>${maven-bundle-plugin-version}</maven.bundle.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-api</artifactId>
+ <version>${config.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <version>${yang-maven-plugin-version}</version>
+ <executions>
+ <execution>
+ <id>config</id>
+ <goals>
+ <goal>generate-sources</goal>
+ </goals>
+ <configuration>
+ <codeGenerators>
+ <generator>
+ <codeGeneratorClass>
+ org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+ </codeGeneratorClass>
+ <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+ <additionalConfiguration>
+ <namespaceToPackage1>
+ ${yang-namespace-mapping-from}==${yang-namespace-mapping-to}
+ </namespaceToPackage1>
+ </additionalConfiguration>
+ </generator>
+ </codeGenerators>
+ <inspectDependencies>true</inspectDependencies>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>yang-jmx-generator-plugin</artifactId>
+ <version>${config.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.8</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${jmxGeneratorPath}</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven.bundle.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ ${yang-namespace-mapping-to}.${module-name},
+ </Export-Package>
+ <Import-Package>
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+
+
+ </plugins>
+ </build>
+</project>
--- /dev/null
+// vi: set smarttab et sw=4 tabstop=4:
+module ${module-name}-${module-implementation-name} {
+
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:controller:config:${module-name}:${module-implementation-name}";
+ prefix "${module-name}-${module-implementation-name}";
+
+ import config { prefix config; revision-date ${config-api-yang-revision}; }
+ import ${module-name} { prefix ${module-name}; revision-date ${revision}; }
+
+ description
+ "This module contains the base YANG definitions for
+ ${module-name} ${module-implementation-name} implementation.";
+
+ revision "${revision}" {
+ description
+ "Initial revision.";
+ }
+
+ // This is the definition of a service implementation
+ identity ${module-name}-${module-implementation-name} {
+ base config:module-type;
+ config:provided-service ${module-name}:${module-name};
+ config:java-name-prefix ${module-name-java-prefix};
+ }
+
+ augment "/config:modules/config:module/config:configuration" {
+ case ${module-name}-${module-implementation-name} {
+ when "/config:modules/config:module/config:type = '${module-name}-${module-implementation-name}'";
+
+ leaf simple-attribute {
+ type uint32;
+ }
+
+ container dto-attribute {
+ leaf inner-attribute {
+ type string;
+ }
+ }
+
+ // Dependency attribute demonstration, the config:required-identity points to a service type
+ // In this case it is the same service type as this implementation provides: ${module-name}
+ container dependency-attribute {
+ uses config:service-ref {
+ refine type {
+ mandatory false;
+ config:required-identity ${module-name}:${module-name};
+ }
+ }
+ }
+
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+// vi: set smarttab et sw=4 tabstop=4:
+module ${module-name} {
+
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:controller:config:${module-name}";
+ prefix "${module-name}";
+
+ import config { prefix config; revision-date ${config-api-yang-revision}; }
+
+ description
+ "This module contains the base YANG definitions for
+ ${module-name} services.";
+
+ revision "${revision}" {
+ description
+ "Initial revision.";
+ }
+
+ // This is the definition of a service
+ identity ${module-name} {
+
+ base "config:service-type";
+
+ // TODO modify the java class
+ config:java-class " ${service-java-class}";
+ }
+}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<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">
+<!-- vi: set et smarttab sw=4 tabstop=4: --><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>
<module>yang-test-plugin</module>
<module>shutdown-api</module>
<module>shutdown-impl</module>
+ <module>config-module-archetype</module>
</modules>
<profiles>
</goals>
</pluginExecutionFilter>
<action>
- <ignore />
+ <ignore/>
</action>
</pluginExecution>
</pluginExecutions>
</plugins>
</pluginManagement>
</build>
-</project>
+</project>
\ No newline at end of file
</dependency>
</dependencies>
+
+
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>
+ org.opendaylight.controller
+ </groupId>
+ <artifactId>
+ yang-test-plugin
+ </artifactId>
+ <versionRange>
+ [0.2.3,)
+ </versionRange>
+ <goals>
+ <goal>
+ delete-sources
+ </goal>
+ <goal>
+ process-sources
+ </goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore/>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
<plugins>
<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>commons.opendaylight</artifactId>
- <version>1.4.2-SNAPSHOT</version>
- <relativePath>../../commons/opendaylight</relativePath>
- </parent>
- <scm>
- <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
- <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
- <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
- <tag>HEAD</tag>
- </scm>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.opendaylight</artifactId>
+ <version>1.4.2-SNAPSHOT</version>
+ <relativePath>../../commons/opendaylight</relativePath>
+ </parent>
+ <scm>
+ <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+ <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+ <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
+ <tag>HEAD</tag>
+ </scm>
- <artifactId>logging.bridge</artifactId>
- <version>0.4.2-SNAPSHOT</version>
- <packaging>bundle</packaging>
+ <artifactId>logging.bridge</artifactId>
+ <version>0.4.2-SNAPSHOT</version>
+ <packaging>bundle</packaging>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
- <dependency>
- <groupId>equinoxSDK381</groupId>
- <artifactId>org.eclipse.osgi</artifactId>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${bundle.plugin.version}</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Import-Package>
- org.slf4j,
- org.osgi.framework,
- org.osgi.service.log
- </Import-Package>
- <Bundle-Activator>
- org.opendaylight.controller.logging.bridge.internal.Activator
- </Bundle-Activator>
- </instructions>
- <manifestLocation>${project.basedir}/META-INF</manifestLocation>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${bundle.plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ org.slf4j,
+ org.osgi.framework,
+ org.osgi.service.log
+ </Import-Package>
+ <Bundle-Activator>
+ org.opendaylight.controller.logging.bridge.internal.Activator
+ </Bundle-Activator>
+ </instructions>
+ <manifestLocation>${project.basedir}/META-INF</manifestLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
if (this.logger != null) {
switch (entry.getLevel()) {
case LogService.LOG_DEBUG:
- this.logger.debug("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.debug("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
case LogService.LOG_INFO:
- this.logger.info("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.info("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
case LogService.LOG_WARNING:
- this.logger.warn("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.warn("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
case LogService.LOG_ERROR:
- this.logger.error("Bundle:{} Message:{} Exception:{}", entry.getBundle()
+ this.logger.error("Bundle:{} Message:{}", entry.getBundle()
.getSymbolicName(), entry.getMessage(), entry.getException());
break;
}
--- /dev/null
+/*
+ * 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.logging.bridge.internal;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+public class LogListenerImplTest {
+ private static final Logger logger = LoggerFactory.getLogger(LogListenerImplTest.class);
+
+ @Test
+ public void test() {
+ LogListenerImpl tested = new LogListenerImpl(logger);
+ tested.logged(getEntry("m1", null));
+ tested.logged(getEntry("m2", new RuntimeException()));
+ }
+
+ private LogEntry getEntry(final String message, final Exception e) {
+ return new LogEntry() {
+ @Override
+ public Bundle getBundle() {
+ Bundle mock = mock(Bundle.class);
+ doReturn(null).when(mock).getSymbolicName();
+ return mock;
+ }
+
+ @Override
+ public ServiceReference getServiceReference() {
+ return null;
+ }
+
+ @Override
+ public int getLevel() {
+ return LogService.LOG_INFO;
+ }
+
+ @Override
+ public String getMessage() {
+ return message;
+ }
+
+ @Override
+ public Throwable getException() {
+ return e;
+ }
+
+ @Override
+ public long getTime() {
+ return 0;
+ }
+ };
+ }
+
+}
grouping set-field-match {
list set-field-match {
+ key "match-type";
leaf match-type {
type identityref {
base match-field;
*/
package org.opendaylight.controller.test.sal.binding.it;
-import static org.ops4j.pax.exam.CoreOptions.*;
-import static org.opendaylight.controller.test.sal.binding.it.TestHelper.*;
-
-import javax.inject.Inject;
-
import org.junit.runner.RunWith;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.DefaultCompositeOption;
import org.ops4j.pax.exam.util.Filter;
-import org.ops4j.pax.exam.util.PathUtils;
import org.osgi.framework.BundleContext;
+import javax.inject.Inject;
+
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles;
+import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
@RunWith(PaxExam.class)
public abstract class AbstractTest {
public static final String YANGTOOLS_MODELS = "org.opendaylight.yangtools.model";
@Inject
- @Filter(timeout=60*1000)
+ @Filter(timeout=120*1000)
BindingAwareBroker broker;
@Inject
}\r
\r
def void publishDataChangeEvent(ImmutableList<ListenerStateCapture<P, D, DCL>> listeners) {\r
- for (listenerSet : listeners) {\r
- val updatedConfiguration = dataBroker.readConfigurationData(listenerSet.path);\r
- val updatedOperational = dataBroker.readOperationalData(listenerSet.path);\r
-\r
- val changeEvent = new DataChangeEventImpl(transaction, listenerSet.initialConfigurationState,\r
- listenerSet.initialOperationalState, updatedOperational, updatedConfiguration);\r
- for (listener : listenerSet.listeners) {\r
- try {\r
- listener.instance.onDataChanged(changeEvent);\r
-\r
- } catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
+ dataBroker.executor.submit [|\r
+ for (listenerSet : listeners) {
+ val updatedConfiguration = dataBroker.readConfigurationData(listenerSet.path);
+ val updatedOperational = dataBroker.readOperationalData(listenerSet.path);
+
+ val changeEvent = new DataChangeEventImpl(transaction, listenerSet.initialConfigurationState,
+ listenerSet.initialOperationalState, updatedOperational, updatedConfiguration);
+ for (listener : listenerSet.listeners) {
+ try {
+ listener.instance.onDataChanged(changeEvent);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ } \r
+ ]\r
}\r
\r
def rollback(List<DataCommitTransaction<P, D>> transactions, Exception e) {\r
leaf connection-timeout-millis {
description "Specifies timeout in milliseconds after which connection must be established.";
type uint32;
- default 5000;
+ default 20000;
}
leaf max-connection-attempts {
contact "Martin Bobak <mbobak@cisco.com>";
description
- "This module contains the definition of types related to
- Internet Assigned Numbers Authority.
+ "This module contains the definition of methods related to
+ sal remote model.
Copyright (c)2013 Cisco Systems, Inc. All rights reserved.
notification data-changed-notification {
description "Data change notification.";
- leaf data-change-event {
- type instance-identifier;
+ list data-change-event {
+ key path;
+ leaf path {
+ type instance-identifier;
+ }
+ leaf store {
+ type enumeration {
+ enum config;
+ enum operation;
+ }
+ }
+ leaf operation {
+ type enumeration {
+ enum created;
+ enum updated;
+ enum deleted;
+ }
+ }
+ anyxml data{
+ description "DataObject ";
+ }
}
}
public static ListenerAdapter createListener(InstanceIdentifier path, String streamName) {
ListenerAdapter listener = new ListenerAdapter(path, streamName);
- lock.lock();
- listenersByInstanceIdentifier.put(path, listener);
- listenersByStreamName.put(streamName, listener);
- lock.unlock();
+ try {
+ lock.lock();
+ listenersByInstanceIdentifier.put(path, listener);
+ listenersByStreamName.put(streamName, listener);
+ } finally {
+ lock.unlock();
+ }
return listener;
}
} catch (Exception e) {
}
}
- lock.lock();
- listenersByStreamName = new ConcurrentHashMap<>();
- listenersByInstanceIdentifier = new ConcurrentHashMap<>();
- lock.unlock();
+ try {
+ lock.lock();
+ listenersByStreamName = new ConcurrentHashMap<>();
+ listenersByInstanceIdentifier = new ConcurrentHashMap<>();
+ } finally {
+ lock.unlock();
+ }
}
public static void removeListenerIfNoSubscriberExists(ListenerAdapter listener) {
listener.close();
} catch (Exception e) {
}
- lock.lock();
- listenersByInstanceIdentifier.remove(listener.getPath());
- listenersByStreamName.remove(listener).getStreamName();
- lock.unlock();
+ try {
+ lock.lock();
+ listenersByInstanceIdentifier.remove(listener.getPath());
+ listenersByStreamName.remove(listener.getStreamName());
+ } finally {
+ lock.unlock();
+ }
}
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.iml.varioustests;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
-import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.w3c.dom.Document;
-
-
-public class VariousTest {
-
- @Ignore
- @Test
- public void test() {
- String[] split = "/something:dfsa/s:sda".split("/");
- System.out.println(split.length);
- for (String str : split) {
- System.out.println(">"+str+"<");
- }
-
- }
-
- @Test
- public void loadXml() {
- TestUtils.readInputToCnSn("/varioustest/xmldata.xml", XmlToCompositeNodeProvider.INSTANCE);
-// TestUtils.normalizeCompositeNode(compositeNode, modules, schemaNodePath)
- }
-
- @Test
- public void buildXml() {
-// Document doc;
-// doc.createElementNS(namespaceURI, qualifiedName)
- }
-
-
-}
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
import java.net.URI;
import org.slf4j.Logger;
clientChannel.writeAndFlush(new PingWebSocketFrame(Unpooled.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6})));
}
- public void close() throws InterruptedException {
- clientChannel.writeAndFlush(new CloseWebSocketFrame());
+ public void close(String reasonText) throws InterruptedException {
+ CloseWebSocketFrame closeWebSocketFrame = new CloseWebSocketFrame(1000,reasonText);
+ clientChannel.writeAndFlush(closeWebSocketFrame);
// WebSocketClientHandler will close the connection when the server
// responds to the CloseWebSocketFrame.
if (args.length > 0) {
uri = new URI(args[0]);
} else {
- uri = new URI("http://192.168.11.1:8181/opendaylight-inventory:nodes");
+ uri = new URI("http://192.168.1.101:8181/opendaylight-inventory:nodes");
}
IClientMessageCallback messageCallback = new ClientMessageCallback();
WebSocketClient webSocketClient = new WebSocketClient(uri, messageCallback);
webSocketClient.connect();
+
+ while (true) {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ String input = br.readLine();
+ if (input.equals("q")) {
+ System.out.print("Would you like to close stream? (Y = yes, empty = yes)\n");
+ input = br.readLine();
+ if (input.equals("yes") || input.isEmpty()) {
+ webSocketClient.close("opendaylight-inventory:nodes");
+ break;
+ }
+ }
+ }
}
private static class ClientMessageCallback implements IClientMessageCallback {
@Override
public void onMessageReceived(Object message) {
- logger.info("received message {}", ((TextWebSocketFrame)message).text());
+ if (message instanceof TextWebSocketFrame) {
+ logger.info("received message {}"+ ((TextWebSocketFrame)message).text());
+ }
}
}
try {
return clientFuture.get();
} catch (CancellationException e) {
- throw new RuntimeException("Netconf client interrupted", e);
+ throw new RuntimeException("Cancelling " + this, e);
} catch (ExecutionException e) {
- throw new IllegalStateException("Unable to create netconf client", e);
+ throw new IllegalStateException("Unable to create " + this, e);
}
}
- public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
- return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher);
+ public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher) throws InterruptedException {
+ return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher);
}
- public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat, NetconfClientDispatcher netconfClientDispatcher,NetconfClientSessionListener listener) throws InterruptedException {
- return new NetconfClient(clientLabelForLogging,address,strat,netconfClientDispatcher,listener);
+ public static NetconfClient clientFor(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy, NetconfClientDispatcher netconfClientDispatcher,NetconfClientSessionListener listener) throws InterruptedException {
+ return new NetconfClient(clientLabelForLogging,address,strategy,netconfClientDispatcher,listener);
}
public NetconfClient(String clientLabelForLogging, InetSocketAddress address, int connectTimeoutMs,
DEFAULT_CONNECT_TIMEOUT), netconfClientDispatcher);
}
- public NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strat,
+ public NetconfClient(String clientLabelForLogging, InetSocketAddress address, ReconnectStrategy strategy,
NetconfClientDispatcher netconfClientDispatcher, NetconfClientSessionListener listener) throws InterruptedException{
this.label = clientLabelForLogging;
dispatch = netconfClientDispatcher;
sessionListener = listener;
- Future<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strat);
+ Future<NetconfClientSession> clientFuture = dispatch.createClient(address, sessionListener, strategy);
this.address = address;
clientSession = get(clientFuture);
this.sessionId = clientSession.getSessionId();
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-import org.opendaylight.controller.netconf.api.NetconfMessage;
-import org.opendaylight.controller.netconf.util.NetconfUtil;
import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
@Ignore
public class SSHNetconfClientLiveTest {
+ private static final Logger logger = LoggerFactory.getLogger(SSHNetconfClientLiveTest.class);
NioEventLoopGroup nettyThreadgroup;
NetconfSshClientDispatcher netconfClientDispatcher;
+ InetSocketAddress address;
+ final int connectionAttempts = 10, attemptMsTimeout = 1000;
+ final int connectionTimeoutMillis = 20000;
@Before
public void setUp() {
nettyThreadgroup = new NioEventLoopGroup();
+
netconfClientDispatcher = new NetconfSshClientDispatcher(new LoginPassword(
System.getProperty("username"), System.getProperty("password")),
- nettyThreadgroup, nettyThreadgroup, 5000);
+ nettyThreadgroup, nettyThreadgroup, connectionTimeoutMillis);
+
+ address = new InetSocketAddress(System.getProperty("host"), Integer.parseInt(System.getProperty("port")));
}
+ @Ignore
@Test
public void test() throws Exception {
- InetSocketAddress address = new InetSocketAddress(System.getProperty("host"), 830);
- int connectionAttempts = 10, attemptMsTimeout = 1000;
+ //runnable.run();
+ }
- NetconfClient netconfClient = new NetconfClient("client", address, connectionAttempts,
- attemptMsTimeout, netconfClientDispatcher);
+ @Test
+ public void testInExecutor() throws Exception {
+ int threads = 4;
+ ExecutorService executorService = Executors.newFixedThreadPool(threads);
+ try {
+ for (int i= 0;i< threads;i++) {
+ InetSocketAddress address = new InetSocketAddress(System.getProperty("host"),
+ Integer.parseInt(System.getProperty("port")));
+ NetconfRunnable runnable = new NetconfRunnable(address);
+ executorService.execute(runnable);
+ }
+ executorService.shutdown();
+ executorService.awaitTermination(1, TimeUnit.MINUTES);
- netconfClient.getCapabilities();
- NetconfMessage netconfMessage = NetconfUtil.createMessage(getClass().getResourceAsStream("/get_schema.xml"));
- NetconfMessage response = netconfClient.sendMessage(netconfMessage);
- NetconfUtil.checkIsMessageOk(response);
+ } finally {
+ executorService.shutdownNow();
+ }
}
+
+ class NetconfRunnable implements Runnable {
+ private final InetSocketAddress address;
+
+ NetconfRunnable(InetSocketAddress address) {
+ this.address = address;
+ }
+
+ @Override
+ public void run() {
+ try (NetconfClient netconfClient = new NetconfClient(address.toString(), address, connectionAttempts,
+ attemptMsTimeout, netconfClientDispatcher);) {
+ logger.info("OK {}", address);
+ } catch (InterruptedException | IOException e) {
+ logger.error("Failed {}", address, e);
+ }
+ }
+ };
}
public void run(final Timeout timeout) throws Exception {
synchronized (this) {
if (state != State.ESTABLISHED) {
- logger.debug("Connection timeout after {}", timeout);
+ logger.debug("Connection timeout after {}, session is in state {}", timeout, state);
final IllegalStateException cause = new IllegalStateException(
"Session was not established after " + timeout);
negotiationFailed(cause);
return true;
}
- private void changeState(final State newState) {
+ private synchronized void changeState(final State newState) {
logger.debug("Changing state from : {} to : {}", state, newState);
Preconditions.checkState(isStateChangePermitted(state, newState), "Cannot change state from %s to %s", state,
newState);
if (state == State.OPEN_WAIT && newState == State.FAILED)
return true;
+ logger.debug("Transition from {} to {} is not allowed", state, newState);
return false;
}
}