Skip to content

Commit fdd7f94

Browse files
committed
#415 Can now preview a deployment
1 parent 3fcbd82 commit fdd7f94

File tree

6 files changed

+53
-2
lines changed

6 files changed

+53
-2
lines changed

examples/sample-project/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/build
55
.gradle
66
.settings
7+
gradle-local.properties

examples/sample-project/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ buildscript {
1515
plugins {
1616
// The following plugins are optional
1717

18+
id "net.saliman.properties" version "1.4.6"
19+
1820
// The Java plugin is used to compile and run JUnit tests
1921
id "java"
2022

examples/sample-project/src/main/ml-config/security/amps/amp-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"namespace": "http://example.com/uri",
33
"local-name": "sample-project-amp-1",
44
"document-uri": "/module/path/name",
5-
"modules-database": "",
5+
"modules-database": "%%MODULES_DATABASE%%",
66
"role": ["rest-reader"]
77
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ group=com.marklogic
22
version=3.10.2
33
javadocsDir=../gh-pages-marklogic-java/javadocs
44

5-
mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.10.1
5+
mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.11.dev
66
mlcpUtilDependency=com.marklogic:mlcp-util:0.9.0
77
mlDataMovementDependency=com.marklogic:marklogic-data-movement-components:1.1
88
mlUnitTestDependency=com.marklogic:marklogic-unit-test-client:0.12.0

src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class MarkLogicPlugin implements Plugin<Project> {
102102
project.task("mlUndeploy", group: deployGroup, dependsOn: ["mlUndeployApp", "mlPostUndeploy", "mlDeleteResourceTimestampsFile"], description: "Undeploys all application resources in the configuration directory and allows for additional steps via mlPostUndeploy.dependsOn; requires -Pconfirm=true to be set so this isn't accidentally executed")
103103
project.task("mlRedeploy", group: deployGroup, dependsOn: ["mlClearModulesDatabase", "mlDeploy", "mlDeleteResourceTimestampsFile"], description: "Clears the modules database and then deploys the application")
104104
project.task("mlDeleteResourceTimestampsFile", type: DeleteResourceTimestampsFileTask, group: deployGroup, description: "Delete the properties file in the build directory (stored there by default) that keeps track of when each resource was last deployed; the file path can be overridden by setting the filePath property of this class")
105+
project.task("mlPreviewDeploy", type: PreviewDeployTask, group: deployGroup, description: "Preview a deployment without making any changes")
105106

106107
String adminGroup = "ml-gradle Admin"
107108
project.task("mlInit", type: InitTask, group: adminGroup, description: "Perform a one-time initialization of a MarkLogic server; uses the properties 'mlLicenseKey' and 'mlLicensee'")
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.marklogic.gradle.task
2+
3+
4+
import com.marklogic.appdeployer.command.security.DeployRolesCommand
5+
import com.marklogic.appdeployer.impl.SimpleAppDeployer
6+
import com.marklogic.mgmt.util.ObjectMapperFactory
7+
import com.marklogic.rest.util.PreviewInterceptor
8+
import org.gradle.api.tasks.TaskAction
9+
10+
/**
11+
* Extends DeployAppTask and applies an instance of PreviewInterceptor to the RestTemplate objects associated with
12+
* the ManageClient created by MarkLogicPlugin. Because of this extension, a user can use the "ignore" property
13+
* supported by the parent class to ignore any commands that cause issues with doing a preview.
14+
*/
15+
class PreviewDeployTask extends DeployAppTask {
16+
17+
@TaskAction
18+
void deployApp() {
19+
// Disable loading of any modules
20+
getAppConfig().setModulePaths(new ArrayList<String>())
21+
22+
// Disable loading of any schemas
23+
getAppConfig().setSchemasPath(null)
24+
25+
SimpleAppDeployer deployer = getAppDeployer()
26+
27+
// Loading roles in two phases breaks the preview feature, so it's disabled
28+
DeployRolesCommand deployRolesCommand = deployer.getCommandOfType(DeployRolesCommand.class)
29+
if (deployRolesCommand != null) {
30+
deployRolesCommand.setDeployRolesInTwoPhases(false)
31+
}
32+
33+
PreviewInterceptor interceptor = new PreviewInterceptor(getManageClient())
34+
getManageClient().getRestTemplate().getInterceptors().add(interceptor)
35+
getManageClient().getRestTemplate().setErrorHandler(interceptor)
36+
if (getManageClient().getRestTemplate() != getManageClient().getSecurityUserRestTemplate()) {
37+
getManageClient().getSecurityUserRestTemplate().getInterceptors().add(interceptor)
38+
getManageClient().getSecurityUserRestTemplate().setErrorHandler(interceptor)
39+
}
40+
41+
super.deployApp()
42+
43+
println "\nPREVIEW OF DEPLOYMENT:\n"
44+
println ObjectMapperFactory.getObjectMapper().writeValueAsString(interceptor.getResults())
45+
}
46+
47+
}

0 commit comments

Comments
 (0)