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

Commit 6211347

Browse files
authored
Merge pull request #144 from derms/feature/issue-28-add-temporal-config
Feature/issue 28 add temporal config
2 parents 595cd0d + 6bc3785 commit 6211347

26 files changed

+474
-9
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Defines all of the directories where configuration files can be found. This is decoupled from the NounManager
99
* classes, who don't need to care where to look for configuration files, they just need to care about how to load the
1010
* data in those files.
11-
*
11+
*
1212
* 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 {
@@ -67,12 +67,14 @@ public File getClustersDir() {
6767
public File getAlertDir() {
6868
return new File(baseDir, "alert");
6969
}
70-
70+
7171
public File getFlexrepDir() {
7272
return new File(baseDir, "flexrep");
7373
}
7474

75-
public void setDatabasesPath(String databasesPath) {
75+
public File getTemporalDir() { return new File(baseDir, "temporal"); }
76+
77+
public void setDatabasesPath(String databasesPath) {
7678
this.databasesPath = databasesPath;
7779
}
7880

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import com.marklogic.appdeployer.command.schemas.LoadSchemasCommand;
2626
import com.marklogic.appdeployer.command.security.*;
2727
import com.marklogic.appdeployer.command.tasks.DeployScheduledTasksCommand;
28+
import com.marklogic.appdeployer.command.temporal.DeployTemporalAxesCommand;
29+
import com.marklogic.appdeployer.command.temporal.DeployTemporalCollectionsCommand;
30+
import com.marklogic.appdeployer.command.temporal.DeployTemporalCollectionsLSQTCommand;
2831
import com.marklogic.appdeployer.command.triggers.DeployTriggersCommand;
2932
import com.marklogic.appdeployer.command.viewschemas.DeployViewSchemasCommand;
3033

@@ -137,11 +140,19 @@ public Map<String, List<Command>> buildCommandMap() {
137140
taskCommands.add(new DeployScheduledTasksCommand());
138141
map.put("mlTaskCommands", taskCommands);
139142

143+
// Temporal
144+
List<Command> temporalCommands = new ArrayList<>();
145+
temporalCommands.add(new DeployTemporalAxesCommand());
146+
temporalCommands.add(new DeployTemporalCollectionsCommand());
147+
temporalCommands.add(new DeployTemporalCollectionsLSQTCommand());
148+
map.put("mlTemporalCommands", temporalCommands);
149+
140150
// Triggers
141151
List<Command> triggerCommands = new ArrayList<Command>();
142152
triggerCommands.add(new DeployTriggersCommand());
143153
map.put("mlTriggerCommands", triggerCommands);
144154

155+
145156
// SQL Views
146157
List<Command> viewCommands = new ArrayList<Command>();
147158
viewCommands.add(new DeployViewSchemasCommand());

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public abstract class SortOrderConstants {
1313
public static Integer DEPLOY_EXTERNAL_SECURITY = 70;
1414
public static Integer DEPLOY_PROTECTED_COLLECTIONS = 80;
1515
public static Integer DEPLOY_MIMETYPES = 90;
16-
16+
1717
public static Integer DEPLOY_TRIGGERS_DATABASE = 100;
1818
public static Integer DEPLOY_SCHEMAS_DATABASE = 100;
1919
public static Integer DEPLOY_CONTENT_DATABASES = 120;
@@ -37,7 +37,11 @@ public abstract class SortOrderConstants {
3737
public static Integer DEPLOY_AMPS = 450;
3838

3939
public static Integer DEPLOY_TRIGGERS = 700;
40-
40+
41+
public static Integer DEPLOY_TEMPORAL_AXIS = 750;
42+
public static Integer DEPLOY_TEMPORAL_COLLECTIONS = 751;
43+
public static Integer DEPLOY_TEMPORAL_COLLECTIONS_LSQT = 752;
44+
4145
public static Integer DEPLOY_SCHEDULED_TASKS = 800;
4246

4347
public static Integer DEPLOY_DEFAULT_PIPELINES = 900;
@@ -51,16 +55,16 @@ public abstract class SortOrderConstants {
5155

5256
public static Integer DEPLOY_FLEXREP_CONFIGS = 1000;
5357
public static Integer DEPLOY_FLEXREP_TARGETS = 1010;
54-
58+
5559
public static Integer DEPLOY_SQL_VIEWS = 1100;
5660

5761
public static Integer DEPLOY_FOREST_REPLICAS = 1200;
58-
62+
5963
// Undo constants
6064
public static Integer DELETE_GROUPS = 10000;
6165

6266
public static Integer DELETE_MIMETYPES = 9500;
63-
67+
6468
public static Integer DELETE_USERS = 9000;
6569
public static Integer DELETE_CERTIFICATE_TEMPLATES = 9010;
6670
public static Integer DELETE_CERTIFICATE_AUTHORITIES = 9020;
@@ -76,7 +80,7 @@ public abstract class SortOrderConstants {
7680
* need to make sure the replicas are deleted first.
7781
*/
7882
public static Integer DELETE_FOREST_REPLICAS = 8000;
79-
83+
8084
public static Integer DELETE_CONTENT_DATABASES = 8100;
8185
public static Integer DELETE_OTHER_DATABASES = 8120;
8286
public static Integer DELETE_TRIGGERS_DATABASE = 8140;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.marklogic.appdeployer.command.temporal;
2+
3+
import com.marklogic.appdeployer.command.AbstractResourceCommand;
4+
import com.marklogic.appdeployer.command.CommandContext;
5+
import com.marklogic.appdeployer.command.SortOrderConstants;
6+
import com.marklogic.mgmt.ResourceManager;
7+
import com.marklogic.mgmt.temporal.TemporalAxesManager;
8+
9+
import java.io.File;
10+
11+
public class DeployTemporalAxesCommand extends AbstractResourceCommand {
12+
13+
private String databaseIdOrName;
14+
15+
public DeployTemporalAxesCommand() {
16+
// TODO - verify that range element indexes exist before creation of temporal axes?
17+
setExecuteSortOrder(SortOrderConstants.DEPLOY_TEMPORAL_AXIS);
18+
//can't delete temporal axes until able to delete temporal collections...
19+
setDeleteResourcesOnUndo(false);
20+
}
21+
22+
@Override
23+
protected File[] getResourceDirs(CommandContext context) {
24+
return new File[] { new File(context.getAppConfig().getConfigDir().getTemporalDir(),"axes") };
25+
}
26+
27+
@Override
28+
protected ResourceManager getResourceManager(CommandContext context) {
29+
String db = databaseIdOrName != null ? databaseIdOrName : context.getAppConfig().getContentDatabaseName();
30+
return new TemporalAxesManager(context.getManageClient(), db);
31+
}
32+
33+
public void setDatabaseIdOrName(String databaseIdOrName) {
34+
this.databaseIdOrName = databaseIdOrName;
35+
}
36+
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.marklogic.appdeployer.command.temporal;
2+
3+
import com.marklogic.appdeployer.command.AbstractResourceCommand;
4+
import com.marklogic.appdeployer.command.CommandContext;
5+
import com.marklogic.appdeployer.command.SortOrderConstants;
6+
import com.marklogic.mgmt.ResourceManager;
7+
import com.marklogic.mgmt.temporal.TemporalCollectionManager;
8+
9+
import java.io.File;
10+
11+
public class DeployTemporalCollectionsCommand extends AbstractResourceCommand {
12+
13+
private String databaseIdOrName;
14+
15+
public DeployTemporalCollectionsCommand() {
16+
setExecuteSortOrder(SortOrderConstants.DEPLOY_TEMPORAL_COLLECTIONS);
17+
// if the temporal collection contains documents, then the delete operation will fail
18+
// TODO - could add check to get count of documents in temporal collection. If zero docs, then can delete
19+
setDeleteResourcesOnUndo(false);
20+
}
21+
22+
@Override
23+
protected File[] getResourceDirs(CommandContext context) {
24+
return new File[] { new File(context.getAppConfig().getConfigDir().getTemporalDir(),"collections") };
25+
}
26+
27+
@Override
28+
protected ResourceManager getResourceManager(CommandContext context) {
29+
String db = databaseIdOrName != null ? databaseIdOrName : context.getAppConfig().getContentDatabaseName();
30+
return new TemporalCollectionManager(context.getManageClient(), db);
31+
}
32+
33+
public void setDatabaseIdOrName(String databaseIdOrName) {
34+
this.databaseIdOrName = databaseIdOrName;
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.marklogic.appdeployer.command.temporal;
2+
3+
import com.marklogic.appdeployer.command.*;
4+
import com.marklogic.mgmt.temporal.TemporalCollectionLSQTManager;
5+
6+
import java.io.File;
7+
8+
/**
9+
* Created by dsmyth on 28/02/2017.
10+
*/
11+
public class DeployTemporalCollectionsLSQTCommand extends AbstractCommand {
12+
13+
private String databaseIdOrName;
14+
15+
public DeployTemporalCollectionsLSQTCommand() {
16+
setExecuteSortOrder(SortOrderConstants.DEPLOY_TEMPORAL_COLLECTIONS_LSQT);
17+
}
18+
19+
public void setDatabaseIdOrName(String databaseIdOrName) {
20+
this.databaseIdOrName = databaseIdOrName;
21+
}
22+
23+
@Override
24+
public void execute(CommandContext context) {
25+
File configDir = new File(new File(context.getAppConfig().getConfigDir().getTemporalDir(), "collections"), "lsqt");
26+
String db = databaseIdOrName != null ? databaseIdOrName : context.getAppConfig().getContentDatabaseName();
27+
if (configDir != null && configDir.exists()) {
28+
for (File f : configDir.listFiles(new ResourceFilenameFilter())) {
29+
String name = f.getName();
30+
// use filename without suffix as temporal collection
31+
String temporalCollectionName = name.replaceAll(".xml|.json","");
32+
String payload = copyFileToString(f, context);
33+
logger.info(format("Extracted temporal collection name '%s' from filename '%s'", temporalCollectionName, name));
34+
new TemporalCollectionLSQTManager(context.getManageClient(),db, temporalCollectionName).save(payload);
35+
}
36+
}
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.marklogic.mgmt.temporal;
2+
3+
import com.marklogic.mgmt.AbstractResourceManager;
4+
import com.marklogic.mgmt.ManageClient;
5+
6+
public class TemporalAxesManager extends AbstractResourceManager {
7+
8+
private String databaseIdOrName;
9+
10+
public TemporalAxesManager(ManageClient client, String databaseIdOrName) {
11+
super(client);
12+
setUpdateAllowed(false);
13+
this.databaseIdOrName = databaseIdOrName;
14+
}
15+
16+
@Override
17+
public String getResourcesPath() {
18+
return format("/manage/v2/databases/%s/temporal/axes", databaseIdOrName);
19+
}
20+
21+
@Override
22+
protected String getIdFieldName() {
23+
return "axis-name";
24+
}
25+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.marklogic.mgmt.temporal;
2+
3+
import com.marklogic.mgmt.AbstractManager;
4+
import com.marklogic.mgmt.ManageClient;
5+
import com.marklogic.rest.util.ResourcesFragment;
6+
7+
/**
8+
* Can't extend {@link com.marklogic.mgmt.AbstractResourceManager} as LSQT is represented as properties of a temporal
9+
* collection, rather than a resource in itself.
10+
*
11+
* Uses the following REST Endpoint -
12+
* /manage/v2/databases/{id|name}/temporal/collections/lsqt/properties?collection={name} (GET/PUT)
13+
*
14+
* Created by dsmyth on 27/02/2017.
15+
*/
16+
public class TemporalCollectionLSQTManager extends AbstractManager {
17+
18+
private String databaseIdOrName;
19+
private String temporalCollectionName;
20+
21+
private ManageClient manageClient;
22+
23+
public TemporalCollectionLSQTManager(ManageClient client, String databaseIdOrName, String temporalCollectionName) {
24+
this.manageClient = client;
25+
this.databaseIdOrName = databaseIdOrName;
26+
this.temporalCollectionName = temporalCollectionName;
27+
}
28+
29+
/**
30+
* @return the resources path for the temporal collections in the databaseIdOrName specified in the constructor
31+
*/
32+
private String getResourcesPath() {
33+
return format("/manage/v2/databases/%s/temporal/collections", databaseIdOrName);
34+
}
35+
36+
public String getPropertiesPath() {
37+
return format("%s/lsqt/properties?collection=%s", getResourcesPath(),temporalCollectionName );
38+
}
39+
40+
public boolean isTemporalCollectionExists() {
41+
ResourcesFragment temporalCollections = new ResourcesFragment(manageClient.getXml(getResourcesPath()));
42+
return temporalCollections.resourceExists(temporalCollectionName);
43+
}
44+
45+
46+
public void save(String payload) {
47+
if (isTemporalCollectionExists()) {
48+
String path = getPropertiesPath();
49+
logger.info(format("Updating LSQT properties for %s temporal collection", temporalCollectionName));
50+
putPayload(manageClient, path, payload);
51+
logger.info(format("Updated LSQT properties for %s temporal collection", temporalCollectionName));
52+
} else {
53+
logger.warn(format("Temporal collection %s not found. No update to LSQT settings applied", temporalCollectionName));
54+
}
55+
}
56+
57+
public ManageClient getManageClient() {
58+
return manageClient;
59+
}
60+
61+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.marklogic.mgmt.temporal;
2+
3+
import com.marklogic.mgmt.AbstractResourceManager;
4+
import com.marklogic.mgmt.ManageClient;
5+
6+
public class TemporalCollectionManager extends AbstractResourceManager {
7+
8+
private String databaseIdOrName;
9+
10+
public TemporalCollectionManager(ManageClient client, String databaseIdOrName) {
11+
super(client);
12+
this.databaseIdOrName = databaseIdOrName;
13+
}
14+
15+
@Override
16+
public String getResourcesPath() {
17+
return format("/manage/v2/databases/%s/temporal/collections", databaseIdOrName);
18+
}
19+
20+
@Override
21+
public String getResourcePath(String resourceNameOrId, String... resourceUrlParams) {
22+
resourceNameOrId = encodeResourceId(resourceNameOrId);
23+
return appendParamsAndValuesToPath(format("%s?collection=%s", getResourcesPath(), resourceNameOrId), resourceUrlParams);
24+
}
25+
26+
@Override
27+
public String getPropertiesPath(String resourceNameOrId, String... resourceUrlParams) {
28+
return appendParamsAndValuesToPath(format("%s/properties?collection=%s", getResourcesPath(),resourceNameOrId),
29+
resourceUrlParams);
30+
}
31+
32+
@Override
33+
protected String getIdFieldName() {
34+
return "collection-name";
35+
}
36+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"axis-name": "system",
3+
"axis-start": {
4+
"element-reference": {
5+
"namespace-uri": "",
6+
"localname": "systemStart"
7+
}
8+
},
9+
"axis-end": {
10+
"element-reference": {
11+
"namespace-uri": "",
12+
"localname": "systemEnd"
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)