Run & debug modules in idea and connect with vagrant

Purpose

This guide is about running modules directly in idea without the need of constant rebuild/replace jars in vagrant.


All following steps assume are working under diku_admin user in tenant diku and you have variables {{okapiUrl}}, which is http://localhost:9130 for local vagrant {{tenant}} and {{FOLIO_TOKEN}} obtained from logging in:

POST {{okapiUrl}}/authn/login

The following guide is how to to replace mod-oai-pmh in okapi running in vagrant and for other modules the steps are the same:

  • mvn clean install -DskipTests
  • Post target/ModuleDescriptor.json to

POST {{okapiUrl}}/_/proxy/modules
Content-Type: application/json
X-Okapi-Tenant: {{tenant}}

  • Pick any available port in localhost, for example, 8083 and adjust url accordingly. http://10.0.2.2 - the address of the host available from vagrant


POST {{okapiUrl}}/_/discovery/modules
Content-Type: application/json
X-Okapi-Tenant: {{tenant}}
X-Okapi-Token: {{FOLIO_TOKEN}}
{
"srvcId": "mod-oai-pmh-3.1.0-SNAPSHOT",
"instId": "mod-oai-pmh-3.1.0-SNAPSHOT",
"url": "http://10.0.2.2:8083"
}

  • Create a run/debug configuration in IDEA, then run the module on specified port, 8083: run org.folio.rest.RestVerticle -Dhttp.port=8083 -Dlog.level=debug

  • Let's find If there is a running instance of the module registered in Okapi:

GET {{okapiUrl}}/_/proxy/tenants/diku/modules
Content-Type: application/json

  • In response find mod-oai-pmh, for example, there can be mod-oai-pmh-3.1.0-SNAPSHOT.148
  • Reroute Okapi to the module running locally in IDEA: Before this step, the module should be up and running on the specified port
POST {{okapiUrl}}/_/proxy/tenants/diku/modules/mod-oai-pmh-3.1.0-SNAPSHOT.148
Content-Type: application/json
{
"id" : "mod-oai-pmh-3.1.0-SNAPSHOT"
}
  • If there is no module running in Okapi, then:
POST {{okapiUrl}}/_/proxy/tenants/diku/modules

Content-Type: application/json
{
"id" : "mod-oai-pmh-3.1.0-SNAPSHOT"
}

  • Enable module for tenant. Note, this will kick off the post tenant API if it is implemented in this module. Before this step, the module should be up and running on the specified port
POST {{okapiUrl}}/_/proxy/tenants/diku/install
Content-Type: application/json
X-Okapi-Tenant: {{tenant}}
X-Okapi-Token: {{FOLIO_TOKEN}}

[
{
"id": "mod-oai-pmh-3.1.0-SNAPSHOT",
"action": "enable"
}
]


  • Check that requests to the module:  GET {{okapiUrl}}/oai-pmh-view/instances or GET http://localhost:8083 get stopped in debug in idea!

  • Profit