Skip to content

Commit

Permalink
Introduce new config for WebhookListener
Browse files Browse the repository at this point in the history
This makes it possible to discriminate between the index name of "updates"
and of "basedump".
  • Loading branch information
dr0i committed May 4, 2021
1 parent 0e464bb commit defcdf4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
49 changes: 28 additions & 21 deletions web/app/controllers/resources/Webhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public class Webhook extends Controller {
Application.CONFIG.getString("webhook.alma.update.filename");
private static final String FILENAME_BASEDUMP =
Application.CONFIG.getString("webhook.alma.basedump.filename");
private static final String INDEX_NAME =
Application.CONFIG.getString("webhook.alma.indexname");
private static final String INDEX_NAME_OF_BASEDUMP =
Application.CONFIG.getString("webhook.alma.basedump.indexname");
private static final String INDEX_NAME_OF_UPDATE =
Application.CONFIG.getString("webhook.alma.update.indexname");
private static final String TOKEN =
Application.CONFIG.getString("webhook.alma.token");
private static final String EMAIL =
Expand All @@ -30,23 +32,29 @@ public class Webhook extends Controller {
private static final String INDEX_BASEDUMP_ALIAS_SUFFIX = "-staging";
private static final String UPDATE_NEWEST_INDEX = "exact";
private static final String CREATE_INDEX = "create";
private static final String CREATE_INDEX_NAME =
INDEX_NAME + "-" + LocalDateTime.now()
private static final String CREATE_INDEX_NAME_OF_BASEDUMP =
INDEX_NAME_OF_BASEDUMP + "-" + LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yyyyMMdd-kkmm"));
private static final String MSG_ETL_PROCESS_IS_ALREADY_RUNNING =
" because an ETL process is already running. Try again later!";
private static final String MSG_UPDATE_ALREADY_RUNNING =
"Couldn't update index '" + INDEX_NAME_OF_UPDATE
+ MSG_ETL_PROCESS_IS_ALREADY_RUNNING;
private static final String MSG_CREATE_INDEX_ALREADY_RUNNING =
"Couldn't created new index with name " + CREATE_INDEX_NAME_OF_BASEDUMP
+ MSG_ETL_PROCESS_IS_ALREADY_RUNNING;
private static final String MORPH_FILENAME = "alma.xml";
// If null, create default values from Global settings
public static String clusterHost = null;
public static String clusterName = null;
private static String msgWrongToken =
"'%s' is the wrong token. Declining to ETL %s.";
private static String msgStartEtl = "Starting ETL of '%s'...";
private static final String MSG_ALREADY_RUNNING =
"An ETL is already running. Only one at a time is allowed. Please try again later.";

/**
* Triggers ETL of updates.
*
* @param token the token to authorize updating
* @param GIVEN_TOKEN the token to authorize updating
* @return "200 ok" or "403 forbidden" (depending on token) or "423 locked" in
* case of an already triggered process that was not yet finished
*/
Expand All @@ -56,24 +64,24 @@ public static Result updateAlma(final String GIVEN_TOKEN) {
return wrongToken(KIND, GIVEN_TOKEN);
}
if (AlmaMarcXml2lobidJsonEs.threadAlreadyStarted) {
sendMail(KIND, false, "Couldn't update index '" + INDEX_NAME
+ " because an ETL process is already running. Try again later!");
return status(423, MSG_ALREADY_RUNNING);
sendMail(KIND, false, MSG_UPDATE_ALREADY_RUNNING);
return status(423, MSG_UPDATE_ALREADY_RUNNING);
}
Logger.info(String.format(msgStartEtl, KIND));
AlmaMarcXml2lobidJsonEs.setKindOfEtl(KIND);
AlmaMarcXml2lobidJsonEs.setEmail(EMAIL);
AlmaMarcXml2lobidJsonEs.main(FILENAME_UPDATE, INDEX_NAME,
AlmaMarcXml2lobidJsonEs.main(FILENAME_UPDATE, INDEX_NAME_OF_UPDATE,
INDEX_UPDATE_ALIAS_SUFFIX, clusterHost, clusterName,
UPDATE_NEWEST_INDEX, MORPH_FILENAME);
sendMail(KIND, true, "Going to update index '" + INDEX_NAME + "'");
sendMail(KIND, true,
"Going to update index '" + INDEX_NAME_OF_UPDATE + "'");
return ok("... started ETL " + KIND);
}

/**
* Triggers ETL of basedump.
*
* @param token the token to authorize updating
* @param GIVEN_TOKEN the token to authorize updating
* @return "200 ok" or "403 forbidden" (depending on token) or "423 locked" in
* case of an already triggered process that was not yet finished
*/
Expand All @@ -83,19 +91,18 @@ public static Result basedumpAlma(final String GIVEN_TOKEN) {
return wrongToken(KIND, GIVEN_TOKEN);
}
if (AlmaMarcXml2lobidJsonEs.threadAlreadyStarted) {
sendMail(KIND, false,
"Couldn't created new index with name " + CREATE_INDEX_NAME
+ " because an ETL process is already running. Try again later!");
return status(423, MSG_ALREADY_RUNNING);
sendMail(KIND, false, MSG_CREATE_INDEX_ALREADY_RUNNING);
return status(423, MSG_CREATE_INDEX_ALREADY_RUNNING);
}
Logger.info(String.format(msgStartEtl, KIND));
AlmaMarcXml2lobidJsonEs.setKindOfEtl(KIND);
AlmaMarcXml2lobidJsonEs.setEmail(EMAIL);
AlmaMarcXml2lobidJsonEs.main(FILENAME_BASEDUMP, CREATE_INDEX_NAME,
INDEX_BASEDUMP_ALIAS_SUFFIX, clusterHost, clusterName, CREATE_INDEX,
MORPH_FILENAME);
AlmaMarcXml2lobidJsonEs.main(FILENAME_BASEDUMP,
CREATE_INDEX_NAME_OF_BASEDUMP, INDEX_BASEDUMP_ALIAS_SUFFIX, clusterHost,
clusterName, CREATE_INDEX, MORPH_FILENAME);
sendMail(KIND, true,
"Going to created new index with name " + CREATE_INDEX_NAME
"Going to created new index with name " + CREATE_INDEX_NAME_OF_BASEDUMP

+ " , adding " + INDEX_BASEDUMP_ALIAS_SUFFIX
+ " to alias of index");
return ok("... started ETL " + KIND);
Expand Down
3 changes: 2 additions & 1 deletion web/conf/resources.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ webhook = {
alma = {
update = {
filename = "/data/other/datenportal/export/alma/prod/update.xml.bgzf"
indexname = "almaresources-staging"
}
basedump = {
filename = "/data/other/datenportal/export/alma/prod/baseline.xml.bgzf"
indexname = "almaresources"
}
token = "123"
indexname = "almaresources"
}
email = "change@me"
}
Expand Down

0 comments on commit defcdf4

Please sign in to comment.