Skip to content

Commit fb2286b

Browse files
committed
fixed #308
cleaned up the project organization for 1.0
1 parent 4a73398 commit fb2286b

File tree

81 files changed

+637
-370
lines changed

Some content is hidden

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

81 files changed

+637
-370
lines changed

marklogic-data-hub/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
id 'com.jfrog.bintray' version '1.7.2'
66
id 'com.marklogic.ml-gradle' version '2.3.4'
77
id 'com.moowork.node' version '0.13'
8+
id 'com.github.hauner.jarTest' version '1.0'
89
}
910

1011
repositories {
@@ -22,7 +23,7 @@ dependencies {
2223
compile 'org.springframework.batch:spring-batch-core:3.0.6.RELEASE'
2324
compile 'org.springframework:spring-jdbc:4.2.6.RELEASE'
2425
compile 'com.marklogic:java-client-api:3.0.5'
25-
compile 'com.marklogic:ml-javaclient-util:2.9.1'
26+
compile 'com.marklogic:ml-javaclient-util:2.10.0'
2627
compile 'com.marklogic:ml-app-deployer:2.3.0'
2728
compile 'com.marklogic:marklogic-spring-batch-core:0.7.0'
2829
compile 'commons-io:commons-io:2.4'

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

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@
5151
import com.marklogic.client.helper.LoggingObject;
5252
import com.marklogic.client.io.JacksonHandle;
5353
import com.marklogic.client.util.RequestParameters;
54-
import com.marklogic.hub.commands.DeployHubDatabasesCommand;
55-
import com.marklogic.hub.commands.LoadHubModulesCommand;
56-
import com.marklogic.hub.commands.LoadUserModulesCommand;
54+
import com.marklogic.hub.deploy.commands.DeployHubDatabasesCommand;
55+
import com.marklogic.hub.deploy.commands.LoadHubModulesCommand;
56+
import com.marklogic.hub.deploy.commands.LoadUserModulesCommand;
57+
import com.marklogic.hub.deploy.HubAppDeployer;
58+
import com.marklogic.hub.deploy.util.HubDeployStatusListener;
59+
import com.marklogic.hub.error.ServerValidationException;
5760
import com.marklogic.mgmt.ManageClient;
5861
import com.marklogic.mgmt.ManageConfig;
5962
import com.marklogic.mgmt.admin.AdminConfig;
@@ -94,19 +97,24 @@ public DataHub(String host, String username, String password) {
9497

9598
private void init(HubConfig hubConfig) {
9699
this.hubConfig = hubConfig;
97-
config = new ManageConfig(hubConfig.host, 8002, hubConfig.username, hubConfig.password);
98-
client = new ManageClient(config);
99-
databaseManager = new DatabaseManager(client);
100-
serverManager = new ServerManager(client);
101-
102-
AdminConfig adminConfig = new AdminConfig();
103-
adminConfig.setHost(hubConfig.host);
104-
adminConfig.setUsername(hubConfig.username);
105-
adminConfig.setPassword(hubConfig.password);
106-
adminManager = new AdminManager(adminConfig);
100+
if (hubConfig.username != null && hubConfig.password != null) {
101+
config = new ManageConfig(hubConfig.host, 8002, hubConfig.username, hubConfig.password);
102+
client = new ManageClient(config);
103+
databaseManager = new DatabaseManager(client);
104+
serverManager = new ServerManager(client);
105+
106+
AdminConfig adminConfig = new AdminConfig();
107+
adminConfig.setHost(hubConfig.host);
108+
adminConfig.setUsername(hubConfig.adminUsername);
109+
adminConfig.setPassword(hubConfig.adminPassword);
110+
adminManager = new AdminManager(adminConfig);
111+
}
112+
else {
113+
logger.info("Missing username and/or password.");
114+
}
107115
}
108116

109-
public void setAdminManager(AdminManager manager) {
117+
void setAdminManager(AdminManager manager) {
110118
this.adminManager = manager;
111119
}
112120

@@ -203,6 +211,10 @@ private AppConfig getAppConfig() {
203211
return config;
204212
}
205213

214+
/**
215+
* Updates the given AppConfig with values from this DataHub
216+
* @param config - the AppConfig instance to update
217+
*/
206218
public void updateAppConfig(AppConfig config) {
207219
config.setHost(hubConfig.host);
208220
config.setRestPort(hubConfig.stagingPort);
@@ -253,6 +265,10 @@ public void updateAppConfig(AppConfig config) {
253265
customTokens.put("%%mlModulesDbName%%", hubConfig.modulesDbName);
254266
customTokens.put("%%mlTriggersDbName%%", hubConfig.triggersDbName);
255267
customTokens.put("%%mlSchemasDbName%%", hubConfig.schemasDbName);
268+
269+
customTokens.put("%%mlHubUserName%%", hubConfig.hubUserName);
270+
customTokens.put("%%mlHubUserPassword%%", hubConfig.hubUserPassword);
271+
customTokens.put("%%mlHubUserRole%%", hubConfig.hubUserRole);
256272
}
257273

258274
public void initProject() {
@@ -432,11 +448,18 @@ private List<Command> getCommands(AppConfig config) {
432448
return commands;
433449
}
434450

451+
/**
452+
* Installs the data hub configuration and server-side modules into MarkLogic
453+
*/
454+
public void install() {
455+
install(null);
456+
}
457+
435458
/**
436459
* Installs the data hub configuration and server-side modules into MarkLogic
437460
* @param listener - the callback method to receive status updates
438461
*/
439-
public void install(StatusListener listener) {
462+
public void install(HubDeployStatusListener listener) {
440463
initProject();
441464

442465
logger.info("Installing the Data Hub into MarkLogic");
@@ -447,11 +470,18 @@ public void install(StatusListener listener) {
447470
deployer.deploy(config);
448471
}
449472

473+
/**
474+
* Uninstalls the data hub configuration and server-side modules from MarkLogic
475+
*/
476+
public void uninstall() {
477+
uninstall(null);
478+
}
479+
450480
/**
451481
* Uninstalls the data hub configuration and server-side modules from MarkLogic
452482
* @param listener - the callback method to receive status updates
453483
*/
454-
public void uninstall(StatusListener listener) {
484+
public void uninstall(HubDeployStatusListener listener) {
455485
logger.debug("Uninstalling the Data Hub from MarkLogic");
456486

457487
AppConfig config = getAppConfig();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public Debugging(DatabaseClient client) {
1616
}
1717

1818
/**
19-
* Enables tracing
19+
* Enables debugging
2020
*/
2121
public void enable() {
2222
RequestParameters params = new RequestParameters();
@@ -25,7 +25,7 @@ public void enable() {
2525
}
2626

2727
/**
28-
* Disables tracing
28+
* Disables debugging
2929
*/
3030
public void disable() {
3131
RequestParameters params = new RequestParameters();
@@ -34,7 +34,7 @@ public void disable() {
3434
}
3535

3636
/**
37-
* Determines if the hub has tracing enabled or not
37+
* Determines if the hub has debugging enabled or not
3838
*
3939
* @return - true if enabled, false otherwise
4040
*/

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

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.marklogic.client.io.DOMHandle;
2424
import com.marklogic.client.util.RequestParameters;
2525
import com.marklogic.hub.flow.Flow;
26+
import com.marklogic.hub.flow.FlowComplexity;
2627
import com.marklogic.hub.flow.FlowType;
2728
import com.marklogic.hub.flow.SimpleFlow;
2829
import com.marklogic.spring.batch.hub.FlowConfig;
@@ -51,21 +52,10 @@ public class FlowManager extends ResourceManager {
5152
private DatabaseClient client;
5253
private HubConfig hubConfig;
5354

54-
private DatabaseClient getClient() {
55-
DatabaseClientFactory.Authentication authMethod = DatabaseClientFactory.Authentication
56-
.valueOf(hubConfig.authMethod.toUpperCase());
57-
58-
return DatabaseClientFactory.newClient(
59-
hubConfig.host,
60-
hubConfig.stagingPort,
61-
hubConfig.username,
62-
hubConfig.password, authMethod);
63-
}
64-
6555
public FlowManager(HubConfig hubConfig) {
6656
super();
6757
this.hubConfig = hubConfig;
68-
this.client = getClient();
58+
this.client = hubConfig.newStagingClient();
6959
this.client.init(NAME, this);
7060
}
7161

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

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@
1616
package com.marklogic.hub;
1717

1818
import com.fasterxml.jackson.annotation.JsonIgnore;
19+
import com.marklogic.client.DatabaseClient;
20+
import com.marklogic.client.DatabaseClientFactory;
1921
import com.marklogic.client.helper.LoggingObject;
2022

2123
import java.io.File;
2224
import java.io.FileInputStream;
2325
import java.io.InputStream;
2426
import java.util.Properties;
2527

28+
/**
29+
* A class for passing around the Data Hub's Configuration
30+
*/
2631
public class HubConfig extends LoggingObject {
2732

2833
public static final String DEFAULT_HOST = "localhost";
@@ -35,13 +40,16 @@ public class HubConfig extends LoggingObject {
3540
public static final String DEFAULT_TRIGGERS_DB_NAME = "data-hub-TRIGGERS";
3641
public static final String DEFAULT_SCHEMAS_DB_NAME = "data-hub-SCHEMAS";
3742

43+
public static final String DEFAULT_HUB_USER_ROLE = "data-hub-user";
44+
public static final String DEFAULT_HUB_USER_NAME = "data-hub-user";
45+
3846
public static final Integer DEFAULT_STAGING_PORT = 8010;
3947
public static final Integer DEFAULT_FINAL_PORT = 8011;
4048
public static final Integer DEFAULT_TRACE_PORT = 8012;
4149
public static final Integer DEFAULT_JOB_PORT = 8013;
4250

4351
public static final String DEFAULT_APP_NAME = "data-hub";
44-
public static final String DEFAULT_MODULES_PATH = "src/data-hub";
52+
public static final String DEFAULT_PROJECT_DIR = ".";
4553

4654
public static final String DEFAULT_AUTH_METHOD = "digest";
4755

@@ -55,6 +63,10 @@ public class HubConfig extends LoggingObject {
5563
@JsonIgnore
5664
public String password;
5765

66+
public String adminUsername;
67+
@JsonIgnore
68+
public String adminPassword;
69+
5870
public String host = DEFAULT_HOST;
5971

6072
public String stagingDbName = DEFAULT_STAGING_NAME;
@@ -81,12 +93,16 @@ public class HubConfig extends LoggingObject {
8193
public String triggersDbName = DEFAULT_TRIGGERS_DB_NAME;
8294
public String schemasDbName = DEFAULT_SCHEMAS_DB_NAME;
8395

96+
public String hubUserName = DEFAULT_HUB_USER_NAME;
97+
public String hubUserPassword = DEFAULT_HUB_USER_NAME;
98+
public String hubUserRole = DEFAULT_HUB_USER_ROLE;
99+
84100
public String authMethod = DEFAULT_AUTH_METHOD;
85101

86102
public String projectDir;
87103

88104
public HubConfig() {
89-
this(DEFAULT_MODULES_PATH);
105+
this(DEFAULT_PROJECT_DIR);
90106
}
91107

92108
public HubConfig(String projectDir) {
@@ -116,7 +132,7 @@ private Properties getProperties(String environment) {
116132
return environmentProperties;
117133
}
118134

119-
public void loadConfigurationFromProperties(Properties environmentProperties) {
135+
private void loadConfigurationFromProperties(Properties environmentProperties) {
120136
name = getEnvPropString(environmentProperties, "mlAppName", name);
121137

122138
host = getEnvPropString(environmentProperties, "mlHost", host);
@@ -151,6 +167,58 @@ public void loadConfigurationFromProperties(Properties environmentProperties) {
151167
password = getEnvPropString(environmentProperties, "mlAdminPassword", password);
152168
}
153169

170+
/**
171+
* Creates a new DatabaseClient for accessing the Staging database
172+
* @return - a DatabaseClient
173+
*/
174+
public DatabaseClient newStagingClient() {
175+
return DatabaseClientFactory.newClient(
176+
host,
177+
stagingPort,
178+
username,
179+
password,
180+
DatabaseClientFactory.Authentication.valueOf(authMethod.toUpperCase()));
181+
}
182+
183+
/**
184+
* Creates a new DatabaseClient for accessing the Final database
185+
* @return - a DatabaseClient
186+
*/
187+
public DatabaseClient newFinalClient() {
188+
return DatabaseClientFactory.newClient(
189+
host,
190+
finalPort,
191+
username,
192+
password,
193+
DatabaseClientFactory.Authentication.valueOf(authMethod.toUpperCase()));
194+
}
195+
196+
/**
197+
* Creates a new DatabaseClient for accessing the Job database
198+
* @return - a DatabaseClient
199+
*/
200+
public DatabaseClient newJobDbClient() {
201+
return DatabaseClientFactory.newClient(
202+
host,
203+
jobPort,
204+
username,
205+
password,
206+
DatabaseClientFactory.Authentication.valueOf(authMethod.toUpperCase()));
207+
}
208+
209+
/**
210+
* Creates a new DatabaseClient for accessing the Trace database
211+
* @return - a DatabaseClient
212+
*/
213+
public DatabaseClient newTraceDbClient() {
214+
return DatabaseClientFactory.newClient(
215+
host,
216+
tracePort,
217+
username,
218+
password,
219+
DatabaseClientFactory.Authentication.valueOf(authMethod.toUpperCase()));
220+
}
221+
154222
private String getEnvPropString(Properties environmentProperties, String key, String fallback) {
155223
String value = environmentProperties.getProperty(key);
156224
if (value == null) {
@@ -172,7 +240,7 @@ private int getEnvPropInteger(Properties environmentProperties, String key, int
172240
}
173241

174242
private void loadConfigurationFromFile(Properties configProperties, String fileName) {
175-
InputStream is = null;
243+
InputStream is;
176244
try {
177245
File file = new File(this.projectDir, fileName);
178246
if(file.exists()) {
@@ -182,7 +250,7 @@ private void loadConfigurationFromFile(Properties configProperties, String fileN
182250
}
183251
}
184252
catch ( Exception e ) {
185-
is = null;
253+
e.printStackTrace();
186254
}
187255
}
188256

0 commit comments

Comments
 (0)