Search in sources :

Example 1 with InstanceSettings

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

the class InstancesMBeanImpl method cloneInstance.

public void cloneInstance(String name, String cloneName, int sshPort, int rmiRegistryPort, int rmiServerPort, String location, String javaOpts) throws MBeanException {
    try {
        if ("".equals(location)) {
            location = null;
        }
        if ("".equals(javaOpts)) {
            javaOpts = null;
        }
        InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts, null, null);
        instanceService.cloneInstance(name, cloneName, settings, false);
    } catch (Exception e) {
        throw new MBeanException(null, e.toString());
    }
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException)

Example 2 with InstanceSettings

use of org.apache.karaf.instance.core.InstanceSettings 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 3 with InstanceSettings

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

the class CloneCommand method doExecute.

protected Object doExecute() throws Exception {
    Map<String, URL> textResources = getResources(textResourceLocation);
    Map<String, URL> binaryResources = getResources(binaryResourceLocations);
    InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts, null, null, null, textResources, binaryResources);
    getInstanceService().cloneInstance(name, cloneName, settings, verbose);
    return null;
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) URL(java.net.URL)

Example 4 with InstanceSettings

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

the class CreateCommand method doExecute.

protected Object doExecute() throws Exception {
    if (!bare) {
        Properties configuration = new Properties();
        File configFile = new File(System.getProperty("karaf.etc"), FEATURES_SERVICE_CONFIG_FILE);
        configuration.load(configFile);
        String featuresRepositories = configuration.getProperty("featuresRepositories", "");
        String featuresBoot = configuration.getProperty("featuresBoot", "");
        if (featureURLs == null) {
            featureURLs = new ArrayList<>();
        }
        for (String repo : featuresRepositories.split(",")) {
            repo = repo.trim();
            if (!repo.isEmpty()) {
                featureURLs.add(repo);
            }
        }
        if (features == null) {
            features = new ArrayList<>();
        }
        for (String feature : featuresBoot.split(",")) {
            feature = feature.trim();
            if (!feature.isEmpty()) {
                features.add(feature);
            }
        }
    }
    Map<String, URL> textResources = getResources(textResourceLocation);
    Map<String, URL> binaryResources = getResources(binaryResourceLocations);
    InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts, featureURLs, features, address, textResources, binaryResources, profiles);
    getInstanceService().createInstance(instance, settings, verbose);
    return null;
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) Properties(org.apache.felix.utils.properties.Properties) File(java.io.File) URL(java.net.URL)

Example 5 with InstanceSettings

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

the class CreateCommandTest method testCreateCommandExecute.

public void testCreateCommandExecute() throws Exception {
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.replay(instanceService);
    CreateCommand cc = new CreateCommand();
    cc.setInstanceService(instanceService);
    cc.sshPort = 9941;
    cc.rmiRegistryPort = 1122;
    cc.rmiServerPort = 44444;
    cc.location = "top";
    cc.javaOpts = "foo";
    cc.features = new ArrayList<>(Arrays.asList("abc", "def"));
    cc.featureURLs = new ArrayList<>(Arrays.asList("http://something"));
    cc.instance = "myInstance";
    cc.verbose = true;
    // Create the features config file used
    System.setProperty("karaf.etc", "target/etc");
    File cfgFile = new File("target/etc/" + CreateCommand.FEATURES_SERVICE_CONFIG_FILE);
    cfgFile.getParentFile().mkdirs();
    cfgFile.createNewFile();
    // check precondition
    EasyMock.verify(instanceService);
    EasyMock.reset(instanceService);
    InstanceSettings expectedIS = new InstanceSettings(9941, 1122, 44444, "top", "foo", Collections.singletonList("http://something"), Arrays.asList("abc", "def"));
    EasyMock.expect(instanceService.createInstance("myInstance", expectedIS, true)).andReturn(null);
    EasyMock.replay(instanceService);
    cc.doExecute();
    EasyMock.verify(instanceService);
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) InstanceService(org.apache.karaf.instance.core.InstanceService) File(java.io.File)

Aggregations

InstanceSettings (org.apache.karaf.instance.core.InstanceSettings)14 File (java.io.File)5 Instance (org.apache.karaf.instance.core.Instance)5 InstanceService (org.apache.karaf.instance.core.InstanceService)4 Test (org.junit.Test)4 URL (java.net.URL)3 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 MBeanException (javax.management.MBeanException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 InstancesMBeanImpl (org.apache.karaf.instance.core.internal.InstancesMBeanImpl)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1