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);
}
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);
});
});
}
Aggregations