Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved metrics update to finally block to assure consistency of timestamps between SQL calls #821

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,6 @@ public void fetch() throws SQLException, IOException {
}
if (sourceMetric != null) {
sourceMetric.getSucceeded().inc();
sourceMetric.setLastExecutionStart(dateTime);
sourceMetric.setLastExecutionEnd(new DateTime());
}
} catch (SQLRecoverableException e) {
long millis = getMaxRetryWait().getMillis();
Expand All @@ -617,21 +615,19 @@ public void fetch() throws SQLException, IOException {
}
if (sourceMetric != null) {
sourceMetric.getSucceeded().inc();
sourceMetric.setLastExecutionStart(dateTime);
sourceMetric.setLastExecutionEnd(new DateTime());
}
}
}
} catch (Exception e) {
if (sourceMetric != null) {
sourceMetric.getFailed().inc();
sourceMetric.setLastExecutionStart(dateTime);
sourceMetric.setLastExecutionEnd(new DateTime());
}
throw new IOException(e);
} finally {
if (sourceMetric != null) {
sourceMetric.incCounter();
sourceMetric.setLastExecutionStart(dateTime);
sourceMetric.setLastExecutionEnd(new DateTime());
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/xbib/tools/CommandLineInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
package org.xbib.tools;

import java.io.InputStream;
import java.util.List;

public interface CommandLineInterpreter {

void run(String resourceName, InputStream in) throws Exception;
void run(String resourceName, List<InputStream> in) throws Exception;

}
15 changes: 10 additions & 5 deletions src/main/java/org/xbib/tools/JDBCImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.Settings.Builder;
import org.elasticsearch.common.unit.TimeValue;
import org.xbib.elasticsearch.common.cron.CronExpression;
import org.xbib.elasticsearch.common.cron.CronThreadPoolExecutor;
Expand Down Expand Up @@ -116,11 +117,15 @@ public JDBCImporter reloadSettings(Settings oldSettings) {
return this;
}

@Override
public void run(String resourceName, InputStream in) {
setSettings(settingsBuilder().loadFromStream(resourceName, in).build());
run();
}
@Override
public void run(String resourceName, List<InputStream> in) {
Builder builder = settingsBuilder();
for (int i = 0; i < in.size(); i++) {
builder.loadFromStream(resourceName, in.get(i));
}
setSettings(builder.build());
run();
}

@Override
public void run() {
Expand Down
37 changes: 24 additions & 13 deletions src/main/java/org/xbib/tools/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,32 @@

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Runner {

public static void main(String[] args) {
try {
Class clazz = Class.forName(args[0]);
CommandLineInterpreter commandLineInterpreter = (CommandLineInterpreter) clazz.newInstance();
InputStream in = args.length > 1 ? new FileInputStream(args[1]) : System.in;
commandLineInterpreter.run("args", in);
in.close();
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
public static void main(String[] args) {
try {
Class clazz = Class.forName(args[0]);
CommandLineInterpreter commandLineInterpreter = (CommandLineInterpreter) clazz.newInstance();
List<InputStream> inputs = new ArrayList<InputStream>();
if (args.length > 1) {
for (int i = 1; i < args.length; i++) {
inputs.add(new FileInputStream(args[i]));
}
} else {
inputs.add(System.in);
}
InputStream in = args.length > 1 ? new FileInputStream(args[1]) : System.in;
commandLineInterpreter.run("args", inputs);
in.close();
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}

}