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

Commit 6d639ee

Browse files
committed
#334 Combining many resources into a single CMA request
Also addresses: #326 Deploying users via CMA #277 Deploying roles via CMA #352 Deploying amps via CMA
1 parent 6460f49 commit 6d639ee

Some content is hidden

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

45 files changed

+1000
-85
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
3-
version=3.14.346
3+
version=3.15.develop
44
mlJavaclientUtilVersion=3.12.0
55
mlJunitVersion=3.1.0
66

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,4 +1378,19 @@ public CmaConfig getCmaConfig() {
13781378
public void setCmaConfig(CmaConfig cmaConfig) {
13791379
this.cmaConfig = cmaConfig;
13801380
}
1381+
1382+
// Still used by DHF 4.3.x
1383+
@Deprecated
1384+
public void setDeployForestsWithCma(boolean b) {
1385+
getCmaConfig().setDeployForests(b);
1386+
}
1387+
@Deprecated
1388+
public void setDeployPrivilegesWithCma(boolean b) {
1389+
getCmaConfig().setDeployPrivileges(b);
1390+
}
1391+
@Deprecated
1392+
public void setDeployAmpsWithCma(boolean b) {
1393+
getCmaConfig().setDeployAmps(b);
1394+
}
1395+
// End of methods still used by DHF 4.3.x
13811396
}

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22

33
public class CmaConfig {
44

5-
private boolean deployAmps = false;
6-
private boolean deployDatabases = false;
7-
private boolean deployForests = false;
8-
private boolean deployPrivileges = false;
9-
private boolean deployServers = false;
5+
private boolean combineRequests;
6+
private boolean deployAmps;
7+
private boolean deployDatabases;
8+
private boolean deployForests;
9+
private boolean deployPrivileges;
10+
private boolean deployRoles;
11+
private boolean deployServers;
12+
private boolean deployUsers;
13+
14+
public void enableAll() {
15+
setCombineRequests(true);
16+
setDeployAmps(true);
17+
setDeployDatabases(true);
18+
setDeployForests(true);
19+
setDeployPrivileges(true);
20+
setDeployRoles(true);
21+
setDeployServers(true);
22+
setDeployUsers(true);
23+
}
1024

1125
public boolean isDeployAmps() {
1226
return deployAmps;
@@ -47,4 +61,28 @@ public boolean isDeployServers() {
4761
public void setDeployServers(boolean deployServers) {
4862
this.deployServers = deployServers;
4963
}
64+
65+
public boolean isDeployRoles() {
66+
return deployRoles;
67+
}
68+
69+
public void setDeployRoles(boolean deployRoles) {
70+
this.deployRoles = deployRoles;
71+
}
72+
73+
public boolean isDeployUsers() {
74+
return deployUsers;
75+
}
76+
77+
public void setDeployUsers(boolean deployUsers) {
78+
this.deployUsers = deployUsers;
79+
}
80+
81+
public boolean isCombineRequests() {
82+
return combineRequests;
83+
}
84+
85+
public void setCombineRequests(boolean combineRequests) {
86+
this.combineRequests = combineRequests;
87+
}
5088
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ public void initialize() {
7272

7373
final String cmaMessage = " with the Configuration Management API (CMA): ";
7474

75+
propertyConsumerMap.put("mlDeployWithCma", (config, prop) -> {
76+
logger.info("Deploy all supported resources and combine requests" + cmaMessage + prop);
77+
if (Boolean.parseBoolean(prop)) {
78+
config.getCmaConfig().enableAll();
79+
}
80+
});
81+
82+
propertyConsumerMap.put("mlCombineCmaRequests", (config, prop) -> {
83+
logger.info("Combine requests" + cmaMessage + prop);
84+
config.getCmaConfig().setCombineRequests(Boolean.parseBoolean(prop));
85+
});
86+
7587
propertyConsumerMap.put("mlDeployAmpsWithCma", (config, prop) -> {
7688
logger.info("Deploy amps" + cmaMessage + prop);
7789
config.getCmaConfig().setDeployAmps(Boolean.parseBoolean(prop));
@@ -92,11 +104,21 @@ public void initialize() {
92104
config.getCmaConfig().setDeployPrivileges(Boolean.parseBoolean(prop));
93105
});
94106

107+
propertyConsumerMap.put("mlDeployRolesWithCma", (config, prop) -> {
108+
logger.info("Deploy servers" + cmaMessage + prop);
109+
config.getCmaConfig().setDeployRoles(Boolean.parseBoolean(prop));
110+
});
111+
95112
propertyConsumerMap.put("mlDeployServersWithCma", (config, prop) -> {
96113
logger.info("Deploy servers" + cmaMessage + prop);
97114
config.getCmaConfig().setDeployServers(Boolean.parseBoolean(prop));
98115
});
99116

117+
propertyConsumerMap.put("mlDeployUsersWithCma", (config, prop) -> {
118+
logger.info("Deploy users" + cmaMessage + prop);
119+
config.getCmaConfig().setDeployUsers(Boolean.parseBoolean(prop));
120+
});
121+
100122
propertyConsumerMap.put("mlAddHostNameTokens", (config, prop) -> {
101123
logger.info("Add host names to the custom tokens map: " + prop);
102124
config.setAddHostNameTokens(Boolean.parseBoolean(prop));

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected void deployResourcesViaCma(CommandContext context, File resourceDir) {
171171
((SupportsCmaCommand) this).addResourceToConfiguration(objectNode, config);
172172
}
173173
}
174-
new Configurations(config).submit(context.getManageClient());
174+
deployConfiguration(context, config);
175175
}
176176

177177
/**
@@ -184,7 +184,20 @@ protected void saveMergedResourcesViaCma(CommandContext context, List<ResourceRe
184184
for (ResourceReference reference : mergedReferences) {
185185
((SupportsCmaCommand)this).addResourceToConfiguration(reference.getObjectNode(), config);
186186
}
187-
new Configurations(config).submit(context.getManageClient());
187+
deployConfiguration(context, config);
188+
}
189+
190+
/**
191+
* Subclasses may override this to defer submission of a configuration so that it can be combined with other
192+
* configurations.
193+
*
194+
* @param context
195+
* @param config
196+
*/
197+
protected void deployConfiguration(CommandContext context, Configuration config) {
198+
if (config.hasResources()) {
199+
new Configurations(config).submit(context.getManageClient());
200+
}
188201
}
189202

190203
/**

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

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.marklogic.appdeployer.AppConfig;
44
import com.marklogic.mgmt.ManageClient;
55
import com.marklogic.mgmt.admin.AdminManager;
6+
import com.marklogic.mgmt.api.configuration.Configuration;
7+
import com.marklogic.mgmt.api.configuration.Configurations;
68

79
import java.util.HashMap;
810
import java.util.Map;
@@ -11,39 +13,58 @@
1113
* Defines the context within which a command executes, which includes:
1214
*
1315
* <ul>
14-
* <li>An AppConfig object that defines configuration values for an application</li>
15-
* <li>A ManageClient for connecting to the Manage API</li>
16-
* <li>An AdminManager for performing operations against the Admin app server</li>
17-
* <li>A context map that commands are free to store anything they wish within</li>
16+
* <li>An AppConfig object that defines configuration values for an application</li>
17+
* <li>A ManageClient for connecting to the Manage API</li>
18+
* <li>An AdminManager for performing operations against the Admin app server</li>
19+
* <li>A context map that commands are free to store anything they wish within</li>
1820
* </ul>
1921
*/
2022
public class CommandContext {
2123

22-
private AppConfig appConfig;
23-
private ManageClient manageClient;
24-
private AdminManager adminManager;
24+
private AppConfig appConfig;
25+
private ManageClient manageClient;
26+
private AdminManager adminManager;
2527

26-
private Map<String, Object> contextMap;
28+
private Map<String, Object> contextMap;
2729

28-
public CommandContext(AppConfig appConfig, ManageClient manageClient, AdminManager adminManager) {
29-
super();
30-
this.appConfig = appConfig;
31-
this.manageClient = manageClient;
32-
this.adminManager = adminManager;
33-
this.contextMap = new HashMap<>();
34-
}
30+
private final static String COMBINED_CMA_REQUEST_KEY = "cma-combined-request";
3531

36-
public AppConfig getAppConfig() {
37-
return appConfig;
38-
}
32+
public CommandContext(AppConfig appConfig, ManageClient manageClient, AdminManager adminManager) {
33+
super();
34+
this.appConfig = appConfig;
35+
this.manageClient = manageClient;
36+
this.adminManager = adminManager;
37+
this.contextMap = new HashMap<>();
38+
}
39+
40+
public void addCmaConfigurationToCombinedRequest(Configuration configuration) {
41+
Configurations configs = getCombinedCmaRequest();
42+
if (configs == null) {
43+
contextMap.put(COMBINED_CMA_REQUEST_KEY, new Configurations(configuration));
44+
} else {
45+
configs.addConfig(configuration);
46+
}
47+
}
3948

40-
public ManageClient getManageClient() {
41-
return manageClient;
42-
}
49+
public Configurations getCombinedCmaRequest() {
50+
return (Configurations) contextMap.get(COMBINED_CMA_REQUEST_KEY);
51+
}
52+
53+
public void removeCombinedCmaRequest() {
54+
contextMap.remove(COMBINED_CMA_REQUEST_KEY);
55+
}
4356

44-
public AdminManager getAdminManager() {
45-
return adminManager;
46-
}
57+
public AppConfig getAppConfig() {
58+
return appConfig;
59+
}
60+
61+
public ManageClient getManageClient() {
62+
return manageClient;
63+
}
64+
65+
public AdminManager getAdminManager() {
66+
return adminManager;
67+
}
4768

4869
public Map<String, Object> getContextMap() {
4970
return contextMap;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ public abstract class SortOrderConstants {
2929
public static Integer DEPLOY_SCHEMAS_DATABASE = 100;
3030

3131
public static Integer DEPLOY_OTHER_DATABASES = 120;
32-
public static Integer DEPLOY_CONTENT_DATABASES = 130;
3332
public static Integer DEPLOY_FORESTS = 150;
3433

35-
public static Integer DEPLOY_REST_API_SERVERS = 200;
34+
// The modules database must exist before we deploy amps
35+
// For 3.15.0, amps are now deployed after databases and before servers so they can be included in a combined
36+
// CMA request with databases and forests.
37+
public static Integer DEPLOY_AMPS = 170;
38+
39+
public static Integer DEPLOY_REST_API_SERVERS = 200;
3640
public static Integer UPDATE_REST_API_SERVERS = 250;
3741
public static Integer DEPLOY_OTHER_SERVERS = 300;
3842

@@ -46,9 +50,6 @@ public abstract class SortOrderConstants {
4650
public static Integer LOAD_MODULES = 400;
4751
public static Integer DELETE_TEST_MODULES = 410;
4852

49-
// The modules database must exist before we deploy amps
50-
public static Integer DEPLOY_AMPS = 450;
51-
5253
public static Integer DEPLOY_TRIGGERS = 700;
5354

5455
public static Integer DEPLOY_TEMPORAL_AXIS = 750;

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.marklogic.appdeployer.command.AbstractUndoableCommand;
77
import com.marklogic.appdeployer.command.CommandContext;
88
import com.marklogic.appdeployer.command.SortOrderConstants;
9-
import com.marklogic.appdeployer.command.SupportsCmaCommand;
109
import com.marklogic.appdeployer.command.forests.DeployForestsCommand;
1110
import com.marklogic.mgmt.PayloadParser;
1211
import com.marklogic.mgmt.api.API;
@@ -90,9 +89,7 @@ public void execute(CommandContext context) {
9089

9190
if (context.getAppConfig().getCmaConfig().isDeployDatabases()) {
9291
deployDatabasesAndForestsViaCma(context, databasePlans);
93-
}
94-
95-
else {
92+
} else {
9693
// Otherwise, create each database one at a time, which also handles sub-databases
9794
databasePlans.forEach(databasePlan -> {
9895
databasePlan.getDeployDatabaseCommand().execute(context);
@@ -143,7 +140,7 @@ public void undo(CommandContext context) {
143140
* database files together; and then building an instance of DeployDatabaseCommand for each database that needs
144141
* to be deployed. This method doesn't make any calls to deploy/undeploy databases though - it just builds up all
145142
* the data that is needed to do so.
146-
*
143+
* <p>
147144
* This is public so that ml-gradle can invoke it when previewing what forests will be created for a database.
148145
*
149146
* @param context
@@ -160,9 +157,9 @@ public List<DatabasePlan> buildDatabasePlans(CommandContext context) {
160157
List<DatabasePlan> databasePlans = mergeDatabasePlanFiles(context, databasePlan);
161158
buildDeployDatabaseCommands(context, databasePlans);
162159

163-
if (logger.isInfoEnabled()) {
164-
logger.info("Logging the files for each database before it's created or updated:");
165-
databasePlans.forEach(plan -> logger.info(plan + "\n"));
160+
if (logger.isDebugEnabled()) {
161+
logger.debug("Logging the files for each database before it's created or updated:");
162+
databasePlans.forEach(plan -> logger.debug(plan + "\n"));
166163
}
167164

168165
return databasePlans;
@@ -351,7 +348,7 @@ protected void buildDeployDatabaseCommands(CommandContext context, List<Database
351348
/**
352349
* As of 3.15.0, if databases are to be deployed via CMA, then their forests will also be deployed via CMA,
353350
* regardless of the setting on the AppConfig instance.
354-
*
351+
* <p>
355352
* Also as of 3.15.0, sub-databases and their forests are never deployed by CMA. Will support this in a future
356353
* release.
357354
*
@@ -375,13 +372,19 @@ protected void deployDatabasesAndForestsViaCma(CommandContext context, List<Data
375372
}
376373
});
377374

378-
new Configurations(dbConfig, forestConfig).submit(context.getManageClient());
375+
if (context.getAppConfig().getCmaConfig().isCombineRequests()) {
376+
logger.info("Adding databases and forests to combined CMA request");
377+
context.addCmaConfigurationToCombinedRequest(dbConfig);
378+
context.addCmaConfigurationToCombinedRequest(forestConfig);
379+
context.getContextMap().put("database-plans", databasePlans);
380+
} else {
381+
new Configurations(dbConfig, forestConfig).submit(context.getManageClient());
379382

380-
// Now account for sub-databases, but not with CMA
381-
databasePlans.forEach(plan -> {
382-
final DeployDatabaseCommand deployDatabaseCommand = plan.getDeployDatabaseCommand();
383-
deployDatabaseCommand.deploySubDatabases(plan.getDatabaseName(), context);
384-
});
383+
// Now account for sub-databases, but not yet (as of 3.15.0) with CMA
384+
databasePlans.forEach(plan -> {
385+
plan.getDeployDatabaseCommand().deploySubDatabases(plan.getDatabaseName(), context);
386+
});
387+
}
385388
}
386389

387390
/**

src/main/java/com/marklogic/appdeployer/command/security/DeployAmpsCommand.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ public boolean cmaShouldBeUsed(CommandContext context) {
4141
public void addResourceToConfiguration(ObjectNode payload, Configuration configuration) {
4242
configuration.addAmp(payload);
4343
}
44+
45+
@Override
46+
protected void deployConfiguration(CommandContext context, Configuration config) {
47+
if (context.getAppConfig().getCmaConfig().isCombineRequests()) {
48+
logger.info("Adding amps to combined CMA request");
49+
context.addCmaConfigurationToCombinedRequest(config);
50+
} else {
51+
super.deployConfiguration(context, config);
52+
}
53+
}
4454
}

src/main/java/com/marklogic/appdeployer/command/security/DeployPrivilegesCommand.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public void addResourceToConfiguration(ObjectNode resource, Configuration config
4141
configuration.addPrivilege(resource);
4242
}
4343

44+
@Override
45+
protected void deployConfiguration(CommandContext context, Configuration config) {
46+
if (context.getAppConfig().getCmaConfig().isCombineRequests()) {
47+
logger.info("Adding privileges to combined CMA request");
48+
context.addCmaConfigurationToCombinedRequest(config);
49+
} else {
50+
super.deployConfiguration(context, config);
51+
}
52+
}
53+
4454
@Override
4555
protected BiPredicate<ResourceReference, ResourceReference> getBiPredicateForMergingResources() {
4656
return (reference1, reference2) -> {

0 commit comments

Comments
 (0)