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