This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#88 New command for deploying all flexrep resources from flexrep/mast…
…er or flexrep/replica
- Loading branch information
Showing
18 changed files
with
709 additions
and
0 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/main/java/com/marklogic/appdeployer/command/flexrep/DeployFlexrepCommand.java
This file contains 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,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; | ||
} | ||
|
||
} |
This file contains 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
4 changes: 4 additions & 0 deletions
4
src/test/resources/sample-app/flexrep-combined/databases/content-database.json
This file contains 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,4 @@ | ||
{ | ||
"database-name": "%%DATABASE%%", | ||
"triggers-database": "%%TRIGGERS_DATABASE%%" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/test/resources/sample-app/flexrep-combined/databases/triggers-database.json
This file contains 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,3 @@ | ||
{ | ||
"database-name": "%%TRIGGERS_DATABASE%%" | ||
} |
11 changes: 11 additions & 0 deletions
11
...sources/sample-app/flexrep-combined/flexrep/master/cpf/cpf-configs/master-cpf-config.json
This file contains 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,11 @@ | ||
{ | ||
"domain-name": "master-domain", | ||
"restart-user-name": "admin", | ||
"eval-module": "Modules", | ||
"eval-root": "/", | ||
"conversion-enabled": false, | ||
"permission": [{ | ||
"role-name": "app-user", | ||
"capability": "read" | ||
}] | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/resources/sample-app/flexrep-combined/flexrep/master/cpf/domains/master-domain.json
This file contains 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,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"] | ||
} |
149 changes: 149 additions & 0 deletions
149
src/test/resources/sample-app/flexrep-combined/flexrep/master/cpf/pipelines/flexrep.xml
This file contains 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,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> |
Oops, something went wrong.