Search in sources :

Example 6 with DeploymentDescriptor

use of org.folio.okapi.bean.DeploymentDescriptor 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 7 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, String instId, Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut) {
    deployments.get(srvcId, instId, resGet -> {
        if (resGet.failed()) {
            fut.handle(new Failure<>(resGet.getType(), resGet.cause()));
        } else {
            DeploymentDescriptor md = resGet.result();
            String url = md.getUrl();
            // check that the node is alive, but only on non-url instances
            if (clusterManager != null && url == null && !clusterManager.getNodes().contains(md.getNodeId())) {
                fut.handle(new Failure<>(NOT_FOUND, "gone"));
                return;
            }
            fut.handle(new Success<>(md));
        }
    });
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor)

Example 8 with DeploymentDescriptor

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

the class DiscoveryManager method autoUndeploy.

public void autoUndeploy(ModuleDescriptor md, ProxyContext pc, Handler<ExtendedAsyncResult<Void>> fut) {
    logger.info("autoUndeploy " + md.getId());
    if (md.getId().startsWith(XOkapiHeaders.OKAPI_MODULE)) {
        fut.handle(new Success<>());
        return;
    }
    deployments.get(md.getId(), res -> {
        if (res.failed()) {
            fut.handle(new Failure<>(res.getType(), res.cause()));
        } else {
            List<DeploymentDescriptor> ddList = res.result();
            CompList<List<Void>> futures = new CompList<>(USER);
            for (DeploymentDescriptor dd : ddList) {
                if (dd.getNodeId() != null) {
                    Future<Void> f = Future.future();
                    callUndeploy(dd, pc, 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 9 with DeploymentDescriptor

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

the class InternalModule method createDeployment.

private void createDeployment(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final DeploymentDescriptor pmd = Json.decodeValue(body, DeploymentDescriptor.class);
        deploymentManager.deploy(pmd, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            final String s = Json.encodePrettily(res.result());
            location(pc, res.result().getInstId(), null, s, fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 10 with DeploymentDescriptor

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

the class BeanTest method testDeploymentDescriptor2.

@Test
public void testDeploymentDescriptor2() {
    int fail = 0;
    final String docSampleDeployment = "{" + LS + "  \"srvcId\" : \"sample-module-1\"," + LS + "  \"descriptor\" : {" + LS + "    \"exec\" : " + "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"," + LS + "    \"env\" : [ {" + LS + "      \"name\" : \"helloGreeting\"" + LS + "    } ]" + LS + "  }" + LS + "}";
    try {
        final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment, DeploymentDescriptor.class);
        String pretty = Json.encodePrettily(md);
        assertEquals(docSampleDeployment, pretty);
    } catch (DecodeException ex) {
        ex.printStackTrace();
        fail = 400;
    }
    assertEquals(0, fail);
}
Also used : DeploymentDescriptor(org.folio.okapi.bean.DeploymentDescriptor) DecodeException(io.vertx.core.json.DecodeException) Test(org.junit.Test)

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