Skip to content

Commit cd80e36

Browse files
committed
#349 New task for printing the forests to be created
1 parent 7f32dce commit cd80e36

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
group=com.marklogic
2-
version=3.6.3
2+
version=3.7.0
33
javadocsDir=../gh-pages-marklogic-java/javadocs
44

5-
mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.6.3
5+
mlAppDeployerDependency=com.marklogic:ml-app-deployer:3.7.0
66
mlcpUtilDependency=com.marklogic:mlcp-util:0.9.0
77
mlDataMovementDependency=com.marklogic:marklogic-data-movement-components:1.0
88
mlUnitTestDependency=com.marklogic:ml-unit-test-client:0.10.0

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.marklogic.gradle.task.forests.ConfigureForestReplicasTask
2626
import com.marklogic.gradle.task.forests.DeleteForestReplicasTask
2727
import com.marklogic.gradle.task.forests.DeployCustomForestsTask
2828
import com.marklogic.gradle.task.forests.DeployForestReplicasTask
29+
import com.marklogic.gradle.task.forests.PrintForestPlanTask
2930
import com.marklogic.gradle.task.groups.DeployGroupsTask
3031
import com.marklogic.gradle.task.groups.SetTraceEventsTask
3132
import com.marklogic.gradle.task.hosts.AssignHostsToGroupsTask
@@ -187,6 +188,7 @@ class MarkLogicPlugin implements Plugin<Project> {
187188
project.task("mlDeleteForestReplicas", type: DeleteForestReplicasTask, group: forestGroup, description: "Deprecated - delete forest replicas via the command.forestNamesAndReplicaCounts map")
188189
project.task("mlDeployCustomForests", type: DeployCustomForestsTask, group: forestGroup, description: "Deploy custom forests as defined in subdirectories of the forests configuration directory")
189190
project.task("mlDeployForestReplicas", type: DeployForestReplicasTask, group: forestGroup, description: "Prefer this over mlConfigureForestReplicas; it does the same thing, but uses the ConfigureForestReplicasCommand that is used by mlDeploy")
191+
project.task("mlPrintForestPlan", type: PrintForestPlanTask, group: forestGroup, description: "Print a list of primary forests to be created for a database specified by -Pdatabase=(name of database) when the database is next deployed")
190192

191193
String groupsGroup = "ml-gradle Group"
192194
project.task("mlDeployGroups", type: DeployGroupsTask, group: groupsGroup, description: "Deploy each group, updating it if it exists, in the configuration directory")

src/main/groovy/com/marklogic/gradle/ProjectPropertySource.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public String getProperty(String name) {
3030
*
3131
* This currently only includes properties that start with "ml". This is to avoid picking up very generically-named
3232
* properties in Gradle, such as "name" and "version", which may conflict with properties from other sources.
33-
* @return
3433
*/
3534
@Override
3635
public Properties getProperties() {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.marklogic.gradle.task.forests
2+
3+
import com.marklogic.appdeployer.AppConfig
4+
import com.marklogic.appdeployer.command.databases.DeployContentDatabasesCommand
5+
import com.marklogic.appdeployer.command.databases.DeployDatabaseCommand
6+
import com.marklogic.appdeployer.command.databases.DeploySchemasDatabaseCommand
7+
import com.marklogic.appdeployer.command.databases.DeployTriggersDatabaseCommand
8+
import com.marklogic.appdeployer.impl.SimpleAppDeployer
9+
import com.marklogic.gradle.task.MarkLogicTask
10+
import com.marklogic.mgmt.api.forest.Forest
11+
import org.gradle.api.tasks.TaskAction
12+
13+
class PrintForestPlanTask extends MarkLogicTask {
14+
15+
@TaskAction
16+
void printForestPlan() {
17+
if (!project.hasProperty("database")) {
18+
println "Please specify a database via the 'database' property"
19+
return
20+
}
21+
22+
String database = project.property("database")
23+
24+
/**
25+
* We unfortunately have to do a little work here to determine what command object to use based on the database
26+
* name. That's to account for the "special" stuff that's done for the content database (mlContentForestsPerHost)
27+
* and for the schema/triggers databases (those commands default to only having forests on one host).
28+
*/
29+
AppConfig appConfig = getAppConfig()
30+
SimpleAppDeployer appDeployer = getAppDeployer()
31+
DeployDatabaseCommand command
32+
if (database.equals(appConfig.getContentDatabaseName()) || database.equals(appConfig.getTestContentDatabaseName())) {
33+
command = appDeployer.getCommandOfType(DeployContentDatabasesCommand.class)
34+
} else if (database.equals(appConfig.getSchemasDatabaseName())) {
35+
command = appDeployer.getCommandOfType(DeploySchemasDatabaseCommand.class)
36+
} else if (database.equals(appConfig.getTriggersDatabaseName())) {
37+
command = appDeployer.getCommandOfType(DeployTriggersDatabaseCommand.class)
38+
} else {
39+
command = new DeployDatabaseCommand()
40+
}
41+
42+
/**
43+
* Now that we have a command, use it to build its command for deploying forests, and then use that to build
44+
* the list of forests that will be created.
45+
*/
46+
List<Forest> forests = command.buildDeployForestsCommand(database, getCommandContext()).buildForests(getCommandContext(), true)
47+
48+
49+
if (forests.isEmpty()) {
50+
println "\nNo primary forests will be created the next time the database '" + database + "' is deployed; this is likely because it already has all of the primary desired forests based on the configuration settings."
51+
println "\nIf replicas have been configured for the database - e.g. via mlDatabaseNamesAndReplicaCounts - and these do not exist yet, " +
52+
"then replicas will be created the next time either the mlDeploy task or mlConfigureForestReplicas task is run."
53+
} else {
54+
for (Forest f : forests) {
55+
println f.getJson()
56+
}
57+
println "\nThe " + forests.size() + " forests (and replicas if applicable) that will be created the next time the database '" + database + "' is deployed (e.g. via the mlDeploy task) are listed above."
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)