added feature topology manager shell 42/7542/5
authorJonathan Fok kan <jfokkan@inocybe.com>
Thu, 31 Jul 2014 21:05:01 +0000 (17:05 -0400)
committerJonathan Fok kan <jfokkan@inocybe.com>
Fri, 1 Aug 2014 17:50:21 +0000 (13:50 -0400)
The shell is installed when odl-nsf-managers is installed

Change-Id: I460c71231ed54342983271304356737a1cb6c377
Signed-off-by: Jonathan Fok Kan <jfokkan@inocybe.com>
12 files changed:
features/nsf/src/main/resources/features.xml
opendaylight/commons/opendaylight/pom.xml
opendaylight/topologymanager/implementation/pom.xml
opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/ITopologyManagerShell.java [new file with mode: 0644]
opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/internal/Activator.java
opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java
opendaylight/topologymanager/shell/pom.xml [new file with mode: 0644]
opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/AddUserLink.java [new file with mode: 0644]
opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/DeleteUserLink.java [new file with mode: 0644]
opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/PrintNodeEdges.java [new file with mode: 0644]
opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/PrintUserLink.java [new file with mode: 0644]
opendaylight/topologymanager/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml [new file with mode: 0644]

index fb61f33fb32a58b82ff261a5c84a16cef3b274c4..37c69cf75365371be473d7231baa61ddc5176460 100644 (file)
@@ -34,6 +34,7 @@
         <bundle>mvn:org.opendaylight.controller/forwardingrulesmanager.implementation/${forwardingrulesmanager.implementation.version}</bundle>
 
         <bundle>mvn:org.opendaylight.controller/topologymanager/${topologymanager.version}</bundle>
+        <bundle>mvn:org.opendaylight.controller/topologymanager.shell/${topologymanager.shell.version}</bundle>
 
         <bundle>mvn:org.opendaylight.controller/networkconfig.neutron/${networkconfig.neutron.version}</bundle>
         <bundle>mvn:org.opendaylight.controller/networkconfig.neutron.implementation/${networkconfig.neutron.implementation.version}</bundle>
@@ -70,4 +71,4 @@
         <bundle>mvn:org.opendaylight.controller/topology.northbound/${topology.northbound.version}</bundle>
         <bundle>mvn:org.opendaylight.controller/usermanager.northbound/${usermanager.northbound.version}</bundle>
     </feature>
-</features>
\ No newline at end of file
+</features>
index be88e4a5059c335147a2ebacdb4f09851bbbc0e9..235b95b742d6f4713cfe13674b0dcb9c706a8503 100644 (file)
     <topology.northbound.version>0.4.2-SNAPSHOT</topology.northbound.version>
     <topology.web.version>0.4.2-SNAPSHOT</topology.web.version>
     <topologymanager.version>0.4.2-SNAPSHOT</topologymanager.version>
+    <topologymanager.shell.version>1.0.0-SNAPSHOT</topologymanager.shell.version>
     <troubleshoot.web.version>0.4.2-SNAPSHOT</troubleshoot.web.version>
     <typesafe.config.version>1.2.0</typesafe.config.version>
     <uncommons.maths.version>1.2.2</uncommons.maths.version>
index 196982b3610ee6f33f2afc8a4685a905780cdb26..746135891ea5acf3b976ae64421dda9a393c4f07 100644 (file)
@@ -44,6 +44,7 @@
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
+        <version>${bundle.plugin.version}</version>
         <extensions>true</extensions>
         <configuration>
           <instructions>
diff --git a/opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/ITopologyManagerShell.java b/opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/ITopologyManagerShell.java
new file mode 100644 (file)
index 0000000..22bd9c0
--- /dev/null
@@ -0,0 +1,17 @@
+/**
+* Copyright (c) 2014 Inocybe Technologies, 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.topologymanager;
+
+import java.util.List;
+
+public interface ITopologyManagerShell {
+    public List<String> printUserLink();
+    public List<String> addUserLink(String name, String ncStr1, String ncStr2);
+    public List<String> deleteUserLinkShell(String name);
+    public List<String> printNodeEdges();
+}
index 4ccbb0197d4bf1cdc1e6d2e87ed6e1a547ea0425..80d7083ec0dee0059a8b7c0c33720522b65fb4bc 100644 (file)
@@ -26,6 +26,7 @@ import org.opendaylight.controller.switchmanager.ISwitchManager;
 import org.opendaylight.controller.topologymanager.ITopologyManager;
 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
 import org.opendaylight.controller.topologymanager.ITopologyManagerClusterWideAware;
+import org.opendaylight.controller.topologymanager.ITopologyManagerShell;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -73,6 +74,7 @@ public class Activator extends ComponentActivatorAbstractBase {
 
             c.setInterface(new String[] { IListenTopoUpdates.class.getName(),
                     ITopologyManager.class.getName(),
+                    ITopologyManagerShell.class.getName(),
                     IConfigurationContainerAware.class.getName(),
                     ICacheUpdateAware.class.getName() }, props);
 
index ff1c026a344d74efa5aa1f1b57e05e60775cd1a4..b0e87c48f3e0812fd2e33c7789e5e916479f6465 100644 (file)
@@ -57,6 +57,7 @@ import org.opendaylight.controller.switchmanager.ISwitchManager;
 import org.opendaylight.controller.topologymanager.ITopologyManager;
 import org.opendaylight.controller.topologymanager.ITopologyManagerAware;
 import org.opendaylight.controller.topologymanager.ITopologyManagerClusterWideAware;
+import org.opendaylight.controller.topologymanager.ITopologyManagerShell;
 import org.opendaylight.controller.topologymanager.TopologyUserLinkConfig;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
@@ -71,6 +72,7 @@ import org.slf4j.LoggerFactory;
 public class TopologyManagerImpl implements
         ICacheUpdateAware<Object, Object>,
         ITopologyManager,
+        ITopologyManagerShell,
         IConfigurationContainerAware,
         IListenTopoUpdates,
         IObjectReader,
@@ -1010,4 +1012,82 @@ public class TopologyManagerImpl implements
             }
         }
     }
+
+    public List<String> printUserLink() {
+        List<String> result = new ArrayList<String>();
+        for (String name : this.userLinksDB.keySet()) {
+            TopologyUserLinkConfig linkConfig = userLinksDB.get(name);
+            result.add("Name : " + name);
+            result.add(linkConfig.toString());
+            result.add("Edge " + getLinkTuple(linkConfig));
+            result.add("Reverse Edge " + getReverseLinkTuple(linkConfig));
+        }
+        return result;
+    }
+
+    public List<String> addUserLink(String name, String ncStr1, String ncStr2) {
+        List<String> result = new ArrayList<String>();
+        if ((name == null)) {
+            result.add("Please enter a valid Name");
+            return result;
+        }
+
+        if (ncStr1 == null) {
+            result.add("Please enter two node connector strings");
+            return result;
+        }
+        if (ncStr2 == null) {
+            result.add("Please enter second node connector string");
+            return result;
+        }
+
+        NodeConnector nc1 = NodeConnector.fromString(ncStr1);
+        if (nc1 == null) {
+            result.add("Invalid input node connector 1 string: " + ncStr1);
+            return result;
+        }
+        NodeConnector nc2 = NodeConnector.fromString(ncStr2);
+        if (nc2 == null) {
+            result.add("Invalid input node connector 2 string: " + ncStr2);
+            return result;
+        }
+
+        TopologyUserLinkConfig config = new TopologyUserLinkConfig(name, ncStr1, ncStr2);
+        result.add(this.addUserLink(config).toString());
+        return result;
+    }
+
+    public List<String> deleteUserLinkShell(String name) {
+        List<String> result = new ArrayList<String>();
+        if ((name == null)) {
+            result.add("Please enter a valid Name");
+            return result;
+        }
+        this.deleteUserLink(name);
+        return result;
+    }
+
+    public List<String> printNodeEdges() {
+        List<String> result = new ArrayList<String>();
+        Map<Node, Set<Edge>> nodeEdges = getNodeEdges();
+        if (nodeEdges == null) {
+            return result;
+        }
+        Set<Node> nodeSet = nodeEdges.keySet();
+        if (nodeSet == null) {
+            return result;
+        }
+        result.add("        Node                                         Edge");
+        for (Node node : nodeSet) {
+            Set<Edge> edgeSet = nodeEdges.get(node);
+            if (edgeSet == null) {
+                continue;
+            }
+            for (Edge edge : edgeSet) {
+                result.add(node + "             " + edge);
+            }
+        }
+        return result;
+    }
+
 }
diff --git a/opendaylight/topologymanager/shell/pom.xml b/opendaylight/topologymanager/shell/pom.xml
new file mode 100644 (file)
index 0000000..078b55c
--- /dev/null
@@ -0,0 +1,52 @@
+<?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>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>commons.opendaylight</artifactId>
+    <version>1.4.2-SNAPSHOT</version>
+    <relativePath>../../commons/opendaylight</relativePath>
+  </parent>
+  <artifactId>topologymanager.shell</artifactId>
+  <version>${topologymanager.shell.version}</version>
+  <packaging>bundle</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.karaf.shell</groupId>
+      <artifactId>org.apache.karaf.shell.console</artifactId>
+      <version>${karaf.shell.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>topologymanager</artifactId>
+      <version>${topologymanager.version}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>${bundle.plugin.version}</version>
+        <configuration>
+          <instructions>
+            <Import-Package>org.apache.felix.service.command,
+              org.apache.karaf.shell.commands,
+              org.apache.karaf.shell.console,
+              *</Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/AddUserLink.java b/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/AddUserLink.java
new file mode 100644 (file)
index 0000000..1565a87
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+* Copyright (c) 2014 Inocybe Technologies, 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.topologymanager.shell;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.topologymanager.ITopologyManagerShell;
+
+@Command(scope = "topologymanager", name = "addUserLink", description="Adds user link")
+public class AddUserLink extends OsgiCommandSupport{
+    private ITopologyManagerShell topologyManager;
+
+    @Argument(index=0, name="name", description="name", required=true, multiValued=false)
+    String name = null;
+
+    @Argument(index=1, name="ncStr1", description="ncStr1", required=true, multiValued=false)
+    String ncStr1 = null;
+
+    @Argument(index=2, name="ncStr2", description="ncStr2", required=true, multiValued=false)
+    String ncStr2 = null;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        for(String p : topologyManager.addUserLink(name, ncStr1, ncStr2)) {
+            System.out.println(p);
+        }
+        return null;
+    }
+
+    public void setTopologyManager(ITopologyManagerShell topologyManager){
+        this.topologyManager = topologyManager;
+    }
+}
diff --git a/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/DeleteUserLink.java b/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/DeleteUserLink.java
new file mode 100644 (file)
index 0000000..b226c3c
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+* Copyright (c) 2014 Inocybe Technologies, 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.topologymanager.shell;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.topologymanager.ITopologyManagerShell;
+
+@Command(scope = "topologymanager", name = "deleteUserLink", description="deletes user link")
+public class DeleteUserLink extends OsgiCommandSupport{
+    private ITopologyManagerShell topologyManager;
+
+    @Argument(index=0, name="name", description="name", required=true, multiValued=false)
+    String name = null;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        for(String p : topologyManager.deleteUserLinkShell(name)) {
+            System.out.println(p);
+        }
+        return null;
+    }
+
+    public void setTopologyManager(ITopologyManagerShell topologyManager){
+        this.topologyManager = topologyManager;
+    }
+}
diff --git a/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/PrintNodeEdges.java b/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/PrintNodeEdges.java
new file mode 100644 (file)
index 0000000..9c5e806
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+* Copyright (c) 2014 Inocybe Technologies, 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.topologymanager.shell;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.topologymanager.ITopologyManagerShell;
+
+@Command(scope = "topologymanager", name = "printNodeEdges", description="Prints node edges")
+public class PrintNodeEdges extends OsgiCommandSupport{
+    private ITopologyManagerShell topologyManager;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        for(String p : topologyManager.printNodeEdges()) {
+            System.out.println(p);
+        }
+        return null;
+    }
+
+    public void setTopologyManager(ITopologyManagerShell topologyManager){
+        this.topologyManager = topologyManager;
+    }
+}
diff --git a/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/PrintUserLink.java b/opendaylight/topologymanager/shell/src/main/java/org/opendaylight/controller/topologymanager/shell/PrintUserLink.java
new file mode 100644 (file)
index 0000000..df7ab35
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+* Copyright (c) 2014 Inocybe Technologies, 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.topologymanager.shell;
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.opendaylight.controller.topologymanager.ITopologyManagerShell;
+
+@Command(scope = "topologymanager", name = "printUserLink", description="Prints user link")
+public class PrintUserLink extends OsgiCommandSupport{
+    private ITopologyManagerShell topologyManager;
+
+    @Override
+    protected Object doExecute() throws Exception {
+        for(String p : topologyManager.printUserLink()) {
+            System.out.println(p);
+        }
+        return null;
+    }
+
+    public void setTopologyManager(ITopologyManagerShell topologyManager){
+        this.topologyManager = topologyManager;
+    }
+}
diff --git a/opendaylight/topologymanager/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/opendaylight/topologymanager/shell/src/main/resources/OSGI-INF/blueprint/blueprint.xml
new file mode 100644 (file)
index 0000000..96b0b10
--- /dev/null
@@ -0,0 +1,33 @@
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <reference id="topologyManagerRef" interface="org.opendaylight.controller.topologymanager.ITopologyManagerShell"/>
+    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+
+        <command>
+        <action class="org.opendaylight.controller.topologymanager.shell.AddUserLink">
+            <property name="topologyManager" ref="topologyManagerRef"/>
+            </action>
+        </command>
+
+        <command>
+        <action class="org.opendaylight.controller.topologymanager.shell.DeleteUserLink">
+            <property name="topologyManager" ref="topologyManagerRef"/>
+            </action>
+        </command>
+
+        <command>
+        <action class="org.opendaylight.controller.topologymanager.shell.PrintNodeEdges">
+            <property name="topologyManager" ref="topologyManagerRef"/>
+            </action>
+        </command>
+
+        <command>
+        <action class="org.opendaylight.controller.topologymanager.shell.PrintUserLink">
+            <property name="topologyManager" ref="topologyManagerRef"/>
+            </action>
+        </command>
+
+    </command-bundle>
+
+
+</blueprint>