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

Commit

Permalink
#88 New command for deploying all flexrep resources from flexrep/mast…
Browse files Browse the repository at this point in the history
…er or flexrep/replica
  • Loading branch information
rjrudin committed Mar 24, 2016
1 parent 3fe7a83 commit 7cadcac
Show file tree
Hide file tree
Showing 18 changed files with 709 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.marklogic.appdeployer.command.flexrep;

import com.marklogic.appdeployer.AppConfig;
import com.marklogic.appdeployer.command.AbstractCommand;
import com.marklogic.appdeployer.command.CommandContext;
import com.marklogic.appdeployer.command.SortOrderConstants;
import com.marklogic.appdeployer.command.UndoableCommand;
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
import com.marklogic.appdeployer.command.cpf.DeployCpfConfigsCommand;
import com.marklogic.appdeployer.command.cpf.DeployDomainsCommand;
import com.marklogic.appdeployer.command.cpf.DeployPipelinesCommand;
import com.marklogic.appdeployer.impl.SimpleAppDeployer;

import java.io.File;

/**
* This command is for deploying all resources associated with a flexrep config. It combines CPF, flexrep configs
* and targets, and optionally an HTTP server by reusing other commands. The intent is to support a configuration
* for both a master and a replica in the same project. Most of the time you won't need this, in which case you
* can just use DeployConfigsCommand and DeployTargetsCommand.
*/
public class DeployFlexrepCommand extends AbstractCommand implements UndoableCommand {

private String path;

public DeployFlexrepCommand() {
this("master");
}

public DeployFlexrepCommand(String path) {
this.path = path;
setExecuteSortOrder(SortOrderConstants.DEPLOY_OTHER_SERVERS);
}

@Override
public Integer getUndoSortOrder() {
return SortOrderConstants.DELETE_OTHER_SERVERS;
}

@Override
public void execute(CommandContext context) {
AppConfig appConfig = context.getAppConfig();
File flexrepBaseDir = getFlexrepBaseDir(appConfig);
if (flexrepBaseDir != null) {
SimpleAppDeployer d = new SimpleAppDeployer(context.getManageClient(), context.getAdminManager(),
new DeployCpfConfigsCommand(), new DeployDomainsCommand(), new DeployPipelinesCommand(), new DeployConfigsCommand(), new DeployTargetsCommand(), new DeployOtherServersCommand());
File currentBaseDir = appConfig.getConfigDir().getBaseDir();
appConfig.getConfigDir().setBaseDir(flexrepBaseDir);
try {
d.deploy(appConfig);
} finally {
appConfig.getConfigDir().setBaseDir(currentBaseDir);
}
}
}


@Override
public void undo(CommandContext context) {
AppConfig appConfig = context.getAppConfig();
File flexrepBaseDir = getFlexrepBaseDir(appConfig);
if (flexrepBaseDir != null) {
SimpleAppDeployer d = new SimpleAppDeployer(context.getManageClient(), context.getAdminManager(), new DeployOtherServersCommand());
File currentBaseDir = appConfig.getConfigDir().getBaseDir();
appConfig.getConfigDir().setBaseDir(flexrepBaseDir);
try {
d.undeploy(appConfig);
} finally {
appConfig.getConfigDir().setBaseDir(currentBaseDir);
}
}
}

protected File getFlexrepBaseDir(AppConfig appConfig) {
if (path == null) {
return null;
}

File flexrepDir = appConfig.getConfigDir().getFlexrepDir();
if (flexrepDir == null || !flexrepDir.exists()) {
return null;
}

File flexrepBaseDir = new File(flexrepDir, path);
if (flexrepBaseDir == null || !flexrepBaseDir.exists()) {
return null;
}

return flexrepBaseDir;
}

public void setPath(String path) {
this.path = path;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.io.File;

import com.marklogic.mgmt.appservers.ServerManager;
import com.marklogic.mgmt.cpf.CpfConfigManager;
import com.marklogic.mgmt.cpf.DomainManager;
import com.marklogic.mgmt.cpf.PipelineManager;
import org.junit.After;
import org.junit.Test;

Expand Down Expand Up @@ -52,6 +56,50 @@ public void noFlexrepDir() {
appDeployer.deploy(appConfig);
}

@Test
public void masterFlexrep() {
appConfig.getConfigDir().setBaseDir(new File("src/test/resources/sample-app/flexrep-combined"));

initializeAppDeployer(new DeployContentDatabasesCommand(1), new DeployTriggersDatabaseCommand(), new DeployFlexrepCommand("master"));

appDeployer.deploy(appConfig);

final String domainName = "master-domain";
final String db = appConfig.getContentDatabaseName();
assertTrue(new ServerManager(manageClient).exists("master-flexrep-server"));
assertTrue(new DomainManager(manageClient).exists(appConfig.getTriggersDatabaseName(), domainName));
assertTrue(new PipelineManager(manageClient).exists(appConfig.getTriggersDatabaseName(), "Flexible Replication"));
assertTrue(new PipelineManager(manageClient).exists(appConfig.getTriggersDatabaseName(), "Status Change Handling"));
assertTrue(new CpfConfigManager(manageClient).exists(appConfig.getTriggersDatabaseName(), domainName));
assertTrue(new ConfigManager(manageClient, db).exists(domainName));
assertTrue(new TargetManager(manageClient, db, domainName).exists("master-domain-target"));

undeploySampleApp();
assertFalse(new ServerManager(manageClient).exists("master-flexrep-server"));
}

@Test
public void replicaFlexrep() {
appConfig.getConfigDir().setBaseDir(new File("src/test/resources/sample-app/flexrep-combined"));

initializeAppDeployer(new DeployContentDatabasesCommand(1), new DeployTriggersDatabaseCommand(), new DeployFlexrepCommand("replica"));

appDeployer.deploy(appConfig);

final String domainName = "replica-domain";
final String db = appConfig.getContentDatabaseName();
assertTrue(new ServerManager(manageClient).exists("replica-flexrep-server"));
assertTrue(new DomainManager(manageClient).exists(appConfig.getTriggersDatabaseName(), domainName));
assertTrue(new PipelineManager(manageClient).exists(appConfig.getTriggersDatabaseName(), "Flexible Replication"));
assertTrue(new PipelineManager(manageClient).exists(appConfig.getTriggersDatabaseName(), "Status Change Handling"));
assertTrue(new CpfConfigManager(manageClient).exists(appConfig.getTriggersDatabaseName(), domainName));
assertTrue(new ConfigManager(manageClient, db).exists(domainName));
assertTrue(new TargetManager(manageClient, db, domainName).exists("replica-domain-target"));

undeploySampleApp();
assertFalse(new ServerManager(manageClient).exists("master-flexrep-server"));
}

private void assertConfigAndTargetAreDeployed() {
final String domainName = "sample-app-domain-1";
ConfigManager configMgr = new ConfigManager(manageClient, appConfig.getContentDatabaseName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"database-name": "%%DATABASE%%",
"triggers-database": "%%TRIGGERS_DATABASE%%"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"database-name": "%%TRIGGERS_DATABASE%%"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"domain-name": "master-domain",
"restart-user-name": "admin",
"eval-module": "Modules",
"eval-root": "/",
"conversion-enabled": false,
"permission": [{
"role-name": "app-user",
"capability": "read"
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"domain-name": "master-domain",
"description": "Test domain for sample app",
"scope": "directory",
"uri": "/master/",
"depth": "infinity",
"eval-module": "Modules",
"eval-root": "/",
"pipeline": ["Status Change Handling", "Flexible Replication"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<pipeline-properties xmlns="http://marklogic.com/manage/pipeline/properties">
<pipeline-id>6600933789859022149</pipeline-id>
<pipeline-name>Flexible Replication</pipeline-name>
<pipeline-description>
Attempts push replication if possible, otherwise updates document properties so that push or poll will occur later.
</pipeline-description>
<success-action>
<module>/MarkLogic/cpf/actions/success-action.xqy</module>
</success-action>
<failure-action>
<module>/MarkLogic/cpf/actions/failure-action.xqy</module>
</failure-action>
<state-transition>
<annotation>
Replicate a document and transition to state "replicated".
</annotation>
<state>http://marklogic.com/states/converted</state>
<on-success>http://marklogic.com/states/replicated</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>9100</priority>
<execute>
<condition>
<module>
/MarkLogic/conversion/actions/conversion-source-condition.xqy
</module>
</condition>
<action>
<module>/MarkLogic/flexrep/actions/replication-action.xqy</module>
</action>
</execute>
</state-transition>
<state-transition>
<annotation>
Replicate a document and transition to state "replicated".
</annotation>
<state>http://marklogic.com/states/structured-xhtml</state>
<on-success>http://marklogic.com/states/replicated</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>5000</priority>
<default-action>
<module>/MarkLogic/flexrep/actions/replication-action.xqy</module>
</default-action>
</state-transition>
<state-transition>
<annotation>
Replicate a document and transition to state "replicated".
</annotation>
<state>http://marklogic.com/states/initial</state>
<on-success>http://marklogic.com/states/replicated</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>5000</priority>
<default-action>
<module>/MarkLogic/flexrep/actions/replication-action.xqy</module>
</default-action>
</state-transition>
<state-transition>
<annotation>
Replicate a document and transition to state "replicated".
</annotation>
<state>http://marklogic.com/states/entities/enriched</state>
<on-success>http://marklogic.com/states/replicated</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>5000</priority>
<default-action>
<module>/MarkLogic/flexrep/actions/replication-action.xqy</module>
</default-action>
</state-transition>
<state-transition>
<annotation>
Replicate a document and transition to state "replicated".
</annotation>
<state>http://marklogic.com/states/xinclude/expanded</state>
<on-success>http://marklogic.com/states/replicated</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>5000</priority>
<default-action>
<module>/MarkLogic/flexrep/actions/replication-action.xqy</module>
</default-action>
</state-transition>
<state-transition>
<annotation>
Replicate a document and transition to state "replicated".
</annotation>
<state>http://marklogic.com/states/alerted</state>
<on-success>http://marklogic.com/states/replicated</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>5000</priority>
<default-action>
<module>/MarkLogic/flexrep/actions/replication-action.xqy</module>
</default-action>
</state-transition>
<state-transition>
<annotation>
Replicate a document and transition to state "replicated".
</annotation>
<state>http://marklogic.com/states/property-updated</state>
<on-success>http://marklogic.com/states/replicated</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>5000</priority>
<default-action>
<module>/MarkLogic/flexrep/actions/replication-action.xqy</module>
</default-action>
</state-transition>
<state-transition>
<annotation>
Document has been updated: reprocess if need be. Note: the preconditions will avoid reprocessing of active documents, so we
will avoid falling into a processing loop when the processing updates a document.
</annotation>
<state>http://marklogic.com/states/updated</state>
<on-success>http://marklogic.com/states/initial</on-success>
<on-failure>http://marklogic.com/states/error</on-failure>
<priority>5000</priority>
</state-transition>
<status-transition>
<annotation>
Leave a bread crumb that the document has been deleted.
</annotation>
<status>deleted</status>
<priority>5000</priority>
<always>true</always>
<default-action>
<module>/MarkLogic/flexrep/actions/delete-action.xqy</module>
</default-action>
</status-transition>
<event-transition>
<annotation>
Pull flexrep properties from prior version of document if needed.
</annotation>
<event>updated</event>
<priority>5000</priority>
<default-action>
<module>
/MarkLogic/flexrep/actions/on-event-pull-properties.xqy
</module>
</default-action>
</event-transition>
<event-transition>
<annotation>
Pull flexrep properties from prior version of document if needed.
</annotation>
<event>property-updated</event>
<priority>5000</priority>
<default-action>
<module>
/MarkLogic/flexrep/actions/on-event-pull-properties.xqy
</module>
</default-action>
</event-transition>
</pipeline-properties>
Loading

0 comments on commit 7cadcac

Please sign in to comment.