This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#7 Can now update the REST API servers
- Loading branch information
Showing
9 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/marklogic/appdeployer/plugin/servers/UpdateRestApiServersPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.marklogic.appdeployer.plugin.servers; | ||
|
||
import java.io.File; | ||
|
||
import com.marklogic.appdeployer.AppConfig; | ||
import com.marklogic.appdeployer.AppPluginContext; | ||
import com.marklogic.appdeployer.plugin.AbstractPlugin; | ||
import com.marklogic.rest.mgmt.appservers.ServerManager; | ||
|
||
public class UpdateRestApiServersPlugin extends AbstractPlugin { | ||
|
||
@Override | ||
public Integer getSortOrderOnDeploy() { | ||
return 600; | ||
} | ||
|
||
@Override | ||
public void onDeploy(AppPluginContext context) { | ||
File f = context.getConfigDir().getRestApiServerFile(); | ||
if (f.exists()) { | ||
ServerManager mgr = new ServerManager(context.getManageClient()); | ||
|
||
String payload = copyFileToString(f); | ||
AppConfig appConfig = context.getAppConfig(); | ||
|
||
String json = tokenReplacer.replaceTokens(payload, appConfig, false); | ||
mgr.updateServer(appConfig.getRestServerName(), appConfig.getGroupName(), json); | ||
|
||
if (appConfig.isTestPortSet()) { | ||
json = tokenReplacer.replaceTokens(payload, appConfig, true); | ||
mgr.updateServer(appConfig.getTestRestServerName(), appConfig.getGroupName(), json); | ||
} | ||
} else { | ||
logger.info(format("No REST API server file found at %s, so not updating the server", f.getAbsolutePath())); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onUndeploy(AppPluginContext context) { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,6 @@ public void updateDatabase() { | |
|
||
@After | ||
public void teardown() { | ||
deleteSampleApp(); | ||
undeploySampleApp(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/com/marklogic/appdeployer/servers/UpdateRestApiServersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.marklogic.appdeployer.servers; | ||
|
||
import org.junit.After; | ||
import org.junit.Test; | ||
|
||
import com.marklogic.appdeployer.AbstractAppDeployerTest; | ||
import com.marklogic.appdeployer.plugin.RestApiPlugin; | ||
import com.marklogic.appdeployer.plugin.servers.UpdateRestApiServersPlugin; | ||
import com.marklogic.rest.mgmt.appservers.ServerManager; | ||
import com.marklogic.rest.util.Fragment; | ||
|
||
public class UpdateRestApiServersTest extends AbstractAppDeployerTest { | ||
|
||
@After | ||
public void teardown() { | ||
undeploySampleApp(); | ||
} | ||
|
||
@Test | ||
public void updateMainAndRestRestApiServers() { | ||
// Deploy a REST API server and a test one too | ||
initializeAppDeployer(); | ||
appConfig.setTestRestPort(SAMPLE_APP_TEST_REST_PORT); | ||
appDeployer.deploy(appConfig, configDir); | ||
|
||
assertAuthentication("The REST API server auth should default to digest", appConfig.getRestServerName(), | ||
"digest"); | ||
assertAuthentication("The test REST API server auth should default to digest", | ||
appConfig.getTestRestServerName(), "digest"); | ||
|
||
// Now redeploy with the update plugin | ||
initializeAppDeployer(new RestApiPlugin(), new UpdateRestApiServersPlugin()); | ||
appDeployer.deploy(appConfig, configDir); | ||
|
||
assertAuthentication( | ||
"The REST API server auth should now be set to basic because of what's in the rest-api-server.json file", | ||
appConfig.getRestServerName(), "basic"); | ||
assertAuthentication( | ||
"The test REST API server auth should now be set to basic because of what's in the rest-api-server.json file", | ||
appConfig.getTestRestServerName(), "basic"); | ||
} | ||
|
||
private void assertAuthentication(String message, String serverName, String auth) { | ||
Fragment xml = new ServerManager(manageClient).getServerPropertiesAsXml(serverName, appConfig.getGroupName()); | ||
assertTrue(message, | ||
xml.elementExists(String.format("/m:http-server-properties/m:authentication[. = '%s']", auth))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/test/resources/sample-app/src/main/ml-config/servers/rest-api-server.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"authentication": "basic" | ||
} |