use of org.folio.okapi.bean.DeploymentDescriptor in project okapi by folio-org.
the class DeploymentManagerTest method test2.
@Test
public void test2(TestContext context) {
async = context.async();
LaunchDescriptor descriptor = new LaunchDescriptor();
descriptor.setExec("java -Dport=%p -jar " + "../okapi-test-module/target/unknown.jar");
DeploymentDescriptor dd = new DeploymentDescriptor("2", "sid", descriptor);
dm.deploy(dd, res -> {
context.assertFalse(res.succeeded());
async.complete();
});
}
use of org.folio.okapi.bean.DeploymentDescriptor in project okapi by folio-org.
the class ProxyService method doCallSystemInterface.
/**
* Actually make a request to a system interface, like _tenant. Assumes we are
* operating as the correct tenant.
*/
private void doCallSystemInterface(String tenantId, String authToken, ModuleInstance inst, String modPerms, String request, ProxyContext pc, Handler<ExtendedAsyncResult<OkapiClient>> fut) {
String curTenant = pc.getTenant();
pc.debug("doCallSystemInterface on " + Json.encode(inst) + " for " + tenantId + " as " + curTenant + " with token " + authToken);
discoveryManager.get(inst.getModuleDescriptor().getId(), gres -> {
if (gres.failed()) {
pc.warn("doCallSystemInterface on " + inst.getModuleDescriptor().getId() + " " + inst.getPath() + " failed. Could not find the module in discovery", gres.cause());
fut.handle(new Failure<>(gres.getType(), gres.cause()));
return;
}
DeploymentDescriptor instance = pickInstance(gres.result());
if (instance == null) {
fut.handle(new Failure<>(USER, "No running instances for module " + inst.getModuleDescriptor().getId() + ". Can not invoke " + inst.getPath()));
return;
}
String baseurl = instance.getUrl();
pc.debug("doCallSystemInterface Url: " + baseurl + " and " + inst.getPath());
Map<String, String> headers = sysReqHeaders(pc.getCtx(), tenantId, authToken);
if (modPerms != null) {
// We are making an auth call
RoutingEntry re = inst.getRoutingEntry();
if (re != null) {
headers.put(XOkapiHeaders.FILTER, re.getPhase());
}
if (!modPerms.isEmpty()) {
headers.put(XOkapiHeaders.MODULE_PERMISSIONS, modPerms);
}
// Clear the permissions-required header that we inherited from the
// original request (e.g. to tenant-enable), as we do not have those
// perms set in the target tenant
headers.put(XOkapiHeaders.PERMISSIONS_REQUIRED, "");
headers.put(XOkapiHeaders.PERMISSIONS_DESIRED, "");
logger.debug("Auth call, some tricks with permissions");
}
pc.debug("doCallSystemInterface: About to create OkapiClient with headers " + Json.encode(headers));
OkapiClient cli = new OkapiClient(baseurl, vertx, headers);
String reqId = inst.getPath().replaceFirst("^[/_]*([^/]+).*", "$1");
// "tenant" or "tenantpermissions"
cli.newReqId(reqId);
cli.enableInfoLog();
HttpMethod meth = HttpMethod.POST;
if (request.isEmpty()) {
pc.debug("doCallSystemInterface: No Req, making a HEAD req");
meth = HttpMethod.HEAD;
}
HttpMethod finalMeth = meth;
cli.request(meth, inst.getPath(), request, cres -> {
cli.close();
if (cres.failed()) {
String msg = finalMeth + " request for " + inst.getModuleDescriptor().getId() + " " + inst.getPath() + " failed with " + cres.cause().getMessage();
pc.warn(msg);
fut.handle(new Failure<>(INTERNAL, msg));
return;
}
// Pass response headers - needed for unit test, if nothing else
String body = cres.result();
pc.debug("doCallSystemInterface response: " + body);
pc.debug("doCallSystemInterface ret " + " hdrs: " + Json.encode(cli.getRespHeaders().entries()));
pc.passOkapiTraceHeaders(cli);
fut.handle(new Success<>(cli));
});
});
}
use of org.folio.okapi.bean.DeploymentDescriptor in project okapi by folio-org.
the class ProxyService method resolveUrls.
private void resolveUrls(Iterator<ModuleInstance> it, Handler<ExtendedAsyncResult<Void>> fut) {
if (!it.hasNext()) {
fut.handle(new Success<>());
} else {
ModuleInstance mi = it.next();
if (mi.getRoutingEntry().getProxyType() == ProxyType.INTERNAL) {
mi.setUrl("");
resolveUrls(it, fut);
return;
}
discoveryManager.get(mi.getModuleDescriptor().getId(), res -> {
if (res.failed()) {
fut.handle(new Failure<>(res.getType(), res.cause()));
} else {
DeploymentDescriptor instance = pickInstance(res.result());
if (instance == null) {
fut.handle(new Failure<>(NOT_FOUND, "No running module instance found for " + mi.getModuleDescriptor().getId()));
return;
}
mi.setUrl(instance.getUrl());
resolveUrls(it, fut);
}
});
}
}
use of org.folio.okapi.bean.DeploymentDescriptor in project okapi by folio-org.
the class DeploymentManager method undeploy.
public void undeploy(String id, Handler<ExtendedAsyncResult<Void>> fut) {
logger.info("undeploy instId " + id);
if (!list.containsKey(id)) {
fut.handle(new Failure<>(NOT_FOUND, "not found: " + id));
} else {
Timer.Context tim = DropwizardHelper.getTimerContext("deploy." + id + ".undeploy");
DeploymentDescriptor md = list.get(id);
dm.remove(md.getSrvcId(), md.getInstId(), res -> {
if (res.failed()) {
tim.close();
fut.handle(new Failure<>(res.getType(), res.cause()));
} else {
ModuleHandle mh = md.getModuleHandle();
mh.stop(future -> {
if (future.failed()) {
tim.close();
fut.handle(new Failure<>(INTERNAL, future.cause()));
} else {
fut.handle(new Success<>());
tim.close();
list.remove(id);
}
});
}
});
}
}
use of org.folio.okapi.bean.DeploymentDescriptor in project okapi by folio-org.
the class DeploymentManager method deploy2.
private void deploy2(Handler<ExtendedAsyncResult<DeploymentDescriptor>> fut, Timer.Context tim, int usePort, DeploymentDescriptor md1, String url) {
LaunchDescriptor descriptor = md1.getDescriptor();
if (descriptor == null) {
ports.free(usePort);
fut.handle(new Failure<>(USER, "No LaunchDescriptor"));
tim.close();
return;
}
HashMap<String, EnvEntry> entries = new HashMap<>();
EnvEntry[] env = descriptor.getEnv();
if (env != null) {
for (EnvEntry e : env) {
entries.put(e.getName(), e);
}
}
em.get(eres -> {
if (eres.failed()) {
ports.free(usePort);
fut.handle(new Failure<>(INTERNAL, "get env: " + eres.cause().getMessage()));
tim.close();
} else {
for (EnvEntry er : eres.result()) {
entries.put(er.getName(), er);
}
if (entries.size() > 0) {
EnvEntry[] nenv = new EnvEntry[entries.size()];
int i = 0;
for (Entry<String, EnvEntry> key : entries.entrySet()) {
nenv[i++] = key.getValue();
}
descriptor.setEnv(nenv);
}
ModuleHandle mh = ModuleHandleFactory.create(vertx, descriptor, ports, usePort);
mh.start(future -> {
if (future.succeeded()) {
DeploymentDescriptor md2 = new DeploymentDescriptor(md1.getInstId(), md1.getSrvcId(), url, md1.getDescriptor(), mh);
md2.setNodeId(md1.getNodeId() != null ? md1.getNodeId() : host);
list.put(md2.getInstId(), md2);
tim.close();
dm.add(md2, res -> fut.handle(new Success<>(md2)));
} else {
tim.close();
ports.free(usePort);
logger.warn("Deploying " + md1.getSrvcId() + " failed");
fut.handle(new Failure<>(USER, future.cause()));
}
});
}
});
}
Aggregations