Skip to content

Commit

Permalink
#167 Waiting for restart if appserver forces one
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Jun 19, 2017
1 parent 782f0bb commit b66ea0c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import com.marklogic.mgmt.ResourceManager;
import com.marklogic.mgmt.SaveReceipt;
import com.marklogic.mgmt.admin.ActionRequiringRestart;
import com.marklogic.mgmt.admin.AdminManager;
import org.springframework.http.ResponseEntity;

import java.io.File;
import java.net.URI;

/**
* Provides a basic implementation for creating/updating a resource while an app is being deployed and then deleting it
Expand Down Expand Up @@ -46,14 +51,26 @@ protected void processExecuteOnResourceDir(CommandContext context, File resource
/**
* Subclasses can override this to add functionality after a resource has been saved.
*
* Starting in version 3.0 of ml-app-deployer, this will always check if the Location header is
* /admin/v1/timestamp, and if so, it will wait for ML to restart.
*
* @param mgr
* @param context
* @param resourceFile
* @param receipt
*/
protected void afterResourceSaved(ResourceManager mgr, CommandContext context, File resourceFile,
SaveReceipt receipt) {

ResponseEntity<String> response = receipt.getResponse();
URI uri = response.getHeaders().getLocation();
if (uri != null && "/admin/v1/timestamp".equals(uri.getPath())) {
AdminManager adminManager = context.getAdminManager();
if (adminManager != null) {
adminManager.waitForRestart();
} else {
logger.warn("Location header indicates ML is restarting, but no AdminManager available to support waiting for a restart");
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.marklogic.appdeployer.command.servers;

import com.marklogic.appdeployer.AbstractAppDeployerTest;
import com.marklogic.appdeployer.ConfigDir;
import com.marklogic.appdeployer.command.appservers.DeployOtherServersCommand;
import com.marklogic.mgmt.appservers.ServerManager;
import org.junit.After;
import org.junit.Test;

import java.io.File;

public class WaitForRestartWhenUpdatingServerTest extends AbstractAppDeployerTest {

@After
public void tearDown() {
undeploySampleApp();
}

@Test
public void test() {
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/sample-app/single-server")));
ServerManager mgr = new ServerManager(manageClient);
initializeAppDeployer(new DeployOtherServersCommand());
appConfig.getCustomTokens().put("%%HTTP_PORT%%", "8048");
appDeployer.deploy(appConfig);

// Now change the port, and then redeploy, and immediately deploy again to verify that the redeploy waits for
// ML to restart
appConfig.getCustomTokens().put("%%HTTP_PORT%%", "8049");
appDeployer.deploy(appConfig);
appDeployer.deploy(appConfig);

// Nothing to verify - the lack of an error means that the command waited for ML to restart
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"server-name": "%%NAME%%-http",
"server-type": "http",
"root": "/",
"group-name": "%%GROUP%%",
"port": %%HTTP_PORT%%,
"modules-database": "Modules",
"content-database": "Documents"
}

0 comments on commit b66ea0c

Please sign in to comment.