Skip to content

Commit 62fa922

Browse files
rjrudinSameeraPriyathamTadikonda
authored andcommitted
DHFPROD-3223: mlServerVersion is now set correctly by the server
This does depend on DHS no longer defaulting servers to DHF 4-specific rewriters, as those no longer exists.
1 parent e1388f0 commit 62fa922

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed

marklogic-data-hub/src/main/java/com/marklogic/hub/cli/command/AbstractInstallerCommand.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,15 @@ protected void verifyUserCanAuthenticate() {
7474
}
7575
}
7676

77+
// TODO Some duplication between this and the logic in DeployHubOtherServersCommand
78+
protected String getServerMajorVersion() {
79+
try {
80+
String serverVersion = this.dataHub.getServerVersion();
81+
return serverVersion != null ? serverVersion.replaceAll("([^.]+)\\..*", "$1") : "9";
82+
} catch (Exception ex) {
83+
logger.warn("Unable to determine the server version; cause: " + ex.getMessage());
84+
logger.warn("Will use 9 as a fallback");
85+
return "9";
86+
}
87+
}
7788
}

marklogic-data-hub/src/main/java/com/marklogic/hub/cli/command/AbstractVerifyCommand.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ protected void verifyPrivileges() {
3434
}
3535

3636
protected void verifyAmps() {
37-
// For amps - there are 66 of them, will just verify that the first and last ones exist
37+
// For amps - just spot-checking a couple of them
3838
AmpManager ampManager = new AmpManager(hubConfig.getManageClient());
3939
Amp firstAmp = new Amp();
40-
firstAmp.setLocalName("addResponseHeader");
40+
firstAmp.setLocalName("map-to-xml");
4141
firstAmp.setModulesDatabase(hubConfig.getAppConfig().getModulesDatabaseName());
42-
firstAmp.setDocumentUri("/data-hub/5/rest-api/lib/endpoint-util.sjs");
42+
firstAmp.setDocumentUri("/com.marklogic.smart-mastering/survivorship/merging/base.xqy");
43+
firstAmp.setNamespace("http://marklogic.com/smart-mastering/survivorship/merging");
4344
Amp lastAmp = new Amp();
44-
lastAmp.setLocalName("invoke-service");
45-
lastAmp.setDocumentUri("/data-hub/5/rest-api/lib/extensions-util.xqy");
45+
lastAmp.setLocalName("construct-type");
46+
lastAmp.setDocumentUri("/com.marklogic.smart-mastering/survivorship/merging/base.xqy");
4647
lastAmp.setModulesDatabase(hubConfig.getAppConfig().getModulesDatabaseName());
47-
lastAmp.setNamespace("http://marklogic.com/rest-api/lib/extensions-util");
48+
lastAmp.setNamespace("http://marklogic.com/smart-mastering/survivorship/merging");
4849
for (Amp amp : new Amp[]{firstAmp, lastAmp}) {
4950
verify(ampManager.ampExists(amp.getJson()), "Expected amp to have been created: " + amp.getJson());
5051
}
@@ -127,9 +128,10 @@ protected void verifyTriggers() {
127128
}
128129

129130
protected void verifyStagingServer(String groupName) {
131+
final String version = getServerMajorVersion();
130132
verifyRewriterAndErrorHandler(new ServerManager(hubConfig.getManageClient(), groupName).getPropertiesAsXml("data-hub-STAGING"),
131-
"/data-hub/5/rest-api/rewriter.xml",
132-
"/data-hub/5/rest-api/error-handler.xqy"
133+
format("/data-hub/5/rest-api/rewriter/%s-rewriter.xml", version),
134+
"/MarkLogic/rest-api/error-handler.xqy"
133135
);
134136
}
135137

@@ -141,8 +143,9 @@ protected void verifyFinalServer(String groupName) {
141143
}
142144

143145
protected void verifyJobServer(String groupName) {
146+
final String version = getServerMajorVersion();
144147
verifyRewriterAndErrorHandler(new ServerManager(hubConfig.getManageClient(), groupName).getPropertiesAsXml("data-hub-JOBS"),
145-
"/data-hub/5/tracing/tracing-rewriter.xml",
148+
format("/data-hub/5/tracing/%s-tracing-rewriter.xml", version),
146149
"/MarkLogic/rest-api/error-handler.xqy"
147150
);
148151
}

marklogic-data-hub/src/main/java/com/marklogic/hub/cli/command/InstallIntoDhsCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.marklogic.appdeployer.command.databases.DeployOtherDatabasesCommand;
66
import com.marklogic.appdeployer.command.security.DeployAmpsCommand;
77
import com.marklogic.appdeployer.command.security.DeployPrivilegesCommand;
8+
import com.marklogic.hub.DataHub;
89
import com.marklogic.hub.cli.Options;
910
import com.marklogic.hub.cli.deploy.CopyQueryOptionsCommand;
1011
import com.marklogic.hub.cli.deploy.DhsDeployServersCommand;
@@ -34,7 +35,7 @@ public void run(ApplicationContext context, Options options) {
3435
// Update the servers in the Curator group
3536
groupName = "Curator";
3637
modifyHubConfigForDhs(groupName);
37-
deployer.setCommands(Arrays.asList(new DhsDeployServersCommand()));
38+
deployer.setCommands(Arrays.asList(new DhsDeployServersCommand(dataHub)));
3839
deployer.deploy(hubConfig.getAppConfig());
3940
}
4041

@@ -50,7 +51,7 @@ protected List<Command> buildCommandsForDhs() {
5051
commands.add(new DeployPrivilegesCommand());
5152
commands.add(new DeployAmpsCommand());
5253
commands.add(dbCommand);
53-
commands.add(new DhsDeployServersCommand());
54+
commands.add(new DhsDeployServersCommand(dataHub));
5455
commands.add(new DeployDatabaseFieldCommand());
5556

5657
Map<String, List<Command>> commandMap = dataHub.buildCommandMap();

marklogic-data-hub/src/main/java/com/marklogic/hub/cli/deploy/DhsDeployServersCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.marklogic.hub.cli.deploy;
22

33
import com.marklogic.appdeployer.command.CommandContext;
4+
import com.marklogic.hub.DataHub;
45
import com.marklogic.hub.deploy.commands.DeployHubOtherServersCommand;
56

67
import java.io.File;
@@ -11,8 +12,8 @@
1112
*/
1213
public class DhsDeployServersCommand extends DeployHubOtherServersCommand {
1314

14-
public DhsDeployServersCommand() {
15-
super(null);
15+
public DhsDeployServersCommand(DataHub dataHub) {
16+
super(dataHub);
1617
}
1718

1819
@Override

marklogic-data-hub/src/main/java/com/marklogic/hub/deploy/commands/DeployHubOtherServersCommand.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,15 @@ public void execute(CommandContext context) {
4545
AppConfig appConfig = context.getAppConfig();
4646
Map<String, String> customTokens = appConfig.getCustomTokens();
4747
//set the server version for the rewriter
48-
String serverVersion = this.dataHub.getServerVersion();
49-
customTokens.put("%%mlServerVersion%%", serverVersion != null ? serverVersion.replaceAll("([^.]+)\\..*", "$1") : "9");
48+
final String token = "%%mlServerVersion%%";
49+
try {
50+
String serverVersion = this.dataHub.getServerVersion();
51+
customTokens.put(token, serverVersion != null ? serverVersion.replaceAll("([^.]+)\\..*", "$1") : "9");
52+
} catch (Exception ex) {
53+
logger.warn("Unable to determine the server version; cause: " + ex.getMessage());
54+
logger.warn("Will set mlServerVersion to 9 as a fallback");
55+
customTokens.put(token, "9");
56+
}
5057
appConfig.setCustomTokens(customTokens);
5158
Map<String, Object> contextMap = context.getContextMap();
5259
contextMap.put("AppConfig", appConfig);

marklogic-data-hub/src/test/java/com/marklogic/hub/cli/deploy/DhsDeployServersCommandTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void test() throws Exception {
2626
server.setPort(8123);
2727
server.setAuthentication("digestbasic");
2828

29-
final String payload = new DhsDeployServersCommand().adjustPayloadBeforeSavingResource(context, null, server.getJson());
29+
final String payload = new DhsDeployServersCommand(null).adjustPayloadBeforeSavingResource(context, null, server.getJson());
3030
JsonNode node = ObjectMapperFactory.getObjectMapper().readTree(payload);
3131
assertEquals("some-server", node.get("server-name").asText());
3232
assertEquals("some-rewriter", node.get("url-rewriter").asText());

0 commit comments

Comments
 (0)