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

Commit c0dfb40

Browse files
committed
#90 Can now set updates-allowed easily on a database
1 parent d019a7c commit c0dfb40

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/main/java/com/marklogic/mgmt/databases/DatabaseManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ public void deleteReplicaForests(String databaseNameOrId) {
6868
logger.info(format("Finished deleting replica forests for database %s", databaseNameOrId));
6969
}
7070

71+
/**
72+
* TODO Not sure, when setting updates-allowed on primary forests, if replica forests need to have their
73+
* updates-allowed set as well.
74+
*
75+
* @param databaseNameOrId
76+
*/
77+
public void setUpdatesAllowedOnPrimaryForests(String databaseNameOrId, String mode) {
78+
ForestManager mgr = new ForestManager(getManageClient());
79+
for (String forestId : getPrimaryForestIds(databaseNameOrId)) {
80+
mgr.setUpdatesAllowed(forestId, mode);
81+
}
82+
}
83+
7184
@Override
7285
protected String[] getDeleteResourceParams(String payload) {
7386
return forestDelete != null ? new String[] { "forest-delete", forestDelete } : new String[] {};

src/main/java/com/marklogic/mgmt/forests/ForestManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public ForestStatus getForestStatus(String forestIdOrName) {
144144
return new ForestStatus(getManageClient().getXml(path));
145145
}
146146

147+
public void setUpdatesAllowed(String forestIdOrName, String mode) {
148+
String path = getPropertiesPath(forestIdOrName);
149+
String json = format("{\"updates-allowed\":\"%s\"}", mode);
150+
getManageClient().putJson(path, json);
151+
}
152+
147153
@Override
148154
protected String[] getDeleteResourceParams(String payload) {
149155
return this.deleteLevel != null ? new String[] { "level", deleteLevel } : null;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.marklogic.appdeployer.command.databases;
2+
3+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.mgmt.databases.DatabaseManager;
5+
import com.marklogic.mgmt.forests.ForestManager;
6+
import org.junit.After;
7+
import org.junit.Test;
8+
9+
import java.io.File;
10+
11+
/**
12+
* Doesn't actually use a command, but it's nice to extend the parent test class.
13+
*/
14+
public class SetUpdatesAllowedOnDatabaseForestsTest extends AbstractAppDeployerTest {
15+
16+
@After
17+
public void teardown() {
18+
undeploySampleApp();
19+
}
20+
21+
@Test
22+
public void test() {
23+
appConfig.getConfigDir().setBaseDir(new File("src/test/resources/sample-app/db-only-config"));
24+
initializeAppDeployer(new DeployContentDatabasesCommand(2));
25+
appDeployer.deploy(appConfig);
26+
27+
DatabaseManager dbMgr = new DatabaseManager(this.manageClient);
28+
dbMgr.setUpdatesAllowedOnPrimaryForests(appConfig.getContentDatabaseName(), "flash-backup");
29+
30+
ForestManager forestMgr = new ForestManager(this.manageClient);
31+
assertEquals("flash-backup", forestMgr.getPropertiesAsXml("sample-app-content-1").getElementValue("//m:updates-allowed"));
32+
assertEquals("flash-backup", forestMgr.getPropertiesAsXml("sample-app-content-2").getElementValue("//m:updates-allowed"));
33+
34+
// Gotta set it back to all so the database/forests can be deleted
35+
dbMgr.setUpdatesAllowedOnPrimaryForests(appConfig.getContentDatabaseName(), "all");
36+
}
37+
}

0 commit comments

Comments
 (0)