Package org.apache.karaf.admin

Examples of org.apache.karaf.admin.Instance


        EasyMock.verify(as);
        EasyMock.verify(inst);
    }

    public void testChangeOptions() throws Exception {
        Instance inst = EasyMock.createMock(Instance.class);
        inst.changeJavaOpts("new opts");
        EasyMock.expectLastCall();
        EasyMock.replay(inst);

        AdminService as = EasyMock.createMock(AdminService.class);
        EasyMock.expect(as.getInstance("test instance")).andReturn(inst);
View Full Code Here


    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

    protected 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

    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

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

        }

        InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts,
                parseStringList(featureURLs), parseStringList(features), new HashMap<String, URL>(), new HashMap<String, URL>(), address);

        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

        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

    public synchronized void renameInstance(String oldName, String newName) throws Exception {
        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

    public synchronized Instance cloneInstance(String name, String cloneName, InstanceSettings settings) throws Exception {
        if (instances.get(cloneName) != null) {
            throw new IllegalArgumentException("Instance " + cloneName + " already exists");
        }
        Instance instance = instances.get(name);
        if (instance == null) {
            throw new IllegalArgumentException("Instance " + name + " not found");
        }

        // define the clone instance location
        String cloneLocationPath = settings.getLocation() != null ? settings.getLocation() : cloneName;
        File cloneLocation = new File(cloneLocationPath);
        if (!cloneLocation.isAbsolute()) {
            cloneLocation = new File(storageLocation, cloneLocationPath);
        }
        // copy instance directory
        String locationPath = instance.getLocation();
        File location = new File(locationPath);
        copy(location, cloneLocation);
        // create the properties map including the instance name, location, ssh and rmi port numbers
        HashMap<String, String> props = new HashMap<String, String>();
        props.put(name, cloneName);
        props.put(locationPath, cloneLocationPath);
        if (settings.getSshPort() > 0)
            props.put(new Integer(instance.getSshPort()).toString(), new Integer(settings.getSshPort()).toString());
        if (settings.getRmiRegistryPort() > 0)
            props.put(new Integer(instance.getRmiRegistryPort()).toString(), new Integer(settings.getRmiRegistryPort()).toString());
        if (settings.getRmiServerPort() > 0)
            props.put(new Integer(instance.getRmiServerPort()).toString(), new Integer(settings.getRmiServerPort()).toString());
        // filtering clone files
        filterResource(cloneLocation, "etc/custom.properties", props);
        filterResource(cloneLocation, "etc/org.apache.karaf.management.cfg", props);
        filterResource(cloneLocation, "etc/org.apache.karaf.shell.cfg", props);
        filterResource(cloneLocation, "etc/org.ops4j.pax.logging.cfg", props);
        filterResource(cloneLocation, "etc/system.properties", props);
        filterResource(cloneLocation, "bin/karaf", props);
        filterResource(cloneLocation, "bin/start", props);
        filterResource(cloneLocation, "bin/stop", props);
        filterResource(cloneLocation, "bin/karaf.bat", props);
        filterResource(cloneLocation, "bin/start.bat", props);
        filterResource(cloneLocation, "bin/stop.bat", props);
        // create and add the clone instance in the registry
        String javaOpts = settings.getJavaOpts();
        if (javaOpts == null || javaOpts.length() == 0) {
            javaOpts = "-server -Xmx512M -Dcom.sun.management.jmxremote";
        }
        Instance cloneInstance = new InstanceImpl(this, cloneName, cloneLocation.toString(), settings.getJavaOpts());
        instances.put(cloneName, cloneInstance);
        saveState();
        return cloneInstance;
    }
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

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.