use of org.folio.okapi.bean.Tenant in project okapi by folio-org.
the class ProxyService method proxy.
public void proxy(RoutingContext ctx) {
ctx.request().pause();
ReadStream<Buffer> stream = ctx.request();
// Pause the request data stream before doing any slow ops, otherwise
// it will get read into a buffer somewhere.
ProxyContext pc = new ProxyContext(ctx);
// It would be nice to pass the request-id to the client, so it knows what
// to look for in Okapi logs. But that breaks the schemas, and RMB-based
// modules will not accept the response. Maybe later...
String tenantId = tenantHeader(pc);
if (tenantId == null) {
stream.resume();
// Error code already set in ctx
return;
}
sanitizeAuthHeaders(ctx.request().headers());
tenantManager.get(tenantId, gres -> {
if (gres.failed()) {
stream.resume();
pc.responseText(400, "No such Tenant " + tenantId);
return;
}
Tenant tenant = gres.result();
moduleManager.getEnabledModules(tenant, mres -> {
if (mres.failed()) {
stream.resume();
pc.responseError(mres.getType(), mres.cause());
return;
}
List<ModuleDescriptor> enabledModules = mres.result();
String metricKey = "proxy." + tenantId + "." + ctx.request().method() + "." + ctx.normalisedPath();
DropwizardHelper.markEvent(metricKey);
List<ModuleInstance> l = getModulesForRequest(pc, enabledModules);
if (l == null) {
stream.resume();
// ctx already set up
return;
}
pc.setModList(l);
pc.logRequest(ctx, tenantId);
ctx.request().headers().add(XOkapiHeaders.URL, okapiUrl);
ctx.request().headers().remove(XOkapiHeaders.MODULE_ID);
resolveUrls(l.iterator(), res -> {
if (res.failed()) {
stream.resume();
pc.responseError(res.getType(), res.cause());
} else {
proxyR(l.iterator(), pc, stream, null);
}
});
});
});
}
use of org.folio.okapi.bean.Tenant in project okapi by folio-org.
the class TenantManager method getModuleUserR.
private void getModuleUserR(String mod, Iterator<String> it, Handler<ExtendedAsyncResult<Void>> fut) {
if (!it.hasNext()) {
// no problems found
fut.handle(new Success<>());
} else {
String tid = it.next();
tenants.get(tid, gres -> {
if (gres.failed()) {
fut.handle(new Failure<>(gres.getType(), gres.cause()));
} else {
Tenant t = gres.result();
if (t.isEnabled(mod)) {
fut.handle(new Failure<>(ANY, tid));
} else {
getModuleUserR(mod, it, fut);
}
}
});
}
}
use of org.folio.okapi.bean.Tenant in project okapi by folio-org.
the class TenantManager method enableAndDisableModule.
/**
* Enable a module for a tenant and disable another. Checks dependencies,
* invokes the tenant interface, and the tenantPermissions interface, and
* finally marks the modules as enabled and disabled.
*
* @param tenantId - id of the the tenant in question
* @param moduleFrom id of the module to be disabled, or null
* @param moduleTo id of the module to be enabled, or null
* @param pc proxyContext for proper logging, etc
* @param fut callback with success, or various errors
*
* To avoid too much callback hell, this has been split into several helpers.
*/
public void enableAndDisableModule(String tenantId, String moduleFrom, String moduleTo, ProxyContext pc, Handler<ExtendedAsyncResult<String>> fut) {
tenants.get(tenantId, tres -> {
if (tres.failed()) {
fut.handle(new Failure<>(tres.getType(), tres.cause()));
} else {
Tenant tenant = tres.result();
enableAndDisableModule(tenant, moduleFrom, moduleTo, pc, fut);
}
});
}
use of org.folio.okapi.bean.Tenant in project okapi by folio-org.
the class TenantManager method updateDescriptor.
public void updateDescriptor(TenantDescriptor td, Handler<ExtendedAsyncResult<Void>> fut) {
final String id = td.getId();
tenants.get(id, gres -> {
if (gres.failed() && gres.getType() != NOT_FOUND) {
logger.warn("TenantManager: UpDesc: getting " + id + " FAILED: ", gres);
fut.handle(new Failure<>(INTERNAL, ""));
}
Tenant t;
if (gres.succeeded()) {
t = new Tenant(td, gres.result().getEnabled());
} else {
t = new Tenant(td);
}
if (tenantStore == null) {
// no database. handles success directly
tenants.add(id, t, fut);
} else {
tenantStore.updateDescriptor(td, upres -> {
if (upres.failed()) {
logger.warn("TenantManager: Updating database for " + id + " FAILED: ", upres);
fut.handle(new Failure<>(INTERNAL, ""));
} else {
// handles success
tenants.add(id, t, fut);
}
});
}
});
}
use of org.folio.okapi.bean.Tenant in project okapi by folio-org.
the class TenantManager method installUpgradeModules.
public void installUpgradeModules(String tenantId, ProxyContext pc, TenantInstallOptions options, List<TenantModuleDescriptor> tml, Handler<ExtendedAsyncResult<List<TenantModuleDescriptor>>> fut) {
tenants.get(tenantId, gres -> {
if (gres.failed()) {
fut.handle(new Failure<>(gres.getType(), gres.cause()));
return;
}
Tenant t = gres.result();
moduleManager.getModulesWithFilter(null, options.getPreRelease(), mres -> {
if (mres.failed()) {
fut.handle(new Failure<>(mres.getType(), mres.cause()));
return;
}
List<ModuleDescriptor> modResult = mres.result();
HashMap<String, ModuleDescriptor> modsAvailable = new HashMap<>(modResult.size());
HashMap<String, ModuleDescriptor> modsEnabled = new HashMap<>();
for (ModuleDescriptor md : modResult) {
modsAvailable.put(md.getId(), md);
logger.info("mod available: " + md.getId());
if (t.isEnabled(md.getId())) {
logger.info("mod enabled: " + md.getId());
modsEnabled.put(md.getId(), md);
}
}
List<TenantModuleDescriptor> tml2 = prepareTenantModuleList(modsAvailable, modsEnabled, tml);
installUpgradeModules2(t, pc, options, modsAvailable, modsEnabled, tml2, fut);
});
});
}
Aggregations