Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 9a7a451

Browse files
committed
#200 Can now disable creation of forests
1 parent c1bdb6e commit 9a7a451

File tree

6 files changed

+65
-17
lines changed

6 files changed

+65
-17
lines changed

src/main/java/com/marklogic/appdeployer/AppConfig.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ public class AppConfig {
124124
// Allows for creating a triggers database without a config file for one
125125
private boolean createTriggersDatabase = false;
126126

127+
// Controls whether forests are created when a database is created
128+
private boolean createForests = true;
129+
127130
// Controls whether forests are deleted when a database is deleted
128131
private boolean deleteForests = true;
129132

@@ -730,7 +733,15 @@ public void setDeleteForests(boolean deleteForests) {
730733
this.deleteForests = deleteForests;
731734
}
732735

733-
public boolean isNoRestServer() {
736+
public boolean isCreateForests() {
737+
return createForests;
738+
}
739+
740+
public void setCreateForests(boolean createForests) {
741+
this.createForests = createForests;
742+
}
743+
744+
public boolean isNoRestServer() {
734745
return noRestServer;
735746
}
736747

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ public AppConfig newAppConfig() {
238238
c.setContentForestsPerHost(Integer.parseInt(prop));
239239
}
240240

241+
prop = getProperty("mlCreateForests");
242+
if (prop != null) {
243+
logger.info("Create forests for each deployed database: " + prop);
244+
c.setCreateForests(Boolean.parseBoolean(prop));
245+
}
246+
241247
/**
242248
* For any database besides the content database, configure the number of forests per host.
243249
*/

src/main/java/com/marklogic/appdeployer/command/databases/DeployContentDatabasesCommand.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ public void execute(CommandContext context) {
5353
SaveReceipt receipt = dbMgr.save(json);
5454
if (shouldCreateForests(context, payload)) {
5555
buildDeployForestsCommand(payload, receipt, context).execute(context);
56-
} else {
57-
if (logger.isInfoEnabled()) {
58-
logger.info("Found custom forests for database, so not creating default forests");
59-
}
6056
}
6157
}
6258
}
@@ -77,10 +73,10 @@ public void undo(CommandContext context) {
7773
String json = payloadTokenReplacer.replaceTokens(payload, appConfig, false);
7874

7975
DatabaseManager dbMgr = newDatabaseManageForDeleting(context);
80-
76+
8177
// remove subdatabases if they exist
8278
removeSubDatabases(dbMgr, context, dbMgr.getResourceId(json));
83-
79+
8480
dbMgr.delete(json);
8581
if (appConfig.isTestPortSet()) {
8682
json = payloadTokenReplacer.replaceTokens(payload, appConfig, true);

src/main/java/com/marklogic/appdeployer/command/databases/DeployDatabaseCommand.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public class DeployDatabaseCommand extends AbstractCommand implements UndoableCo
5959
private int forestsPerHost = 1;
6060

6161
/**
62-
* Passed on to DeployForestsCommand.
62+
* Passed on to DeployForestsCommand. If forests are to be created, controls whether forests on created on every
63+
* host or only one one host.
6364
*/
6465
private boolean createForestsOnEachHost = true;
6566

@@ -99,16 +100,11 @@ public void execute(CommandContext context) {
99100
databaseName = receipt.getResourceId();
100101
if (shouldCreateForests(context, payload)) {
101102
buildDeployForestsCommand(payload, receipt, context).execute(context);
102-
} else {
103-
if (logger.isInfoEnabled()) {
104-
logger.info("Found custom forests for database, so not creating default forests");
105-
}
106103
}
107-
// subdatabases? create and attach
104+
108105
if(!isSubDatabase()){
109-
this.addSubDatabases(dbMgr, context, receipt.getResourceId());
106+
this.addSubDatabases(dbMgr, context, databaseName);
110107
}
111-
112108
}
113109
}
114110

@@ -236,7 +232,9 @@ protected String getPayload(CommandContext context) {
236232
}
237233

238234
/**
239-
* This is where we check to see if a custom forests directory exists at ./forests/(database name). The database
235+
* Determines if forests should be created after a database is deployed.
236+
*
237+
* This includes checking to see if a custom forests directory exists at ./forests/(database name). The database
240238
* name is extracted from the payload via a PayloadParser. This check can be disabled by setting
241239
* checkForCustomForests to false.
242240
*
@@ -245,10 +243,21 @@ protected String getPayload(CommandContext context) {
245243
* @return
246244
*/
247245
protected boolean shouldCreateForests(CommandContext context, String payload) {
246+
if (!context.getAppConfig().isCreateForests()) {
247+
if (logger.isInfoEnabled()) {
248+
logger.info("Forest creation is disabled, so not creating any forests");
249+
}
250+
return false;
251+
}
252+
248253
if (isCheckForCustomForests()) {
249254
PayloadParser parser = new PayloadParser();
250255
String dbName = parser.getPayloadFieldValue(payload, "database-name");
251-
return !customForestsExist(context, dbName);
256+
boolean exist = !customForestsExist(context, dbName);
257+
if (exist && logger.isInfoEnabled()) {
258+
logger.info("Found custom forests for database " + dbName + ", so not creating default forests");
259+
}
260+
return exist;
252261
}
253262
return true;
254263
}

src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public void allProperties() {
103103
p.setProperty("mlAppServicesSimpleSsl", "true");
104104

105105
p.setProperty("mlContentForestsPerHost", "17");
106+
p.setProperty("mlCreateForests", "false");
106107
p.setProperty("mlForestsPerHost", "some-db,2,other-db,3");
107108
p.setProperty("mlModulePermissions", "some-perm,read,some-perm,update");
108109
p.setProperty("mlAdditionalBinaryExtensions", ".gradle,.properties");
@@ -174,6 +175,7 @@ public void allProperties() {
174175
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getAppServicesSslHostnameVerifier());
175176

176177
assertEquals((Integer) 17, config.getContentForestsPerHost());
178+
assertFalse(config.isCreateForests());
177179
Map<String, Integer> forestCounts = config.getForestCounts();
178180
assertEquals(2, (int)forestCounts.get("some-db"));
179181
assertEquals(3, (int)forestCounts.get("other-db"));

src/test/java/com/marklogic/appdeployer/command/databases/DeployOtherDatabasesTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.marklogic.appdeployer.command.databases;
22

33
import java.io.File;
4+
import java.util.regex.Pattern;
45

56
import org.junit.Test;
67

@@ -11,6 +12,29 @@
1112

1213
public class DeployOtherDatabasesTest extends AbstractAppDeployerTest {
1314

15+
@Test
16+
public void dontCreateForests() {
17+
ConfigDir configDir = appConfig.getConfigDir();
18+
configDir.setBaseDir(new File("src/test/resources/sample-app/lots-of-databases"));
19+
20+
appConfig.setResourceFilenamesIncludePattern(Pattern.compile("other-schemas-database.*"));
21+
appConfig.setCreateForests(false);
22+
23+
initializeAppDeployer(new DeployOtherDatabasesCommand());
24+
25+
final String dbName = "other-sample-app-schemas";
26+
DatabaseManager dbMgr = new DatabaseManager(manageClient);
27+
28+
try {
29+
appDeployer.deploy(appConfig);
30+
assertTrue(dbMgr.exists(dbName));
31+
assertTrue("No forests should have been created for the database", dbMgr.getForestIds(dbName).isEmpty());
32+
} finally {
33+
undeploySampleApp();
34+
assertFalse(dbMgr.exists(dbName));
35+
}
36+
}
37+
1438
@Test
1539
public void test() {
1640
ConfigDir configDir = appConfig.getConfigDir();

0 commit comments

Comments
 (0)