use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.
the class JMXBundleDeployer method newFromData.
private static BundleDTO newFromData(CompositeData cd) {
final BundleDTO dto = new BundleDTO();
dto.id = Long.parseLong(cd.get("Identifier").toString());
dto.symbolicName = cd.get("SymbolicName").toString();
String state = cd.get("State").toString();
if ("UNINSTALLED".equals(state)) {
dto.state = Bundle.UNINSTALLED;
} else if ("INSTALLED".equals(state)) {
dto.state = Bundle.INSTALLED;
} else if ("RESOLVED".equals(state)) {
dto.state = Bundle.RESOLVED;
} else if ("STARTING".equals(state)) {
dto.state = Bundle.STARTING;
} else if ("STOPPING".equals(state)) {
dto.state = Bundle.STOPPING;
} else if ("ACTIVE".equals(state)) {
dto.state = Bundle.ACTIVE;
}
dto.version = cd.get("Version").toString();
return dto;
}
use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.
the class JMXBundleDeployer method deploy.
/**
* Gets the current list of installed bsns, compares it to the bsn provided.
* If bsn doesn't exist, then install it. If it does exist then update it.
*
* @param bsn Bundle-SymbolicName of bundle you are wanting to deploy
* @param bundle the bundle
* @return the id of the updated or installed bundle
* @throws Exception
*/
public long deploy(String bsn, File bundle) throws Exception {
final ObjectName framework = getFramework(mBeanServerConnection);
long bundleId = -1;
for (BundleDTO osgiBundle : listBundles()) {
if (osgiBundle.symbolicName.equals(bsn)) {
bundleId = osgiBundle.id;
break;
}
}
if (bundleId > -1) {
mBeanServerConnection.invoke(framework, "stopBundle", new Object[] { bundleId }, new String[] { "long" });
mBeanServerConnection.invoke(framework, "updateBundleFromURL", new Object[] { bundleId, bundle.toURI().toURL().toExternalForm() }, new String[] { "long", String.class.getName() });
mBeanServerConnection.invoke(framework, "refreshBundle", new Object[] { bundleId }, new String[] { "long" });
} else {
Object installed = mBeanServerConnection.invoke(framework, "installBundleFromURL", new Object[] { bundle.getAbsolutePath(), bundle.toURI().toURL().toExternalForm() }, new String[] { String.class.getName(), String.class.getName() });
bundleId = Long.parseLong(installed.toString());
}
mBeanServerConnection.invoke(framework, "startBundle", new Object[] { bundleId }, new String[] { "long" });
return bundleId;
}
use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.
the class RemoteJMXTest method testJMXBundleDeployer.
public void testJMXBundleDeployer() throws Exception {
JMXBundleDeployer jmxBundleDeployer = new JMXBundleDeployer();
long bundleId = jmxBundleDeployer.deploy("biz.aQute.remote.agent", IO.getFile("generated/biz.aQute.remote.agent.jar"));
assertTrue(bundleId > 0);
BundleDTO agentBundle = null;
long state = -1;
for (BundleDTO bundle : jmxBundleDeployer.listBundles()) {
if (bundle.symbolicName.equals("biz.aQute.remote.agent")) {
agentBundle = bundle;
state = bundle.state;
}
}
assertNotNull(agentBundle);
assertEquals(Bundle.ACTIVE, state);
}
use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.
the class RemoteTest method testSimple.
public void testSimple() throws Exception {
LauncherSupervisor supervisor = new LauncherSupervisor();
supervisor.connect("localhost", Agent.DEFAULT_PORT);
assertNotNull(supervisor);
Agent agent = supervisor.getAgent();
assertNotNull(agent.getFramework());
// Create stdin/stderr buffers
// and redirect output
StringBuffer stderr = new StringBuffer();
StringBuffer stdout = new StringBuffer();
supervisor.setStderr(stderr);
supervisor.setStdout(stdout);
supervisor.redirect(1);
//
// Install the bundle systemio
//
File f = IO.getFile("generated/biz.aQute.remote.test.systemio.jar");
String sha = supervisor.addFile(f);
BundleDTO bundle = agent.install(f.getAbsolutePath(), sha);
//
// Start the bundle and capture the output
//
String result = agent.start(bundle.id);
assertNull(result, result);
Thread.sleep(1000);
assertEquals("Hello World", stdout.toString().trim());
stdout.setLength(0);
// Send input (will be consumed by the Activator.stop
ByteArrayInputStream bin = new ByteArrayInputStream(new String("Input\n").getBytes());
supervisor.setStdin(bin);
// stop the bundle (will return input as uppercase)
result = agent.stop(bundle.id);
assertNull(result, result);
Thread.sleep(1000);
assertEquals("INPUT", stdout.toString().trim());
}
use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.
the class AgentTest method testAgentUpdateBundleFromURL.
public void testAgentUpdateBundleFromURL() throws Exception {
BundleDTO t2Bundle = supervisor.getAgent().getBundles(2).get(0);
assertEquals("bsn-2", t2Bundle.symbolicName);
assertEquals("2.0.0", t2Bundle.version);
long previousModified = t2Bundle.lastModified;
File t2prime = create("bsn-2", new Version(2, 0, 1));
assertNull(supervisor.getAgent().updateFromURL(t2Bundle.id, t2prime.toURI().toURL().toExternalForm()));
t2Bundle = supervisor.getAgent().getBundles(2).get(0);
assertTrue(previousModified != t2Bundle.lastModified);
}
Aggregations