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

Commit 9e2a988

Browse files
committed
#240 Server existence check includes group name
updated test
1 parent 8f34412 commit 9e2a988

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

src/main/java/com/marklogic/mgmt/resource/appservers/ServerManager.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.marklogic.mgmt.resource.AbstractResourceManager;
44
import com.marklogic.mgmt.ManageClient;
5+
import com.marklogic.rest.util.Fragment;
6+
import com.marklogic.rest.util.ResourcesFragment;
57

68
public class ServerManager extends AbstractResourceManager {
79

@@ -18,7 +20,25 @@ public ServerManager(ManageClient manageClient, String groupName) {
1820
this.groupName = groupName != null ? groupName : DEFAULT_GROUP;
1921
}
2022

21-
@Override
23+
/**
24+
* When doing an existence check, have to take the group name into account.
25+
*
26+
* @param resourceNameOrId
27+
* @param resourceUrlParams
28+
* @return
29+
*/
30+
@Override
31+
public boolean exists(String resourceNameOrId, String... resourceUrlParams) {
32+
String path = getResourcesPath();
33+
if (groupName != null) {
34+
path += "?group-id=" + groupName;
35+
}
36+
Fragment f = useSecurityUser() ? getManageClient().getXmlAsSecurityUser(path)
37+
: getManageClient().getXml(path);
38+
return new ResourcesFragment(f).resourceExists(resourceNameOrId);
39+
}
40+
41+
@Override
2242
public String getResourcePath(String resourceNameOrId, String... resourceUrlParams) {
2343
return format("%s/%s?group-id=%s", getResourcesPath(), resourceNameOrId, groupName);
2444
}

src/test/java/com/marklogic/appdeployer/command/servers/UpdateServerInOtherGroupTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,37 @@
1212

1313
public class UpdateServerInOtherGroupTest extends AbstractAppDeployerTest {
1414

15+
/**
16+
* Creates two servers with the same name, one in Default and one in the other group.
17+
*/
1518
@Test
1619
public void test() {
1720
appConfig.setConfigDir(new ConfigDir(new File("src/test/resources/sample-app/other-group")));
1821

1922
appConfig.setGroupName("Default");
2023

2124
final String otherGroup = "sample-app-other-group";
22-
final String otherServer = "sample-app-other-server";
25+
final String serverName = "sample-app-other-server";
2326

2427
GroupManager groupManager = new GroupManager(manageClient);
25-
ServerManager serverManager = new ServerManager(manageClient);
28+
ServerManager defaultServerManager = new ServerManager(manageClient);
29+
ServerManager otherServerManager = new ServerManager(manageClient, otherGroup);
2630

2731
initializeAppDeployer(new DeployGroupsCommand(), new DeployOtherServersCommand());
2832

2933
try {
3034
deploySampleApp();
3135

3236
assertTrue(groupManager.exists(otherGroup));
33-
assertTrue(serverManager.exists(otherServer));
37+
assertTrue(defaultServerManager.exists(serverName));
38+
assertTrue(otherServerManager.exists(serverName));
3439

3540
// Now deploy it again, verifying no errors - i.e. that the other group name is included correctly in the call to update the server
3641
deploySampleApp();
3742

3843
assertTrue(groupManager.exists(otherGroup));
39-
assertTrue(serverManager.exists(otherServer));
44+
assertTrue(defaultServerManager.exists(serverName));
45+
assertTrue(otherServerManager.exists(serverName));
4046

4147
} finally {
4248
undeploySampleApp();

src/test/java/com/marklogic/appdeployer/export/ExportServerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public void serverInOtherGroup() {
5353
deploySampleApp();
5454

5555
assertTrue(new GroupManager(manageClient).exists(groupName));
56-
assertTrue(new ServerManager(manageClient).exists(serverName));
56+
57+
assertTrue(new ServerManager(manageClient, groupName).exists(serverName));
58+
assertFalse(new ServerManager(manageClient, "Default").exists(serverName));
5759
}
5860
}

src/test/resources/sample-app/other-group/servers/http-server.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"server-name": "sample-app-other-server",
33
"server-type": "http",
44
"root": "/",
5-
"group-name": "sample-app-other-group",
5+
"group-name": "Default",
66
"port": 8048,
77
"modules-database": "Modules",
88
"content-database": "Documents"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"server-name": "sample-app-other-server",
3+
"server-type": "http",
4+
"root": "/",
5+
"group-name": "sample-app-other-group",
6+
"port": 8049,
7+
"modules-database": "Modules",
8+
"content-database": "Documents"
9+
}

0 commit comments

Comments
 (0)