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

Commit 6460f49

Browse files
committed
#323 Can now deploy servers via CMA
1 parent ffcc45d commit 6460f49

16 files changed

+146
-57
lines changed

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

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ public class AppConfig {
7373
private boolean catchDeployExceptions = false;
7474
private boolean catchUndeployExceptions = false;
7575

76-
private boolean deployAmpsWithCma = false;
77-
private boolean deployDatabasesWithCma = false;
78-
private boolean deployForestsWithCma = false;
79-
private boolean deployPrivilegesWithCma = false;
76+
private CmaConfig cmaConfig = new CmaConfig();
8077
private boolean mergeResources = true;
8178

8279
private boolean addHostNameTokens = false;
@@ -1260,22 +1257,6 @@ public void setAppServicesTrustManager(X509TrustManager appServicesTrustManager)
12601257
this.appServicesTrustManager = appServicesTrustManager;
12611258
}
12621259

1263-
public boolean isDeployAmpsWithCma() {
1264-
return deployAmpsWithCma;
1265-
}
1266-
1267-
public void setDeployAmpsWithCma(boolean deployAmpsWithCma) {
1268-
this.deployAmpsWithCma = deployAmpsWithCma;
1269-
}
1270-
1271-
public boolean isDeployForestsWithCma() {
1272-
return deployForestsWithCma;
1273-
}
1274-
1275-
public void setDeployForestsWithCma(boolean deployForestsWithCma) {
1276-
this.deployForestsWithCma = deployForestsWithCma;
1277-
}
1278-
12791260
@Deprecated
12801261
public boolean isCreateTriggersDatabase() {
12811262
return createTriggersDatabase;
@@ -1286,14 +1267,6 @@ public void setCreateTriggersDatabase(boolean createTriggerDatabase) {
12861267
this.createTriggersDatabase = createTriggerDatabase;
12871268
}
12881269

1289-
public boolean isDeployPrivilegesWithCma() {
1290-
return deployPrivilegesWithCma;
1291-
}
1292-
1293-
public void setDeployPrivilegesWithCma(boolean deployPrivilegesWithCma) {
1294-
this.deployPrivilegesWithCma = deployPrivilegesWithCma;
1295-
}
1296-
12971270
public ReplicaBuilderStrategy getReplicaBuilderStrategy() {
12981271
return replicaBuilderStrategy;
12991272
}
@@ -1398,11 +1371,11 @@ public void setAppServicesConnectionType(DatabaseClient.ConnectionType appServic
13981371
this.appServicesConnectionType = appServicesConnectionType;
13991372
}
14001373

1401-
public boolean isDeployDatabasesWithCma() {
1402-
return deployDatabasesWithCma;
1374+
public CmaConfig getCmaConfig() {
1375+
return cmaConfig;
14031376
}
14041377

1405-
public void setDeployDatabasesWithCma(boolean deployDatabasesWithCma) {
1406-
this.deployDatabasesWithCma = deployDatabasesWithCma;
1378+
public void setCmaConfig(CmaConfig cmaConfig) {
1379+
this.cmaConfig = cmaConfig;
14071380
}
14081381
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.marklogic.appdeployer;
2+
3+
public class CmaConfig {
4+
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;
10+
11+
public boolean isDeployAmps() {
12+
return deployAmps;
13+
}
14+
15+
public void setDeployAmps(boolean deployAmps) {
16+
this.deployAmps = deployAmps;
17+
}
18+
19+
public boolean isDeployDatabases() {
20+
return deployDatabases;
21+
}
22+
23+
public void setDeployDatabases(boolean deployDatabases) {
24+
this.deployDatabases = deployDatabases;
25+
}
26+
27+
public boolean isDeployForests() {
28+
return deployForests;
29+
}
30+
31+
public void setDeployForests(boolean deployForests) {
32+
this.deployForests = deployForests;
33+
}
34+
35+
public boolean isDeployPrivileges() {
36+
return deployPrivileges;
37+
}
38+
39+
public void setDeployPrivileges(boolean deployPrivileges) {
40+
this.deployPrivileges = deployPrivileges;
41+
}
42+
43+
public boolean isDeployServers() {
44+
return deployServers;
45+
}
46+
47+
public void setDeployServers(boolean deployServers) {
48+
this.deployServers = deployServers;
49+
}
50+
}

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,34 @@ public void initialize() {
6767
logger.info("mlOptimizeWithCma is DEPRECATED; please use a property specific to the resource that you want to deploy with CMA");
6868
// mlOptimizeWithCma was deprecated in 3.11; it was only used for deploying forests, so if the
6969
// property is still used, the client in theory expects forests to still be deployed with CMA
70-
config.setDeployForestsWithCma(true);
70+
config.getCmaConfig().setDeployForests(true);
7171
});
7272

7373
final String cmaMessage = " with the Configuration Management API (CMA): ";
74+
7475
propertyConsumerMap.put("mlDeployAmpsWithCma", (config, prop) -> {
7576
logger.info("Deploy amps" + cmaMessage + prop);
76-
config.setDeployAmpsWithCma(Boolean.parseBoolean(prop));
77+
config.getCmaConfig().setDeployAmps(Boolean.parseBoolean(prop));
7778
});
7879

7980
propertyConsumerMap.put("mlDeployDatabasesWithCma", (config, prop) -> {
8081
logger.info("Deploy databases and forests" + cmaMessage + prop);
81-
config.setDeployDatabasesWithCma(Boolean.parseBoolean(prop));
82+
config.getCmaConfig().setDeployDatabases(Boolean.parseBoolean(prop));
8283
});
8384

8485
propertyConsumerMap.put("mlDeployForestsWithCma", (config, prop) -> {
8586
logger.info("Deploy forests" + cmaMessage + prop);
86-
config.setDeployForestsWithCma(Boolean.parseBoolean(prop));
87+
config.getCmaConfig().setDeployForests(Boolean.parseBoolean(prop));
8788
});
8889

8990
propertyConsumerMap.put("mlDeployPrivilegesWithCma", (config, prop) -> {
9091
logger.info("Deploy privileges" + cmaMessage + prop);
91-
config.setDeployPrivilegesWithCma(Boolean.parseBoolean(prop));
92+
config.getCmaConfig().setDeployPrivileges(Boolean.parseBoolean(prop));
93+
});
94+
95+
propertyConsumerMap.put("mlDeployServersWithCma", (config, prop) -> {
96+
logger.info("Deploy servers" + cmaMessage + prop);
97+
config.getCmaConfig().setDeployServers(Boolean.parseBoolean(prop));
9298
});
9399

94100
propertyConsumerMap.put("mlAddHostNameTokens", (config, prop) -> {

src/main/java/com/marklogic/appdeployer/command/appservers/DeployOtherServersCommand.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.node.ObjectNode;
44
import com.marklogic.appdeployer.command.*;
55
import com.marklogic.mgmt.PayloadParser;
6+
import com.marklogic.mgmt.api.configuration.Configuration;
67
import com.marklogic.mgmt.api.server.Server;
78
import com.marklogic.mgmt.resource.ResourceManager;
89
import com.marklogic.mgmt.resource.appservers.ServerManager;
@@ -17,7 +18,7 @@
1718
* "Other" = non-REST-API servers. This will process every JSON/XML file that's not named "rest-api-server.*" in the
1819
* servers directory.
1920
*/
20-
public class DeployOtherServersCommand extends AbstractResourceCommand {
21+
public class DeployOtherServersCommand extends AbstractResourceCommand implements SupportsCmaCommand {
2122

2223
/**
2324
* Defines the server names that, by default, this command will never undeploy.
@@ -37,6 +38,16 @@ public DeployOtherServersCommand() {
3738
setResourceClassType(Server.class);
3839
}
3940

41+
@Override
42+
public boolean cmaShouldBeUsed(CommandContext context) {
43+
return context.getAppConfig().getCmaConfig().isDeployServers();
44+
}
45+
46+
@Override
47+
public void addResourceToConfiguration(ObjectNode resource, Configuration configuration) {
48+
configuration.addServer(resource);
49+
}
50+
4051
protected void initializeDefaultServersToNotUndeploy() {
4152
defaultServersToNotUndeploy = new HashSet<>();
4253
defaultServersToNotUndeploy.add("Admin");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void execute(CommandContext context) {
8888
logger.info("Not sorting databases by dependencies, will sort them by their filenames instead");
8989
}
9090

91-
if (context.getAppConfig().isDeployDatabasesWithCma()) {
91+
if (context.getAppConfig().getCmaConfig().isDeployDatabases()) {
9292
deployDatabasesAndForestsViaCma(context, databasePlans);
9393
}
9494

@@ -99,7 +99,7 @@ public void execute(CommandContext context) {
9999
});
100100

101101
// Either create forests in one bulk CMA request, or via a command per database
102-
if (context.getAppConfig().isDeployForestsWithCma()) {
102+
if (context.getAppConfig().getCmaConfig().isDeployForests()) {
103103
deployAllForestsInSingleCmaRequest(context, databasePlans);
104104
} else {
105105
databasePlans.forEach(databasePlan -> {
@@ -343,7 +343,7 @@ protected void buildDeployDatabaseCommands(CommandContext context, List<Database
343343
// Set the payload so the command doesn't try to generate it
344344
command.setPayload(databasePlan.getPayload());
345345

346-
command.setPostponeForestCreation(context.getAppConfig().isDeployForestsWithCma());
346+
command.setPostponeForestCreation(context.getAppConfig().getCmaConfig().isDeployForests());
347347
databasePlan.setDeployDatabaseCommand(command);
348348
});
349349
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void execute(CommandContext context) {
7676
// Replicas are currently handled by ConfigureForestReplicasCommand
7777
List<Forest> forests = buildForests(context, false);
7878

79-
if (context.getAppConfig().isDeployForestsWithCma() && !forests.isEmpty() && cmaEndpointExists(context)) {
79+
if (context.getAppConfig().getCmaConfig().isDeployForests() && !forests.isEmpty() && cmaEndpointExists(context)) {
8080
createForestsViaCma(context, forests);
8181
} else {
8282
createForestsViaForestEndpoint(context, forests);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected ResourceManager getResourceManager(CommandContext context) {
3434

3535
@Override
3636
public boolean cmaShouldBeUsed(CommandContext context) {
37-
return context.getAppConfig().isDeployAmpsWithCma();
37+
return context.getAppConfig().getCmaConfig().isDeployAmps();
3838
}
3939

4040
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected ResourceManager getResourceManager(CommandContext context) {
3333

3434
@Override
3535
public boolean cmaShouldBeUsed(CommandContext context) {
36-
return context.getAppConfig().isDeployPrivilegesWithCma();
36+
return context.getAppConfig().getCmaConfig().isDeployPrivileges();
3737
}
3838

3939
@Override

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void mostProperties() {
221221
p.setProperty("mlDeployDatabasesWithCma", "true");
222222
p.setProperty("mlDeployForestsWithCma", "true");
223223
p.setProperty("mlDeployPrivilegesWithCma", "true");
224-
p.setProperty("mlDeployRolesWithCma", "true");
224+
p.setProperty("mlDeployServersWithCma", "true");
225225

226226
p.setProperty("mlHost", "prophost");
227227
p.setProperty("mlAppName", "propname");
@@ -326,10 +326,11 @@ public void mostProperties() {
326326
assertTrue(config.isCatchDeployExceptions());
327327
assertTrue(config.isCatchUndeployExceptions());
328328

329-
assertTrue(config.isDeployAmpsWithCma());
330-
assertTrue(config.isDeployDatabasesWithCma());
331-
assertTrue(config.isDeployForestsWithCma());
332-
assertTrue(config.isDeployPrivilegesWithCma());
329+
assertTrue(config.getCmaConfig().isDeployAmps());
330+
assertTrue(config.getCmaConfig().isDeployDatabases());
331+
assertTrue(config.getCmaConfig().isDeployForests());
332+
assertTrue(config.getCmaConfig().isDeployPrivileges());
333+
assertTrue(config.getCmaConfig().isDeployServers());
333334

334335
assertEquals("prophost", config.getHost());
335336
assertEquals("propname", config.getName());

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ public void servers() {
108108

109109
@Test
110110
public void databasesWithoutCma() {
111-
appConfig.setDeployDatabasesWithCma(false);
111+
appConfig.getCmaConfig().setDeployDatabases(false);
112112
deployMultipleDatabasesNeededMergingAndVerify();
113113
}
114114

115115
@Test
116116
public void databasesWithCma() {
117-
appConfig.setDeployDatabasesWithCma(true);
117+
appConfig.getCmaConfig().setDeployDatabases(true);
118118
deployMultipleDatabasesNeededMergingAndVerify();
119119
}
120120

@@ -124,7 +124,7 @@ public void databasesWithCma() {
124124
private void deployMultipleDatabasesNeededMergingAndVerify() {
125125
appConfig.setContentForestsPerHost(2);
126126
appConfig.setTestRestPort(appConfig.getRestPort() + 1);
127-
appConfig.setDeployForestsWithCma(true);
127+
appConfig.getCmaConfig().setDeployForests(true);
128128

129129
initializeAppDeployer(new DeployOtherDatabasesCommand());
130130
deploySampleApp();

0 commit comments

Comments
 (0)