26
26
import java .util .ArrayList ;
27
27
import java .util .HashSet ;
28
28
import java .util .List ;
29
+ import java .util .Map ;
29
30
import java .util .Set ;
30
31
31
32
import org .slf4j .Logger ;
70
71
public class DataHub {
71
72
72
73
static final private Logger LOGGER = LoggerFactory .getLogger (DataHub .class );
73
- static final public String STAGING_NAME = "data-hub-STAGING" ;
74
- static final public String FINAL_NAME = "data-hub-FINAL" ;
75
- static final public String MODULES_DB_NAME = "data-hub-modules" ;
74
+
76
75
private ManageConfig config ;
77
76
private ManageClient client ;
78
- public static String HUB_NAME = "data-hub" ;
79
- public static int FORESTS_PER_HOST = 4 ;
80
- private String host ;
81
- private int stagingRestPort ;
82
- private int finalRestPort ;
83
- private String username ;
84
- private String password ;
85
77
86
78
private File assetInstallTimeFile = new File ("./assetInstallTime.properties" );
79
+ private HubConfig hubConfig ;
87
80
88
- private final static int DEFAULT_STAGING_REST_PORT = 8010 ;
89
- private final static int DEFAULT_FINAL_REST_PORT = 8011 ;
90
-
91
- public DataHub (HubConfig config ) {
92
- this (config .getHost (), config .getStagingPort (), config .getFinalPort (), config .getAdminUsername (), config .getAdminPassword ());
81
+ public DataHub (HubConfig hubConfig ) {
82
+ init (hubConfig );
93
83
}
94
84
95
85
public DataHub (String host , String username , String password ) {
96
- this (host , DEFAULT_STAGING_REST_PORT , DEFAULT_FINAL_REST_PORT , username , password );
86
+ hubConfig = new HubConfig ();
87
+ hubConfig .host = host ;
88
+ hubConfig .adminUsername = username ;
89
+ hubConfig .adminPassword = password ;
90
+ init (hubConfig );
97
91
}
98
92
99
- public DataHub (String host , int stagingRestPort , int finalRestPort , String username , String password ) {
100
- config = new ManageConfig (host , 8002 , username , password );
93
+ private void init (HubConfig hubConfig ) {
94
+ this .hubConfig = hubConfig ;
95
+ config = new ManageConfig (hubConfig .host , 8002 , hubConfig .adminUsername , hubConfig .adminPassword );
101
96
client = new ManageClient (config );
102
- this .host = host ;
103
- this .stagingRestPort = stagingRestPort ;
104
- this .finalRestPort = finalRestPort ;
105
- this .username = username ;
106
- this .password = password ;
107
97
}
108
98
109
99
public void setAssetInstallTimeFile (File assetInstallTimeFile ) {
@@ -117,35 +107,47 @@ public void setAssetInstallTimeFile(File assetInstallTimeFile) {
117
107
public boolean isInstalled () {
118
108
ServerManager sm = new ServerManager (client );
119
109
DatabaseManager dm = new DatabaseManager (client );
120
- boolean stagingAppServerExists = sm .exists (STAGING_NAME );
121
- boolean finalAppServerExists = sm .exists (FINAL_NAME );
122
- boolean appserversOk = (stagingAppServerExists && finalAppServerExists );
110
+ boolean stagingAppServerExists = sm .exists (hubConfig .stagingHttpName );
111
+ boolean finalAppServerExists = sm .exists (hubConfig .finalHttpName );
112
+ boolean tracingAppServerExists = sm .exists (hubConfig .tracingHttpName );
113
+ boolean appserversOk = (stagingAppServerExists && finalAppServerExists && tracingAppServerExists );
123
114
124
- boolean stagingDbExists = dm .exists (STAGING_NAME );
125
- boolean finalDbExists = dm .exists (FINAL_NAME );
115
+ boolean stagingDbExists = dm .exists (hubConfig .stagingDbName );
116
+ boolean finalDbExists = dm .exists (hubConfig .finalDbName );
117
+ boolean tracingDbExists = dm .exists (hubConfig .stagingDbName );
126
118
127
119
boolean stagingForestsExist = false ;
128
120
boolean finalForestsExist = false ;
121
+ boolean tracingForestsExist = false ;
129
122
130
123
boolean stagingIndexesOn = false ;
131
124
boolean finalIndexesOn = false ;
125
+ boolean tracingIndexesOn = false ;
132
126
133
127
if (stagingDbExists ) {
134
- Fragment f = dm .getPropertiesAsXml (STAGING_NAME );
128
+ Fragment f = dm .getPropertiesAsXml (hubConfig . stagingDbName );
135
129
stagingIndexesOn = Boolean .parseBoolean (f .getElementValue ("//m:triple-index" ));
136
130
stagingIndexesOn = stagingIndexesOn && Boolean .parseBoolean (f .getElementValue ("//m:collection-lexicon" ));
137
- stagingForestsExist = (dm .getForestIds (STAGING_NAME ).size () == FORESTS_PER_HOST );
131
+ stagingForestsExist = (dm .getForestIds (hubConfig . stagingDbName ).size () == hubConfig . stagingForestsPerHost );
138
132
}
139
133
140
134
if (finalDbExists ) {
141
- Fragment f = dm .getPropertiesAsXml (FINAL_NAME );
135
+ Fragment f = dm .getPropertiesAsXml (hubConfig . finalDbName );
142
136
finalIndexesOn = Boolean .parseBoolean (f .getElementValue ("//m:triple-index" ));
143
137
finalIndexesOn = finalIndexesOn && Boolean .parseBoolean (f .getElementValue ("//m:collection-lexicon" ));
144
- finalForestsExist = (dm .getForestIds (FINAL_NAME ).size () == FORESTS_PER_HOST );
138
+ finalForestsExist = (dm .getForestIds (hubConfig .finalDbName ).size () == hubConfig .finalForestsPerHost );
139
+ }
140
+
141
+ if (tracingDbExists ) {
142
+ tracingIndexesOn = true ;
143
+ int forests = dm .getForestIds (hubConfig .tracingDbName ).size ();
144
+ tracingForestsExist = (forests == hubConfig .tracingForestsPerHost );
145
145
}
146
+
146
147
boolean dbsOk = (stagingDbExists && stagingIndexesOn &&
147
- finalDbExists && finalIndexesOn );
148
- boolean forestsOk = (stagingForestsExist && finalForestsExist );
148
+ finalDbExists && finalIndexesOn &&
149
+ tracingDbExists && tracingIndexesOn );
150
+ boolean forestsOk = (stagingForestsExist && finalForestsExist && tracingForestsExist );
149
151
150
152
return (appserversOk && dbsOk && forestsOk );
151
153
}
@@ -157,9 +159,9 @@ public boolean isInstalled() {
157
159
public void validateServer () throws ServerValidationException {
158
160
try {
159
161
AdminConfig adminConfig = new AdminConfig ();
160
- adminConfig .setHost (host );
161
- adminConfig .setUsername (username );
162
- adminConfig .setPassword (password );
162
+ adminConfig .setHost (hubConfig . host );
163
+ adminConfig .setUsername (hubConfig . adminUsername );
164
+ adminConfig .setPassword (hubConfig . adminPassword );
163
165
AdminManager am = new AdminManager (adminConfig );
164
166
String versionString = am .getServerVersion ();
165
167
int major = Integer .parseInt (versionString .substring (0 , 1 ));
@@ -175,16 +177,26 @@ public void validateServer() throws ServerValidationException {
175
177
176
178
private AppConfig getAppConfig () throws IOException {
177
179
AppConfig config = new AppConfig ();
178
- config .setHost (host );
179
- config .setRestPort (stagingRestPort );
180
- config .setName (HUB_NAME );
181
- config .setRestAdminUsername (username );
182
- config .setRestAdminPassword (password );
180
+ config .setHost (hubConfig .host );
181
+ config .setRestPort (hubConfig .stagingPort );
182
+ config .setName (hubConfig .name );
183
+ config .setRestAdminUsername (hubConfig .adminUsername );
184
+ config .setRestAdminPassword (hubConfig .adminPassword );
185
+ config .setModulesDatabaseName (hubConfig .modulesDbName );
186
+
183
187
List <String > paths = new ArrayList <String >();
184
188
paths .add (new ClassPathResource ("ml-modules" ).getPath ());
189
+
185
190
String configPath = new ClassPathResource ("ml-config" ).getPath ();
186
191
config .setConfigDir (new ConfigDir (new File (configPath )));
187
192
config .setModulePaths (paths );
193
+
194
+ Map <String , String > customTokens = config .getCustomTokens ();
195
+ customTokens .put ("%%STAGING_DATABASE%%" , hubConfig .stagingDbName );
196
+ customTokens .put ("%%FINAL_DATABASE%%" , hubConfig .finalDbName );
197
+ customTokens .put ("%%TRACING_DATABASE%%" , hubConfig .tracingDbName );
198
+ customTokens .put ("%%MODULES_DATABASE%%" , hubConfig .modulesDbName );
199
+
188
200
return config ;
189
201
}
190
202
@@ -193,6 +205,7 @@ private AppConfig getAppConfig() throws IOException {
193
205
* @throws IOException
194
206
*/
195
207
public void install () throws IOException {
208
+ LOGGER .debug ("Installing the Data Hub into MarkLogic" );
196
209
// clean up any lingering cache for deployed modules
197
210
PropertiesModuleManager moduleManager = new PropertiesModuleManager (this .assetInstallTimeFile );
198
211
moduleManager .deletePropertiesFile ();
@@ -206,14 +219,15 @@ public void install() throws IOException {
206
219
207
220
private DatabaseClient getDatabaseClient (int port ) {
208
221
AppConfig config = new AppConfig ();
209
- config .setHost (host );
210
- config .setName (HUB_NAME );
211
- config .setRestAdminUsername (username );
212
- config .setRestAdminPassword (password );
213
- DatabaseClient client = DatabaseClientFactory .newClient (host , port , username , password ,
222
+ config .setHost (hubConfig . host );
223
+ config .setName (hubConfig . name );
224
+ config .setRestAdminUsername (hubConfig . adminUsername );
225
+ config .setRestAdminPassword (hubConfig . adminPassword );
226
+ DatabaseClient client = DatabaseClientFactory .newClient (hubConfig . host , port , hubConfig . adminUsername , hubConfig . adminPassword ,
214
227
config .getRestAuthentication (), config .getRestSslContext (), config .getRestSslHostnameVerifier ());
215
228
return client ;
216
229
}
230
+
217
231
/**
218
232
* Installs User Provided modules into the Data Hub
219
233
*
@@ -224,15 +238,12 @@ private DatabaseClient getDatabaseClient(int port) {
224
238
* @throws IOException
225
239
*/
226
240
public Set <File > installUserModules (String pathToUserModules ) throws IOException {
227
- AppConfig config = new AppConfig ();
228
- config .setHost (host );
229
- config .setRestPort (finalRestPort );
230
- config .setName (HUB_NAME );
231
- config .setRestAdminUsername (username );
232
- config .setRestAdminPassword (password );
241
+ LOGGER .debug ("Installing user modules into MarkLogic" );
233
242
234
- DatabaseClient stagingClient = getDatabaseClient (stagingRestPort );
235
- DatabaseClient finalClient = getDatabaseClient (finalRestPort );
243
+ AppConfig config = getAppConfig ();
244
+
245
+ DatabaseClient stagingClient = getDatabaseClient (hubConfig .stagingPort );
246
+ DatabaseClient finalClient = getDatabaseClient (hubConfig .finalPort );
236
247
237
248
238
249
Set <File > loadedFiles = new HashSet <File >();
@@ -274,7 +285,8 @@ else if (isConformanceDir) {
274
285
}
275
286
276
287
public JsonNode validateUserModules () {
277
- DatabaseClient client = getDatabaseClient (stagingRestPort );
288
+ LOGGER .debug ("validating user modules" );
289
+ DatabaseClient client = getDatabaseClient (hubConfig .stagingPort );
278
290
EntitiesValidator ev = new EntitiesValidator (client );
279
291
return ev .validate ();
280
292
}
@@ -290,22 +302,27 @@ private List<Command> getCommands(AppConfig config) {
290
302
291
303
// Databases
292
304
List <Command > dbCommands = new ArrayList <Command >();
293
- DeployHubDatabaseCommand staging = new DeployHubDatabaseCommand (STAGING_NAME );
294
- staging .setForestsPerHost (FORESTS_PER_HOST );
305
+ DeployHubDatabaseCommand staging = new DeployHubDatabaseCommand (hubConfig . stagingDbName );
306
+ staging .setForestsPerHost (hubConfig . stagingForestsPerHost );
295
307
dbCommands .add (staging );
296
308
297
- DeployHubDatabaseCommand finalDb = new DeployHubDatabaseCommand (FINAL_NAME );
298
- finalDb .setForestsPerHost (FORESTS_PER_HOST );
309
+ DeployHubDatabaseCommand finalDb = new DeployHubDatabaseCommand (hubConfig . finalDbName );
310
+ finalDb .setForestsPerHost (hubConfig . finalForestsPerHost );
299
311
dbCommands .add (finalDb );
300
312
301
- dbCommands .add (new DeployModulesDatabaseCommand (MODULES_DB_NAME ));
313
+ DeployHubDatabaseCommand tracingDb = new DeployHubDatabaseCommand (hubConfig .tracingDbName );
314
+ tracingDb .setForestsPerHost (hubConfig .tracingForestsPerHost );
315
+ dbCommands .add (tracingDb );
316
+
317
+ dbCommands .add (new DeployModulesDatabaseCommand (hubConfig .modulesDbName ));
302
318
dbCommands .add (new DeployTriggersDatabaseCommand ());
303
319
dbCommands .add (new DeploySchemasDatabaseCommand ());
304
320
commands .addAll (dbCommands );
305
321
306
322
// App Servers
307
- commands .add (new DeployRestApiCommand (STAGING_NAME , stagingRestPort ));
308
- commands .add (new DeployRestApiCommand (FINAL_NAME , finalRestPort ));
323
+ commands .add (new DeployRestApiCommand (hubConfig .stagingHttpName , hubConfig .stagingPort ));
324
+ commands .add (new DeployRestApiCommand (hubConfig .finalHttpName , hubConfig .finalPort ));
325
+ commands .add (new DeployRestApiCommand (hubConfig .tracingHttpName , hubConfig .tracePort ));
309
326
310
327
// Modules
311
328
commands .add (new LoadModulesCommand ());
@@ -320,6 +337,7 @@ private List<Command> getCommands(AppConfig config) {
320
337
* @throws IOException
321
338
*/
322
339
public void uninstall () throws IOException {
340
+ LOGGER .debug ("Uninstalling the Data Hub from MarkLogic" );
323
341
AdminManager manager = new AdminManager ();
324
342
AppConfig config = getAppConfig ();
325
343
SimpleAppDeployer deployer = new SimpleAppDeployer (client , manager );
0 commit comments