Search in sources :

Example 1 with Instance

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

the class InstancesMBeanImpl method createInstance.

public int createInstance(String name, int sshPort, int rmiRegistryPort, int rmiServerPort, String location, String javaOpts, String features, String featureURLs, String address) throws MBeanException {
    try {
        if ("".equals(location)) {
            location = null;
        }
        if ("".equals(javaOpts)) {
            javaOpts = null;
        }
        InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts, parseStringList(featureURLs), parseStringList(features), address);
        Instance inst = instanceService.createInstance(name, settings, false);
        if (inst != null) {
            return inst.getPid();
        } else {
            return -1;
        }
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) Instance(org.apache.karaf.instance.core.Instance) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException)

Example 2 with Instance

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

the class DestroyCommand method doExecute.

@SuppressWarnings("deprecation")
protected Object doExecute() throws Exception {
    final MultiException exception = new MultiException("Error destroying instance(s)");
    for (Instance instance : getMatchingInstances(instances)) {
        try {
            instance.destroy();
        } catch (Exception e) {
            exception.addException(e);
        }
    }
    exception.throwIfExceptions();
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) MultiException(org.apache.karaf.shell.support.MultiException) MultiException(org.apache.karaf.shell.support.MultiException)

Example 3 with Instance

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

the class ListCommand method doExecute.

protected Object doExecute() throws Exception {
    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));
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) Instance(org.apache.karaf.instance.core.Instance)

Example 4 with Instance

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

the class RestartCommand method doExecute.

@SuppressWarnings("deprecation")
protected Object doExecute() throws Exception {
    MultiException exception = new MultiException("Error starting instance(s)");
    List<Instance> toWaitFor = new ArrayList<>();
    for (Instance instance : getMatchingInstances(instances)) {
        try {
            String opts = javaOpts;
            if (opts == null) {
                opts = instance.getJavaOpts();
            }
            if (opts == null) {
                opts = DEFAULT_OPTS;
            }
            if (debug) {
                opts += DEBUG_OPTS;
            }
            instance.restart(opts);
        } catch (Exception e) {
            exception.addException(e);
        }
    }
    exception.throwIfExceptions();
    while (true) {
        boolean allStarted = true;
        for (Instance child : toWaitFor) {
            allStarted &= Instance.STARTED.equals(child.getState());
        }
        if (allStarted) {
            break;
        } else {
            Thread.sleep(500);
        }
    }
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) ArrayList(java.util.ArrayList) MultiException(org.apache.karaf.shell.support.MultiException) MultiException(org.apache.karaf.shell.support.MultiException)

Example 5 with Instance

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

the class StartCommand method doExecute.

@SuppressWarnings("deprecation")
protected Object doExecute() throws Exception {
    MultiException exception = new MultiException("Error starting instance(s)");
    List<Instance> toWaitFor = new ArrayList<>();
    for (Instance instance : getMatchingInstances(instances)) {
        try {
            String opts = javaOpts;
            if (opts == null) {
                opts = instance.getJavaOpts();
            }
            if (opts == null) {
                opts = DEFAULT_OPTS;
            }
            if (debug) {
                opts += DEBUG_OPTS;
            }
            if (wait) {
                String state = instance.getState();
                if (Instance.STOPPED.equals(state)) {
                    instance.start(opts);
                    toWaitFor.add(instance);
                }
            } else {
                instance.start(opts);
            }
        } catch (Exception e) {
            exception.addException(e);
        }
    }
    exception.throwIfExceptions();
    while (true) {
        boolean allStarted = true;
        for (Instance child : toWaitFor) {
            allStarted &= Instance.STARTED.equals(child.getState());
        }
        if (allStarted) {
            break;
        } else {
            Thread.sleep(500);
        }
    }
    return null;
}
Also used : Instance(org.apache.karaf.instance.core.Instance) ArrayList(java.util.ArrayList) MultiException(org.apache.karaf.shell.support.MultiException) MultiException(org.apache.karaf.shell.support.MultiException)

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