karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: KARAF-3551 - Extend instance service with ssh and RMI hosts
Date Mon, 08 Feb 2016 13:15:46 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x 95ee24656 -> 3879146e5


KARAF-3551 - Extend instance service with ssh and RMI hosts


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/3879146e
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/3879146e
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/3879146e

Branch: refs/heads/karaf-4.0.x
Commit: 3879146e5eff05dc3960ebbdec601237e238a917
Parents: 95ee246
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Feb 8 13:47:21 2016 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Feb 8 13:50:07 2016 +0100

----------------------------------------------------------------------
 .../karaf/instance/command/ListCommand.java     |  6 +++
 .../apache/karaf/instance/core/Instance.java    |  6 +++
 .../karaf/instance/core/InstancesMBean.java     |  7 ++-
 .../instance/core/internal/InstanceImpl.java    | 12 +++++
 .../core/internal/InstanceServiceImpl.java      | 55 ++++++++++++++------
 .../core/internal/InstanceToTableMapper.java    | 13 +++--
 .../internal/InstanceServiceMBeanImplTest.java  |  4 ++
 .../internal/InstanceToTableMapperTest.java     | 12 +++++
 8 files changed, 93 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/main/java/org/apache/karaf/instance/command/ListCommand.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/command/ListCommand.java b/instance/src/main/java/org/apache/karaf/instance/command/ListCommand.java
index 9cd121a..5e28454 100644
--- a/instance/src/main/java/org/apache/karaf/instance/command/ListCommand.java
+++ b/instance/src/main/java/org/apache/karaf/instance/command/ListCommand.java
@@ -39,16 +39,22 @@ public class ListCommand extends InstanceCommandSupport {
         Instance[] instances = getInstanceService().getInstances();
         ShellTable table = new ShellTable();
         table.column("SSH Port").alignRight();
+        table.column("SSH Host").alignRight();
         table.column("RMI Registry").alignRight();
+        table.column("RMI Registry Host").alignRight();
         table.column("RMI Server").alignRight();
+        table.column("RMI Server Host").alignRight();
         table.column("State");
         table.column("PID");
         table.column(getRightColumnHeader());
         for (Instance instance : instances) {
             table.addRow().addContent(
                     instance.getSshPort(),
+                    instance.getSshHost(),
                     instance.getRmiRegistryPort(),
+                    instance.getRmiRegistryHost(),
                     instance.getRmiServerPort(),
+                    instance.getRmiServerHost(),
                     instance.getState(),
                     instance.getPid(),
                     getRightColumnValue(instance));

http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/main/java/org/apache/karaf/instance/core/Instance.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/core/Instance.java b/instance/src/main/java/org/apache/karaf/instance/core/Instance.java
index 99fdd1e..b3fd5d4 100644
--- a/instance/src/main/java/org/apache/karaf/instance/core/Instance.java
+++ b/instance/src/main/java/org/apache/karaf/instance/core/Instance.java
@@ -35,14 +35,20 @@ public interface Instance {
 
     void changeSshPort(int port) throws Exception;
 
+    String getSshHost();
+
     int getRmiRegistryPort();
 
     void changeRmiRegistryPort(int port) throws Exception;
 
+    String getRmiRegistryHost();
+
     int getRmiServerPort();
 
     void changeRmiServerPort(int port) throws Exception;
 
+    String getRmiServerHost();
+
     String getJavaOpts();
 
     void changeJavaOpts(String javaOpts) throws Exception;

http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java b/instance/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
index 0265091..1c74294 100644
--- a/instance/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
+++ b/instance/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
@@ -25,14 +25,17 @@ public interface InstancesMBean {
     String INSTANCE_NAME = "Name";
     String INSTANCE_IS_ROOT = "Is Root";
     String INSTANCE_SSH_PORT = "SSH Port";
+    String INSTANCE_SSH_HOST = "SSH Host";
     String INSTANCE_RMI_REGISTRY_PORT = "RMI Registry Port";
+    String INSTANCE_RMI_REGISTRY_HOST = "RMI Registry Host";
     String INSTANCE_RMI_SERVER_PORT = "RMI Server Port";
+    String INSTANCE_RMI_SERVER_HOST = "RMI Server Host";
     String INSTANCE_STATE = "State";
     String INSTANCE_LOCATION = "Location";
     String INSTANCE_JAVAOPTS = "JavaOpts";
 
-    String[] INSTANCE = {INSTANCE_PID, INSTANCE_NAME, INSTANCE_IS_ROOT, INSTANCE_SSH_PORT,
INSTANCE_RMI_REGISTRY_PORT,
-            INSTANCE_RMI_SERVER_PORT, INSTANCE_STATE, INSTANCE_LOCATION, INSTANCE_JAVAOPTS
};
+    String[] INSTANCE = {INSTANCE_PID, INSTANCE_NAME, INSTANCE_IS_ROOT, INSTANCE_SSH_PORT,
INSTANCE_SSH_HOST, INSTANCE_RMI_REGISTRY_PORT, INSTANCE_RMI_REGISTRY_HOST,
+            INSTANCE_RMI_SERVER_PORT, INSTANCE_RMI_SERVER_HOST, INSTANCE_STATE, INSTANCE_LOCATION,
INSTANCE_JAVAOPTS };
 
     // Operations
     int createInstance(String name, int sshPort, int rmiRegistryPort, int rmiServerPort,
String location, String javaOpts, String features, String featureURLs) throws MBeanException;

http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
index 229cc53..da48b80 100644
--- a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
+++ b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
@@ -52,6 +52,10 @@ public class InstanceImpl implements Instance {
         return service.getInstanceSshPort(name);
     }
 
+    public String getSshHost() {
+        return service.getInstanceSshHost(name);
+    }
+
     public void changeSshPort(int port) throws Exception {
         service.changeInstanceSshPort(name, port);
     }
@@ -64,6 +68,10 @@ public class InstanceImpl implements Instance {
         service.changeInstanceRmiRegistryPort(name, port);
     }
 
+    public String getRmiRegistryHost() {
+        return service.getInstanceRmiRegistryHost(name);
+    }
+
     public int getRmiServerPort() {
         return service.getInstanceRmiServerPort(name);
     }
@@ -72,6 +80,10 @@ public class InstanceImpl implements Instance {
         service.changeInstanceRmiServerPort(name, port);
     }
 
+    public String getRmiServerHost() {
+        return service.getInstanceRmiServerHost(name);
+    }
+
     public String getJavaOpts() {
         return service.getInstanceJavaOpts(name);
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
index 56c9c46..6372b8a 100644
--- a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
+++ b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
@@ -847,6 +847,10 @@ public class InstanceServiceImpl implements InstanceService {
         setKarafPort(name, "etc/org.apache.karaf.shell.cfg", "sshPort", port);
     }
 
+    String getInstanceSshHost(String name) {
+        return getKarafHost(name, "etc/org.apache.karaf.shell.cfg", "sshHost");
+    }
+
     int getInstanceRmiRegistryPort(String name) {
         return getKarafPort(name, "etc/org.apache.karaf.management.cfg", "rmiRegistryPort");
     }
@@ -855,6 +859,10 @@ public class InstanceServiceImpl implements InstanceService {
         setKarafPort(name, "etc/org.apache.karaf.management.cfg", "rmiRegistryPort", port);
     }
 
+    String getInstanceRmiRegistryHost(String name) {
+        return getKarafHost(name, "etc/org.apache.karaf.management.cfg", "rmiRegistryHost");
+    }
+
     int getInstanceRmiServerPort(String name) {
         return getKarafPort(name, "etc/org.apache.karaf.management.cfg", "rmiServerPort");
     }
@@ -863,6 +871,10 @@ public class InstanceServiceImpl implements InstanceService {
         setKarafPort(name, "etc/org.apache.karaf.management.cfg", "rmiServerPort", port);
     }
 
+    String getInstanceRmiServerHost(String name) {
+        return getKarafHost(name, "etc/org.apache.karaf.management.cfg", "rmiServerHost");
+    }
+
     private int getKarafPort(final String name, final String path, final String key) {
         return execute(new Task<Integer>() {
             public Integer call(State state) throws IOException {
@@ -871,6 +883,7 @@ public class InstanceServiceImpl implements InstanceService {
         }, false);
     }
 
+
     private Integer getKarafPort(State state, String name, String path, final String key)
{
         InstanceState instance = state.instances.get(name);
         if (instance == null) {
@@ -887,23 +900,6 @@ public class InstanceServiceImpl implements InstanceService {
             return 0;
         }
     }
-    
-    private String getKarafHost(State state, String name, String path, final String key)
{
-        InstanceState instance = state.instances.get(name);
-        if (instance == null) {
-            throw new IllegalArgumentException("Instance " + name + " not found");
-        }
-        File f = new File(instance.loc, path);
-        try {
-            return FileLockUtils.execute(f, new FileLockUtils.CallableWithProperties<String>()
{
-                public String call(org.apache.felix.utils.properties.Properties properties)
throws IOException {
-                    return properties.get(key).toString();
-                }
-            }, false);
-        } catch (IOException e) {
-            return "0.0.0.0";
-        }
-    }
 
     private void setKarafPort(final String name, final String path, final String key, final
int port) throws IOException {
         execute(new Task<Object>() {
@@ -927,6 +923,31 @@ public class InstanceServiceImpl implements InstanceService {
         }, true);
     }
 
+    private String getKarafHost(final String name, final String path, final String key) {
+        return execute(new Task<String>() {
+            public String call(State state) throws IOException {
+                return InstanceServiceImpl.this.getKarafHost(state, name, path, key);
+            }
+        }, false);
+    }
+
+    private String getKarafHost(State state, String name, String path, final String key)
{
+        InstanceState instance = state.instances.get(name);
+        if (instance == null) {
+            throw new IllegalArgumentException("Instance " + name + " not found");
+        }
+        File f = new File(instance.loc, path);
+        try {
+            return FileLockUtils.execute(f, new FileLockUtils.CallableWithProperties<String>()
{
+                public String call(org.apache.felix.utils.properties.Properties properties)
throws IOException {
+                    return properties.get(key).toString();
+                }
+            }, false);
+        } catch (IOException e) {
+            return "0.0.0.0";
+        }
+    }
+
     boolean isInstanceRoot(final String name) {
         return execute(new Task<Boolean>() {
             public Boolean call(State state) throws IOException {

http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceToTableMapper.java
----------------------------------------------------------------------
diff --git a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceToTableMapper.java
b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceToTableMapper.java
index baaedaf..45d1cbc 100644
--- a/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceToTableMapper.java
+++ b/instance/src/main/java/org/apache/karaf/instance/core/internal/InstanceToTableMapper.java
@@ -43,8 +43,10 @@ public class InstanceToTableMapper {
             state = "Error";
         }
         Object[] itemValues = new Object[] {instance.getPid(), instance.getName(), instance.isRoot(),
-                                            instance.getSshPort(), instance.getRmiRegistryPort(),
-                                            instance.getRmiServerPort(), state, instance.getLocation(),
+                                            instance.getSshPort(), instance.getSshHost(),
+                                            instance.getRmiRegistryPort(), instance.getRmiRegistryHost(),
+                                            instance.getRmiServerPort(), instance.getRmiServerHost(),
+                                            state, instance.getLocation(),
                                             instance.getJavaOpts()};
         return new CompositeDataSupport(comp, InstancesMBean.INSTANCE, itemValues);
     }
@@ -52,13 +54,18 @@ public class InstanceToTableMapper {
     private static CompositeType createRowType() throws OpenDataException {
         String desc = "This type describes Karaf instance";
         OpenType<?>[] itemTypes = new OpenType[] {SimpleType.INTEGER, SimpleType.STRING,
SimpleType.BOOLEAN,
-                                                  SimpleType.INTEGER, SimpleType.INTEGER,
SimpleType.INTEGER,
+                                                  SimpleType.INTEGER, SimpleType.STRING,
+                                                  SimpleType.INTEGER, SimpleType.STRING,
+                                                  SimpleType.INTEGER, SimpleType.STRING,
                                                   SimpleType.STRING, SimpleType.STRING, SimpleType.STRING};
         String[] descriptions = new String[] {"The Process ID of the instance or 0 if not
running",
                                               "The name of the instance", "Whether the instance
is root",
                                               "The SSH port that can be used to connect to
the instance",
+                                              "The host address where the SSH server is listening",
                                               "The RMI registry port that can be used to
manage the instance",
+                                              "The host address where the RMI registry is
listening",
                                               "The RMI server port that can be used to manage
the instance",
+                                              "The host address where the RMI server is listening",
                                               "The state of the instance", "The location
of the instance",
                                               "The Java options of the instance"};
         CompositeType comp = new CompositeType("Instances", desc, InstancesMBean.INSTANCE,
descriptions, itemTypes);

http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceServiceMBeanImplTest.java
----------------------------------------------------------------------
diff --git a/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceServiceMBeanImplTest.java
b/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceServiceMBeanImplTest.java
index 309acfb..8dbf49a 100644
--- a/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceServiceMBeanImplTest.java
+++ b/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceServiceMBeanImplTest.java
@@ -66,8 +66,11 @@ public class InstanceServiceMBeanImplTest extends TestCase {
         Instance i1 = EasyMock.createMock(Instance.class);
         EasyMock.expect(i1.getPid()).andReturn(1234);
         EasyMock.expect(i1.getSshPort()).andReturn(8818);
+        EasyMock.expect(i1.getSshHost()).andReturn("0.0.0.0");
         EasyMock.expect(i1.getRmiRegistryPort()).andReturn(1122);
+        EasyMock.expect(i1.getRmiRegistryHost()).andReturn("0.0.0.0");
         EasyMock.expect(i1.getRmiServerPort()).andReturn(44444);
+        EasyMock.expect(i1.getRmiServerHost()).andReturn("0.0.0.0");
         EasyMock.expect(i1.getName()).andReturn("i1");
         EasyMock.expect(i1.isRoot()).andReturn(true);
         EasyMock.expect(i1.getLocation()).andReturn("somewhere");
@@ -92,6 +95,7 @@ public class InstanceServiceMBeanImplTest extends TestCase {
         Assert.assertTrue(cd1.containsValue(8818));
         Assert.assertTrue(cd1.containsValue(1122));
         Assert.assertTrue(cd1.containsValue(44444));
+        Assert.assertTrue(cd1.containsValue("0.0.0.0"));
         Assert.assertTrue(cd1.containsValue("somewhere"));
         Assert.assertTrue(cd1.containsValue("someopts"));
         Assert.assertTrue(cd1.containsValue("Stopped"));

http://git-wip-us.apache.org/repos/asf/karaf/blob/3879146e/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceToTableMapperTest.java
----------------------------------------------------------------------
diff --git a/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceToTableMapperTest.java
b/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceToTableMapperTest.java
index c9541d3..6210ccb 100644
--- a/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceToTableMapperTest.java
+++ b/instance/src/test/java/org/apache/karaf/instance/core/management/internal/InstanceToTableMapperTest.java
@@ -36,8 +36,11 @@ public class InstanceToTableMapperTest extends TestCase {
         EasyMock.expect(instance.getName()).andReturn("MyInstance");
         EasyMock.expect(instance.isRoot()).andReturn(false);
         EasyMock.expect(instance.getSshPort()).andReturn(0);
+        EasyMock.expect(instance.getSshHost()).andReturn("0.0.0.0");
         EasyMock.expect(instance.getRmiRegistryPort()).andReturn(0);
+        EasyMock.expect(instance.getRmiRegistryHost()).andReturn("0.0.0.0");
         EasyMock.expect(instance.getRmiServerPort()).andReturn(0);
+        EasyMock.expect(instance.getRmiServerHost()).andReturn("0.0.0.0");
         EasyMock.expect(instance.getState()).andThrow(new Exception("gotcha"));
         EasyMock.expect(instance.getLocation()).andReturn("somewhere");
         EasyMock.expect(instance.getJavaOpts()).andReturn("someopts");
@@ -52,8 +55,11 @@ public class InstanceToTableMapperTest extends TestCase {
         Assert.assertEquals("MyInstance", cd.get("Name"));
         Assert.assertEquals(false, cd.get("Is Root"));
         Assert.assertEquals(0, cd.get("SSH Port"));
+        Assert.assertEquals("0.0.0.0", cd.get("SSH Host"));
         Assert.assertEquals(0, cd.get("RMI Registry Port"));
+        Assert.assertEquals("0.0.0.0", cd.get("RMI Registry Host"));
         Assert.assertEquals(0, cd.get("RMI Server Port"));
+        Assert.assertEquals("0.0.0.0", cd.get("RMI Server Host"));
         Assert.assertEquals("Error", cd.get("State"));
         Assert.assertEquals("somewhere", cd.get("Location"));
         Assert.assertEquals("someopts", cd.get("JavaOpts"));
@@ -65,8 +71,11 @@ public class InstanceToTableMapperTest extends TestCase {
         EasyMock.expect(instance.getName()).andReturn("MyInstance");
         EasyMock.expect(instance.isRoot()).andReturn(true);
         EasyMock.expect(instance.getSshPort()).andReturn(0);
+        EasyMock.expect(instance.getSshHost()).andReturn("0.0.0.0");
         EasyMock.expect(instance.getRmiRegistryPort()).andReturn(0);
+        EasyMock.expect(instance.getRmiRegistryHost()).andReturn("0.0.0.0");
         EasyMock.expect(instance.getRmiServerPort()).andReturn(0);
+        EasyMock.expect(instance.getRmiServerHost()).andReturn("0.0.0.0");
         EasyMock.expect(instance.getState()).andReturn("Started");
         EasyMock.expect(instance.getLocation()).andReturn(null);
         EasyMock.expect(instance.getJavaOpts()).andReturn(null);
@@ -81,8 +90,11 @@ public class InstanceToTableMapperTest extends TestCase {
         Assert.assertEquals("MyInstance", cd.get("Name"));
         Assert.assertEquals(true, cd.get("Is Root"));
         Assert.assertEquals(0, cd.get("SSH Port"));
+        Assert.assertEquals("0.0.0.0", cd.get("SSH Host"));
         Assert.assertEquals(0, cd.get("RMI Registry Port"));
+        Assert.assertEquals("0.0.0.0", cd.get("RMI Registry Host"));
         Assert.assertEquals(0, cd.get("RMI Server Port"));
+        Assert.assertEquals("0.0.0.0", cd.get("RMI Server Host"));
         Assert.assertEquals("Started", cd.get("State"));
         Assert.assertNull(cd.get("Location"));
         Assert.assertNull(cd.get("JavaOpts"));


Mime
View raw message