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

Commit 584b0b0

Browse files
committed
#334 Fixing some bugs with combined CMA requests
Turns out amps can't be included with databases and forests because REST API instances are created after them, but amps may depend on a modules database created by a REST API instance. Also removed custom forests from a combined request, as there was little improvement to that, and it could lead to a bug in DHF with its custom command for deploying database fields.
1 parent bfb50ca commit 584b0b0

File tree

7 files changed

+35
-66
lines changed

7 files changed

+35
-66
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.marklogic.mgmt.admin.AdminManager;
88
import com.marklogic.mgmt.api.API;
99
import com.marklogic.mgmt.api.Resource;
10+
import com.marklogic.mgmt.api.configuration.Configuration;
11+
import com.marklogic.mgmt.api.configuration.Configurations;
1012
import com.marklogic.mgmt.cma.ConfigurationManager;
1113
import com.marklogic.mgmt.mapper.DefaultResourceMapper;
1214
import com.marklogic.mgmt.mapper.ResourceMapper;
@@ -480,6 +482,19 @@ protected boolean cmaEndpointExists(CommandContext context) {
480482
return new ConfigurationManager(context.getManageClient()).endpointExists();
481483
}
482484

485+
/**
486+
* Subclasses may override this to defer submission of a configuration so that it can be combined with other
487+
* configurations.
488+
*
489+
* @param context
490+
* @param config
491+
*/
492+
protected void deployConfiguration(CommandContext context, Configuration config) {
493+
if (config.hasResources()) {
494+
new Configurations(config).submit(context.getManageClient());
495+
}
496+
}
497+
483498
protected void setIncrementalMode(boolean incrementalMode) {
484499
if (resourceFilenameFilter instanceof IncrementalFilenameFilter) {
485500
((IncrementalFilenameFilter) resourceFilenameFilter).setIncrementalMode(incrementalMode);

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,6 @@ protected void saveMergedResourcesViaCma(CommandContext context, List<ResourceRe
175175
deployConfiguration(context, config);
176176
}
177177

178-
/**
179-
* Subclasses may override this to defer submission of a configuration so that it can be combined with other
180-
* configurations.
181-
*
182-
* @param context
183-
* @param config
184-
*/
185-
protected void deployConfiguration(CommandContext context, Configuration config) {
186-
if (config.hasResources()) {
187-
new Configurations(config).submit(context.getManageClient());
188-
}
189-
}
190-
191178
/**
192179
* Defaults to the parent method. This was extracted so that a subclass can override it and have access to the
193180
* CommandContext, which allows for reading in the contents of each file and replacing tokens, which may impact the

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public abstract class SortOrderConstants {
3232
public static Integer DEPLOY_OTHER_DATABASES = 120;
3333
public static Integer DEPLOY_FORESTS = 150;
3434

35-
// The modules database must exist before we deploy amps
36-
// For 3.15.0, amps are now deployed after databases and before servers so they can be included in a combined
37-
// CMA request with databases and forests.
38-
public static Integer DEPLOY_AMPS = 170;
39-
4035
public static Integer DEPLOY_REST_API_SERVERS = 200;
4136
public static Integer UPDATE_REST_API_SERVERS = 250;
4237
public static Integer DEPLOY_OTHER_SERVERS = 300;
@@ -51,7 +46,10 @@ public abstract class SortOrderConstants {
5146
public static Integer LOAD_MODULES = 400;
5247
public static Integer DELETE_TEST_MODULES = 410;
5348

54-
public static Integer DEPLOY_TRIGGERS = 700;
49+
// The modules database must exist before we deploy amps
50+
public static Integer DEPLOY_AMPS = 450;
51+
52+
public static Integer DEPLOY_TRIGGERS = 700;
5553

5654
public static Integer DEPLOY_TEMPORAL_AXIS = 750;
5755
public static Integer DEPLOY_TEMPORAL_COLLECTIONS = 751;

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,12 @@ protected void deployDatabasesAndForestsViaCma(CommandContext context, List<Data
372372
}
373373
});
374374

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());
375+
new Configurations(dbConfig, forestConfig).submit(context.getManageClient());
382376

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-
}
377+
// Now account for sub-databases, but not yet (as of 3.15.0) with CMA
378+
databasePlans.forEach(plan -> {
379+
plan.getDeployDatabaseCommand().deploySubDatabases(plan.getDatabaseName(), context);
380+
});
388381
}
389382

390383
/**

src/main/java/com/marklogic/appdeployer/command/forests/DeployCustomForestsCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void execute(CommandContext context) {
5454
}
5555

5656
if (configuration != null) {
57-
context.addCmaConfigurationToCombinedRequest(configuration);
57+
deployConfiguration(context, configuration);
5858
}
5959
}
6060

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,4 @@ protected boolean ampIsUnchanged(ObjectNode amp) {
7575
}
7676
return false;
7777
}
78-
79-
@Override
80-
protected void deployConfiguration(CommandContext context, Configuration config) {
81-
if (context.getAppConfig().getCmaConfig().isCombineRequests()) {
82-
logger.info("Adding amps to combined CMA request");
83-
context.addCmaConfigurationToCombinedRequest(config);
84-
} else {
85-
super.deployConfiguration(context, config);
86-
}
87-
}
8878
}

src/main/java/com/marklogic/appdeployer/impl/CmaDeployerListener.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import com.marklogic.appdeployer.command.Command;
44
import com.marklogic.appdeployer.command.CommandContext;
55
import com.marklogic.appdeployer.command.SortOrderConstants;
6-
import com.marklogic.appdeployer.command.databases.DatabasePlan;
7-
import com.marklogic.appdeployer.command.security.DeployAmpsCommand;
86
import com.marklogic.appdeployer.command.security.DeployUsersCommand;
97
import com.marklogic.mgmt.api.configuration.Configurations;
108

@@ -15,10 +13,10 @@
1513
* should be submitted when any of the following are true:
1614
*
1715
* <ol>
18-
* <li>DeployUsersCommand was just executed, meaning that a combined request of privileges, roles, and users should be submitted.</li>
19-
* <li>DeployOtherDatabaseCommand was just executed, meaning that a combined request of databases and forests should be submitted.</li>
16+
* <li>Users were just deployed, meaning that a combined request of privileges, roles, protected paths,
17+
* query rolesets, and users should be submitted.</li>
2018
* <li>No commands remain to be executed. In this case, need to check for a pending combined request that should be submitted. This can easily
21-
* happen in e.g. an ml-gradle context when running a task like mlDeployPrivileges or mlDeployDatabases.
19+
* happen in e.g. an ml-gradle context when running a task like mlDeployPrivileges.
2220
* </li>
2321
* </ol>
2422
* <p>
@@ -30,33 +28,22 @@ public class CmaDeployerListener extends DeployerListenerSupport {
3028

3129
@Override
3230
public void afterCommandExecuted(Command command, DeploymentContext context, List<Command> remainingCommands) {
33-
if (combinedRequestBeSubmitted(command, remainingCommands)) {
31+
if (combinedRequestShouldBeSubmitted(command, remainingCommands)) {
3432
CommandContext commandContext = context.getCommandContext();
3533

3634
Configurations configs = commandContext.getCombinedCmaRequest();
3735
if (configs != null) {
3836
commandContext.removeCombinedCmaRequest();
39-
4037
if (configs.hasResources()) {
4138
logger.info("Submitting combined CMA request");
4239
configs.submit(commandContext.getManageClient());
43-
44-
if (command instanceof DeployAmpsCommand || remainingCommands.isEmpty()) {
45-
List<DatabasePlan> databasePlans = (List<DatabasePlan>) commandContext.getContextMap().get("database-plans");
46-
if (databasePlans != null) {
47-
commandContext.getContextMap().remove("database-plans");
48-
databasePlans.forEach(plan -> {
49-
plan.getDeployDatabaseCommand().deploySubDatabases(plan.getDatabaseName(), commandContext);
50-
});
51-
}
52-
}
5340
}
5441
}
5542
}
5643
}
5744

58-
protected boolean combinedRequestBeSubmitted(Command command, List<Command> remainingCommands) {
59-
if (command instanceof DeployUsersCommand || command instanceof DeployAmpsCommand) {
45+
protected boolean combinedRequestShouldBeSubmitted(Command command, List<Command> remainingCommands) {
46+
if (command instanceof DeployUsersCommand) {
6047
return true;
6148
}
6249

@@ -65,12 +52,11 @@ protected boolean combinedRequestBeSubmitted(Command command, List<Command> rema
6552
}
6653

6754
/**
68-
* At least for many ml-app-deployer tests, a small subset of commands are used - for example, perhaps only the
69-
* commands for deploying databases and triggers are used. To ensure that databases are still deployed, we look
70-
* at the next command to see if it's being executed after amps are deployed, as amps are the last resource
71-
* we include in a combined request. If so, then we know we need to submit the combined request.
55+
* At least for many ml-app-deployer tests, a small subset of commands are used. To ensure a combined request
56+
* is submitted, we look at the next command to see if it executes after users are deployed, and if so, then
57+
* the request is submitted.
7258
*/
7359
Command nextCommand = remainingCommands.get(0);
74-
return nextCommand.getExecuteSortOrder() >= SortOrderConstants.DEPLOY_AMPS;
60+
return nextCommand.getExecuteSortOrder() >= SortOrderConstants.DEPLOY_USERS;
7561
}
7662
}

0 commit comments

Comments
 (0)