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

Commit 3572c4e

Browse files
committed
#74 New command for verifying server version
1 parent a6809fb commit 3572c4e

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.marklogic.appdeployer.command.admin;
2+
3+
import com.marklogic.appdeployer.command.AbstractCommand;
4+
import com.marklogic.appdeployer.command.CommandContext;
5+
6+
/**
7+
* Version 2.+ of ml-app-deployer requires at least version 8.x of MarkLogic. There are features in ml-app-deployer 2.x
8+
* - such as support for alerts and triggers - that require a certain version of 8, but we at least want to make sure
9+
* that no one tries to run this against ML 7 or an older version.
10+
*/
11+
public class RequireAtLeastMl8Command extends AbstractCommand {
12+
13+
@Override
14+
public void execute(CommandContext context) {
15+
int major = 0;
16+
try {
17+
String version = context.getAdminManager().getServerVersion();
18+
if (logger.isInfoEnabled()) {
19+
logger.info("Verifying MarkLogic version is at least 8 or higher; version: " + version);
20+
}
21+
major = Integer.parseInt(version.split("\\.")[0]);
22+
} catch (Exception e) {
23+
logger.warn("Unable to verify MarkLogic version is 8 or higher, will continue with deployment; error: "
24+
+ e.getMessage());
25+
major = 8;
26+
}
27+
if (major < 8) {
28+
throw new RuntimeException("Only MarkLogic versions 8 and higher are supported");
29+
}
30+
}
31+
32+
}

src/main/java/com/marklogic/mgmt/admin/AdminManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.web.client.RestTemplate;
1313

1414
import com.marklogic.mgmt.AbstractManager;
15+
import com.marklogic.rest.util.Fragment;
1516
import com.marklogic.rest.util.RestTemplateUtil;
1617

1718
public class AdminManager extends AbstractManager {
@@ -197,6 +198,14 @@ public boolean execute() {
197198
});
198199
}
199200

201+
public Fragment getServerConfig() {
202+
return new Fragment(restTemplate.getForObject(adminConfig.getBaseUrl() + "/admin/v1/server-config", String.class));
203+
}
204+
205+
public String getServerVersion() {
206+
return getServerConfig().getElementValue("/m:host/m:version");
207+
}
208+
200209
public void setWaitForRestartCheckInterval(int waitForRestartCheckInterval) {
201210
this.waitForRestartCheckInterval = waitForRestartCheckInterval;
202211
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.marklogic.appdeployer.command.admin;
2+
3+
import org.junit.Test;
4+
5+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
6+
7+
public class RequireAtLeastMl8Test extends AbstractAppDeployerTest {
8+
9+
@Test
10+
public void testThatNoExceptionIsThrown() {
11+
initializeAppDeployer(new RequireAtLeastMl8Command());
12+
appDeployer.deploy(appConfig);
13+
}
14+
}

0 commit comments

Comments
 (0)