use of org.folio.okapi.util.ModuleHandle in project okapi by folio-org.
the class DeploymentManager method undeploy.
public void undeploy(String id, Handler<ExtendedAsyncResult<Void>> fut) {
logger.info("undeploy instId " + id);
if (!list.containsKey(id)) {
fut.handle(new Failure<>(NOT_FOUND, "not found: " + id));
} else {
Timer.Context tim = DropwizardHelper.getTimerContext("deploy." + id + ".undeploy");
DeploymentDescriptor md = list.get(id);
dm.remove(md.getSrvcId(), md.getInstId(), res -> {
if (res.failed()) {
tim.close();
fut.handle(new Failure<>(res.getType(), res.cause()));
} else {
ModuleHandle mh = md.getModuleHandle();
mh.stop(future -> {
if (future.failed()) {
tim.close();
fut.handle(new Failure<>(INTERNAL, future.cause()));
} else {
fut.handle(new Success<>());
tim.close();
list.remove(id);
}
});
}
});
}
}
use of org.folio.okapi.util.ModuleHandle in project okapi by folio-org.
the class DeploymentManager method deploy2.
private void deploy2(Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut, Timer.Context tim, int usePort, DeploymentDescriptor md1, String url) {
LaunchDescriptor descriptor = md1.getDescriptor();
if (descriptor == null) {
ports.free(usePort);
fut.handle(new Failure<>(USER, "No LaunchDescriptor"));
tim.close();
return;
}
HashMap<String, EnvEntry> entries = new HashMap<>();
EnvEntry[] env = descriptor.getEnv();
if (env != null) {
for (EnvEntry e : env) {
entries.put(e.getName(), e);
}
}
em.get(eres -> {
if (eres.failed()) {
ports.free(usePort);
fut.handle(new Failure<>(INTERNAL, "get env: " + eres.cause().getMessage()));
tim.close();
} else {
for (EnvEntry er : eres.result()) {
entries.put(er.getName(), er);
}
if (entries.size() > 0) {
EnvEntry[] nenv = new EnvEntry[entries.size()];
int i = 0;
for (Entry<String, EnvEntry> key : entries.entrySet()) {
nenv[i++] = key.getValue();
}
descriptor.setEnv(nenv);
}
ModuleHandle mh = ModuleHandleFactory.create(vertx, descriptor, ports, usePort);
mh.start(future -> {
if (future.succeeded()) {
DeploymentDescriptor md2 = new DeploymentDescriptor(md1.getInstId(), md1.getSrvcId(), url, md1.getDescriptor(), mh);
md2.setNodeId(md1.getNodeId() != null ? md1.getNodeId() : host);
list.put(md2.getInstId(), md2);
tim.close();
dm.add(md2, res -> fut.handle(new Success<>(md2)));
} else {
tim.close();
ports.free(usePort);
logger.warn("Deploying " + md1.getSrvcId() + " failed");
fut.handle(new Failure<>(USER, future.cause()));
}
});
}
});
}
use of org.folio.okapi.util.ModuleHandle in project okapi by folio-org.
the class ProcessModuleHandleTest method test1.
@Test
public void test1(TestContext context) {
final Async async = context.async();
LaunchDescriptor desc = new LaunchDescriptor();
desc.setExec("java -version %p");
ModuleHandle mh = createModuleHandle(desc, 0);
mh.start(res -> {
if (!res.succeeded()) {
logger.error("CAUSE: " + res.cause());
}
context.assertTrue(res.succeeded());
if (!res.succeeded()) {
async.complete();
return;
}
mh.stop(res2 -> {
context.assertTrue(res2.succeeded());
async.complete();
});
});
}
use of org.folio.okapi.util.ModuleHandle in project okapi by folio-org.
the class ProcessModuleHandleTest method test3.
@Test
public void test3(TestContext context) {
final Async async = context.async();
LaunchDescriptor desc = new LaunchDescriptor();
desc.setExec("java -Dport=%p -jar unknown.jar");
ModuleHandle mh = createModuleHandle(desc, 9231);
mh.start(res -> {
context.assertFalse(res.succeeded());
async.complete();
});
}
use of org.folio.okapi.util.ModuleHandle in project okapi by folio-org.
the class ProcessModuleHandleTest method test4.
@Test
public void test4(TestContext context) {
final Async async = context.async();
LaunchDescriptor desc = new LaunchDescriptor();
desc.setExec("java -Dport=9000 -jar unknown.jar");
ModuleHandle mh = createModuleHandle(desc, 9231);
mh.start(res -> {
context.assertFalse(res.succeeded());
context.assertEquals("Can not deploy: No %p in the exec line", res.cause().getMessage());
async.complete();
});
}
Aggregations