Search in sources :

Example 1 with EnvEntry

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()));
                }
            });
        }
    });
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) ModuleHandle(org.folio.okapi.util.ModuleHandle) Success(org.folio.okapi.common.Success) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) EnvEntry(org.folio.okapi.bean.EnvEntry)

Example 2 with EnvEntry

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);
                }
            });
        }
    });
}
Also used : List(java.util.List) LinkedList(java.util.LinkedList) CompList(org.folio.okapi.util.CompList) CompList(org.folio.okapi.util.CompList) EnvEntry(org.folio.okapi.bean.EnvEntry)

Example 3 with EnvEntry

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);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Map(java.util.Map) EnvEntry(org.folio.okapi.bean.EnvEntry)

Example 4 with EnvEntry

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));
    }
}
Also used : DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure) EnvEntry(org.folio.okapi.bean.EnvEntry)

Example 5 with EnvEntry

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);
            }
        });
    }
}
Also used : EnvEntry(org.folio.okapi.bean.EnvEntry)

Aggregations

EnvEntry (org.folio.okapi.bean.EnvEntry)5 DecodeException (io.vertx.core.json.DecodeException)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)1 LaunchDescriptor (org.folio.okapi.bean.LaunchDescriptor)1 Failure (org.folio.okapi.common.Failure)1 Success (org.folio.okapi.common.Success)1 CompList (org.folio.okapi.util.CompList)1 ModuleHandle (org.folio.okapi.util.ModuleHandle)1