This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Feature/issue 28 add temporal config #144
Merged
rjrudin
merged 11 commits into
marklogic:dev
from
derms:feature/issue-28-add-temporal-config
Mar 19, 2017
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d3f6b93
Initial cut of temporal config support
ccfc26e
Merge branch 'dev' of https://github.com/rjrudin/ml-app-deployer into…
655fbaf
reset to previous commit
cdf3211
Added temporal config
5a18659
added temporal config
2a2b281
Reset to commit
f29685f
reset to commit
c0ec99a
updated sort order constants with temporal config
887ed9a
Added temporal commands to command map builder
160149d
re-ordered temporal config
6bc3785
Removed special characters
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/marklogic/appdeployer/command/temporal/DeployTemporalAxesCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.marklogic.appdeployer.command.temporal; | ||
|
|
||
| import com.marklogic.appdeployer.command.AbstractResourceCommand; | ||
| import com.marklogic.appdeployer.command.CommandContext; | ||
| import com.marklogic.appdeployer.command.SortOrderConstants; | ||
| import com.marklogic.mgmt.ResourceManager; | ||
| import com.marklogic.mgmt.temporal.TemporalAxesManager; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| public class DeployTemporalAxesCommand extends AbstractResourceCommand { | ||
|
|
||
| private String databaseIdOrName; | ||
|
|
||
| public DeployTemporalAxesCommand() { | ||
| // TODO - verify that range element indexes exist before creation of temporal axes? | ||
| setExecuteSortOrder(SortOrderConstants.DEPLOY_TEMPORAL_AXIS); | ||
| //can't delete temporal axes until able to delete temporal collections... | ||
| setDeleteResourcesOnUndo(false); | ||
| } | ||
|
|
||
| @Override | ||
| protected File[] getResourceDirs(CommandContext context) { | ||
| return new File[] { new File(context.getAppConfig().getConfigDir().getTemporalDir(),"axes") }; | ||
| } | ||
|
|
||
| @Override | ||
| protected ResourceManager getResourceManager(CommandContext context) { | ||
| String db = databaseIdOrName != null ? databaseIdOrName : context.getAppConfig().getContentDatabaseName(); | ||
| return new TemporalAxesManager(context.getManageClient(), db); | ||
| } | ||
|
|
||
| public void setDatabaseIdOrName(String databaseIdOrName) { | ||
| this.databaseIdOrName = databaseIdOrName; | ||
| } | ||
|
|
||
| } | ||
36 changes: 36 additions & 0 deletions
36
...ain/java/com/marklogic/appdeployer/command/temporal/DeployTemporalCollectionsCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.marklogic.appdeployer.command.temporal; | ||
|
|
||
| import com.marklogic.appdeployer.command.AbstractResourceCommand; | ||
| import com.marklogic.appdeployer.command.CommandContext; | ||
| import com.marklogic.appdeployer.command.SortOrderConstants; | ||
| import com.marklogic.mgmt.ResourceManager; | ||
| import com.marklogic.mgmt.temporal.TemporalCollectionManager; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| public class DeployTemporalCollectionsCommand extends AbstractResourceCommand { | ||
|
|
||
| private String databaseIdOrName; | ||
|
|
||
| public DeployTemporalCollectionsCommand() { | ||
| setExecuteSortOrder(SortOrderConstants.DEPLOY_TEMPORAL_COLLECTIONS); | ||
| // if the temporal collection contains documents, then the delete operation will fail | ||
| // TODO - could add check to get count of documents in temporal collection. If zero docs, then can delete | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine too. "Undeploying" temporal config can be a future enhancement. |
||
| setDeleteResourcesOnUndo(false); | ||
| } | ||
|
|
||
| @Override | ||
| protected File[] getResourceDirs(CommandContext context) { | ||
| return new File[] { new File(context.getAppConfig().getConfigDir().getTemporalDir(),"collections") }; | ||
| } | ||
|
|
||
| @Override | ||
| protected ResourceManager getResourceManager(CommandContext context) { | ||
| String db = databaseIdOrName != null ? databaseIdOrName : context.getAppConfig().getContentDatabaseName(); | ||
| return new TemporalCollectionManager(context.getManageClient(), db); | ||
| } | ||
|
|
||
| public void setDatabaseIdOrName(String databaseIdOrName) { | ||
| this.databaseIdOrName = databaseIdOrName; | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
...java/com/marklogic/appdeployer/command/temporal/DeployTemporalCollectionsLSQTCommand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.marklogic.appdeployer.command.temporal; | ||
|
|
||
| import com.marklogic.appdeployer.command.*; | ||
| import com.marklogic.mgmt.temporal.TemporalCollectionLSQTManager; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| /** | ||
| * Created by dsmyth on 28/02/2017. | ||
| */ | ||
| public class DeployTemporalCollectionsLSQTCommand extends AbstractCommand { | ||
|
|
||
| private String databaseIdOrName; | ||
|
|
||
| public DeployTemporalCollectionsLSQTCommand() { | ||
| setExecuteSortOrder(SortOrderConstants.DEPLOY_TEMPORAL_COLLECTIONS_LSQT); | ||
| } | ||
|
|
||
| public void setDatabaseIdOrName(String databaseIdOrName) { | ||
| this.databaseIdOrName = databaseIdOrName; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute(CommandContext context) { | ||
| File configDir = new File(new File(context.getAppConfig().getConfigDir().getTemporalDir(), "collections"), "lsqt"); | ||
| String db = databaseIdOrName != null ? databaseIdOrName : context.getAppConfig().getContentDatabaseName(); | ||
| if (configDir != null && configDir.exists()) { | ||
| for (File f : configDir.listFiles(new ResourceFilenameFilter())) { | ||
| String name = f.getName(); | ||
| // use filename without suffix as temporal collection | ||
| String temporalCollectionName = name.replaceAll(".xml|.json",""); | ||
| String payload = copyFileToString(f, context); | ||
| logger.info(format("Extracted temporal collection name '%s' from filename '%s'", temporalCollectionName, name)); | ||
| new TemporalCollectionLSQTManager(context.getManageClient(),db, temporalCollectionName).save(payload); | ||
| } | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/marklogic/mgmt/temporal/TemporalAxesManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.marklogic.mgmt.temporal; | ||
|
|
||
| import com.marklogic.mgmt.AbstractResourceManager; | ||
| import com.marklogic.mgmt.ManageClient; | ||
|
|
||
| public class TemporalAxesManager extends AbstractResourceManager { | ||
|
|
||
| private String databaseIdOrName; | ||
|
|
||
| public TemporalAxesManager(ManageClient client, String databaseIdOrName) { | ||
| super(client); | ||
| setUpdateAllowed(false); | ||
| this.databaseIdOrName = databaseIdOrName; | ||
| } | ||
|
|
||
| @Override | ||
| public String getResourcesPath() { | ||
| return format("/manage/v2/databases/%s/temporal/axes", databaseIdOrName); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getIdFieldName() { | ||
| return "axis-name"; | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/marklogic/mgmt/temporal/TemporalCollectionLSQTManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.marklogic.mgmt.temporal; | ||
|
|
||
| import com.marklogic.mgmt.AbstractManager; | ||
| import com.marklogic.mgmt.ManageClient; | ||
| import com.marklogic.rest.util.ResourcesFragment; | ||
|
|
||
| /** | ||
| * Can't extend {@link com.marklogic.mgmt.AbstractResourceManager} as LSQT is represented as properties of a temporal | ||
| * collection, rather than a resource in itself. | ||
| * | ||
| * Uses the following REST Endpoint - | ||
| * /manage/v2/databases/{id|name}/temporal/collections/lsqt/properties?collection={name} (GET/PUT) | ||
| * | ||
| * Created by dsmyth on 27/02/2017. | ||
| */ | ||
| public class TemporalCollectionLSQTManager extends AbstractManager { | ||
|
|
||
| private String databaseIdOrName; | ||
| private String temporalCollectionName; | ||
|
|
||
| private ManageClient manageClient; | ||
|
|
||
| public TemporalCollectionLSQTManager(ManageClient client, String databaseIdOrName, String temporalCollectionName) { | ||
| this.manageClient = client; | ||
| this.databaseIdOrName = databaseIdOrName; | ||
| this.temporalCollectionName = temporalCollectionName; | ||
| } | ||
|
|
||
| /** | ||
| * @return the resources path for the temporal collections in the databaseIdOrName specified in the constructor | ||
| */ | ||
| private String getResourcesPath() { | ||
| return format("/manage/v2/databases/%s/temporal/collections", databaseIdOrName); | ||
| } | ||
|
|
||
| public String getPropertiesPath() { | ||
| return format("%s/lsqt/properties?collection=%s", getResourcesPath(),temporalCollectionName ); | ||
| } | ||
|
|
||
| public boolean isTemporalCollectionExists() { | ||
| ResourcesFragment temporalCollections = new ResourcesFragment(manageClient.getXml(getResourcesPath())); | ||
| return temporalCollections.resourceExists(temporalCollectionName); | ||
| } | ||
|
|
||
|
|
||
| public void save(String payload) { | ||
| if (isTemporalCollectionExists()) { | ||
| String path = getPropertiesPath(); | ||
| logger.info(format("Updating LSQT properties for %s temporal collection", temporalCollectionName)); | ||
| putPayload(manageClient, path, payload); | ||
| logger.info(format("Updated LSQT properties for %s temporal collection", temporalCollectionName)); | ||
| } else { | ||
| logger.warn(format("Temporal collection %s not found. No update to LSQT settings applied", temporalCollectionName)); | ||
| } | ||
| } | ||
|
|
||
| public ManageClient getManageClient() { | ||
| return manageClient; | ||
| } | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/marklogic/mgmt/temporal/TemporalCollectionManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.marklogic.mgmt.temporal; | ||
|
|
||
| import com.marklogic.mgmt.AbstractResourceManager; | ||
| import com.marklogic.mgmt.ManageClient; | ||
|
|
||
| public class TemporalCollectionManager extends AbstractResourceManager { | ||
|
|
||
| private String databaseIdOrName; | ||
|
|
||
| public TemporalCollectionManager(ManageClient client, String databaseIdOrName) { | ||
| super(client); | ||
| this.databaseIdOrName = databaseIdOrName; | ||
| } | ||
|
|
||
| @Override | ||
| public String getResourcesPath() { | ||
| return format("/manage/v2/databases/%s/temporal/collections", databaseIdOrName); | ||
| } | ||
|
|
||
| @Override | ||
| public String getResourcePath(String resourceNameOrId, String... resourceUrlParams) { | ||
| resourceNameOrId = encodeResourceId(resourceNameOrId); | ||
| return appendParamsAndValuesToPath(format("%s?collection=%s", getResourcesPath(), resourceNameOrId), resourceUrlParams); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertiesPath(String resourceNameOrId, String... resourceUrlParams) { | ||
| return appendParamsAndValuesToPath(format("%s/properties?collection=%s", getResourcesPath(),resourceNameOrId), | ||
| resourceUrlParams); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getIdFieldName() { | ||
| return "collection-name"; | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/test/resources/sample-app/src/main/ml-config/temporal/axis/temporal-system-axis.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "axis-name": "system", | ||
| "axis-start": { | ||
| "element-reference": { | ||
| "namespace-uri": "", | ||
| "localname": "systemStart" | ||
| } | ||
| }, | ||
| "axis-end": { | ||
| "element-reference": { | ||
| "namespace-uri": "", | ||
| "localname": "systemEnd" | ||
| } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/test/resources/sample-app/src/main/ml-config/temporal/axis/temporal-valid-axis.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "axis-name": "valid", | ||
| "axis-start": { | ||
| "element-reference": { | ||
| "namespace-uri": "", | ||
| "localname": "validStart" | ||
| } | ||
| }, | ||
| "axis-end": { | ||
| "element-reference": { | ||
| "namespace-uri": "", | ||
| "localname": "validEnd" | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
...ces/sample-app/src/main/ml-config/temporal/collections/lsqt/temporal-collection-lsqt.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "lsqt-enabled": true, | ||
| "automation": { | ||
| "enabled": true, | ||
| "period": 5000 | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
...est/resources/sample-app/src/main/ml-config/temporal/collections/temporal-collection.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "collection-name": "temporal-collection", | ||
| "system-axis": "system", | ||
| "valid-axis": "valid" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine - possible enhancement in the future if the Manage API doesn't give a very helpful error