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

Commit

Permalink
#240 Server existence check includes group name
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Feb 8, 2018
1 parent 8f34412 commit 7d679df
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.marklogic.mgmt.resource.AbstractResourceManager;
import com.marklogic.mgmt.ManageClient;
import com.marklogic.rest.util.Fragment;
import com.marklogic.rest.util.ResourcesFragment;

public class ServerManager extends AbstractResourceManager {

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

@Override
/**
* When doing an existence check, have to take the group name into account.
*
* @param resourceNameOrId
* @param resourceUrlParams
* @return
*/
@Override
public boolean exists(String resourceNameOrId, String... resourceUrlParams) {
String path = getResourcesPath();
if (groupName != null) {
path += "?group-id=" + groupName;
}
Fragment f = useSecurityUser() ? getManageClient().getXmlAsSecurityUser(path)
: getManageClient().getXml(path);
return new ResourcesFragment(f).resourceExists(resourceNameOrId);
}

@Override
public String getResourcePath(String resourceNameOrId, String... resourceUrlParams) {
return format("%s/%s?group-id=%s", getResourcesPath(), resourceNameOrId, groupName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,37 @@

public class UpdateServerInOtherGroupTest extends AbstractAppDeployerTest {

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

appConfig.setGroupName("Default");

final String otherGroup = "sample-app-other-group";
final String otherServer = "sample-app-other-server";
final String serverName = "sample-app-other-server";

GroupManager groupManager = new GroupManager(manageClient);
ServerManager serverManager = new ServerManager(manageClient);
ServerManager defaultServerManager = new ServerManager(manageClient);
ServerManager otherServerManager = new ServerManager(manageClient, otherGroup);

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

try {
deploySampleApp();

assertTrue(groupManager.exists(otherGroup));
assertTrue(serverManager.exists(otherServer));
assertTrue(defaultServerManager.exists(serverName));
assertTrue(otherServerManager.exists(serverName));

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

assertTrue(groupManager.exists(otherGroup));
assertTrue(serverManager.exists(otherServer));
assertTrue(defaultServerManager.exists(serverName));
assertTrue(otherServerManager.exists(serverName));

} finally {
undeploySampleApp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"server-name": "sample-app-other-server",
"server-type": "http",
"root": "/",
"group-name": "sample-app-other-group",
"group-name": "Default",
"port": 8048,
"modules-database": "Modules",
"content-database": "Documents"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"server-name": "sample-app-other-server",
"server-type": "http",
"root": "/",
"group-name": "sample-app-other-group",
"port": 8049,
"modules-database": "Modules",
"content-database": "Documents"
}

0 comments on commit 7d679df

Please sign in to comment.