From: Ed Warnicke Date: Fri, 7 Feb 2014 06:13:46 +0000 (+0000) Subject: Merge "Improve logging in NetconfClient, logging-bridge. Increase connection timeout... X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~518 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=26aab6293f113ec504806e20e382c4fbd1ed3a7c;hp=dbb635f96384aa204520ad7109fe072a7044ff6d Merge "Improve logging in NetconfClient, logging-bridge. Increase connection timeout in sal-netconf-connector." --- diff --git a/opendaylight/appauth/pom.xml b/opendaylight/appauth/pom.xml index 934fdfae80..30879c6565 100644 --- a/opendaylight/appauth/pom.xml +++ b/opendaylight/appauth/pom.xml @@ -27,6 +27,7 @@ + org.opendaylight.controller.configuration, org.opendaylight.controller.containermanager, org.opendaylight.controller.sal.authorization, org.opendaylight.controller.sal.utils, @@ -47,6 +48,10 @@ + + org.opendaylight.controller + configuration + org.opendaylight.controller sal diff --git a/opendaylight/appauth/src/main/java/org/opendaylight/controller/appauth/authorization/Authorization.java b/opendaylight/appauth/src/main/java/org/opendaylight/controller/appauth/authorization/Authorization.java index 1992f59711..b70a79b4ae 100644 --- a/opendaylight/appauth/src/main/java/org/opendaylight/controller/appauth/authorization/Authorization.java +++ b/opendaylight/appauth/src/main/java/org/opendaylight/controller/appauth/authorization/Authorization.java @@ -16,6 +16,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentMap; +import org.opendaylight.controller.configuration.ConfigurationObject; import org.opendaylight.controller.containermanager.IContainerAuthorization; import org.opendaylight.controller.sal.authorization.AppRoleLevel; import org.opendaylight.controller.sal.authorization.IResourceAuthorization; @@ -36,7 +37,7 @@ import org.slf4j.LoggerFactory; */ public abstract class Authorization implements IResourceAuthorization { private static final Logger logger = LoggerFactory.getLogger(Authorization.class); - private static final String namesRegex = "^[a-zA-Z0-9]+[{\\.|\\_|\\-}[a-zA-Z0-9]]*$"; + private static final String namesRegex = ConfigurationObject.getRegularExpression(); /* * The configured resource groups */ diff --git a/opendaylight/config/config-module-archetype/pom.xml b/opendaylight/config/config-module-archetype/pom.xml new file mode 100644 index 0000000000..42c9105c05 --- /dev/null +++ b/opendaylight/config/config-module-archetype/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + org.opendaylight.controller + config-subsystem + 0.2.4-SNAPSHOT + + + config-module-archetype + config-module-archetype + Archetype for new module managed by configuration subsystem + + diff --git a/opendaylight/config/config-module-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/opendaylight/config/config-module-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000000..fc30b4d2c3 --- /dev/null +++ b/opendaylight/config/config-module-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,46 @@ + + config-module-archetype + + true + + + + + + + + impl + + + 2013-04-05 + + + 0.2.4-SNAPSHOT + + + 0.6.2-SNAPSHOT + + + 2014-01-31 + + + java.lang.AutoCloseable + + + 2.4.0 + + + urn:opendaylight:params:xml:ns:yang:controller + + + org.opendaylight.controller.config.yang + + + + + + + src/main/yang + + + diff --git a/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000000..d1c371d618 --- /dev/null +++ b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,104 @@ + + 4.0.0 + + ${groupId} + ${artifactId} + ${version} + bundle + + + ${project.build.directory}/generated-sources/config + ${config-api-version} + ${maven-bundle-plugin-version} + + + + + org.opendaylight.controller + config-api + ${config.version} + + + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${yang-maven-plugin-version} + + + config + + generate-sources + + + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + + ${jmxGeneratorPath} + + + ${yang-namespace-mapping-from}==${yang-namespace-mapping-to} + + + + + true + + + + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${config.version} + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + add-source + generate-sources + + add-source + + + + ${jmxGeneratorPath} + + + + + + + + org.apache.felix + maven-bundle-plugin + ${maven.bundle.version} + true + + + ${project.groupId}.${project.artifactId} + + ${yang-namespace-mapping-to}.${module-name}, + + + * + + + + + + + + + diff --git a/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/src/main/yang/__module-name__-impl.yang b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/src/main/yang/__module-name__-impl.yang new file mode 100644 index 0000000000..8c1dab1495 --- /dev/null +++ b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/src/main/yang/__module-name__-impl.yang @@ -0,0 +1,54 @@ +// 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 diff --git a/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/src/main/yang/__module-name__.yang b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/src/main/yang/__module-name__.yang new file mode 100644 index 0000000000..2afc91e8e3 --- /dev/null +++ b/opendaylight/config/config-module-archetype/src/main/resources/archetype-resources/src/main/yang/__module-name__.yang @@ -0,0 +1,27 @@ +// 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 diff --git a/opendaylight/config/pom.xml b/opendaylight/config/pom.xml index dbf8654d6e..80621a4d44 100644 --- a/opendaylight/config/pom.xml +++ b/opendaylight/config/pom.xml @@ -1,6 +1,5 @@ - - + 4.0.0 @@ -44,6 +43,7 @@ yang-test-plugin shutdown-api shutdown-impl + config-module-archetype @@ -410,7 +410,7 @@ - + @@ -420,4 +420,4 @@ - + \ No newline at end of file diff --git a/opendaylight/config/yang-test/pom.xml b/opendaylight/config/yang-test/pom.xml index 8e40260dbf..9c6e98e571 100644 --- a/opendaylight/config/yang-test/pom.xml +++ b/opendaylight/config/yang-test/pom.xml @@ -59,7 +59,49 @@ + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.opendaylight.controller + + + yang-test-plugin + + + [0.2.3,) + + + + delete-sources + + + process-sources + + + + + + + + + + + + + + org.opendaylight.yangtools diff --git a/opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java b/opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java index 34542de896..720dc7b234 100644 --- a/opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java +++ b/opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java @@ -12,7 +12,7 @@ import java.io.Serializable; public abstract class ConfigurationObject implements Serializable { private static final long serialVersionUID = 1L; - private static final String DEFAULT_REGEX = "^[\\w-\\+\\*\\/\\.\\(\\)\\[\\]\\@]{1,256}$"; + private static final String DEFAULT_REGEX = "^[\\w-=\\+\\*\\/\\.\\(\\)\\[\\]\\@\\|\\:]{1,256}$"; private static final String REGEX_PROP_NAME = "resourceNameRegularExpression"; private static String regex; @@ -31,7 +31,7 @@ public abstract class ConfigurationObject implements Serializable { * resource name regular expression, false otherwise */ protected boolean isValidResourceName(String name) { - return (name != null) ? name.matches(regex) : false; + return name != null && name.matches(regex); } /** diff --git a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java index bce7dd30ba..b94103fb1c 100644 --- a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java @@ -331,7 +331,7 @@ public class ForwardingRulesManager implements for (FlowEntryInstall installEntry : toInstallSafe) { // Install and update database - Status ret = addEntriesInternal(installEntry, async); + Status ret = addEntryInternal(installEntry, async); if (ret.isSuccess()) { oneSucceded = true; @@ -494,7 +494,7 @@ public class ForwardingRulesManager implements } // Install new entries for (FlowEntryInstall newEntry : toInstallSafe) { - succeeded = this.addEntriesInternal(newEntry, async); + succeeded = this.addEntryInternal(newEntry, async); } } else { /* @@ -554,7 +554,9 @@ public class ForwardingRulesManager implements /** * This is the function that modifies the final container flows merged * entries on the network node and update the database. It expects that all - * the validity checks are passed + * the validity checks are passed. + * This function is supposed to be called only on the controller on which + * the IFRM call is executed. * * @param currentEntries * @param newEntries @@ -564,13 +566,13 @@ public class ForwardingRulesManager implements * contain the unique id assigned to this request */ private Status modifyEntryInternal(FlowEntryInstall currentEntries, FlowEntryInstall newEntries, boolean async) { + Status status = new Status(StatusCode.UNDEFINED); FlowEntryDistributionOrderFutureTask futureStatus = distributeWorkOrder(currentEntries, newEntries, UpdateType.CHANGED); if (futureStatus != null) { - Status retStatus = new Status(StatusCode.UNDEFINED); try { - retStatus = futureStatus.get(); - if (retStatus.getCode() + status = futureStatus.get(); + if (status.getCode() .equals(StatusCode.TIMEOUT)) { // A timeout happened, lets cleanup the workMonitor workMonitor.remove(futureStatus.getOrder()); @@ -580,30 +582,31 @@ public class ForwardingRulesManager implements } catch (ExecutionException e) { log.error("", e); } - return retStatus; } else { // Modify the flow on the network node - Status status = async ? programmer.modifyFlowAsync(currentEntries.getNode(), currentEntries.getInstall() - .getFlow(), newEntries.getInstall() - .getFlow()) : programmer.modifyFlow(currentEntries.getNode(), currentEntries.getInstall() - .getFlow(), newEntries.getInstall() - .getFlow()); + status = modifyEntryInHw(currentEntries, newEntries, async); + } - if (!status.isSuccess()) { - log.trace("SDN Plugin failed to program the flow: {}. The failure is: {}", newEntries.getInstall(), - status.getDescription()); - return status; - } + if (!status.isSuccess()) { + log.trace("{} SDN Plugin failed to program the flow: {}. The failure is: {}", + (futureStatus != null) ? "Remote" : "Local", newEntries.getInstall(), status.getDescription()); + return status; + } - log.trace("Modified {} => {}", currentEntries.getInstall(), newEntries.getInstall()); + log.trace("Modified {} => {}", currentEntries.getInstall(), newEntries.getInstall()); - // Update DB - newEntries.setRequestId(status.getRequestId()); - updateSwViews(currentEntries, false); - updateSwViews(newEntries, true); + // Update DB + newEntries.setRequestId(status.getRequestId()); + updateSwViews(currentEntries, false); + updateSwViews(newEntries, true); - return status; - } + return status; + } + + private Status modifyEntryInHw(FlowEntryInstall currentEntries, FlowEntryInstall newEntries, boolean async) { + return async ? programmer.modifyFlowAsync(currentEntries.getNode(), currentEntries.getInstall().getFlow(), + newEntries.getInstall().getFlow()) : programmer.modifyFlow(currentEntries.getNode(), currentEntries + .getInstall().getFlow(), newEntries.getInstall().getFlow()); } /** @@ -672,6 +675,8 @@ public class ForwardingRulesManager implements * This is the function that removes the final container flows merged entry * from the network node and update the database. It expects that all the * validity checks are passed + * This function is supposed to be called only on the controller on which + * the IFRM call is executed. * * @param entry * the flow entry to remove @@ -681,13 +686,12 @@ public class ForwardingRulesManager implements * contain the unique id assigned to this request */ private Status removeEntryInternal(FlowEntryInstall entry, boolean async) { + Status status = new Status(StatusCode.UNDEFINED); FlowEntryDistributionOrderFutureTask futureStatus = distributeWorkOrder(entry, null, UpdateType.REMOVED); if (futureStatus != null) { - Status retStatus = new Status(StatusCode.UNDEFINED); try { - retStatus = futureStatus.get(); - if (retStatus.getCode() - .equals(StatusCode.TIMEOUT)) { + status = futureStatus.get(); + if (status.getCode().equals(StatusCode.TIMEOUT)) { // A timeout happened, lets cleanup the workMonitor workMonitor.remove(futureStatus.getOrder()); } @@ -696,28 +700,31 @@ public class ForwardingRulesManager implements } catch (ExecutionException e) { log.error("", e); } - return retStatus; } else { // Mark the entry to be deleted (for CC just in case we fail) entry.toBeDeleted(); // Remove from node - Status status = async ? programmer.removeFlowAsync(entry.getNode(), entry.getInstall() - .getFlow()) : programmer.removeFlow(entry.getNode(), entry.getInstall() - .getFlow()); - - if (!status.isSuccess()) { - log.trace("SDN Plugin failed to remove the flow: {}. The failure is: {}", entry.getInstall(), - status.getDescription()); - return status; - } - log.trace("Removed {}", entry.getInstall()); - - // Update DB - updateSwViews(entry, false); + status = removeEntryInHw(entry, async); + } + if (!status.isSuccess()) { + log.trace("{} SDN Plugin failed to remove the flow: {}. The failure is: {}", + (futureStatus != null) ? "Remote" : "Local", entry.getInstall(), status.getDescription()); return status; } + + log.trace("Removed {}", entry.getInstall()); + + // Update DB + updateSwViews(entry, false); + + return status; + } + + private Status removeEntryInHw(FlowEntryInstall entry, boolean async) { + return async ? programmer.removeFlowAsync(entry.getNode(), entry.getInstall().getFlow()) : programmer + .removeFlow(entry.getNode(), entry.getInstall().getFlow()); } /** @@ -725,6 +732,8 @@ public class ForwardingRulesManager implements * on the network node and updates the database. It expects that all the * validity and conflict checks are passed. That means it does not check * whether this flow would conflict or overwrite an existing one. + * This function is supposed to be called only on the controller on which + * the IFRM call is executed. * * @param entry * the flow entry to install @@ -733,14 +742,13 @@ public class ForwardingRulesManager implements * @return the status of this request. In case of asynchronous call, it will * contain the unique id assigned to this request */ - private Status addEntriesInternal(FlowEntryInstall entry, boolean async) { + private Status addEntryInternal(FlowEntryInstall entry, boolean async) { + Status status = new Status(StatusCode.UNDEFINED); FlowEntryDistributionOrderFutureTask futureStatus = distributeWorkOrder(entry, null, UpdateType.ADDED); if (futureStatus != null) { - Status retStatus = new Status(StatusCode.UNDEFINED); try { - retStatus = futureStatus.get(); - if (retStatus.getCode() - .equals(StatusCode.TIMEOUT)) { + status = futureStatus.get(); + if (status.getCode().equals(StatusCode.TIMEOUT)) { // A timeout happened, lets cleanup the workMonitor workMonitor.remove(futureStatus.getOrder()); } @@ -749,27 +757,29 @@ public class ForwardingRulesManager implements } catch (ExecutionException e) { log.error("", e); } - return retStatus; } else { - // Install the flow on the network node - Status status = async ? programmer.addFlowAsync(entry.getNode(), entry.getInstall() - .getFlow()) : programmer.addFlow(entry.getNode(), entry.getInstall() - .getFlow()); + status = addEntryInHw(entry, async); + } - if (!status.isSuccess()) { - log.trace("SDN Plugin failed to program the flow: {}. The failure is: {}", entry.getInstall(), - status.getDescription()); - return status; - } + if (!status.isSuccess()) { + log.trace("{} SDN Plugin failed to program the flow: {}. The failure is: {}", + (futureStatus != null) ? "Remote" : "Local", entry.getInstall(), status.getDescription()); + return status; + } + + log.trace("Added {}", entry.getInstall()); - log.trace("Added {}", entry.getInstall()); + // Update DB + entry.setRequestId(status.getRequestId()); + updateSwViews(entry, true); - // Update DB - entry.setRequestId(status.getRequestId()); - updateSwViews(entry, true); + return status; + } - return status; - } + private Status addEntryInHw(FlowEntryInstall entry, boolean async) { + // Install the flow on the network node + return async ? programmer.addFlowAsync(entry.getNode(), entry.getInstall().getFlow()) : programmer.addFlow( + entry.getNode(), entry.getInstall().getFlow()); } /** @@ -2526,13 +2536,13 @@ public class ForwardingRulesManager implements FlowEntryInstall feiNew = workOrder.get(fe); switch (fe.getUpType()) { case ADDED: - gotStatus = addEntriesInternal(feiCurrent, false); + gotStatus = addEntryInHw(feiCurrent, false); break; case CHANGED: - gotStatus = modifyEntryInternal(feiCurrent, feiNew, false); + gotStatus = modifyEntryInHw(feiCurrent, feiNew, false); break; case REMOVED: - gotStatus = removeEntryInternal(feiCurrent, false); + gotStatus = removeEntryInHw(feiCurrent, false); break; } // Remove the Order diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java index b0140ec83a..d1cb25861a 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/listeners/Notificator.java @@ -30,10 +30,13 @@ public class Notificator { 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; } @@ -63,10 +66,13 @@ public class Notificator { } 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) { @@ -81,10 +87,13 @@ public class Notificator { 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(); + } } } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/iml/varioustests/VariousTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/iml/varioustests/VariousTest.java deleted file mode 100644 index cdfed8e494..0000000000 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/iml/varioustests/VariousTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.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) - } - - -} diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/client/WebSocketClient.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/client/WebSocketClient.java index bff63b88ad..845d54ea1f 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/client/WebSocketClient.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/client/WebSocketClient.java @@ -24,6 +24,8 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; 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; @@ -81,8 +83,9 @@ public class WebSocketClient { 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. @@ -95,17 +98,32 @@ public class WebSocketClient { 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()); + } } } diff --git a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java index 11a1be2118..6582d8c021 100644 --- a/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java +++ b/opendaylight/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/NeutronSubnet.java @@ -269,22 +269,26 @@ public class NeutronSubnet extends ConfigurationObject implements Serializable { } gatewayIPAssigned = false; dnsNameservers = new ArrayList(); - allocationPools = new ArrayList(); - hostRoutes = new ArrayList(); - try { - SubnetUtils util = new SubnetUtils(cidr); - SubnetInfo info = util.getInfo(); - if (gatewayIP == null) { - gatewayIP = info.getLowAddress(); - } - if (allocationPools.size() < 1) { - NeutronSubnet_IPAllocationPool source = - new NeutronSubnet_IPAllocationPool(info.getLowAddress(), - info.getHighAddress()); - allocationPools = source.splitPool(gatewayIP); + if (hostRoutes == null) { + hostRoutes = new ArrayList(); + } + if (allocationPools == null) { + allocationPools = new ArrayList(); + try { + SubnetUtils util = new SubnetUtils(cidr); + SubnetInfo info = util.getInfo(); + if (gatewayIP == null) { + gatewayIP = info.getLowAddress(); + } + if (allocationPools.size() < 1) { + NeutronSubnet_IPAllocationPool source = + new NeutronSubnet_IPAllocationPool(info.getLowAddress(), + info.getHighAddress()); + allocationPools = source.splitPool(gatewayIP); + } + } catch (Exception e) { + return false; } - } catch (Exception e) { - return false; } return true; } diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java index 72ee7a679b..63dd0bc29a 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java @@ -48,6 +48,7 @@ public class Controller implements IController, CommandProvider, IPluginInConnec .getLogger(Controller.class); private ControllerIO controllerIO; private Thread switchEventThread; + private volatile boolean shutdownSwitchEventThread;// default to false private ConcurrentHashMap switches; private PriorityBlockingQueue switchEvents; // only 1 message listener per OFType @@ -69,6 +70,12 @@ public class Controller implements IController, CommandProvider, IPluginInConnec while (true) { try { + if(shutdownSwitchEventThread) { + // break out of the infinite loop + // if you are shutting down + logger.info("Switch Event Thread is shutting down"); + break; + } SwitchEvent ev = switchEvents.take(); SwitchEvent.SwitchEventType eType = ev.getEventType(); ISwitch sw = ev.getSwitch(); @@ -104,12 +111,14 @@ public class Controller implements IController, CommandProvider, IPluginInConnec logger.error("Unknown switch event {}", eType.ordinal()); } } catch (InterruptedException e) { - switchEvents.clear(); - return; + // nothing to do except retry + } catch (Exception e) { + // log the exception and retry + logger.warn("Exception in Switch Event Thread is {}" ,e); } } + switchEvents.clear(); } - } /** @@ -167,6 +176,7 @@ public class Controller implements IController, CommandProvider, IPluginInConnec ((SwitchHandler) entry.getValue()).stop(); it.remove(); } + shutdownSwitchEventThread = true; switchEventThread.interrupt(); try { controllerIO.shutDown(); diff --git a/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java index aa6e4ac383..5cd47f2f20 100644 --- a/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java +++ b/opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java @@ -467,11 +467,8 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen @Override public void nodeFlowStatisticsUpdated(Node node, List flowStatsList) { - List currentStat = this.flowStatistics.get(node); - // Update cache only if changed to avoid unnecessary cache sync operations - if (! flowStatsList.equals(currentStat)){ - this.flowStatistics.put(node, flowStatsList); - } + // No equality check because duration fields change constantly + this.flowStatistics.put(node, flowStatsList); } @Override diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java index 28c811c669..de18b021ff 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SwitchConfig.java @@ -123,8 +123,8 @@ public class SwitchConfig extends ConfigurationObject implements Cloneable, Seri } private Status validateNodeId() { - if (nodeId == null || nodeId.isEmpty()) { - return new Status(StatusCode.BADREQUEST, "NodeId cannot be empty"); + if (!isValidResourceName(nodeId)) { + return new Status(StatusCode.BADREQUEST, "Invalid NodeId"); } return new Status(StatusCode.SUCCESS); }