*/
package org.opendaylight.controller.config.manager.impl.dynamicmbean;
-import static java.lang.String.format;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.controller.config.api.annotations.Description;
+import org.opendaylight.controller.config.api.annotations.RequireInterface;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.config.manager.impl.util.InterfacesHelper;
+import org.opendaylight.controller.config.spi.Module;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import javax.management.ReflectionException;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.annotations.Description;
-import org.opendaylight.controller.config.api.annotations.RequireInterface;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-import org.opendaylight.controller.config.manager.impl.util.InterfacesHelper;
-import org.opendaylight.controller.config.spi.Module;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static java.lang.String.format;
/**
* Contains common code for readable/rw dynamic mbean wrappers. Routes all
} catch (InstanceNotFoundException e) {
new MBeanException(e);
}
+
if (obj instanceof ObjectName) {
AttributeHolder attributeHolder = attributeHolderMap
.get(attributeName);
}
return obj;
}
+
+
+ if(isDependencyListAttr(attributeName, obj)) {
+ obj = fixDependencyListAttribute(obj);
+ }
+
return obj;
+ }
+
+ private Object fixDependencyListAttribute(Object attribute) {
+ if(attribute.getClass().isArray() == false)
+ throw new IllegalArgumentException("Unexpected attribute type, should be an array, but was " + attribute.getClass());
+
+ for (int i = 0; i < Array.getLength(attribute); i++) {
+
+ Object on = Array.get(attribute, i);
+ if(on instanceof ObjectName == false)
+ throw new IllegalArgumentException("Unexpected attribute type, should be an ObjectName, but was " + on.getClass());
+ on = fixObjectName((ObjectName) on);
+
+ Array.set(attribute, i, on);
+ }
+
+ return attribute;
+ }
+
+ private boolean isDependencyListAttr(String attributeName, Object attribute) {
+ if (attributeHolderMap.containsKey(attributeName) == false)
+ return false;
+
+ AttributeHolder attributeHolder = attributeHolderMap.get(attributeName);
+ boolean isDepList = true;
+ isDepList &= attributeHolder.getRequireInterfaceOrNull() != null;
+ isDepList &= attribute instanceof ObjectName[];
+ return isDepList;
}
protected ObjectName fixObjectName(ObjectName on) {
*/
package org.opendaylight.controller.config.manager.impl.dynamicmbean;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import org.opendaylight.controller.config.api.annotations.Description;
+import org.opendaylight.controller.config.api.annotations.RequireInterface;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import javax.management.MBeanAttributeInfo;
import javax.management.ObjectName;
-
-import org.opendaylight.controller.config.api.annotations.Description;
-import org.opendaylight.controller.config.api.annotations.RequireInterface;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
@Immutable
class AttributeHolder {
private final RequireInterface requireInterfaceAnnotation;
private final String attributeType;
+ public static final Set<Class<?>> PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER = new HashSet<>();
+
+ static {
+ PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(ObjectName.class);
+ PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(ObjectName[].class);
+ PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.add(List.class);
+ }
+
public AttributeHolder(String name, Object object, String returnType,
boolean writable,
@Nullable RequireInterface requireInterfaceAnnotation,
static RequireInterface findRequireInterfaceAnnotation(final Method setter,
Set<Class<?>> inspectedInterfaces) {
- // only allow setX(ObjectName y) or setX(ObjectName[] y) to continue
- if (setter.getParameterTypes().length != 1
- || (setter.getParameterTypes()[0].equals(ObjectName.class) == false && setter
- .getParameterTypes()[0].equals(ObjectName[].class) == false)) {
+ // only allow setX(ObjectName y) or setX(ObjectName[] y) or setX(List<ObjectName> y) to continue
+
+ if (setter.getParameterTypes().length > 1)
+ return null;
+ if(PERMITTED_PARAMETER_TYPES_FOR_DEPENDENCY_SETTER.contains(setter.getParameterTypes()[0]) == false)
return null;
- }
List<RequireInterface> foundRequireInterfaces = AnnotationsHelper
.findMethodAnnotationInSuperClassesAndIfcs(setter, RequireInterface.class, inspectedInterfaces);
*/
package org.opendaylight.controller.config.manager.impl.dynamicmbean;
-import java.lang.reflect.Method;
+import org.opendaylight.controller.config.api.ModuleIdentifier;
+import org.opendaylight.controller.config.api.ValidationException;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.config.manager.impl.TransactionIdentifier;
+import org.opendaylight.controller.config.spi.Module;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.annotation.concurrent.ThreadSafe;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.ReflectionException;
-
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.api.ValidationException;
-import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
-import org.opendaylight.controller.config.manager.impl.TransactionIdentifier;
-import org.opendaylight.controller.config.spi.Module;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.lang.reflect.Method;
/**
* Wraps {@link org.opendaylight.controller.config.spi.Module} instance in a
try {
if (attribute.getValue() instanceof ObjectName) {
- AttributeHolder attributeHolder = attributeHolderMap
- .get(attribute.getName());
- if (attributeHolder.getRequireInterfaceOrNull() != null) {
- attribute = new Attribute(attribute.getName(),
- fixObjectName((ObjectName) attribute.getValue()));
- } else {
- attribute = new Attribute(attribute.getName(),
- attribute.getValue());
- }
+ attribute = fixDependencyAttribute(attribute);
+ } else if(attribute.getValue() instanceof ObjectName[]) {
+ attribute = fixDependencyListAttribute(attribute);
}
+
internalServer.setAttribute(objectNameInternal, attribute);
} catch (InstanceNotFoundException e) {
throw new MBeanException(e);
}
+ private Attribute fixDependencyListAttribute(Attribute attribute) {
+ AttributeHolder attributeHolder = attributeHolderMap
+ .get(attribute.getName());
+ if (attributeHolder.getRequireInterfaceOrNull() != null) {
+ attribute = new Attribute(attribute.getName(),
+ fixObjectNames((ObjectName[]) attribute.getValue()));
+ }
+ return attribute;
+ }
+
+ private Attribute fixDependencyAttribute(Attribute attribute) {
+ AttributeHolder attributeHolder = attributeHolderMap
+ .get(attribute.getName());
+ if (attributeHolder.getRequireInterfaceOrNull() != null) {
+ attribute = new Attribute(attribute.getName(),
+ fixObjectName((ObjectName) attribute.getValue()));
+ } else {
+ attribute = new Attribute(attribute.getName(),
+ attribute.getValue());
+ }
+ return attribute;
+ }
+
+ private ObjectName[] fixObjectNames(ObjectName[] dependencies) {
+ int i = 0;
+
+ for (ObjectName dependencyOn : dependencies) {
+ dependencies[i++] = fixObjectName(dependencyOn);
+ }
+
+ return dependencies;
+ }
+
@Override
public AttributeList setAttributes(AttributeList attributes) {
AttributeList result = new AttributeList();
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-inet-types</artifactId>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-inet-types</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>config-manager</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>config-manager</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-util</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
--- /dev/null
+package org.opendaylight.controller.config.yang.test.impl;
+
+import com.google.common.collect.Lists;
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.config.api.ValidationException;
+import org.opendaylight.controller.config.api.jmx.CommitStatus;
+import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.ObjectName;
+import java.util.ArrayList;
+import java.util.List;
+
+public class NetconfTestImplModuleTest extends AbstractConfigTest {
+
+ public static final String TESTING_DEP_PREFIX = "testing-dep";
+ private NetconfTestImplModuleFactory factory;
+ private final String instanceName = "n1";
+
+ @Before
+ public void setUp() {
+
+ factory = new NetconfTestImplModuleFactory();
+ super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory,
+ new DepTestImplModuleFactory()));
+ }
+
+ @Test
+ public void testDependencyList() throws InstanceAlreadyExistsException, ValidationException,
+ ConflictingVersionException {
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+
+ ObjectName on = createInstance(transaction, instanceName, 4);
+ transaction.validateConfig();
+ CommitStatus status = transaction.commit();
+
+ assertBeanCount(1, factory.getImplementationName());
+ assertBeanCount(4 + 1, DepTestImplModuleFactory.NAME);
+ assertStatus(status, 1 + 4 + 1, 0, 0);
+
+ transaction = configRegistryClient.createTransaction();
+
+ NetconfTestImplModuleMXBean proxy = transaction.newMXBeanProxy(ObjectNameUtil.withoutTransactionName(on),
+ NetconfTestImplModuleMXBean.class);
+ proxy.getComplexList();
+ List<ObjectName> testingDeps = proxy.getTestingDeps();
+ ObjectName testingDep = proxy.getTestingDep();
+
+ Assert.assertEquals(TESTING_DEP_PREFIX, ObjectNameUtil.getInstanceName(testingDep));
+ assertTestingDeps(testingDeps, 4);
+
+ transaction.abortConfig();
+ }
+
+ private void assertTestingDeps(List<ObjectName> testingDeps, int i) {
+ Assert.assertEquals(i, testingDeps.size());
+
+ int c = 1;
+ for (ObjectName testingDep : testingDeps) {
+ Assert.assertEquals(TESTING_DEP_PREFIX + Integer.toString(c++), ObjectNameUtil.getInstanceName(testingDep));
+ }
+ }
+
+
+ private ObjectName createInstance(ConfigTransactionJMXClient transaction, String instanceName, int depsCount)
+ throws InstanceAlreadyExistsException {
+ ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
+ NetconfTestImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, NetconfTestImplModuleMXBean.class);
+
+ ObjectName dep = transaction.createModule(DepTestImplModuleFactory.NAME, TESTING_DEP_PREFIX);
+ mxBean.setTestingDep(dep);
+
+ ArrayList<ObjectName> testingDeps = Lists.newArrayList();
+ for (int i = 0; i < depsCount; i++) {
+ dep = transaction.createModule(DepTestImplModuleFactory.NAME, TESTING_DEP_PREFIX + Integer.toString(i + 1));
+ testingDeps.add(dep);
+ }
+ mxBean.setTestingDeps(testingDeps);
+
+ return nameCreated;
+ }
+
+}
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>
- zeromq-routingtable.implementation
+ remoterpc-routingtable.implementation
</artifactId>
<version>0.4.1-SNAPSHOT</version>
</dependency>
<logger name="org.opendaylight.controller.sal.implementation" level="INFO"/>
<logger name="org.opendaylight.controller.sal.implementation.internal.Inventory" level="INFO"/>
<logger name="org.opendaylight.controller.sal.implementation.internal.Topology" level="INFO"/>
- <!-- zeromq router and zeromq routing table -->
+ <!-- remoterpc router and remoterpc routing table -->
<logger name="org.opendaylight.controller.sal.connector.remoterpc" level="INFO" />
<!-- Functional Modules -->
<logger name="org.opendaylight.controller.arphandler" level="INFO"/>
<module>sal-rest-connector</module>
<module>sal-netconf-connector</module>
- <module>zeromq-routingtable/implementation</module>
+ <module>remoterpc-routingtable/implementation</module>
<module>sal-remoterpc-connector/implementation</module>
<!-- Clustered Data Store -->
<module>clustered-data-store/implementation</module>
<tag>HEAD</tag>
</scm>
- <artifactId>zeromq-routingtable.implementation</artifactId>
+ <artifactId>remoterpc-routingtable.implementation</artifactId>
<version>0.4.1-SNAPSHOT</version>
<packaging>bundle</packaging>
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;
return this.routingTableCache;
}
+ /**
+ * This is used from integration test NP rest API to check out the result of the
+ * cache population
+ * <Note> For testing purpose only-- use it wisely</Note>
+ * @return
+ */
+ public String dumpRoutingTableCache(){
+ Set<Map.Entry<I, R>> cacheEntrySet = this.routingTableCache.entrySet();
+ StringBuilder sb = new StringBuilder();
+ for(Map.Entry<I,R> 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
<tag>HEAD</tag>
</scm>
- <artifactId>zeromq-routingtable.integrationtest</artifactId>
+ <artifactId>remoterpc-routingtable.integrationtest</artifactId>
<version>0.4.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>zeromq-routingtable.implementation</artifactId>
+ <artifactId>remoterpc-routingtable.implementation</artifactId>
<version>0.4.1-SNAPSHOT</version>
</dependency>
<dependency>
.versionAsInProject(),
mavenBundle(ODL, "sal-connector-api")
.versionAsInProject(),
- mavenBundle(ODL, "zeromq-routingtable.implementation")
+ mavenBundle(ODL, "remoterpc-routingtable.implementation")
.versionAsInProject(),
mavenBundle("org.jboss.spec.javax.transaction",
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>sal-remoterpc-connector-test-parent</artifactId>
+ <groupId>org.opendaylight.controller.tests</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>remoterpc-routingtable-nb-it</artifactId>
+ <packaging>bundle</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${bundle.plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.opendaylight.controller.tests.zmqroutingtable.rest
+ </Export-Package>
+ <Import-Package>
+ 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
+
+ </Import-Package>
+ <Web-ContextPath>/controller/nb/v2/zmqnbrt</Web-ContextPath>
+ <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
+ </instructions>
+ <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>containermanager</artifactId>
+ <version>0.5.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>commons.northbound</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal</artifactId>
+ <version>0.5.1-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>5.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>remoterpc-routingtable.implementation</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ </dependencies>
+
+ </project>
--- /dev/null
+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
--- /dev/null
+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());
+ }
+
+
+
+}
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>JAXRSZmqRT</servlet-name>
+ <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JAXRSZmqRT</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>NB api</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
+ <http-method>PUT</http-method>
+ <http-method>PATCH</http-method>
+ <http-method>DELETE</http-method>
+ <http-method>HEAD</http-method>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>System-Admin</role-name>
+ <role-name>Network-Admin</role-name>
+ <role-name>Network-Operator</role-name>
+ <role-name>Container-User</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <security-role>
+ <role-name>System-Admin</role-name>
+ </security-role>
+ <security-role>
+ <role-name>Network-Admin</role-name>
+ </security-role>
+ <security-role>
+ <role-name>Network-Operator</role-name>
+ </security-role>
+ <security-role>
+ <role-name>Container-User</role-name>
+ </security-role>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>opendaylight</realm-name>
+ </login-config>
+</web-app>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>zeromq-routingtable.implementation</artifactId>
+ <artifactId>remoterpc-routingtable.implementation</artifactId>
<!-- TODO: fix the version. Why is it not MD Sal project version?-->
<version>0.4.1-SNAPSHOT</version>
</dependency>
</dependency>
<dependency>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>zeromq-routingtable.implementation</artifactId>
+ <artifactId>remoterpc-routingtable.implementation</artifactId>
<version>0.4.1-SNAPSHOT</version>
</dependency>
<dependency>
import org.opendaylight.yangtools.yang.common.QName;
import java.net.URI;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Set;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
public class NetconfOperationServiceImplTest {
- private Date date = new Date(0);
+ private static final Date date1970_01_01;
+
+ static {
+ try {
+ date1970_01_01 = new SimpleDateFormat("yyyy-MM-dd").parse("1970-01-01");
+ } catch (ParseException e) {
+ throw new IllegalStateException(e);
+ }
+ }
@Test
public void testCheckConsistencyBetweenYangStoreAndConfig_ok() throws Exception {
mockYangStoreSnapshot());
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void testCheckConsistencyBetweenYangStoreAndConfig_yangStoreMore() throws Exception {
try {
NetconfOperationServiceImpl.checkConsistencyBetweenYangStoreAndConfig(mockJmxClient("qname1"),
mockYangStoreSnapshot("qname2", "qname1"));
+ fail("An exception of type " + IllegalArgumentException.class + " was expected");
} catch (IllegalStateException e) {
String message = e.getMessage();
Assert.assertThat(
message,
JUnitMatchers
- .containsString(" missing from config subsystem but present in yangstore: [(namespace?revision=1970-01-01)qname2]"));
+ .containsString("missing from config subsystem but present in yangstore: [(namespace?revision=1970-01-01)qname2]"));
Assert.assertThat(
message,
JUnitMatchers
.containsString("All modules present in config: [(namespace?revision=1970-01-01)qname1]"));
- throw e;
}
}
}
private QName getQName(String qname) {
- return new QName(URI.create("namespace"), date, qname);
+ return new QName(URI.create("namespace"), date1970_01_01, qname);
}
private LookupRegistry mockJmxClient(String... visibleQNames) {
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
- <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
+ <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>