Skip to content

Commit 06707b0

Browse files
committed
fixed #324
fixed #304 #322 - added backend service to return hub version
1 parent 3880266 commit 06707b0

File tree

22 files changed

+530
-173
lines changed

22 files changed

+530
-173
lines changed

marklogic-data-hub/build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'java'
44
id 'maven-publish'
55
id 'com.jfrog.bintray' version '1.7.2'
6-
id 'com.marklogic.ml-gradle' version '2.3.4'
6+
id 'com.marklogic.ml-gradle' version '2.4.0'
77
id 'com.moowork.node' version '0.13'
88
}
99

@@ -23,7 +23,7 @@ dependencies {
2323
compile 'org.springframework:spring-jdbc:4.2.6.RELEASE'
2424
compile 'com.marklogic:java-client-api:3.0.5'
2525
compile 'com.marklogic:ml-javaclient-util:2.10.0'
26-
compile 'com.marklogic:ml-app-deployer:2.3.0'
26+
compile 'com.marklogic:ml-app-deployer:2.4.0'
2727
compile 'com.marklogic:marklogic-spring-batch-core:0.7.0'
2828
compile 'commons-io:commons-io:2.4'
2929
testCompile 'org.springframework.batch:spring-batch-test:3.0.6.RELEASE'
@@ -80,6 +80,12 @@ task copyUIAssets(type: Copy) {
8080
dependsOn tasks.buildUI
8181
}
8282

83+
processResources {
84+
filesMatching("**/version.properties") {
85+
expand(project: project)
86+
}
87+
}
88+
8389
if (!gradle.startParameter.taskNames.contains('bootrun')) {
8490
processResources.dependsOn copyUIAssets
8591
}

marklogic-data-hub/src/main/java/com/marklogic/hub/DataHub.java

Lines changed: 81 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@
5050
import com.marklogic.client.extensions.ResourceServices.ServiceResultIterator;
5151
import com.marklogic.client.helper.LoggingObject;
5252
import com.marklogic.client.io.JacksonHandle;
53+
import com.marklogic.client.io.StringHandle;
5354
import com.marklogic.client.util.RequestParameters;
55+
import com.marklogic.hub.deploy.HubAppDeployer;
5456
import com.marklogic.hub.deploy.commands.DeployHubDatabasesCommand;
5557
import com.marklogic.hub.deploy.commands.LoadHubModulesCommand;
5658
import com.marklogic.hub.deploy.commands.LoadUserModulesCommand;
57-
import com.marklogic.hub.deploy.HubAppDeployer;
5859
import com.marklogic.hub.deploy.util.HubDeployStatusListener;
5960
import com.marklogic.hub.error.ServerValidationException;
6061
import com.marklogic.mgmt.ManageClient;
@@ -71,11 +72,9 @@
7172
import org.springframework.web.client.ResourceAccessException;
7273

7374
import java.io.IOException;
75+
import java.io.InputStream;
7476
import java.nio.file.Paths;
75-
import java.util.ArrayList;
76-
import java.util.HashMap;
77-
import java.util.List;
78-
import java.util.Map;
77+
import java.util.*;
7978

8079
public class DataHub extends LoggingObject {
8180

@@ -118,63 +117,49 @@ void setAdminManager(AdminManager manager) {
118117
* Determines if the data hub is installed in MarkLogic
119118
* @return true if installed, false otherwise
120119
*/
121-
public boolean isInstalled() {
120+
public InstallInfo isInstalled() {
121+
122+
InstallInfo installInfo = new InstallInfo();
123+
122124
ResourcesFragment srf = serverManager.getAsXml();
123-
boolean stagingAppServerExists = srf.resourceExists(hubConfig.stagingHttpName);
124-
boolean finalAppServerExists = srf.resourceExists(hubConfig.finalHttpName);
125-
boolean traceAppServerExists = srf.resourceExists(hubConfig.traceHttpName);
126-
boolean jobAppServerExists = srf.resourceExists(hubConfig.jobHttpName);
127-
boolean appserversOk = (stagingAppServerExists && finalAppServerExists && traceAppServerExists && jobAppServerExists);
125+
installInfo.stagingAppServerExists = srf.resourceExists(hubConfig.stagingHttpName);
126+
installInfo.finalAppServerExists = srf.resourceExists(hubConfig.finalHttpName);
127+
installInfo.traceAppServerExists = srf.resourceExists(hubConfig.traceHttpName);
128+
installInfo.jobAppServerExists = srf.resourceExists(hubConfig.jobHttpName);
128129

129130
ResourcesFragment drf = databaseManager.getAsXml();
130-
boolean stagingDbExists = drf.resourceExists(hubConfig.stagingDbName);
131-
boolean finalDbExists = drf.resourceExists(hubConfig.finalDbName);
132-
boolean traceDbExists = drf.resourceExists(hubConfig.traceDbName);
133-
boolean jobDbExists = drf.resourceExists(hubConfig.jobDbName);
134-
135-
boolean stagingForestsExist = false;
136-
boolean finalForestsExist = false;
137-
boolean traceForestsExist = false;
138-
boolean jobForestsExist = false;
139-
140-
boolean stagingIndexesOn = false;
141-
boolean finalIndexesOn = false;
142-
boolean traceIndexesOn = false;
143-
boolean jobIndexesOn = false;
144-
145-
if (stagingDbExists) {
131+
installInfo.stagingDbExists = drf.resourceExists(hubConfig.stagingDbName);
132+
installInfo.finalDbExists = drf.resourceExists(hubConfig.finalDbName);
133+
installInfo.traceDbExists = drf.resourceExists(hubConfig.traceDbName);
134+
installInfo.jobDbExists = drf.resourceExists(hubConfig.jobDbName);
135+
136+
if (installInfo.stagingDbExists) {
146137
Fragment f = databaseManager.getPropertiesAsXml(hubConfig.stagingDbName);
147-
stagingIndexesOn = Boolean.parseBoolean(f.getElementValue("//m:triple-index"));
148-
stagingIndexesOn = stagingIndexesOn && Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon"));
149-
stagingForestsExist = (f.getElements("//m:forest").size() == hubConfig.stagingForestsPerHost);
138+
installInfo.stagingTripleIndexOn = Boolean.parseBoolean(f.getElementValue("//m:triple-index"));
139+
installInfo.stagingCollectionLexiconOn = Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon"));
140+
installInfo.stagingForestsExist = (f.getElements("//m:forest").size() > 0);
150141
}
151142

152-
if (finalDbExists) {
143+
if (installInfo.finalDbExists) {
153144
Fragment f = databaseManager.getPropertiesAsXml(hubConfig.finalDbName);
154-
finalIndexesOn = Boolean.parseBoolean(f.getElementValue("//m:triple-index"));
155-
finalIndexesOn = finalIndexesOn && Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon"));
156-
finalForestsExist = (f.getElements("//m:forest").size() == hubConfig.finalForestsPerHost);
145+
installInfo.finalTripleIndexOn = Boolean.parseBoolean(f.getElementValue("//m:triple-index"));
146+
installInfo.finalCollectionLexiconOn = Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon"));
147+
installInfo.finalForestsExist = (f.getElements("//m:forest").size() > 0);
157148
}
158149

159-
if (traceDbExists) {
160-
traceIndexesOn = true;
150+
if (installInfo.traceDbExists) {
161151
Fragment f = databaseManager.getPropertiesAsXml(hubConfig.traceDbName);
162-
traceForestsExist = (f.getElements("//m:forest").size() == hubConfig.traceForestsPerHost);
152+
installInfo.traceForestsExist = (f.getElements("//m:forest").size() > 0);
163153
}
164154

165-
if (jobDbExists) {
166-
jobIndexesOn = true;
155+
if (installInfo.jobDbExists) {
167156
Fragment f = databaseManager.getPropertiesAsXml(hubConfig.jobDbName);
168-
jobForestsExist = (f.getElements("//m:forest").size() == hubConfig.jobForestsPerHost);
157+
installInfo.jobForestsExist = (f.getElements("//m:forest").size() > 0);
169158
}
170159

171-
boolean dbsOk = (stagingDbExists && stagingIndexesOn &&
172-
finalDbExists && finalIndexesOn &&
173-
traceDbExists && traceIndexesOn &&
174-
jobDbExists && jobIndexesOn);
175-
boolean forestsOk = (stagingForestsExist && finalForestsExist && traceForestsExist && jobForestsExist);
160+
logger.info(installInfo.toString());
176161

177-
return (appserversOk && dbsOk && forestsOk);
162+
return installInfo;
178163
}
179164

180165
/**
@@ -265,6 +250,22 @@ public void updateAppConfig(AppConfig config) {
265250
customTokens.put("%%mlHubUserName%%", hubConfig.hubUserName);
266251
customTokens.put("%%mlHubUserPassword%%", hubConfig.hubUserPassword);
267252
customTokens.put("%%mlHubUserRole%%", hubConfig.hubUserRole);
253+
254+
try {
255+
String version = getJarVersion();
256+
customTokens.put("%%mlHubVersion%%", version);
257+
}
258+
catch(IOException e) {
259+
e.printStackTrace();
260+
}
261+
}
262+
263+
String getJarVersion() throws IOException {
264+
Properties properties = new Properties();
265+
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("version.properties");
266+
properties.load(inputStream);
267+
String version = (String)properties.get("version");
268+
return version;
268269
}
269270

270271
public void initProject() {
@@ -505,6 +506,20 @@ public void uninstall(HubDeployStatusListener listener) {
505506
deployer.undeploy(config);
506507
}
507508

509+
/**
510+
* Gets the hub version for the installed server side modules
511+
* @return - the version of the installed modules
512+
*/
513+
public String getHubVersion() {
514+
try {
515+
DatabaseClient client = getDatabaseClient(hubConfig.stagingPort);
516+
HubVersion hv = new HubVersion(client);
517+
return hv.getVersion();
518+
}
519+
catch(Exception e) {}
520+
return "1.0.0";
521+
}
522+
508523
class EntitiesValidator extends ResourceManager {
509524
private static final String NAME = "validate";
510525

@@ -524,4 +539,24 @@ public JsonNode validate() {
524539
return res.getContent(handle).get();
525540
}
526541
}
542+
543+
class HubVersion extends ResourceManager {
544+
private static final String NAME = "hubversion";
545+
546+
public HubVersion(DatabaseClient client) {
547+
super();
548+
client.init(NAME, this);
549+
}
550+
551+
public String getVersion() {
552+
RequestParameters params = new RequestParameters();
553+
ServiceResultIterator resultItr = this.getServices().get(params);
554+
if (resultItr == null || ! resultItr.hasNext()) {
555+
return null;
556+
}
557+
ServiceResult res = resultItr.next();
558+
StringHandle handle = new StringHandle();
559+
return res.getContent(handle).get();
560+
}
561+
}
527562
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.marklogic.hub;
2+
3+
public class InstallInfo {
4+
public boolean stagingAppServerExists = false;
5+
public boolean finalAppServerExists = false;
6+
public boolean traceAppServerExists = false;
7+
public boolean jobAppServerExists = false;
8+
9+
public boolean stagingDbExists = false;
10+
public boolean finalDbExists = false;
11+
public boolean traceDbExists = false;
12+
public boolean jobDbExists = false;
13+
14+
public boolean stagingTripleIndexOn = false;
15+
public boolean stagingCollectionLexiconOn = false;
16+
public boolean finalTripleIndexOn = false;
17+
public boolean finalCollectionLexiconOn = false;
18+
19+
public boolean stagingForestsExist = false;
20+
public boolean finalForestsExist = false;
21+
public boolean traceForestsExist = false;
22+
public boolean jobForestsExist = false;
23+
24+
public boolean isPartiallyInstalled() {
25+
return (
26+
stagingAppServerExists ||
27+
finalAppServerExists ||
28+
traceAppServerExists ||
29+
jobAppServerExists ||
30+
stagingDbExists ||
31+
stagingTripleIndexOn ||
32+
stagingCollectionLexiconOn ||
33+
finalDbExists ||
34+
finalTripleIndexOn ||
35+
finalCollectionLexiconOn ||
36+
traceDbExists ||
37+
jobDbExists ||
38+
stagingForestsExist ||
39+
finalForestsExist ||
40+
traceForestsExist ||
41+
jobForestsExist
42+
);
43+
}
44+
45+
public boolean isInstalled() {
46+
boolean appserversOk = (
47+
stagingAppServerExists &&
48+
finalAppServerExists &&
49+
traceAppServerExists &&
50+
jobAppServerExists
51+
);
52+
53+
boolean dbsOk = (
54+
stagingDbExists &&
55+
stagingTripleIndexOn &&
56+
stagingCollectionLexiconOn &&
57+
finalDbExists &&
58+
finalTripleIndexOn &&
59+
finalCollectionLexiconOn &&
60+
traceDbExists &&
61+
jobDbExists
62+
);
63+
boolean forestsOk = (
64+
stagingForestsExist &&
65+
finalForestsExist &&
66+
traceForestsExist &&
67+
jobForestsExist
68+
);
69+
70+
return (appserversOk && dbsOk && forestsOk);
71+
}
72+
73+
public String toString() {
74+
return "\n" +
75+
"Checking MarkLogic Installation:\n" +
76+
"\tAppServers:\n" +
77+
"\t\tStaging: " + (stagingAppServerExists ? "exists" : "MISSING") + "\n" +
78+
"\t\tFinal: " + (finalAppServerExists? "exists" : "MISSING") + "\n" +
79+
"\t\tTrace: " + (traceAppServerExists? "exists" : "MISSING") + "\n" +
80+
"\t\tJob: " + (jobAppServerExists? "exists" : "MISSING") + "\n" +
81+
"\tDatabases:\n" +
82+
"\t\tStaging: " + (stagingDbExists ? "exists" : "MISSING") + "\n" +
83+
"\t\tFinal: " + (finalDbExists? "exists" : "MISSING") + "\n" +
84+
"\t\tTrace: " + (traceDbExists ? "exists" : "MISSING") + "\n" +
85+
"\t\tJob: " + (jobDbExists ? "exists" : "MISSING") + "\n" +
86+
"\tDatabases Indexes:\n" +
87+
"\t\tStaging Triples Index : " + (stagingTripleIndexOn ? "exists" : "MISSING") + "\n" +
88+
"\t\tStaging Collection Lexicon : " + (stagingCollectionLexiconOn ? "exists" : "MISSING") + "\n" +
89+
"\t\tFinal Triples Index : " + (finalTripleIndexOn ? "exists" : "MISSING") + "\n" +
90+
"\t\tFinal Collection Lexicon : " + (finalCollectionLexiconOn ? "exists" : "MISSING") + "\n" +
91+
"\tForests\n" +
92+
"\t\tStaging: " + (stagingForestsExist ? "exists" : "MISSING") + "\n" +
93+
"\t\tFinal: " + (finalForestsExist ? "exists" : "MISSING") + "\n" +
94+
"\t\tTrace: " + (traceForestsExist ? "exists" : "MISSING") + "\n" +
95+
"\t\tJob: " + (jobForestsExist ? "exists" : "MISSING") + "\n" +
96+
"\n\n" +
97+
"OVERAL RESULT: " + (isInstalled() ? "INSTALLED" : "NOT INSTALLED") + "\n";
98+
}
99+
100+
}

marklogic-data-hub/src/main/resources/ml-modules/root/com.marklogic.hub/lib/config.xqy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ declare variable $FINAL-DATABASE := "%%mlFinalDbName%%";
99
declare variable $TRACE-DATABASE := "%%mlTraceDbName%%";
1010
declare variable $JOB-DATABASE := "%%mlJobDbName%%";
1111
declare variable $MODULES-DATABASE := "%%mlModulesDbName%%";
12+
declare variable $HUB-VERSION := "%%mlHubVersion%%";

marklogic-data-hub/src/main/resources/ml-modules/services/hubstats.xqy

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ declare function service:get-db-count($db)
3838
};
3939

4040
(:~
41-
: Entry point for java to get flow(s).
42-
:
43-
: if the "flow-name" param is given then return a flow. Otherwise
44-
: return all flows.
41+
: Entry point for java to get hub stats
4542
:
4643
:)
4744
declare function get(
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(:
2+
Copyright 2012-2016 MarkLogic Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
:)
16+
xquery version "1.0-ml";
17+
18+
module namespace service = "http://marklogic.com/rest-api/resource/hubversion";
19+
20+
import module namespace config = "http://marklogic.com/data-hub/config"
21+
at "/com.marklogic.hub/lib/config.xqy";
22+
23+
import module namespace debug = "http://marklogic.com/data-hub/debug"
24+
at "/com.marklogic.hub/lib/debug-lib.xqy";
25+
26+
import module namespace perf = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
29+
declare option xdmp:mapping "false";
30+
31+
declare function get(
32+
$context as map:map,
33+
$params as map:map
34+
) as document-node()*
35+
{
36+
debug:dump-env(),
37+
perf:log('/v1/resources/hubversion:get', function() {
38+
xdmp:set-response-content-type("text/plain"),
39+
document {
40+
$config:HUB-VERSION
41+
}
42+
})
43+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!-- Copyright 2016 MarkLogic Corporation. All Rights Reserved. -->
2+
<metadata>
3+
<title>hubversion</title>
4+
<description>
5+
<div>
6+
Entry point for getting the hub version of the installed modules
7+
</div>
8+
</description>
9+
<method name="GET"/>
10+
</metadata>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=${project.version}

0 commit comments

Comments
 (0)