Skip to content

Commit 54081f3

Browse files
committed
Add command line option to fetch updates and exit afterwards
1 parent cdda20b commit 54081f3

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/main/java/de/komoot/photon/App.java

+25-4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ public static void main(String[] rawArgs) throws Exception {
6464
return;
6565
}
6666

67+
if (args.isNominatimUpdate()) {
68+
shutdownES = true;
69+
log.info("Ensuring that the cluster is ready, this might take some time.");
70+
// inspired by https://stackoverflow.com/a/50316299
71+
esClient.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
72+
final NominatimUpdater nominatimUpdater = setupNominatimUpdater(args, esClient);
73+
Thread updateThread = new Thread(() -> nominatimUpdater.update());
74+
updateThread.start();
75+
updateThread.join();
76+
return;
77+
}
78+
6779
// no special action specified -> normal mode: start search API
6880
startApi(args, esClient);
6981
} finally {
@@ -130,6 +142,18 @@ private static void startNominatimImport(CommandLineArgs args, Server esServer,
130142
log.info("imported data from nominatim to photon with languages: " + args.getLanguages());
131143
}
132144

145+
/**
146+
* Prepare Nominatim updater
147+
*
148+
* @param args
149+
* @param esNodeClient
150+
*/
151+
private static NominatimUpdater setupNominatimUpdater(CommandLineArgs args, Client esNodeClient) {
152+
NominatimUpdater nominatimUpdater = new NominatimUpdater(args.getHost(), args.getPort(), args.getDatabase(), args.getUser(), args.getPassword());
153+
Updater updater = new de.komoot.photon.elasticsearch.Updater(esNodeClient, args.getLanguages());
154+
nominatimUpdater.setUpdater(updater);
155+
return nominatimUpdater;
156+
}
133157

134158
/**
135159
* start api to accept search requests via http
@@ -157,10 +181,7 @@ private static void startApi(CommandLineArgs args, Client esNodeClient) {
157181
get("reverse/", new ReverseSearchRequestHandler("reverse/", esNodeClient, args.getLanguages()));
158182

159183
// setup update API
160-
final NominatimUpdater nominatimUpdater = new NominatimUpdater(args.getHost(), args.getPort(), args.getDatabase(), args.getUser(), args.getPassword());
161-
Updater updater = new de.komoot.photon.elasticsearch.Updater(esNodeClient, args.getLanguages());
162-
nominatimUpdater.setUpdater(updater);
163-
184+
final NominatimUpdater nominatimUpdater = setupNominatimUpdater(args, esNodeClient);
164185
get("/nominatim-update", (Request request, Response response) -> {
165186
new Thread(() -> nominatimUpdater.update()).start();
166187
return "nominatim update started (more information in console output) ...";

src/main/java/de/komoot/photon/CommandLineArgs.java

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public class CommandLineArgs {
2020
@Parameter(names = "-nominatim-import", description = "import nominatim database into photon (this will delete previous index)")
2121
private boolean nominatimImport = false;
2222

23+
@Parameter(names = "-nominatim-update", description = "fetch updates from nominatim database into photon and exit (this updates the index only without offering an API")
24+
private boolean nominatimUpdate = false;
25+
2326
@Parameter(names = "-languages", description = "languages nominatim importer should import and use at run-time, comma separated (default is 'en,fr,de,it')")
2427
private String languages = "en,fr,de,it";
2528

0 commit comments

Comments
 (0)