Search in sources :

Example 16 with DeploymentDescriptor

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

the class DeploymentManager method shutdownR.

private void shutdownR(Iterator<String> it, int count, Handler<ExtendedAsyncResult<Void>> fut) {
    if (!it.hasNext()) {
        if (count != 0) {
            logger.info("All " + count + " modules shut down");
        }
        fut.handle(new Success<>());
    } else {
        DeploymentDescriptor md = list.get(it.next());
        ModuleHandle mh = md.getModuleHandle();
        logger.debug("Shutting down " + md.getSrvcId());
        mh.stop(future -> shutdownR(it, count + 1, fut));
    }
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) ModuleHandle(org.folio.okapi.util.ModuleHandle)

Example 17 with DeploymentDescriptor

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

the class DiscoveryManager method healthList.

private void healthList(List<DeploymentDescriptor> list, Handler<ExtendedAsyncResult<List<HealthDescriptor>>> fut) {
    List<HealthDescriptor> all = new LinkedList<>();
    CompList<List<HealthDescriptor>> futures = new CompList<>(INTERNAL);
    for (DeploymentDescriptor md : list) {
        Future<HealthDescriptor> f = Future.future();
        health(md, res -> {
            if (res.succeeded()) {
                all.add(res.result());
            }
            f.handle(res);
        });
        futures.add(f);
    }
    futures.all(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) HealthDescriptor(org.folio.okapi.bean.HealthDescriptor) LinkedList(java.util.LinkedList)

Example 18 with DeploymentDescriptor

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

the class DiscoveryManager method restartModules.

public void restartModules(Handler<ExtendedAsyncResult<Void>> fut) {
    deploymentStore.getAll(res1 -> {
        if (res1.failed()) {
            fut.handle(new Failure<>(res1.getType(), res1.cause()));
        } else {
            CompList<List<Void>> futures = new CompList<>(INTERNAL);
            for (DeploymentDescriptor dd : res1.result()) {
                Future<DeploymentDescriptor> f = Future.future();
                addAndDeploy1(dd, null, f::handle);
                futures.add(f);
            }
            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)

Example 19 with DeploymentDescriptor

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

the class DiscoveryManager method get.

public void get(String srvcId, Handler<ExtendedAsyncResult<List<DeploymentDescriptor>>> fut) {
    deployments.get(srvcId, res -> {
        if (res.failed()) {
            fut.handle(new Failure<>(res.getType(), res.cause()));
        } else {
            List<DeploymentDescriptor> result = res.result();
            Iterator<DeploymentDescriptor> it = result.iterator();
            while (it.hasNext()) {
                DeploymentDescriptor md = it.next();
                String url = md.getUrl();
                // but not those that have an explicit URL
                if (clusterManager != null && url == null && !clusterManager.getNodes().contains(md.getNodeId())) {
                    it.remove();
                }
            }
            fut.handle(new Success<>(result));
        }
    });
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor)

Example 20 with DeploymentDescriptor

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

the class DiscoveryManager method callDeploy.

/**
 * Helper to actually launch (deploy) a module on a node.
 */
private void callDeploy(String nodeId, ProxyContext pc, DeploymentDescriptor dd, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut) {
    logger.debug("callDeploy starting for " + Json.encode(dd));
    getNode(nodeId, noderes -> {
        if (noderes.failed()) {
            fut.handle(new Failure<>(noderes.getType(), noderes.cause()));
        } else {
            Map<String, String> headers = new HashMap<>();
            if (pc != null) {
                for (String s : pc.getCtx().request().headers().names()) {
                    if (s.startsWith("X-") || s.startsWith("x-")) {
                        final String v = pc.getCtx().request().headers().get(s);
                        headers.put(s, v);
                    }
                }
            }
            OkapiClient ok = new OkapiClient(noderes.result().getUrl(), vertx, headers);
            String reqdata = Json.encode(dd);
            ok.post("/_/deployment/modules", reqdata, okres -> {
                ok.close();
                if (okres.failed()) {
                    fut.handle(new Failure<>(okres.getType(), okres.cause().getMessage()));
                } else {
                    DeploymentDescriptor pmd = Json.decodeValue(okres.result(), DeploymentDescriptor.class);
                    fut.handle(new Success<>(pmd));
                }
            });
        }
    });
}
Also used : OkapiClient(org.folio.okapi.common.OkapiClient) HashMap(java.util.HashMap) DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor)

Aggregations

DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)20 DecodeException (io.vertx.core.json.DecodeException)6 Test (org.junit.Test)6 LinkedList (java.util.LinkedList)4 List (java.util.List)4 LaunchDescriptor (org.folio.okapi.bean.LaunchDescriptor)4 CompList (org.folio.okapi.util.CompList)4 ModuleHandle (org.folio.okapi.util.ModuleHandle)3 HashMap (java.util.HashMap)2 Failure (org.folio.okapi.common.Failure)2 OkapiClient (org.folio.okapi.common.OkapiClient)2 Timer (com.codahale.metrics.Timer)1 HttpMethod (io.vertx.core.http.HttpMethod)1 LinkedHashMap (java.util.LinkedHashMap)1 EnvEntry (org.folio.okapi.bean.EnvEntry)1 HealthDescriptor (org.folio.okapi.bean.HealthDescriptor)1 ModuleInstance (org.folio.okapi.bean.ModuleInstance)1 RoutingEntry (org.folio.okapi.bean.RoutingEntry)1 Success (org.folio.okapi.common.Success)1