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

Commit dc321a0

Browse files
committed
#212 Can now update the task server
1 parent fd6faa5 commit dc321a0

File tree

7 files changed

+125
-0
lines changed

7 files changed

+125
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public File getTasksDir() {
156156
return new File(baseDir, "tasks");
157157
}
158158

159+
public File getTaskServersDir() {
160+
return new File(baseDir, "task-servers");
161+
}
162+
159163
public void setDatabasesPath(String databasesPath) {
160164
this.databasesPath = databasesPath;
161165
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.marklogic.appdeployer.command.schemas.LoadSchemasCommand;
2727
import com.marklogic.appdeployer.command.security.*;
2828
import com.marklogic.appdeployer.command.tasks.DeployScheduledTasksCommand;
29+
import com.marklogic.appdeployer.command.taskservers.UpdateTaskServerCommand;
2930
import com.marklogic.appdeployer.command.temporal.DeployTemporalAxesCommand;
3031
import com.marklogic.appdeployer.command.temporal.DeployTemporalCollectionsCommand;
3132
import com.marklogic.appdeployer.command.temporal.DeployTemporalCollectionsLSQTCommand;
@@ -140,6 +141,7 @@ public Map<String, List<Command>> buildCommandMap() {
140141
// Tasks
141142
List<Command> taskCommands = new ArrayList<Command>();
142143
taskCommands.add(new DeployScheduledTasksCommand());
144+
taskCommands.add(new UpdateTaskServerCommand());
143145
map.put("mlTaskCommands", taskCommands);
144146

145147
// Temporal

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public abstract class SortOrderConstants {
4646
public static Integer DEPLOY_TEMPORAL_COLLECTIONS_LSQT = 752;
4747

4848
public static Integer DEPLOY_SCHEDULED_TASKS = 800;
49+
public static Integer UPDATE_TASK_SERVER = 810;
4950

5051
public static Integer DEPLOY_DEFAULT_PIPELINES = 900;
5152
public static Integer DEPLOY_PIPELINES = 905;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.marklogic.appdeployer.command.taskservers;
2+
3+
import com.marklogic.appdeployer.command.AbstractCommand;
4+
import com.marklogic.appdeployer.command.CommandContext;
5+
import com.marklogic.appdeployer.command.SortOrderConstants;
6+
import com.marklogic.mgmt.resource.taskservers.TaskServerManager;
7+
8+
import java.io.File;
9+
10+
/**
11+
* As of ML 9.0-3, the Manage API only supports a PUT call to update the single task server within a cluster.
12+
* <p>
13+
* In addition, the single task server is named "TaskServer" and there's no apparent way to change that. So this
14+
* command assumes that name as well.
15+
*/
16+
public class UpdateTaskServerCommand extends AbstractCommand {
17+
18+
private String taskServerName = "TaskServer";
19+
20+
public UpdateTaskServerCommand() {
21+
setExecuteSortOrder(SortOrderConstants.UPDATE_TASK_SERVER);
22+
}
23+
24+
@Override
25+
public void execute(CommandContext context) {
26+
File dir = context.getAppConfig().getConfigDir().getTaskServersDir();
27+
if (dir.exists()) {
28+
if (logger.isInfoEnabled()) {
29+
logger.info("Processing files in directory: " + dir.getAbsolutePath());
30+
}
31+
32+
TaskServerManager mgr = new TaskServerManager(context.getManageClient());
33+
for (File f : listFilesInDirectory(dir)) {
34+
if (logger.isInfoEnabled()) {
35+
logger.info("Processing file: " + f.getAbsolutePath());
36+
}
37+
String payload = copyFileToString(f, context);
38+
mgr.updateTaskServer(taskServerName, payload);
39+
}
40+
}
41+
}
42+
43+
public void setTaskServerName(String taskServerName) {
44+
this.taskServerName = taskServerName;
45+
}
46+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.marklogic.mgmt.resource.taskservers;
2+
3+
import com.marklogic.mgmt.AbstractManager;
4+
import com.marklogic.mgmt.ManageClient;
5+
import com.marklogic.rest.util.Fragment;
6+
7+
public class TaskServerManager extends AbstractManager {
8+
9+
private ManageClient manageClient;
10+
11+
public TaskServerManager(ManageClient manageClient) {
12+
this.manageClient = manageClient;
13+
}
14+
15+
public void updateTaskServer(String taskServerName, String payload) {
16+
String path = format("/manage/v2/task-servers/%s/properties", taskServerName);
17+
if (payloadParser.isJsonPayload(payload)) {
18+
manageClient.putJson(path, payload);
19+
} else {
20+
manageClient.putXml(path, payload);
21+
}
22+
}
23+
24+
public Fragment getPropertiesAsXml() {
25+
return getPropertiesAsXml("TaskServer");
26+
}
27+
28+
public Fragment getPropertiesAsXml(String taskServerName) {
29+
return manageClient.getXml(format("/manage/v2/task-servers/%s/properties", taskServerName));
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.marklogic.appdeployer.command.taskservers;
2+
3+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.mgmt.resource.taskservers.TaskServerManager;
5+
import com.marklogic.rest.util.Fragment;
6+
import org.junit.Test;
7+
8+
public class UpdateTaskServerTest extends AbstractAppDeployerTest {
9+
10+
@Test
11+
public void test() {
12+
TaskServerManager mgr = new TaskServerManager(manageClient);
13+
14+
initializeAppDeployer(new UpdateTaskServerCommand());
15+
deploySampleApp();
16+
17+
try {
18+
Fragment xml = mgr.getPropertiesAsXml();
19+
assertEquals("false", xml.getElementValue("/m:task-server-properties/m:log-errors"));
20+
assertEquals("false", xml.getElementValue("/m:task-server-properties/m:debug-allow"));
21+
assertEquals("false", xml.getElementValue("/m:task-server-properties/m:profile-allow"));
22+
} finally {
23+
String payload = "{\n" +
24+
"\t\"log-errors\": true,\n" +
25+
"\t\"debug-allow\": true,\n" +
26+
"\t\"profile-allow\": true\n" +
27+
"}";
28+
29+
mgr.updateTaskServer("TaskServer", payload);
30+
Fragment xml = mgr.getPropertiesAsXml();
31+
assertEquals("true", xml.getElementValue("/m:task-server-properties/m:log-errors"));
32+
assertEquals("true", xml.getElementValue("/m:task-server-properties/m:debug-allow"));
33+
assertEquals("true", xml.getElementValue("/m:task-server-properties/m:profile-allow"));
34+
}
35+
}
36+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"log-errors": false,
3+
"debug-allow": false,
4+
"profile-allow": false
5+
}

0 commit comments

Comments
 (0)