1
1
package de .komoot .photon ;
2
2
3
-
4
3
import com .beust .jcommander .JCommander ;
5
4
import com .beust .jcommander .ParameterException ;
5
+
6
+ import de .komoot .photon .elasticsearch .ReplicationUpdater ;
7
+ import de .komoot .photon .elasticsearch .Replicatior ;
6
8
import de .komoot .photon .elasticsearch .Server ;
7
9
import de .komoot .photon .nominatim .NominatimConnector ;
8
10
import de .komoot .photon .nominatim .NominatimUpdater ;
11
13
import spark .Request ;
12
14
import spark .Response ;
13
15
16
+ import java .io .File ;
14
17
import java .io .FileNotFoundException ;
15
18
import java .io .IOException ;
16
19
17
20
import static spark .Spark .*;
18
21
19
-
20
22
@ Slf4j
21
23
public class App {
22
24
@@ -43,6 +45,11 @@ public static void main(String[] rawArgs) throws Exception {
43
45
return ;
44
46
}
45
47
48
+ if (args .isReplicate ()) {
49
+ startReplicationUpdate (args );
50
+ return ;
51
+ }
52
+
46
53
boolean shutdownES = false ;
47
54
final Server esServer = new Server (args ).start ();
48
55
try {
@@ -63,11 +70,11 @@ public static void main(String[] rawArgs) throws Exception {
63
70
// no special action specified -> normal mode: start search API
64
71
startApi (args , esClient );
65
72
} finally {
66
- if (shutdownES ) esServer .shutdown ();
73
+ if (shutdownES )
74
+ esServer .shutdown ();
67
75
}
68
76
}
69
77
70
-
71
78
/**
72
79
* dump elastic search index and create a new and empty one
73
80
*
@@ -83,7 +90,6 @@ private static void startRecreatingIndex(Server esServer) {
83
90
log .info ("deleted photon index and created an empty new one." );
84
91
}
85
92
86
-
87
93
/**
88
94
* take nominatim data and dump it to json
89
95
*
@@ -93,7 +99,8 @@ private static void startJsonDump(CommandLineArgs args) {
93
99
try {
94
100
final String filename = args .getJsonDump ();
95
101
final JsonDumper jsonDumper = new JsonDumper (filename , args .getLanguages ());
96
- NominatimConnector nominatimConnector = new NominatimConnector (args .getHost (), args .getPort (), args .getDatabase (), args .getUser (), args .getPassword ());
102
+ NominatimConnector nominatimConnector = new NominatimConnector (args .getHost (), args .getPort (), args .getDatabase (), args .getUser (),
103
+ args .getPassword ());
97
104
nominatimConnector .setImporter (jsonDumper );
98
105
nominatimConnector .readEntireDatabase (args .getCountryCodes ().split ("," ));
99
106
log .info ("json dump was created: " + filename );
@@ -102,7 +109,6 @@ private static void startJsonDump(CommandLineArgs args) {
102
109
}
103
110
}
104
111
105
-
106
112
/**
107
113
* take nominatim data to fill elastic search index
108
114
*
@@ -126,11 +132,22 @@ private static void startNominatimImport(CommandLineArgs args, Server esServer,
126
132
log .info ("imported data from nominatim to photon with languages: " + args .getLanguages ());
127
133
}
128
134
135
+ /**
136
+ * Run generation of replication files once
137
+ *
138
+ * @param args the arguments from the command line
139
+ */
140
+ private static void startReplicationUpdate (CommandLineArgs args ) {
141
+ final NominatimUpdater nominatimUpdater = new NominatimUpdater (args .getHost (), args .getPort (), args .getDatabase (), args .getUser (), args .getPassword ());
142
+ Updater updater = new ReplicationUpdater (new File (args .getReplicationDirectory ()), null );
143
+ nominatimUpdater .setUpdater (updater );
144
+ nominatimUpdater .update ();
145
+ }
129
146
130
147
/**
131
148
* start api to accept search requests via http
132
149
*
133
- * @param args
150
+ * @param args the arguments from the command line
134
151
* @param esNodeClient
135
152
*/
136
153
private static void startApi (CommandLineArgs args , Client esNodeClient ) {
@@ -146,11 +163,19 @@ private static void startApi(CommandLineArgs args, Client esNodeClient) {
146
163
// setup update API
147
164
final NominatimUpdater nominatimUpdater = new NominatimUpdater (args .getHost (), args .getPort (), args .getDatabase (), args .getUser (), args .getPassword ());
148
165
Updater updater = new de .komoot .photon .elasticsearch .Updater (esNodeClient , args .getLanguages ());
149
- nominatimUpdater .setUpdater (updater );
150
-
151
- get ("/nominatim-update" , (Request request , Response response ) -> {
152
- new Thread (() -> nominatimUpdater .update ()).start ();
153
- return "nominatim update started (more information in console output) ..." ;
154
- });
166
+ String replicationUrl = args .getReplicationUrl ();
167
+ if (replicationUrl == null ) {
168
+ if (args .isGenerateFiles ()) {
169
+ updater = new ReplicationUpdater (new File (args .getReplicationDirectory ()), updater );
170
+ }
171
+ nominatimUpdater .setUpdater (updater );
172
+ get ("/nominatim-update" , (Request request , Response response ) -> {
173
+ new Thread (() -> nominatimUpdater .update ()).start ();
174
+ return "nominatim update started (more information in console output) ..." ;
175
+ });
176
+ } else {
177
+ Replicatior replicator = new Replicatior (new File (args .getReplicationDirectory ()), args .getReplicationUrl (), args .getReplicationInterval (), updater );
178
+ replicator .start ();
179
+ }
155
180
}
156
181
}
0 commit comments