Search in sources :

Example 1 with ModuleHandle

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);
                    }
                });
            }
        });
    }
}
Also used : Timer(com.codahale.metrics.Timer) DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) ModuleHandle(org.folio.okapi.util.ModuleHandle)

Example 2 with ModuleHandle

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()));
                }
            });
        }
    });
}
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 3 with ModuleHandle

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();
        });
    });
}
Also used : Async(io.vertx.ext.unit.Async) ProcessModuleHandle(org.folio.okapi.util.ProcessModuleHandle) ModuleHandle(org.folio.okapi.util.ModuleHandle) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Test(org.junit.Test)

Example 4 with ModuleHandle

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();
    });
}
Also used : Async(io.vertx.ext.unit.Async) ProcessModuleHandle(org.folio.okapi.util.ProcessModuleHandle) ModuleHandle(org.folio.okapi.util.ModuleHandle) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Test(org.junit.Test)

Example 5 with ModuleHandle

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();
    });
}
Also used : Async(io.vertx.ext.unit.Async) ProcessModuleHandle(org.folio.okapi.util.ProcessModuleHandle) ModuleHandle(org.folio.okapi.util.ModuleHandle) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Test(org.junit.Test)

Aggregations

ModuleHandle (org.folio.okapi.util.ModuleHandle)11 LaunchDescriptor (org.folio.okapi.bean.LaunchDescriptor)9 Async (io.vertx.ext.unit.Async)8 ProcessModuleHandle (org.folio.okapi.util.ProcessModuleHandle)8 Test (org.junit.Test)8 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)3 Timer (com.codahale.metrics.Timer)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 EnvEntry (org.folio.okapi.bean.EnvEntry)1 Success (org.folio.okapi.common.Success)1