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

Commit 4e52422

Browse files
committed
#298 Checking for REST API existence now accounts for a group name
1 parent 670aca0 commit 4e52422

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

src/main/java/com/marklogic/appdeployer/command/restapis/DeployRestApiServersCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public Integer getUndoSortOrder() {
6060
public void execute(CommandContext context) {
6161
String payload = getRestApiPayload(context);
6262
if (payload != null) {
63-
RestApiManager mgr = new RestApiManager(context.getManageClient());
6463
AppConfig appConfig = context.getAppConfig();
64+
RestApiManager mgr = new RestApiManager(context.getManageClient(), appConfig.getGroupName());
6565

6666
mgr.createRestApi(payloadTokenReplacer.replaceTokens(payload, appConfig, false));
6767

@@ -194,7 +194,7 @@ protected boolean deleteRestApi(String serverName, String groupName, ManageClien
194194
request.setIncludeModules(includeModules);
195195
request.setDeleteContentReplicaForests(isDeleteContentReplicaForests());
196196
request.setDeleteModulesReplicaForests(isDeleteModulesReplicaForests());
197-
return new RestApiManager(manageClient).deleteRestApi(request);
197+
return new RestApiManager(manageClient, groupName).deleteRestApi(request);
198198
}
199199

200200
public boolean isDeleteModulesDatabase() {

src/main/java/com/marklogic/mgmt/api/restapi/RestApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public String getJson() {
2929
}
3030

3131
public String save() {
32-
ResponseEntity<String> re = new RestApiManager(api.getManageClient()).createRestApi(name, getJson());
32+
ResponseEntity<String> re = new RestApiManager(api.getManageClient(), this.group).createRestApi(name, getJson());
3333
if (re == null) {
3434
return String.format("REST API with name %s already exists", name);
3535
} else {

src/main/java/com/marklogic/mgmt/resource/restapis/RestApiManager.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ public class RestApiManager extends LoggingObject {
1616

1717
private PayloadParser payloadParser = new PayloadParser();
1818
private ManageClient client;
19+
private String groupName;
1920

2021
public RestApiManager(ManageClient client) {
22+
this(client, ServerManager.DEFAULT_GROUP);
23+
}
24+
25+
public RestApiManager(ManageClient client, String groupName) {
2126
this.client = client;
27+
this.groupName = groupName;
2228
}
2329

2430
public ResponseEntity<String> createRestApi(String json) {
@@ -48,15 +54,20 @@ public String extractNameFromJson(String json) {
4854
* somewhere in it. With 9.0-4, the url-rewriter must match the pattern:
4955
* <p>
5056
* ^/MarkLogic/rest-api/(8000-rewriter|rewriter|rewriter-noxdbc)\.xml$
57+
* </p>
5158
* <p>
5259
* It's not likely that a user's custom rewriter will fit that pattern, so this method no longer uses /v1/rest-apis,
5360
* opting to use ServerManager instead.
54-
*
61+
* </p>
62+
* <p>
63+
* As of ml-app-deployer version 3.8.4, this now properly accounts for a group name.
64+
* </p>
5565
* @param name
5666
* @return
5767
*/
5868
public boolean restApiServerExists(String name) {
59-
return new ServerManager(client).exists(name);
69+
final String group = this.groupName != null ? this.groupName : ServerManager.DEFAULT_GROUP;
70+
return new ServerManager(this.client, group).exists(name);
6071
}
6172

6273
/**
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.marklogic.appdeployer.command.restapis;
2+
3+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.appdeployer.command.groups.DeployGroupsCommand;
5+
import com.marklogic.mgmt.resource.appservers.ServerManager;
6+
import org.junit.After;
7+
import org.junit.Test;
8+
9+
import java.io.File;
10+
11+
public class CreateRestApiInOtherGroupTest extends AbstractAppDeployerTest {
12+
13+
@After
14+
public void tearDown() {
15+
undeploySampleApp();
16+
}
17+
18+
@Test
19+
public void test() {
20+
final String groupName = "ml-app-deployer-other-group";
21+
final String serverName = appConfig.getRestServerName();
22+
23+
appConfig.setGroupName(groupName);
24+
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/rest-api-other-group"));
25+
initializeAppDeployer(new DeployGroupsCommand(), new DeployRestApiServersCommand());
26+
27+
deploySampleApp();
28+
assertTrue(new ServerManager(manageClient, groupName).exists(serverName));
29+
assertFalse(new ServerManager(manageClient).exists(serverName));
30+
31+
deploySampleApp();
32+
assertTrue("The deployment should have succeeded because RestApiManager now checks to see if the REST API server " +
33+
"exists in the group defined by appConfig.getGroupName as opposed to just the Default group",
34+
new ServerManager(manageClient, groupName).exists(serverName));
35+
assertFalse(new ServerManager(manageClient).exists(serverName));
36+
}
37+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"group-name": "ml-app-deployer-other-group"
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"rest-api": {
3+
"name": "%%NAME%%",
4+
"group": "ml-app-deployer-other-group",
5+
"database": "%%DATABASE%%",
6+
"modules-database": "%%MODULES_DATABASE%%",
7+
"port": "%%PORT%%",
8+
"xdbc-enabled": true,
9+
"forests-per-host": 1,
10+
"error-format": "json"
11+
}
12+
}

0 commit comments

Comments
 (0)