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

Commit ad64288

Browse files
committed
#213 New property for controlling which databases have forests created on one host
1 parent dc321a0 commit ad64288

File tree

7 files changed

+131
-7
lines changed

7 files changed

+131
-7
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
33
version=dev
4-
mlJavaclientUtilVersion=77
4+
mlJavaclientUtilVersion=3.2-78
55
mlJunitVersion=3.1.0
66

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
import javax.net.ssl.SSLContext;
1616
import java.io.FileFilter;
17-
import java.util.ArrayList;
18-
import java.util.HashMap;
19-
import java.util.List;
20-
import java.util.Map;
17+
import java.util.*;
2118
import java.util.regex.Pattern;
2219

2320
/**
@@ -153,6 +150,9 @@ public class AppConfig {
153150
// Comma-delimited string used for configuring forest replicas
154151
private String databaseNamesAndReplicaCounts;
155152

153+
// Comma-delimited string of database names that should only have forests (most likely just one) created on one host
154+
private Set<String> databaseNamesWithForestsOnOneHost;
155+
156156
// Data/fast/large directories for default forests
157157
private String forestDataDirectory;
158158
private String forestFastDataDirectory;
@@ -1055,4 +1055,12 @@ public boolean isCatchUndeployExceptions() {
10551055
public void setCatchUndeployExceptions(boolean catchUndeployExceptions) {
10561056
this.catchUndeployExceptions = catchUndeployExceptions;
10571057
}
1058+
1059+
public Set<String> getDatabaseNamesWithForestsOnOneHost() {
1060+
return databaseNamesWithForestsOnOneHost;
1061+
}
1062+
1063+
public void setDatabaseNamesWithForestsOnOneHost(Set<String> databaseNamesWithForestsOnOneHost) {
1064+
this.databaseNamesWithForestsOnOneHost = databaseNamesWithForestsOnOneHost;
1065+
}
10581066
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@ public AppConfig newAppConfig() {
276276
c.setDatabaseNamesAndReplicaCounts(prop);
277277
}
278278

279+
prop = getProperty("mlDatabaseNamesWithForestsOnOneHost");
280+
if (prop != null) {
281+
logger.info("Databases that will have their forest(s) created on a single host: " + prop);
282+
String[] names = prop.split(",");
283+
Set<String> set = new HashSet<>();
284+
for (String name : names) {
285+
set.add(name);
286+
}
287+
c.setDatabaseNamesWithForestsOnOneHost(set);
288+
}
289+
279290
prop = getProperty("mlForestDataDirectory");
280291
if (prop != null) {
281292
logger.info("Default forest data directory for all databases: " + prop);

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.ArrayList;
1717
import java.util.List;
1818
import java.util.Map;
19+
import java.util.Set;
1920

2021
/**
2122
* Can be used for creating any kind of database with any sorts of forests. Specifying a config file for the database or
@@ -283,6 +284,9 @@ protected boolean customForestsExist(CommandContext context, String dbName) {
283284
/**
284285
* Allows for how an instance of DeployForestsCommand is built to be overridden by a subclass.
285286
*
287+
* Starting in 3.2.0, the "createForestsOnEachHost" property is overridden if the database name is in the
288+
* databaseNamesWithForestsOnOneHost property in AppConfig.
289+
*
286290
* @param dbPayload
287291
* Needed so we can look up forest counts based on the database name
288292
* @param receipt
@@ -294,7 +298,17 @@ protected DeployForestsCommand buildDeployForestsCommand(String dbPayload, SaveR
294298
final String databaseName = receipt.getResourceId();
295299

296300
DeployForestsCommand c = new DeployForestsCommand();
297-
c.setCreateForestsOnEachHost(createForestsOnEachHost);
301+
302+
Set<String> names = context.getAppConfig().getDatabaseNamesWithForestsOnOneHost();
303+
if (names != null && names.contains(databaseName)) {
304+
if (logger.isInfoEnabled()) {
305+
logger.info("Will only create forest(s) on one host for database: " + databaseName);
306+
}
307+
c.setCreateForestsOnEachHost(false);
308+
} else {
309+
c.setCreateForestsOnEachHost(createForestsOnEachHost);
310+
}
311+
298312
c.setForestsPerHost(determineForestCountPerHost(dbPayload, context));
299313
c.setForestFilename(forestFilename);
300314
c.setDatabaseName(databaseName);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44
import java.util.Map;
55
import java.util.Properties;
6+
import java.util.Set;
67

78
import com.marklogic.client.DatabaseClientFactory;
89
import com.marklogic.client.ext.SecurityContextType;
@@ -139,6 +140,7 @@ public void allProperties() {
139140
p.setProperty("mlResourceFilenamesToIncludeRegex", "qa-.*");
140141

141142
p.setProperty("mlDatabaseNamesAndReplicaCounts", "Documents,1,Security,2");
143+
p.setProperty("mlDatabaseNamesWithForestsOnOneHost", "Documents,Security");
142144

143145
p.setProperty("mlForestDataDirectory", "/data/path");
144146
p.setProperty("mlForestFastDataDirectory", "/fast/path");
@@ -163,7 +165,7 @@ public void allProperties() {
163165

164166
assertTrue(config.isCatchDeployExceptions());
165167
assertTrue(config.isCatchUndeployExceptions());
166-
168+
167169
assertEquals("prophost", config.getHost());
168170
assertEquals("propname", config.getName());
169171
assertTrue(config.isNoRestServer());
@@ -239,6 +241,11 @@ public void allProperties() {
239241

240242
assertEquals("Documents,1,Security,2", config.getDatabaseNamesAndReplicaCounts());
241243

244+
Set<String> set = config.getDatabaseNamesWithForestsOnOneHost();
245+
assertEquals(2, set.size());
246+
assertTrue(set.contains("Documents"));
247+
assertTrue(set.contains("Security"));
248+
242249
assertEquals("/data/path", config.getForestDataDirectory());
243250
assertEquals("/fast/path", config.getForestFastDataDirectory());
244251
assertEquals("/large/path", config.getForestLargeDataDirectory());
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.marklogic.appdeployer.command.databases;
2+
3+
import com.marklogic.appdeployer.AppConfig;
4+
import com.marklogic.appdeployer.command.CommandContext;
5+
import com.marklogic.appdeployer.command.forests.DeployForestsCommand;
6+
import com.marklogic.mgmt.SaveReceipt;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
10+
import java.util.HashMap;
11+
import java.util.HashSet;
12+
import java.util.Map;
13+
import java.util.Set;
14+
15+
public class CreateForestsOnOneHostTest extends Assert {
16+
17+
@Test
18+
public void test() {
19+
DeployDatabaseCommand command = new DeployDatabaseCommand();
20+
21+
AppConfig appConfig = new AppConfig();
22+
CommandContext context = new CommandContext(appConfig, null, null);
23+
24+
Set<String> names = new HashSet<>();
25+
names.add("some-name");
26+
appConfig.setDatabaseNamesWithForestsOnOneHost(names);
27+
28+
Map<String, Integer> forestCountMap = new HashMap<>();
29+
forestCountMap.put("some-name", 3);
30+
forestCountMap.put("other-name", 2);
31+
appConfig.setForestCounts(forestCountMap);
32+
33+
String payload = "{\"database-name\":\"some-name\"}";
34+
SaveReceipt receipt = new SaveReceipt("some-name", payload, null, null);
35+
DeployForestsCommand forestsCommand = command.buildDeployForestsCommand(payload, receipt, context);
36+
assertFalse(forestsCommand.isCreateForestsOnEachHost());
37+
assertEquals(3, forestsCommand.getForestsPerHost());
38+
39+
payload = "{\"database-name\":\"other-name\"}";
40+
receipt = new SaveReceipt("other-name", payload, null, null);
41+
forestsCommand = command.buildDeployForestsCommand(payload, receipt, context);
42+
assertTrue(forestsCommand.isCreateForestsOnEachHost());
43+
assertEquals(2, forestsCommand.getForestsPerHost());
44+
}
45+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.marklogic.appdeployer.command.forests;
2+
3+
import com.marklogic.appdeployer.AppConfig;
4+
import com.marklogic.appdeployer.command.CommandContext;
5+
import com.marklogic.appdeployer.command.databases.DeployDatabaseCommand;
6+
import com.marklogic.mgmt.ManageClient;
7+
import com.marklogic.mgmt.ManageConfig;
8+
9+
import java.util.HashSet;
10+
import java.util.Set;
11+
12+
/**
13+
* Debug program for verifying that a forest is only created on one host. Gotta run this against a cluster with 2 or
14+
* more hosts.
15+
*/
16+
public class CreateForestsOnOneHostDebug {
17+
18+
public static void main(String[] args) {
19+
final String host = args[0];
20+
final String password = args[1];
21+
22+
ManageConfig config = new ManageConfig(host, 8002, "admin", password);
23+
ManageClient manageClient = new ManageClient(config);
24+
25+
AppConfig appConfig = new AppConfig();
26+
Set<String> names = new HashSet<>();
27+
names.add("testdb");
28+
appConfig.setDatabaseNamesWithForestsOnOneHost(names);
29+
CommandContext context = new CommandContext(appConfig, manageClient, null);
30+
31+
DeployDatabaseCommand ddc = new DeployDatabaseCommand();
32+
ddc.setForestsPerHost(1);
33+
ddc.setCreateDatabaseWithoutFile(true);
34+
ddc.setDatabaseName("testdb");
35+
36+
ddc.execute(context);
37+
ddc.undo(context);
38+
}
39+
}

0 commit comments

Comments
 (0)