use of org.folio.okapi.deployment.DeploymentManager in project okapi by folio-org.
the class DeploymentManagerTest method setUp.
@Before
public void setUp(TestContext context) {
async = context.async();
vertx = Vertx.vertx();
ports = new Ports(9231, 9239);
em = new EnvManager(new EnvStoreNull());
ds = new DeploymentStoreNull();
em.init(vertx, res1 -> {
dis = new DiscoveryManager(ds);
dis.init(vertx, res2 -> {
dm = new DeploymentManager(vertx, dis, em, "myhost.index", ports, 9230, "");
async.complete();
});
});
}
use of org.folio.okapi.deployment.DeploymentManager in project okapi by folio-org.
the class MainVerticle method init.
@Override
public void init(Vertx vertx, Context context) {
ModuleVersionReporter m = new ModuleVersionReporter("org.folio.okapi/okapi-core");
okapiVersion = m.getVersion();
m.logStart();
boolean enableProxy = false;
boolean enableDeployment = false;
super.init(vertx, context);
JsonObject config = context.config();
port = Integer.parseInt(Config.getSysConf("port", "9130", config));
int portStart = Integer.parseInt(Config.getSysConf("port_start", Integer.toString(port + 1), config));
int portEnd = Integer.parseInt(Config.getSysConf("port_end", Integer.toString(portStart + 10), config));
String okapiVersion2 = Config.getSysConf("okapiVersion", null, config);
if (okapiVersion2 != null) {
okapiVersion = okapiVersion2;
}
if (clusterManager != null) {
logger.info("cluster NodeId " + clusterManager.getNodeID());
} else {
logger.info("clusterManager not in use");
}
final String host = Config.getSysConf("host", "localhost", config);
String okapiUrl = Config.getSysConf("okapiurl", "http://localhost:" + port, config);
// Remove trailing slash, if there
okapiUrl = okapiUrl.replaceAll("/+$", "");
final String nodeName = Config.getSysConf("nodename", null, config);
String storageType = Config.getSysConf("storage", "inmemory", config);
String loglevel = Config.getSysConf("loglevel", "", config);
if (!loglevel.isEmpty()) {
logHelper.setRootLogLevel(loglevel);
} else {
String lev = getenv("OKAPI_LOGLEVEL");
if (lev != null && !lev.isEmpty()) {
logHelper.setRootLogLevel(loglevel);
}
}
String mode = config.getString("mode", "cluster");
switch(mode) {
case "deployment":
enableDeployment = true;
break;
case "proxy":
enableProxy = true;
break;
case "purgedatabase":
initMode = PURGE;
// so we get to initialize the database. We exit soon after anyway
enableProxy = true;
break;
case "initdatabase":
initMode = INIT;
enableProxy = true;
break;
default:
// cluster and dev
enableDeployment = true;
enableProxy = true;
break;
}
storage = new Storage(vertx, storageType, config);
envManager = new EnvManager(storage.getEnvStore());
discoveryManager = new DiscoveryManager(storage.getDeploymentStore());
if (clusterManager != null) {
discoveryManager.setClusterManager(clusterManager);
}
if (enableDeployment) {
Ports ports = new Ports(portStart, portEnd);
deploymentManager = new DeploymentManager(vertx, discoveryManager, envManager, host, ports, port, nodeName);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
CountDownLatch latch = new CountDownLatch(1);
deploymentManager.shutdown(ar -> latch.countDown());
try {
if (!latch.await(2, TimeUnit.MINUTES)) {
logger.error("Timed out waiting to undeploy all");
}
} catch (InterruptedException e) {
logger.error("Exception while shutting down");
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
}
});
}
if (enableProxy) {
ModuleStore moduleStore = storage.getModuleStore();
moduleManager = new ModuleManager(moduleStore);
TenantStore tenantStore = storage.getTenantStore();
tenantManager = new TenantManager(moduleManager, tenantStore);
moduleManager.setTenantManager(tenantManager);
discoveryManager.setModuleManager(moduleManager);
logger.info("Proxy using " + storageType + " storage");
PullManager pullManager = new PullManager(vertx, moduleManager);
InternalModule internalModule = new InternalModule(moduleManager, tenantManager, deploymentManager, discoveryManager, envManager, pullManager, okapiVersion);
proxyService = new ProxyService(vertx, moduleManager, tenantManager, discoveryManager, internalModule, okapiUrl);
tenantManager.setProxyService(proxyService);
} else {
// not really proxying, except to /_/deployment
moduleManager = new ModuleManager(null);
// make sure it is not shared
moduleManager.forceLocalMap();
tenantManager = new TenantManager(moduleManager, null);
tenantManager.forceLocalMap();
moduleManager.setTenantManager(tenantManager);
discoveryManager.setModuleManager(moduleManager);
InternalModule internalModule = new InternalModule(null, null, deploymentManager, null, envManager, null, okapiVersion);
// no modules, tenants, or discovery. Only deployment and env.
proxyService = new ProxyService(vertx, moduleManager, tenantManager, discoveryManager, internalModule, okapiUrl);
}
}
Aggregations