Search in sources :

Example 16 with Tenant

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

the class TenantStorePostgres method updateDescriptor.

@Override
public void updateDescriptor(TenantDescriptor td, Handler<ExtendedAsyncResult<Void>> fut) {
    Tenant t = new Tenant(td);
    pgTable.update(t, fut);
}
Also used : Tenant(org.folio.okapi.bean.Tenant)

Example 17 with Tenant

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

the class MainVerticle method checkSuperTenant.

/**
 * Create the super tenant, if not already there.
 *
 * @param fut
 */
private void checkSuperTenant(String okapiModule, Future<Void> fut) {
    tenantManager.get(XOkapiHeaders.SUPERTENANT_ID, gres -> {
        if (gres.succeeded()) {
            // we already have one, go on
            logger.info("checkSuperTenant: Already have " + XOkapiHeaders.SUPERTENANT_ID);
            Tenant st = gres.result();
            Set<String> enabledMods = st.getEnabled().keySet();
            if (enabledMods.contains(okapiModule)) {
                logger.info("checkSuperTenant: enabled version is OK");
                startEnv(fut);
                return;
            }
            // Check version compatibility
            String enver = "";
            for (String emod : enabledMods) {
                if (emod.startsWith("okapi-")) {
                    enver = emod;
                }
            }
            final String ev = enver;
            logger.debug("checkSuperTenant: Enabled version is '" + ev + "', not '" + okapiModule + "'");
            // See Okapi-359 about version checks across the cluster
            if (ModuleId.compare(ev, okapiModule) > 0) {
                logger.warn("checkSuperTenant: This Okapi is too old, " + okapiVersion + " we already have " + ev + " in the database. " + " Use that!");
            } else {
                logger.info("checkSuperTenant: Need to upgrade the stored version");
                // Use the commit, easier interface.
                // the internal module can not have dependencies
                // See Okapi-359 about version checks across the cluster
                tenantManager.updateModuleCommit(XOkapiHeaders.SUPERTENANT_ID, ev, okapiModule, ures -> {
                    if (ures.failed()) {
                        logger.debug("checkSuperTenant: " + "Updating enabled internalModule failed: " + ures.cause());
                        fut.fail(ures.cause());
                        return;
                    }
                    logger.info("Upgraded the InternalModule version" + " from '" + ev + "' to '" + okapiModule + "'" + " for " + XOkapiHeaders.SUPERTENANT_ID);
                });
            }
            startEnv(fut);
            return;
        }
        if (gres.getType() != NOT_FOUND) {
            logger.warn("checkSuperTenant: Could not get " + XOkapiHeaders.SUPERTENANT_ID + ": " + gres.cause());
            // something went badly wrong
            fut.fail(gres.cause());
            return;
        }
        logger.info("Creating the superTenant " + XOkapiHeaders.SUPERTENANT_ID);
        final String docTenant = "{" + "\"descriptor\" : {" + " \"id\" : \"" + XOkapiHeaders.SUPERTENANT_ID + "\"," + " \"name\" : \"" + XOkapiHeaders.SUPERTENANT_ID + "\"," + " \"description\" : \"Okapi built-in super tenant\"" + " }," + "\"enabled\" : {" + "\"" + okapiModule + "\" : true" + "}" + "}";
        final Tenant ten = Json.decodeValue(docTenant, Tenant.class);
        tenantManager.insert(ten, ires -> {
            if (ires.failed()) {
                logger.warn("Failed to create the superTenant " + XOkapiHeaders.SUPERTENANT_ID + " " + ires.cause());
                // something went badly wrong
                fut.fail(ires.cause());
                return;
            }
            startEnv(fut);
        });
    });
}
Also used : Tenant(org.folio.okapi.bean.Tenant)

Aggregations

Tenant (org.folio.okapi.bean.Tenant)17 JsonObject (io.vertx.core.json.JsonObject)3 ModuleDescriptor (org.folio.okapi.bean.ModuleDescriptor)3 TenantDescriptor (org.folio.okapi.bean.TenantDescriptor)3 TenantModuleDescriptor (org.folio.okapi.bean.TenantModuleDescriptor)3 DecodeException (io.vertx.core.json.DecodeException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Failure (org.folio.okapi.common.Failure)2 Buffer (io.vertx.core.buffer.Buffer)1 JsonArray (io.vertx.core.json.JsonArray)1 HashMap (java.util.HashMap)1 List (java.util.List)1 InterfaceDescriptor (org.folio.okapi.bean.InterfaceDescriptor)1 ModuleInstance (org.folio.okapi.bean.ModuleInstance)1 PermissionList (org.folio.okapi.bean.PermissionList)1 CompList (org.folio.okapi.util.CompList)1 ProxyContext (org.folio.okapi.util.ProxyContext)1