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

Commit b66ea0c

Browse files
committed
#167 Waiting for restart if appserver forces one
1 parent 782f0bb commit b66ea0c

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import com.marklogic.mgmt.ResourceManager;
66
import com.marklogic.mgmt.SaveReceipt;
77
import com.marklogic.mgmt.admin.ActionRequiringRestart;
8+
import com.marklogic.mgmt.admin.AdminManager;
9+
import org.springframework.http.ResponseEntity;
10+
11+
import java.io.File;
12+
import java.net.URI;
813

914
/**
1015
* Provides a basic implementation for creating/updating a resource while an app is being deployed and then deleting it
@@ -46,14 +51,26 @@ protected void processExecuteOnResourceDir(CommandContext context, File resource
4651
/**
4752
* Subclasses can override this to add functionality after a resource has been saved.
4853
*
54+
* Starting in version 3.0 of ml-app-deployer, this will always check if the Location header is
55+
* /admin/v1/timestamp, and if so, it will wait for ML to restart.
56+
*
4957
* @param mgr
5058
* @param context
5159
* @param resourceFile
5260
* @param receipt
5361
*/
5462
protected void afterResourceSaved(ResourceManager mgr, CommandContext context, File resourceFile,
5563
SaveReceipt receipt) {
56-
64+
ResponseEntity<String> response = receipt.getResponse();
65+
URI uri = response.getHeaders().getLocation();
66+
if (uri != null && "/admin/v1/timestamp".equals(uri.getPath())) {
67+
AdminManager adminManager = context.getAdminManager();
68+
if (adminManager != null) {
69+
adminManager.waitForRestart();
70+
} else {
71+
logger.warn("Location header indicates ML is restarting, but no AdminManager available to support waiting for a restart");
72+
}
73+
}
5774
}
5875

5976
@Override
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.marklogic.appdeployer.command.servers;
2+
3+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.appdeployer.ConfigDir;
5+
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
6+
import com.marklogic.mgmt.appservers.ServerManager;
7+
import org.junit.After;
8+
import org.junit.Test;
9+
10+
import java.io.File;
11+
12+
public class WaitForRestartWhenUpdatingServerTest extends AbstractAppDeployerTest {
13+
14+
@After
15+
public void tearDown() {
16+
undeploySampleApp();
17+
}
18+
19+
@Test
20+
public void test() {
21+
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/sample-app/single-server")));
22+
ServerManager mgr = new ServerManager(manageClient);
23+
initializeAppDeployer(new DeployOtherServersCommand());
24+
appConfig.getCustomTokens().put("%%HTTP_PORT%%", "8048");
25+
appDeployer.deploy(appConfig);
26+
27+
// Now change the port, and then redeploy, and immediately deploy again to verify that the redeploy waits for
28+
// ML to restart
29+
appConfig.getCustomTokens().put("%%HTTP_PORT%%", "8049");
30+
appDeployer.deploy(appConfig);
31+
appDeployer.deploy(appConfig);
32+
33+
// Nothing to verify - the lack of an error means that the command waited for ML to restart
34+
}
35+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"server-name": "%%NAME%%-http",
3+
"server-type": "http",
4+
"root": "/",
5+
"group-name": "%%GROUP%%",
6+
"port": %%HTTP_PORT%%,
7+
"modules-database": "Modules",
8+
"content-database": "Documents"
9+
}

0 commit comments

Comments
 (0)