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

Commit 551ce51

Browse files
committed
Added test for deleting multiple "other" servers at once, and added exception handling for intermittent error
1 parent aa7af90 commit 551ce51

File tree

5 files changed

+81
-15
lines changed

5 files changed

+81
-15
lines changed

src/main/java/com/marklogic/appdeployer/command/AbstractResourceCommand.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public abstract class AbstractResourceCommand extends AbstractUndoableCommand {
1414

1515
private boolean deleteResourcesOnUndo = true;
1616
private boolean restartAfterDelete = false;
17+
private boolean catchExceptionOnDeleteFailure = false;
1718

1819
protected abstract File[] getResourceDirs(CommandContext context);
1920

@@ -71,17 +72,38 @@ public void undo(CommandContext context) {
7172
}
7273
}
7374

75+
/**
76+
* If catchExceptionOnDeleteFailure is set to true, this will catch and log any exception that occurs when trying to
77+
* delete the resource. This has been necessary when deleting two app servers in a row - for some reason, the 2nd
78+
* delete will intermittently fail with a connection reset error, but the app server is in fact deleted
79+
* successfully.
80+
*
81+
* @param mgr
82+
* @param context
83+
* @param f
84+
*/
7485
protected void deleteResource(final ResourceManager mgr, CommandContext context, File f) {
7586
final String payload = tokenReplacer.replaceTokens(copyFileToString(f), context.getAppConfig(), false);
76-
if (restartAfterDelete) {
77-
context.getAdminManager().invokeActionRequiringRestart(new ActionRequiringRestart() {
78-
@Override
79-
public boolean execute() {
80-
return mgr.delete(payload).isDeleted();
87+
try {
88+
if (restartAfterDelete) {
89+
context.getAdminManager().invokeActionRequiringRestart(new ActionRequiringRestart() {
90+
@Override
91+
public boolean execute() {
92+
return mgr.delete(payload).isDeleted();
93+
}
94+
});
95+
} else {
96+
mgr.delete(payload);
97+
}
98+
} catch (RuntimeException e) {
99+
if (catchExceptionOnDeleteFailure) {
100+
logger.warn("Caught exception while trying to delete resource; cause: " + e.getMessage());
101+
if (restartAfterDelete) {
102+
context.getAdminManager().waitForRestart();
81103
}
82-
});
83-
} else {
84-
mgr.delete(payload);
104+
} else {
105+
throw e;
106+
}
85107
}
86108
}
87109

@@ -100,4 +122,8 @@ public boolean isDeleteResourcesOnUndo() {
100122
public boolean isRestartAfterDelete() {
101123
return restartAfterDelete;
102124
}
125+
126+
public void setCatchExceptionOnDeleteFailure(boolean catchExceptionOnDeleteFailure) {
127+
this.catchExceptionOnDeleteFailure = catchExceptionOnDeleteFailure;
128+
}
103129
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public DeployOtherServersCommand() {
1919
setExecuteSortOrder(SortOrderConstants.DEPLOY_OTHER_SERVERS);
2020
setUndoSortOrder(SortOrderConstants.DELETE_OTHER_SERVERS);
2121
setRestartAfterDelete(true);
22+
setCatchExceptionOnDeleteFailure(true);
2223
setResourceFilenameFilter(new ResourceFilenameFilter() {
2324
@Override
2425
public boolean accept(File dir, String name) {
Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,53 @@
11
package com.marklogic.appdeployer.command.servers;
22

3-
import org.junit.After;
3+
import java.io.File;
4+
45
import org.junit.Test;
56

67
import com.marklogic.appdeployer.AbstractAppDeployerTest;
8+
import com.marklogic.appdeployer.ConfigDir;
79
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
810
import com.marklogic.appdeployer.command.databases.DeployContentDatabasesCommand;
911
import com.marklogic.appdeployer.command.databases.DeploySchemasDatabaseCommand;
1012
import com.marklogic.appdeployer.command.databases.DeployTriggersDatabaseCommand;
13+
import com.marklogic.mgmt.appservers.ServerManager;
1114

1215
/**
13-
* Only purpose of this test so far is to ensure that we wait properly after deleting the server.
16+
* Main purpose of these tests is to ensure that we wait properly after deleting a server.
1417
*/
1518
public class ManageOtherServerTest extends AbstractAppDeployerTest {
1619

17-
@After
18-
public void teardown() {
19-
undeploySampleApp();
20-
}
21-
2220
@Test
2321
public void updateMainAndRestRestApiServers() {
2422
// Create some other databases that have to be deleted to ensure we wait for a restart after deleting the ODBC
2523
// server
2624
initializeAppDeployer(new DeployContentDatabasesCommand(1), new DeployTriggersDatabaseCommand(),
2725
new DeploySchemasDatabaseCommand(), new DeployOtherServersCommand());
2826
appConfig.getCustomTokens().put("%%ODBC_PORT%%", "8048");
27+
try {
28+
appDeployer.deploy(appConfig);
29+
} finally {
30+
appDeployer.undeploy(appConfig);
31+
}
32+
}
33+
34+
@Test
35+
public void odbcAndXdbcServers() {
36+
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/sample-app/other-servers")));
37+
38+
ServerManager mgr = new ServerManager(manageClient);
39+
40+
initializeAppDeployer(new DeployOtherServersCommand());
41+
appConfig.getCustomTokens().put("%%ODBC_PORT%%", "8048");
42+
appConfig.getCustomTokens().put("%%XDBC_PORT%%", "8049");
2943
appDeployer.deploy(appConfig);
3044

45+
assertTrue(mgr.exists("sample-app-xdbc"));
46+
assertTrue(mgr.exists("sample-app-odbc"));
47+
48+
appDeployer.undeploy(appConfig);
49+
50+
assertFalse(mgr.exists("sample-app-xdbc"));
51+
assertFalse(mgr.exists("sample-app-odbc"));
3152
}
3253
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"server-name": "%%NAME%%-odbc",
3+
"server-type": "odbc",
4+
"root": "/",
5+
"group-name": "%%GROUP%%",
6+
"port": %%ODBC_PORT%%,
7+
"modules-database": "Modules",
8+
"content-database": "Documents"
9+
}
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)