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

Commit c630abf

Browse files
committed
#394 Can now deploy partition and partition queries
1 parent 5cdfd6e commit c630abf

File tree

22 files changed

+565
-59
lines changed

22 files changed

+565
-59
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ public File getTriggersDir() {
128128
return new File(getBaseDir(), "triggers");
129129
}
130130

131+
// This is expected to be relative to a database-specific directory
132+
public File getPartitionsDir() {
133+
return new File(getBaseDir(), "partitions");
134+
}
135+
136+
// This is expected to be relative to a database-specific directory
137+
public File getPartitionQueriesDir() {
138+
return new File(getBaseDir(), "partition-queries");
139+
}
140+
131141
public File getUsersDir() {
132142
return new File(getSecurityDir(), "users");
133143
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.marklogic.appdeployer.command.modules.DeleteTestModulesCommand;
2424
import com.marklogic.appdeployer.command.modules.LoadModulesCommand;
2525
import com.marklogic.appdeployer.command.plugins.InstallPluginsCommand;
26+
import com.marklogic.appdeployer.command.rebalancer.DeployPartitionQueriesCommand;
27+
import com.marklogic.appdeployer.command.rebalancer.DeployPartitionsCommand;
2628
import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand;
2729
import com.marklogic.appdeployer.command.schemas.LoadSchemasCommand;
2830
import com.marklogic.appdeployer.command.security.*;
@@ -42,7 +44,7 @@
4244
/**
4345
* The intent of this class is to construct a map of commonly used commands that can used in a variety of contexts - i.e.
4446
* ml-gradle or the Data Hub Framework - thus preventing those clients from having to duplicate this code.
45-
*
47+
* <p>
4648
* A map is returned so that the commands can be grouped into lists, which is convenient for e.g. ml-gradle tasks that
4749
* want to execute all of the commands for a particular resource or set of resources - e.g. mlSecurityCommands for
4850
* invoking all commands pertaining to security resources.
@@ -83,6 +85,12 @@ public Map<String, List<Command>> buildCommandMap() {
8385
dbCommands.add(new DeployOtherDatabasesCommand());
8486
map.put("mlDatabaseCommands", dbCommands);
8587

88+
// Database rebalancer
89+
List<Command> rebalancerCommands = new ArrayList<>();
90+
rebalancerCommands.add(new DeployPartitionsCommand());
91+
rebalancerCommands.add(new DeployPartitionQueriesCommand());
92+
map.put("mlRebalancerCommands", rebalancerCommands);
93+
8694
// Schemas
8795
List<Command> schemaCommands = new ArrayList<>();
8896
schemaCommands.add(new LoadSchemasCommand());

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

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
public abstract class SortOrderConstants {
44

5-
public static Integer DEPLOY_PRIVILEGES = 5;
6-
public static Integer DEPLOY_ROLES = 10;
5+
public static Integer DEPLOY_PRIVILEGES = 5;
6+
public static Integer DEPLOY_ROLES = 10;
77
public static Integer DEPLOY_PROTECTED_PATHS = 12; // depends on roles
88
public static Integer DEPLOY_QUERY_ROLESETS = 13; // depends on roles
9-
public static Integer DEPLOY_USERS = 15; // depends on roles
9+
public static Integer DEPLOY_USERS = 15; // depends on roles
1010

1111
// After users are deployed so they're not included in combined CMA requests
1212
public static Integer DEPLOY_PRIVILEGE_ROLES = 18;
@@ -16,38 +16,40 @@ public abstract class SortOrderConstants {
1616
public static Integer GENERATE_TEMPORARY_CERTIFICATE = 25;
1717
public static Integer INSERT_HOST_CERTIFICATES = 28;
1818

19-
public static Integer DEPLOY_EXTERNAL_SECURITY = 35;
20-
public static Integer DEPLOY_PROTECTED_COLLECTIONS = 40;
21-
public static Integer DEPLOY_MIMETYPES = 45;
19+
public static Integer DEPLOY_EXTERNAL_SECURITY = 35;
20+
public static Integer DEPLOY_PROTECTED_COLLECTIONS = 40;
21+
public static Integer DEPLOY_MIMETYPES = 45;
2222

2323
public static Integer DEPLOY_GROUPS = 90;
2424

2525
// Hosts need to be assigned to their group before databases are created.
2626
// This is so that when forests are created based on the mlDatabaseGroups
2727
// then the forests will be created on the correct hosts.
28-
public static Integer ASSIGN_HOSTS_TO_GROUPS = 95;
28+
public static Integer ASSIGN_HOSTS_TO_GROUPS = 95;
2929

30-
@Deprecated
30+
@Deprecated
3131
public static Integer DEPLOY_TRIGGERS_DATABASE = 100;
32-
@Deprecated
32+
@Deprecated
3333
public static Integer DEPLOY_SCHEMAS_DATABASE = 100;
3434

3535
public static Integer DEPLOY_OTHER_DATABASES = 120;
36-
public static Integer DEPLOY_FORESTS = 150;
36+
public static Integer DEPLOY_FORESTS = 150;
37+
public static Integer DEPLOY_PARTITIONS = 170;
38+
public static Integer DEPLOY_PARTITION_QUERIES = 175;
3739

3840
public static Integer DEPLOY_REST_API_SERVERS = 200;
39-
public static Integer UPDATE_REST_API_SERVERS = 250;
40-
public static Integer DEPLOY_OTHER_SERVERS = 300;
41+
public static Integer UPDATE_REST_API_SERVERS = 250;
42+
public static Integer DEPLOY_OTHER_SERVERS = 300;
4143

42-
public static Integer MODIFY_LOCAL_CLUSTER = 350;
44+
public static Integer MODIFY_LOCAL_CLUSTER = 350;
4345

44-
// Module code may depend on schemas, but not vice-versa.
45-
public static Integer LOAD_SCHEMAS = 350;
46+
// Module code may depend on schemas, but not vice-versa.
47+
public static Integer LOAD_SCHEMAS = 350;
4648

47-
// Modules have to be loaded after the REST API server has been updated, for if the deployer is expecting to load
48-
// modules via SSL, then the REST API server must already be configured with a certificate template
49-
public static Integer LOAD_MODULES = 400;
50-
public static Integer DELETE_TEST_MODULES = 410;
49+
// Modules have to be loaded after the REST API server has been updated, for if the deployer is expecting to load
50+
// modules via SSL, then the REST API server must already be configured with a certificate template
51+
public static Integer LOAD_MODULES = 400;
52+
public static Integer DELETE_TEST_MODULES = 410;
5153

5254
// The modules database must exist before we deploy amps
5355
public static Integer DEPLOY_AMPS = 450;
@@ -58,63 +60,63 @@ public abstract class SortOrderConstants {
5860
public static Integer DEPLOY_TEMPORAL_COLLECTIONS = 751;
5961
public static Integer DEPLOY_TEMPORAL_COLLECTIONS_LSQT = 752;
6062

61-
public static Integer DEPLOY_SCHEDULED_TASKS = 800;
62-
public static Integer UPDATE_TASK_SERVER = 810;
63+
public static Integer DEPLOY_SCHEDULED_TASKS = 800;
64+
public static Integer UPDATE_TASK_SERVER = 810;
6365

64-
public static Integer DEPLOY_DEFAULT_PIPELINES = 900;
65-
public static Integer DEPLOY_PIPELINES = 905;
66-
public static Integer DEPLOY_DOMAINS = 910;
67-
public static Integer DEPLOY_CPF_CONFIGS = 920;
66+
public static Integer DEPLOY_DEFAULT_PIPELINES = 900;
67+
public static Integer DEPLOY_PIPELINES = 905;
68+
public static Integer DEPLOY_DOMAINS = 910;
69+
public static Integer DEPLOY_CPF_CONFIGS = 920;
6870

69-
public static Integer DEPLOY_ALERT_CONFIGS = 950;
70-
public static Integer DEPLOY_ALERT_ACTIONS = 960;
71-
public static Integer DEPLOY_ALERT_RULES = 970;
71+
public static Integer DEPLOY_ALERT_CONFIGS = 950;
72+
public static Integer DEPLOY_ALERT_ACTIONS = 960;
73+
public static Integer DEPLOY_ALERT_RULES = 970;
7274

73-
public static Integer DEPLOY_FLEXREP_CONFIGS = 1000;
74-
public static Integer DEPLOY_FLEXREP_TARGETS = 1010;
75+
public static Integer DEPLOY_FLEXREP_CONFIGS = 1000;
76+
public static Integer DEPLOY_FLEXREP_TARGETS = 1010;
7577
public static Integer DEPLOY_FLEXREP_PULLS = 1020;
7678

77-
public static Integer DEPLOY_SQL_VIEWS = 1100;
79+
public static Integer DEPLOY_SQL_VIEWS = 1100;
7880

79-
public static Integer DEPLOY_FOREST_REPLICAS = 1200;
81+
public static Integer DEPLOY_FOREST_REPLICAS = 1200;
8082

81-
public static Integer LOAD_DATA = 1300;
83+
public static Integer LOAD_DATA = 1300;
8284

83-
public static Integer INSTALL_PLUGINS = 1400;
85+
public static Integer INSTALL_PLUGINS = 1400;
8486

8587
public static Integer DELETE_MIMETYPES = 8500;
8688

8789
public static Integer UNASSIGN_HOSTS_FROM_GROUPS = 8590;
8890
public static Integer DELETE_GROUPS = 8600;
8991

90-
public static Integer DELETE_USERS = 9000;
91-
public static Integer DELETE_CERTIFICATE_TEMPLATES = 9010;
92-
public static Integer DELETE_EXTERNAL_SECURITY = 9030;
93-
public static Integer DELETE_PROTECTED_COLLECTIONS = 9040;
92+
public static Integer DELETE_USERS = 9000;
93+
public static Integer DELETE_CERTIFICATE_TEMPLATES = 9010;
94+
public static Integer DELETE_EXTERNAL_SECURITY = 9030;
95+
public static Integer DELETE_PROTECTED_COLLECTIONS = 9040;
9496
public static Integer DELETE_QUERY_ROLESETS = 9050;
9597

96-
// Roles can reference privileges, so must delete roles first
97-
public static Integer DELETE_ROLES = 9060;
98-
public static Integer DELETE_PRIVILEGES = 9070;
99-
// Protected paths reference roles
98+
// Roles can reference privileges, so must delete roles first
99+
public static Integer DELETE_ROLES = 9060;
100+
public static Integer DELETE_PRIVILEGES = 9070;
101+
// Protected paths reference roles
100102
public static Integer DELETE_PROTECTED_PATHS = 9080;
101103

102104

103105
/*
104-
* This executes before databases are deleted, as deleting databases normally deletes the primary forests, so we
105-
* need to make sure the replicas are deleted first.
106-
*/
107-
public static Integer DELETE_FOREST_REPLICAS = 8000;
106+
* This executes before databases are deleted, as deleting databases normally deletes the primary forests, so we
107+
* need to make sure the replicas are deleted first.
108+
*/
109+
public static Integer DELETE_FOREST_REPLICAS = 8000;
108110

109-
public static Integer DELETE_CONTENT_DATABASES = 8100;
110-
public static Integer DELETE_OTHER_DATABASES = 8120;
111+
public static Integer DELETE_CONTENT_DATABASES = 8100;
112+
public static Integer DELETE_OTHER_DATABASES = 8120;
111113

112-
@Deprecated
113-
public static Integer DELETE_TRIGGERS_DATABASE = 8140;
114-
@Deprecated
115-
public static Integer DELETE_SCHEMAS_DATABASE = 8160;
114+
@Deprecated
115+
public static Integer DELETE_TRIGGERS_DATABASE = 8140;
116+
@Deprecated
117+
public static Integer DELETE_SCHEMAS_DATABASE = 8160;
116118

117-
public static Integer DELETE_REST_API_SERVERS = 7000;
119+
public static Integer DELETE_REST_API_SERVERS = 7000;
118120

119121
// Amps can reference roles and databases, so must delete amps before both (and before deleting REST API servers
120122
// too, which may delete databases)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.marklogic.appdeployer.command.rebalancer;
2+
3+
import com.marklogic.appdeployer.AppConfig;
4+
import com.marklogic.appdeployer.ConfigDir;
5+
import com.marklogic.appdeployer.command.AbstractResourceCommand;
6+
import com.marklogic.appdeployer.command.CommandContext;
7+
import com.marklogic.appdeployer.command.SortOrderConstants;
8+
import com.marklogic.mgmt.resource.ResourceManager;
9+
import com.marklogic.mgmt.resource.rebalancer.PartitionQueryManager;
10+
11+
import java.io.File;
12+
13+
public class DeployPartitionQueriesCommand extends AbstractResourceCommand {
14+
15+
private PartitionQueryManager currentPartitionQueryManager;
16+
17+
public DeployPartitionQueriesCommand() {
18+
setExecuteSortOrder(SortOrderConstants.DEPLOY_PARTITION_QUERIES);
19+
20+
// Partition queries are expected to be deleted when the parent database is deleted
21+
setDeleteResourcesOnUndo(false);
22+
}
23+
24+
@Override
25+
public void execute(CommandContext context) {
26+
AppConfig appConfig = context.getAppConfig();
27+
for (ConfigDir configDir : appConfig.getConfigDirs()) {
28+
for (File dir : configDir.getDatabaseResourceDirectories()) {
29+
String databaseName = determineDatabaseNameForDatabaseResourceDirectory(context, configDir, dir);
30+
deployPartitionQueries(context, new ConfigDir(dir), databaseName);
31+
}
32+
}
33+
}
34+
35+
protected void deployPartitionQueries(CommandContext context, ConfigDir configDir, String databaseIdOrName) {
36+
currentPartitionQueryManager = new PartitionQueryManager(context.getManageClient(), databaseIdOrName);
37+
processExecuteOnResourceDir(context, configDir.getPartitionQueriesDir());
38+
}
39+
40+
@Override
41+
protected ResourceManager getResourceManager(CommandContext context) {
42+
return currentPartitionQueryManager;
43+
}
44+
45+
@Override
46+
protected File[] getResourceDirs(CommandContext context) {
47+
return findResourceDirs(context, configDir -> configDir.getPartitionQueriesDir());
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.marklogic.appdeployer.command.rebalancer;
2+
3+
import com.marklogic.appdeployer.AppConfig;
4+
import com.marklogic.appdeployer.ConfigDir;
5+
import com.marklogic.appdeployer.command.AbstractResourceCommand;
6+
import com.marklogic.appdeployer.command.CommandContext;
7+
import com.marklogic.appdeployer.command.SortOrderConstants;
8+
import com.marklogic.mgmt.resource.ResourceManager;
9+
import com.marklogic.mgmt.resource.rebalancer.PartitionManager;
10+
11+
import java.io.File;
12+
13+
public class DeployPartitionsCommand extends AbstractResourceCommand {
14+
15+
private PartitionManager currentPartitionManager;
16+
17+
public DeployPartitionsCommand() {
18+
setExecuteSortOrder(SortOrderConstants.DEPLOY_PARTITIONS);
19+
20+
// Partitions are expected to be deleted when the parent database is deleted
21+
setDeleteResourcesOnUndo(false);
22+
}
23+
24+
@Override
25+
public void execute(CommandContext context) {
26+
AppConfig appConfig = context.getAppConfig();
27+
for (ConfigDir configDir : appConfig.getConfigDirs()) {
28+
for (File dir : configDir.getDatabaseResourceDirectories()) {
29+
String databaseName = determineDatabaseNameForDatabaseResourceDirectory(context, configDir, dir);
30+
deployPartitions(context, new ConfigDir(dir), databaseName);
31+
}
32+
}
33+
}
34+
35+
protected void deployPartitions(CommandContext context, ConfigDir configDir, String databaseIdOrName) {
36+
currentPartitionManager = new PartitionManager(context.getManageClient(), databaseIdOrName);
37+
processExecuteOnResourceDir(context, configDir.getPartitionsDir());
38+
}
39+
40+
@Override
41+
protected ResourceManager getResourceManager(CommandContext context) {
42+
return currentPartitionManager;
43+
}
44+
45+
@Override
46+
protected File[] getResourceDirs(CommandContext context) {
47+
return findResourceDirs(context, configDir -> configDir.getPartitionsDir());
48+
}
49+
}

src/main/java/com/marklogic/mgmt/ManageClient.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,20 @@ public Fragment getXmlAsSecurityUser(String path, String... namespacePrefixesAnd
263263
}
264264

265265
public String getJson(String path) {
266-
logRequest(path, "JSON", "GET");
267-
HttpHeaders headers = new HttpHeaders();
268-
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
269-
return getRestTemplate().exchange(buildUri(path), HttpMethod.GET, new HttpEntity<>(headers), String.class)
270-
.getBody();
266+
return getJson(path, String.class).getBody();
271267
}
272268

269+
public JsonNode getJsonNode(String path) {
270+
return getJson(path, JsonNode.class).getBody();
271+
}
272+
273+
protected <T> ResponseEntity<T> getJson(String path, Class<T> responseType) {
274+
logRequest(path, "JSON", "GET");
275+
HttpHeaders headers = new HttpHeaders();
276+
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
277+
return getRestTemplate().exchange(buildUri(path), HttpMethod.GET, new HttpEntity<>(headers), responseType);
278+
}
279+
273280
public String getJson(URI uri) {
274281
logRequest(uri.toString(), "JSON", "GET");
275282
HttpHeaders headers = new HttpHeaders();

src/main/java/com/marklogic/mgmt/api/database/AssignmentPolicy.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@ public class AssignmentPolicy {
1010
@XmlElement(name = "assignment-policy-name")
1111
private String assignmentPolicyName;
1212

13+
@XmlElement(name = "lower-bound-included")
14+
private Boolean lowerBoundIncluded;
15+
16+
@XmlElement(name = "default-partition")
17+
private Integer defaultPartition;
18+
1319
public String getAssignmentPolicyName() {
1420
return assignmentPolicyName;
1521
}
1622

1723
public void setAssignmentPolicyName(String assignmentPolicyName) {
1824
this.assignmentPolicyName = assignmentPolicyName;
1925
}
26+
27+
public Boolean getLowerBoundIncluded() {
28+
return lowerBoundIncluded;
29+
}
30+
31+
public void setLowerBoundIncluded(Boolean lowerBoundIncluded) {
32+
this.lowerBoundIncluded = lowerBoundIncluded;
33+
}
34+
35+
public Integer getDefaultPartition() {
36+
return defaultPartition;
37+
}
38+
39+
public void setDefaultPartition(Integer defaultPartition) {
40+
this.defaultPartition = defaultPartition;
41+
}
2042
}

0 commit comments

Comments
 (0)