Search in sources :

Example 6 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceMBeanImplTest method testSshChangePort.

public void testSshChangePort() throws Exception {
    Instance inst = EasyMock.createMock(Instance.class);
    inst.changeSshPort(7788);
    EasyMock.expectLastCall();
    EasyMock.replay(inst);
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
    EasyMock.replay(instanceService);
    InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
    instanceServiceMBean.changeSshPort("test instance", 7788);
    EasyMock.verify(instanceService);
    EasyMock.verify(inst);
}
Also used : Instance(org.apache.karaf.instance.core.Instance) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl) InstancesMBean(org.apache.karaf.instance.core.InstancesMBean) InstanceService(org.apache.karaf.instance.core.InstanceService)

Example 7 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceMBeanImplTest method testCreateInstance.

public void testCreateInstance() throws Exception {
    final InstanceSettings instanceSettings = new InstanceSettings(123, 456, 789, "somewhere", "someopts", Collections.emptyList(), Arrays.asList("webconsole", "funfeat"), "localhost");
    final Instance inst = EasyMock.createMock(Instance.class);
    EasyMock.expect(inst.getPid()).andReturn(42);
    EasyMock.replay(inst);
    org.apache.karaf.instance.core.InstanceService instanceService = EasyMock.createMock(org.apache.karaf.instance.core.InstanceService.class);
    EasyMock.expect(instanceService.createInstance("t1", instanceSettings, false)).andReturn(inst);
    EasyMock.replay(instanceService);
    InstancesMBeanImpl ab = new InstancesMBeanImpl(instanceService);
    assertEquals(42, ab.createInstance("t1", 123, 456, 789, "somewhere", "someopts", " webconsole,  funfeat", ""));
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) InstanceService(org.apache.karaf.instance.core.InstanceService) Instance(org.apache.karaf.instance.core.Instance) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl)

Example 8 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceMBeanImplTest method testRmiServerChangePort.

public void testRmiServerChangePort() throws Exception {
    Instance inst = EasyMock.createMock(Instance.class);
    inst.changeRmiServerPort(44444);
    EasyMock.expectLastCall();
    EasyMock.replay(inst);
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
    EasyMock.replay(instanceService);
    InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
    instanceServiceMBean.changeRmiServerPort("test instance", 44444);
    EasyMock.verify(instanceService);
    EasyMock.verify(inst);
}
Also used : Instance(org.apache.karaf.instance.core.Instance) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl) InstancesMBean(org.apache.karaf.instance.core.InstancesMBean) InstanceService(org.apache.karaf.instance.core.InstanceService)

Example 9 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceToTableMapperTest method testJMXInstance2.

public void testJMXInstance2() throws Exception {
    Instance instance = EasyMock.createMock(Instance.class);
    EasyMock.expect(instance.getPid()).andReturn(1712);
    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);
    EasyMock.replay(instance);
    TabularData td = InstanceToTableMapper.tableFrom(Collections.singletonList(instance));
    Collection<?> keys = (Collection<?>) td.keySet().iterator().next();
    Assert.assertEquals("MyInstance", keys.iterator().next());
    CompositeData cd = td.get(keys.toArray());
    Assert.assertEquals(1712, cd.get("Pid"));
    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"));
}
Also used : Instance(org.apache.karaf.instance.core.Instance) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 10 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceImplTest method testTextResources.

public void testTextResources() throws Exception {
    InstanceServiceImpl service = new InstanceServiceImpl();
    service.setStorageLocation(new File("target/instances/" + System.currentTimeMillis()));
    Map<String, URL> textResources = new HashMap<>();
    textResources.put("etc/myresource", getClass().getClassLoader().getResource("myresource"));
    InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null, null, null, null, textResources, new HashMap<>());
    Instance instance = service.createInstance(getName(), settings, false);
    assertFileExists(instance.getLocation(), "etc/myresource");
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) HashMap(java.util.HashMap) Instance(org.apache.karaf.instance.core.Instance) File(java.io.File) URL(java.net.URL)

Aggregations

Instance (org.apache.karaf.instance.core.Instance)28 InstanceService (org.apache.karaf.instance.core.InstanceService)11 InstancesMBeanImpl (org.apache.karaf.instance.core.internal.InstancesMBeanImpl)10 InstancesMBean (org.apache.karaf.instance.core.InstancesMBean)8 InstanceSettings (org.apache.karaf.instance.core.InstanceSettings)5 TabularData (javax.management.openmbean.TabularData)4 MultiException (org.apache.karaf.shell.support.MultiException)4 ArrayList (java.util.ArrayList)3 CompositeData (javax.management.openmbean.CompositeData)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 MBeanException (javax.management.MBeanException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 ServletException (javax.servlet.ServletException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1