Search in sources :

Example 11 with InstanceSettings

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

the class InstanceServiceImplTest method testToSimulateRenameInstanceByExternalProcess.

/**
     * <p>
     * Test the renaming of an existing instance.
     * </p>
     */
@Test
public void testToSimulateRenameInstanceByExternalProcess() throws Exception {
    InstanceServiceImpl service = new InstanceServiceImpl();
    File storageLocation = tempFolder.newFolder("instances");
    service.setStorageLocation(storageLocation);
    InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null, null, null);
    service.createInstance(getName(), settings, true);
    //to simulate the scenario that the instance name get changed by 
    //external process, likely the admin command CLI tool, which cause
    //the instance storage file get updated, the AdminService should be 
    //able to reload the storage file before check any status for the 
    //instance
    File storageFile = new File(storageLocation, InstanceServiceImpl.STORAGE_FILE);
    assertTrue(storageFile.isFile());
    Properties storage = loadStorage(storageFile);
    storage.setProperty("item.0.name", getName() + "b");
    saveStorage(storage, storageFile, "testToSimulateRenameInstanceByExternalProcess");
    assertNotNull(service.getInstance(getName() + "b"));
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 12 with InstanceSettings

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

the class InstanceServiceImplTest method testRenameInstance.

/**
     * <p>
     * Test the renaming of an existing instance.
     * </p>
     */
@Test
public void testRenameInstance() throws Exception {
    InstanceServiceImpl service = new InstanceServiceImpl();
    service.setStorageLocation(tempFolder.newFolder("instances"));
    InstanceSettings settings = new InstanceSettings(8122, 1122, 44444, getName(), null, null, null);
    service.createInstance(getName(), settings, true);
    service.renameInstance(getName(), getName() + "b", true);
    assertNotNull(service.getInstance(getName() + "b"));
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) Test(org.junit.Test)

Example 13 with InstanceSettings

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

the class InstanceServiceMBeanImplTest method testCreateInstance2.

public void testCreateInstance2() throws Exception {
    final InstanceSettings instanceSettings = new InstanceSettings(0, 0, 0, null, null, Collections.emptyList(), Collections.emptyList(), "localhost");
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.expect(instanceService.createInstance("t1", instanceSettings, false)).andReturn(null);
    EasyMock.replay(instanceService);
    InstancesMBean ab = new InstancesMBeanImpl(instanceService);
    assertEquals(-1, ab.createInstance("t1", 0, 0, 0, "", "", "", ""));
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl) InstancesMBean(org.apache.karaf.instance.core.InstancesMBean) InstanceService(org.apache.karaf.instance.core.InstanceService)

Example 14 with InstanceSettings

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

the class InstancePlugin method doPost.

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    boolean success = false;
    String action = req.getParameter("action");
    String name = req.getParameter("name");
    if (action == null) {
        success = true;
    } else if ("create".equals(action)) {
        int sshPort = parsePortNumber(req.getParameter("sshPort"));
        int rmiRegistryPort = parsePortNumber(req.getParameter("rmiRegistryPort"));
        int rmiServerPort = parsePortNumber(req.getParameter("rmiServerPort"));
        String location = parseString(req.getParameter("location"));
        String javaOpts = parseString(req.getParameter("javaOpts"));
        List<String> featureURLs = parseStringList(req.getParameter("featureURLs"));
        List<String> features = parseStringList(req.getParameter("features"));
        InstanceSettings settings = new InstanceSettings(sshPort, rmiRegistryPort, rmiServerPort, location, javaOpts, featureURLs, features);
        success = createInstance(name, settings);
    } else if ("destroy".equals(action)) {
        success = destroyInstance(name);
    } else if ("start".equals(action)) {
        String javaOpts = req.getParameter("javaOpts");
        success = startInstance(name, javaOpts);
    } else if ("stop".equals(action)) {
        success = stopInstance(name);
    }
    if (success) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        this.renderJSON(res, null);
    } else {
        super.doPost(req, res);
    }
}
Also used : InstanceSettings(org.apache.karaf.instance.core.InstanceSettings) ArrayList(java.util.ArrayList) List(java.util.List)

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