Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/com/marklogic/appdeployer/ConfigDir.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Defines all of the directories where configuration files can be found. This is decoupled from the NounManager
* classes, who don't need to care where to look for configuration files, they just need to care about how to load the
* data in those files.
*
*
* Every directory path referenced in this should have a setter so that it can be modified in e.g. a Gradle build file.
*/
public class ConfigDir {
Expand Down Expand Up @@ -67,12 +67,14 @@ public File getClustersDir() {
public File getAlertDir() {
return new File(baseDir, "alert");
}

public File getFlexrepDir() {
return new File(baseDir, "flexrep");
}

public void setDatabasesPath(String databasesPath) {
public File getTemporalDir() { return new File(baseDir, "temporal"); }

public void setDatabasesPath(String databasesPath) {
this.databasesPath = databasesPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import com.marklogic.appdeployer.command.schemas.LoadSchemasCommand;
import com.marklogic.appdeployer.command.security.*;
import com.marklogic.appdeployer.command.tasks.DeployScheduledTasksCommand;
import com.marklogic.appdeployer.command.temporal.DeployTemporalAxesCommand;
import com.marklogic.appdeployer.command.temporal.DeployTemporalCollectionsCommand;
import com.marklogic.appdeployer.command.temporal.DeployTemporalCollectionsLSQTCommand;
import com.marklogic.appdeployer.command.triggers.DeployTriggersCommand;
import com.marklogic.appdeployer.command.viewschemas.DeployViewSchemasCommand;

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

// Temporal
List<Command> temporalCommands = new ArrayList<>();
temporalCommands.add(new DeployTemporalAxesCommand());
temporalCommands.add(new DeployTemporalCollectionsCommand());
temporalCommands.add(new DeployTemporalCollectionsLSQTCommand());
map.put("mlTemporalCommands", temporalCommands);

// Triggers
List<Command> triggerCommands = new ArrayList<Command>();
triggerCommands.add(new DeployTriggersCommand());
map.put("mlTriggerCommands", triggerCommands);


// SQL Views
List<Command> viewCommands = new ArrayList<Command>();
viewCommands.add(new DeployViewSchemasCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class SortOrderConstants {
public static Integer DEPLOY_EXTERNAL_SECURITY = 70;
public static Integer DEPLOY_PROTECTED_COLLECTIONS = 80;
public static Integer DEPLOY_MIMETYPES = 90;

public static Integer DEPLOY_TRIGGERS_DATABASE = 100;
public static Integer DEPLOY_SCHEMAS_DATABASE = 100;
public static Integer DEPLOY_CONTENT_DATABASES = 120;
Expand All @@ -37,7 +37,11 @@ public abstract class SortOrderConstants {
public static Integer DEPLOY_AMPS = 450;

public static Integer DEPLOY_TRIGGERS = 700;


public static Integer DEPLOY_TEMPORAL_AXIS = 750;
public static Integer DEPLOY_TEMPORAL_COLLECTIONS = 751;
public static Integer DEPLOY_TEMPORAL_COLLECTIONS_LSQT = 752;

public static Integer DEPLOY_SCHEDULED_TASKS = 800;

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

public static Integer DEPLOY_FLEXREP_CONFIGS = 1000;
public static Integer DEPLOY_FLEXREP_TARGETS = 1010;

public static Integer DEPLOY_SQL_VIEWS = 1100;

public static Integer DEPLOY_FOREST_REPLICAS = 1200;

// Undo constants
public static Integer DELETE_GROUPS = 10000;

public static Integer DELETE_MIMETYPES = 9500;

public static Integer DELETE_USERS = 9000;
public static Integer DELETE_CERTIFICATE_TEMPLATES = 9010;
public static Integer DELETE_CERTIFICATE_AUTHORITIES = 9020;
Expand All @@ -76,7 +80,7 @@ public abstract class SortOrderConstants {
* need to make sure the replicas are deleted first.
*/
public static Integer DELETE_FOREST_REPLICAS = 8000;

public static Integer DELETE_CONTENT_DATABASES = 8100;
public static Integer DELETE_OTHER_DATABASES = 8120;
public static Integer DELETE_TRIGGERS_DATABASE = 8140;
Expand Down
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?
Copy link
Contributor Author

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

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;
}

}
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
Copy link
Contributor Author

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 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;
}
}
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);
}
}
}
}
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";
}
}
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;
}

}
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";
}
}
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"
}
}
}
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"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"lsqt-enabled": true,
"automation": {
"enabled": true,
"period": 5000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"collection-name": "temporal-collection",
"system-axis": "system",
"valid-axis": "valid"
}
Loading