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