use of org.folio.okapi.bean.EnvEntry 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.bean.EnvEntry in project okapi by folio-org.
the class EnvManager method init.
public void init(Vertx vertx, Handler<ExtendedAsyncResult<Void>> fut) {
logger.debug("starting EnvManager");
envMap.init(vertx, "env", res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
} else {
envStore.getAll(res2 -> {
if (res2.failed()) {
fut.handle(new Failure<>(res2.getType(), res2.cause()));
} else {
CompList<List<Void>> futures = new CompList<>(INTERNAL);
for (EnvEntry e : res2.result()) {
Future<Void> f = Future.future();
add1(e, f::handle);
futures.add(f);
}
futures.all(fut);
}
});
}
});
}
use of org.folio.okapi.bean.EnvEntry in project okapi by folio-org.
the class DockerModuleHandle method createContainer.
private void createContainer(int exposedPort, Handler<AsyncResult<Void>> future) {
logger.info("create container from image " + image);
JsonObject j = new JsonObject();
j.put("AttachStdin", Boolean.FALSE);
j.put("AttachStdout", Boolean.TRUE);
j.put("AttachStderr", Boolean.TRUE);
j.put("StopSignal", "SIGTERM");
if (env != null) {
JsonArray a = new JsonArray();
for (EnvEntry nv : env) {
a.add(nv.getName() + "=" + nv.getValue());
}
j.put("env", a);
}
j.put("Image", image);
JsonObject hp = new JsonObject().put("HostPort", Integer.toString(hostPort));
JsonArray ep = new JsonArray().add(hp);
JsonObject pb = new JsonObject();
pb.put(Integer.toString(exposedPort) + "/tcp", ep);
JsonObject hc = new JsonObject();
hc.put("PortBindings", pb);
hc.put("PublishAllPorts", Boolean.FALSE);
j.put("HostConfig", hc);
if (this.cmd != null && this.cmd.length > 0) {
JsonArray a = new JsonArray();
for (String aCmd : cmd) {
a.add(aCmd);
}
j.put("Cmd", a);
}
if (dockerArgs != null) {
for (Map.Entry<String, Object> entry : dockerArgs.properties().entrySet()) {
j.put(entry.getKey(), entry.getValue());
}
}
String doc = j.encodePrettily();
doc = doc.replace("%p", Integer.toString(hostPort));
logger.info("createContainer\n" + doc);
postUrlBody(dockerUrl + "/containers/create", doc, future);
}
use of org.folio.okapi.bean.EnvEntry in project okapi by folio-org.
the class InternalModule method createEnv.
private void createEnv(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
try {
final EnvEntry pmd = Json.decodeValue(body, EnvEntry.class);
envManager.add(pmd, res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
return;
}
final String js = Json.encodePrettily(pmd);
location(pc, pmd.getName(), null, js, fut);
});
} catch (DecodeException ex) {
fut.handle(new Failure<>(USER, ex));
}
}
use of org.folio.okapi.bean.EnvEntry in project okapi by folio-org.
the class EnvManager method getR.
private void getR(Iterator<String> it, List<EnvEntry> all, Handler<ExtendedAsyncResult<List<EnvEntry>>> fut) {
if (!it.hasNext()) {
fut.handle(new Success<>(all));
} else {
String srvcId = it.next();
get(srvcId, resGet -> {
if (resGet.failed()) {
fut.handle(new Failure<>(resGet.getType(), resGet.cause()));
} else {
EnvEntry dpl = resGet.result();
all.add(dpl);
getR(it, all, fut);
}
});
}
}
Aggregations