5050import com .marklogic .client .extensions .ResourceServices .ServiceResultIterator ;
5151import com .marklogic .client .helper .LoggingObject ;
5252import com .marklogic .client .io .JacksonHandle ;
53+ import com .marklogic .client .io .StringHandle ;
5354import com .marklogic .client .util .RequestParameters ;
55+ import com .marklogic .hub .deploy .HubAppDeployer ;
5456import com .marklogic .hub .deploy .commands .DeployHubDatabasesCommand ;
5557import com .marklogic .hub .deploy .commands .LoadHubModulesCommand ;
5658import com .marklogic .hub .deploy .commands .LoadUserModulesCommand ;
57- import com .marklogic .hub .deploy .HubAppDeployer ;
5859import com .marklogic .hub .deploy .util .HubDeployStatusListener ;
5960import com .marklogic .hub .error .ServerValidationException ;
6061import com .marklogic .mgmt .ManageClient ;
7172import org .springframework .web .client .ResourceAccessException ;
7273
7374import java .io .IOException ;
75+ import java .io .InputStream ;
7476import 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
8079public 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}
0 commit comments