Skip to content

Commit 01da647

Browse files
committed
fixed #389
1 parent 05f8a79 commit 01da647

File tree

9 files changed

+108
-88
lines changed

9 files changed

+108
-88
lines changed

marklogic-data-hub/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ if (!(
8686
gradle.startParameter.taskNames*.toLowerCase().contains("bootrun") ||
8787
gradle.startParameter.taskNames*.toLowerCase().contains("test") ||
8888
gradle.startParameter.taskNames*.toLowerCase().contains("publishplugins") ||
89+
gradle.startParameter.taskNames*.toLowerCase().contains("publishtomavenlocal") ||
8990
gradle.startParameter.taskNames*.toLowerCase().contains("bintrayUpload")
9091
)
9192
) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.marklogic.appdeployer.command.Command;
2222
import com.marklogic.appdeployer.command.CommandMapBuilder;
2323
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
24+
import com.marklogic.appdeployer.command.forests.DeployCustomForestsCommand;
2425
import com.marklogic.appdeployer.command.security.DeployRolesCommand;
2526
import com.marklogic.appdeployer.command.security.DeployUsersCommand;
2627
import com.marklogic.appdeployer.impl.SimpleAppDeployer;
@@ -336,6 +337,10 @@ public Map<String, List<Command>> getCommands() {
336337
List<Command> mimetypeCommands = commandMap.get("mlMimetypeCommands");
337338
mimetypeCommands.add(0, new DeployHubMimetypesCommand(hubConfig));
338339

340+
List<Command> forestCommands = commandMap.get("mlForestCommands");
341+
DeployCustomForestsCommand deployCustomForestsCommand = (DeployCustomForestsCommand)forestCommands.get(0);
342+
deployCustomForestsCommand.setCustomForestsPath(hubConfig.customForestPath);
343+
339344
return commandMap;
340345
}
341346

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

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class HubConfig {
4949
public static final String OLD_HUB_CONFIG_DIR = "marklogic-config";
5050
public static final String HUB_CONFIG_DIR = "hub-internal-config";
5151
public static final String USER_CONFIG_DIR = "user-config";
52-
public static final String SEARCH_OPTIONS_FILE = "all-search-options.xml";
5352

5453
public static final String DEFAULT_HOST = "localhost";
5554

@@ -79,6 +78,8 @@ public class HubConfig {
7978

8079
public static final Integer DEFAULT_FORESTS_PER_HOST = 4;
8180

81+
public static final String DEFAULT_CUSTOM_FOREST_PATH = "forests";
82+
8283
private static final String GRADLE_PROPERTIES_FILENAME = "gradle.properties";
8384

8485
private String username;
@@ -120,8 +121,13 @@ public class HubConfig {
120121
public String jobAuthMethod = DEFAULT_AUTH_METHOD;
121122

122123
public String modulesDbName = DEFAULT_MODULES_DB_NAME;
124+
public Integer modulesForestsPerHost = 1;
125+
123126
public String triggersDbName = DEFAULT_TRIGGERS_DB_NAME;
127+
public Integer triggersForestsPerHost = 1;
128+
124129
public String schemasDbName = DEFAULT_SCHEMAS_DB_NAME;
130+
public Integer schemasForestsPerHost = 1;
125131

126132
public Integer appServicesPort = DEFAULT_APP_SERVICES_PORT;
127133
public Integer adminPort = DEFAULT_ADMIN_PORT;
@@ -130,6 +136,8 @@ public class HubConfig {
130136
public String hubRoleName = DEFAULT_ROLE_NAME;
131137
public String hubUserName = DEFAULT_USER_NAME;
132138

139+
public String customForestPath = DEFAULT_CUSTOM_FOREST_PATH;
140+
133141
public String projectDir;
134142

135143
private Properties environmentProperties;
@@ -208,9 +216,16 @@ public void loadConfigurationFromProperties(Properties environmentProperties) {
208216
jobPort = getEnvPropInteger(environmentProperties, "mlJobPort", jobPort);
209217
jobAuthMethod = getEnvPropString(environmentProperties, "mlJobAuth", jobAuthMethod);
210218

219+
customForestPath = getEnvPropString(environmentProperties, "mlCustomForestPath", customForestPath);
220+
211221
modulesDbName = getEnvPropString(environmentProperties, "mlModulesDbName", modulesDbName);
222+
modulesForestsPerHost = getEnvPropInteger(environmentProperties, "mlModulesForestsPerHost", modulesForestsPerHost);
223+
212224
triggersDbName = getEnvPropString(environmentProperties, "mlTriggersDbName", triggersDbName);
225+
triggersForestsPerHost = getEnvPropInteger(environmentProperties, "mlTriggersForestsPerHost", triggersForestsPerHost);
226+
213227
schemasDbName = getEnvPropString(environmentProperties, "mlSchemasDbName", schemasDbName);
228+
schemasForestsPerHost = getEnvPropInteger(environmentProperties, "mlSchemasForestsPerHost", schemasForestsPerHost);
214229

215230
hubRoleName = getEnvPropString(environmentProperties, "mlHubUserRole", hubRoleName);
216231
hubUserName = getEnvPropString(environmentProperties, "mlHubUserName", hubUserName);
@@ -521,35 +536,7 @@ public AppConfig getAppConfig() {
521536
return config;
522537
}
523538

524-
public void updateAppConfig(AppConfig config) {
525-
config.setHost(host);
526-
config.setRestPort(stagingPort);
527-
config.setAppServicesPort(appServicesPort);
528-
config.setRestAdminUsername(getRestAdminUsername());
529-
config.setRestAdminPassword(getRestAdminPassword());
530-
config.setModulesDatabaseName(modulesDbName);
531-
532-
config.setTriggersDatabaseName(triggersDbName);
533-
config.setSchemasDatabaseName(schemasDbName);
534-
config.setModulesDatabaseName(modulesDbName);
535-
536-
config.setReplaceTokensInModules(true);
537-
config.setUseRoxyTokenPrefix(false);
538-
539-
HashMap<String, Integer> forestCounts = new HashMap<>();
540-
forestCounts.put(stagingDbName, stagingForestsPerHost);
541-
forestCounts.put(finalDbName, finalForestsPerHost);
542-
forestCounts.put(traceDbName, traceForestsPerHost);
543-
forestCounts.put(modulesDbName, 1);
544-
config.setForestCounts(forestCounts);
545-
546-
ConfigDir configDir = new ConfigDir(getUserConfigDir().toFile());
547-
config.setConfigDir(configDir);
548-
549-
config.setSchemasPath(getUserConfigDir().resolve("schemas").toString());
550-
551-
Map<String, String> customTokens = config.getCustomTokens();
552-
539+
public Map<String, String> getCustomTokens(Map<String, String> customTokens) {
553540
customTokens.put("%%mlStagingAppserverName%%", stagingHttpName);
554541
customTokens.put("\"%%mlStagingPort%%\"", stagingPort.toString());
555542
customTokens.put("%%mlStagingDbName%%", stagingDbName);
@@ -571,12 +558,64 @@ public void updateAppConfig(AppConfig config) {
571558
customTokens.put("%%mlJobForestsPerHost%%", jobForestsPerHost.toString());
572559

573560
customTokens.put("%%mlModulesDbName%%", modulesDbName);
561+
customTokens.put("%%mlModulesForestsPerHost%%", modulesForestsPerHost.toString());
562+
574563
customTokens.put("%%mlTriggersDbName%%", triggersDbName);
564+
customTokens.put("%%mlTriggersForestsPerHost%%", triggersForestsPerHost.toString());
565+
575566
customTokens.put("%%mlSchemasDbName%%", schemasDbName);
567+
customTokens.put("%%mlSchemasForestsPerHost%%", schemasForestsPerHost.toString());
576568

577569
customTokens.put("%%mlHubUserRole%%", hubRoleName);
578570
customTokens.put("%%mlHubUserName%%", hubUserName);
579571

572+
customTokens.put("%%mlCustomForestPath%%", customForestPath);
573+
574+
if (environmentProperties != null) {
575+
Enumeration keyEnum = environmentProperties.propertyNames();
576+
while (keyEnum.hasMoreElements()) {
577+
String key = (String) keyEnum.nextElement();
578+
if (key.matches("^ml[A-Z].+") && !customTokens.containsKey(key)) {
579+
customTokens.put("%%" + key + "%%", (String) environmentProperties.get(key));
580+
}
581+
}
582+
}
583+
584+
return customTokens;
585+
}
586+
587+
public void updateAppConfig(AppConfig config) {
588+
config.setHost(host);
589+
config.setRestPort(stagingPort);
590+
config.setAppServicesPort(appServicesPort);
591+
config.setRestAdminUsername(getRestAdminUsername());
592+
config.setRestAdminPassword(getRestAdminPassword());
593+
config.setModulesDatabaseName(modulesDbName);
594+
595+
config.setTriggersDatabaseName(triggersDbName);
596+
config.setSchemasDatabaseName(schemasDbName);
597+
config.setModulesDatabaseName(modulesDbName);
598+
599+
config.setReplaceTokensInModules(true);
600+
config.setUseRoxyTokenPrefix(false);
601+
602+
HashMap<String, Integer> forestCounts = new HashMap<>();
603+
forestCounts.put(stagingDbName, stagingForestsPerHost);
604+
forestCounts.put(finalDbName, finalForestsPerHost);
605+
forestCounts.put(traceDbName, traceForestsPerHost);
606+
forestCounts.put(jobDbName, jobForestsPerHost);
607+
forestCounts.put(modulesDbName, modulesForestsPerHost);
608+
forestCounts.put(triggersDbName, triggersForestsPerHost);
609+
forestCounts.put(schemasDbName, schemasForestsPerHost);
610+
config.setForestCounts(forestCounts);
611+
612+
ConfigDir configDir = new ConfigDir(getUserConfigDir().toFile());
613+
config.setConfigDir(configDir);
614+
615+
config.setSchemasPath(getUserConfigDir().resolve("schemas").toString());
616+
617+
Map<String, String> customTokens = getCustomTokens(config.getCustomTokens());
618+
580619
if (environmentProperties != null) {
581620
Enumeration keyEnum = environmentProperties.propertyNames();
582621
while (keyEnum.hasMoreElements()) {
@@ -655,8 +694,13 @@ public String toString() {
655694
.append("jobAuthMethod: " + jobAuthMethod + "\n")
656695
.append("\n")
657696
.append("modulesDbName: " + modulesDbName + "\n")
697+
.append("modulesForestsPerHost: " + modulesForestsPerHost + "\n")
698+
.append("\n")
658699
.append("triggersDbName: " + triggersDbName + "\n")
700+
.append("triggersForestsPerHost: " + triggersForestsPerHost + "\n")
701+
.append("\n")
659702
.append("schemasDbName: " + schemasDbName + "\n")
703+
.append("schemasForestsPerHost: " + schemasForestsPerHost + "\n")
660704
.append("\n")
661705
.append("projectDir: " + projectDir + "\n")
662706
.append("\n");

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class HubProject {
2424
private Path pluginsDir;
2525
private HubConfig hubConfig;
2626

27-
private Map<String, String> customTokens = new HashMap<>();
27+
private Map<String, String> customTokens;
2828

2929
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
3030

@@ -33,38 +33,7 @@ public HubProject(HubConfig config) {
3333
this.projectDirStr = config.projectDir;
3434
this.projectDir = Paths.get(this.projectDirStr);
3535
this.pluginsDir = Paths.get(this.projectDirStr, "plugins");
36-
37-
customTokens.put("%%mlHost%%", hubConfig.host);
38-
customTokens.put("%%mlStagingAppserverName%%", hubConfig.stagingHttpName);
39-
customTokens.put("%%mlStagingPort%%", hubConfig.stagingPort.toString());
40-
customTokens.put("%%mlStagingDbName%%", hubConfig.stagingDbName);
41-
customTokens.put("%%mlStagingForestsPerHost%%", hubConfig.stagingForestsPerHost.toString());
42-
customTokens.put("%%mlStagingAuth%%", hubConfig.stagingAuthMethod);
43-
44-
customTokens.put("%%mlFinalAppserverName%%", hubConfig.finalHttpName);
45-
customTokens.put("%%mlFinalPort%%", hubConfig.finalPort.toString());
46-
customTokens.put("%%mlFinalDbName%%", hubConfig.finalDbName);
47-
customTokens.put("%%mlFinalForestsPerHost%%", hubConfig.finalForestsPerHost.toString());
48-
customTokens.put("%%mlFinalAuth%%", hubConfig.finalAuthMethod);
49-
50-
customTokens.put("%%mlTraceAppserverName%%", hubConfig.traceHttpName);
51-
customTokens.put("%%mlTracePort%%", hubConfig.tracePort.toString());
52-
customTokens.put("%%mlTraceDbName%%", hubConfig.traceDbName);
53-
customTokens.put("%%mlTraceForestsPerHost%%", hubConfig.traceForestsPerHost.toString());
54-
customTokens.put("%%mlTraceAuth%%", hubConfig.traceAuthMethod);
55-
56-
customTokens.put("%%mlJobAppserverName%%", hubConfig.jobHttpName);
57-
customTokens.put("%%mlJobPort%%", hubConfig.jobPort.toString());
58-
customTokens.put("%%mlJobDbName%%", hubConfig.jobDbName);
59-
customTokens.put("%%mlJobForestsPerHost%%", hubConfig.jobForestsPerHost.toString());
60-
customTokens.put("%%mlJobAuth%%", hubConfig.jobAuthMethod);
61-
62-
customTokens.put("%%mlModulesDbName%%", hubConfig.modulesDbName);
63-
customTokens.put("%%mlTriggersDbName%%", hubConfig.triggersDbName);
64-
customTokens.put("%%mlSchemasDbName%%", hubConfig.schemasDbName);
65-
66-
customTokens.put("%%mlHubUserRole%%", hubConfig.hubRoleName);
67-
customTokens.put("%%mlHubUserName%%", hubConfig.hubUserName);
36+
customTokens = hubConfig.getCustomTokens(new HashMap<>());
6837
}
6938

7039
/**

marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/DeployHubDatabaseCommand.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ public void execute(CommandContext context) {
8080
if (payload != null) {
8181
DatabaseManager dbMgr = new DatabaseManager(context.getManageClient());
8282
SaveReceipt receipt = dbMgr.save(payload);
83-
buildDeployForestsCommand(payload, receipt, context).execute(context);
83+
int forestCount = determineForestCountPerHost(payload, context);
84+
if (forestCount > 0) {
85+
buildDeployForestsCommand(payload, receipt, context).execute(context);
86+
}
8487
}
8588
}
8689

marklogic-data-hub/src/main/resources/scaffolding/build_gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ plugins {
88
id 'java'
99
id 'eclipse'
1010
id 'idea'
11+
12+
// This plugin allows you to create different environments
13+
// for your gradle deploy. Each environment is represented
14+
// by a gradle-${env}.properties file
15+
// See https://github.com/stevesaliman/gradle-properties-plugin
16+
// specify the env on the command line with:
17+
// gradle -PenvironmentName=x ...
1118
id 'net.saliman.properties' version '1.4.6'
19+
20+
// This gradle plugin extends the ml-gradle plugin with
21+
// commands that make the Data Hub Framework do its magic
1222
id 'com.marklogic.ml-data-hub' version '1.1.2'
1323
}
1424

@@ -18,6 +28,8 @@ repositories {
1828
}
1929

2030
dependencies {
31+
// this allows you to write custom java code that depends
32+
// on the Data Hub Framework library
2133
compile 'com.marklogic:marklogic-data-hub:1.1.2'
2234
compile 'com.marklogic:marklogic-xcc:9.0.1'
2335
}

marklogic-data-hub/src/main/resources/scaffolding/gradle_properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,17 @@ mlJobForestsPerHost=%%mlJobForestsPerHost%%
6464
mlJobAuth=%%mlJobAuth%%
6565

6666
mlModulesDbName=%%mlModulesDbName%%
67+
mlModulesForestsPerHost=%%mlModulesForestsPerHost%%
68+
6769
mlTriggersDbName=%%mlTriggersDbName%%
70+
mlTriggersForestsPerHost=%%mlTriggersForestsPerHost%%
71+
6872
mlSchemasDbName=%%mlSchemasDbName%%
73+
mlSchemasForestsPerHost=%%mlSchemasForestsPerHost%%
74+
75+
# You can override this to specify an alternate folder for your
76+
# custom forest info. Defaults to user-config/forests/
77+
# mlCustomForestPath=%%mlCustomForestPath%%
6978

7079
# The name of the Role to create for Hub Access
7180
mlHubUserRole=%%mlHubUserRole%%

ml-data-hub-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies {
3131
compile gradleApi()
3232
compile project(":marklogic-data-hub")
3333
compile 'com.marklogic:marklogic-xcc:8.0.6'
34-
compile 'com.marklogic:ml-gradle:2.7.1'
34+
compile 'com.marklogic:ml-gradle:2.7.2'
3535

3636
testCompile localGroovy()
3737
testCompile gradleTestKit()

quick-start/src/main/java/com/marklogic/quickstart/service/SearchService.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@
2626
import com.marklogic.hub.HubConfig;
2727
import com.marklogic.hub.HubDatabase;
2828
import com.marklogic.quickstart.model.SearchQuery;
29-
import org.w3c.dom.Document;
30-
import org.w3c.dom.Element;
3129

32-
import javax.xml.parsers.DocumentBuilder;
33-
import javax.xml.parsers.DocumentBuilderFactory;
34-
import java.nio.file.Path;
35-
import java.nio.file.Paths;
3630
import java.util.ArrayList;
3731

3832
public class SearchService extends SearchableService {
@@ -53,23 +47,6 @@ public SearchService(HubConfig hubConfig) {
5347
this.finalDocMgr = finalClient.newDocumentManager();
5448
}
5549

56-
private Element getOptions() {
57-
try {
58-
Path dir = Paths.get(hubConfig.projectDir, HubConfig.USER_CONFIG_DIR, HubConfig.SEARCH_OPTIONS_FILE);
59-
if (dir.toFile().exists()) {
60-
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
61-
dbf.setNamespaceAware(true);
62-
DocumentBuilder db = dbf.newDocumentBuilder();
63-
Document doc = db.parse(dir.toFile());
64-
return doc.getDocumentElement();
65-
}
66-
}
67-
catch (Exception e) {
68-
throw new RuntimeException(e);
69-
}
70-
return null;
71-
}
72-
7350
public StringHandle search(SearchQuery searchQuery) {
7451
QueryManager queryMgr;
7552
if (searchQuery.database.equals(HubDatabase.STAGING)) {

0 commit comments

Comments
 (0)