[KARAF-6064] Add configs operation on Cave Deployer to list the configuration PIDs 17/head
authorJean-Baptiste Onofré <jbonofre@apache.org>
Mon, 7 Jan 2019 16:35:39 +0000 (17:35 +0100)
committerJean-Baptiste Onofré <jbonofre@apache.org>
Mon, 7 Jan 2019 16:35:39 +0000 (17:35 +0100)
deployer/api/src/main/java/org/apache/karaf/cave/deployer/api/Deployer.java
deployer/command/src/main/java/org/apache/karaf/cave/deployer/command/ConfigListCommand.java [new file with mode: 0644]
deployer/management/src/main/java/org/apache/karaf/cave/deployer/management/CaveDeployerMBean.java
deployer/management/src/main/java/org/apache/karaf/cave/deployer/management/internal/CaveDeployerMBeanImpl.java
deployer/service/src/main/java/org/apache/karaf/cave/deployer/service/impl/DeployerImpl.java

index c21d5aa..7ca7cf8 100644 (file)
@@ -173,6 +173,11 @@ public interface Deployer {
     List<String> installedFeatures(String connection) throws Exception;
 
     /**
+     * Simple remote operation to list the configuration PIDs on a remote Karaf instance.
+     */
+    List<String> configs(String connection) throws Exception;
+
+    /**
      * Simple remote operation to create an empty configuration on a remote Karaf instance.
      */
     void createConfig(String pid, String connection) throws Exception;
diff --git a/deployer/command/src/main/java/org/apache/karaf/cave/deployer/command/ConfigListCommand.java b/deployer/command/src/main/java/org/apache/karaf/cave/deployer/command/ConfigListCommand.java
new file mode 100644 (file)
index 0000000..1284ebe
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.cave.deployer.command;
+
+import org.apache.karaf.cave.deployer.api.Deployer;
+import org.apache.karaf.cave.deployer.command.completers.ConnectionCompleter;
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+import java.util.List;
+
+@Service
+@Command(scope = "cave", name = "deployer-config-list", description = "List the configuration PIDs on a remote instance")
+public class ConfigListCommand implements Action {
+
+    @Reference
+    private Deployer deployer;
+
+    @Argument(index = 0, name = "connection", description = "The connection to use", required = true, multiValued = false)
+    @Completion(ConnectionCompleter.class)
+    String connection;
+
+    @Override
+    public Object execute() throws Exception {
+        List<String> configs = deployer.configs(connection);
+        for (String config : configs) {
+            System.out.println(config);
+        }
+        return null;
+    }
+
+}
index cc573ff..3a457b3 100644 (file)
@@ -49,6 +49,7 @@ public interface CaveDeployerMBean {
     void uninstallFeature(String feature, String connection) throws Exception;
     TabularData getFeatures(String connection) throws Exception;
 
+    List<String> configs(String connection) throws Exception;
     void createConfig(String pid, String connection) throws Exception;
     Map<String, String> getConfigProperties(String pid, String connection) throws Exception;
     void deleteConfig(String pid, String connection) throws Exception;
index bfe6833..b9f2b07 100644 (file)
@@ -218,6 +218,11 @@ public class CaveDeployerMBeanImpl extends StandardMBean implements CaveDeployer
     }
 
     @Override
+    public List<String> configs(String connection) throws Exception {
+        return deployer.configs(connection);
+    }
+
+    @Override
     public void createConfig(String pid, String connection) throws Exception {
         deployer.createConfig(pid, connection);
     }
index 22d549e..db4c62c 100644 (file)
@@ -721,6 +721,25 @@ public class DeployerImpl implements Deployer {
     }
 
     @Override
+    public List<String> configs(String connectionName) throws Exception {
+        Connection connection = getConnection(connectionName);
+        JMXConnector jmxConnector = connect(connection.getJmxUrl(),
+                connection.getKarafName(),
+                connection.getUser(),
+                connection.getPassword());
+        try {
+            MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
+            ObjectName name = new ObjectName("org.apache.karaf:type=config,name=" + connection.getKarafName());
+            List<String> result = (List<String>) mBeanServerConnection.getAttribute(name, "Configs");
+            return result;
+        } finally {
+            if (jmxConnector != null) {
+                jmxConnector.close();
+            }
+        }
+    }
+
+    @Override
     public void createConfig(String pid, String connectionName) throws Exception {
         Connection connection = getConnection(connectionName);
         JMXConnector jmxConnector = connect(connection.getJmxUrl(),