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

Commit ccfc26e

Browse files
Dermot SmythDermot Smyth
authored andcommitted
Merge branch 'dev' of https://github.com/rjrudin/ml-app-deployer into feature/issue-28-add-temporal-config
# Conflicts: # src/main/java/com/marklogic/appdeployer/command/SortOrderConstants.java
2 parents d3f6b93 + 6daecf9 commit ccfc26e

File tree

25 files changed

+749
-153
lines changed

25 files changed

+749
-153
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ repositories {
1515
}
1616

1717
dependencies {
18-
compile 'com.marklogic:ml-javaclient-util:2.11.0'
18+
compile 'com.marklogic:ml-javaclient-util:2.13.0'
1919
compile 'jaxen:jaxen:1.1.6'
2020
compile 'org.apache.httpcomponents:httpclient:4.3.5'
21-
compile 'org.springframework:spring-web:4.1.5.RELEASE'
21+
compile 'org.springframework:spring-web:4.3.5.RELEASE'
2222
testCompile ('com.marklogic:ml-junit:2.6.0') {
2323
exclude module: "ml-javaclient-util"
2424
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
3-
version=2.5.0
3+
version=2.6.0

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public class AppConfig {
133133
private boolean generateExtractionTemplate = true;
134134
private boolean generateSearchOptions = true;
135135

136+
private String[] resourceFilenamesToIgnore;
137+
136138
public AppConfig() {
137139
this(DEFAULT_MODULES_PATH, DEFAULT_SCHEMAS_PATH);
138140
}
@@ -696,4 +698,12 @@ public String getModuleTimestampsPath() {
696698
public void setModuleTimestampsPath(String moduleTimestampsPath) {
697699
this.moduleTimestampsPath = moduleTimestampsPath;
698700
}
701+
702+
public String[] getResourceFilenamesToIgnore() {
703+
return resourceFilenamesToIgnore;
704+
}
705+
706+
public void setResourceFilenamesToIgnore(String... resourceFilenamesToIgnore) {
707+
this.resourceFilenamesToIgnore = resourceFilenamesToIgnore;
708+
}
699709
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public File getCpfDir() {
6060
return new File(baseDir, "cpf");
6161
}
6262

63+
public File getClustersDir() {
64+
return new File(baseDir, "clusters");
65+
}
66+
6367
public File getAlertDir() {
6468
return new File(baseDir, "alert");
6569
}

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,47 +281,60 @@ public AppConfig newAppConfig() {
281281
c.setStaticCheckLibraryAssets(Boolean.parseBoolean(prop));
282282
}
283283

284+
/**
285+
* The following properties are all for generating Entity Services artifacts.
286+
*/
284287
prop = getProperty("mlModelsPath");
285288
if (prop != null) {
286289
logger.info("Entity Services models path: " + prop);
287290
c.setModelsPath(prop);
288291
}
289-
290292
prop = getProperty("mlInstanceConverterPath");
291293
if (prop != null) {
292294
logger.info("Entity Services instance converter path: " + prop);
293295
c.setInstanceConverterPath(prop);
294296
}
295-
296297
prop = getProperty("mlGenerateInstanceConverter");
297298
if (prop != null) {
298299
logger.info("Entity Services generate instance converter: " + prop);
299300
c.setGenerateInstanceConverter(Boolean.parseBoolean(prop));
300301
}
301-
302302
prop = getProperty("mlGenerateSchema");
303303
if (prop != null) {
304304
logger.info("Entity Services generate schema: " + prop);
305305
c.setGenerateSchema(Boolean.parseBoolean(prop));
306306
}
307-
308307
prop = getProperty("mlGenerateSearchOptions");
309308
if (prop != null) {
310309
logger.info("Entity Services generate search options: " + prop);
311310
c.setGenerateSearchOptions(Boolean.parseBoolean(prop));
312311
}
313-
314312
prop = getProperty("mlGenerateDatabaseProperties");
315313
if (prop != null) {
316314
logger.info("Entity Services generate database properties: " + prop);
317315
c.setGenerateDatabaseProperties(Boolean.parseBoolean(prop));
318316
}
319-
320317
prop = getProperty("mlGenerateExtractionTemplate");
321318
if (prop != null) {
322319
logger.info("Entity Services generate extraction template: " + prop);
323320
c.setGenerateExtractionTemplate(Boolean.parseBoolean(prop));
324321
}
322+
// End Entity Services properties
323+
324+
/**
325+
* Sets resource filenames to ignore on ALL commands. Be careful here, in case you have files for different kinds
326+
* of resources, but with the same filename (this should be very rare and easily avoided).
327+
*
328+
* Also that as of version 2.6.0 of ml-app-deployer, this property is processed by AbstractAppDeployer, NOT by
329+
* the Command itself. So in order for this property to be applied, you must execute a Command via a subclass of
330+
* AbstractAppDeployer (most commonly SimpleAppDeployer).
331+
*/
332+
prop = getProperty("mlResourceFilenamesToIgnore");
333+
if (prop != null) {
334+
String[] values = prop.split(",");
335+
logger.info("Ignoring resource filenames: " + Arrays.asList(values));
336+
c.setResourceFilenamesToIgnore(values);
337+
}
325338

326339
return c;
327340
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public Integer getExecuteSortOrder() {
4141
* @param filenames
4242
*/
4343
public void setFilenamesToIgnore(String... filenames) {
44+
if (filenames == null || filenames.length == 0) {
45+
return;
46+
}
4447
if (resourceFilenameFilter != null && resourceFilenameFilter instanceof ResourceFilenameFilter) {
4548
ResourceFilenameFilter rff = (ResourceFilenameFilter) resourceFilenameFilter;
4649
Set<String> set = null;
@@ -52,6 +55,7 @@ public void setFilenamesToIgnore(String... filenames) {
5255
for (String f : filenames) {
5356
set.add(f);
5457
}
58+
rff.setFilenamesToIgnore(set);
5559
} else {
5660
this.resourceFilenameFilter = new ResourceFilenameFilter(filenames);
5761
}

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ public abstract class AbstractResourceCommand extends AbstractUndoableCommand {
2323
@Override
2424
public void execute(CommandContext context) {
2525
for (File resourceDir : getResourceDirs(context)) {
26-
if (resourceDir.exists()) {
27-
ResourceManager mgr = getResourceManager(context);
26+
processExecuteOnResourceDir(context, resourceDir);
27+
}
28+
}
29+
30+
protected void processExecuteOnResourceDir(CommandContext context, File resourceDir) {
31+
if (resourceDir.exists()) {
32+
ResourceManager mgr = getResourceManager(context);
33+
if (logger.isInfoEnabled()) {
34+
logger.info("Processing files in directory: " + resourceDir.getAbsolutePath());
35+
}
36+
for (File f : listFilesInDirectory(resourceDir)) {
2837
if (logger.isInfoEnabled()) {
29-
logger.info("Processing files in directory: " + resourceDir.getAbsolutePath());
30-
}
31-
for (File f : listFilesInDirectory(resourceDir)) {
32-
if (logger.isInfoEnabled()) {
33-
logger.info("Processing file: " + f.getAbsolutePath());
34-
}
35-
SaveReceipt receipt = saveResource(mgr, context, f);
36-
afterResourceSaved(mgr, context, f, receipt);
38+
logger.info("Processing file: " + f.getAbsolutePath());
3739
}
40+
SaveReceipt receipt = saveResource(mgr, context, f);
41+
afterResourceSaved(mgr, context, f, receipt);
3842
}
3943
}
4044
}
@@ -56,18 +60,22 @@ protected void afterResourceSaved(ResourceManager mgr, CommandContext context, F
5660
public void undo(CommandContext context) {
5761
if (deleteResourcesOnUndo) {
5862
for (File resourceDir : getResourceDirs(context)) {
59-
if (resourceDir.exists()) {
60-
if (logger.isInfoEnabled()) {
61-
logger.info("Processing files in directory: " + resourceDir.getAbsolutePath());
62-
}
63-
final ResourceManager mgr = getResourceManager(context);
64-
for (File f : listFilesInDirectory(resourceDir)) {
65-
if (logger.isInfoEnabled()) {
66-
logger.info("Processing file: " + f.getAbsolutePath());
67-
}
68-
deleteResource(mgr, context, f);
69-
}
63+
processUndoOnResourceDir(context, resourceDir);
64+
}
65+
}
66+
}
67+
68+
protected void processUndoOnResourceDir(CommandContext context, File resourceDir) {
69+
if (resourceDir.exists()) {
70+
if (logger.isInfoEnabled()) {
71+
logger.info("Processing files in directory: " + resourceDir.getAbsolutePath());
72+
}
73+
final ResourceManager mgr = getResourceManager(context);
74+
for (File f : listFilesInDirectory(resourceDir)) {
75+
if (logger.isInfoEnabled()) {
76+
logger.info("Processing file: " + f.getAbsolutePath());
7077
}
78+
deleteResource(mgr, context, f);
7179
}
7280
}
7381
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package com.marklogic.appdeployer.command;
2+
3+
import com.marklogic.appdeployer.command.alert.DeployAlertActionsCommand;
4+
import com.marklogic.appdeployer.command.alert.DeployAlertConfigsCommand;
5+
import com.marklogic.appdeployer.command.alert.DeployAlertRulesCommand;
6+
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
7+
import com.marklogic.appdeployer.command.appservers.UpdateRestApiServersCommand;
8+
import com.marklogic.appdeployer.command.clusters.ModifyLocalClusterCommand;
9+
import com.marklogic.appdeployer.command.cpf.DeployCpfConfigsCommand;
10+
import com.marklogic.appdeployer.command.cpf.DeployDomainsCommand;
11+
import com.marklogic.appdeployer.command.cpf.DeployPipelinesCommand;
12+
import com.marklogic.appdeployer.command.databases.DeployContentDatabasesCommand;
13+
import com.marklogic.appdeployer.command.databases.DeployOtherDatabasesCommand;
14+
import com.marklogic.appdeployer.command.databases.DeploySchemasDatabaseCommand;
15+
import com.marklogic.appdeployer.command.databases.DeployTriggersDatabaseCommand;
16+
import com.marklogic.appdeployer.command.flexrep.DeployConfigsCommand;
17+
import com.marklogic.appdeployer.command.flexrep.DeployFlexrepCommand;
18+
import com.marklogic.appdeployer.command.flexrep.DeployTargetsCommand;
19+
import com.marklogic.appdeployer.command.forests.ConfigureForestReplicasCommand;
20+
import com.marklogic.appdeployer.command.forests.DeployCustomForestsCommand;
21+
import com.marklogic.appdeployer.command.groups.DeployGroupsCommand;
22+
import com.marklogic.appdeployer.command.mimetypes.DeployMimetypesCommand;
23+
import com.marklogic.appdeployer.command.modules.LoadModulesCommand;
24+
import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand;
25+
import com.marklogic.appdeployer.command.schemas.LoadSchemasCommand;
26+
import com.marklogic.appdeployer.command.security.*;
27+
import com.marklogic.appdeployer.command.tasks.DeployScheduledTasksCommand;
28+
import com.marklogic.appdeployer.command.triggers.DeployTriggersCommand;
29+
import com.marklogic.appdeployer.command.viewschemas.DeployViewSchemasCommand;
30+
31+
import java.util.ArrayList;
32+
import java.util.HashMap;
33+
import java.util.List;
34+
import java.util.Map;
35+
36+
/**
37+
* The intent of this class is to construct a map of commonly used commands that can used in a variety of contexts - i.e.
38+
* ml-gradle or the Data Hub Framework - thus preventing those clients from having to duplicate this code.
39+
*
40+
* A map is returned so that the commands can be grouped into lists, which is convenient for e.g. ml-gradle tasks that
41+
* want to execute all of the commands for a particular resource or set of resources - e.g. mlSecurityCommands for
42+
* invoking all commands pertaining to security resources.
43+
*/
44+
public class CommandMapBuilder {
45+
46+
public Map<String, List<Command>> buildCommandMap() {
47+
Map<String, List<Command>> map = new HashMap<>();
48+
49+
// Security
50+
List<Command> securityCommands = new ArrayList<Command>();
51+
securityCommands.add(new DeployRolesCommand());
52+
securityCommands.add(new DeployUsersCommand());
53+
securityCommands.add(new DeployAmpsCommand());
54+
securityCommands.add(new DeployCertificateTemplatesCommand());
55+
securityCommands.add(new DeployCertificateAuthoritiesCommand());
56+
securityCommands.add(new DeployExternalSecurityCommand());
57+
securityCommands.add(new DeployPrivilegesCommand());
58+
securityCommands.add(new DeployProtectedCollectionsCommand());
59+
map.put("mlSecurityCommands", securityCommands);
60+
61+
// Cluster
62+
List<Command> clusterCommands = new ArrayList<Command>();
63+
clusterCommands.add(new ModifyLocalClusterCommand());
64+
map.put("mlClusterCommands", clusterCommands);
65+
66+
// Databases
67+
List<Command> dbCommands = new ArrayList<Command>();
68+
dbCommands.add(new DeployContentDatabasesCommand());
69+
dbCommands.add(new DeployTriggersDatabaseCommand());
70+
dbCommands.add(new DeploySchemasDatabaseCommand());
71+
dbCommands.add(new DeployOtherDatabasesCommand());
72+
map.put("mlDatabaseCommands", dbCommands);
73+
74+
// Schemas
75+
List<Command> schemaCommands = new ArrayList<>();
76+
schemaCommands.add(new LoadSchemasCommand());
77+
map.put("mlSchemaCommands", schemaCommands);
78+
79+
// REST API instance creation
80+
List<Command> restApiCommands = new ArrayList<>();
81+
restApiCommands.add(new DeployRestApiServersCommand());
82+
map.put("mlRestApiCommands", restApiCommands);
83+
84+
// App servers
85+
List<Command> serverCommands = new ArrayList<>();
86+
serverCommands.add(new DeployOtherServersCommand());
87+
serverCommands.add(new UpdateRestApiServersCommand());
88+
map.put("mlServerCommands", serverCommands);
89+
90+
// Modules
91+
List<Command> moduleCommands = new ArrayList<>();
92+
moduleCommands.add(new LoadModulesCommand());
93+
map.put("mlModuleCommands", moduleCommands);
94+
95+
// Alerting
96+
List<Command> alertCommands = new ArrayList<Command>();
97+
alertCommands.add(new DeployAlertConfigsCommand());
98+
alertCommands.add(new DeployAlertActionsCommand());
99+
alertCommands.add(new DeployAlertRulesCommand());
100+
map.put("mlAlertCommands", alertCommands);
101+
102+
// CPF
103+
List<Command> cpfCommands = new ArrayList<Command>();
104+
cpfCommands.add(new DeployCpfConfigsCommand());
105+
cpfCommands.add(new DeployDomainsCommand());
106+
cpfCommands.add(new DeployPipelinesCommand());
107+
map.put("mlCpfCommands", cpfCommands);
108+
109+
// Flexrep
110+
List<Command> flexrepCommands = new ArrayList<Command>();
111+
flexrepCommands.add(new DeployConfigsCommand());
112+
flexrepCommands.add(new DeployTargetsCommand());
113+
flexrepCommands.add(new DeployFlexrepCommand());
114+
map.put("mlFlexrepCommands", flexrepCommands);
115+
116+
// Groups
117+
List<Command> groupCommands = new ArrayList<Command>();
118+
groupCommands.add(new DeployGroupsCommand());
119+
map.put("mlGroupCommands", groupCommands);
120+
121+
List<Command> mimetypeCommands = new ArrayList<Command>();
122+
mimetypeCommands.add(new DeployMimetypesCommand());
123+
map.put("mlMimetypeCommands", mimetypeCommands);
124+
125+
// Forests
126+
List<Command> forestCommands = new ArrayList<Command>();
127+
forestCommands.add(new DeployCustomForestsCommand());
128+
map.put("mlForestCommands", forestCommands);
129+
130+
// Forest replicas
131+
List<Command> replicaCommands = new ArrayList<Command>();
132+
replicaCommands.add(new ConfigureForestReplicasCommand());
133+
map.put("mlForestReplicaCommands", replicaCommands);
134+
135+
// Tasks
136+
List<Command> taskCommands = new ArrayList<Command>();
137+
taskCommands.add(new DeployScheduledTasksCommand());
138+
map.put("mlTaskCommands", taskCommands);
139+
140+
// Triggers
141+
List<Command> triggerCommands = new ArrayList<Command>();
142+
triggerCommands.add(new DeployTriggersCommand());
143+
map.put("mlTriggerCommands", triggerCommands);
144+
145+
// SQL Views
146+
List<Command> viewCommands = new ArrayList<Command>();
147+
viewCommands.add(new DeployViewSchemasCommand());
148+
map.put("mlViewCommands", viewCommands);
149+
150+
return map;
151+
}
152+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.marklogic.appdeployer.command.clusters;
2+
3+
import com.marklogic.appdeployer.command.AbstractCommand;
4+
import com.marklogic.appdeployer.command.CommandContext;
5+
import com.marklogic.appdeployer.command.SortOrderConstants;
6+
import com.marklogic.mgmt.clusters.ClusterManager;
7+
8+
import java.io.File;
9+
10+
/**
11+
* Looks for a file with a name starting with "local-cluster" (e.g. "local-cluster.json" or "local-cluster.xml") in the
12+
* "clusters" directory. The cluster endpoints - https://docs.marklogic.com/REST/management/clusters - offer a lot more
13+
* functionality; this command is just for the https://docs.marklogic.com/REST/PUT/manage/v2/properties endpoint.
14+
*/
15+
public class ModifyLocalClusterCommand extends AbstractCommand {
16+
17+
public ModifyLocalClusterCommand() {
18+
setExecuteSortOrder(SortOrderConstants.MODIFY_LOCAL_CLUSTER);
19+
}
20+
21+
@Override
22+
public void execute(CommandContext context) {
23+
File configDir = context.getAppConfig().getConfigDir().getClustersDir();
24+
if (configDir != null && configDir.exists()) {
25+
for (File f : configDir.listFiles()) {
26+
if (f.isFile() && f.getName().startsWith("local-cluster")) {
27+
String payload = copyFileToString(f);
28+
payload = tokenReplacer.replaceTokens(payload, context.getAppConfig(), false);
29+
new ClusterManager(context.getManageClient()).modifyLocalCluster(payload, context.getAdminManager());
30+
}
31+
}
32+
}
33+
}
34+
35+
}

0 commit comments

Comments
 (0)