Skip to content

Commit

Permalink
Refactor bookkeeping client (#3)
Browse files Browse the repository at this point in the history
* Remvoe slf4j-12 from lib to avoid conflict

* Refactor bookkeeping client

* Refactoring
  • Loading branch information
martinboulais authored Oct 8, 2024
1 parent e48f9f5 commit e306b96
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 286 deletions.
Binary file removed lib/slf4j-log4j12-1.7.30.jar
Binary file not shown.
66 changes: 17 additions & 49 deletions src/alice/dip/AliDip2BK.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
import java.util.Properties;

public class AliDip2BK implements Runnable {

public static String Version = "2.0 14-Nov-2023";
public static String DNSnode = "dipnsdev.cern.ch";
public static String[] endFillCases = {"CUCU"};
public static boolean LIST_PARAM = false;
static public String LIST_PARAM_PAT = "*";
static public int DEBUG_LEVEL = 1;
static public String OUTPUT_FILE = null;
public static String BKURL = "http://localhost:4000";
public static String BKP_TOKEN = null;
public static String bookkeepingUrl = "http://localhost:4000";
public static String bookkeepingToken = null;
public static boolean SAVE_PARAMETERS_HISTORY_PER_RUN = false;
public static String KEEP_RUNS_HISTORY_DIRECTORY = null;
public static String KEEP_FILLS_HISTORY_DIRECTORY = null;
Expand All @@ -49,14 +48,13 @@ public class AliDip2BK implements Runnable {
String confFile = "AliDip2BK.properties";
DipClient client;
DipMessagesProcessor process;
BookkeepingClient dbw;
BookkeepingClient bookkeepingClient;
StartOfRunKafkaConsumer kcs;
EndOfRunKafkaConsumer kce;
private long startDate;
private long stopDate;

public AliDip2BK() {

startDate = (new Date()).getTime();

ProgPath = getClass().getClassLoader().getResource(".").getPath();
Expand All @@ -67,8 +65,8 @@ public AliDip2BK() {

verifyDirs();

dbw = new BookkeepingClient();
process = new DipMessagesProcessor(dbw);
bookkeepingClient = new BookkeepingClient(bookkeepingUrl, bookkeepingToken);
process = new DipMessagesProcessor(bookkeepingClient);

client = new DipClient(DipParametersFile, process);

Expand All @@ -86,7 +84,6 @@ public AliDip2BK() {

Thread t = new Thread(this);
t.start();

}

static public void log(int level, String module, String mess) {
Expand All @@ -98,18 +95,14 @@ static public void log(int level, String module, String mess) {
}

public static void main(String[] args) {

@SuppressWarnings("unused")
AliDip2BK service = new AliDip2BK();

}

public void run() {

int stat_count = 0;

for (; ; ) {

try {
Thread.sleep(10000);
stat_count = stat_count + 10;
Expand Down Expand Up @@ -139,8 +132,7 @@ public void run() {
Thread.currentThread().interrupt();
}

if (process.QueueSize() == 0)
break;
if (process.QueueSize() == 0) break;
}
}

Expand All @@ -151,7 +143,6 @@ public void run() {
}
process.saveState();
writeStat("AliDip2BK.stat", true);
dbw.close();
}
});
}
Expand All @@ -164,16 +155,14 @@ public void showConfig() {
con = con + "* DIP/DIM =" + DNSnode + "\n";
con = con + "* KAFKA Server = " + bootstrapServers + "\n";
con = con + "* KAFKA Group ID=" + KAFKA_group_id + "\n";
con = con + "* Bookkeeping URL =" + BKURL + "\n";
con = con + "* Bookkeeping URL =" + bookkeepingUrl + "\n";
con = con + "* \n";
con = con + "*************************************************\n";

System.out.println(con);

}

public void loadConf(String filename) {

private void loadConf(String filename) {
String input = ProgPath + "/" + filename;

Properties prop = new Properties();
Expand All @@ -195,7 +184,6 @@ public void loadConf(String filename) {
DipParametersFile = ProgPath + para_file_name;
} else {
log(4, "AliDip2BK.loadConf", " Dip Data Providers Subscription file name is undefined in the conf file ");

}

String list_param = prop.getProperty("ListDataProvidersPattern");
Expand All @@ -204,11 +192,8 @@ public void loadConf(String filename) {

LIST_PARAM = true;
LIST_PARAM_PAT = list_param;

} else {
log(4, "AliDip2BK.loadConf ",
" List DIP Data Providers Pattern is undefined ! The DIP broswer will not start ");

log(4, "AliDip2BK.loadConf ", " List DIP Data Providers Pattern is undefined ! The DIP broswer will not start ");
}

String debug_n = prop.getProperty("DEBUG_LEVEL");
Expand All @@ -227,13 +212,9 @@ public void loadConf(String filename) {
if (keh != null) {
keh = keh.trim();
SAVE_PARAMETERS_HISTORY_PER_RUN = false;
if (keh.equalsIgnoreCase("Y"))
SAVE_PARAMETERS_HISTORY_PER_RUN = true;
if (keh.equalsIgnoreCase("YES"))
SAVE_PARAMETERS_HISTORY_PER_RUN = true;
if (keh.equalsIgnoreCase("true"))
SAVE_PARAMETERS_HISTORY_PER_RUN = true;

if (keh.equalsIgnoreCase("Y")) SAVE_PARAMETERS_HISTORY_PER_RUN = true;
if (keh.equalsIgnoreCase("YES")) SAVE_PARAMETERS_HISTORY_PER_RUN = true;
if (keh.equalsIgnoreCase("true")) SAVE_PARAMETERS_HISTORY_PER_RUN = true;
}

String kfhd = prop.getProperty("KEEP_FILLS_HISTORY_DIRECTORY");
Expand All @@ -249,12 +230,9 @@ public void loadConf(String filename) {
String sde = prop.getProperty("SIMULATE_DIP_EVENTS");
if (sde != null) {

if (sde.equalsIgnoreCase("Y"))
SIMULATE_DIP_EVENTS = true;
if (sde.equalsIgnoreCase("YES"))
SIMULATE_DIP_EVENTS = true;
if (sde.equalsIgnoreCase("true"))
SIMULATE_DIP_EVENTS = true;
if (sde.equalsIgnoreCase("Y")) SIMULATE_DIP_EVENTS = true;
if (sde.equalsIgnoreCase("YES")) SIMULATE_DIP_EVENTS = true;
if (sde.equalsIgnoreCase("true")) SIMULATE_DIP_EVENTS = true;
}

String kgid = prop.getProperty("KAFKA_group_id");
Expand Down Expand Up @@ -283,22 +261,18 @@ public void loadConf(String filename) {
String bkurl = prop.getProperty("BookkeepingURL");

if (bkurl != null) {
BKURL = bkurl;
bookkeepingUrl = bkurl;
}
String bkpToken = prop.getProperty(("BKP_TOKEN"));
if (bkpToken != null) {
BKP_TOKEN = bkpToken;
bookkeepingToken = bkpToken;
}

} catch (IOException ex) {
log(4, "AliDip2BK.loadCong", "Failed to access properties file " + ex);

}

}

public void writeStat(String file, boolean final_report) {

String full_file = ProgPath + AliDip2BK.KEEP_STATE_DIR + file;

stopDate = (new Date()).getTime();
Expand Down Expand Up @@ -336,20 +310,16 @@ public void writeStat(String file, boolean final_report) {

AliDip2BK.log(4, "ProcData.writeStat", " ERROR writing file=" + full_file + " ex=" + e);
}

}

public void verifyDirs() {

verifyDir(KEEP_RUNS_HISTORY_DIRECTORY);
verifyDir(KEEP_FILLS_HISTORY_DIRECTORY);
verifyDir(STORE_HIST_FILE_DIR);
verifyDir(KEEP_STATE_DIR);

}

public void verifyDir(String name) {

if (name != null) {

File directory = new File(String.valueOf(ProgPath + "/" + name));
Expand All @@ -358,8 +328,6 @@ public void verifyDir(String name) {
directory.mkdir();
AliDip2BK.log(2, "AliDip2BK->verifyDir", "created new Directory=" + name);
}

}
}

}
Loading

0 comments on commit e306b96

Please sign in to comment.