Package org.apache.karaf.admin

Examples of org.apache.karaf.admin.Instance


        String javaOpts = settings.getJavaOpts();
        if (javaOpts == null || javaOpts.length() == 0) {
            javaOpts = "-server -Xmx512M -Dcom.sun.management.jmxremote";
        }
        Instance instance = new InstanceImpl(this, name, karafBase.toString(), settings.getJavaOpts());
        instances.put(name, instance);
        saveState();
        return instance;
    }
View Full Code Here


            LOGGER.warn("Unable to reload Karaf instance list", e);
        }
        if (instances.get(newName) != null) {
            throw new IllegalArgumentException("Instance " + newName + " already exists");
        }
        Instance instance = instances.get(oldName);
        if (instance == null) {
            throw new IllegalArgumentException("Instance " + oldName + " not found");
        }
        if (instance.isRoot()) {
            throw new IllegalArgumentException("Root instance cannot be renamed");
        }
        if (instance.getPid() != 0) {
            throw new IllegalStateException("Instance not stopped");
        }

        println(Ansi.ansi().a("Renaming instance ")
                .a(Ansi.Attribute.INTENSITY_BOLD).a(oldName).a(Ansi.Attribute.RESET)
                .a(" to ")
                .a(Ansi.Attribute.INTENSITY_BOLD).a(newName).a(Ansi.Attribute.RESET).toString());
        // remove the old instance
        instances.remove(oldName);
        // update instance
        instance.setName(newName);
        // rename directory
        String oldLocationPath = instance.getLocation();
        File oldLocation = new File(oldLocationPath);
        String basedir = oldLocation.getParent();
        File newLocation = new File(basedir, newName);
        oldLocation.renameTo(newLocation);
        // update the instance location
        instance.setLocation(newLocation.getPath());
        // create the properties map including the instance name and instance location
        HashMap<String, String> props = new HashMap<String, String>();
        props.put(oldName, newName);
        props.put(oldLocationPath, newLocation.getPath());
        // replace all references to the "old" name by the new one in etc/system.properties
View Full Code Here

        }

        InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts,
                parseStringList(featureURLs), parseStringList(features));

        Instance inst = adminService.createInstance(name, settings);
        if (inst != null) {
            return inst.getPid();
        } else {
            return -1;
        }
    }
View Full Code Here

    public void startInstance(String name, String opts) throws Exception {
        getExistingInstance(name).start(opts);
    }

    public void startInstance(String name, String opts, boolean wait) throws Exception {
        Instance child = getExistingInstance(name);
        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);
        }
    }
View Full Code Here

        TabularData table = JmxInstance.tableFrom(instances);
        return table;
    }

    private Instance getExistingInstance(String name) {
        Instance i = adminService.getInstance(name);
        if (i == null) {
            throw new IllegalArgumentException("Instance '" + name + "' does not exist");
        }
        return i;
    }
View Full Code Here

        return false;
    }

    private boolean destroyInstance(String name) {
        try {
            Instance instance = adminService.getInstance(name);
            if (instance != null) {
                instance.destroy();
                return true;
            }
        } catch (Exception ex) {
            Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
View Full Code Here

        return false;
    }

    private boolean startInstance(String name, String javaOpts) {
        try {
            Instance instance = adminService.getInstance(name);
            if (instance != null) {
                instance.start(javaOpts);
                return true;
            }
        } catch (Exception ex) {
            Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
View Full Code Here

        return false;
    }

    private boolean stopInstance(String name) {
        try {
            Instance instance = adminService.getInstance(name);
            if (instance != null) {
                instance.stop();
                return true;
            }
        } catch (Exception ex) {
            Logger.getLogger(AdminPlugin.class.getName()).log(Level.SEVERE, null, ex);
        }
View Full Code Here

    public void testConfigurationFiles() throws Exception {
        AdminServiceImpl service = new AdminServiceImpl();
        service.setStorageLocation(new File("target/instances/" + System.currentTimeMillis()));

        InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null, null, null);
        Instance instance = service.createInstance(getName(), settings);

        assertFileExists(instance.getLocation(), "etc/config.properties");
        assertFileExists(instance.getLocation(), "etc/users.properties");
        assertFileExists(instance.getLocation(), "etc/startup.properties");

        assertFileExists(instance.getLocation(), "etc/java.util.logging.properties");
        assertFileExists(instance.getLocation(), "etc/org.apache.karaf.features.cfg");
        assertFileExists(instance.getLocation(), "etc/org.apache.felix.fileinstall-deploy.cfg");
        assertFileExists(instance.getLocation(), "etc/org.apache.karaf.log.cfg");
        assertFileExists(instance.getLocation(), "etc/org.apache.karaf.management.cfg");
        assertFileExists(instance.getLocation(), "etc/org.ops4j.pax.logging.cfg");
        assertFileExists(instance.getLocation(), "etc/org.ops4j.pax.url.mvn.cfg");
    }
View Full Code Here

        service.setStorageLocation(new File("target/instances/" + System.currentTimeMillis()));
        Map<String, URL> textResources = new HashMap<String, URL>();
        textResources.put("etc/myresource", getClass().getClassLoader().getResource("myresource"));

        InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null, null, null, textResources, new HashMap<String, URL>());
        Instance instance = service.createInstance(getName(), settings);

        assertFileExists(instance.getLocation(), "etc/myresource");
    }
View Full Code Here

TOP

Related Classes of org.apache.karaf.admin.Instance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.