From 3b301f14027755f8924714c25d888132080f6b54 Mon Sep 17 00:00:00 2001 From: Ed Warnicke Date: Tue, 24 Jun 2014 13:59:16 -0500 Subject: [PATCH] Remove remoterpc dead code. Change-Id: I4b16a179a93d3ccc65021aafccc2ed9f9e00b7e9 Signed-off-by: Ed Warnicke --- opendaylight/commons/opendaylight/pom.xml | 20 - .../distribution/opendaylight/pom.xml | 10 - opendaylight/md-sal/pom.xml | 3 - .../implementation/pom.xml | 97 ---- .../remoterpc/api/RouteChangeListener.java | 18 - .../connector/remoterpc/api/RoutingTable.java | 113 ----- .../remoterpc/api/RoutingTableException.java | 52 -- .../remoterpc/api/SystemException.java | 56 --- .../connector/remoterpc/impl/Activator.java | 95 ---- .../remoterpc/impl/RoutingTableImpl.java | 464 ----------------- .../remoterpc/impl/RoutingTableImplTest.java | 334 ------------- .../integrationtest/pom.xml | 230 --------- .../impl/ZeroMQRoutingTableTestIT.java | 330 ------------- .../src/test/resources/logback.xml | 12 - .../integrationtest/test-nb/pom.xml | 87 ---- .../rest/RouteIdentifierImpl.java | 76 --- .../tests/zmqroutingtable/rest/Router.java | 164 ------ .../src/main/resources/WEB-INF/web.xml | 58 --- .../implementation/pom.xml | 176 ------- .../md/sal/remote/rpc/ZeroMQServerModule.java | 69 --- .../remote/rpc/ZeroMQServerModuleFactory.java | 35 -- .../remoterpc/CapturedMessageHandler.java | 37 -- .../sal/connector/remoterpc/ClientImpl.java | 254 ---------- .../remoterpc/ClientRequestHandler.java | 194 -------- .../sal/connector/remoterpc/Context.java | 92 ---- .../connector/remoterpc/RemoteRpcClient.java | 18 - .../remoterpc/RemoteRpcProvider.java | 295 ----------- .../connector/remoterpc/RemoteRpcServer.java | 13 - .../remoterpc/RoutingTableProvider.java | 56 --- .../sal/connector/remoterpc/ServerImpl.java | 264 ---------- .../remoterpc/ServerRequestHandler.java | 292 ----------- .../sal/connector/remoterpc/SocketPair.java | 48 -- .../sal/connector/remoterpc/dto/Message.java | 191 ------- .../remoterpc/dto/MessageWrapper.java | 32 -- .../remoterpc/dto/RouteIdentifierImpl.java | 93 ---- .../connector/remoterpc/util/XmlUtils.java | 71 --- .../main/yang/odl-sal-dom-rpc-remote-cfg.yang | 50 -- .../connector/remoterpc/ClientImplTest.java | 107 ---- .../remoterpc/ClientRequestHandlerTest.java | 124 ----- .../connector/remoterpc/MockRoutingTable.java | 79 --- .../remoterpc/RemoteRpcProviderTest.java | 62 --- .../connector/remoterpc/SerilizationTest.java | 85 ---- .../connector/remoterpc/ServerImplTest.java | 195 -------- .../remoterpc/ServerRequestHandlerTest.java | 110 ----- .../remoterpc/utils/MessagingUtil.java | 186 ------- .../utils/RemoteServerTestClient.java | 89 ---- .../src/test/resources/AddFlow.xml | 36 -- .../src/test/resources/FourSimpleChildren.xml | 6 - .../src/test/resources/logback-test.xml | 13 - .../integrationtest/consumer-service/pom.xml | 77 --- .../zeromq/consumer/ExampleConsumer.java | 128 ----- .../src/main/resources/FourSimpleChildren.xml | 6 - .../main/resources/InvalidCompositeChild.xml | 14 - .../src/main/resources/InvalidSimpleChild.xml | 3 - .../src/main/resources/OneSimpleChild.xml | 3 - .../resources/OneSimpleOneCompositeChild.xml | 9 - .../main/resources/TwoCompositeChildren.xml | 14 - .../src/main/resources/TwoSimpleChildren.xml | 4 - .../integrationtest/pom.xml | 26 - .../integrationtest/provider-service/pom.xml | 82 --- .../zeromq/provider/ExampleProvider.java | 130 ----- .../integrationtest/test-it/pom.xml | 467 ------------------ .../sample/zeromq/test/it/RouterTest.java | 452 ----------------- .../test-it/src/test/resources/controller.xml | 197 -------- .../test-it/src/test/resources/logback.xml | 16 - .../integrationtest/test-nb/pom.xml | 101 ---- .../tests/zmqrouter/rest/Router.java | 273 ---------- .../src/main/resources/WEB-INF/web.xml | 58 --- 68 files changed, 7651 deletions(-) delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/pom.xml delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RouteChangeListener.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTable.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTableException.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/SystemException.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/Activator.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/integrationtest/pom.xml delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/ZeroMQRoutingTableTestIT.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/resources/logback.xml delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/pom.xml delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/RouteIdentifierImpl.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/Router.java delete mode 100644 opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModule.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModuleFactory.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/CapturedMessageHandler.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImpl.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandler.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/Context.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcClient.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProvider.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcServer.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RoutingTableProvider.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandler.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/SocketPair.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/Message.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/MessageWrapper.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/RouteIdentifierImpl.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/util/XmlUtils.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/yang/odl-sal-dom-rpc-remote-cfg.yang delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImplTest.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandlerTest.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/MockRoutingTable.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProviderTest.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/SerilizationTest.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImplTest.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandlerTest.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/MessagingUtil.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/RemoteServerTestClient.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/AddFlow.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/FourSimpleChildren.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/logback-test.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/pom.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/java/org/opendaylight/controller/sample/zeromq/consumer/ExampleConsumer.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/FourSimpleChildren.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidCompositeChild.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidSimpleChild.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleChild.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleOneCompositeChild.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoCompositeChildren.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoSimpleChildren.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/pom.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/pom.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/src/main/java/org/opendaylight/controller/sample/zeromq/provider/ExampleProvider.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/pom.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/java/org/opendaylight/controller/sample/zeromq/test/it/RouterTest.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/resources/controller.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/resources/logback.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/pom.xml delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqrouter/rest/Router.java delete mode 100644 opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index 3f25b7283f..17cb9f4034 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -1169,11 +1169,6 @@ protocol_plugins.stub ${protocol_plugins.stub.version} - - org.opendaylight.controller - remoterpc-routingtable.implementation - ${mdsal.version} - org.opendaylight.controller routing.dijkstra_implementation @@ -1261,11 +1256,6 @@ sal-remote ${mdsal.version} - - org.opendaylight.controller - sal-remoterpc-connector - ${mdsal.version} - org.opendaylight.controller sal-rest-connector @@ -1522,16 +1512,6 @@ sample-toaster-provider ${mdsal.version} - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-consumer - ${mdsal.version} - - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-provider - ${mdsal.version} - org.opendaylight.controller.thirdparty com.sun.jersey.jersey-servlet diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index 7160acba81..b9cfb0f7a6 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -935,12 +935,6 @@ protocol-framework - - - org.opendaylight.controller - remoterpc-routingtable.implementation - ${mdsal.version} - org.opendaylight.controller sal-binding-api @@ -1002,10 +996,6 @@ org.opendaylight.controller sal-remote - - org.opendaylight.controller - sal-remoterpc-connector - org.opendaylight.controller sal-rest-connector diff --git a/opendaylight/md-sal/pom.xml b/opendaylight/md-sal/pom.xml index 5b4f1718bc..174f635a13 100644 --- a/opendaylight/md-sal/pom.xml +++ b/opendaylight/md-sal/pom.xml @@ -54,9 +54,6 @@ compatibility - - remoterpc-routingtable/implementation - sal-remoterpc-connector/implementation sal-rest-docgen diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/pom.xml b/opendaylight/md-sal/remoterpc-routingtable/implementation/pom.xml deleted file mode 100644 index 8cab0b546c..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/pom.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - 4.0.0 - - org.opendaylight.controller - sal-parent - 1.1-SNAPSHOT - ../.. - - - remoterpc-routingtable.implementation - bundle - - - - com.google.guava - guava - - - - org.opendaylight.controller - clustering.services - ${clustering.services.version} - - - - org.opendaylight.controller - sal - - - org.osgi - org.osgi.compendium - - - - - org.opendaylight.controller - sal-connector-api - ${project.version} - - - - junit - junit - test - - - org.mockito - mockito-all - test - - - - - - - - org.apache.felix - maven-bundle-plugin - ${bundle.plugin.version} - true - - - org.opendaylight.controller.sal.connector.remoterpc.api, - org.opendaylight.controller.sal.connector.remoterpc.impl - javax.xml.bind.annotation, - org.opendaylight.controller.sal.core, - org.opendaylight.controller.sal.utils, - org.opendaylight.controller.sal.packet, - org.opendaylight.controller.sal.topology, - org.opendaylight.controller.clustering.services, - org.opendaylight.controller.md.sal.common.api.data, - org.opendaylight.yangtools.yang.binding, - org.osgi.service.component, - org.slf4j, - org.apache.felix.dm, - org.apache.commons.lang3.builder, - org.apache.commons.lang3.tuple, - org.eclipse.osgi.framework.console, - org.osgi.framework, - javax.transaction, - com.google.common.base, - com.google.common.collect - org.opendaylight.controller.sal.connector.remoterpc.impl.Activator - - ${project.basedir}/META-INF - - - - - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - HEAD - https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main - - diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RouteChangeListener.java b/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RouteChangeListener.java deleted file mode 100644 index c9b47ed54b..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RouteChangeListener.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.connector.remoterpc.api; - -import java.util.EventListener; - -public interface RouteChangeListener extends EventListener { - - - void onRouteUpdated(I key, R new_value); - - void onRouteDeleted(I key); -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTable.java b/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTable.java deleted file mode 100644 index e5e314cd87..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTable.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.connector.remoterpc.api; - -import java.util.Set; - -public interface RoutingTable { - - /** - * Adds a network address for the route. If the route already exists, - * it throws DuplicateRouteException. - * This method would be used when registering a global service. - * - * - * @param routeId route identifier - * @param route network address - * @throws DuplicateRouteException - * @throws RoutingTableException - */ - public void addGlobalRoute(I routeId, R route) throws RoutingTableException, SystemException; - - /** - * Remove the route. - * This method would be used when registering a global service. - * @param routeId - * @throws RoutingTableException - * @throws SystemException - */ - public void removeGlobalRoute(I routeId) throws RoutingTableException, SystemException; - - /** - * Adds a network address for the route. If the route already exists, - * it throws DuplicateRouteException. - * This method would be used when registering a global service. - * - * - * @param routeId route identifier - * @param route network address - * @throws DuplicateRouteException - * @throws RoutingTableException - */ - public R getGlobalRoute(I routeId) throws RoutingTableException, SystemException; - - /** - * Adds a network address for the route. If address for route - * exists, appends the address to the list - * - * @param routeId route identifier - * @param route network address - * @throws RoutingTableException for any logical exception - * @throws SystemException - */ - public void addRoute(I routeId, R route) throws RoutingTableException,SystemException; - - - /** - * Removes the network address for the route from routing table. If only - * one network address existed, remove the route as well. - * @param routeId - * @param route - */ - public void removeRoute(I routeId, R route) throws RoutingTableException,SystemException; - - /** - * Adds address for a set of route identifiers. If address for route - * exists, appends the address to the set. - * - * @param routeIds a set of routeIds - * @param route network address - * @throws RoutingTableException for any logical exception - * @throws SystemException - */ - public void addRoutes(Set routeIds, R route) throws RoutingTableException,SystemException; - - /** - * Removes address for a set of route identifiers. - * - * @param routeIds a set of routeIds - * @param route network address - * @throws RoutingTableException for any logical exception - * @throws SystemException - */ - public void removeRoutes(Set routeIds, R route) throws RoutingTableException,SystemException; - - /** - * Returns a set of network addresses associated with this route - * @param routeId - * @return - */ - public Set getRoutes(I routeId); - - - /** - * Returns the last inserted address from the list of network addresses - * associated with the route. - * @param routeId - * @return - */ - public R getLastAddedRoute(I routeId); - - public class DuplicateRouteException extends RoutingTableException { - public DuplicateRouteException(String message) { - super(message); - } - - } - -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTableException.java b/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTableException.java deleted file mode 100644 index fc7f6f1b7b..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTableException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.connector.remoterpc.api; - -/** - * @author: syedbahm - */ -public class RoutingTableException extends Exception { - - /** - * Constructs a new exception with {@code null} as its detail message. - * The cause is not initialized, and may subsequently be initialized by a - * call to {@link #initCause}. - */ - public RoutingTableException() { - super(); - } - - /** - * Constructs a new exception with the specified detail message. The - * cause is not initialized, and may subsequently be initialized by - * a call to {@link #initCause}. - * - * @param message the detail message. The detail message is saved for - * later retrieval by the {@link #getMessage()} method. - */ - public RoutingTableException(String message) { - super(message); - } - - /** - * Constructs a new exception with the specified detail message and - * cause.

Note that the detail message associated with - * {@code cause} is not automatically incorporated in - * this exception's detail message. - * - * @param message the detail message (which is saved for later retrieval - * by the {@link #getMessage()} method). - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A null value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - */ - public RoutingTableException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/SystemException.java b/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/SystemException.java deleted file mode 100644 index 491858e2aa..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/SystemException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - - - -package org.opendaylight.controller.sal.connector.remoterpc.api; - -/** - * @author: syedbahm - * - */ -public class SystemException extends Exception { - /** - * Constructs a new exception with {@code null} as its detail message. - * The cause is not initialized, and may subsequently be initialized by a - * call to {@link #initCause}. - */ - public SystemException() { - super(); - } - - /** - * Constructs a new exception with the specified detail message. The - * cause is not initialized, and may subsequently be initialized by - * a call to {@link #initCause}. - * - * @param message the detail message. The detail message is saved for - * later retrieval by the {@link #getMessage()} method. - */ - public SystemException(String message) { - super(message); - } - - /** - * Constructs a new exception with the specified detail message and - * cause.

Note that the detail message associated with - * {@code cause} is not automatically incorporated in - * this exception's detail message. - * - * @param message the detail message (which is saved for later retrieval - * by the {@link #getMessage()} method). - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A null value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - * @since 1.4 - */ - public SystemException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/Activator.java b/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/Activator.java deleted file mode 100644 index a826a3c1d7..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/Activator.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc.impl; - -import org.apache.felix.dm.Component; -import org.opendaylight.controller.clustering.services.ICacheUpdateAware; -import org.opendaylight.controller.clustering.services.IClusterGlobalServices; -import org.opendaylight.controller.sal.connector.remoterpc.api.RouteChangeListener; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Dictionary; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Set; - -/** - * @author: syedbahm - */ -public class Activator extends ComponentActivatorAbstractBase { - - protected static final Logger logger = LoggerFactory - .getLogger(Activator.class); - private static final String CACHE_UPDATE_AWARE_REGISTRY_KEY = "cachenames" ; - - - /** - * Method which tells how many Global implementations are - * supported by the bundle. This way we can tune the number of - * components created. This components will be created ONLY at the - * time of bundle startup and will be destroyed only at time of - * bundle destruction, this is the major difference with the - * implementation retrieved via getImplementations where all of - * them are assumed to be in a container! - * - * - * @return The list of implementations the bundle will support, - * in Global version - */ - - @Override - protected Object[] getGlobalImplementations(){ - logger.debug("Calling getGlobalImplementations to return:", RoutingTableImpl.class); - return new Object[] { - RoutingTableImpl.class - }; - } - - /** - * Configure the dependency for a given instance Global - * - * @param c Component assigned for this instance, this will be - * what will be used for configuration - * @param imp implementation to be configured - * - */ - @Override - protected void configureGlobalInstance(Component c, Object imp){ - if (imp.equals(RoutingTableImpl.class)) { - Dictionary> props = new Hashtable>(); - Set propSet = new HashSet(); - propSet.add(RoutingTableImpl.GLOBALRPC_CACHE); - propSet.add(RoutingTableImpl.RPC_CACHE); - props.put(CACHE_UPDATE_AWARE_REGISTRY_KEY, propSet); - - c.setInterface(new String[] { RoutingTable.class.getName(),ICacheUpdateAware.class.getName() }, props); - logger.debug("configureGlobalInstance adding dependency:", IClusterGlobalServices.class); - - - // RouteChangeListener services will be none or many so the - // dependency is optional - c.add(createServiceDependency() - .setService(RouteChangeListener.class) - .setCallbacks("setRouteChangeListener", "unsetRouteChangeListener") - .setRequired(false)); - - //dependency is required as it provides us the caching support - c.add(createServiceDependency().setService( - IClusterGlobalServices.class).setCallbacks( - "setClusterGlobalServices", - "unsetClusterGlobalServices").setRequired(true)); - - } - } - - -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java b/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java deleted file mode 100644 index e242b0a393..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java +++ /dev/null @@ -1,464 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc.impl; - -import java.util.Collections; -import java.util.EnumSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentMap; - -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.NotSupportedException; -import javax.transaction.RollbackException; - -import org.apache.felix.dm.Component; -import org.opendaylight.controller.clustering.services.CacheConfigException; -import org.opendaylight.controller.clustering.services.CacheExistException; -import org.opendaylight.controller.clustering.services.CacheListenerAddException; -import org.opendaylight.controller.clustering.services.ICacheUpdateAware; -import org.opendaylight.controller.clustering.services.IClusterGlobalServices; -import org.opendaylight.controller.clustering.services.IClusterServices; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException; -import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; - -public class RoutingTableImpl implements RoutingTable, ICacheUpdateAware { - - private final Logger log = LoggerFactory.getLogger(RoutingTableImpl.class); - - private IClusterGlobalServices clusterGlobalServices = null; - - private ConcurrentMap globalRpcCache = null; - private ConcurrentMap> rpcCache = null; //need routes to ordered by insert-order - - public static final String GLOBALRPC_CACHE = "remoterpc_routingtable.globalrpc_cache"; - public static final String RPC_CACHE = "remoterpc_routingtable.rpc_cache"; - - public RoutingTableImpl() { - } - - @Override - public R getGlobalRoute(final I routeId) throws RoutingTableException, SystemException { - Preconditions.checkNotNull(routeId, "getGlobalRoute: routeId cannot be null!"); - return globalRpcCache.get(routeId); - } - - @Override - public void addGlobalRoute(final I routeId, final R route) throws RoutingTableException, SystemException { - Preconditions.checkNotNull(routeId, "addGlobalRoute: routeId cannot be null!"); - Preconditions.checkNotNull(route, "addGlobalRoute: route cannot be null!"); - try { - - log.debug("addGlobalRoute: adding a new route with id[{}] and value [{}]", routeId, route); - clusterGlobalServices.tbegin(); - if (globalRpcCache.putIfAbsent(routeId, route) != null) { - throw new DuplicateRouteException(" There is already existing route " + routeId); - } - clusterGlobalServices.tcommit(); - - } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) { - throw new RoutingTableException("Transaction error - while trying to create route id=" - + routeId + "with route" + route, e); - } catch (javax.transaction.SystemException e) { - throw new SystemException("System error occurred - while trying to create with value", e); - } - - } - - @Override - public void removeGlobalRoute(final I routeId) throws RoutingTableException, SystemException { - Preconditions.checkNotNull(routeId, "removeGlobalRoute: routeId cannot be null!"); - try { - log.debug("removeGlobalRoute: removing a new route with id [{}]", routeId); - - clusterGlobalServices.tbegin(); - globalRpcCache.remove(routeId); - clusterGlobalServices.tcommit(); - - } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) { - throw new RoutingTableException("Transaction error - while trying to remove route id=" - + routeId, e); - } catch (javax.transaction.SystemException e) { - throw new SystemException("System error occurred - while trying to remove with value", e); - } - } - - - @Override - public Set getRoutes(final I routeId) { - Preconditions.checkNotNull(routeId, "getRoutes: routeId cannot be null!"); - Set routes = rpcCache.get(routeId); - - if (routes == null) { - return Collections.emptySet(); - } - - return ImmutableSet.copyOf(routes); - } - - - - @Override - public R getLastAddedRoute(final I routeId) { - - Set routes = getRoutes(routeId); - - if (routes.isEmpty()) { - return null; - } - - R route = null; - Iterator iter = routes.iterator(); - while (iter.hasNext()) { - route = iter.next(); - } - - return route; - } - - @Override - public void addRoute(final I routeId, final R route) throws RoutingTableException, SystemException { - Preconditions.checkNotNull(routeId, "addRoute: routeId cannot be null"); - Preconditions.checkNotNull(route, "addRoute: route cannot be null"); - - try{ - clusterGlobalServices.tbegin(); - log.debug("addRoute: adding a route with k/v [{}/{}]", routeId, route); - threadSafeAdd(routeId, route); - clusterGlobalServices.tcommit(); - - } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) { - throw new RoutingTableException("Transaction error - while trying to remove route id=" - + routeId, e); - } catch (javax.transaction.SystemException e) { - throw new SystemException("System error occurred - while trying to remove with value", e); - } - } - - @Override - public void addRoutes(final Set routeIds, final R route) throws RoutingTableException, SystemException { - Preconditions.checkNotNull(routeIds, "addRoutes: routeIds must not be null"); - for (I routeId : routeIds){ - addRoute(routeId, route); - } - } - - @Override - public void removeRoute(final I routeId, final R route) throws RoutingTableException, SystemException { - Preconditions.checkNotNull(routeId, "removeRoute: routeId cannot be null!"); - Preconditions.checkNotNull(route, "removeRoute: route cannot be null!"); - - LinkedHashSet routes = rpcCache.get(routeId); - if (routes == null) { - return; - } - - try { - log.debug("removeRoute: removing a new route with k/v [{}/{}]", routeId, route); - - clusterGlobalServices.tbegin(); - threadSafeRemove(routeId, route); - clusterGlobalServices.tcommit(); - - } catch (NotSupportedException | HeuristicRollbackException | RollbackException | HeuristicMixedException e) { - throw new RoutingTableException("Transaction error - while trying to remove route id=" - + routeId, e); - } catch (javax.transaction.SystemException e) { - throw new SystemException("System error occurred - while trying to remove with value", e); - } - } - - @Override - public void removeRoutes(final Set routeIds, final R route) throws RoutingTableException, SystemException { - Preconditions.checkNotNull(routeIds, "removeRoutes: routeIds must not be null"); - for (I routeId : routeIds){ - removeRoute(routeId, route); - } - } - - /** - * This method guarantees that no 2 thread over write each other's changes. - * Just so that we dont end up in infinite loop, it tries for 100 times then throw - */ - private void threadSafeAdd(final I routeId, final R route) { - - for (int i=0;i<100;i++){ - - LinkedHashSet updatedRoutes = new LinkedHashSet<>(); - updatedRoutes.add(route); - LinkedHashSet oldRoutes = rpcCache.putIfAbsent(routeId, updatedRoutes); - if (oldRoutes == null) { - return; - } - - updatedRoutes = new LinkedHashSet<>(oldRoutes); - updatedRoutes.add(route); - - if (rpcCache.replace(routeId, oldRoutes, updatedRoutes)) { - return; - } - } - //the method did not already return means it failed to add route in 10 attempts - throw new IllegalStateException("Failed to add route [" + routeId + "]"); - } - - /** - * This method guarantees that no 2 thread over write each other's changes. - * Just so that we dont end up in infinite loop, it tries for 10 times then throw - */ - private void threadSafeRemove(final I routeId, final R route) { - LinkedHashSet updatedRoutes = null; - for (int i=0;i<10;i++){ - LinkedHashSet oldRoutes = rpcCache.get(routeId); - - // if route to be deleted is the only entry in the set then remove routeId from the cache - if ((oldRoutes.size() == 1) && oldRoutes.contains(route)){ - rpcCache.remove(routeId); - return; - } - - // if there are multiple routes for this routeId, remove the route to be deleted only from the set. - updatedRoutes = new LinkedHashSet<>(oldRoutes); - updatedRoutes.remove(route); - if (rpcCache.replace(routeId, oldRoutes, updatedRoutes)) { - return; - } - - } - //the method did not already return means it failed to remove route in 10 attempts - throw new IllegalStateException("Failed to remove route [" + routeId + "]"); - } - - - // /** - // * @deprecated doesn't do anything will be removed once listeners used - // * whiteboard pattern Registers listener for sending any change - // * notification - // * @param listener - // */ - // @Override - // public void registerRouteChangeListener(RouteChangeListener listener) { - // - // } - - // public void setRouteChangeListener(RouteChangeListener rcl) { - // if(rcl != null){ - // routeChangeListeners.add(rcl); - // }else{ - // log.warn("setRouteChangeListener called with null listener"); - // } - // } - // - // public void unSetRouteChangeListener(RouteChangeListener rcl) { - // if(rcl != null){ - // routeChangeListeners.remove(rcl); - // }else{ - // log.warn("unSetRouteChangeListener called with null listener"); - // } - // } - - /** - * Returning the set of route change listeners for Unit testing Note: the - * package scope is default - * - * @return List of registered RouteChangeListener listeners - */ - // Set getRegisteredRouteChangeListeners() { - // return routeChangeListeners; - // } - public void setClusterGlobalServices(final IClusterGlobalServices clusterGlobalServices) { - this.clusterGlobalServices = clusterGlobalServices; - } - - public void unsetClusterGlobalServices(final IClusterGlobalServices clusterGlobalServices) { - if ((clusterGlobalServices != null) && (this.clusterGlobalServices.equals(clusterGlobalServices))) { - this.clusterGlobalServices = null; - } - } - - /** - * Finds OR Creates clustered cache for Global RPCs - * - * @throws CacheExistException -- cluster global services exception when cache exist - * @throws CacheConfigException -- cluster global services exception during cache config - * @throws CacheListenerAddException -- cluster global services exception during adding of listener - */ - - @SuppressWarnings("unchecked") - void findOrCreateGlobalRpcCache() throws CacheExistException, CacheConfigException, - CacheListenerAddException { - // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it - // should be caching? - - // let us check here if the cache already exists -- if so don't create - if (!clusterGlobalServices.existCache(GLOBALRPC_CACHE)) { - - globalRpcCache = (ConcurrentMap) clusterGlobalServices.createCache(GLOBALRPC_CACHE, - EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - log.debug("Cache created [{}] ", GLOBALRPC_CACHE); - - } else { - globalRpcCache = (ConcurrentMap) clusterGlobalServices.getCache(GLOBALRPC_CACHE); - log.debug("Cache exists [{}] ", GLOBALRPC_CACHE); - } - } - - /** - * Finds OR Creates clustered cache for Routed RPCs - * - * @throws CacheExistException -- cluster global services exception when cache exist - * @throws CacheConfigException -- cluster global services exception during cache config - * @throws CacheListenerAddException -- cluster global services exception during adding of listener - */ - - @SuppressWarnings("unchecked") - void findOrCreateRpcCache() throws CacheExistException, CacheConfigException, - CacheListenerAddException { - // TBD: HOW DO WE DECIDE ON PROPERTIES OF THE CACHE i.e. what duration it - // should be caching? - - if (clusterGlobalServices.existCache(RPC_CACHE)){ - rpcCache = (ConcurrentMap>) clusterGlobalServices.getCache(RPC_CACHE); - log.debug("Cache exists [{}] ", RPC_CACHE); - return; - } - - //cache doesnt exist, create one - rpcCache = (ConcurrentMap>) clusterGlobalServices.createCache(RPC_CACHE, - EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - log.debug("Cache created [{}] ", RPC_CACHE); - } - - - /** - * Function called by the dependency manager when all the required - * dependencies are satisfied - */ - void init(final Component c) { - try { - - findOrCreateGlobalRpcCache(); - findOrCreateRpcCache(); - - } catch (CacheExistException|CacheConfigException|CacheListenerAddException e) { - throw new IllegalStateException("could not construct routing table cache"); - } - } - - /** - * Useful for unit testing It has package - * scope - */ - ConcurrentMap getGlobalRpcCache() { - return this.globalRpcCache; - } - - /** - * Useful for unit testing It has package - * scope - */ - ConcurrentMap> getRpcCache() { - return this.rpcCache; - } - - /** - * This is used from integration test NP rest API to check out the result of the - * cache population - * For testing purpose only-- use it wisely - * - * @return - */ - public String dumpGlobalRpcCache() { - Set> cacheEntrySet = this.globalRpcCache.entrySet(); - StringBuilder sb = new StringBuilder(); - for (Map.Entry entry : cacheEntrySet) { - sb.append("Key:").append(entry.getKey()).append("---->Value:") - .append((entry.getValue() != null) ? entry.getValue() : "null") - .append("\n"); - } - return sb.toString(); - } - - public String dumpRpcCache() { - Set>> cacheEntrySet = this.rpcCache.entrySet(); - StringBuilder sb = new StringBuilder(); - for (Map.Entry> entry : cacheEntrySet) { - sb.append("Key:").append(entry.getKey()).append("---->Value:") - .append((entry.getValue() != null) ? entry.getValue() : "null") - .append("\n"); - } - return sb.toString(); - } - /** - * Invoked when a new entry is available in the cache, the key is only - * provided, the value will come as an entryUpdate invocation - * - * @param key Key for the entry just created - * @param cacheName name of the cache for which update has been received - * @param originLocal true if the event is generated from this node - */ - @Override - public void entryCreated(final I key, final String cacheName, final boolean originLocal) { - // TBD: do we require this. - if (log.isDebugEnabled()) { - log.debug("RoutingTableUpdates: entryCreated routeId = " + key + " cacheName=" + cacheName); - } - } - - /** - * Called anytime a given entry is updated - * - * @param key Key for the entry modified - * @param new_value the new value the key will have - * @param cacheName name of the cache for which update has been received - * @param originLocal true if the event is generated from this node - */ - @Override - public void entryUpdated(final I key, final R new_value, final String cacheName, final boolean originLocal) { - if (log.isDebugEnabled()) { - log.debug("RoutingTableUpdates: entryUpdated routeId = " + key + ",value = " + new_value - + " ,cacheName=" + cacheName + " originLocal=" + originLocal); - } - // if (!originLocal) { - // for (RouteChangeListener rcl : routeChangeListeners) { - // rcl.onRouteUpdated(key, new_value); - // } - // } - } - - /** - * Called anytime a given key is removed from the ConcurrentHashMap we are - * listening to. - * - * @param key Key of the entry removed - * @param cacheName name of the cache for which update has been received - * @param originLocal true if the event is generated from this node - */ - @Override - public void entryDeleted(final I key, final String cacheName, final boolean originLocal) { - if (log.isDebugEnabled()) { - log.debug("RoutingTableUpdates: entryUpdated routeId = " + key + " local = " + originLocal - + " cacheName=" + cacheName + " originLocal=" + originLocal); - } - // if (!originLocal) { - // for (RouteChangeListener rcl : routeChangeListeners) { - // rcl.onRouteDeleted(key); - // } - // } - } -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java b/opendaylight/md-sal/remoterpc-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java deleted file mode 100644 index 1ff49c1543..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc.impl; - -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.when; - -import java.net.URI; -import java.util.EnumSet; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import junit.framework.Assert; - -import org.apache.felix.dm.Component; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.clustering.services.IClusterGlobalServices; -import org.opendaylight.controller.clustering.services.IClusterServices; -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; - -public class RoutingTableImplTest { - - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace, "global"); - - private IClusterGlobalServices clusterService; - private RoutingTableImpl, String> routingTable; - ConcurrentMap mockGlobalRpcCache; - ConcurrentMap mockRpcCache; - - @Before - public void setUp() throws Exception{ - clusterService = mock(IClusterGlobalServices.class); - routingTable = new RoutingTableImpl, String>(); - mockGlobalRpcCache = new ConcurrentHashMap<>(); - mockRpcCache = new ConcurrentHashMap<>(); - createRoutingTableCache(); - } - - @After - public void tearDown(){ - reset(clusterService); - mockGlobalRpcCache = null; - mockRpcCache = null; - } - - @Test - public void addGlobalRoute_ValidArguments_ShouldAdd() throws Exception { - - Assert.assertNotNull(mockGlobalRpcCache); - RpcRouter.RouteIdentifier routeIdentifier = getRouteIdentifier(); - - final String expectedRoute = "172.27.12.1:5000"; - routingTable.addGlobalRoute(routeIdentifier, expectedRoute); - - ConcurrentMap latestCache = routingTable.getGlobalRpcCache(); - Assert.assertEquals(mockGlobalRpcCache, latestCache); - Assert.assertEquals(expectedRoute, latestCache.get(routeIdentifier)); - } - - @Test (expected = RoutingTable.DuplicateRouteException.class) - public void addGlobalRoute_DuplicateRoute_ShouldThrow() throws Exception{ - - Assert.assertNotNull(mockGlobalRpcCache); - - RpcRouter.RouteIdentifier routeIdentifier = getRouteIdentifier(); - routingTable.addGlobalRoute(routeIdentifier, new String()); - routingTable.addGlobalRoute(routeIdentifier, new String()); - } - - @Test - public void getGlobalRoute_ExistingRouteId_ShouldReturnRoute() throws Exception { - - Assert.assertNotNull(mockGlobalRpcCache); - RpcRouter.RouteIdentifier routeIdentifier = getRouteIdentifier(); - String expectedRoute = "172.27.12.1:5000"; - - routingTable.addGlobalRoute(routeIdentifier, expectedRoute); - - String actualRoute = routingTable.getGlobalRoute(routeIdentifier); - Assert.assertEquals(expectedRoute, actualRoute); - } - - @Test - public void getGlobalRoute_NonExistentRouteId_ShouldReturnNull() throws Exception { - - Assert.assertNotNull(mockGlobalRpcCache); - RpcRouter.RouteIdentifier routeIdentifier = getRouteIdentifier(); - - String actualRoute = routingTable.getGlobalRoute(routeIdentifier); - Assert.assertNull(actualRoute); - } - - @Test - public void removeGlobalRoute_ExistingRouteId_ShouldRemove() throws Exception { - - Assert.assertNotNull(mockGlobalRpcCache); - RpcRouter.RouteIdentifier routeIdentifier = getRouteIdentifier(); - - ConcurrentMap cache = routingTable.getGlobalRpcCache(); - Assert.assertTrue(cache.size() == 0); - routingTable.addGlobalRoute(routeIdentifier, "172.27.12.1:5000"); - Assert.assertTrue(cache.size() == 1); - - routingTable.removeGlobalRoute(routeIdentifier); - Assert.assertTrue(cache.size() == 0); - - } - - @Test - public void removeGlobalRoute_NonExistentRouteId_ShouldDoNothing() throws Exception { - - Assert.assertNotNull(mockGlobalRpcCache); - RpcRouter.RouteIdentifier routeIdentifier = getRouteIdentifier(); - - ConcurrentMap cache = routingTable.getGlobalRpcCache(); - Assert.assertTrue(cache.size() == 0); - - routingTable.removeGlobalRoute(routeIdentifier); - Assert.assertTrue(cache.size() == 0); - - } - - @Test - public void addRoute_ForNewRouteId_ShouldAddRoute() throws Exception { - Assert.assertTrue(mockRpcCache.size() == 0); - - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - - routingTable.addRoute(routeId, new String()); - Assert.assertTrue(mockRpcCache.size() == 1); - - Set routes = routingTable.getRoutes(routeId); - Assert.assertEquals(1, routes.size()); - } - - @Test - public void addRoute_ForExistingRouteId_ShouldAppendRoute() throws Exception { - - Assert.assertTrue(mockRpcCache.size() == 0); - - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - - String route_1 = "10.0.0.1:5955"; - String route_2 = "10.0.0.2:5955"; - - routingTable.addRoute(routeId, route_1); - routingTable.addRoute(routeId, route_2); - - Assert.assertTrue(mockRpcCache.size() == 1); - - Set routes = routingTable.getRoutes(routeId); - Assert.assertEquals(2, routes.size()); - Assert.assertTrue(routes.contains(route_1)); - Assert.assertTrue(routes.contains(route_2)); - } - - @Test - public void addRoute_UsingMultipleThreads_ShouldNotOverwrite(){ - ExecutorService threadPool = Executors.newCachedThreadPool(); - - int numOfRoutesToAdd = 100; - String routePrefix_1 = "10.0.0.1:555"; - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - threadPool.submit(addRoutes(numOfRoutesToAdd, routePrefix_1, routeId)); - String routePrefix_2 = "10.0.0.1:556"; - threadPool.submit(addRoutes(numOfRoutesToAdd, routePrefix_2, routeId)); - - // wait for all tasks to complete; timeout in 10 sec - threadPool.shutdown(); - try { - threadPool.awaitTermination(10, TimeUnit.SECONDS); // - } catch (InterruptedException e) { - e.printStackTrace(); - } - - Assert.assertEquals(2*numOfRoutesToAdd, routingTable.getRoutes(routeId).size()); - } - - @Test(expected = NullPointerException.class) - public void addRoute_NullRouteId_shouldThrowNpe() throws Exception { - - routingTable.addRoute(null, new String()); - } - - @Test(expected = NullPointerException.class) - public void addRoute_NullRoute_shouldThrowNpe() throws Exception{ - - routingTable.addRoute(getRouteIdentifier(), null); - } - - @Test (expected = UnsupportedOperationException.class) - public void getRoutes_Call_ShouldReturnImmutableCopy() throws Exception{ - Assert.assertNotNull(routingTable); - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - routingTable.addRoute(routeId, new String()); - - Set routes = routingTable.getRoutes(routeId); //returns Immutable Set - - routes.add(new String()); //can not be modified; should throw - } - - @Test - public void getRoutes_With2RoutesFor1RouteId_ShouldReturnASetWithSize2() throws Exception{ - Assert.assertNotNull(routingTable); - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - routingTable.addRoute(routeId, "10.0.0.1:5555"); - routingTable.addRoute(routeId, "10.0.0.2:5555"); - - Set routes = routingTable.getRoutes(routeId); //returns Immutable Set - - Assert.assertEquals(2, routes.size()); - } - - @Test - public void getLastAddedRoute_WhenMultipleRoutesExists_ShouldReturnLatestRoute() - throws Exception { - - Assert.assertNotNull(routingTable); - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - String route_1 = "10.0.0.1:5555"; - String route_2 = "10.0.0.2:5555"; - routingTable.addRoute(routeId, route_1); - routingTable.addRoute(routeId, route_2); - - Assert.assertEquals(route_2, routingTable.getLastAddedRoute(routeId)); - } - - @Test - public void removeRoute_WhenMultipleRoutesExist_RemovesGivenRoute() throws Exception{ - Assert.assertNotNull(routingTable); - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - String route_1 = "10.0.0.1:5555"; - String route_2 = "10.0.0.2:5555"; - - routingTable.addRoute(routeId, route_1); - routingTable.addRoute(routeId, route_2); - - Assert.assertEquals(2, routingTable.getRoutes(routeId).size()); - - routingTable.removeRoute(routeId, route_1); - Assert.assertEquals(1, routingTable.getRoutes(routeId).size()); - - } - - @Test - public void removeRoute_WhenOnlyOneRouteExists_RemovesRouteId() throws Exception{ - Assert.assertNotNull(routingTable); - RpcRouter.RouteIdentifier routeId = getRouteIdentifier(); - String route_1 = "10.0.0.1:5555"; - - routingTable.addRoute(routeId, route_1); - Assert.assertEquals(1, routingTable.getRoutes(routeId).size()); - - routingTable.removeRoute(routeId, route_1); - ConcurrentMap cache = routingTable.getRpcCache(); - Assert.assertFalse(cache.containsKey(routeId)); - - } - - /* - * Private helper methods - */ - private void createRoutingTableCache() throws Exception { - - //here init - Component c = mock(Component.class); - - when(clusterService.existCache( - RoutingTableImpl.GLOBALRPC_CACHE)).thenReturn(false); - - when(clusterService.createCache(RoutingTableImpl.GLOBALRPC_CACHE, - EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL))). - thenReturn(mockGlobalRpcCache); - - when(clusterService.existCache( - RoutingTableImpl.RPC_CACHE)).thenReturn(false); - - when(clusterService.createCache(RoutingTableImpl.RPC_CACHE, - EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL))). - thenReturn(mockRpcCache); - - doNothing().when(clusterService).tbegin(); - doNothing().when(clusterService).tcommit(); - - routingTable.setClusterGlobalServices(this.clusterService); - routingTable.init(c); - - Assert.assertEquals(mockGlobalRpcCache, routingTable.getGlobalRpcCache()); - Assert.assertEquals(mockRpcCache, routingTable.getRpcCache()); - } - - private RpcRouter.RouteIdentifier getRouteIdentifier(){ - RpcRouter.RouteIdentifier routeIdentifier = mock(RpcRouter.RouteIdentifier.class); - InstanceIdentifier identifier = mock(InstanceIdentifier.class); - when(routeIdentifier.getType()).thenReturn(QNAME); - when(routeIdentifier.getRoute()).thenReturn(identifier); - - return routeIdentifier; - } - - private Runnable addRoutes(final int numRoutes, final String routePrefix, final RpcRouter.RouteIdentifier routeId){ - return new Runnable() { - @Override - public void run() { - for (int i=0;i - - 4.0.0 - - org.opendaylight.controller - commons.integrationtest - 0.5.1-SNAPSHOT - ../../../commons/integrationtest - - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main - HEAD - - - remoterpc-routingtable.integrationtest - 0.4.1-SNAPSHOT - - - - org.opendaylight.controller - remoterpc-routingtable.implementation - - - org.opendaylight.controller - clustering.services - - - org.opendaylight.controller - sal - - - org.opendaylight.controller - sal.implementation - - - org.opendaylight.controller - containermanager - - - org.opendaylight.controller - containermanager.it.implementation - - - org.opendaylight.controller - clustering.stub - - - junit - junit - - - org.ops4j.pax.exam - pax-exam-container-native - test - - - org.ops4j.pax.exam - pax-exam-link-mvn - test - - - org.ops4j.pax.url - pax-url-aether - test - - - org.slf4j - log4j-over-slf4j - - - ch.qos.logback - logback-core - - - ch.qos.logback - logback-classic - - - org.apache.felix - org.apache.felix.dependencymanager.shell - - - eclipselink - javax.resource - - - com.google.guava - guava - - - org.opendaylight.controller - sal - - - org.opendaylight.yangtools - yang-binding - - - org.opendaylight.yangtools - yang-common - - - org.opendaylight.controller - sal-connector-api - - - org.opendaylight.controller - sal-common-util - - - - junit - junit - - - org.opendaylight.controller - sal-common-api - - - org.opendaylight.controller - sal-binding-broker-impl - - - org.ops4j.pax.exam - pax-exam-container-native - ${exam.version} - test - - - org.ops4j.pax.exam - pax-exam-junit4 - ${exam.version} - test - - - org.ops4j.pax.exam - pax-exam-link-mvn - ${exam.version} - test - - - - org.opendaylight.controller - config-manager - - - equinoxSDK381 - org.eclipse.osgi - test - - - org.slf4j - log4j-over-slf4j - - - ch.qos.logback - logback-core - - - ch.qos.logback - logback-classic - - - org.opendaylight.yangtools.thirdparty - antlr4-runtime-osgi-nohead - - - org.opendaylight.yangtools.thirdparty - xtend-lib-osgi - - - - org.opendaylight.controller - clustering.services - - - junit - junit - test - - - - equinoxSDK381 - org.eclipse.osgi - - - org.ops4j.pax.exam - pax-exam-junit4 - ${exam.version} - - - org.ops4j.pax.exam - pax-exam - ${exam.version} - - - - - ../implementation/target/jacoco.exec - ../implementation/target/jacoco-it.exec - - - - - org.jacoco - jacoco-maven-plugin - - ../implementation/target/jacoco-it.exec - org.opendaylight.controller.* - - - - pre-test - - prepare-agent - - - - post-test - - true - - - - - - - diff --git a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/ZeroMQRoutingTableTestIT.java b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/ZeroMQRoutingTableTestIT.java deleted file mode 100644 index 924921264f..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/ZeroMQRoutingTableTestIT.java +++ /dev/null @@ -1,330 +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.connector.remoterpc.impl; - -import junit.framework.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.util.PathUtils; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import java.io.Serializable; -import java.net.URI; -import java.util.Set; - -import static org.ops4j.pax.exam.CoreOptions.junitBundles; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import static org.ops4j.pax.exam.CoreOptions.options; -import static org.ops4j.pax.exam.CoreOptions.systemPackages; -import static org.ops4j.pax.exam.CoreOptions.systemProperty; - - - - -@RunWith(PaxExam.class) -public class - ZeroMQRoutingTableTestIT { - private Logger log = LoggerFactory - .getLogger(ZeroMQRoutingTableTestIT.class); - - public static final String ODL = "org.opendaylight.controller"; - public static final String YANG = "org.opendaylight.yangtools"; - public static final String CONTROLLER = "org.opendaylight.controller"; - public static final String YANGTOOLS = "org.opendaylight.yangtools"; - RoutingIdentifierImpl rii = new RoutingIdentifierImpl(); - // get the OSGI bundle context - @Inject - private BundleContext bc; - @Inject - private RoutingTable routingTable = null; - - // Configure the OSGi container - @Configuration - public Option[] config() { - return options( - // - systemProperty("logback.configurationFile").value( - "file:" + PathUtils.getBaseDir() - + "/src/test/resources/logback.xml"), - // To start OSGi console for inspection remotely - systemProperty("osgi.console").value("2401"), - // Set the systemPackages (used by clustering) - systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"), - // List framework bundles - - mavenBundle("equinoxSDK381", - "org.eclipse.equinox.console").versionAsInProject(), - mavenBundle("equinoxSDK381", - "org.eclipse.equinox.util").versionAsInProject(), - mavenBundle("equinoxSDK381", - "org.eclipse.osgi.services").versionAsInProject(), - mavenBundle("equinoxSDK381", - "org.eclipse.equinox.ds").versionAsInProject(), - mavenBundle("equinoxSDK381", - "org.apache.felix.gogo.command").versionAsInProject(), - mavenBundle("equinoxSDK381", - "org.apache.felix.gogo.runtime").versionAsInProject(), - mavenBundle("equinoxSDK381", - "org.apache.felix.gogo.shell").versionAsInProject(), - // List logger bundles - mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(), - mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), - mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), - mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), - // List all the bundles on which the test case depends - mavenBundle(ODL, - "clustering.services").versionAsInProject(), - - mavenBundle(ODL, "sal").versionAsInProject(), - mavenBundle(ODL, - "sal.implementation").versionAsInProject(), - mavenBundle(ODL, "containermanager").versionAsInProject(), - mavenBundle(ODL, - "containermanager.it.implementation").versionAsInProject(), - mavenBundle("org.jboss.spec.javax.transaction", - "jboss-transaction-api_1.1_spec").versionAsInProject(), - mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(), - mavenBundle("org.apache.felix", - "org.apache.felix.dependencymanager").versionAsInProject(), - mavenBundle("org.apache.felix", - "org.apache.felix.dependencymanager.shell").versionAsInProject(), - mavenBundle("eclipselink", "javax.resource").versionAsInProject(), - - mavenBundle("com.google.guava","guava").versionAsInProject(), - // List logger bundles - mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(), - mavenBundle("org.slf4j", "log4j-over-slf4j") - .versionAsInProject(), - mavenBundle("ch.qos.logback", "logback-core") - .versionAsInProject(), - mavenBundle("ch.qos.logback", "logback-classic") - .versionAsInProject(), - - mavenBundle(ODL, "clustering.services") - .versionAsInProject(), - mavenBundle(ODL, "clustering.stub") - .versionAsInProject(), - - - // List all the bundles on which the test case depends - mavenBundle(ODL, "sal") - .versionAsInProject(), - mavenBundle(ODL, "sal-connector-api") - .versionAsInProject(), - mavenBundle(ODL, "remoterpc-routingtable.implementation") - .versionAsInProject(), - - mavenBundle("org.jboss.spec.javax.transaction", - "jboss-transaction-api_1.1_spec").versionAsInProject(), - mavenBundle("org.apache.commons", "commons-lang3") - .versionAsInProject(), - mavenBundle("org.apache.felix", - "org.apache.felix.dependencymanager") - .versionAsInProject(), - - mavenBundle(ODL, - "sal-core-api") - .versionAsInProject(), - mavenBundle("org.opendaylight.yangtools","yang-data-api") - .versionAsInProject(), - mavenBundle("org.opendaylight.yangtools","yang-model-api") - .versionAsInProject(), - mavenBundle("org.opendaylight.yangtools","yang-binding") - .versionAsInProject(), - - mavenBundle(CONTROLLER, "sal-binding-api").versionAsInProject(), // - mavenBundle(CONTROLLER, "sal-binding-config").versionAsInProject(), - mavenBundle(CONTROLLER, "sal-binding-broker-impl").versionAsInProject(), // - mavenBundle("org.javassist", "javassist").versionAsInProject(), // - mavenBundle(CONTROLLER, "sal-common-util").versionAsInProject(), // - - mavenBundle(YANGTOOLS, "yang-data-api").versionAsInProject(), // - mavenBundle(YANGTOOLS, "yang-data-impl").versionAsInProject(), // - mavenBundle(YANGTOOLS, "yang-model-api").versionAsInProject(), // - mavenBundle(YANGTOOLS, "yang-model-util").versionAsInProject(), // - mavenBundle(YANGTOOLS, "yang-parser-api").versionAsInProject(), - mavenBundle(YANGTOOLS, "yang-parser-impl").versionAsInProject(), - - - mavenBundle(YANGTOOLS, "binding-generator-spi").versionAsInProject(), // - mavenBundle(YANGTOOLS, "binding-model-api").versionAsInProject(), // - mavenBundle(YANGTOOLS, "binding-generator-util").versionAsInProject(), - mavenBundle(YANGTOOLS, "yang-parser-impl").versionAsInProject(), - mavenBundle(YANGTOOLS, "binding-type-provider").versionAsInProject(), - mavenBundle(YANGTOOLS, "binding-generator-api").versionAsInProject(), - mavenBundle(YANGTOOLS, "binding-generator-spi").versionAsInProject(), - mavenBundle(YANGTOOLS, "binding-generator-impl").versionAsInProject(), - - - mavenBundle(CONTROLLER, "sal-core-api").versionAsInProject().update(), // - mavenBundle(CONTROLLER, "sal-broker-impl").versionAsInProject(), // - mavenBundle(CONTROLLER, "sal-core-spi").versionAsInProject().update(), // - - mavenBundle(YANGTOOLS + ".thirdparty", "antlr4-runtime-osgi-nohead").versionAsInProject(), // - - mavenBundle(YANG+".thirdparty", "xtend-lib-osgi").versionAsInProject(), - mavenBundle("com.google.guava", "guava").versionAsInProject(), // - mavenBundle("org.javassist", "javassist").versionAsInProject(), - mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(), // - mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), // - mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), // - mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), // - - mavenBundle(ODL, "sal-common").versionAsInProject(), // - mavenBundle(ODL, "sal-common-api").versionAsInProject(),// - mavenBundle(ODL, "sal-common-impl").versionAsInProject(), // - mavenBundle(ODL, "sal-common-util").versionAsInProject(), // - - mavenBundle(ODL, "config-api").versionAsInProject(), // - mavenBundle(ODL, "config-manager").versionAsInProject(), // - mavenBundle("commons-io", "commons-io").versionAsInProject(), - mavenBundle("org.apache.commons", "commons-lang3").versionAsInProject(), - - mavenBundle(ODL, "sal-binding-api").versionAsInProject(), // - mavenBundle(ODL, "sal-binding-config").versionAsInProject(), - mavenBundle("org.javassist", "javassist").versionAsInProject(), // - mavenBundle(ODL, "sal-common-util").versionAsInProject(), // - - mavenBundle(YANG, "yang-data-api").versionAsInProject(), // - mavenBundle(YANG, "yang-data-impl").versionAsInProject(), // - mavenBundle(YANG, "yang-model-api").versionAsInProject(), // - mavenBundle(YANG, "yang-model-util").versionAsInProject(), // - mavenBundle(YANG, "yang-parser-api").versionAsInProject(), - mavenBundle(YANG, "yang-parser-impl").versionAsInProject(), - - - mavenBundle(YANG, "binding-generator-spi").versionAsInProject(), // - mavenBundle(YANG, "binding-model-api").versionAsInProject(), // - mavenBundle(YANG, "binding-generator-util").versionAsInProject(), - mavenBundle(YANG, "yang-parser-impl").versionAsInProject(), - mavenBundle(YANG, "binding-type-provider").versionAsInProject(), - mavenBundle(YANG, "binding-generator-api").versionAsInProject(), - mavenBundle(YANG, "binding-generator-spi").versionAsInProject(), - mavenBundle(YANG, "binding-generator-impl").versionAsInProject(), - - - mavenBundle(ODL, "sal-core-api").versionAsInProject().update(), // - mavenBundle(ODL, "sal-broker-impl").versionAsInProject(), // - mavenBundle(ODL, "sal-core-spi").versionAsInProject().update(), // - - mavenBundle(YANG + ".thirdparty", "antlr4-runtime-osgi-nohead").versionAsInProject(), // - - mavenBundle(YANG, "concepts").versionAsInProject(), - mavenBundle(YANG, "yang-binding").versionAsInProject(), // - mavenBundle(YANG, "yang-common").versionAsInProject(), // - mavenBundle(YANG+".thirdparty", "xtend-lib-osgi").versionAsInProject(), - mavenBundle("com.google.guava", "guava").versionAsInProject(), // - mavenBundle("org.javassist", "javassist").versionAsInProject(), - - junitBundles()); - } - - 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"; - default: - return "Not CONVERTED"; - } - } - - @Test - public void testAddGlobalRoute () throws Exception{ - - routingTable.addGlobalRoute(rii,"172.27.12.1:5000"); - - Set routes = routingTable.getRoutes(rii); - - for(String route:routes){ - Assert.assertEquals(route,"172.27.12.1:5000"); - } - - - } - - - @Test - public void testDeleteGlobalRoute () throws Exception{ - - routingTable.removeGlobalRoute(rii); - - Set routes = routingTable.getRoutes(rii); - - Assert.assertNull(routes); - - - } - - - - class RoutingIdentifierImpl implements RpcRouter.RouteIdentifier,Serializable { - - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace,"global"); - private final QName instance = new QName(URI.create("127.0.0.1"),"local"); - - @Override - public QName getContext() { - return QNAME; - } - - @Override - public QName getType() { - return QNAME; - } - - @Override - public org.opendaylight.yangtools.yang.data.api.InstanceIdentifier getRoute() { - return InstanceIdentifier.of(instance); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - RoutingIdentifierImpl that = (RoutingIdentifierImpl) o; - - if (QNAME != null ? !QNAME.equals(that.QNAME) : that.QNAME != null) return false; - if (instance != null ? !instance.equals(that.instance) : that.instance != null) return false; - if (namespace != null ? !namespace.equals(that.namespace) : that.namespace != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = namespace != null ? namespace.hashCode() : 0; - result = 31 * result + (QNAME != null ? QNAME.hashCode() : 0); - result = 31 * result + (instance != null ? instance.hashCode() : 0); - return result; - } - } - - - - - -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/resources/logback.xml b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/resources/logback.xml deleted file mode 100644 index 6d9dfda9a3..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/resources/logback.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - diff --git a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/pom.xml b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/pom.xml deleted file mode 100644 index d74e7130a4..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/pom.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - 4.0.0 - - sal-remoterpc-connector-test-parent - org.opendaylight.controller.tests - 1.1-SNAPSHOT - - - remoterpc-routingtable-nb-it - bundle - - - - - org.apache.felix - maven-bundle-plugin - ${bundle.plugin.version} - true - - - - org.opendaylight.controller.tests.zmqroutingtable.rest - - - com.sun.jersey.spi.container.servlet, - com.fasterxml.jackson.annotation, - javax.ws.rs, - javax.ws.rs.core, - javax.xml.bind, - javax.xml.bind.annotation, - org.slf4j, - org.apache.catalina.filters, - org.codehaus.jackson.jaxrs, - org.opendaylight.controller.sal.utils, - org.opendaylight.yangtools.yang.common, - org.opendaylight.controller.sal.connector.api, - org.opendaylight.controller.sal.connector.remoterpc.api, - org.opendaylight.controller.sal.connector.remoterpc.impl, - org.osgi.framework, - com.google.common.base, - org.opendaylight.yangtools.yang.data.api, - !org.codehaus.enunciate.jaxrs - - - /controller/nb/v2/zmqnbrt - ,${classes;ANNOTATION;javax.ws.rs.Path} - - ${project.basedir}/src/main/resources/META-INF - - - - - - - org.opendaylight.controller - containermanager - - - org.opendaylight.controller - commons.northbound - - - org.opendaylight.controller - sal - - - - org.osgi - org.osgi.core - - - junit - junit - - - org.opendaylight.controller - remoterpc-routingtable.implementation - - - com.google.guava - guava - - - - diff --git a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/RouteIdentifierImpl.java b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/RouteIdentifierImpl.java deleted file mode 100644 index eb5ecd798c..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/RouteIdentifierImpl.java +++ /dev/null @@ -1,76 +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.tests.zmqroutingtable.rest; - -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; - -import java.io.Serializable; -import java.net.URI; - -/** - * @author: syedbahm - * Date: 12/10/13 - */ -public class RouteIdentifierImpl implements RpcRouter.RouteIdentifier, Serializable { - - private final URI namespace; - private final QName QNAME; - private final QName instance; - - public RouteIdentifierImpl() { - namespace = URI.create("http://cisco.com/example"); - QNAME = new QName(namespace, "global"); - instance = new QName(URI.create("127.0.0.1"), "local"); - } - - public RouteIdentifierImpl(String url,String instanceIP){ - namespace = URI.create(url); - QNAME = new QName(namespace,"global"); - instance = new QName(URI.create(instanceIP), "local"); - } - - - @Override - public QName getContext() { - return QNAME; - } - - @Override - public QName getType() { - return QNAME; - } - - @Override - public org.opendaylight.yangtools.yang.data.api.InstanceIdentifier getRoute() { - return InstanceIdentifier.of(instance); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - RouteIdentifierImpl that = (RouteIdentifierImpl) o; - - if (!QNAME.equals(that.QNAME)) return false; - if (!instance.equals(that.instance)) return false; - if (!namespace.equals(that.namespace)) return false; - - return true; - } - - @Override - public int hashCode() { - int result = namespace.hashCode(); - result = 31 * result + QNAME.hashCode(); - result = 31 * result + instance.hashCode(); - return result; - } -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/Router.java b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/Router.java deleted file mode 100644 index 9bf6e53424..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/Router.java +++ /dev/null @@ -1,164 +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.tests.zmqroutingtable.rest; - -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException; -import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException; -import org.opendaylight.controller.sal.connector.remoterpc.impl.RoutingTableImpl; -import org.opendaylight.yangtools.yang.common.QName; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleReference; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import java.io.Serializable; -import java.net.URI; - -@Path("router") -public class Router implements Serializable { - private Logger _logger = LoggerFactory.getLogger(Router.class); - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace, "heartbeat"); - - - @GET - @Path("/hello") - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "Hello"; - } - - - - - @GET - @Path("/rtadd") - @Produces(MediaType.TEXT_PLAIN) - public String addToRoutingTable(@QueryParam("nsp") String namespace,@QueryParam("inst") String instance,@QueryParam("port") String port) { - _logger.info("Invoking adding an entry in routing table"); - - BundleContext ctx = getBundleContext(); - ServiceReference routingTableServiceReference = ctx.getServiceReference(RoutingTable.class); - if (routingTableServiceReference == null) { - _logger.debug("Could not get routing table impl reference"); - return "Could not get routingtable referen "; - } - RoutingTableImpl routingTable = (RoutingTableImpl) ctx.getService(routingTableServiceReference); - if (routingTable == null) { - _logger.info("Could not get routing table service"); - return "Could not get routing table service"; - } - - - RouteIdentifierImpl rii = new RouteIdentifierImpl(namespace,instance); - try { - routingTable.addGlobalRoute(rii, instance+":"+ port); - } catch (RoutingTableException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - - } catch (SystemException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - } - - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("Result of adding route:").append("\n") - .append(routingTable.dumpRoutingTableCache()); - return stringBuilder.toString(); - } - - @GET - @Path("/rtdelete") - @Produces(MediaType.TEXT_PLAIN) - public String invokeDeleteRoutingTable(@QueryParam("nsp") String namespace,@QueryParam("inst") String instance) { - _logger.info("Invoking delete an entry in routing table"); - - BundleContext ctx = getBundleContext(); - ServiceReference routingTableServiceReference = ctx.getServiceReference(RoutingTable.class); - if (routingTableServiceReference == null) { - _logger.debug("Could not get routing table impl reference"); - return "Could not get routingtable referen "; - } - RoutingTableImpl routingTable = (RoutingTableImpl) ctx.getService(routingTableServiceReference); - if (routingTable == null) { - _logger.info("Could not get routing table service"); - return "Could not get routing table service"; - } - - - RouteIdentifierImpl rii = new RouteIdentifierImpl(namespace,instance); - try { - routingTable.removeGlobalRoute(rii); - } catch (RoutingTableException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - - } catch (SystemException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - } - - - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("Result of deleting route:").append("\n") - .append(routingTable.dumpRoutingTableCache()); - - return stringBuilder.toString(); - } - - @GET - @Path("/routingtable") - @Produces(MediaType.TEXT_PLAIN) - public String invokeGetRoutingTable() { - _logger.info("Invoking getting of routing table"); - - BundleContext ctx = getBundleContext(); - ServiceReference routingTableServiceReference = ctx.getServiceReference(RoutingTable.class); - if (routingTableServiceReference == null) { - _logger.debug("Could not get routing table impl reference"); - return "Could not get routingtable referen "; - } - RoutingTableImpl routingTable = (RoutingTableImpl) ctx.getService(routingTableServiceReference); - if (routingTable == null) { - _logger.info("Could not get routing table service"); - return "Could not get routing table service"; - } - - - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("Result of getting routetable:").append("\n") - .append(routingTable.dumpRoutingTableCache()); - - return stringBuilder.toString(); - } - - - - private BundleContext getBundleContext() { - ClassLoader tlcl = Thread.currentThread().getContextClassLoader(); - Bundle bundle = null; - - if (tlcl instanceof BundleReference) { - bundle = ((BundleReference) tlcl).getBundle(); - } else { - _logger.info("Unable to determine the bundle context based on " + - "thread context classloader."); - bundle = FrameworkUtil.getBundle(this.getClass()); - } - return (bundle == null ? null : bundle.getBundleContext()); - } - - - -} diff --git a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml deleted file mode 100644 index 2a0f3f3651..0000000000 --- a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - JAXRSZmqRT - com.sun.jersey.spi.container.servlet.ServletContainer - - javax.ws.rs.Application - org.opendaylight.controller.northbound.commons.NorthboundApplication - - 1 - - - - JAXRSZmqRT - /* - - - - - - - NB api - /* - POST - GET - PUT - PATCH - DELETE - HEAD - - - System-Admin - Network-Admin - Network-Operator - Container-User - - - - - System-Admin - - - Network-Admin - - - Network-Operator - - - Container-User - - - - BASIC - opendaylight - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml deleted file mode 100644 index 63b80e9181..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml +++ /dev/null @@ -1,176 +0,0 @@ - - - 4.0.0 - - org.opendaylight.controller - sal-parent - 1.1-SNAPSHOT - ../.. - - - sal-remoterpc-connector - bundle - - - 1.0.1 - 0.3.1 - - - - - ${project.groupId} - sal-common-util - ${project.version} - - - ${project.groupId} - sal-connector-api - ${project.version} - - - - ${project.groupId} - sal-core-api - ${project.version} - - - com.fasterxml.jackson.core - jackson-annotations - - - - com.fasterxml.jackson.core - jackson-core - - - - com.fasterxml.jackson.core - jackson-databind - - - com.google.guava - guava - - - - - junit - junit - - - org.mockito - mockito-all - - - org.opendaylight.controller - remoterpc-routingtable.implementation - ${project.version} - - - - - org.opendaylight.controller - sal - - - - - org.opendaylight.yangtools - yang-common - - - org.opendaylight.yangtools - yang-data-api - - - org.opendaylight.yangtools - yang-data-impl - - - - - org.osgi - org.osgi.core - - - org.slf4j - slf4j-api - - - org.zeromq - jeromq - ${zeromq.version} - - - - stax - stax-api - ${stax.version} - - - ch.qos.logback - logback-classic - test - - - - - - - org.apache.felix - maven-bundle-plugin - true - - - *, - !org.codehaus.enunciate.jaxrs - org.opendaylight.controller.config.yang.md.sal.remote.rpc, - org.opendaylight.controller.sal.connector.remoterpc.util, - org.opendaylight.controller.sal.connector.remoterpc.dto, - org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcClient, - org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcServer, - org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcProvider - ${project.groupId}.${project.artifactId} - - - - - - org.opendaylight.yangtools - yang-maven-plugin - - - - generate-sources - - - - - org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator - ${jmxGeneratorPath} - - urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang - - - - org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl - ${salGeneratorPath} - - - org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl - target/site/models - - - - org.opendaylight.yangtools.yang.unified.doc.generator.maven.DocumentationGeneratorImpl - target/site/models - - - true - - - - - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModule.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModule.java deleted file mode 100644 index e3ac9bab30..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModule.java +++ /dev/null @@ -1,69 +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.config.yang.md.sal.remote.rpc; - -import org.opendaylight.controller.sal.connector.remoterpc.ClientImpl; -import org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcProvider; -import org.opendaylight.controller.sal.connector.remoterpc.RoutingTableProvider; -import org.opendaylight.controller.sal.connector.remoterpc.ServerImpl; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; -import org.osgi.framework.BundleContext; - -/** - * - */ -public final class ZeroMQServerModule -extends org.opendaylight.controller.config.yang.md.sal.remote.rpc.AbstractZeroMQServerModule { - - private static final Integer ZEROMQ_ROUTER_PORT = 5554; - private BundleContext bundleContext; - - public ZeroMQServerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, - final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public ZeroMQServerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, - final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, - final ZeroMQServerModule oldModule, final java.lang.AutoCloseable oldInstance) { - - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - protected void customValidation() { - // Add custom validation for module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - - Broker broker = getDomBrokerDependency(); - - final int port = getPort() != null ? getPort() : ZEROMQ_ROUTER_PORT; - - ServerImpl serverImpl = new ServerImpl(port); - - ClientImpl clientImpl = new ClientImpl(); - - RoutingTableProvider provider = new RoutingTableProvider(bundleContext);//,serverImpl); - - RemoteRpcProvider facade = new RemoteRpcProvider(serverImpl, clientImpl); - facade.setRoutingTableProvider(provider); - facade.setContext(bundleContext); - facade.setRpcProvisionRegistry((RpcProvisionRegistry) broker); - - broker.registerProvider(facade, bundleContext); - return facade; - } - - public void setBundleContext(final BundleContext bundleContext) { - this.bundleContext = bundleContext; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModuleFactory.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModuleFactory.java deleted file mode 100644 index 0c2a370e06..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/config/yang/md/sal/remote/rpc/ZeroMQServerModuleFactory.java +++ /dev/null @@ -1,35 +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.config.yang.md.sal.remote.rpc; - -import org.opendaylight.controller.config.api.DependencyResolver; -import org.opendaylight.controller.config.api.DynamicMBeanWithInstance; -import org.opendaylight.controller.config.spi.Module; -import org.osgi.framework.BundleContext; - -/** -* -*/ -public class ZeroMQServerModuleFactory extends org.opendaylight.controller.config.yang.md.sal.remote.rpc.AbstractZeroMQServerModuleFactory -{ - - @Override - public Module createModule(String instanceName, DependencyResolver dependencyResolver, BundleContext bundleContext) { - ZeroMQServerModule module = (ZeroMQServerModule) super.createModule(instanceName, dependencyResolver, bundleContext); - module.setBundleContext(bundleContext); - return module; - } - - @Override - public Module createModule(String instanceName, DependencyResolver dependencyResolver, - DynamicMBeanWithInstance old, BundleContext bundleContext) throws Exception { - ZeroMQServerModule module = (ZeroMQServerModule) super.createModule(instanceName, dependencyResolver, old,bundleContext); - module.setBundleContext(bundleContext); - return module; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/CapturedMessageHandler.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/CapturedMessageHandler.java deleted file mode 100644 index 2dc5eee59a..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/CapturedMessageHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -public class CapturedMessageHandler implements Runnable { - - private Logger _logger = LoggerFactory.getLogger(CapturedMessageHandler.class); - - private ZMQ.Socket socket; - - public CapturedMessageHandler(ZMQ.Socket socket){ - this.socket = socket; - } - - @Override - public void run(){ - - try { - while (!Thread.currentThread().isInterrupted()){ - String message = socket.recvStr(); - _logger.debug("Captured [{}]", message); - } - } catch (Exception e) { - _logger.error("Exception raised [{}]", e.getMessage()); - } - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImpl.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImpl.java deleted file mode 100644 index 200ebaee6a..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImpl.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; -import java.util.concurrent.TimeUnit; - -import org.opendaylight.controller.sal.common.util.RpcErrors; -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException; -import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException; -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.opendaylight.controller.sal.connector.remoterpc.dto.RouteIdentifierImpl; -import org.opendaylight.controller.sal.connector.remoterpc.util.XmlUtils; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -import com.google.common.base.Optional; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; - -/** - * An implementation of {@link org.opendaylight.controller.sal.core.api.RpcImplementation} that makes - * remote RPC calls - */ -public class ClientImpl implements RemoteRpcClient { - - private final Logger _logger = LoggerFactory.getLogger(ClientImpl.class); - - private final ZMQ.Context context = ZMQ.context(1); - private final ClientRequestHandler handler; - private RoutingTableProvider routingTableProvider; - - public ClientImpl(){ - handler = new ClientRequestHandler(context); - start(); - } - - public ClientImpl(ClientRequestHandler handler){ - this.handler = handler; - start(); - } - - public RoutingTableProvider getRoutingTableProvider() { - return routingTableProvider; - } - - @Override - public void setRoutingTableProvider(RoutingTableProvider routingTableProvider) { - this.routingTableProvider = routingTableProvider; - } - - @Override - public void start() {/*NOOPS*/} - - @Override - public void stop() { - closeZmqContext(); - handler.close(); - _logger.info("Stopped"); - } - - @Override - public void close(){ - stop(); - } - - /** - * Finds remote server that can execute this rpc and sends a message to it - * requesting execution. - * The call blocks until a response from remote server is received. Its upto - * the client of this API to implement a timeout functionality. - * - * @param rpc remote service to be executed - * @param input payload for the remote service - * @return - */ - public ListenableFuture> invokeRpc(QName rpc, CompositeNode input) { - RouteIdentifierImpl routeId = new RouteIdentifierImpl(); - routeId.setType(rpc); - - String address = lookupRemoteAddressForGlobalRpc(routeId); - return sendMessage(input, routeId, address); - } - - /** - * Finds remote server that can execute this routed rpc and sends a message to it - * requesting execution. - * The call blocks until a response from remote server is received. Its upto - * the client of this API to implement a timeout functionality. - * - * @param rpc - * rpc to be called - * @param identifier - * instance identifier on which rpc is to be executed - * @param input - * payload - * @return - */ - public ListenableFuture> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) { - - RouteIdentifierImpl routeId = new RouteIdentifierImpl(); - routeId.setType(rpc); - routeId.setRoute(identifier); - - String address = lookupRemoteAddressForRpc(routeId); - - return sendMessage(input, routeId, address); - } - - private ListenableFuture> sendMessage(CompositeNode input, RouteIdentifierImpl routeId, String address) { - Message request = new Message.MessageBuilder() - .type(Message.MessageType.REQUEST) - .sender(Context.getInstance().getLocalUri()) - .recipient(address) - .route(routeId) - .payload(XmlUtils.compositeNodeToXml(input)) - .build(); - - List errors = new ArrayList(); - - try{ - Message response = handler.handle(request); - CompositeNode payload = null; - - if ( response != null ) { - - _logger.info("Received response [{}]", response); - - Object rawPayload = response.getPayload(); - switch (response.getType()) { - case ERROR: - if ( rawPayload instanceof List ) - errors = (List) rawPayload; - break; - - case RESPONSE: - payload = XmlUtils.xmlToCompositeNode((String) rawPayload); - break; - - default: - errors.add( - RpcErrors.getRpcError(null, null,null,null,"Unable to get response from remote controller", null, null) - ); - break; - - } - } - return Futures.immediateFuture(Rpcs.getRpcResult(true, payload, errors)); - - } catch (Exception e){ - collectErrors(e, errors); - return Futures.immediateFuture(Rpcs.getRpcResult(false, null, errors)); - } - } - - /** - * Find address for the given route identifier in routing table - * @param routeId route identifier - * @return remote network address - */ - private String lookupRemoteAddressForGlobalRpc(RpcRouter.RouteIdentifier routeId){ - checkNotNull(routeId, "route must not be null"); - - Optional, String>> routingTable = routingTableProvider.getRoutingTable(); - checkNotNull(routingTable.isPresent(), "Routing table is null"); - - String address = null; - try { - address = routingTable.get().getGlobalRoute(routeId); - } catch (RoutingTableException|SystemException e) { - _logger.error("Exception caught while looking up remote address " + e); - } - checkState(address != null, "Address not found for route [%s]", routeId); - - return address; - } - - /** - * Find address for the given route identifier in routing table - * @param routeId route identifier - * @return remote network address - */ - private String lookupRemoteAddressForRpc(RpcRouter.RouteIdentifier routeId){ - checkNotNull(routeId, "route must not be null"); - - Optional, String>> routingTable = routingTableProvider.getRoutingTable(); - checkNotNull(routingTable.isPresent(), "Routing table is null"); - - String address = routingTable.get().getLastAddedRoute(routeId); - checkState(address != null, "Address not found for route [%s]", routeId); - - return address; - } - - private void collectErrors(Exception e, List errors){ - if (e == null) return; - if (errors == null) errors = new ArrayList(); - - errors.add(RpcErrors.getRpcError(null, null, null, null, e.getMessage(), null, e.getCause())); - for (Throwable t : e.getSuppressed()) { - errors.add(RpcErrors.getRpcError(null, null, null, null, t.getMessage(), null, t)); - } - } - - /** - * Closes ZMQ Context. It tries to gracefully terminate the context. If - * termination takes more than a second, its forcefully shutdown. - */ - private void closeZmqContext() { - ExecutorService exec = Executors.newSingleThreadExecutor(); - FutureTask zmqTermination = new FutureTask(new Runnable() { - - @Override - public void run() { - try { - if (context != null) - context.term(); - _logger.debug("ZMQ Context terminated"); - } catch (Exception e) { - _logger.debug("ZMQ Context termination threw exception [{}]. Continuing shutdown...", e); - } - } - }, null); - - exec.execute(zmqTermination); - - try { - zmqTermination.get(1L, TimeUnit.SECONDS); - } catch (Exception e) {/*ignore and continue with shutdown*/} - - exec.shutdownNow(); - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandler.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandler.java deleted file mode 100644 index fe70fb77be..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandler.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import com.google.common.base.Preconditions; -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -/** - * - */ -class ClientRequestHandler implements AutoCloseable{ - - private Logger _logger = LoggerFactory.getLogger(ClientRequestHandler.class); - private final String DEFAULT_NAME = "remoterpc-client-worker"; - private final String INPROC_PROTOCOL_PREFIX = "inproc://"; - private final String TCP_PROTOCOL_PREFIX = "tcp://"; - - private ZMQ.Context context; - - /* - * Worker thread pool. Each thread runs a ROUTER-DEALER pair - */ - private ExecutorService workerPool; - - /* - * Set of remote servers this client is currently connected to - */ - private Map connectedServers; - - protected ClientRequestHandler(ZMQ.Context context) { - this.context = context; - connectedServers = new ConcurrentHashMap(); - start(); - } - - /** - * Starts a pool of worker as needed. A worker thread that has not been used for 5 min - * is terminated and removed from the pool. If thread dies due to an exception, its - * restarted. - */ - private void start(){ - - workerPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE, - 5L, TimeUnit.MINUTES, - new SynchronousQueue()){ - - @Override - protected void afterExecute(Runnable r, Throwable t) { - if (isTerminating() || isTerminated() || isShutdown()) - return; - - Worker worker = (Worker) r; - Preconditions.checkState( worker != null ); - String remoteServerAddress = worker.getRemoteServerAddress(); - connectedServers.remove(remoteServerAddress); - - if ( t != null ){ - _logger.debug("Exception caught while terminating worker [{},{}]. " + - "Restarting worker...", t.getClass(), t.getMessage()); - - connectedServers.put(remoteServerAddress, remoteServerAddress); - this.execute(r); - } - super.afterExecute(r, null); - } - }; - } - - public Message handle(Message request) throws IOException, ClassNotFoundException, InterruptedException { - - String remoteServerAddress = request.getRecipient(); - //if we already have router-dealer bridge setup for this address the send request - //otherwise first create the bridge and then send request - if ( connectedServers.containsKey(remoteServerAddress) ) - return sendMessage(request, remoteServerAddress); - - else{ - workerPool.execute(new Worker(remoteServerAddress)); - connectedServers.put(remoteServerAddress, remoteServerAddress); - //give little time for sockets to get initialized - //TODO: Add socket ping-pong message to ensure socket init rather than thread.sleep. - Thread.sleep(1000); - return sendMessage(request, remoteServerAddress); - } - } - - private Message sendMessage(Message request, String address) throws IOException, ClassNotFoundException { - Message response = null; - ZMQ.Socket socket = context.socket(ZMQ.REQ); - - try { - String inProcessSocketAddress = INPROC_PROTOCOL_PREFIX + address; - socket.connect( inProcessSocketAddress ); - _logger.debug("Sending request [{}]", request); - socket.send(Message.serialize(request)); - _logger.info("Request sent. Waiting for reply..."); - byte[] reply = socket.recv(0); - _logger.info("Response received"); - response = (Message) Message.deserialize(reply); - _logger.debug("Response [{}]", response); - } finally { - socket.close(); - } - return response; - } - - /** - * This gets called automatically if used with try-with-resources - */ - @Override - public void close(){ - workerPool.shutdown(); - _logger.info("Request Handler closed"); - } - - /** - * Total number of workers in the pool. Number of workers represent - * number of remote servers {@link org.opendaylight.controller.sal.connector.remoterpc.ClientImpl} is connected to. - * - * @return worker count - */ - public int getWorkerCount(){ - - if (workerPool == null) return 0; - - return ((ThreadPoolExecutor)workerPool).getActiveCount(); - } - /** - * Handles RPC request - */ - private class Worker implements Runnable { - private String name; - private String remoteServer; // - - public Worker(String address){ - this.name = DEFAULT_NAME + "[" + address + "]"; - this.remoteServer = address; - } - - public String getRemoteServerAddress(){ - return this.remoteServer; - } - - @Override - public void run() { - Thread.currentThread().setName(name); - _logger.debug("Starting ... "); - - ZMQ.Socket router = context.socket(ZMQ.ROUTER); - ZMQ.Socket dealer = context.socket(ZMQ.DEALER); - - try { - int success = router.bind(INPROC_PROTOCOL_PREFIX + remoteServer); - Preconditions.checkState(-1 != success, "Could not bind to " + remoteServer); - - dealer.connect(TCP_PROTOCOL_PREFIX + remoteServer); - - _logger.info("Worker started for [{}]", remoteServer); - - //TODO: Add capture handler - //This code will block until the zmq context is terminated. - ZMQ.proxy(router, dealer, null); - - } catch (Exception e) { - _logger.debug("Ignoring exception [{}, {}]", e.getClass(), e.getMessage()); - } finally { - try { - router.close(); - dealer.close(); - } catch (Exception x) { - _logger.debug("Exception while closing socket [{}]", x); - } - _logger.debug("Closing..."); - } - } - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/Context.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/Context.java deleted file mode 100644 index 37bff7b7bb..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/Context.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Enumeration; - -import org.zeromq.ZMQ; - -/** - * Provides a ZeroMQ Context object - */ -public class Context { - private final ZMQ.Context zmqContext = ZMQ.context(1); - private String uri; - private final String DEFAULT_RPC_PORT = "5554"; - - private static Context _instance = new Context(); - - private Context() {} - - public static Context getInstance(){ - return _instance; - } - - public ZMQ.Context getZmqContext(){ - return this.zmqContext; - } - - public String getLocalUri(){ - uri = (uri != null) ? uri - : new StringBuilder().append(getIpAddress()).append(":") - .append(getRpcPort()).toString(); - - return uri; - } - - public String getRpcPort(){ - String rpcPort = (System.getProperty("rpc.port") != null) - ? System.getProperty("rpc.port") - : DEFAULT_RPC_PORT; - - return rpcPort; - } - - private String getIpAddress(){ - String ipAddress = (System.getProperty("local.ip") != null) - ? System.getProperty("local.ip") - : findIpAddress(); - - return ipAddress; - } - - /** - * Finds IPv4 address of the local VM - * TODO: This method is non-deterministic. There may be more than one IPv4 address. Cant say which - * address will be returned. Read IP from a property file or enhance the code to make it deterministic. - * Should we use IP or hostname? - * - * @return - */ - private String findIpAddress() { - String hostAddress = null; - Enumeration e = null; - try { - e = NetworkInterface.getNetworkInterfaces(); - } catch (SocketException e1) { - e1.printStackTrace(); - } - while (e.hasMoreElements()) { - - NetworkInterface n = (NetworkInterface) e.nextElement(); - - Enumeration ee = n.getInetAddresses(); - while (ee.hasMoreElements()) { - InetAddress i = (InetAddress) ee.nextElement(); - if ((i instanceof Inet4Address) && (i.isSiteLocalAddress())) - hostAddress = i.getHostAddress(); - } - } - return hostAddress; - - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcClient.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcClient.java deleted file mode 100644 index 94e3232f17..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcClient.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -public interface RemoteRpcClient extends AutoCloseable{ - - void setRoutingTableProvider(RoutingTableProvider provider); - - void stop(); - - void start(); -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProvider.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProvider.java deleted file mode 100644 index 76df25682e..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProvider.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import static com.google.common.base.Preconditions.checkState; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.opendaylight.controller.md.sal.common.api.routing.RouteChange; -import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException; -import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException; -import org.opendaylight.controller.sal.connector.remoterpc.dto.RouteIdentifierImpl; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.sal.core.api.Provider; -import org.opendaylight.controller.sal.core.api.RoutedRpcDefaultImplementation; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry; -import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; -import org.opendaylight.controller.sal.core.api.RpcRoutingContext; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.osgi.framework.BundleContext; -import org.osgi.util.tracker.ServiceTracker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Optional; -import com.google.common.util.concurrent.ListenableFuture; - -public class RemoteRpcProvider implements - RpcImplementation, - RoutedRpcDefaultImplementation, - AutoCloseable, - Provider { - - private final Logger _logger = LoggerFactory.getLogger(RemoteRpcProvider.class); - - private final ServerImpl server; - private final ClientImpl client; - private RoutingTableProvider routingTableProvider; - private final RpcListener listener = new RpcListener(); - private final RoutedRpcListener routeChangeListener = new RoutedRpcListener(); - private ProviderSession brokerSession; - private RpcProvisionRegistry rpcProvisionRegistry; - private BundleContext context; - private ServiceTracker clusterTracker; - - public RemoteRpcProvider(ServerImpl server, ClientImpl client) { - this.server = server; - this.client = client; - } - - public void setRoutingTableProvider(RoutingTableProvider provider) { - this.routingTableProvider = provider; - client.setRoutingTableProvider(provider); - } - - public void setContext(BundleContext context){ - this.context = context; - } - - public void setRpcProvisionRegistry(RpcProvisionRegistry rpcProvisionRegistry){ - this.rpcProvisionRegistry = rpcProvisionRegistry; - } - - @Override - public void onSessionInitiated(ProviderSession session) { - brokerSession = session; - server.setBrokerSession(session); - start(); - } - - @Override - public Set getSupportedRpcs() { - //TODO: Ask Tony if we need to get this from routing table - return Collections.emptySet(); - } - - @Override - public Collection getProviderFunctionality() { - // TODO Auto-generated method stub - return null; - } - - @Override - public ListenableFuture> invokeRpc(QName rpc, CompositeNode input) { - return client.invokeRpc(rpc, input); - } - - @Override - public ListenableFuture> invokeRpc(QName rpc, InstanceIdentifier identifier, CompositeNode input) { - return client.invokeRpc(rpc, identifier, input); - } - - public void start() { - server.start(); - client.start(); - brokerSession.addRpcRegistrationListener(listener); - rpcProvisionRegistry.setRoutedRpcDefaultDelegate(this); - rpcProvisionRegistry.registerRouteChangeListener(routeChangeListener); - - announceSupportedRpcs(); - announceSupportedRoutedRpcs(); - } - - @Override - public void close() throws Exception { - unregisterSupportedRpcs(); - unregisterSupportedRoutedRpcs(); - server.close(); - client.close(); - } - - public void stop() { - server.stop(); - client.stop(); - } - - /** - * Add all the locally registered RPCs in the clustered routing table - */ - private void announceSupportedRpcs(){ - Set currentlySupported = brokerSession.getSupportedRpcs(); - for (QName rpc : currentlySupported) { - listener.onRpcImplementationAdded(rpc); - } - } - - /** - * Add all the locally registered Routed RPCs in the clustered routing table - */ - private void announceSupportedRoutedRpcs(){ - - //TODO: announce all routed RPCs as well - - } - - /** - * Un-Register all the supported RPCs from clustered routing table - */ - private void unregisterSupportedRpcs(){ - Set currentlySupported = brokerSession.getSupportedRpcs(); - //TODO: remove all routed RPCs as well - for (QName rpc : currentlySupported) { - listener.onRpcImplementationRemoved(rpc); - } - } - - /** - * Un-Register all the locally supported Routed RPCs from clustered routing table - */ - private void unregisterSupportedRoutedRpcs(){ - - //TODO: remove all routed RPCs as well - - } - - private RoutingTable, String> getRoutingTable(){ - Optional, String>> routingTable = - routingTableProvider.getRoutingTable(); - - checkState(routingTable.isPresent(), "Routing table is null"); - - return routingTable.get(); - } - - /** - * Listener for rpc registrations in broker - */ - private class RpcListener implements RpcRegistrationListener { - - @Override - public void onRpcImplementationAdded(QName rpc) { - - _logger.debug("Adding registration for [{}]", rpc); - RouteIdentifierImpl routeId = new RouteIdentifierImpl(); - routeId.setType(rpc); - - RoutingTable, String> routingTable = getRoutingTable(); - - try { - routingTable.addGlobalRoute(routeId, server.getServerAddress()); - _logger.debug("Route added [{}-{}]", routeId, server.getServerAddress()); - - } catch (RoutingTableException | SystemException e) { - //TODO: This can be thrown when route already exists in the table. Broker - //needs to handle this. - _logger.error("Unhandled exception while adding global route to routing table [{}]", e); - - } - } - - @Override - public void onRpcImplementationRemoved(QName rpc) { - - _logger.debug("Removing registration for [{}]", rpc); - RouteIdentifierImpl routeId = new RouteIdentifierImpl(); - routeId.setType(rpc); - - RoutingTable, String> routingTable = getRoutingTable(); - - try { - routingTable.removeGlobalRoute(routeId); - } catch (RoutingTableException | SystemException e) { - _logger.error("Route delete failed {}", e); - } - } - } - - /** - * Listener for Routed Rpc registrations in broker - */ - private class RoutedRpcListener - implements RouteChangeListener { - - /** - * - * @param routeChange - */ - @Override - public void onRouteChange(RouteChange routeChange) { - Map> announcements = routeChange.getAnnouncements(); - announce(getRouteIdentifiers(announcements)); - - Map> removals = routeChange.getRemovals(); - remove(getRouteIdentifiers(removals)); - } - - /** - * - * @param announcements - */ - private void announce(Set> announcements) { - _logger.debug("Announcing [{}]", announcements); - RoutingTable, String> routingTable = getRoutingTable(); - try { - routingTable.addRoutes(announcements, server.getServerAddress()); - } catch (RoutingTableException | SystemException e) { - _logger.error("Route announcement failed {}", e); - } - } - - /** - * - * @param removals - */ - private void remove(Set> removals){ - _logger.debug("Removing [{}]", removals); - RoutingTable, String> routingTable = getRoutingTable(); - try { - routingTable.removeRoutes(removals, server.getServerAddress()); - } catch (RoutingTableException | SystemException e) { - _logger.error("Route removal failed {}", e); - } - } - - /** - * - * @param changes - * @return - */ - private Set> getRouteIdentifiers(Map> changes) { - RouteIdentifierImpl routeId = null; - Set> routeIdSet = new HashSet<>(); - - for (RpcRoutingContext context : changes.keySet()){ - routeId = new RouteIdentifierImpl(); - routeId.setType(context.getRpc()); - //routeId.setContext(context.getContext()); - - for (InstanceIdentifier instanceId : changes.get(context)){ - routeId.setRoute(instanceId); - routeIdSet.add(routeId); - } - } - return routeIdSet; - } - - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcServer.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcServer.java deleted file mode 100644 index e845e43c2a..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcServer.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -public interface RemoteRpcServer extends AutoCloseable { - -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RoutingTableProvider.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RoutingTableProvider.java deleted file mode 100644 index d960303fcf..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/RoutingTableProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.impl.RoutingTableImpl; -import org.osgi.framework.BundleContext; -import org.osgi.util.tracker.ServiceTracker; - -import com.google.common.base.Optional; - -public class RoutingTableProvider implements AutoCloseable { - - @SuppressWarnings("rawtypes") - final ServiceTracker tracker; - - private RoutingTableImpl routingTableImpl = null; - - //final private RouteChangeListener routeChangeListener; - - - public RoutingTableProvider(BundleContext ctx){//,RouteChangeListener rcl) { - @SuppressWarnings("rawtypes") - ServiceTracker rawTracker = new ServiceTracker<>(ctx, RoutingTable.class, null); - tracker = rawTracker; - tracker.open(); - - //routeChangeListener = rcl; - } - - public Optional, String>> getRoutingTable() { - @SuppressWarnings("unchecked") - RoutingTable, String> tracked = tracker.getService(); - - if(tracked instanceof RoutingTableImpl){ - if(routingTableImpl != tracked){ - routingTableImpl= (RoutingTableImpl)tracked; - //routingTableImpl.setRouteChangeListener(routeChangeListener); - } - } - - return Optional.fromNullable(tracked); - } - - @Override - public void close() throws Exception { - tracker.close(); - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java deleted file mode 100644 index 3acea356ce..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImpl.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.connector.remoterpc; - -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; -import java.util.concurrent.TimeUnit; - -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.yangtools.yang.common.QName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; - -/** - * ZeroMq based implementation of RpcRouter. - */ -public class ServerImpl implements RemoteRpcServer { - - private final Logger _logger = LoggerFactory.getLogger(ServerImpl.class); - - private ExecutorService serverPool; - protected ServerRequestHandler handler; - - private Set remoteServices; - private ProviderSession brokerSession; - private ZMQ.Context context; - - private final String HANDLER_INPROC_ADDRESS = "inproc://rpc-request-handler"; - private final int HANDLER_WORKER_COUNT = 2; - private final int HWM = 200;//high water mark on sockets - private volatile State status = State.STOPPED; - - private String serverAddress; - private final int port; - - public static enum State { - STARTING, STARTED, STOPPED; - } - - public ServerImpl(int port) { - this.port = port; - } - - public State getStatus() { - return this.status; - } - - public Optional getHandler() { - return Optional.fromNullable(this.handler); - } - - public void setBrokerSession(ProviderSession session) { - this.brokerSession = session; - } - - public Optional getBrokerSession() { - return Optional.fromNullable(this.brokerSession); - } - - public Optional getZmqContext() { - return Optional.fromNullable(this.context); - } - - public String getServerAddress() { - return serverAddress; - } - - public String getHandlerAddress() { - return HANDLER_INPROC_ADDRESS; - } - - /** - * - */ - public void start() { - Preconditions.checkState(State.STOPPED == this.getStatus(), - "Remote RPC Server is already running"); - - status = State.STARTING; - _logger.debug("Remote RPC Server is starting..."); - - String hostIpAddress = findIpAddress(); - - //Log and silently die as per discussion in the bug (bug-362) - //https://bugs.opendaylight.org/show_bug.cgi?id=362 - // - // A tracking enhancement defect (bug-366) is created to properly fix this issue - //https://bugs.opendaylight.org/show_bug.cgi?id=366 - //checkState(hostIpAddress != null, "Remote RPC Server could not acquire host ip address"); - - if (hostIpAddress == null) { - _logger.error("Remote RPC Server could not acquire host ip address. Stopping..."); - stop(); - return; - } - - this.serverAddress = new StringBuilder(hostIpAddress). - append(":"). - append(port). - toString(); - - context = ZMQ.context(1); - remoteServices = new HashSet();// - serverPool = Executors.newSingleThreadExecutor();//main server thread - serverPool.execute(receive()); // Start listening rpc requests - - status = State.STARTED; - _logger.info("Remote RPC Server started [{}]", getServerAddress()); - } - - public void stop(){ - close(); - } - - /** - * - */ - @Override - public void close() { - - if (State.STOPPED == this.getStatus()) return; //do nothing - - if (serverPool != null) - serverPool.shutdown(); - - closeZmqContext(); - - status = State.STOPPED; - _logger.info("Remote RPC Server stopped"); - } - - /** - * Closes ZMQ Context. It tries to gracefully terminate the context. If - * termination takes more than 5 seconds, its forcefully shutdown. - */ - private void closeZmqContext() { - ExecutorService exec = Executors.newSingleThreadExecutor(); - FutureTask zmqTermination = new FutureTask(new Runnable() { - - @Override - public void run() { - try { - if (context != null) - context.term(); - _logger.debug("ZMQ Context terminated gracefully!"); - } catch (Exception e) { - _logger.debug("ZMQ Context termination threw exception [{}]. Continuing shutdown...", e); - } - } - }, null); - - exec.execute(zmqTermination); - - try { - zmqTermination.get(5L, TimeUnit.SECONDS); - } catch (Exception e) {/*ignore and continue with shutdown*/} - - exec.shutdownNow(); - } - - /** - * Main listener thread that spawns {@link ServerRequestHandler} as workers. - * - * @return - */ - private Runnable receive() { - return new Runnable() { - - @Override - public void run() { - Thread.currentThread().setName("remote-rpc-server"); - _logger.debug("Remote RPC Server main thread starting..."); - - //socket clients connect to (frontend) - ZMQ.Socket clients = context.socket(ZMQ.ROUTER); - - //socket RequestHandlers connect to (backend) - ZMQ.Socket workers = context.socket(ZMQ.DEALER); - - try (SocketPair capturePair = new SocketPair(); - ServerRequestHandler requestHandler = new ServerRequestHandler(context, - brokerSession, - HANDLER_WORKER_COUNT, - HANDLER_INPROC_ADDRESS, - getServerAddress());) { - - handler = requestHandler; - clients.setHWM(HWM); - clients.bind("tcp://*:" + port); - workers.setHWM(HWM); - workers.bind(HANDLER_INPROC_ADDRESS); - //start worker threads - _logger.debug("Remote RPC Server worker threads starting..."); - requestHandler.start(); - //start capture thread - // handlerPool.execute(new CaptureHandler(capturePair.getReceiver())); - // Connect work threads to client threads via a queue - ZMQ.proxy(clients, workers, null);//capturePair.getSender()); - - } catch (Exception e) { - _logger.debug("Unhandled exception [{}, {}]", e.getClass(), e.getMessage()); - } finally { - if (clients != null) clients.close(); - if (workers != null) workers.close(); - _logger.info("Remote RPC Server stopped"); - } - } - }; - } - - /** - * Finds IPv4 address of the local VM - * TODO: This method is non-deterministic. There may be more than one IPv4 address. Cant say which - * address will be returned. Read IP from a property file or enhance the code to make it deterministic. - * Should we use IP or hostname? - * - * @return - */ - private String findIpAddress() { - Enumeration e = null; - try { - e = NetworkInterface.getNetworkInterfaces(); - } catch (SocketException e1) { - _logger.error("Failed to get list of interfaces", e1); - return null; - } - while (e.hasMoreElements()) { - - NetworkInterface n = (NetworkInterface) e.nextElement(); - - Enumeration ee = n.getInetAddresses(); - while (ee.hasMoreElements()) { - InetAddress i = (InetAddress) ee.nextElement(); - _logger.debug("Trying address {}", i); - if ((i instanceof Inet4Address) && (!i.isLoopbackAddress())) { - String hostAddress = i.getHostAddress(); - _logger.debug("Settled on host address {}", hostAddress); - return hostAddress; - } - } - } - - _logger.error("Failed to find a suitable host address"); - return null; - } - -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandler.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandler.java deleted file mode 100644 index a25387d297..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandler.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Future; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.opendaylight.controller.sal.connector.remoterpc.util.XmlUtils; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -/** - * - */ -public class ServerRequestHandler implements AutoCloseable{ - - private final Logger _logger = LoggerFactory.getLogger(ServerRequestHandler.class); - private final String DEFAULT_NAME = "remote-rpc-worker"; - private final String dealerAddress; - private final String serverAddress; - private final int workerCount; - private final ZMQ.Context context; - private final Broker.ProviderSession broker; - - private RequestHandlerThreadPool workerPool; - private final AtomicInteger threadId = new AtomicInteger(); - - public ServerRequestHandler(ZMQ.Context context, - Broker.ProviderSession session, - int workerCount, - String dealerAddress, - String serverAddress) { - this.context = context; - this.dealerAddress = dealerAddress; - this.serverAddress = serverAddress; - this.broker = session; - this.workerCount = workerCount; - } - - public ThreadPoolExecutor getWorkerPool(){ - return workerPool; - } - - public void start(){ - workerPool = new RequestHandlerThreadPool( - workerCount, workerCount, - 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue()); - //unbound is ok. Task will never be submitted - - for (int i=0;i> rpc = null; - RpcResult result = null; - - //TODO Call this in a new thread with timeout - try { - rpc = broker.rpc( - (QName) request.getRoute().getType(), - XmlUtils.xmlToCompositeNode((String) request.getPayload())); - - result = (rpc != null) ? rpc.get() : null; - - handler.sendResponse(result); - - } catch (Exception e) { - _logger.debug("Broker threw [{}]", e); - handler.sendError(e.getMessage()); - } - } - - } - } catch (Exception e) { - printException(e); - } finally { - closeSocket(socket); - } - } - - private void printException(Exception e) { - try (StringWriter s = new StringWriter(); - PrintWriter p = new PrintWriter(s)) { - e.printStackTrace(p); - _logger.debug(s.toString()); - } catch (IOException e1) {/*Ignore and continue*/ } - } - - private void closeSocket(ZMQ.Socket socket) { - try { - if (socket != null) socket.close(); - } catch (Exception x) { - _logger.debug("Exception while closing socket [{}]", x); - } finally { - if (socket != null) socket.close(); - } - _logger.debug("Closing..."); - } - } - - - /** - * - */ - public class RequestHandlerThreadPool extends ThreadPoolExecutor{ - - public RequestHandlerThreadPool(int corePoolSize, - int maximumPoolSize, - long keepAliveTime, - TimeUnit unit, - BlockingQueue workQueue) { - super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); - } - - @Override - protected void afterExecute(Runnable r, Throwable t) { - if (isTerminating() || isTerminated() || isShutdown()) - return; - - if ( t != null ){ - _logger.debug("Exception caught while terminating worker [{},{}]", t.getClass(), t.getMessage()); - } - - this.execute(new Worker(threadId.incrementAndGet())); - super.afterExecute(r, null); - } - } - - class MessageHandler{ - private final ZMQ.Socket socket; - private Message message; //parsed message received on zmq server port - private boolean messageForBroker = false; //if the message is valid and not a "ping" message - - public MessageHandler(ZMQ.Socket socket){ - this.socket = socket; - } - - void receiveMessage(){ - byte[] bytes = socket.recv(); //this blocks - _logger.debug("Received bytes:[{}]", bytes.length); - - Object objectRecvd = null; - try{ - objectRecvd = Message.deserialize(bytes); - }catch (Exception e){ - sendError(e.getMessage()); - return; - } - - if (!(objectRecvd instanceof Message)) { - sendError("Invalid message received"); - return; - } - - message = (Message) objectRecvd; - - _logger.info("Received request [{}]", message); - - if (Message.MessageType.PING == message.getType()){ - sendPong(); - return; - } - - messageForBroker = true; - } - - boolean hasMessageForBroker(){ - return messageForBroker; - } - - Message getMessage(){ - return message; - } - - void sendResponse(RpcResult result){ - CompositeNode payload = (result != null) ? result.getResult() : null; - - String recipient = null; - RpcRouter.RouteIdentifier routeId = null; - - if (message != null) { - recipient = message.getSender(); - routeId = message.getRoute(); - } - - Message response = new Message.MessageBuilder() - .type(Message.MessageType.RESPONSE) - .sender(serverAddress) - .recipient(recipient) - .route(routeId) - .payload(XmlUtils.compositeNodeToXml(payload)) - .build(); - - send(response); - } - - private void sendError(String msg){ - Message errorResponse = new Message.MessageBuilder() - .type(Message.MessageType.ERROR) - .sender(serverAddress) - .payload(msg) - .build(); - - send(errorResponse); - } - - private void sendPong(){ - Message pong = new Message.MessageBuilder() - .type(Message.MessageType.PONG) - .sender(serverAddress) - .build(); - - send(pong); - } - - private void send(Message msg){ - byte[] serializedMessage = null; - try { - serializedMessage = Message.serialize(msg); - } catch (Exception e) { - _logger.debug("Unexpected error during serialization of response [{}]", msg); - return; - } - - if (serializedMessage != null) - if (socket.send(serializedMessage)) - _logger.info("Response sent [{}]", msg); - else _logger.debug("Failed to send serialized message"); - } - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/SocketPair.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/SocketPair.java deleted file mode 100644 index f569944a7f..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/SocketPair.java +++ /dev/null @@ -1,48 +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.connector.remoterpc; - -import org.zeromq.ZMQ; - -import java.util.UUID; - -/** - * - */ -public class SocketPair implements AutoCloseable{ - private ZMQ.Socket sender; - private ZMQ.Socket receiver; - - private static final String INPROC_PREFIX = "inproc://"; - - public SocketPair(){ - String address = new StringBuilder(INPROC_PREFIX) - .append(UUID.randomUUID()) - .toString(); - - receiver = Context.getInstance().getZmqContext().socket(ZMQ.PAIR); - receiver.bind(address); - - sender = Context.getInstance().getZmqContext().socket(ZMQ.PAIR); - sender.connect(address); - } - - public ZMQ.Socket getSender(){ - return this.sender; - } - - public ZMQ.Socket getReceiver(){ - return this.receiver; - } - - @Override - public void close() throws Exception { - sender.close(); - receiver.close(); - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/Message.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/Message.java deleted file mode 100644 index cbcfe3e2a9..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/Message.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc.dto; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import org.opendaylight.controller.sal.connector.api.RpcRouter; - -public class Message implements Serializable { - private static final long serialVersionUID = 1L; - - public static enum MessageType { - PING((byte) 0), - PONG((byte) 1), - REQUEST((byte) 2), - RESPONSE((byte) 3), - ERROR((byte)4); - - private final byte type; - - MessageType(byte type) { - this.type = type; - } - - public byte getType(){ - return this.type; - } - } - - private MessageType type; - private String sender; - private String recipient; - private RpcRouter.RouteIdentifier route; - private Object payload; - - public MessageType getType() { - return type; - } - - public void setType(MessageType type) { - this.type = type; - } - - public String getSender() { - return sender; - } - - public void setSender(String sender) { - this.sender = sender; - } - - public RpcRouter.RouteIdentifier getRoute() { - return route; - } - - public void setRoute(RpcRouter.RouteIdentifier route) { - this.route = route; - } - - public Object getPayload() { - return payload; - } - - public void setPayload(Object payload) { - this.payload = payload; - } - - public String getRecipient() { - return recipient; - } - - public void setRecipient(String recipient) { - this.recipient = recipient; - } - - @Override - public String toString() { - return "Message{" + - "type=" + type + - ", sender='" + sender + '\'' + - ", recipient='" + recipient + '\'' + - ", route=" + route + - ", payload=" + payload + - '}'; - } - - /** - * Converts any {@link Serializable} object to byte[] - * - * @param obj - * @return - * @throws IOException - */ - public static byte[] serialize(Object obj) throws IOException { - ByteArrayOutputStream b = new ByteArrayOutputStream(); - ObjectOutputStream o = new ObjectOutputStream(b); - o.writeObject(obj); - return b.toByteArray(); - } - - /** - * Converts byte[] to a java object - * - * @param bytes - * @return - * @throws IOException - * @throws ClassNotFoundException - */ - public static Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException { - ByteArrayInputStream b = new ByteArrayInputStream(bytes); - ObjectInputStream o = new ObjectInputStream(b); - return o.readObject(); - } - - public static class Response extends Message implements RpcRouter.RpcReply { - private static final long serialVersionUID = 1L; - private ResponseCode code; // response code - - public static enum ResponseCode { - SUCCESS(200), BADREQUEST(400), TIMEOUT(408), GONE(410), SERVERERROR(500), SERVICEUNAVAILABLE(503); - - private final int code; - - ResponseCode(int code) { - this.code = code; - } - } - - public ResponseCode getCode() { - return code; - } - - public void setCode(ResponseCode code) { - this.code = code; - } - } - - /** - * Builds a {@link Message} object - */ - public static class MessageBuilder{ - - private final Message message; - - public MessageBuilder(){ - message = new Message(); - } - - - public MessageBuilder type(MessageType type){ - message.setType(type); - return this; - } - - public MessageBuilder sender(String sender){ - message.setSender(sender); - return this; - } - - public MessageBuilder recipient(String recipient){ - message.setRecipient(recipient); - return this; - } - - public MessageBuilder route(RpcRouter.RouteIdentifier route){ - message.setRoute(route); - return this; - } - - public MessageBuilder payload(Object obj){ - message.setPayload(obj); - return this; - } - - public Message build(){ - return message; - } - } -} - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/MessageWrapper.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/MessageWrapper.java deleted file mode 100644 index 85f4113663..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/MessageWrapper.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc.dto; - -import org.zeromq.ZMQ; - -/** - * A class encapsulating {@link Message} and the {@link ZMQ.Socket} over which it is transmitted - */ -public class MessageWrapper { - - private Message _message; - private ZMQ.Socket _receiveSocket; - - public MessageWrapper(Message message, ZMQ.Socket receiveSocket) { - this._message = message; - this._receiveSocket = receiveSocket; - } - - public Message getMessage() { - return _message; - } - - public ZMQ.Socket getReceiveSocket() { - return _receiveSocket; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/RouteIdentifierImpl.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/RouteIdentifierImpl.java deleted file mode 100644 index 53c7cc0b8d..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/dto/RouteIdentifierImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.connector.remoterpc.dto; - -import java.io.Serializable; - -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; - -public class RouteIdentifierImpl implements RpcRouter.RouteIdentifier,Serializable { - private static final long serialVersionUID = 1L; - - private QName context; - private QName type; - private InstanceIdentifier route; - - @Override - public QName getContext() { - return this.context; - } - - @Override - public QName getType() { - return this.type; - } - - @Override - public InstanceIdentifier getRoute() { - return this.route; - } - - public void setContext(QName context) { - this.context = context; - } - - public void setType(QName type) { - this.type = type; - } - - public void setRoute(InstanceIdentifier route) { - this.route = route; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - RouteIdentifierImpl that = (RouteIdentifierImpl) o; - - if (context == null){ - if (that.getContext() != null) return false; - }else - if (!context.equals(that.context)) return false; - - if (route == null){ - if (that.getRoute() != null) return false; - }else - if (!route.equals(that.route)) return false; - - if (type == null){ - if (that.getType() != null) return false; - }else - if (!type.equals(that.type)) return false; - - return true; - } - - @Override - public int hashCode() { - int prime = 31; - int result = 0; - result = prime * result + (context == null ? 0:context.hashCode()); - result = prime * result + (type == null ? 0:type.hashCode()); - result = prime * result + (route == null ? 0:route.hashCode()); - return result; - } - - @Override - public String toString() { - return "RouteIdentifierImpl{" + - "context=" + context + - ", type=" + type + - ", route=" + route + - '}'; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/util/XmlUtils.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/util/XmlUtils.java deleted file mode 100644 index 3bc39630e1..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/util/XmlUtils.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc.util; - -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.SimpleNode; -import org.opendaylight.yangtools.yang.data.impl.NodeUtils; -import org.opendaylight.yangtools.yang.data.impl.XmlTreeBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; - -import javax.xml.stream.XMLStreamException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import java.io.ByteArrayInputStream; -import java.io.StringWriter; - -public class XmlUtils { - - private static final Logger _logger = LoggerFactory.getLogger(XmlUtils.class); - - public static String compositeNodeToXml(CompositeNode cNode){ - if (cNode == null) return new String(); - - Document domTree = NodeUtils.buildShadowDomTree(cNode); - StringWriter writer = new StringWriter(); - try { - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - transformer.transform(new DOMSource(domTree), new StreamResult(writer)); - } catch (TransformerException e) { - _logger.error("Error during translation of Document to OutputStream", e); - } - - return writer.toString(); - } - - public static CompositeNode xmlToCompositeNode(String xml){ - if (xml==null || xml.length()==0) return null; - - Node dataTree; - try { - dataTree = XmlTreeBuilder.buildDataTree(new ByteArrayInputStream(xml.getBytes())); - } catch (XMLStreamException e) { - _logger.error("Error during building data tree from XML", e); - return null; - } - if (dataTree == null) { - _logger.error("data tree is null"); - return null; - } - if (dataTree instanceof SimpleNode) { - _logger.error("RPC XML was resolved as SimpleNode"); - return null; - } - return (CompositeNode) dataTree; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/yang/odl-sal-dom-rpc-remote-cfg.yang b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/yang/odl-sal-dom-rpc-remote-cfg.yang deleted file mode 100644 index beeb936c97..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/main/yang/odl-sal-dom-rpc-remote-cfg.yang +++ /dev/null @@ -1,50 +0,0 @@ -module odl-sal-dom-rpc-remote-cfg { - yang-version 1; - namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote:rpc"; - prefix "rpc-cluster"; - - import config { prefix config; revision-date 2013-04-05; } - import opendaylight-md-sal-dom {prefix dom;} - - description - "Service definition for Binding Aware MD-SAL."; - - revision "2013-10-28" { - description - "Initial revision"; - } - - identity remote-rpc-server { - base config:service-type; - config:java-class "org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcServer"; - } - - identity remote-rpc-client { - base config:service-type; - config:java-class "org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcClient"; - } - - identity remote-zeromq-rpc-server { - base config:module-type; - config:java-name-prefix ZeroMQServer; - } - - augment "/config:modules/config:module/config:configuration" { - case remote-zeromq-rpc-server { - when "/config:modules/config:module/config:type = 'remote-zeromq-rpc-server'"; - - container dom-broker { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity dom:dom-broker-osgi-registry; - } - } - } - - leaf port { - type uint16; - } - } - } -} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImplTest.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImplTest.java deleted file mode 100644 index f8d14ce62e..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientImplTest.java +++ /dev/null @@ -1,107 +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.connector.remoterpc; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.opendaylight.controller.sal.connector.remoterpc.utils.MessagingUtil; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; - -import com.google.common.base.Optional; - -/** - * - */ -public class ClientImplTest { - RoutingTableProvider routingTableProvider; - ClientImpl client; - ClientRequestHandler mockHandler; - - @Before - public void setUp() throws Exception { - - //mock routing table - routingTableProvider = mock(RoutingTableProvider.class); - RoutingTable, String> mockRoutingTable = new MockRoutingTable(); - Optional, String>> optionalRoutingTable = Optional.fromNullable(mockRoutingTable); - when(routingTableProvider.getRoutingTable()).thenReturn(optionalRoutingTable); - - //mock ClientRequestHandler - mockHandler = mock(ClientRequestHandler.class); - - client = new ClientImpl(mockHandler); - client.setRoutingTableProvider(routingTableProvider); - - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void getRoutingTableProvider_Call_ShouldReturnMockProvider() throws Exception { - Assert.assertEquals(routingTableProvider, client.getRoutingTableProvider()); - - } - - @Test - public void testStart() throws Exception { - - } - - @Test - public void testStop() throws Exception { - - } - - @Test - public void testClose() throws Exception { - - } - - //@Test - public void invokeRpc_NormalCall_ShouldReturnSuccess() throws Exception { - - when(mockHandler.handle(any(Message.class))). - thenReturn(MessagingUtil.createEmptyMessage()); - - RpcResult result = client.invokeRpc(null, null).get(); - - Assert.assertTrue(result.isSuccessful()); - Assert.assertTrue(result.getErrors().isEmpty()); - Assert.assertNull(result.getResult()); - } - - //@Test - public void invokeRpc_HandlerThrowsException_ShouldReturnError() throws Exception { - - when(mockHandler.handle(any(Message.class))). - thenThrow(new IOException()); - - RpcResult result = client.invokeRpc(null, null).get(); - - Assert.assertFalse(result.isSuccessful()); - Assert.assertFalse(result.getErrors().isEmpty()); - Assert.assertNull(result.getResult()); - } - -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandlerTest.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandlerTest.java deleted file mode 100644 index 09188683cd..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ClientRequestHandlerTest.java +++ /dev/null @@ -1,124 +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.connector.remoterpc; - -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; -import java.util.concurrent.TimeUnit; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.opendaylight.controller.sal.connector.remoterpc.utils.MessagingUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -/** - * - */ -public class ClientRequestHandlerTest { - - private final Logger _logger = LoggerFactory.getLogger(ClientRequestHandlerTest.class); - - ZMQ.Context context; - ExecutorService serverThread; - final String SERVER_ADDRESS = "localhost:5553"; - - ClientRequestHandler handler; - - @Before - public void setUp() throws Exception { - context = ZMQ.context(1); - serverThread = Executors.newCachedThreadPool(); - handler = new ClientRequestHandler(context); - } - - @After - public void tearDown() throws Exception { - serverThread.shutdown(); - MessagingUtil.closeZmqContext(context); - handler.close(); - } - - @Test - public void handle_SingleRemote_ShouldReturnResponse() throws Exception { - serverThread.execute(MessagingUtil.startReplyServer(context, SERVER_ADDRESS, 1)); - Message request = new Message(); - request.setRecipient(SERVER_ADDRESS); - Message response = handleMessageWithTimeout(request); - Assert.assertNotNull(response); - //should be connected to only 1 remote server - Assert.assertEquals(1, handler.getWorkerCount()); - Assert.assertEquals(response.getRecipient(), SERVER_ADDRESS); - } - - // @Test - public void handle_MultiRemote_ShouldReturnResponses() throws Exception { - ExecutorService threadPool = Executors.newCachedThreadPool(); - final int port = 5555; - String serverAddress = null; - for (int i = 0; i < 5; i++) { - serverAddress = "localhost:" + (port + i); - serverThread.execute(MessagingUtil.startReplyServer(context, serverAddress, 1)); - threadPool.execute(createEmptyMessageTaskAndHandle(handler, serverAddress)); - } - Thread.sleep(5000);//wait for all messages to get processed - //should be connected to 5 remote server - Assert.assertEquals(5, handler.getWorkerCount()); - } - - private Runnable createEmptyMessageTaskAndHandle(final ClientRequestHandler handler, final String serverAddress) { - - return new Runnable() { - @Override - public void run() { - Message request = new Message(); - request.setRecipient(serverAddress); - try { - Message response = handleMessageWithTimeout(request); - Assert.assertNotNull(response); - Assert.assertEquals(response.getRecipient(), serverAddress); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }; - } - - private Message handleMessageWithTimeout(final Message request) { - Message response = null; - - FutureTask task = new FutureTask(new Callable() { - - @Override - public Message call() { - try { - return handler.handle(request); - } catch (Exception e) { - _logger.debug("Client handler failed to handle request. Exception is [{}]", e); - } - return null; - } - }); - - serverThread.execute(task); - - try { - response = (Message) task.get(5L, TimeUnit.SECONDS); //wait for max 5 sec for server to respond - } catch (Exception e) {/*ignore and continue*/} - - return response; - } - -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/MockRoutingTable.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/MockRoutingTable.java deleted file mode 100644 index 179051e4d4..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/MockRoutingTable.java +++ /dev/null @@ -1,79 +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.connector.remoterpc; - -import java.util.HashSet; -import java.util.Set; - -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException; -import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException; - -/** - * Mock implementation of routing table - */ -public class MockRoutingTable implements RoutingTable { - - - @Override - public void addRoute(Object o, Object o2) throws RoutingTableException, SystemException { - - } - - @Override - public void addGlobalRoute(Object o, Object o2) throws RoutingTableException, SystemException { - - } - - @Override - public void removeRoute(Object o, Object o2) { - - } - - @Override - public void addRoutes(Set set, Object o) throws RoutingTableException, SystemException { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void removeRoutes(Set set, Object o) throws RoutingTableException, SystemException { - //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void removeGlobalRoute(Object o) throws RoutingTableException, SystemException { - - } - - @Override - public Object getGlobalRoute(Object o) throws RoutingTableException, SystemException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public Set getRoutes(Object o) { - Set routes = new HashSet(); - routes.add("localhost:5554"); - return routes; - } - - @Override - public Object getLastAddedRoute(Object o) { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - -// @Override -// public Set getAllRoutes() { -// return Collections.emptySet(); -// } - -// @Override -// public Object getARoute(Object o) { -// return null; -// } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProviderTest.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProviderTest.java deleted file mode 100644 index 06360aa7b3..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/RemoteRpcProviderTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.opendaylight.controller.sal.connector.remoterpc; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class RemoteRpcProviderTest { - @Before - public void setUp() throws Exception { - - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void testSetRoutingTableProvider() throws Exception { - - } - - @Test - public void testOnSessionInitiated() throws Exception { - - } - - @Test - public void testGetSupportedRpcs() throws Exception { - - } - - @Test - public void testGetProviderFunctionality() throws Exception { - - } - - @Test - public void testInvokeRpc() throws Exception { - - } - - @Test - public void testInvokeRoutedRpc() throws Exception { - - } - - @Test - public void testStart() throws Exception { - - } - - @Test - public void testClose() throws Exception { - - } - - @Test - public void testStop() throws Exception { - - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/SerilizationTest.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/SerilizationTest.java deleted file mode 100644 index 41422fd680..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/SerilizationTest.java +++ /dev/null @@ -1,85 +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.connector.remoterpc; - -import org.junit.Test; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.SimpleNode; -import org.opendaylight.yangtools.yang.data.impl.NodeUtils; -import org.opendaylight.yangtools.yang.data.impl.XmlTreeBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; - -import javax.xml.stream.XMLStreamException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.io.StringWriter; - -public class SerilizationTest { - - private static final Logger _logger = LoggerFactory.getLogger(SerilizationTest.class); - - public void fromXml() { - } - - @Test - public void toXml() throws FileNotFoundException { - - //InputStream xmlStream = SerilizationTest.class.getResourceAsStream("/FourSimpleChildren.xml"); - InputStream xmlStream = SerilizationTest.class.getResourceAsStream("/AddFlow.xml"); - StringWriter writer = new StringWriter(); - - CompositeNode data = loadCompositeNode(xmlStream); - Document domTree = NodeUtils.buildShadowDomTree(data); - try { - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer transformer = tf.newTransformer(); - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); - //transformer.setOutputProperty(OutputKeys.METHOD, "xml"); - //transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - //transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - //transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); - transformer.transform(new DOMSource(domTree), new StreamResult(writer)); - } catch (TransformerException e) { - _logger.error("Error during translation of Document to OutputStream", e); - } - - _logger.info("Parsed xml [{}]", writer.toString()); - } - - // Figure out how to include TestUtils through pom ...was getting errors - private CompositeNode loadCompositeNode(InputStream xmlInputStream) throws FileNotFoundException { - if (xmlInputStream == null) { - throw new IllegalArgumentException(); - } - Node dataTree; - try { - dataTree = XmlTreeBuilder.buildDataTree(xmlInputStream); - } catch (XMLStreamException e) { - _logger.error("Error during building data tree from XML", e); - return null; - } - if (dataTree == null) { - _logger.error("data tree is null"); - return null; - } - if (dataTree instanceof SimpleNode) { - _logger.error("RPC XML was resolved as SimpleNode"); - return null; - } - return (CompositeNode) dataTree; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImplTest.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImplTest.java deleted file mode 100644 index 7ffdf17ce7..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerImplTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ThreadPoolExecutor; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.utils.MessagingUtil; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sal.core.api.RpcRegistrationListener; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.zeromq.ZMQ; - -import zmq.Ctx; -import zmq.SocketBase; - -import com.google.common.base.Optional; - -public class ServerImplTest { - - private static ZMQ.Context context; - private ServerImpl server; - private Broker.ProviderSession brokerSession; - private RoutingTableProvider routingTableProvider; - private RpcRegistrationListener listener; - - ExecutorService pool; - - //Server configuration - private final int HANDLER_COUNT = 2; - private final int HWM = 200; - private final int port = 5554; - //server address - private final String SERVER_ADDRESS = "tcp://localhost:5554"; - - //@BeforeClass - public static void init() { - context = ZMQ.context(1); - } - - //@AfterClass - public static void destroy() { - MessagingUtil.closeZmqContext(context); - } - - @Before - public void setup() throws InterruptedException { - context = ZMQ.context(1); - brokerSession = mock(Broker.ProviderSession.class); - routingTableProvider = mock(RoutingTableProvider.class); - listener = mock(RpcRegistrationListener.class); - - server = new ServerImpl(port); - server.setBrokerSession(brokerSession); - - RoutingTable, String> mockRoutingTable = new MockRoutingTable(); - Optional, String>> optionalRoutingTable = Optional.fromNullable(mockRoutingTable); - when(routingTableProvider.getRoutingTable()).thenReturn(optionalRoutingTable); - - when(brokerSession.addRpcRegistrationListener(listener)).thenReturn(null); - when(brokerSession.getSupportedRpcs()).thenReturn(Collections.emptySet()); - when(brokerSession.rpc(null, mock(CompositeNode.class))).thenReturn(null); - server.start(); - Thread.sleep(5000);//wait for server to start - } - - @After - public void tearDown() throws InterruptedException { - - if (pool != null) - pool.shutdown(); - - if (server != null) - server.stop(); - - MessagingUtil.closeZmqContext(context); - - Thread.sleep(5000);//wait for server to stop - Assert.assertEquals(ServerImpl.State.STOPPED, server.getStatus()); - } - - @Test - public void getBrokerSession_Call_ShouldReturnBrokerSession() throws Exception { - Optional mayBeBroker = server.getBrokerSession(); - - if (mayBeBroker.isPresent()) - Assert.assertEquals(brokerSession, mayBeBroker.get()); - else - Assert.fail("Broker does not exist in Remote RPC Server"); - - } - - @Test - public void start_Call_ShouldSetServerStatusToStarted() throws Exception { - Assert.assertEquals(ServerImpl.State.STARTED, server.getStatus()); - - } - - @Test - public void start_Call_ShouldCreateNZmqSockets() throws Exception { - final int EXPECTED_COUNT = 2 + HANDLER_COUNT; //1 ROUTER + 1 DEALER + HANDLER_COUNT - - Optional mayBeContext = server.getZmqContext(); - if (mayBeContext.isPresent()) - Assert.assertEquals(EXPECTED_COUNT, findSocketCount(mayBeContext.get())); - else - Assert.fail("ZMQ Context does not exist in Remote RPC Server"); - } - - @Test - public void start_Call_ShouldCreate1ServerThread() { - final String SERVER_THREAD_NAME = "remote-rpc-server"; - final int EXPECTED_COUNT = 1; - List serverThreads = findThreadsWithName(SERVER_THREAD_NAME); - Assert.assertEquals(EXPECTED_COUNT, serverThreads.size()); - } - - @Test - public void start_Call_ShouldCreateNHandlerThreads() { - //final String WORKER_THREAD_NAME = "remote-rpc-worker"; - final int EXPECTED_COUNT = HANDLER_COUNT; - - Optional serverRequestHandlerOptional = server.getHandler(); - if (serverRequestHandlerOptional.isPresent()){ - ServerRequestHandler handler = serverRequestHandlerOptional.get(); - ThreadPoolExecutor workerPool = handler.getWorkerPool(); - Assert.assertEquals(EXPECTED_COUNT, workerPool.getPoolSize()); - } else { - Assert.fail("Server is in illegal state. ServerHandler does not exist"); - } - - } - - @Test - public void testStop() throws Exception { - - } - - @Test - public void testOnRouteUpdated() throws Exception { - - } - - @Test - public void testOnRouteDeleted() throws Exception { - - } - - private int findSocketCount(ZMQ.Context context) - throws NoSuchFieldException, IllegalAccessException { - Field ctxField = context.getClass().getDeclaredField("ctx"); - ctxField.setAccessible(true); - Ctx ctx = Ctx.class.cast(ctxField.get(context)); - - Field socketListField = ctx.getClass().getDeclaredField("sockets"); - socketListField.setAccessible(true); - List sockets = List.class.cast(socketListField.get(ctx)); - - return sockets.size(); - } - - private List findThreadsWithName(String name) { - Thread[] threads = new Thread[Thread.activeCount()]; - Thread.enumerate(threads); - - List foundThreads = new ArrayList(); - for (Thread t : threads) { - if (t.getName().startsWith(name)) - foundThreads.add(t); - } - - return foundThreads; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandlerTest.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandlerTest.java deleted file mode 100644 index e5fbc761b4..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/ServerRequestHandlerTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc; - -import static org.mockito.Mockito.mock; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.sal.connector.remoterpc.utils.MessagingUtil; -import org.opendaylight.controller.sal.core.api.Broker; -import org.zeromq.ZMQ; - -public class ServerRequestHandlerTest { - - ServerRequestHandler handler; - ZMQ.Context context; - ExecutorService executorService = Executors.newCachedThreadPool(); - private final int workerCount = 2; - private final String mockDealerAddress = "inproc://rpc-request-handler"; - private final String mockServerIp = "localhost"; - private final int mockServerPort = 5554; - - @Before - public void setUp() throws Exception { - context = ZMQ.context(1); - String mockServerAddress = mockServerIp + ":" + mockServerPort; - Broker.ProviderSession mockSession = mock(Broker.ProviderSession.class); - handler = new ServerRequestHandler(context, mockSession, workerCount, mockDealerAddress, mockServerAddress); - handler.start(); - } - - @After - public void tearDown() throws Exception { - executorService.shutdown(); - MessagingUtil.closeZmqContext(context); - handler.close(); - } - - @Test - public void testStart() throws Exception { - //should start workers == workerCount - Assert.assertEquals(workerCount, handler.getWorkerPool().getPoolSize()); - - //killing a thread should recreate another one - - //start router-dealer bridge - executorService.execute(MessagingUtil.createRouterDealerBridge(context, mockDealerAddress, mockServerPort)); - Thread.sleep(1000); //give sometime for socket initialization - - //this will kill the thread - final String WORKER_THREAD_NAME = "remote-rpc-worker"; - interruptAThreadWithName(WORKER_THREAD_NAME); - - //send 4 message to router - for (int i = 0; i < 4; i++) - executorService.execute(MessagingUtil.sendAnEmptyMessage(context, "tcp://" + mockServerIp + ":" + mockServerPort)); - - //worker pool size should not change. - Assert.assertEquals(workerCount, handler.getWorkerPool().getPoolSize()); - - Thread.sleep(10000); //wait for processing to complete - } - - @Test - public void testClose() throws Exception { - - } - - /** - * Interrupts the first thread found whose name starts with the provided name - * - * @param name - */ - private void interruptAThreadWithName(String name) { - List workerThreads = findThreadsWithName(name); - if (workerThreads.size() > 0) workerThreads.get(0).interrupt(); - } - - /** - * Find all threads that start with the given name - * - * @param name - * @return - */ - private List findThreadsWithName(String name) { - Thread[] threads = new Thread[Thread.activeCount()]; - Thread.enumerate(threads); - - List foundThreads = new ArrayList(); - for (Thread t : threads) { - if (t.getName().startsWith(name)) - foundThreads.add(t); - } - - return foundThreads; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/MessagingUtil.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/MessagingUtil.java deleted file mode 100644 index 883aa52f3f..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/MessagingUtil.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.sal.connector.remoterpc.utils; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; -import java.util.concurrent.TimeUnit; - -import junit.framework.Assert; - -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -public class MessagingUtil { - - private static final Logger _logger = LoggerFactory.getLogger(MessagingUtil.class); - - public static Runnable startReplyServer(final ZMQ.Context context, - final String serverAddress, - final int numRequests /*number of requests after which server shuts down*/) { - return new Runnable() { - - @Override - public void run() { - final ZMQ.Socket socket = context.socket(ZMQ.REP); - try { - int returnCode = socket.bind("tcp://" + serverAddress); - Assert.assertNotSame(-1, returnCode); - _logger.info(" Starting reply server[{}] for test...", serverAddress); - - //for (int i=0;i zmqTermination = new FutureTask(new Runnable() { - - @Override - public void run() { - try { - if (context != null) - context.term(); - _logger.debug("ZMQ Context terminated gracefully!"); - } catch (Exception e) {/*Ignore and continue shutdown*/} - } - }, null); - - exec.execute(zmqTermination); - - try { - zmqTermination.get(1L, TimeUnit.SECONDS); - } catch (Exception e) { - _logger.debug("ZMQ Context terminated forcefully!"); - } - - exec.shutdownNow(); - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/RemoteServerTestClient.java b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/RemoteServerTestClient.java deleted file mode 100644 index 7a4f4a5974..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/utils/RemoteServerTestClient.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.opendaylight.controller.sal.connector.remoterpc.utils; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.opendaylight.controller.sal.connector.remoterpc.util.XmlUtils; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.zeromq.ZMQ; - -public class RemoteServerTestClient { - - - - public static void main(String args[]) throws Exception{ - String serverAddress = "tcp://10.195.128.108:5666"; - ZMQ.Context ctx = ZMQ.context(1); - ExecutorService executor = Executors.newSingleThreadExecutor(); - RemoteServerTestClient client = new RemoteServerTestClient(); - executor.execute( - MessagingUtil.sendAMessage(ctx, serverAddress, client.createPingMessage(serverAddress)) - ); - MessagingUtil.sendAMessage(ctx, serverAddress, client.createPingMessage(serverAddress)); - - Thread.sleep(5000); - MessagingUtil.closeZmqContext(ctx); - executor.shutdown(); - } - - public Message createPingMessage(String serverAddress){ - Message ping = new Message.MessageBuilder() - .type(Message.MessageType.PING) - .sender("localhost:5444") - .recipient(serverAddress) - .build(); - - return ping; - } - public Message createAddFlowMessage(String serverAddress ){ - - RpcRouter.RouteIdentifier routeIdentifier = getAddFlowRpcIdentifier(); - - Message addFlow = new Message.MessageBuilder() - .type(Message.MessageType.REQUEST) - .sender("localhost:5444") - .recipient(serverAddress) - .route(routeIdentifier) - .payload(getAddFlowPayload(1,1)) - .build(); - - return addFlow; - } - - private RpcRouter.RouteIdentifier getAddFlowRpcIdentifier(){ - throw new UnsupportedOperationException(); - } - - private CompositeNode getAddFlowPayload(int flowId, int tableId){ - final String xml = - "" - + "5" - + "Foo" - + "" - + "" - + "" - + "2048" - + "" - + "" - + "10.0.10.2/24" - + "" - + "" + flowId + "" - + "" + tableId + "" - + "" - + "" - + "0" - + "" - + "" - + "0" - + "" - + "" - + "" - + "" - + "" - + ""; - - return XmlUtils.xmlToCompositeNode(xml); - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/AddFlow.xml b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/AddFlow.xml deleted file mode 100644 index b042b8f65b..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/AddFlow.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - BA-7 - 4 - 5 - - /(urn:opendaylight:inventory?revision=2013-08-19)nodes/(urn:opendaylight:inventory?revision=2013-08-19)node[{(urn:opendaylight:inventory?revision=2013-08-19)id=openflow:1}] - - - 10.0.10.2/24 - - - 2048 - - - - - - 0 - - - 0 - - - - - - - /(urn:opendaylight:inventory?revision=2013-08-19)nodes/(urn:opendaylight:inventory?revision=2013-08-19)node[{(urn:opendaylight:inventory?revision=2013-08-19)id=openflow:1}]/(urn:opendaylight:flow:inventory?revision=2013-08-19)table[{(urn:opendaylight:flow:inventory?revision=2013-08-19)id=4}] - - - /(urn:opendaylight:inventory?revision=2013-08-19)nodes/(urn:opendaylight:inventory?revision=2013-08-19)node[{(urn:opendaylight:inventory?revision=2013-08-19)id=openflow:1}]/(urn:opendaylight:flow:inventory?revision=2013-08-19)table[{(urn:opendaylight:flow:inventory?revision=2013-08-19)id=4}]/(urn:opendaylight:flow:inventory?revision=2013-08-19)flow[{(urn:opendaylight:flow:inventory?revision=2013-08-19)id=4}] - - Foo - - \ No newline at end of file diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/FourSimpleChildren.xml b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/FourSimpleChildren.xml deleted file mode 100644 index 5ac991b120..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/FourSimpleChildren.xml +++ /dev/null @@ -1,6 +0,0 @@ - - eth0 - ethernetCsmacd - false - some interface - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/logback-test.xml b/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/logback-test.xml deleted file mode 100644 index 7eb75b90c7..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/src/test/resources/logback-test.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/pom.xml deleted file mode 100644 index 8435884e7b..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - 4.0.0 - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-parent - 1.1-SNAPSHOT - - sal-remoterpc-connector-test-consumer - bundle - - - - - org.opendaylight.controller - containermanager - - - - org.opendaylight.controller - sal - - - org.opendaylight.controller - sal-binding-api - - - org.opendaylight.controller - sal-common-util - - - - org.opendaylight.controller - sal-common-util - - - org.opendaylight.controller - sal-core-api - - - org.opendaylight.yangtools - yang-binding - - - org.opendaylight.yangtools - yang-common - - - org.opendaylight.yangtools - yang-data-api - - - org.opendaylight.yangtools - yang-data-impl - ${yangtools.version} - - - - - - - org.apache.felix - maven-bundle-plugin - - - org.opendaylight.controller.sample.zeromq.consumer.ExampleConsumer - - - - - - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/java/org/opendaylight/controller/sample/zeromq/consumer/ExampleConsumer.java b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/java/org/opendaylight/controller/sample/zeromq/consumer/ExampleConsumer.java deleted file mode 100644 index aac6da47ba..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/java/org/opendaylight/controller/sample/zeromq/consumer/ExampleConsumer.java +++ /dev/null @@ -1,128 +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.sample.zeromq.consumer; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.net.URI; -import java.util.Hashtable; -import java.util.concurrent.Future; - -import org.opendaylight.controller.sal.core.api.AbstractConsumer; -import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.api.SimpleNode; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.opendaylight.yangtools.yang.data.impl.XmlTreeBuilder; - -import javax.xml.stream.XMLStreamException; - -public class ExampleConsumer extends AbstractConsumer { - - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace, "heartbeat"); - - private ConsumerSession session; - - private ServiceRegistration thisReg; - private Logger _logger = LoggerFactory.getLogger(ExampleConsumer.class); - - @Override - public void onSessionInitiated(ConsumerSession session) { - this.session = session; - } - - public RpcResult invokeRpc(QName qname, CompositeNode input) { - _logger.info("Invoking RPC:[{}] with Input:[{}]", qname.getLocalName(), input); - RpcResult result = null; - Future> future = ExampleConsumer.this.session.rpc(qname, input); - try { - result = future.get(); - } catch (Exception e) { - e.printStackTrace(); - } - _logger.info("Returning Result:[{}]", result); - return result; - } - - @Override - protected void startImpl(BundleContext context){ - thisReg = context.registerService(ExampleConsumer.class, this, new Hashtable()); - } - @Override - protected void stopImpl(BundleContext context) { - super.stopImpl(context); - thisReg.unregister(); - } - - public CompositeNode getValidCompositeNodeWithOneSimpleChild() throws FileNotFoundException { - InputStream xmlStream = ExampleConsumer.class.getResourceAsStream("/OneSimpleChild.xml"); - return loadCompositeNode(xmlStream); - } - - public CompositeNode getValidCompositeNodeWithTwoSimpleChildren() throws FileNotFoundException { - InputStream xmlStream = ExampleConsumer.class.getResourceAsStream("/TwoSimpleChildren.xml"); - return loadCompositeNode(xmlStream); - } - - public CompositeNode getValidCompositeNodeWithFourSimpleChildren() throws FileNotFoundException { - InputStream xmlStream = ExampleConsumer.class.getResourceAsStream("/FourSimpleChildren.xml"); - return loadCompositeNode(xmlStream); - } - - public CompositeNode getValidCompositeNodeWithOneSimpleOneCompositeChild() throws FileNotFoundException { - InputStream xmlStream = ExampleConsumer.class.getResourceAsStream("/OneSimpleOneCompositeChild.xml"); - return loadCompositeNode(xmlStream); - } - - public CompositeNode getValidCompositeNodeWithTwoCompositeChildren() throws FileNotFoundException { - InputStream xmlStream = ExampleConsumer.class.getResourceAsStream("/TwoCompositeChildren.xml"); - return loadCompositeNode(xmlStream); - } - - public CompositeNode getInvalidCompositeNodeSimpleChild() throws FileNotFoundException { - InputStream xmlStream = ExampleConsumer.class.getResourceAsStream("/InvalidSimpleChild.xml"); - return loadCompositeNode(xmlStream); - } - - public CompositeNode getInvalidCompositeNodeCompositeChild() throws FileNotFoundException { - InputStream xmlStream = ExampleConsumer.class.getResourceAsStream("/InvalidCompositeChild.xml"); - return loadCompositeNode(xmlStream); - } - - //Note to self: Stolen from TestUtils - ///Users/alefan/odl/controller4/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java - // Figure out how to include TestUtils through pom ...was getting errors - private CompositeNode loadCompositeNode(InputStream xmlInputStream) throws FileNotFoundException { - if (xmlInputStream == null) { - throw new IllegalArgumentException(); - } - Node dataTree; - try { - dataTree = XmlTreeBuilder.buildDataTree(xmlInputStream); - } catch (XMLStreamException e) { - _logger.error("Error during building data tree from XML", e); - return null; - } - if (dataTree == null) { - _logger.error("data tree is null"); - return null; - } - if (dataTree instanceof SimpleNode) { - _logger.error("RPC XML was resolved as SimpleNode"); - return null; - } - return (CompositeNode) dataTree; - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/FourSimpleChildren.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/FourSimpleChildren.xml deleted file mode 100644 index 5ac991b120..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/FourSimpleChildren.xml +++ /dev/null @@ -1,6 +0,0 @@ - - eth0 - ethernetCsmacd - false - some interface - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidCompositeChild.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidCompositeChild.xml deleted file mode 100644 index 3979d02ccf..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidCompositeChild.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - eth1 - ethernet - false - some interface - - - error - ethernet - true - some interface - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidSimpleChild.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidSimpleChild.xml deleted file mode 100644 index 6082d72a71..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/InvalidSimpleChild.xml +++ /dev/null @@ -1,3 +0,0 @@ - - error - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleChild.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleChild.xml deleted file mode 100644 index f431b0453d..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleChild.xml +++ /dev/null @@ -1,3 +0,0 @@ - - eth0 - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleOneCompositeChild.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleOneCompositeChild.xml deleted file mode 100644 index bca7682ee7..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/OneSimpleOneCompositeChild.xml +++ /dev/null @@ -1,9 +0,0 @@ - - eth0 - - eth1 - ethernetCsmacd - false - some interface - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoCompositeChildren.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoCompositeChildren.xml deleted file mode 100644 index c49407e4c0..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoCompositeChildren.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - eth1 - ethernet - false - some interface - - - eth2 - ethernet - true - some interface - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoSimpleChildren.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoSimpleChildren.xml deleted file mode 100644 index 5f4729c99d..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/consumer-service/src/main/resources/TwoSimpleChildren.xml +++ /dev/null @@ -1,4 +0,0 @@ - - eth0 - ethernetCsmacd - \ No newline at end of file diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/pom.xml deleted file mode 100644 index 3f47700f8d..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/pom.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - 4.0.0 - - org.opendaylight.controller - sal-parent - 1.1-SNAPSHOT - ../.. - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-parent - pom - - - consumer-service - provider-service - test-it - test-nb - - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/pom.xml deleted file mode 100644 index 2b9dc0cf25..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/pom.xml +++ /dev/null @@ -1,82 +0,0 @@ - - 4.0.0 - - sal-remoterpc-connector-test-parent - org.opendaylight.controller.tests - 1.1-SNAPSHOT - - sal-remoterpc-connector-test-provider - bundle - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL - - - - - - - org.apache.felix - maven-bundle-plugin - - - org.opendaylight.controller.sample.zeromq.provider.ExampleProvider - - - - - - - - - org.opendaylight.controller - sal-binding-api - - - org.opendaylight.controller - sal-common-util - - - org.opendaylight.controller - sal-core-api - - - - - org.opendaylight.controller - containermanager - - - - org.opendaylight.controller - sal - - - org.opendaylight.yangtools - yang-binding - - - org.opendaylight.yangtools - yang-common - - - org.opendaylight.yangtools - yang-data-api - - - org.opendaylight.yangtools - yang-data-impl - - - org.opendaylight.controller - sal-common-util - - - org.opendaylight.controller - sal-remoterpc-connector - - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/src/main/java/org/opendaylight/controller/sample/zeromq/provider/ExampleProvider.java b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/src/main/java/org/opendaylight/controller/sample/zeromq/provider/ExampleProvider.java deleted file mode 100644 index ff930db6fd..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/provider-service/src/main/java/org/opendaylight/controller/sample/zeromq/provider/ExampleProvider.java +++ /dev/null @@ -1,130 +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.sample.zeromq.provider; - -import org.opendaylight.controller.sal.common.util.RpcErrors; -import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.controller.sal.core.api.AbstractProvider; -import org.opendaylight.controller.sal.core.api.Broker.ProviderSession; -import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration; -import org.opendaylight.controller.sal.core.api.RpcImplementation; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.Node; -import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl; -import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class ExampleProvider extends AbstractProvider implements RpcImplementation { - - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace, "heartbeat"); - private RpcRegistration reg; - - private ServiceRegistration thisReg; - - private ProviderSession session; - private Logger _logger = LoggerFactory.getLogger(ExampleProvider.class); - - @Override - public void onSessionInitiated(ProviderSession session) { - this.session = session; - } - - @Override - public Set getSupportedRpcs() { - Set supportedRpcs = new HashSet(); - supportedRpcs.add(QNAME); - return supportedRpcs; - } - - @Override - public RpcResult invokeRpc(final QName rpc, CompositeNode input) { - boolean success = false; - CompositeNode output = null; - Collection errors = new ArrayList<>(); - - // Only handle supported RPC calls - if (getSupportedRpcs().contains(rpc)) { - if (input == null) { - errors.add(RpcErrors.getRpcError("app", "tag", "info", RpcError.ErrorSeverity.WARNING, "message:null input", RpcError.ErrorType.RPC, null)); - } - else { - if (isErroneousInput(input)) { - errors.add(RpcErrors.getRpcError("app", "tag", "info", RpcError.ErrorSeverity.ERROR, "message:error", RpcError.ErrorType.RPC, null)); - } - else { - success = true; - output = addSuccessNode(input); - } - } - } - return Rpcs.getRpcResult(success, output, errors); - } - - // Examines input -- dives into CompositeNodes and finds any value equal to "error" - private boolean isErroneousInput(CompositeNode input) { - for (Node n : input.getChildren()) { - if (n instanceof CompositeNode) { - if (isErroneousInput((CompositeNode)n)) { - return true; - } - } - else { //SimpleNode - if ((input.getChildren().get(0).getValue()).equals("error")) { - return true; - } - } - } - return false; - } - - // Adds a child SimpleNode containing the value "success" to the input CompositeNode - private CompositeNode addSuccessNode(CompositeNode input) { - List> list = new ArrayList>(input.getChildren()); - SimpleNodeTOImpl simpleNode = new SimpleNodeTOImpl(QNAME, input, "success"); - list.add(simpleNode); - return new CompositeNodeTOImpl(QNAME, null, list); - } - - @Override - protected void startImpl(BundleContext context) { - thisReg = context.registerService(ExampleProvider.class, this, new Hashtable()); - } - - @Override - protected void stopImpl(BundleContext context) { - if (reg != null) { - try { - reg.close(); - thisReg.unregister(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - public void announce(QName name) { - _logger.debug("Announcing [{}]\n\n\n", name); - reg = this.session.addRpcImplementation(name, this); - } - -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/pom.xml deleted file mode 100644 index 0ffc330f90..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/pom.xml +++ /dev/null @@ -1,467 +0,0 @@ - - 4.0.0 - - sal-remoterpc-connector-test-parent - org.opendaylight.controller.tests - 1.1-SNAPSHOT - - sal-remoterpc-connector-test-it - - scm:git:ssh://git.opendaylight.org:29418/controller.git - scm:git:ssh://git.opendaylight.org:29418/controller.git - https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL - - - - - - - org.ops4j.pax.exam - maven-paxexam-plugin - - - generate-config - - generate-depends-file - - - - - - - - - - org.eclipse.m2e - lifecycle-mapping - ${lifecycle.mapping.version} - - - - - - - org.ops4j.pax.exam - - - maven-paxexam-plugin - - - [1.2.4,) - - - - generate-depends-file - - - - - - - - - - - - - - - - - - org.opendaylight.yangtools.thirdparty - xtend-lib-osgi - - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-provider - - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-consumer - - - org.opendaylight.controller - sal-broker-impl - - - org.ops4j.pax.exam - pax-exam-container-native - ${exam.version} - test - - - org.ops4j.pax.exam - pax-exam-junit4 - ${exam.version} - test - - - org.ops4j.pax.exam - pax-exam-link-mvn - ${exam.version} - test - - - org.ops4j.pax.url - pax-url-aether - test - - - equinoxSDK381 - org.eclipse.osgi - test - - - org.slf4j - log4j-over-slf4j - - - ch.qos.logback - logback-core - - - ch.qos.logback - logback-classic - - - org.opendaylight.controller - sal-binding-api - - - org.opendaylight.controller - sal-common-util - - - org.opendaylight.controller - sal-core-api - - - org.opendaylight.controller - sal-remoterpc-connector - - - - org.opendaylight.controller - containermanager - - - org.osgi - org.osgi.compendium - - - commons-io - commons-io - - - - - - org.opendaylight.yangtools - yang-binding - - - org.opendaylight.yangtools - yang-common - - - org.opendaylight.yangtools - yang-data-api - - - - org.opendaylight.yangtools - yang-parser-impl - ${yangtools.version} - - - org.opendaylight.controller - sal-common-util - - - org.opendaylight.yangtools.thirdparty - antlr4-runtime-osgi-nohead - - - - - org.opendaylight.controller - zeromq-routingtable.implementation - - - org.opendaylight.controller - clustering.services - - - org.opendaylight.controller - sal - - - org.osgi - org.osgi.compendium - - - - - org.opendaylight.controller - sal.implementation - - - commons-io - commons-io - - - - - org.opendaylight.controller - containermanager - - - org.osgi - org.osgi.compendium - - - commons-io - commons-io - - - - - org.opendaylight.controller - containermanager.it.implementation - - - commons-io - commons-io - - - - - org.opendaylight.controller - clustering.stub - - - commons-io - commons-io - - - - - - org.apache.felix - org.apache.felix.dependencymanager.shell - - - org.osgi - org.osgi.compendium - - - - - eclipselink - javax.resource - - - com.google.guava - guava - - - org.opendaylight.controller - sal - - - org.opendaylight.controller - ietf-netconf-monitoring - - - org.opendaylight.yangtools - yang-binding - - - org.opendaylight.yangtools.model - yang-ext - - - org.opendaylight.yangtools.model - opendaylight-l2-types - - - org.opendaylight.controller - sal-binding-it - - - org.opendaylight.controller - sal-binding-config - - - org.opendaylight.controller - sal-binding-broker-impl - - - org.opendaylight.controller - sal-broker-impl - - - - org.opendaylight.controller.model - model-inventory - - - org.opendaylight.yangtools - yang-common - - - org.opendaylight.controller - sal-connector-api - - - org.opendaylight.controller - sal-common-util - - - - org.opendaylight.controller - clustering.services - - - - equinoxSDK381 - org.eclipse.osgi - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - - - org.zeromq - jeromq - - - - org.opendaylight.yangtools.thirdparty - xtend-lib-osgi - test - - - org.opendaylight.controller - sal-binding-broker-impl - provided - - - org.ops4j.pax.exam - pax-exam-container-native - ${exam.version} - test - - - org.ops4j.pax.exam - pax-exam-junit4 - ${exam.version} - test - - - org.opendaylight.controller - config-netconf-connector - test - - - org.opendaylight.controller - logback-config - - - org.opendaylight.controller - config-persister-impl - - - org.opendaylight.controller - config-persister-file-xml-adapter - - - org.opendaylight.controller - netconf-impl - - - org.opendaylight.controller - netconf-client - - - org.ops4j.pax.exam - pax-exam - ${exam.version} - - compile - - - org.ops4j.pax.exam - pax-exam-link-mvn - ${exam.version} - test - - - equinoxSDK381 - org.eclipse.osgi - test - - - org.slf4j - log4j-over-slf4j - - - ch.qos.logback - logback-core - - - ch.qos.logback - logback-classic - - - org.mockito - mockito-all - test - - - org.opendaylight.controller.model - model-flow-service - provided - - - org.opendaylight.controller - config-manager - - - commons-io - commons-io - - - - - org.opendaylight.controller.model - model-flow-management - provided - - - org.opendaylight.yangtools.thirdparty - antlr4-runtime-osgi-nohead - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/java/org/opendaylight/controller/sample/zeromq/test/it/RouterTest.java b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/java/org/opendaylight/controller/sample/zeromq/test/it/RouterTest.java deleted file mode 100644 index e02e290a29..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/java/org/opendaylight/controller/sample/zeromq/test/it/RouterTest.java +++ /dev/null @@ -1,452 +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.sample.zeromq.test.it; - -import junit.framework.Assert; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.opendaylight.controller.sal.connector.remoterpc.RemoteRpcClient; - -import org.opendaylight.controller.sal.connector.remoterpc.dto.Message; -import org.opendaylight.controller.sal.core.api.Broker; -import org.opendaylight.controller.sample.zeromq.consumer.ExampleConsumer; -import org.opendaylight.controller.sample.zeromq.provider.ExampleProvider; - -import org.opendaylight.controller.test.sal.binding.it.TestHelper; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcError; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.util.Filter; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; -import org.osgi.framework.ServiceReference; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.zeromq.ZMQ; - -import javax.inject.Inject; - -import java.io.IOException; -import java.net.URI; - -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles; -import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles; - -//import static org.ops4j.pax.exam.CoreOptions.*; - -@RunWith(PaxExam.class) -public class RouterTest { - - private Logger _logger = LoggerFactory.getLogger(RouterTest.class); - - public static final String ODL = "org.opendaylight.controller"; - public static final String YANG = "org.opendaylight.yangtools"; - public static final String SAMPLE = "org.opendaylight.controller.tests"; - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace, "heartbeat"); - - - @Inject - org.osgi.framework.BundleContext ctx; - - @Inject - @Filter(timeout=60*1000) - Broker broker; - - private ZMQ.Context zmqCtx = ZMQ.context(1); - //private Server router; - //private ExampleProvider provider; - - //@Test - public void testInvokeRpc() throws Exception{ - //Thread.sleep(1000); - //Send announcement - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - Assert.assertNotNull(providerRef); - - ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); - Assert.assertNotNull(provider); - - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - Assert.assertNotNull(consumerRef); - ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); - Assert.assertNotNull(consumer); - - - _logger.debug("Provider sends announcement [{}]", "heartbeat"); - provider.announce(QNAME); - ServiceReference routerRef = ctx.getServiceReference(RemoteRpcClient.class); - RemoteRpcClient router = (RemoteRpcClient) ctx.getService(routerRef); - _logger.debug("Found router[{}]", router); - _logger.debug("Invoking RPC [{}]", QNAME); - for (int i = 0; i < 3; i++) { - RpcResult result = router.invokeRpc(QNAME, consumer.getValidCompositeNodeWithOneSimpleChild()); - _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); - Assert.assertNotNull(result); - } - } - - @Test - public void testInvokeRpcWithValidSimpleNode() throws Exception{ - //Thread.sleep(1500); - - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - Assert.assertNotNull(providerRef); - ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); - Assert.assertNotNull(provider); - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - Assert.assertNotNull(consumerRef); - ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); - Assert.assertNotNull(consumer); - - // Provider sends announcement - _logger.debug("Provider sends announcement [{}]", "heartbeat"); - provider.announce(QNAME); - // Consumer invokes RPC - _logger.debug("Invoking RPC [{}]", QNAME); - CompositeNode input = consumer.getValidCompositeNodeWithOneSimpleChild(); - for (int i = 0; i < 3; i++) { - RpcResult result = consumer.invokeRpc(QNAME, input); - Assert.assertNotNull(result); - _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); - Assert.assertTrue(result.isSuccessful()); - Assert.assertNotNull(result.getResult()); - Assert.assertEquals(0, result.getErrors().size()); - Assert.assertEquals(input.getChildren().size()+1, result.getResult().getChildren().size()); - } - } - - @Test - public void testInvokeRpcWithValidSimpleNodes() throws Exception{ - //Thread.sleep(1500); - - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - Assert.assertNotNull(providerRef); - ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); - Assert.assertNotNull(provider); - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - Assert.assertNotNull(consumerRef); - ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); - Assert.assertNotNull(consumer); - - // Provider sends announcement - _logger.debug("Provider sends announcement [{}]", "heartbeat"); - provider.announce(QNAME); - // Consumer invokes RPC - _logger.debug("Invoking RPC [{}]", QNAME); - CompositeNode input = consumer.getValidCompositeNodeWithFourSimpleChildren(); - for (int i = 0; i < 3; i++) { - RpcResult result = consumer.invokeRpc(QNAME, input); - Assert.assertNotNull(result); - _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); - Assert.assertTrue(result.isSuccessful()); - Assert.assertNotNull(result.getResult()); - Assert.assertEquals(0, result.getErrors().size()); - Assert.assertEquals(input.getChildren().size()+1, result.getResult().getChildren().size()); - } - } - - @Test - public void testInvokeRpcWithValidCompositeNode() throws Exception{ - //Thread.sleep(1500); - - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - Assert.assertNotNull(providerRef); - ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); - Assert.assertNotNull(provider); - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - Assert.assertNotNull(consumerRef); - ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); - Assert.assertNotNull(consumer); - - // Provider sends announcement - _logger.debug("Provider sends announcement [{}]", "heartbeat"); - provider.announce(QNAME); - // Consumer invokes RPC - _logger.debug("Invoking RPC [{}]", QNAME); - CompositeNode input = consumer.getValidCompositeNodeWithTwoCompositeChildren(); - for (int i = 0; i < 3; i++) { - RpcResult result = consumer.invokeRpc(QNAME, input); - Assert.assertNotNull(result); - _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); - Assert.assertTrue(result.isSuccessful()); - Assert.assertNotNull(result.getResult()); - Assert.assertEquals(0, result.getErrors().size()); - Assert.assertEquals(input.getChildren().size()+1, result.getResult().getChildren().size()); - } - } - - @Test - public void testInvokeRpcWithNullInput() throws Exception{ - //Thread.sleep(1500); - - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - Assert.assertNotNull(providerRef); - ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); - Assert.assertNotNull(provider); - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - Assert.assertNotNull(consumerRef); - ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); - Assert.assertNotNull(consumer); - - // Provider sends announcement - _logger.debug("Provider sends announcement [{}]", QNAME.getLocalName()); - provider.announce(QNAME); - // Consumer invokes RPC - _logger.debug("Invoking RPC [{}]", QNAME); - for (int i = 0; i < 3; i++) { - RpcResult result = consumer.invokeRpc(QNAME, null); - Assert.assertNotNull(result); - _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); - Assert.assertFalse(result.isSuccessful()); - Assert.assertNull(result.getResult()); - Assert.assertEquals(1, result.getErrors().size()); - Assert.assertEquals(RpcError.ErrorSeverity.WARNING, ((RpcError)result.getErrors().toArray()[0]).getSeverity()); - } - } - - @Test - public void testInvokeRpcWithInvalidSimpleNode() throws Exception{ - //Thread.sleep(1500); - - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - Assert.assertNotNull(providerRef); - ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); - Assert.assertNotNull(provider); - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - Assert.assertNotNull(consumerRef); - ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); - Assert.assertNotNull(consumer); - - // Provider sends announcement - _logger.debug("Provider sends announcement [{}]", QNAME.getLocalName()); - provider.announce(QNAME); - // Consumer invokes RPC - _logger.debug("Invoking RPC [{}]", QNAME); - CompositeNode input = consumer.getInvalidCompositeNodeSimpleChild(); - for (int i = 0; i < 3; i++) { - RpcResult result = consumer.invokeRpc(QNAME, input); - Assert.assertNotNull(result); - _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); - Assert.assertFalse(result.isSuccessful()); - Assert.assertNull(result.getResult()); - Assert.assertEquals(1, result.getErrors().size()); - Assert.assertEquals(RpcError.ErrorSeverity.ERROR, ((RpcError)result.getErrors().toArray()[0]).getSeverity()); - } - } - - @Test - public void testInvokeRpcWithInvalidCompositeNode() throws Exception{ - //Thread.sleep(1500); - - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - Assert.assertNotNull(providerRef); - ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); - Assert.assertNotNull(provider); - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - Assert.assertNotNull(consumerRef); - ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); - Assert.assertNotNull(consumer); - - // Provider sends announcement - _logger.debug("Provider sends announcement [{}]", QNAME.getLocalName()); - provider.announce(QNAME); - // Consumer invokes RPC - _logger.debug("Invoking RPC [{}]", QNAME); - CompositeNode input = consumer.getInvalidCompositeNodeCompositeChild(); - for (int i = 0; i < 3; i++) { - RpcResult result = consumer.invokeRpc(QNAME, input); - Assert.assertNotNull(result); - _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); - Assert.assertFalse(result.isSuccessful()); - Assert.assertNull(result.getResult()); - Assert.assertEquals(1, result.getErrors().size()); - Assert.assertEquals(RpcError.ErrorSeverity.ERROR, ((RpcError)result.getErrors().toArray()[0]).getSeverity()); - } - } - - //@Test - // This method is UNTESTED -- need to get around the bundling issues before I know if this even work -// public void testInvokeRpcWithValidCompositeNode() throws Exception{ -// Thread.sleep(10000); -// //Send announcement -// ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); -// Assert.assertNotNull(providerRef); -// -// ExampleProvider provider = (ExampleProvider)ctx.getService(providerRef); -// Assert.assertNotNull(provider); -// -// ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); -// Assert.assertNotNull(consumerRef); -// -// ExampleConsumer consumer = (ExampleConsumer)ctx.getService(consumerRef); -// Assert.assertNotNull(consumer); -// -// _logger.debug("Provider sends announcement [{}]", "heartbeat"); -// provider.announce(QNAME); -// ServiceReference routerRef = ctx.getServiceReference(Client.class); -// Client router = (Client) ctx.getService(routerRef); -// _logger.debug("Found router[{}]", router); -// _logger.debug("Invoking RPC [{}]", QNAME); -// for (int i = 0; i < 3; i++) { -// RpcResult result = router.getInstance().invokeRpc(QNAME, consumer.getValidCompositeNodeWithOneSimpleChild()); -// _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(), result.getResult(), result.getErrors()); -// Assert.assertNotNull(result); -// } -// } - - private Message send(Message msg) throws IOException { - ZMQ.Socket reqSocket = zmqCtx.socket(ZMQ.REQ); - reqSocket.connect("tcp://localhost:5555"); - reqSocket.send(Message.serialize(msg)); - Message response = parseMessage(reqSocket); - - return response; - } - - /** - * @param socket - * @return - */ - private Message parseMessage(ZMQ.Socket socket) { - - Message msg = null; - try { - byte[] bytes = socket.recv(); - _logger.debug("Received bytes:[{}]", bytes.length); - msg = (Message) Message.deserialize(bytes); - } catch (Throwable t) { - t.printStackTrace(); - } - return msg; - } - - - private void printState(){ - Bundle[] b = ctx.getBundles(); - _logger.debug("\n\nNumber of bundles [{}]\n\n]", b.length); - for (int i=0;i - - - - - urn:opendaylight:params:xml:ns:yang:controller:config?module=config&revision=2013-04-05 - - - urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl?module=opendaylight-sal-binding-broker-impl&revision=2013-10-28 - - - urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 - - - urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:impl?module=opendaylight-sal-dom-broker-impl&revision=2013-10-28 - - urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom?module=opendaylight-md-sal-dom&revision=2013-10-28 - - urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote:rpc?module=odl-sal-dom-rpc-remote-cfg&revision=2013-10-28 - - - - - - - - - prefix:schema-service-singleton - - yang-schema-service - - - - prefix:hash-map-data-store - - hash-map-data-store - - - - prefix:dom-broker-impl - - dom-broker - - - dom:dom-data-store - - ref_hash-map-data-store - - - - - prefix:binding-broker-impl - - binding-broker-impl - - - binding:binding-notification-service - - ref_binding-notification-broker - - - - binding:binding-data-broker - - ref_binding-data-broker - - - - - prefix:runtime-generated-mapping - - runtime-mapping-singleton - - - - prefix:binding-notification-broker - - binding-notification-broker - - - - prefix:binding-data-broker - - binding-data-broker - - - dom:dom-broker-osgi-registry - - ref_dom-broker - - - - binding:binding-dom-mapping-service - - ref_runtime-mapping-singleton - - - - - prefix:remote-zeromq-rpc-server - - remoter - 5666 - - - prefix:dom-broker-osgi-registry - - ref_dom-broker - - - - - - - - dom:schema-service - - - ref_yang-schema-service - - /config/modules/module[name='schema-service-singleton']/instance[name='yang-schema-service'] - - - - - - binding:binding-notification-service - - - ref_binding-notification-broker - - /config/modules/module[name='binding-notification-broker']/instance[name='binding-notification-broker'] - - - - - - dom:dom-data-store - - - ref_hash-map-data-store - - /config/modules/module[name='hash-map-data-store']/instance[name='hash-map-data-store'] - - - - - - binding:binding-broker-osgi-registry - - - ref_binding-broker-impl - - /config/modules/module[name='binding-broker-impl']/instance[name='binding-broker-impl'] - - - - - - binding-impl:binding-dom-mapping-service - - - ref_runtime-mapping-singleton - - /config/modules/module[name='runtime-generated-mapping']/instance[name='runtime-mapping-singleton'] - - - - - - dom:dom-broker-osgi-registry - - - ref_dom-broker - /config/modules/module[name='dom-broker-impl']/instance[name='dom-broker'] - - - - - - binding:binding-data-broker - - - ref_binding-data-broker - - /config/modules/module[name='binding-data-broker']/instance[name='binding-data-broker'] - - - - - - - - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/resources/logback.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/resources/logback.xml deleted file mode 100644 index 1d17796373..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-it/src/test/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/pom.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/pom.xml deleted file mode 100644 index b681db27fb..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/pom.xml +++ /dev/null @@ -1,101 +0,0 @@ - - - 4.0.0 - - sal-remoterpc-connector-test-parent - org.opendaylight.controller.tests - 1.1-SNAPSHOT - - - sal-remoterpc-connector-test-nb - bundle - - - - - org.apache.felix - maven-bundle-plugin - ${bundle.plugin.version} - true - - - - - - com.sun.jersey.spi.container.servlet, - !org.codehaus.jackson.annotate, - javax.ws.rs, - javax.ws.rs.core, - javax.xml.bind, - javax.xml.bind.annotation, - org.slf4j, - org.apache.catalina.filters, - !org.codehaus.jackson.jaxrs, - org.opendaylight.controller.sample.zeromq.provider, - org.opendaylight.controller.sample.zeromq.consumer, - org.opendaylight.controller.sal.utils, - org.opendaylight.yangtools.yang.common, - org.opendaylight.controller.sal.connector.api, - org.opendaylight.controller.sal.connector.remoterpc.api;version="[0.4,1)", - org.opendaylight.controller.sal.connector.remoterpc.impl;version="[0.4,1)", - org.opendaylight.controller.sal.connector.remoterpc.dto, - org.opendaylight.controller.sal.connector.remoterpc.util, - org.osgi.framework, - com.google.common.base, - org.opendaylight.yangtools.yang.data.api, - !org.codehaus.enunciate.jaxrs - - - /controller/nb/v2/zmqnb - ,${classes;ANNOTATION;javax.ws.rs.Path} - - ${project.basedir}/src/main/resources/META-INF - - - - - - - org.opendaylight.controller - containermanager - - - org.opendaylight.controller - commons.northbound - - - org.opendaylight.controller - sal - - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-provider - - - org.opendaylight.controller.tests - sal-remoterpc-connector-test-consumer - - - org.opendaylight.controller - sal-remoterpc-connector - - - org.osgi - org.osgi.core - - - junit - junit - - - org.opendaylight.controller - remoterpc-routingtable.implementation - - - com.google.guava - guava - - - - diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqrouter/rest/Router.java b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqrouter/rest/Router.java deleted file mode 100644 index e97be52f3d..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqrouter/rest/Router.java +++ /dev/null @@ -1,273 +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.tests.zmqrouter.rest; - -import org.opendaylight.controller.sal.connector.api.RpcRouter; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTable; -import org.opendaylight.controller.sal.connector.remoterpc.api.RoutingTableException; -import org.opendaylight.controller.sal.connector.remoterpc.api.SystemException; -import org.opendaylight.controller.sal.connector.remoterpc.impl.RoutingTableImpl; -import org.opendaylight.controller.sal.connector.remoterpc.util.XmlUtils; -import org.opendaylight.controller.sample.zeromq.consumer.ExampleConsumer; -import org.opendaylight.controller.sample.zeromq.provider.ExampleProvider; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import java.io.Serializable; -import java.net.URI; -import java.util.Set; - -@Path("router") -public class Router { - private Logger _logger = LoggerFactory.getLogger(Router.class); - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace, "heartbeat"); - - - @GET - @Path("/hello") - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "Hello"; - } - - @GET - @Path("/announce") - @Produces(MediaType.TEXT_PLAIN) - public String announce() { - _logger.info("Announce request received"); - - BundleContext ctx = getBundleContext(); - ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class); - if (providerRef == null) { - _logger.debug("Could not get provider reference"); - return "Could not get provider reference"; - } - - ExampleProvider provider = (ExampleProvider) ctx.getService(providerRef); - if (provider == null) { - _logger.info("Could not get provider service"); - return "Could not get provider service"; - } - - provider.announce(QNAME); - return "Announcement sent "; - - } - - @GET - @Path("/rpc") - @Produces(MediaType.TEXT_PLAIN) - public String invokeRpc() throws Exception { - _logger.info("Invoking RPC"); - - ExampleConsumer consumer = getConsumer(); - RpcResult result = consumer.invokeRpc(QNAME, consumer.getValidCompositeNodeWithOneSimpleChild()); - _logger.info("Result [{}]", result.isSuccessful()); - - return stringify(result); - } - - @GET - @Path("/rpc-success") - @Produces(MediaType.TEXT_PLAIN) - public String invokeRpcSuccess() throws Exception { - ExampleConsumer consumer = getConsumer(); - RpcResult result = consumer.invokeRpc(QNAME, consumer.getValidCompositeNodeWithFourSimpleChildren()); //TODO: Change this - _logger.info("Result [{}]", result.isSuccessful()); - - return stringify(result); - } - - @GET - @Path("/rpc-failure") - @Produces(MediaType.TEXT_PLAIN) - public String invokeRpcFailure() throws Exception { - ExampleConsumer consumer = getConsumer(); - //RpcResult result = consumer.invokeRpc(QNAME, consumer.getInvalidCompositeNodeCompositeChild()); //TODO: Change this - RpcResult result = consumer.invokeRpc(QNAME, null); //TODO: Change this - _logger.info("Result [{}]", result.isSuccessful()); - - return stringify(result); - } - - @GET - @Path("/routingtable") - @Produces(MediaType.TEXT_PLAIN) - public String invokeRoutingTable() { - _logger.info("Invoking adding an entry in routing table"); - - BundleContext ctx = getBundleContext(); - ServiceReference routingTableServiceReference = ctx.getServiceReference(RoutingTable.class); - if (routingTableServiceReference == null) { - _logger.debug("Could not get routing table impl reference"); - return "Could not get routingtable referen "; - } - RoutingTableImpl routingTable = (RoutingTableImpl) ctx.getService(routingTableServiceReference); - if (routingTable == null) { - _logger.info("Could not get routing table service"); - return "Could not get routing table service"; - } - - - RoutingIdentifierImpl rii = new RoutingIdentifierImpl(); - try { - routingTable.addGlobalRoute(rii.toString(), "172.27.12.1:5000"); - } catch (RoutingTableException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - - } catch (SystemException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - } - - String result = routingTable.dumpRoutingTableCache(); - - - - - _logger.info("Result [{}] routes added for route" + rii + result); - - return result; - } - - @GET - @Path("/routingtabledelete") - @Produces(MediaType.TEXT_PLAIN) - public String invokeDeleteRoutingTable() { - _logger.info("Invoking adding an entry in routing table"); - - BundleContext ctx = getBundleContext(); - ServiceReference routingTableServiceReference = ctx.getServiceReference(RoutingTable.class); - if (routingTableServiceReference == null) { - _logger.debug("Could not get routing table impl reference"); - return "Could not get routingtable referen "; - } - RoutingTable routingTable = (RoutingTableImpl) ctx.getService(routingTableServiceReference); - if (routingTable == null) { - _logger.info("Could not get routing table service"); - return "Could not get routing table service"; - } - - - RoutingIdentifierImpl rii = new RoutingIdentifierImpl(); - try { - routingTable.removeGlobalRoute(rii.toString()); - } catch (RoutingTableException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - - } catch (SystemException e) { - _logger.error("error in adding routing identifier" + e.getMessage()); - } - - Set routes = routingTable.getRoutes(rii.toString()); - - StringBuilder stringBuilder = new StringBuilder(); - if (routes != null) { - for (String route : routes) { - stringBuilder.append(route); - } - } else { - stringBuilder.append(" successfully"); - } - - _logger.info("Result [{}] routes removed for route" + rii + stringBuilder.toString()); - - return stringBuilder.toString(); - } - - private String stringify(RpcResult result) { - CompositeNode node = result.getResult(); - StringBuilder builder = new StringBuilder("result:").append(XmlUtils.compositeNodeToXml(node)).append("\n") - .append("error:").append(result.getErrors()).append("\n"); - - return builder.toString(); - } - - private BundleContext getBundleContext() { - ClassLoader tlcl = Thread.currentThread().getContextClassLoader(); - Bundle bundle = null; - - if (tlcl instanceof BundleReference) { - bundle = ((BundleReference) tlcl).getBundle(); - } else { - _logger.info("Unable to determine the bundle context based on " + - "thread context classloader."); - bundle = FrameworkUtil.getBundle(this.getClass()); - } - return (bundle == null ? null : bundle.getBundleContext()); - } - - private ExampleConsumer getConsumer() { - BundleContext ctx = getBundleContext(); - ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class); - if (consumerRef == null) { - _logger.debug("Could not get consumer reference"); - throw new NullPointerException("Could not get consumer reference"); - } - ExampleConsumer consumer = (ExampleConsumer) ctx.getService(consumerRef); - if (consumer == null) { - _logger.info("Could not get consumer service"); - throw new NullPointerException("Could not get consumer service"); - } - return consumer; - } - - class RoutingIdentifierImpl implements RpcRouter.RouteIdentifier, Serializable { - - private final URI namespace = URI.create("http://cisco.com/example"); - private final QName QNAME = new QName(namespace, "global"); - private final QName instance = new QName(URI.create("127.0.0.1"), "local"); - - @Override - public QName getContext() { - return QNAME; - } - - @Override - public QName getType() { - return QNAME; - } - - @Override - public org.opendaylight.yangtools.yang.data.api.InstanceIdentifier getRoute() { - return InstanceIdentifier.of(instance); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - RoutingIdentifierImpl that = (RoutingIdentifierImpl) o; - - if (!QNAME.equals(that.QNAME)) return false; - if (!instance.equals(that.instance)) return false; - if (!namespace.equals(that.namespace)) return false; - - return true; - } - - @Override - public int hashCode() { - int result = namespace.hashCode(); - result = 31 * result + QNAME.hashCode(); - result = 31 * result + instance.hashCode(); - return result; - } - } -} diff --git a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml deleted file mode 100644 index 5bd21398fb..0000000000 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - JAXRSZmq - com.sun.jersey.spi.container.servlet.ServletContainer - - javax.ws.rs.Application - org.opendaylight.controller.northbound.commons.NorthboundApplication - - 1 - - - - JAXRSZmq - /* - - - - - - - NB api - /* - POST - GET - PUT - PATCH - DELETE - HEAD - - - System-Admin - Network-Admin - Network-Operator - Container-User - - - - - System-Admin - - - Network-Admin - - - Network-Operator - - - Container-User - - - - BASIC - opendaylight - - -- 2.36.6