Package org.apache.karaf.instance.core

Examples of org.apache.karaf.instance.core.Instance


            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");
        }

        logInfo("Renaming instance %s to %s", printOutput, oldName, newName);
       
        // 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


            LOGGER.warn("Unable to reload Karaf instance list", e);
        }
        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");
        }

        logInfo("Cloning instance %s into %s", printOutput, name, cloneName);
       
        // 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

        return false;
    }

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

        return false;
    }

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

        return false;
    }

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

    public void testCreateInstance() throws Exception {
        final InstanceSettings instanceSettings = new InstanceSettings(123, 456,789, "somewhere", "someopts",
                Collections.<String>emptyList(), Arrays.asList("webconsole", "funfeat"), "localhost");
       
        final Instance inst = EasyMock.createMock(Instance.class);
        EasyMock.expect(inst.getPid()).andReturn(42);
        EasyMock.replay(inst);

        org.apache.karaf.instance.core.InstanceService instanceService = EasyMock.createMock(org.apache.karaf.instance.core.InstanceService.class);
        EasyMock.expect(instanceService.createInstance("t1", instanceSettings, false)).andReturn(inst);
        EasyMock.replay(instanceService);
View Full Code Here

        InstancesMBean ab = new InstancesMBeanImpl(instanceService);
        assertEquals(-1, ab.createInstance("t1", 0, 0, 0, "", "", "", ""));
    }
   
    public void testGetInstances() throws Exception {      
        Instance i1 = EasyMock.createMock(Instance.class);
        EasyMock.expect(i1.getPid()).andReturn(1234);
        EasyMock.expect(i1.getSshPort()).andReturn(8818);
        EasyMock.expect(i1.getRmiRegistryPort()).andReturn(1122);
        EasyMock.expect(i1.getRmiServerPort()).andReturn(44444);
        EasyMock.expect(i1.getName()).andReturn("i1");
        EasyMock.expect(i1.isRoot()).andReturn(true);
        EasyMock.expect(i1.getLocation()).andReturn("somewhere");
        EasyMock.expect(i1.getJavaOpts()).andReturn("someopts");
        EasyMock.expect(i1.getState()).andReturn("Stopped");
        EasyMock.replay(i1);
        Instance i2 = EasyMock.createNiceMock(Instance.class);
        EasyMock.expect(i2.getName()).andReturn("i2");
        EasyMock.replay(i2);
       
        InstanceService instanceService = EasyMock.createMock(InstanceService.class);
        EasyMock.expect(instanceService.getInstances()).andReturn(new Instance[]{i1, i2});
        EasyMock.replay(instanceService);
View Full Code Here

        CompositeData cd2 = tabularData.get(new Object [] {"i2"});
        Assert.assertTrue(cd2.containsValue("i2"));
    }
   
    public void testStartInstanceWithJavaOpts() throws Exception {
        Instance inst = EasyMock.createMock(Instance.class);
        inst.start("-x -y -z");
        EasyMock.expectLastCall();
        EasyMock.replay(inst);

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

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

    public void testStartInstanceWithNoJavaOpts() throws Exception {
        Instance inst = EasyMock.createMock(Instance.class);
        inst.start(null);
        EasyMock.expectLastCall();
        EasyMock.replay(inst);

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

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

    public void testStopInstance() throws Exception {
        Instance inst = EasyMock.createMock(Instance.class);
        inst.stop();
        EasyMock.expectLastCall();
        EasyMock.replay(inst);

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

TOP

Related Classes of org.apache.karaf.instance.core.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.