Search in sources :

Example 16 with Instance

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

the class InstancesMBeanImpl method startInstance.

public void startInstance(String name, String opts, boolean wait, boolean debug) throws MBeanException {
    try {
        Instance child = getExistingInstance(name);
        String options = opts;
        if (options == null) {
            options = child.getJavaOpts();
        }
        if (options == null) {
            options = DEFAULT_OPTS;
        }
        if (debug) {
            options += DEBUG_OPTS;
        }
        if (wait) {
            String state = child.getState();
            if (Instance.STOPPED.equals(state)) {
                child.start(opts);
            }
            if (!Instance.STARTED.equals(state)) {
                do {
                    Thread.sleep(500);
                    state = child.getState();
                } while (Instance.STARTING.equals(state));
            }
        } else {
            child.start(opts);
        }
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : Instance(org.apache.karaf.instance.core.Instance) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException)

Example 17 with Instance

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

the class InstancesMBeanImpl method getInstances.

public TabularData getInstances() throws MBeanException {
    List<Instance> instances = Arrays.asList(instanceService.getInstances());
    TabularData table = InstanceToTableMapper.tableFrom(instances);
    return table;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) TabularData(javax.management.openmbean.TabularData)

Example 18 with Instance

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

the class InstanceServiceMBeanImplTest method testStartInstanceWithJavaOpts.

public void testStartInstanceWithJavaOpts() throws Exception {
    Instance inst = EasyMock.createMock(Instance.class);
    inst.start("-x -y -z");
    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.startInstance("test instance", "-x -y -z");
    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 19 with Instance

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

the class InstanceServiceMBeanImplTest method testDestroyInstance.

public void testDestroyInstance() throws Exception {
    Instance inst = EasyMock.createMock(Instance.class);
    inst.destroy();
    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.destroyInstance("test instance");
    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 20 with Instance

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

the class InstanceCommandSupport method getMatchingInstances.

protected List<Instance> getMatchingInstances(List<String> patterns) {
    List<Instance> instances = new ArrayList<>();
    Instance[] allInstances = instanceService.getInstances();
    for (Instance instance : allInstances) {
        if (match(instance.getName(), patterns)) {
            instances.add(instance);
        }
    }
    if (instances.isEmpty()) {
        throw new IllegalArgumentException("No matching instances");
    }
    return instances;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) ArrayList(java.util.ArrayList)

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