@@ -158,39 +158,6 @@ ext {
158158}
159159
160160
161- /*
162- * As of ML 8.0-3, triggers can not yet be managed via the Management REST API, so we still rely on a custom Gradle task
163- * that uses XCC to create the trigger. With 8.0-4, you should not use this approach - triggers can instead be defined under src/main/ml-config/triggers.
164- */
165- task createSampleTrigger (type : com.marklogic.gradle.task.trigger.CreateTriggersTask ) {
166- xccUrl = contentXccUrl
167- triggerName = " sample-project-trigger"
168- description = " This is an example of creating a trigger"
169- dataEventCommit = " post"
170- dataEventScopeArgs = [" some-collection" ]
171- dataEventContentArgs = [" create" , " modify" , " delete" ]
172- moduleRoot = " /"
173- modulePath = " /ext/sample-project/trigger/sample-trigger.xqy"
174- }
175-
176-
177- /*
178- * Example of attaching the creation of our trigger to the end of the mlDeploy process. mlPostDeploy is an empty task
179- * that is called by mlDeploy after mlAppDeploy runs; mlPostDeploy thus allows for any additional tasks to be added to
180- * the deployment process.
181- */
182- mlPostDeploy. dependsOn createSampleTrigger
183-
184-
185- /*
186- * Example of including a custom command in the deployment process. The order in which it's invoked is determined by
187- * the command's "getExecuteSortOrder" method.
188- */
189- ext {
190- mlAppDeployer. commands. add(new ClearTriggersDatabaseCommand ())
191- }
192-
193-
194161/*
195162 * ml-gradle does not blindly process every file in the ml-config/databases directory. It checks for specific files
196163 * for a content database, a schemas database, and a triggers database. There are specific commands for each file, and
@@ -214,38 +181,54 @@ ext {
214181
215182
216183/*
217- * Below is an example of a custom command, which also fixes a bug in ML that should be fixed in the 8.0-4 release. The
218- * bug is - when a pipeline is updated via the Management REST API, pipeline states are dropped. To address this, we
219- * insert a command to clear the triggers database before any CPF resources are created, thus forcing a create instead
220- * of an update, thereby bypassing the bug. This example also shows how the ManageClient instance in CommandContext can
221- * be used to easily make any call to the Management REST API. Note that this class could also be defined in the Gradle
222- * buildSrc directory, which is really a better option for keeping your build.gradle file slim.
184+ * Example of a custom command, which in this case performs a merge on a database. The benefit of doing this in a
185+ * command (as opposed to a task) is that a command can be included in the mlDeploy and mlUndeploy tasks by adding it to
186+ * the mlAppDeployer object, as shown below.
187+ *
188+ * This example also shows how the ManageClient instance in CommandContext can be used to easily make any call to the
189+ * Management REST API. Note that this class could also be defined in the Gradle buildSrc directory, which is really a
190+ * better option for keeping your build.gradle file slim.
223191 */
224192import com.marklogic.appdeployer.command.AbstractCommand ;
225193import com.marklogic.appdeployer.command.CommandContext ;
226- import com.marklogic.appdeployer.command.SortOrderConstants ;
227194
228- class ClearTriggersDatabaseCommand extends AbstractCommand {
195+ class MergeContentDatabaseCommand extends AbstractCommand {
229196 public Integer getExecuteSortOrder () {
230- return SortOrderConstants . DEPLOY_DEFAULT_PIPELINES - 1 ;
197+ return Integer . MAX_VALUE ;
231198 }
232199 public void execute (CommandContext context ) {
233- String dbName = context. getAppConfig(). getTriggersDatabaseName ();
234- logger. info(" Clearing database: " + dbName);
235- context. getManageClient(). postJson(" /manage/v2/databases/" + dbName, ' {"operation":"clear -database"}' );
236- logger. info(" Cleared database: " + dbName)
200+ String dbName = context. getAppConfig(). getContentDatabaseName ();
201+ logger. info(" Merging database: " + dbName);
202+ context. getManageClient(). postJson(" /manage/v2/databases/" + dbName, ' {"operation":"merge -database"}' );
203+ logger. info(" Merged database: " + dbName)
237204 }
238205}
239206
240207
241208/*
242- * Sometimes, you need a custom step, but you want it to be a separate task - not a command that's included when
243- * mlDeploy is invoked. Below is a task that extends MarkLogicTask, which provides access to a number of helpful
244- * objects for implementing custom functionality.
209+ * Example of including our custom command in the deployment process. The order in which it's invoked is determined by
210+ * the command's "getExecuteSortOrder" method.
211+ */
212+ ext {
213+ // mlAppDeployer.commands.add(new MergeContentDatabaseCommand())
214+ }
215+
216+
217+ /*
218+ * Below is an example of a custom task that merges a database - just like the command above. The benefit of creating a
219+ * task versus a command is that we can invoke this without running a full mlDeploy. The MarkLogicTask class provides
220+ * access to a number of helpful objects via methods like getAppConfig() and getManageClient().
245221 */
246222task mergeContentDatabase (type : com.marklogic.gradle.task.MarkLogicTask ) {
247223 description = " Call this task to initiate a merge on the content database"
248224 doLast {
249225 getManageClient(). postJson(" /manage/v2/databases/" + getAppConfig(). getContentDatabaseName(), ' {"operation":"merge-database"}' )
250226 }
251227}
228+
229+ /*
230+ * Example of attaching our custom task to the end of the mlDeploy process. mlPostDeploy is an empty task
231+ * that is called by mlDeploy after mlAppDeploy runs; mlPostDeploy thus allows for any additional tasks to be added to
232+ * the deployment process.
233+ */
234+ // mlPostDeploy.dependsOn mergeContentDatabase
0 commit comments