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

Commit

Permalink
#362 Updating a task server now waits for a restart if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed May 22, 2019
1 parent d570dd2 commit 9b0311d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void execute(CommandContext context) {
logger.info("Processing file: " + f.getAbsolutePath());
}
String payload = copyFileToString(f, context);
mgr.updateTaskServer(taskServerName, payload);
mgr.updateTaskServer(taskServerName, payload, context.getAdminManager());
}
} else {
logResourceDirectoryNotFound(dir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.marklogic.mgmt.AbstractManager;
import com.marklogic.mgmt.ManageClient;
import com.marklogic.mgmt.admin.AdminManager;
import com.marklogic.rest.util.Fragment;
import org.springframework.http.ResponseEntity;

public class TaskServerManager extends AbstractManager {

Expand All @@ -12,12 +14,24 @@ public TaskServerManager(ManageClient manageClient) {
this.manageClient = manageClient;
}

public void updateTaskServer(String taskServerName, String payload) {
/**
*
* @param taskServerName
* @param payload
* @param adminManager required in the event that the update to the task server causes a restart
*/
public void updateTaskServer(String taskServerName, String payload, AdminManager adminManager) {
String path = format("/manage/v2/task-servers/%s/properties", taskServerName);

ResponseEntity<String> response;
if (payloadParser.isJsonPayload(payload)) {
manageClient.putJson(path, payload);
response = manageClient.putJson(path, payload);
} else {
manageClient.putXml(path, payload);
response = manageClient.putXml(path, payload);
}

if (response != null && response.getHeaders().getLocation() != null && adminManager != null) {
adminManager.waitForRestart();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.marklogic.appdeployer.command.taskservers;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.marklogic.appdeployer.AbstractAppDeployerTest;
import com.marklogic.mgmt.resource.taskservers.TaskServerManager;
import com.marklogic.mgmt.util.ObjectMapperFactory;
import com.marklogic.rest.util.Fragment;
import org.junit.Test;

Expand All @@ -10,6 +12,7 @@ public class UpdateTaskServerTest extends AbstractAppDeployerTest {
@Test
public void test() {
TaskServerManager mgr = new TaskServerManager(manageClient);
final int currentThreadCount = Integer.parseInt(mgr.getPropertiesAsXml().getElementValue("/node()/m:threads"));

initializeAppDeployer(new UpdateTaskServerCommand());
deploySampleApp();
Expand All @@ -20,13 +23,13 @@ public void test() {
assertEquals("false", xml.getElementValue("/m:task-server-properties/m:debug-allow"));
assertEquals("false", xml.getElementValue("/m:task-server-properties/m:profile-allow"));
} finally {
String payload = "{\n" +
"\t\"log-errors\": true,\n" +
"\t\"debug-allow\": true,\n" +
"\t\"profile-allow\": true\n" +
"}";
ObjectNode payload = ObjectMapperFactory.getObjectMapper().createObjectNode();
payload.put("threads", currentThreadCount);
payload.put("log-errors", true);
payload.put("debug-allow", true);
payload.put("profile-allow", true);
mgr.updateTaskServer("TaskServer", payload.toString(), adminManager);

mgr.updateTaskServer("TaskServer", payload);
Fragment xml = mgr.getPropertiesAsXml();
assertEquals("true", xml.getElementValue("/m:task-server-properties/m:log-errors"));
assertEquals("true", xml.getElementValue("/m:task-server-properties/m:debug-allow"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"threads": 32,
"log-errors": false,
"debug-allow": false,
"profile-allow": false
Expand Down

0 comments on commit 9b0311d

Please sign in to comment.