Module deployment flow
Module deployment flow
For enabling module to FOLIO system it needs next steps:
- Register Module descriptor into OKAPI using its API
- Deploy module by Deployment descriptor using OKAPI API
- Enabling module to concrete tenant using OKAPI API
After this steps module will be ready to use for concrete tenant. It is possible to enable one instance of the module to many tenants.
Adding a hooks on lifecycle phases
Before deployment hook
It is possible to add custom code that will run once before the application is deployed (e.g. to init a DB, create a cache, create static variables, etc.) by implementing the InitAPIs
interface. You must implement the init(Vertx vertx, Context context, Handler<AsyncResult<Boolean>> resultHandler)
. Only one implementation per module is supported. Currently the implementation should sit in the org.folio.rest.impl
package in the implementing project. The implementation will run during verticle deployment. The verticle will not complete deployment until the init() completes. The init() function can do anything basically, but it must call back the Handler.
public class InitAPIs implements InitAPI {
public void init(Vertx vertx, Context context, Handler<AsyncResult<Boolean>> resultHandler){
try {
resultHandler.handle(io.vertx.core.Future.succeededFuture(true));
} catch (Exception e) {
e.printStackTrace();
resultHandler.handle(io.vertx.core.Future.failedFuture(e.getMessage()));
}
}
}
After deployment hook
It is possible to add custom code that will be run immediately after the verticle running the module is deployed. It is possible by implementing PostDeployVerticle and (Vertx vertx, Context context, Handler<AsyncResult<Boolean>> resultHandler) method.
public class PostDeployVerticleIml implements PostDeployVerticle {
@Override
public void init(Vertx vertx, Context context, Handler<AsyncResult<Boolean>> handler) {
if(context != null){
handler.handle(io.vertx.core.Future.succeededFuture(true));
}
else{
handler.handle(io.vertx.core.Future.failedFuture("Internal error");
}
}
}
Enable module for tenant
After enabling module for tenant using OKAPI API, it call module /_/tenant endpoint. This endpoint create schema at database if it not exist and run custom SQL snippets if there are registered and schema file. Example at schema.json
{
"tableName": "module_table_name",
"generateId": false,
"pkColumnName": "_id",
"withMetadata": false,
"withAuditing": false,
"customSnippetPath": "CUSTOM_SQL_SNIPPET.sql"
}
This SQL snippet executes only with table creation if it is not exist.