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

Commit 232b2a7

Browse files
committed
#171 Now able to deploy resources to any database
#171 Added test for deploying temporal to multiple databases
1 parent 3c8e873 commit 232b2a7

File tree

44 files changed

+863
-443
lines changed

Some content is hidden

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

44 files changed

+863
-443
lines changed
Lines changed: 119 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,162 @@
11
package com.marklogic.appdeployer;
22

33
import java.io.File;
4+
import java.io.FileFilter;
45
import java.util.ArrayList;
6+
import java.util.Arrays;
57
import java.util.List;
68

79
/**
810
* Defines all of the directories where configuration files can be found. This is decoupled from the NounManager
911
* classes, who don't need to care where to look for configuration files, they just need to care about how to load the
1012
* data in those files.
11-
*
12-
* Every directory path referenced in this should have a setter so that it can be modified in e.g. a Gradle build file.
1313
*/
1414
public class ConfigDir {
1515

16-
private File baseDir;
16+
private File baseDir;
1717

18-
private String databasesPath = "databases";
19-
private String defaultContentDatabaseFilename = "content-database.json";
18+
private String databasesPath = "databases";
19+
private String defaultContentDatabaseFilename = "content-database.json";
2020

21-
private String restApiPath = "rest-api.json";
21+
private String restApiPath = "rest-api.json";
2222

23-
private List<File> contentDatabaseFiles;
23+
private List<File> contentDatabaseFiles;
2424

25-
public ConfigDir() {
26-
this(new File("src/main/ml-config"));
27-
}
25+
public ConfigDir() {
26+
this(new File("src/main/ml-config"));
27+
}
28+
29+
public ConfigDir(File baseDir) {
30+
setBaseDir(baseDir);
31+
}
32+
33+
public void setBaseDir(File baseDir) {
34+
this.baseDir = baseDir;
35+
initializeContentDatabaseFiles();
36+
}
37+
38+
public File getDatabasesDir() {
39+
return new File(baseDir, databasesPath);
40+
}
41+
42+
/**
43+
* Return a list of every directory under the databases directory. Each such directory is considered to contain
44+
* resources for the database with a name matching that of the directory.
45+
*
46+
* @return
47+
*/
48+
public List<File> getDatabaseResourceDirectories() {
49+
File dbDir = getDatabasesDir();
50+
if (dbDir != null && dbDir.exists()) {
51+
File[] dirs = dbDir.listFiles(new FileFilter() {
52+
@Override
53+
public boolean accept(File pathname) {
54+
return pathname.isDirectory();
55+
}
56+
});
57+
return Arrays.asList(dirs);
58+
}
59+
return new ArrayList<File>();
60+
}
2861

29-
public ConfigDir(File baseDir) {
30-
setBaseDir(baseDir);
31-
}
62+
protected void initializeContentDatabaseFiles() {
63+
contentDatabaseFiles = new ArrayList<>();
64+
contentDatabaseFiles.add(new File(getDatabasesDir(), defaultContentDatabaseFilename));
65+
}
3266

33-
public void setBaseDir(File baseDir) {
34-
this.baseDir = baseDir;
35-
initializeContentDatabaseFiles();
36-
}
67+
public File getRestApiFile() {
68+
return new File(baseDir, restApiPath);
69+
}
3770

38-
public File getDatabasesDir() {
39-
return new File(baseDir, databasesPath);
40-
}
71+
public File getRestApiServerFile() {
72+
return new File(getServersDir(), "rest-api-server.json");
73+
}
74+
75+
public File getSecurityDir() {
76+
return new File(baseDir, "security");
77+
}
78+
79+
public File getServersDir() {
80+
return new File(baseDir, "servers");
81+
}
82+
83+
public File getForestsDir() {
84+
return new File(baseDir, "forests");
85+
}
4186

42-
protected void initializeContentDatabaseFiles() {
43-
contentDatabaseFiles = new ArrayList<>();
44-
contentDatabaseFiles.add(new File(getDatabasesDir(), defaultContentDatabaseFilename));
45-
}
87+
public File getCpfDir() {
88+
return new File(baseDir, "cpf");
89+
}
4690

47-
public File getRestApiFile() {
48-
return new File(baseDir, restApiPath);
49-
}
91+
public File getClustersDir() {
92+
return new File(baseDir, "clusters");
93+
}
5094

51-
public File getRestApiServerFile() {
52-
return new File(getServersDir(), "rest-api-server.json");
53-
}
95+
public File getAlertDir() {
96+
return new File(baseDir, "alert");
97+
}
5498

55-
public File getSecurityDir() {
56-
return new File(baseDir, "security");
57-
}
99+
public File getAlertConfigsDir() {
100+
return new File(getAlertDir(), "configs");
101+
}
58102

59-
public File getServersDir() { return new File(baseDir, "servers"); }
103+
public File getFlexrepDir() {
104+
return new File(baseDir, "flexrep");
105+
}
60106

61-
public File getForestsDir() {
62-
return new File(baseDir, "forests");
63-
}
107+
public File getFlexrepConfigsDir() {
108+
return new File(getFlexrepDir(), "configs");
109+
}
64110

65-
public File getCpfDir() {
66-
return new File(baseDir, "cpf");
67-
}
111+
public File getViewSchemasDir() {
112+
return new File(baseDir, "view-schemas");
113+
}
68114

69-
public File getClustersDir() {
70-
return new File(baseDir, "clusters");
71-
}
115+
public File getTemporalDir() {
116+
return new File(baseDir, "temporal");
117+
}
72118

73-
public File getAlertDir() {
74-
return new File(baseDir, "alert");
75-
}
119+
public File getTemporalAxesDir() {
120+
return new File(getTemporalDir(), "axes");
121+
}
76122

77-
public File getFlexrepDir() {
78-
return new File(baseDir, "flexrep");
79-
}
123+
public File getTemporalCollectionsDir() {
124+
return new File(getTemporalDir(), "collections");
125+
}
80126

81-
public File getTemporalDir() { return new File(baseDir, "temporal"); }
127+
public File getTemporalCollectionsLsqtDir() {
128+
return new File(getTemporalCollectionsDir(), "lqst");
129+
}
82130

83131
public File getTasksDir() {
84-
return new File(baseDir, "tasks");
132+
return new File(baseDir, "tasks");
85133
}
86134

87135
public void setDatabasesPath(String databasesPath) {
88-
this.databasesPath = databasesPath;
89-
}
136+
this.databasesPath = databasesPath;
137+
}
90138

91-
public void setRestApiPath(String restApiPath) {
92-
this.restApiPath = restApiPath;
93-
}
139+
public void setRestApiPath(String restApiPath) {
140+
this.restApiPath = restApiPath;
141+
}
94142

95-
public File getBaseDir() {
96-
return baseDir;
97-
}
143+
public File getBaseDir() {
144+
return baseDir;
145+
}
98146

99-
public List<File> getContentDatabaseFiles() {
100-
return contentDatabaseFiles;
101-
}
147+
public List<File> getContentDatabaseFiles() {
148+
return contentDatabaseFiles;
149+
}
102150

103-
public void setContentDatabaseFiles(List<File> contentDatabaseFiles) {
104-
this.contentDatabaseFiles = contentDatabaseFiles;
105-
}
151+
public void setContentDatabaseFiles(List<File> contentDatabaseFiles) {
152+
this.contentDatabaseFiles = contentDatabaseFiles;
153+
}
106154

107-
public String getDefaultContentDatabaseFilename() {
108-
return defaultContentDatabaseFilename;
109-
}
155+
public String getDefaultContentDatabaseFilename() {
156+
return defaultContentDatabaseFilename;
157+
}
110158

111-
public void setDefaultContentDatabaseFilename(String contentDatabaseFilename) {
112-
this.defaultContentDatabaseFilename = contentDatabaseFilename;
113-
}
159+
public void setDefaultContentDatabaseFilename(String contentDatabaseFilename) {
160+
this.defaultContentDatabaseFilename = contentDatabaseFilename;
161+
}
114162
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.marklogic.mgmt.SaveReceipt;
77
import com.marklogic.mgmt.admin.ActionRequiringRestart;
88
import com.marklogic.mgmt.admin.AdminManager;
9+
import org.springframework.http.HttpHeaders;
910
import org.springframework.http.ResponseEntity;
1011

1112
import java.io.File;
@@ -62,13 +63,18 @@ protected void processExecuteOnResourceDir(CommandContext context, File resource
6263
protected void afterResourceSaved(ResourceManager mgr, CommandContext context, File resourceFile,
6364
SaveReceipt receipt) {
6465
ResponseEntity<String> response = receipt.getResponse();
65-
URI uri = response.getHeaders().getLocation();
66-
if (uri != null && "/admin/v1/timestamp".equals(uri.getPath())) {
67-
AdminManager adminManager = context.getAdminManager();
68-
if (adminManager != null) {
69-
adminManager.waitForRestart();
70-
} else {
71-
logger.warn("Location header indicates ML is restarting, but no AdminManager available to support waiting for a restart");
66+
if (response != null) {
67+
HttpHeaders headers = response.getHeaders();
68+
if (headers != null) {
69+
URI uri = headers.getLocation();
70+
if (uri != null && "/admin/v1/timestamp".equals(uri.getPath())) {
71+
AdminManager adminManager = context.getAdminManager();
72+
if (adminManager != null) {
73+
adminManager.waitForRestart();
74+
} else {
75+
logger.warn("Location header indicates ML is restarting, but no AdminManager available to support waiting for a restart");
76+
}
77+
}
7278
}
7379
}
7480
}

src/main/java/com/marklogic/appdeployer/command/alert/DeployAlertActionsCommand.java

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
import java.io.File;
44

5+
import com.marklogic.appdeployer.AppConfig;
6+
import com.marklogic.appdeployer.ConfigDir;
57
import com.marklogic.appdeployer.command.AbstractCommand;
68
import com.marklogic.appdeployer.command.CommandContext;
79
import com.marklogic.appdeployer.command.SortOrderConstants;
810
import com.marklogic.mgmt.alert.AlertActionManager;
11+
import com.marklogic.mgmt.alert.AlertConfigManager;
912

1013
/**
1114
* This is similar to how DeployTargetsCommand works for Flexrep. Since action belong to a certain alert config, this
@@ -20,50 +23,53 @@
2023
*/
2124
public class DeployAlertActionsCommand extends AbstractCommand {
2225

23-
private String databaseIdOrName;
24-
private String actionsDirectorySuffix = "-actions";
26+
private String actionsDirectorySuffix = "-actions";
2527

26-
public DeployAlertActionsCommand() {
27-
setExecuteSortOrder(SortOrderConstants.DEPLOY_ALERT_ACTIONS);
28-
}
28+
public DeployAlertActionsCommand() {
29+
setExecuteSortOrder(SortOrderConstants.DEPLOY_ALERT_ACTIONS);
30+
}
2931

30-
@Override
31-
public void execute(CommandContext context) {
32-
File configDir = new File(context.getAppConfig().getConfigDir().getAlertDir(), "configs");
33-
if (configDir != null && configDir.exists()) {
34-
for (File f : configDir.listFiles()) {
35-
if (f.isDirectory() && f.getName().endsWith(actionsDirectorySuffix)) {
36-
deployActionsInDirectory(f, context);
37-
}
38-
}
39-
}
40-
}
32+
@Override
33+
public void execute(CommandContext context) {
34+
AppConfig appConfig = context.getAppConfig();
35+
deployActions(context, appConfig.getConfigDir(), appConfig.getContentDatabaseName());
4136

42-
protected void deployActionsInDirectory(File dir, CommandContext context) {
43-
String dbName = databaseIdOrName != null ? databaseIdOrName : context.getAppConfig().getContentDatabaseName();
44-
String configUri = extractConfigUriFromDirectory(dir);
37+
for (File dir : appConfig.getConfigDir().getDatabaseResourceDirectories()) {
38+
deployActions(context, new ConfigDir(dir), dir.getName());
39+
}
40+
}
4541

46-
if (logger.isInfoEnabled()) {
47-
logger.info(format("Deploying alert actions with config URI '%s' in directory: %s", configUri,
48-
dir.getAbsolutePath()));
49-
}
42+
protected void deployActions(CommandContext context, ConfigDir configDir, String databaseIdOrName) {
43+
File configsDir = configDir.getAlertConfigsDir();
44+
if (configsDir != null && configsDir.exists()) {
45+
for (File f : configsDir.listFiles()) {
46+
if (f.isDirectory() && f.getName().endsWith(actionsDirectorySuffix)) {
47+
deployActionsInDirectory(f, context, databaseIdOrName);
48+
}
49+
}
50+
}
51+
}
5052

51-
AlertActionManager mgr = new AlertActionManager(context.getManageClient(), dbName, configUri);
52-
for (File f : listFilesInDirectory(dir)) {
53-
saveResource(mgr, context, f);
54-
}
55-
}
53+
protected void deployActionsInDirectory(File dir, CommandContext context, String databaseIdOrName) {
54+
String configUri = extractConfigUriFromDirectory(dir);
5655

57-
protected String extractConfigUriFromDirectory(File dir) {
58-
String name = dir.getName();
59-
return name.substring(0, name.length() - actionsDirectorySuffix.length());
60-
}
56+
if (logger.isInfoEnabled()) {
57+
logger.info(format("Deploying alert actions with config URI '%s' in directory: %s", configUri,
58+
dir.getAbsolutePath()));
59+
}
6160

62-
public void setDatabaseIdOrName(String databaseIdOrName) {
63-
this.databaseIdOrName = databaseIdOrName;
64-
}
61+
AlertActionManager mgr = new AlertActionManager(context.getManageClient(), databaseIdOrName, configUri);
62+
for (File f : listFilesInDirectory(dir)) {
63+
saveResource(mgr, context, f);
64+
}
65+
}
6566

66-
public void setActionsDirectorySuffix(String targetDirectorySuffix) {
67-
this.actionsDirectorySuffix = targetDirectorySuffix;
68-
}
67+
protected String extractConfigUriFromDirectory(File dir) {
68+
String name = dir.getName();
69+
return name.substring(0, name.length() - actionsDirectorySuffix.length());
70+
}
71+
72+
public void setActionsDirectorySuffix(String targetDirectorySuffix) {
73+
this.actionsDirectorySuffix = targetDirectorySuffix;
74+
}
6975
}

0 commit comments

Comments
 (0)