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

Commit 7340929

Browse files
committed
#304 Only supporting a list of default servers to not undeploy
1 parent 4b9e863 commit 7340929

File tree

8 files changed

+44
-62
lines changed

8 files changed

+44
-62
lines changed

src/main/java/com/marklogic/appdeployer/AppConfig.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ public class AppConfig {
222222

223223
private boolean updateMimetypeWhenPropertiesAreEqual = false;
224224

225-
private String[] serversToNotUndeploy;
226-
227225
private Map<String, Object> additionalProperties = new HashMap<>();
228226

229227
public AppConfig() {
@@ -1258,12 +1256,4 @@ public X509TrustManager getAppServicesTrustManager() {
12581256
public void setAppServicesTrustManager(X509TrustManager appServicesTrustManager) {
12591257
this.appServicesTrustManager = appServicesTrustManager;
12601258
}
1261-
1262-
public String[] getServersToNotUndeploy() {
1263-
return serversToNotUndeploy;
1264-
}
1265-
1266-
public void setServersToNotUndeploy(String... serversToNotUndeploy) {
1267-
this.serversToNotUndeploy = serversToNotUndeploy;
1268-
}
12691259
}

src/main/java/com/marklogic/appdeployer/DefaultAppConfigFactory.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,6 @@ public void initialize() {
635635
logger.info("Update mimetype when properties are equal (defaults to false to avoid unnecessary ML restarts): " + prop);
636636
config.setUpdateMimetypeWhenPropertiesAreEqual(Boolean.parseBoolean(prop));
637637
});
638-
639-
propertyConsumerMap.put("mlServersToNotUndeploy", (config, prop) -> {
640-
String[] values = prop.split(",");
641-
logger.info("Servers that will not be undeployed: " + Arrays.asList(values));
642-
config.setServersToNotUndeploy(values);
643-
});
644638
}
645639

646640
@Override

src/main/java/com/marklogic/appdeployer/command/appservers/DeployOtherServersCommand.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,17 @@ protected ResourceManager adjustResourceManagerForPayload(ResourceManager mgr, C
7878
@Override
7979
protected String adjustPayloadBeforeDeletingResource(ResourceManager mgr, CommandContext context, File f, String payload) {
8080
String serverName = new PayloadParser().getPayloadFieldValue(payload, "server-name", false);
81-
if (serverName != null) {
82-
if (!shouldUndeployServer(serverName, context)) {
83-
logger.info(format("Not undeploying server %s because it's in the list of server names to not undeploy", serverName));
84-
return null;
85-
}
81+
82+
if (serverName != null && !shouldUndeployServer(serverName, context)) {
83+
logger.info(format("Not undeploying server %s because it's in the list of server names to not undeploy", serverName));
84+
return null;
8685
}
8786

8887
return super.adjustPayloadBeforeDeletingResource(mgr, context, f, payload);
8988
}
9089

9190
public boolean shouldUndeployServer(String serverName, CommandContext context) {
92-
if (defaultServersToNotUndeploy != null && defaultServersToNotUndeploy.contains(serverName)) {
93-
return false;
94-
}
95-
96-
String[] names = null;
97-
if (context != null && context.getAppConfig() != null) {
98-
names = context.getAppConfig().getServersToNotUndeploy();
99-
}
100-
return names != null ? !Arrays.asList(names).contains(serverName) : true;
91+
return defaultServersToNotUndeploy == null || !defaultServersToNotUndeploy.contains(serverName);
10192
}
10293

10394
public Set<String> getDefaultServersToNotUndeploy() {

src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ public void allProperties() {
199199

200200
p.setProperty("mlUpdateMimetypeWhenPropertiesAreEqual", "true");
201201

202-
p.setProperty("mlServersToNotUndeploy", "server1,server2");
203-
204202
sut = new DefaultAppConfigFactory(new SimplePropertySource(p));
205203
AppConfig config = sut.newAppConfig();
206204

@@ -350,10 +348,6 @@ public void allProperties() {
350348
assertEquals("other-group", map.get("host2"));
351349

352350
assertTrue(config.isUpdateMimetypeWhenPropertiesAreEqual());
353-
354-
assertEquals(2, config.getServersToNotUndeploy().length);
355-
assertEquals("server1", config.getServersToNotUndeploy()[0]);
356-
assertEquals("server2", config.getServersToNotUndeploy()[1]);
357351
}
358352

359353
/**

src/test/java/com/marklogic/appdeployer/command/databases/DontUndeployDefaultDatabasesTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.Test;
77

88
import java.io.File;
9+
import java.util.Set;
910

1011
public class DontUndeployDefaultDatabasesTest extends AbstractAppDeployerTest {
1112

@@ -26,4 +27,21 @@ public void test() {
2627
assertFalse(mgr.exists(appConfig.getContentDatabaseName()));
2728
assertTrue(mgr.exists("Fab"));
2829
}
30+
31+
@Test
32+
public void verifyDatabasesToNotUndeploy() {
33+
DeployOtherDatabasesCommand c = new DeployOtherDatabasesCommand();
34+
Set<String> set = c.getDefaultDatabasesToNotUndeploy();
35+
assertTrue(set.contains("App-Services"));
36+
assertTrue(set.contains("Documents"));
37+
assertTrue(set.contains("Extensions"));
38+
assertTrue(set.contains("Fab"));
39+
assertTrue(set.contains("Last-Login"));
40+
assertTrue(set.contains("Meters"));
41+
assertTrue(set.contains("Modules"));
42+
assertTrue(set.contains("Schemas"));
43+
assertTrue(set.contains("Security"));
44+
assertTrue(set.contains("Triggers"));
45+
assertEquals(10, set.size());
46+
}
2947
}
Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.marklogic.appdeployer.command.servers;
22

33
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4-
import com.marklogic.appdeployer.AppConfig;
54
import com.marklogic.appdeployer.ConfigDir;
6-
import com.marklogic.appdeployer.command.CommandContext;
75
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
86
import com.marklogic.mgmt.resource.appservers.ServerManager;
97
import org.junit.Test;
@@ -12,55 +10,39 @@
1210
import java.util.HashSet;
1311
import java.util.Set;
1412

15-
public class DontUndeploySpecificServersTest extends AbstractAppDeployerTest {
13+
public class DontUndeployDefaultServersTest extends AbstractAppDeployerTest {
1614

1715
@Test
1816
public void test() {
19-
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/sample-app/other-servers")));
17+
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/sample-app/default-servers")));
2018

2119
ServerManager mgr = new ServerManager(manageClient);
2220

2321
DeployOtherServersCommand c = new DeployOtherServersCommand();
2422
initializeAppDeployer(c);
2523

26-
appConfig.getCustomTokens().put("%%ODBC_PORT%%", "8048");
2724
appConfig.getCustomTokens().put("%%XDBC_PORT%%", "8049");
25+
2826
deploySampleApp();
2927

30-
try {
31-
assertTrue(mgr.exists("sample-app-xdbc"));
32-
assertTrue(mgr.exists("sample-app-odbc"));
28+
assertTrue(mgr.exists("sample-app-xdbc"));
29+
assertTrue(mgr.exists("Manage"));
3330

34-
appConfig.setServersToNotUndeploy("sample-app-xdbc", "sample-app-odbc");
35-
undeploySampleApp();
36-
assertTrue(mgr.exists("sample-app-xdbc"));
37-
assertTrue(mgr.exists("sample-app-odbc"));
38-
} finally {
39-
appConfig.setServersToNotUndeploy(null);
40-
undeploySampleApp();
41-
assertFalse(mgr.exists("sample-app-xdbc"));
42-
assertFalse(mgr.exists("sample-app-odbc"));
43-
}
31+
undeploySampleApp();
32+
assertFalse(mgr.exists("sample-app-xdbc"));
33+
assertTrue(mgr.exists("Manage"));
4434
}
4535

4636
@Test
4737
public void unitTestShouldUndeployServer() {
4838
DeployOtherServersCommand c = new DeployOtherServersCommand();
4939

50-
AppConfig appConfig = new AppConfig();
51-
CommandContext context = new CommandContext(appConfig, null, null);
52-
5340
// These should all be not-undeployed by default
5441
assertFalse(c.shouldUndeployServer("Admin", null));
5542
assertFalse(c.shouldUndeployServer("App-Services", null));
5643
assertFalse(c.shouldUndeployServer("HealthCheck", null));
5744
assertFalse(c.shouldUndeployServer("Manage", null));
5845

59-
appConfig.setServersToNotUndeploy("server1", "server2");
60-
assertFalse(c.shouldUndeployServer("server1", context));
61-
assertFalse(c.shouldUndeployServer("server2", context));
62-
assertTrue(c.shouldUndeployServer("server3", context));
63-
6446
Set<String> customDefaultServersNotToUndeploy = new HashSet<>();
6547
customDefaultServersNotToUndeploy.add("Admin");
6648
customDefaultServersNotToUndeploy.add("TestServer");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"server-name": "Manage",
3+
"server-type": "http"
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"server-name": "%%NAME%%-xdbc",
3+
"server-type": "xdbc",
4+
"root": "/",
5+
"group-name": "%%GROUP%%",
6+
"port": %%XDBC_PORT%%,
7+
"modules-database": "Modules",
8+
"content-database": "Documents"
9+
}

0 commit comments

Comments
 (0)