BUG 2230: RSVP SPI provider 91/26191/7
authorClaudio D. Gasparini <cgaspari@cisco.com>
Sun, 30 Aug 2015 13:11:31 +0000 (15:11 +0200)
committerMilos Fabian <milfabia@cisco.com>
Fri, 18 Sep 2015 16:05:15 +0000 (16:05 +0000)
-Implementation of RSVP Extension Provider
-Implementation of RSVP Extension Provider Tests

Change-Id: I10008c7f0ab798670f8c63e2866ab3f841de0cfe
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
rsvp/spi/src/main/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModule.java [new file with mode: 0644]
rsvp/spi/src/main/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModuleFactory.java [new file with mode: 0644]
rsvp/spi/src/main/yang/odl-rsvp-parser-spi-cfg.yang [new file with mode: 0644]
rsvp/spi/src/test/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModuleTest.java [new file with mode: 0644]

diff --git a/rsvp/spi/src/main/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModule.java b/rsvp/spi/src/main/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModule.java
new file mode 100644 (file)
index 0000000..523e9cc
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015 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.rsvp.spi;
+
+import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderActivator;
+import org.opendaylight.protocol.rsvp.parser.spi.pojo.SimpleRSVPExtensionProviderContext;
+
+public class SimpleRSVPExtensionProviderContextModule extends org.opendaylight.controller.config.yang.rsvp.spi.AbstractSimpleRSVPExtensionProviderContextModule {
+    public SimpleRSVPExtensionProviderContextModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+        super(identifier, dependencyResolver);
+    }
+
+    public SimpleRSVPExtensionProviderContextModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.rsvp.spi.SimpleRSVPExtensionProviderContextModule oldModule, java.lang.AutoCloseable oldInstance) {
+        super(identifier, dependencyResolver, oldModule, oldInstance);
+    }
+
+    @Override
+    public void customValidation() {
+        // add custom validation form module attributes here.
+    }
+
+    @Override
+    public java.lang.AutoCloseable createInstance() {
+        final class SimpleRSVPExtensionProviderContextAutoCloseable extends SimpleRSVPExtensionProviderContext implements AutoCloseable {
+            @Override
+            public void close() {
+                for (final RSVPExtensionProviderActivator e : getRsvpExtensionDependency()) {
+                    e.stop();
+                }
+            }
+        }
+
+        final SimpleRSVPExtensionProviderContextAutoCloseable ret = new SimpleRSVPExtensionProviderContextAutoCloseable();
+        for (final RSVPExtensionProviderActivator e : getRsvpExtensionDependency()) {
+            e.start(ret);
+        }
+        return ret;
+    }
+
+}
diff --git a/rsvp/spi/src/main/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModuleFactory.java b/rsvp/spi/src/main/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModuleFactory.java
new file mode 100644 (file)
index 0000000..0fe85af
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2015 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.rsvp.spi;
+public class SimpleRSVPExtensionProviderContextModuleFactory extends org.opendaylight.controller.config.yang.rsvp.spi.AbstractSimpleRSVPExtensionProviderContextModuleFactory {
+
+}
diff --git a/rsvp/spi/src/main/yang/odl-rsvp-parser-spi-cfg.yang b/rsvp/spi/src/main/yang/odl-rsvp-parser-spi-cfg.yang
new file mode 100644 (file)
index 0000000..5957360
--- /dev/null
@@ -0,0 +1,75 @@
+// vi: set smarttab et sw=4 tabstop=4:
+module odl-rsvp-parser-spi-cfg {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:yang:controller:rsvp:spi";
+    prefix "rsvp-spi";
+
+    import config { prefix config; revision-date 2013-04-05; }
+
+    organization "Cisco Systems, Inc.";
+
+    contact "Claudio D. Gasparini <cgaspari@cisco.com>";
+
+    description
+        "This module contains the base YANG definitions for
+         RSPV listener implementation.
+
+        Copyright (c)2015 Cisco Systems, Inc. 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";
+
+   revision "2015-08-26" {
+        description
+            "Initial revision";
+    }
+
+    identity consumer-extensions {
+        description
+            "Service representing a RSVP parser extension registry. Extension
+            consumers have this service injected.";
+
+        base "config:service-type";
+        config:java-class "org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionConsumerContext";
+    }
+
+    identity rsvp-extensions {
+        description
+            "Service representing a RSVP parser extension registry. Extension
+            providers have this service injected for registration.";
+
+        base "consumer-extensions";
+        config:java-class "org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext";
+    }
+
+    identity rsvp-extension {
+        description
+            "Service representing a RSVP parser extension.";
+
+        base "config:service-type";
+        config:java-class "org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderActivator";
+    }
+
+    identity rsvp-extensions-impl {
+        base config:module-type;
+        config:provided-service rsvp-extensions;
+        config:java-name-prefix SimpleRSVPExtensionProviderContext;
+    }
+
+    augment "/config:modules/config:module/config:configuration" {
+        case rsvp-extensions-impl {
+            when "/config:modules/config:module/config:type = 'rsvp-extensions-impl'";
+
+            list rsvp-extension {
+                uses config:service-ref {
+                    refine type {
+                        mandatory true;
+                        config:required-identity rsvp-extension;
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/rsvp/spi/src/test/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModuleTest.java b/rsvp/spi/src/test/java/org/opendaylight/controller/config/yang/rsvp/spi/SimpleRSVPExtensionProviderContextModuleTest.java
new file mode 100644 (file)
index 0000000..995dd7d
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2015 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.rsvp.spi;
+
+import java.util.List;
+import javax.management.ObjectName;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.config.api.jmx.CommitStatus;
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
+
+public class SimpleRSVPExtensionProviderContextModuleTest extends AbstractConfigTest {
+    private static final String FACTORY_NAME = SimpleRSVPExtensionProviderContextModuleFactory.NAME;
+    private static final String INSTANCE_NAME = "bgp-rsvp-extensions-impl";
+
+    public static ObjectName SimpleRSVPExtensionProviderContextModuleInstance(final ConfigTransactionJMXClient transaction, final List<ObjectName> extensions) throws Exception {
+        final ObjectName objectName = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+        final SimpleRSVPExtensionProviderContextModuleMXBean mxBean = transaction.newMXBeanProxy(objectName, SimpleRSVPExtensionProviderContextModuleMXBean.class);
+        mxBean.setRsvpExtension(extensions);
+        return objectName;
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, new SimpleRSVPExtensionProviderContextModuleFactory()));
+    }
+
+    @Test
+    public void testCreateBean() throws Exception {
+        final CommitStatus status = createInstance();
+        assertBeanCount(1, FACTORY_NAME);
+        assertStatus(status, 1, 0, 0);
+    }
+
+    @Test
+    public void testReusingOldInstance() throws Exception {
+        createInstance();
+        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+        assertBeanCount(1, FACTORY_NAME);
+        final CommitStatus status = transaction.commit();
+        assertBeanCount(1, FACTORY_NAME);
+        assertStatus(status, 0, 0, 1);
+    }
+
+    private CommitStatus createInstance() throws Exception {
+        final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
+        transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
+        return transaction.commit();
+    }
+}
\ No newline at end of file