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

Commit d3f6b93

Browse files
Dermot SmythDermot Smyth
authored andcommitted
Initial cut of temporal config support
1 parent 09f109b commit d3f6b93

25 files changed

+465
-11
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 {
@@ -63,12 +63,14 @@ public File getCpfDir() {
6363
public File getAlertDir() {
6464
return new File(baseDir, "alert");
6565
}
66-
66+
6767
public File getFlexrepDir() {
6868
return new File(baseDir, "flexrep");
6969
}
7070

71-
public void setDatabasesPath(String databasesPath) {
71+
public File getTemporalDir() { return new File(baseDir, "temporal"); }
72+
73+
public void setDatabasesPath(String databasesPath) {
7274
this.databasesPath = databasesPath;
7375
}
7476

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

Lines changed: 12 additions & 8 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;
@@ -26,7 +26,7 @@ public abstract class SortOrderConstants {
2626

2727
// Module code may depend on schemas, but not vice-versa.
2828
public static Integer LOAD_SCHEMAS = 350;
29-
29+
3030
// Modules have to be loaded after the REST API server has been updated, for if the deployer is expecting to load
3131
// modules via SSL, then the REST API server must already be configured with a certificate template
3232
public static Integer LOAD_MODULES = 400;
@@ -35,7 +35,11 @@ public abstract class SortOrderConstants {
3535
public static Integer DEPLOY_AMPS = 450;
3636

3737
public static Integer DEPLOY_TRIGGERS = 700;
38-
38+
39+
public static Integer DEPLOY_TEMPORAL_AXIS = 750;
40+
public static Integer DEPLOY_TEMPORAL_COLLECTIONS = 751;
41+
public static Integer DEPLOY_TEMPORAL_COLLECTIONS_LSQT = 752;
42+
3943
public static Integer DEPLOY_SCHEDULED_TASKS = 800;
4044

4145
public static Integer DEPLOY_DEFAULT_PIPELINES = 900;
@@ -49,16 +53,16 @@ public abstract class SortOrderConstants {
4953

5054
public static Integer DEPLOY_FLEXREP_CONFIGS = 1000;
5155
public static Integer DEPLOY_FLEXREP_TARGETS = 1010;
52-
56+
5357
public static Integer DEPLOY_SQL_VIEWS = 1100;
5458

5559
public static Integer DEPLOY_FOREST_REPLICAS = 1200;
56-
60+
5761
// Undo constants
5862
public static Integer DELETE_GROUPS = 10000;
5963

6064
public static Integer DELETE_MIMETYPES = 9500;
61-
65+
6266
public static Integer DELETE_USERS = 9000;
6367
public static Integer DELETE_CERTIFICATE_TEMPLATES = 9010;
6468
public static Integer DELETE_CERTIFICATE_AUTHORITIES = 9020;
@@ -75,7 +79,7 @@ public abstract class SortOrderConstants {
7579
* need to make sure the replicas are deleted first.
7680
*/
7781
public static Integer DELETE_FOREST_REPLICAS = 8000;
78-
82+
7983
public static Integer DELETE_CONTENT_DATABASES = 8100;
8084
public static Integer DELETE_OTHER_DATABASES = 8120;
8185
public static Integer DELETE_TRIGGERS_DATABASE = 8140;
@@ -84,5 +88,5 @@ public abstract class SortOrderConstants {
8488
public static Integer DELETE_REST_API_SERVERS = 7000;
8589
public static Integer DELETE_OTHER_SERVERS = 7010;
8690

87-
public static Integer DELETE_SCHEDULED_TASKS = 1000;
91+
public static Integer DELETE_SCHEDULED_TASKS = 1000;
8892
}
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"axis-name": "valid",
3+
"axis-start": {
4+
"element-reference": {
5+
"namespace-uri": "",
6+
"localname": "validStart"
7+
}
8+
},
9+
"axis-end": {
10+
"element-reference": {
11+
"namespace-uri": "",
12+
"localname": "validEnd"
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)