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

Commit 5fd91e0

Browse files
committed
Merge branch 'dev'
2 parents 6ea8e3a + 426d6dd commit 5fd91e0

File tree

85 files changed

+1268
-435
lines changed

Some content is hidden

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

85 files changed

+1268
-435
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
3-
version=3.2.0
4-
mlJavaclientUtilVersion=3.2.0
3+
version=3.3.0
4+
mlJavaclientUtilVersion=3.3.0
55
mlJunitVersion=3.1.0
66

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

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public class AppConfig {
116116
private int modulesLoaderThreadCount = 8;
117117

118118
private String schemasPath;
119-
private ConfigDir configDir;
119+
120+
private List<ConfigDir> configDirs;
120121

121122
// Passed into the PayloadTokenReplacer that subclasses of AbstractCommand use
122123
private Map<String, String> customTokens = new HashMap<>();
@@ -154,6 +155,7 @@ public class AppConfig {
154155
private Set<String> databasesWithForestsOnOneHost;
155156

156157
private Map<String, Set<String>> databaseHosts;
158+
private Map<String, Set<String>> databaseGroups;
157159

158160
// Data/fast/large directories for default forests
159161
private String forestDataDirectory;
@@ -183,7 +185,9 @@ public class AppConfig {
183185
// Additional PropertiesSources instance to use for replacing module tokens
184186
private List<PropertiesSource> moduleTokensPropertiesSources = new ArrayList<>();
185187

186-
private Map<String, Integer> forestCounts = new HashMap<>();
188+
private Pattern moduleFilenamesIncludePattern;
189+
190+
private Map<String, Integer> forestCounts = new HashMap<>();
187191

188192
// Entity Services properties
189193
private String modelsPath = "data/entity-services";
@@ -212,7 +216,8 @@ public AppConfig(String defaultModulePath) {
212216
public AppConfig(String defaultModulePath, String defaultSchemasPath) {
213217
modulePaths = new ArrayList<String>();
214218
modulePaths.add(defaultModulePath);
215-
configDir = new ConfigDir();
219+
configDirs = new ArrayList<>();
220+
configDirs.add(new ConfigDir());
216221
schemasPath = defaultSchemasPath;
217222
}
218223

@@ -523,16 +528,40 @@ public void setRestAuthentication(Authentication authentication) {
523528
}
524529

525530
/**
531+
* As of 3.3.0, this now returns the first ConfigDir in the List of ConfigsDir that this class now maintains.
532+
*
526533
* @return a {@code ConfigDir} instance that defines the location of the configuration directory (where files are
527534
* stored that are then loaded via MarkLogic Management API endpoints) as well as paths to specific
528535
* resources within that directory
529536
*/
537+
@Deprecated
530538
public ConfigDir getConfigDir() {
531-
return configDir;
539+
return getFirstConfigDir();
540+
}
541+
542+
/**
543+
* Starting in 3.3.0, use this when you only care about the first ConfigDir in the List of ConfigDirs maintained by
544+
* this class.
545+
*
546+
* @return
547+
*/
548+
public ConfigDir getFirstConfigDir() {
549+
if (configDirs == null || configDirs.isEmpty()) {
550+
this.configDirs = new ArrayList<>();
551+
this.configDirs.add(new ConfigDir());
552+
}
553+
return configDirs.get(0);
532554
}
533555

534-
public void setConfigDir(ConfigDir configDir) {
535-
this.configDir = configDir;
556+
/**
557+
* As of 3.3.0, this is instead clearing and adding the ConfigDir to the List of ConfigDirs that this class now
558+
* maintains.
559+
*
560+
* @param configDir
561+
*/
562+
public void setConfigDir(ConfigDir configDir) {
563+
this.configDirs = new ArrayList<>();
564+
this.configDirs.add(configDir);
536565
}
537566

538567
/**
@@ -1106,4 +1135,28 @@ public Map<String, Set<String>> getDatabaseHosts() {
11061135
public void setDatabaseHosts(Map<String, Set<String>> databaseHosts) {
11071136
this.databaseHosts = databaseHosts;
11081137
}
1138+
1139+
public Map<String, Set<String>> getDatabaseGroups() {
1140+
return databaseGroups;
1141+
}
1142+
1143+
public void setDatabaseGroups(Map<String, Set<String>> databaseGroups) {
1144+
this.databaseGroups = databaseGroups;
1145+
}
1146+
1147+
public List<ConfigDir> getConfigDirs() {
1148+
return configDirs;
1149+
}
1150+
1151+
public void setConfigDirs(List<ConfigDir> configDirs) {
1152+
this.configDirs = configDirs;
1153+
}
1154+
1155+
public Pattern getModuleFilenamesIncludePattern() {
1156+
return moduleFilenamesIncludePattern;
1157+
}
1158+
1159+
public void setModuleFilenamesIncludePattern(Pattern moduleFilenamesIncludePattern) {
1160+
this.moduleFilenamesIncludePattern = moduleFilenamesIncludePattern;
1161+
}
11091162
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,41 @@ public File getAmpsDir() {
8080
return new File(getSecurityDir(), "amps");
8181
}
8282

83+
public File getCertificateAuthoritiesDir() {
84+
return new File(getSecurityDir(), "certificate-authorities");
85+
}
86+
87+
public File getCertificateTemplatesDir() {
88+
return new File(getSecurityDir(), "certificate-templates");
89+
}
90+
91+
public File getExternalSecuritiesDir() {
92+
return new File(getSecurityDir(), "external-security");
93+
}
94+
8395
public File getPrivilegesDir() {
8496
return new File(getSecurityDir(), "privileges");
8597
}
8698

99+
public File getProtectedCollectionsDir() {
100+
return new File(getSecurityDir(), "protected-collections");
101+
}
102+
87103
public File getRolesDir() {
88104
return new File(getSecurityDir(), "roles");
89105
}
90106

107+
public File getTriggersDir() {
108+
return new File(getBaseDir(), "triggers");
109+
}
110+
91111
public File getUsersDir() {
92112
return new File(getSecurityDir(), "users");
93113
}
94114

95115
public File getProtectedPathsDir() { return new File(getSecurityDir(), "protected-paths"); }
96116

97-
public File getQueryRoleSetsDir() { return new File(getSecurityDir(), "query-rolesets"); }
117+
public File getQueryRolesetsDir() { return new File(getSecurityDir(), "query-rolesets"); }
98118

99119
public File getServersDir() {
100120
return new File(baseDir, "servers");
@@ -132,6 +152,10 @@ public File getGroupsDir() {
132152
return new File(baseDir, "groups");
133153
}
134154

155+
public File getMimetypesDir() {
156+
return new File(baseDir, "mimetypes");
157+
}
158+
135159
public File getViewSchemasDir() {
136160
return new File(baseDir, "view-schemas");
137161
}

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

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,30 @@ public AppConfig newAppConfig() {
5858
* The path to the directory containing all the resource configuration files. Defaults to src/main/ml-config.
5959
* mlConfigPath is the preferred one, as its name is consistent with other properties that refer to a path.
6060
* mlConfigDir is deprecated but still supported.
61+
*
62+
* As of 3.3.0, mlConfigPaths is the preferred property, and mlConfigDir and mlConfigPath will be ignored if
63+
* it's set.
6164
*/
62-
prop = getProperty("mlConfigDir");
65+
prop = getProperty("mlConfigPaths");
6366
if (prop != null) {
64-
logger.info("mlConfigDir is deprecated; please use mlConfigPath; Config dir: " + prop);
65-
c.setConfigDir(new ConfigDir(new File(prop)));
67+
logger.info("Config paths: " + prop);
68+
List<ConfigDir> list = new ArrayList<>();
69+
for (String path : prop.split(",")) {
70+
list.add(new ConfigDir(new File(path)));
71+
}
72+
c.setConfigDirs(list);
6673
}
67-
prop = getProperty("mlConfigPath");
68-
if (prop != null) {
69-
logger.info("Config path: " + prop);
70-
c.setConfigDir(new ConfigDir(new File(prop)));
74+
else {
75+
prop = getProperty("mlConfigDir");
76+
if (prop != null) {
77+
logger.info("mlConfigDir is deprecated; please use mlConfigPath; Config dir: " + prop);
78+
c.setConfigDir(new ConfigDir(new File(prop)));
79+
}
80+
prop = getProperty("mlConfigPath");
81+
if (prop != null) {
82+
logger.info("Config path: " + prop);
83+
c.setConfigDir(new ConfigDir(new File(prop)));
84+
}
7185
}
7286

7387
/**
@@ -287,21 +301,16 @@ public AppConfig newAppConfig() {
287301
c.setDatabasesWithForestsOnOneHost(set);
288302
}
289303

304+
prop = getProperty("mlDatabaseGroups");
305+
if (prop != null) {
306+
logger.info("Databases and the groups containing the hosts that their forests will be created on: " + prop);
307+
c.setDatabaseGroups(buildSetMapFromDelimitedString(prop));
308+
}
309+
290310
prop = getProperty("mlDatabaseHosts");
291311
if (prop != null) {
292312
logger.info("Databases and the hosts that their forests will be created on: " + prop);
293-
String[] tokens = prop.split(",");
294-
Map<String, Set<String>> map = new HashMap<>();
295-
for (int i = 0; i < tokens.length; i += 2) {
296-
String dbName = tokens[i];
297-
String[] hostNames = tokens[i + 1].split("\\|");
298-
Set<String> names = new HashSet<>();
299-
for (String name : hostNames) {
300-
names.add(name);
301-
}
302-
map.put(dbName, names);
303-
}
304-
c.setDatabaseHosts(map);
313+
c.setDatabaseHosts(buildSetMapFromDelimitedString(prop));
305314
}
306315

307316
prop = getProperty("mlForestDataDirectory");
@@ -509,6 +518,12 @@ public AppConfig newAppConfig() {
509518
c.setModuleTimestampsPath(prop);
510519
}
511520

521+
prop = getProperty("mlModulesRegex");
522+
if (prop != null) {
523+
logger.info("Including module filenames matching regex: " + prop);
524+
c.setModuleFilenamesIncludePattern(Pattern.compile(prop));
525+
}
526+
512527
/**
513528
* Whether or not to load asset modules in bulk - i.e. in one transaction. Defaults to true.
514529
*/
@@ -644,4 +659,19 @@ protected Map<String, String> buildMapFromCommaDelimitedString(String str) {
644659
}
645660
return map;
646661
}
662+
663+
protected Map<String, Set<String>> buildSetMapFromDelimitedString(String str) {
664+
String[] tokens = str.split(",");
665+
Map<String, Set<String>> map = new LinkedHashMap<>();
666+
for (int i = 0; i < tokens.length; i += 2) {
667+
String dbName = tokens[i];
668+
String[] hostNames = tokens[i + 1].split("\\|");
669+
Set<String> names = new LinkedHashSet<>();
670+
for (String name : hostNames) {
671+
names.add(name);
672+
}
673+
map.put(dbName, names);
674+
}
675+
return map;
676+
}
647677
}

src/main/java/com/marklogic/appdeployer/command/AbstractCommand.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ protected File[] listFilesInDirectory(File dir) {
206206
return files;
207207
}
208208

209+
protected void logResourceDirectoryNotFound(File dir) {
210+
if (dir != null && logger.isInfoEnabled()) {
211+
logger.info("No resource directory found at: " + dir.getAbsolutePath());
212+
}
213+
}
214+
209215
public void setPayloadTokenReplacer(PayloadTokenReplacer payloadTokenReplacer) {
210216
this.payloadTokenReplacer = payloadTokenReplacer;
211217
}

src/main/java/com/marklogic/appdeployer/command/AbstractResourceCommand.java

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package com.marklogic.appdeployer.command;
22

3+
import com.marklogic.appdeployer.AppConfig;
4+
import com.marklogic.appdeployer.ConfigDir;
35
import com.marklogic.mgmt.admin.AdminManager;
46
import com.marklogic.mgmt.resource.ResourceManager;
57
import com.marklogic.mgmt.SaveReceipt;
68
import com.marklogic.mgmt.admin.ActionRequiringRestart;
7-
import com.marklogic.mgmt.admin.AdminManager;
89
import org.springframework.http.HttpHeaders;
910
import org.springframework.http.ResponseEntity;
1011

1112
import java.io.File;
1213
import java.net.URI;
14+
import java.util.ArrayList;
15+
import java.util.List;
1316

1417
/**
1518
* Provides a basic implementation for creating/updating a resource while an app is being deployed and then deleting it
@@ -32,21 +35,54 @@ public void execute(CommandContext context) {
3235
}
3336
}
3437

35-
protected void processExecuteOnResourceDir(CommandContext context, File resourceDir) {
36-
if (resourceDir.exists()) {
37-
ResourceManager mgr = getResourceManager(context);
38-
if (logger.isInfoEnabled()) {
39-
logger.info("Processing files in directory: " + resourceDir.getAbsolutePath());
40-
}
41-
for (File f : listFilesInDirectory(resourceDir, context)) {
42-
if (logger.isInfoEnabled()) {
43-
logger.info("Processing file: " + f.getAbsolutePath());
44-
}
45-
SaveReceipt receipt = saveResource(mgr, context, f);
46-
afterResourceSaved(mgr, context, f, receipt);
47-
}
48-
}
49-
}
38+
protected File[] findResourceDirs(CommandContext context, ResourceDirFinder resourceDirFinder) {
39+
return findResourceDirs(context.getAppConfig(), resourceDirFinder);
40+
}
41+
42+
/**
43+
* A subclass is likely to use this as a simple way of selecting all of the resource directories, specific to the
44+
* subclass's resource, within each ConfigDir on the AppConfig.
45+
*
46+
* @param appConfig
47+
* @param resourceDirFinder
48+
* @return
49+
*/
50+
protected File[] findResourceDirs(AppConfig appConfig, ResourceDirFinder resourceDirFinder) {
51+
List<File> list = new ArrayList<>();
52+
List<ConfigDir> configDirs = appConfig.getConfigDirs();
53+
if (configDirs != null && !configDirs.isEmpty()) {
54+
for (ConfigDir configDir : appConfig.getConfigDirs()) {
55+
File dir = resourceDirFinder.getResourceDir(configDir);
56+
if (dir != null && dir.exists()) {
57+
list.add(dir);
58+
} else {
59+
logResourceDirectoryNotFound(dir);
60+
}
61+
}
62+
}
63+
else {
64+
logger.warn("No ConfigDir objects found in AppConfig, unable to find resource directories");
65+
}
66+
return list.toArray(new File[]{});
67+
}
68+
69+
protected void processExecuteOnResourceDir(CommandContext context, File resourceDir) {
70+
if (resourceDir.exists()) {
71+
ResourceManager mgr = getResourceManager(context);
72+
if (logger.isInfoEnabled()) {
73+
logger.info("Processing files in directory: " + resourceDir.getAbsolutePath());
74+
}
75+
for (File f : listFilesInDirectory(resourceDir, context)) {
76+
if (logger.isInfoEnabled()) {
77+
logger.info("Processing file: " + f.getAbsolutePath());
78+
}
79+
SaveReceipt receipt = saveResource(mgr, context, f);
80+
afterResourceSaved(mgr, context, f, receipt);
81+
}
82+
} else {
83+
logResourceDirectoryNotFound(resourceDir);
84+
}
85+
}
5086

5187
/**
5288
* Defaults to the parent method. This was extracted so that a subclass can override it and have access to the

src/main/java/com/marklogic/appdeployer/command/CommandMapBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public Map<String, List<Command>> buildCommandMap() {
6161
securityCommands.add(new DeployExternalSecurityCommand());
6262
securityCommands.add(new DeployPrivilegesCommand());
6363
securityCommands.add(new DeployProtectedCollectionsCommand());
64+
securityCommands.add(new DeployProtectedPathsCommand());
65+
securityCommands.add(new DeployQueryRolesetsCommand());
6466
map.put("mlSecurityCommands", securityCommands);
6567

6668
// Cluster
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.marklogic.appdeployer.command;
2+
3+
import com.marklogic.appdeployer.ConfigDir;
4+
5+
import java.io.File;
6+
7+
/**
8+
* Exists solely for the "findResourceDirs" method in AbstractResourceCommand.
9+
*/
10+
public interface ResourceDirFinder {
11+
File getResourceDir(ConfigDir configDir);
12+
}

0 commit comments

Comments
 (0)