Search in sources :

Example 11 with Failure

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

the class InternalModule method upgradeModulesForTenant.

private void upgradeModulesForTenant(ProxyContext pc, String id, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        TenantInstallOptions options = createTenantOptions(pc.getCtx());
        tenantManager.installUpgradeModules(id, pc, options, null, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
            } else {
                logger.info("installUpgradeModules returns:\n" + Json.encodePrettily(res.result()));
                fut.handle(new Success<>(Json.encodePrettily(res.result())));
            }
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure) TenantInstallOptions(org.folio.okapi.util.TenantInstallOptions)

Example 12 with Failure

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

the class InternalModule method enableModuleForTenant.

private void enableModuleForTenant(ProxyContext pc, String id, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final TenantModuleDescriptor td = Json.decodeValue(body, TenantModuleDescriptor.class);
        String moduleTo = td.getId();
        tenantManager.enableAndDisableModule(id, null, moduleTo, pc, eres -> {
            if (eres.failed()) {
                fut.handle(new Failure<>(eres.getType(), eres.cause()));
                return;
            }
            td.setId(eres.result());
            location(pc, td.getId(), null, Json.encodePrettily(td), fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : TenantModuleDescriptor(org.folio.okapi.bean.TenantModuleDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Example 13 with Failure

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

the class InternalModule method createEnv.

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

Example 14 with Failure

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

the class InternalModule method discoveryDeploy.

private void discoveryDeploy(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final DeploymentDescriptor pmd = Json.decodeValue(body, DeploymentDescriptor.class);
        discoveryManager.addAndDeploy(pmd, pc, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            DeploymentDescriptor md = res.result();
            final String s = Json.encodePrettily(md);
            final String baseuri = pc.getCtx().request().uri() + "/" + md.getSrvcId();
            location(pc, md.getInstId(), baseuri, 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 15 with Failure

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

the class InternalModule method createTenant.

private void createTenant(ProxyContext pc, String body, Handler<ExtendedAsyncResult<String>> fut) {
    try {
        final TenantDescriptor td = Json.decodeValue(body, TenantDescriptor.class);
        if (td.getId() == null || td.getId().isEmpty()) {
            td.setId(UUID.randomUUID().toString());
        }
        final String id = td.getId();
        if (!id.matches("^[a-z0-9_-]+$")) {
            fut.handle(new Failure<>(USER, "Invalid tenant id '" + id + "'"));
            return;
        }
        Tenant t = new Tenant(td);
        tenantManager.insert(t, res -> {
            if (res.failed()) {
                fut.handle(new Failure<>(res.getType(), res.cause()));
                return;
            }
            location(pc, id, null, Json.encodePrettily(t.getDescriptor()), fut);
        });
    } catch (DecodeException ex) {
        fut.handle(new Failure<>(USER, ex));
    }
}
Also used : Tenant(org.folio.okapi.bean.Tenant) TenantDescriptor(org.folio.okapi.bean.TenantDescriptor) DecodeException(io.vertx.core.json.DecodeException) Failure(org.folio.okapi.common.Failure)

Aggregations

Failure (org.folio.okapi.common.Failure)18 DecodeException (io.vertx.core.json.DecodeException)13 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)6 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)6 Buffer (io.vertx.core.buffer.Buffer)4 HttpClientRequest (io.vertx.core.http.HttpClientRequest)4 DeploymentDescriptor (org.folio.okapi.bean.DeploymentDescriptor)4 Tenant (org.folio.okapi.bean.Tenant)4 JsonObject (io.vertx.core.json.JsonObject)3 ArrayList (java.util.ArrayList)3 Handler (io.vertx.core.Handler)2 MultiMap (io.vertx.core.MultiMap)2 Vertx (io.vertx.core.Vertx)2 HttpClient (io.vertx.core.http.HttpClient)2 HttpClientOptions (io.vertx.core.http.HttpClientOptions)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 HttpMethod (io.vertx.core.http.HttpMethod)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)2 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 Json (io.vertx.core.json.Json)2