Search in sources :

Example 6 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 7 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 8 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 9 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 10 with InstanceSettings

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

the class InstanceServiceImplTest method testHandleFeatures.

@Test
public void testHandleFeatures() throws Exception {
    InstanceServiceImpl as = new InstanceServiceImpl();
    File f = tempFolder.newFile(getName() + ".test");
    Properties p = new Properties();
    p.put("featuresBoot", "abc,def ");
    p.put("featuresRepositories", "somescheme://xyz");
    try (OutputStream os = new FileOutputStream(f)) {
        p.store(os, "Test comment");
    }
    InstanceSettings s = new InstanceSettings(8122, 1122, 44444, null, null, null, Arrays.asList("test"));
    as.addFeaturesFromSettings(f, s);
    Properties p2 = new Properties();
    try (InputStream is = new FileInputStream(f)) {
        p2.load(is);
    }
    assertEquals(2, p2.size());
    assertEquals("abc,def,test", p2.get("featuresBoot"));
    assertEquals("somescheme://xyz", p2.get("featuresRepositories"));
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

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