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

Commit

Permalink
#298 Checking for REST API existence now accounts for a group name
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Aug 12, 2018
1 parent 670aca0 commit 4e52422
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public Integer getUndoSortOrder() {
public void execute(CommandContext context) {
String payload = getRestApiPayload(context);
if (payload != null) {
RestApiManager mgr = new RestApiManager(context.getManageClient());
AppConfig appConfig = context.getAppConfig();
RestApiManager mgr = new RestApiManager(context.getManageClient(), appConfig.getGroupName());

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

Expand Down Expand Up @@ -194,7 +194,7 @@ protected boolean deleteRestApi(String serverName, String groupName, ManageClien
request.setIncludeModules(includeModules);
request.setDeleteContentReplicaForests(isDeleteContentReplicaForests());
request.setDeleteModulesReplicaForests(isDeleteModulesReplicaForests());
return new RestApiManager(manageClient).deleteRestApi(request);
return new RestApiManager(manageClient, groupName).deleteRestApi(request);
}

public boolean isDeleteModulesDatabase() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/marklogic/mgmt/api/restapi/RestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String getJson() {
}

public String save() {
ResponseEntity<String> re = new RestApiManager(api.getManageClient()).createRestApi(name, getJson());
ResponseEntity<String> re = new RestApiManager(api.getManageClient(), this.group).createRestApi(name, getJson());
if (re == null) {
return String.format("REST API with name %s already exists", name);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ public class RestApiManager extends LoggingObject {

private PayloadParser payloadParser = new PayloadParser();
private ManageClient client;
private String groupName;

public RestApiManager(ManageClient client) {
this(client, ServerManager.DEFAULT_GROUP);
}

public RestApiManager(ManageClient client, String groupName) {
this.client = client;
this.groupName = groupName;
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.marklogic.appdeployer.command.restapis;

import com.marklogic.appdeployer.AbstractAppDeployerTest;
import com.marklogic.appdeployer.command.groups.DeployGroupsCommand;
import com.marklogic.mgmt.resource.appservers.ServerManager;
import org.junit.After;
import org.junit.Test;

import java.io.File;

public class CreateRestApiInOtherGroupTest extends AbstractAppDeployerTest {

@After
public void tearDown() {
undeploySampleApp();
}

@Test
public void test() {
final String groupName = "ml-app-deployer-other-group";
final String serverName = appConfig.getRestServerName();

appConfig.setGroupName(groupName);
appConfig.getFirstConfigDir().setBaseDir(new File("src/test/resources/sample-app/rest-api-other-group"));
initializeAppDeployer(new DeployGroupsCommand(), new DeployRestApiServersCommand());

deploySampleApp();
assertTrue(new ServerManager(manageClient, groupName).exists(serverName));
assertFalse(new ServerManager(manageClient).exists(serverName));

deploySampleApp();
assertTrue("The deployment should have succeeded because RestApiManager now checks to see if the REST API server " +
"exists in the group defined by appConfig.getGroupName as opposed to just the Default group",
new ServerManager(manageClient, groupName).exists(serverName));
assertFalse(new ServerManager(manageClient).exists(serverName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"group-name": "ml-app-deployer-other-group"
}
12 changes: 12 additions & 0 deletions src/test/resources/sample-app/rest-api-other-group/rest-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rest-api": {
"name": "%%NAME%%",
"group": "ml-app-deployer-other-group",
"database": "%%DATABASE%%",
"modules-database": "%%MODULES_DATABASE%%",
"port": "%%PORT%%",
"xdbc-enabled": true,
"forests-per-host": 1,
"error-format": "json"
}
}

0 comments on commit 4e52422

Please sign in to comment.