Search in sources :

Example 1 with Success

use of org.folio.okapi.common.Success 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 Success

use of org.folio.okapi.common.Success in project okapi by folio-org.

the class MongoUtil method delete.

public void delete(String id, Handler<ExtendedAsyncResult<Void>> fut) {
    JsonObject jq = new JsonObject().put("_id", id);
    cli.removeDocument(collection, jq, rres -> {
        if (rres.failed()) {
            fut.handle(new Failure<>(INTERNAL, rres.cause()));
        } else if (rres.result().getRemovedCount() == 0) {
            fut.handle(new Failure<>(NOT_FOUND, id));
        } else {
            fut.handle(new Success<>());
        }
    });
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Failure(org.folio.okapi.common.Failure) Success(org.folio.okapi.common.Success)

Aggregations

Success (org.folio.okapi.common.Success)2 JsonObject (io.vertx.core.json.JsonObject)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)1 EnvEntry (org.folio.okapi.bean.EnvEntry)1 LaunchDescriptor (org.folio.okapi.bean.LaunchDescriptor)1 Failure (org.folio.okapi.common.Failure)1 ModuleHandle (org.folio.okapi.util.ModuleHandle)1