Skip to content

Commit 81159f8

Browse files
committed
Merge pull request #195 from paxtonhare/138_tests
adding trace server, db, forests
2 parents fea3b91 + 76f88b9 commit 81159f8

File tree

43 files changed

+965
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+965
-308
lines changed

examples/gradle-advanced/build.gradle

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ ext {
3131
modulesDatabaseName = mlModulesDbName
3232
triggersDatabaseName = mlTriggersDbName
3333
schemasDatabaseName = mlSchemasDbName
34-
restPort = Integer.parseInt(mlStagingAppserverPort)
34+
restPort = Integer.parseInt(mlStagingPort)
3535

3636
// Configure custom tokens for our json files
3737
customTokens.put("%%STAGING_SERVER_NAME%%", mlStagingAppserverName)
38-
customTokens.put("%%STAGING_SERVER_PORT%%", mlStagingAppserverPort)
38+
customTokens.put("%%STAGING_SERVER_PORT%%", mlStagingPort)
3939
customTokens.put("%%STAGING_DB_NAME%%", mlStagingDbName)
4040

4141
customTokens.put("%%FINAL_SERVER_NAME%%", mlFinalAppserverName)
42-
customTokens.put("%%FINAL_SERVER_PORT%%", mlFinalAppserverPort)
42+
customTokens.put("%%FINAL_SERVER_PORT%%", mlFinalPort)
4343
customTokens.put("%%FINAL_DB_NAME%%", mlFinalDbName)
4444

45+
customTokens.put("%%TRACE_SERVER_NAME%%", mlTraceAppserverName)
46+
customTokens.put("%%TRACE_SERVER_PORT%%", mlTracePort)
47+
customTokens.put("%%TRACE_DB_NAME%%", mlTraceDbName)
48+
4549
customTokens.put("%%MODULES_DB_NAME%%", mlModulesDbName)
4650
}
4751
}
@@ -58,14 +62,22 @@ ext {
5862

5963
// install the staging database
6064
def stagingDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("staging-database.json")
65+
stagingDbCommand.setForestsPerHost(Integer.parseInt(mlStagingForestsPerHost));
6166
mlAppDeployer.commands.add(stagingDbCommand)
6267
mlDatabaseCommands.add(stagingDbCommand)
6368

6469
// install the final database
6570
def finalDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("final-database.json")
71+
finalDbCommand.setForestsPerHost(Integer.parseInt(mlFinalForestsPerHost));
6672
mlAppDeployer.commands.add(finalDbCommand)
6773
mlDatabaseCommands.add(finalDbCommand)
6874

75+
// install the trace database
76+
def traceDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("trace-database.json")
77+
traceDbCommand.setForestsPerHost(Integer.parseInt(mlTraceForestsPerHost));
78+
mlAppDeployer.commands.add(traceDbCommand)
79+
mlDatabaseCommands.add(traceDbCommand)
80+
6981
// install the modules database
7082
def modulesDbCommand = new com.marklogic.appdeployer.command.databases.DeployDatabaseCommand("modules-database.json")
7183
mlAppDeployer.commands.add(modulesDbCommand)

examples/gradle-advanced/gradle.properties

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ mlHost=localhost
22
mlAppName=gradle-advanced-example
33

44
mlStagingAppserverName=data-hub-STAGING
5-
mlStagingAppserverPort=8100
5+
mlStagingPort=8100
66
mlStagingDbName=data-hub-STAGING
7+
mlStagingForestsPerHost=4
78

89
mlFinalAppserverName=data-hub-FINAL
9-
mlFinalAppserverPort=8101
10+
mlFinalPort=8101
1011
mlFinalDbName=data-hub-FINAL
12+
mlFinalForestsPerHost=4
13+
14+
mlTraceAppserverName=data-hub-TRACING
15+
mlTracePort=8102
16+
mlTraceDbName=data-hub-TRACING
17+
mlTraceForestsPerHost=1
1118

1219
mlModulesDbName=data-hub-MODULES
1320
mlTriggersDbName=data-hub-TRIGGERS
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"database-name": "%%TRACE_DB_NAME%%",
3+
"range-element-index": [],
4+
"schema-database": "%%SCHEMAS_DATABASE%%",
5+
"triggers-database": "%%TRIGGERS_DATABASE%%",
6+
"triple-index": true,
7+
"collection-lexicon": true,
8+
"uri-lexicon": true
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"server-name": "%%TRACE_SERVER_NAME%%",
3+
"server-type": "http",
4+
"root": "/",
5+
"group-name": "%%GROUP%%",
6+
"port": %%TRACE_SERVER_PORT%%,
7+
"modules-database": "%%MODULES_DB_NAME%%",
8+
"content-database": "%%TRACE_DB_NAME%%",
9+
"authentication": "digest",
10+
"default-error-format": "json",
11+
"error-handler": "/MarkLogic/rest-api/error-handler.xqy",
12+
"url-rewriter": "/MarkLogic/rest-api/rewriter.xml",
13+
"rewrite-resolves-globally": true
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mlHost=localhost
22
mlStagingPort=8100
33
mlFinalPort=8101
4+
mlTracePort=8102
45
hubModulesPath=./plugins

marklogic-data-hub/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mlConfigDir=marklogic-data-hub/src/main/resources/ml-config
33
publishUrl=file:../marklogic-data-hub/releases
44
mlStagingRestPort=8010
55
mlFinalRestPort=8011
6+
mlTraceRestPort=8012
67
mlUsername=admin
78
mlPassword=admin
89
mlHost=localhost

marklogic-data-hub/src/main/java/com/marklogic/hub/DataHub.java

Lines changed: 81 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.ArrayList;
2727
import java.util.HashSet;
2828
import java.util.List;
29+
import java.util.Map;
2930
import java.util.Set;
3031

3132
import org.slf4j.Logger;
@@ -70,40 +71,29 @@
7071
public class DataHub {
7172

7273
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+
7675
private ManageConfig config;
7776
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;
8577

8678
private File assetInstallTimeFile = new File("./assetInstallTime.properties");
79+
private HubConfig hubConfig;
8780

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);
9383
}
9484

9585
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);
9791
}
9892

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);
10196
client = new ManageClient(config);
102-
this.host = host;
103-
this.stagingRestPort = stagingRestPort;
104-
this.finalRestPort = finalRestPort;
105-
this.username = username;
106-
this.password = password;
10797
}
10898

10999
public void setAssetInstallTimeFile(File assetInstallTimeFile) {
@@ -117,35 +107,47 @@ public void setAssetInstallTimeFile(File assetInstallTimeFile) {
117107
public boolean isInstalled() {
118108
ServerManager sm = new ServerManager(client);
119109
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);
123114

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);
126118

127119
boolean stagingForestsExist = false;
128120
boolean finalForestsExist = false;
121+
boolean tracingForestsExist = false;
129122

130123
boolean stagingIndexesOn = false;
131124
boolean finalIndexesOn = false;
125+
boolean tracingIndexesOn = false;
132126

133127
if (stagingDbExists) {
134-
Fragment f = dm.getPropertiesAsXml(STAGING_NAME);
128+
Fragment f = dm.getPropertiesAsXml(hubConfig.stagingDbName);
135129
stagingIndexesOn = Boolean.parseBoolean(f.getElementValue("//m:triple-index"));
136130
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);
138132
}
139133

140134
if (finalDbExists) {
141-
Fragment f = dm.getPropertiesAsXml(FINAL_NAME);
135+
Fragment f = dm.getPropertiesAsXml(hubConfig.finalDbName);
142136
finalIndexesOn = Boolean.parseBoolean(f.getElementValue("//m:triple-index"));
143137
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);
145145
}
146+
146147
boolean dbsOk = (stagingDbExists && stagingIndexesOn &&
147-
finalDbExists && finalIndexesOn);
148-
boolean forestsOk = (stagingForestsExist && finalForestsExist);
148+
finalDbExists && finalIndexesOn &&
149+
tracingDbExists && tracingIndexesOn);
150+
boolean forestsOk = (stagingForestsExist && finalForestsExist && tracingForestsExist);
149151

150152
return (appserversOk && dbsOk && forestsOk);
151153
}
@@ -157,9 +159,9 @@ public boolean isInstalled() {
157159
public void validateServer() throws ServerValidationException {
158160
try {
159161
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);
163165
AdminManager am = new AdminManager(adminConfig);
164166
String versionString = am.getServerVersion();
165167
int major = Integer.parseInt(versionString.substring(0, 1));
@@ -175,16 +177,26 @@ public void validateServer() throws ServerValidationException {
175177

176178
private AppConfig getAppConfig() throws IOException {
177179
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+
183187
List<String> paths = new ArrayList<String>();
184188
paths.add(new ClassPathResource("ml-modules").getPath());
189+
185190
String configPath = new ClassPathResource("ml-config").getPath();
186191
config.setConfigDir(new ConfigDir(new File(configPath)));
187192
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+
188200
return config;
189201
}
190202

@@ -193,6 +205,7 @@ private AppConfig getAppConfig() throws IOException {
193205
* @throws IOException
194206
*/
195207
public void install() throws IOException {
208+
LOGGER.debug("Installing the Data Hub into MarkLogic");
196209
// clean up any lingering cache for deployed modules
197210
PropertiesModuleManager moduleManager = new PropertiesModuleManager(this.assetInstallTimeFile);
198211
moduleManager.deletePropertiesFile();
@@ -206,14 +219,15 @@ public void install() throws IOException {
206219

207220
private DatabaseClient getDatabaseClient(int port) {
208221
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,
214227
config.getRestAuthentication(), config.getRestSslContext(), config.getRestSslHostnameVerifier());
215228
return client;
216229
}
230+
217231
/**
218232
* Installs User Provided modules into the Data Hub
219233
*
@@ -224,15 +238,12 @@ private DatabaseClient getDatabaseClient(int port) {
224238
* @throws IOException
225239
*/
226240
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");
233242

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);
236247

237248

238249
Set<File> loadedFiles = new HashSet<File>();
@@ -274,7 +285,8 @@ else if (isConformanceDir) {
274285
}
275286

276287
public JsonNode validateUserModules() {
277-
DatabaseClient client = getDatabaseClient(stagingRestPort);
288+
LOGGER.debug("validating user modules");
289+
DatabaseClient client = getDatabaseClient(hubConfig.stagingPort);
278290
EntitiesValidator ev = new EntitiesValidator(client);
279291
return ev.validate();
280292
}
@@ -290,22 +302,27 @@ private List<Command> getCommands(AppConfig config) {
290302

291303
// Databases
292304
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);
295307
dbCommands.add(staging);
296308

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);
299311
dbCommands.add(finalDb);
300312

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));
302318
dbCommands.add(new DeployTriggersDatabaseCommand());
303319
dbCommands.add(new DeploySchemasDatabaseCommand());
304320
commands.addAll(dbCommands);
305321

306322
// 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));
309326

310327
// Modules
311328
commands.add(new LoadModulesCommand());
@@ -320,6 +337,7 @@ private List<Command> getCommands(AppConfig config) {
320337
* @throws IOException
321338
*/
322339
public void uninstall() throws IOException {
340+
LOGGER.debug("Uninstalling the Data Hub from MarkLogic");
323341
AdminManager manager = new AdminManager();
324342
AppConfig config = getAppConfig();
325343
SimpleAppDeployer deployer = new SimpleAppDeployer(client, manager);

0 commit comments

Comments
 (0)