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

Commit

Permalink
#74 New command for verifying server version
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Jan 6, 2016
1 parent a6809fb commit 3572c4e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.marklogic.appdeployer.command.admin;

import com.marklogic.appdeployer.command.AbstractCommand;
import com.marklogic.appdeployer.command.CommandContext;

/**
* Version 2.+ of ml-app-deployer requires at least version 8.x of MarkLogic. There are features in ml-app-deployer 2.x
* - such as support for alerts and triggers - that require a certain version of 8, but we at least want to make sure
* that no one tries to run this against ML 7 or an older version.
*/
public class RequireAtLeastMl8Command extends AbstractCommand {

@Override
public void execute(CommandContext context) {
int major = 0;
try {
String version = context.getAdminManager().getServerVersion();
if (logger.isInfoEnabled()) {
logger.info("Verifying MarkLogic version is at least 8 or higher; version: " + version);
}
major = Integer.parseInt(version.split("\\.")[0]);
} catch (Exception e) {
logger.warn("Unable to verify MarkLogic version is 8 or higher, will continue with deployment; error: "
+ e.getMessage());
major = 8;
}
if (major < 8) {
throw new RuntimeException("Only MarkLogic versions 8 and higher are supported");
}
}

}
9 changes: 9 additions & 0 deletions src/main/java/com/marklogic/mgmt/admin/AdminManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.web.client.RestTemplate;

import com.marklogic.mgmt.AbstractManager;
import com.marklogic.rest.util.Fragment;
import com.marklogic.rest.util.RestTemplateUtil;

public class AdminManager extends AbstractManager {
Expand Down Expand Up @@ -197,6 +198,14 @@ public boolean execute() {
});
}

public Fragment getServerConfig() {
return new Fragment(restTemplate.getForObject(adminConfig.getBaseUrl() + "/admin/v1/server-config", String.class));
}

public String getServerVersion() {
return getServerConfig().getElementValue("/m:host/m:version");
}

public void setWaitForRestartCheckInterval(int waitForRestartCheckInterval) {
this.waitForRestartCheckInterval = waitForRestartCheckInterval;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.marklogic.appdeployer.command.admin;

import org.junit.Test;

import com.marklogic.appdeployer.AbstractAppDeployerTest;

public class RequireAtLeastMl8Test extends AbstractAppDeployerTest {

@Test
public void testThatNoExceptionIsThrown() {
initializeAppDeployer(new RequireAtLeastMl8Command());
appDeployer.deploy(appConfig);
}
}

0 comments on commit 3572c4e

Please sign in to comment.