From: Basheeruddin Ahmed Date: Mon, 16 Dec 2013 23:58:38 +0000 (-0800) Subject: Changed zeromq-routingtable module to remoterpc-routingtable based on codereview... X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~177^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=55702e8f81f83de95367774cd2fa4f4f1b452469 Changed zeromq-routingtable module to remoterpc-routingtable based on codereview comments Change-Id: Idbdeca125c81c382a4ec0eec479c614b5ecf891a Signed-off-by: Basheeruddin Ahmed --- diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index 35e160e827..b0f7ad89a4 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -464,7 +464,7 @@ org.opendaylight.controller - zeromq-routingtable.implementation + remoterpc-routingtable.implementation 0.4.1-SNAPSHOT diff --git a/opendaylight/distribution/opendaylight/src/main/resources/configuration/logback.xml b/opendaylight/distribution/opendaylight/src/main/resources/configuration/logback.xml index 2815422274..84d1c913c4 100644 --- a/opendaylight/distribution/opendaylight/src/main/resources/configuration/logback.xml +++ b/opendaylight/distribution/opendaylight/src/main/resources/configuration/logback.xml @@ -61,7 +61,7 @@ - + diff --git a/opendaylight/md-sal/pom.xml b/opendaylight/md-sal/pom.xml index 4f2b255afd..0d6523bc0b 100644 --- a/opendaylight/md-sal/pom.xml +++ b/opendaylight/md-sal/pom.xml @@ -43,7 +43,7 @@ sal-rest-connector sal-netconf-connector - zeromq-routingtable/implementation + remoterpc-routingtable/implementation sal-remoterpc-connector/implementation clustered-data-store/implementation diff --git a/opendaylight/md-sal/zeromq-routingtable/implementation/pom.xml b/opendaylight/md-sal/remoterpc-routingtable/implementation/pom.xml similarity index 98% rename from opendaylight/md-sal/zeromq-routingtable/implementation/pom.xml rename to opendaylight/md-sal/remoterpc-routingtable/implementation/pom.xml index 2926786849..a788baf4c0 100644 --- a/opendaylight/md-sal/zeromq-routingtable/implementation/pom.xml +++ b/opendaylight/md-sal/remoterpc-routingtable/implementation/pom.xml @@ -15,7 +15,7 @@ HEAD - zeromq-routingtable.implementation + remoterpc-routingtable.implementation 0.4.1-SNAPSHOT bundle diff --git a/opendaylight/md-sal/zeromq-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 similarity index 100% rename from opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RouteChangeListener.java rename to opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RouteChangeListener.java diff --git a/opendaylight/md-sal/zeromq-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 similarity index 100% rename from opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTable.java rename to opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTable.java diff --git a/opendaylight/md-sal/zeromq-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 similarity index 100% rename from opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTableException.java rename to opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/RoutingTableException.java diff --git a/opendaylight/md-sal/zeromq-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 similarity index 100% rename from opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/SystemException.java rename to opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/api/SystemException.java diff --git a/opendaylight/md-sal/zeromq-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 similarity index 100% rename from opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/Activator.java rename to opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/Activator.java diff --git a/opendaylight/md-sal/zeromq-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 similarity index 95% rename from opendaylight/md-sal/zeromq-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java rename to opendaylight/md-sal/remoterpc-routingtable/implementation/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImpl.java index 4e1dfb0058..59292a174e 100644 --- a/opendaylight/md-sal/zeromq-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 @@ -30,6 +30,7 @@ import javax.transaction.RollbackException; import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentMap; @@ -254,6 +255,23 @@ public class RoutingTableImpl implements RoutingTable, ICacheUpdateA return this.routingTableCache; } + /** + * 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 dumpRoutingTableCache(){ + Set> cacheEntrySet = this.routingTableCache.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 diff --git a/opendaylight/md-sal/zeromq-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 similarity index 100% rename from opendaylight/md-sal/zeromq-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java rename to opendaylight/md-sal/remoterpc-routingtable/implementation/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/RoutingTableImplTest.java diff --git a/opendaylight/md-sal/zeromq-routingtable/integrationtest/pom.xml b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/pom.xml similarity index 98% rename from opendaylight/md-sal/zeromq-routingtable/integrationtest/pom.xml rename to opendaylight/md-sal/remoterpc-routingtable/integrationtest/pom.xml index 308d5a9316..bdc4569f31 100644 --- a/opendaylight/md-sal/zeromq-routingtable/integrationtest/pom.xml +++ b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/pom.xml @@ -14,13 +14,13 @@ HEAD - zeromq-routingtable.integrationtest + remoterpc-routingtable.integrationtest 0.4.1-SNAPSHOT org.opendaylight.controller - zeromq-routingtable.implementation + remoterpc-routingtable.implementation 0.4.1-SNAPSHOT diff --git a/opendaylight/md-sal/zeromq-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 similarity index 99% rename from opendaylight/md-sal/zeromq-routingtable/integrationtest/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/ZeroMQRoutingTableTestIT.java rename to opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/java/org/opendaylight/controller/sal/connector/remoterpc/impl/ZeroMQRoutingTableTestIT.java index a7929e82fc..0cf505c8cf 100644 --- a/opendaylight/md-sal/zeromq-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 @@ -120,7 +120,7 @@ public class .versionAsInProject(), mavenBundle(ODL, "sal-connector-api") .versionAsInProject(), - mavenBundle(ODL, "zeromq-routingtable.implementation") + mavenBundle(ODL, "remoterpc-routingtable.implementation") .versionAsInProject(), mavenBundle("org.jboss.spec.javax.transaction", diff --git a/opendaylight/md-sal/zeromq-routingtable/integrationtest/src/test/resources/logback.xml b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/resources/logback.xml similarity index 100% rename from opendaylight/md-sal/zeromq-routingtable/integrationtest/src/test/resources/logback.xml rename to opendaylight/md-sal/remoterpc-routingtable/integrationtest/src/test/resources/logback.xml diff --git a/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/pom.xml b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/pom.xml new file mode 100644 index 0000000000..35b2a4b250 --- /dev/null +++ b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + + sal-remoterpc-connector-test-parent + org.opendaylight.controller.tests + 1.0-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, + 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.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 + 0.5.1-SNAPSHOT + + + org.opendaylight.controller + commons.northbound + 0.4.1-SNAPSHOT + + + org.opendaylight.controller + sal + 0.5.1-SNAPSHOT + + + + org.osgi + org.osgi.core + 5.0.0 + + + junit + junit + + + org.opendaylight.controller + remoterpc-routingtable.implementation + 0.4.1-SNAPSHOT + + + 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 new file mode 100644 index 0000000000..6b7ee26f14 --- /dev/null +++ b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/RouteIdentifierImpl.java @@ -0,0 +1,69 @@ +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; + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..c426927d52 --- /dev/null +++ b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/java/org/opendaylight/controller/tests/zmqroutingtable/rest/Router.java @@ -0,0 +1,157 @@ +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 new file mode 100644 index 0000000000..2a0f3f3651 --- /dev/null +++ b/opendaylight/md-sal/remoterpc-routingtable/integrationtest/test-nb/src/main/resources/WEB-INF/web.xml @@ -0,0 +1,58 @@ + + + + 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 index b8e0938a5f..c973498e85 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml +++ b/opendaylight/md-sal/sal-remoterpc-connector/implementation/pom.xml @@ -37,7 +37,7 @@ org.opendaylight.controller - zeromq-routingtable.implementation + remoterpc-routingtable.implementation 0.4.1-SNAPSHOT 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 index dd7e36cfb4..dc2fdbf9a0 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/pom.xml +++ b/opendaylight/md-sal/sal-remoterpc-connector/integrationtest/test-nb/pom.xml @@ -97,7 +97,7 @@ org.opendaylight.controller - zeromq-routingtable.implementation + remoterpc-routingtable.implementation 0.4.1-SNAPSHOT