Search in sources :

Example 1 with LaunchDescriptor

use of org.folio.okapi.bean.LaunchDescriptor in project okapi by folio-org.

the class DeploymentManagerTest method test2.

@Test
public void test2(TestContext context) {
    async = context.async();
    LaunchDescriptor descriptor = new LaunchDescriptor();
    descriptor.setExec("java -Dport=%p -jar " + "../okapi-test-module/target/unknown.jar");
    DeploymentDescriptor dd = new DeploymentDescriptor("2", "sid", descriptor);
    dm.deploy(dd, res -> {
        context.assertFalse(res.succeeded());
        async.complete();
    });
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor) Test(org.junit.Test)

Example 2 with LaunchDescriptor

use of org.folio.okapi.bean.LaunchDescriptor 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 LaunchDescriptor

use of org.folio.okapi.bean.LaunchDescriptor in project okapi by folio-org.

the class DiscoveryManager method autoDeploy2.

private void autoDeploy2(ModuleDescriptor md, ProxyContext pc, Collection<String> allNodes, List<DeploymentDescriptor> ddList, Handler<ExtendedAsyncResult<Void>> fut) {
    LaunchDescriptor modLaunchDesc = md.getLaunchDescriptor();
    CompList<List<Void>> futures = new CompList<>(USER);
    // deploy on all nodes for now
    for (String node : allNodes) {
        // check if we have deploy on node
        logger.info("autoDeploy " + md.getId() + " consider " + node);
        DeploymentDescriptor foundDd = null;
        for (DeploymentDescriptor dd : ddList) {
            if (dd.getNodeId() == null || node.equals(dd.getNodeId())) {
                foundDd = dd;
            }
        }
        if (foundDd == null) {
            logger.info("autoDeploy " + md.getId() + " must deploy on node " + node);
            DeploymentDescriptor dd = new DeploymentDescriptor();
            dd.setDescriptor(modLaunchDesc);
            dd.setSrvcId(md.getId());
            dd.setNodeId(node);
            Future<DeploymentDescriptor> f = Future.future();
            addAndDeploy(dd, pc, f::handle);
            futures.add(f);
        } else {
            logger.info("autoDeploy " + md.getId() + " already deployed on " + node);
        }
    }
    futures.all(fut);
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) LinkedList(java.util.LinkedList) List(java.util.List) CompList(org.folio.okapi.util.CompList) CompList(org.folio.okapi.util.CompList) LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor)

Example 4 with LaunchDescriptor

use of org.folio.okapi.bean.LaunchDescriptor in project okapi by folio-org.

the class DiscoveryManager method addAndDeploy1.

/**
 * Adds a service to the discovery, and optionally deploys it too.
 *
 *   1: We have LaunchDescriptor and NodeId: Deploy on that node.
 *   2: NodeId, but no LaunchDescriptor: Fetch the module, use its LaunchDescriptor, and deploy.
 *   3: No nodeId: Do not deploy at all, just record the existence (URL and instId) of the module.
 */
private void addAndDeploy1(DeploymentDescriptor dd, ProxyContext pc, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut) {
    logger.info("addAndDeploy: " + Json.encodePrettily(dd));
    if (dd.getSrvcId() == null) {
        fut.handle(new Failure<>(USER, "Needs srvcId"));
        return;
    }
    LaunchDescriptor launchDesc = dd.getDescriptor();
    final String nodeId = dd.getNodeId();
    if (nodeId == null) {
        if (launchDesc == null) {
            // 3: externally deployed
            if (dd.getInstId() == null) {
                fut.handle(new Failure<>(USER, "Needs instId"));
            } else {
                add(dd, res -> {
                    // just add it
                    if (res.failed()) {
                        fut.handle(new Failure<>(res.getType(), res.cause()));
                    } else {
                        fut.handle(new Success<>(dd));
                    }
                });
            }
        } else {
            fut.handle(new Failure<>(USER, "missing nodeId"));
        }
    } else {
        if (launchDesc == null) {
            logger.debug("addAndDeploy: case 2 for " + dd.getSrvcId());
            addAndDeploy2(dd, pc, fut, nodeId);
        } else {
            // Have a launchdesc already in dd
            logger.debug("addAndDeploy: case 1: We have a ld: " + Json.encode(dd));
            callDeploy(nodeId, pc, dd, fut);
        }
    }
}
Also used : LaunchDescriptor(org.folio.okapi.bean.LaunchDescriptor)

Example 5 with LaunchDescriptor

use of org.folio.okapi.bean.LaunchDescriptor 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)

Aggregations

LaunchDescriptor (org.folio.okapi.bean.LaunchDescriptor)14 Test (org.junit.Test)10 ModuleHandle (org.folio.okapi.util.ModuleHandle)9 Async (io.vertx.ext.unit.Async)8 ProcessModuleHandle (org.folio.okapi.util.ProcessModuleHandle)8 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)4 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 EnvEntry (org.folio.okapi.bean.EnvEntry)1 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)1 Success (org.folio.okapi.common.Success)1 CompList (org.folio.okapi.util.CompList)1