4040import com .marklogic .appdeployer .command .Command ;
4141import com .marklogic .appdeployer .command .modules .AllButAssetsModulesFinder ;
4242import com .marklogic .appdeployer .command .modules .AssetModulesFinder ;
43- import com .marklogic .appdeployer .command .security .DeployRolesCommand ;
44- import com .marklogic .appdeployer .command .security .DeployUsersCommand ;
4543import com .marklogic .appdeployer .impl .SimpleAppDeployer ;
4644import com .marklogic .client .DatabaseClient ;
4745import com .marklogic .client .DatabaseClientFactory ;
6664import com .marklogic .mgmt .appservers .ServerManager ;
6765import com .marklogic .mgmt .databases .DatabaseManager ;
6866import com .marklogic .rest .util .Fragment ;
67+ import com .marklogic .rest .util .ResourcesFragment ;
6968
7069public class DataHub {
7170
@@ -106,14 +105,17 @@ public void setAssetInstallTimeFile(File assetInstallTimeFile) {
106105 public boolean isInstalled () {
107106 ServerManager sm = new ServerManager (client );
108107 DatabaseManager dm = new DatabaseManager (client );
109- boolean stagingAppServerExists = sm .exists (hubConfig .stagingHttpName );
110- boolean finalAppServerExists = sm .exists (hubConfig .finalHttpName );
111- boolean tracingAppServerExists = sm .exists (hubConfig .tracingHttpName );
108+
109+ ResourcesFragment srf = sm .getAsXml ();
110+ boolean stagingAppServerExists = srf .resourceExists (hubConfig .stagingHttpName );
111+ boolean finalAppServerExists = srf .resourceExists (hubConfig .finalHttpName );
112+ boolean tracingAppServerExists = srf .resourceExists (hubConfig .tracingHttpName );
112113 boolean appserversOk = (stagingAppServerExists && finalAppServerExists && tracingAppServerExists );
113114
114- boolean stagingDbExists = dm .exists (hubConfig .stagingDbName );
115- boolean finalDbExists = dm .exists (hubConfig .finalDbName );
116- boolean tracingDbExists = dm .exists (hubConfig .stagingDbName );
115+ ResourcesFragment drf = dm .getAsXml ();
116+ boolean stagingDbExists = drf .resourceExists (hubConfig .stagingDbName );
117+ boolean finalDbExists = drf .resourceExists (hubConfig .finalDbName );
118+ boolean tracingDbExists = drf .resourceExists (hubConfig .stagingDbName );
117119
118120 boolean stagingForestsExist = false ;
119121 boolean finalForestsExist = false ;
@@ -127,20 +129,20 @@ public boolean isInstalled() {
127129 Fragment f = dm .getPropertiesAsXml (hubConfig .stagingDbName );
128130 stagingIndexesOn = Boolean .parseBoolean (f .getElementValue ("//m:triple-index" ));
129131 stagingIndexesOn = stagingIndexesOn && Boolean .parseBoolean (f .getElementValue ("//m:collection-lexicon" ));
130- stagingForestsExist = (dm . getForestIds ( hubConfig . stagingDbName ).size () == hubConfig .stagingForestsPerHost );
132+ stagingForestsExist = (f . getElements ( "//m:forest" ).size () == hubConfig .stagingForestsPerHost );
131133 }
132134
133135 if (finalDbExists ) {
134136 Fragment f = dm .getPropertiesAsXml (hubConfig .finalDbName );
135137 finalIndexesOn = Boolean .parseBoolean (f .getElementValue ("//m:triple-index" ));
136138 finalIndexesOn = finalIndexesOn && Boolean .parseBoolean (f .getElementValue ("//m:collection-lexicon" ));
137- finalForestsExist = (dm . getForestIds ( hubConfig . finalDbName ).size () == hubConfig .finalForestsPerHost );
139+ finalForestsExist = (f . getElements ( "//m:forest" ).size () == hubConfig .finalForestsPerHost );
138140 }
139141
140142 if (tracingDbExists ) {
141143 tracingIndexesOn = true ;
142- int forests = dm .getForestIds (hubConfig .tracingDbName ). size ( );
143- tracingForestsExist = (forests == hubConfig .tracingForestsPerHost );
144+ Fragment f = dm .getPropertiesAsXml (hubConfig .tracingDbName );
145+ tracingForestsExist = (f . getElements ( "//m:forest" ). size () == hubConfig .tracingForestsPerHost );
144146 }
145147
146148 boolean dbsOk = (stagingDbExists && stagingIndexesOn &&
@@ -157,11 +159,7 @@ public boolean isInstalled() {
157159 */
158160 public void validateServer () throws ServerValidationException {
159161 try {
160- AdminConfig adminConfig = new AdminConfig ();
161- adminConfig .setHost (hubConfig .host );
162- adminConfig .setUsername (hubConfig .adminUsername );
163- adminConfig .setPassword (hubConfig .adminPassword );
164- AdminManager am = new AdminManager (adminConfig );
162+ AdminManager am = getAdminManager ();
165163 String versionString = am .getServerVersion ();
166164 int major = Integer .parseInt (versionString .substring (0 , 1 ));
167165 int minor = Integer .parseInt (versionString .substring (2 , 3 ) + versionString .substring (4 , 5 ));
@@ -204,16 +202,21 @@ private AppConfig getAppConfig() throws IOException {
204202 * @throws IOException
205203 */
206204 public void install () throws IOException {
205+ long startTime = System .nanoTime ();
207206 LOGGER .debug ("Installing the Data Hub into MarkLogic" );
207+
208208 // clean up any lingering cache for deployed modules
209209 PropertiesModuleManager moduleManager = new PropertiesModuleManager (this .assetInstallTimeFile );
210210 moduleManager .deletePropertiesFile ();
211211
212- AdminManager manager = new AdminManager ();
213212 AppConfig config = getAppConfig ();
214- SimpleAppDeployer deployer = new SimpleAppDeployer (client , manager );
213+ SimpleAppDeployer deployer = new SimpleAppDeployer (client , getAdminManager () );
215214 deployer .setCommands (getCommands (config ));
215+
216216 deployer .deploy (config );
217+ long endTime = System .nanoTime ();
218+ long duration = (endTime - startTime );
219+ LOGGER .info ("Install took: " + (duration / 1000000000 ) + " seconds" );
217220 }
218221
219222 private DatabaseClient getDatabaseClient (int port ) {
@@ -293,12 +296,6 @@ public JsonNode validateUserModules() {
293296 private List <Command > getCommands (AppConfig config ) {
294297 List <Command > commands = new ArrayList <Command >();
295298
296- // Security
297- List <Command > securityCommands = new ArrayList <Command >();
298- securityCommands .add (new DeployRolesCommand ());
299- securityCommands .add (new DeployUsersCommand ());
300- commands .addAll (securityCommands );
301-
302299 // Databases
303300 List <Command > dbCommands = new ArrayList <Command >();
304301 DeployHubDatabaseCommand staging = new DeployHubDatabaseCommand (hubConfig .stagingDbName );
@@ -317,9 +314,9 @@ private List<Command> getCommands(AppConfig config) {
317314 commands .addAll (dbCommands );
318315
319316 // App Servers
320- commands .add (new DeployRestApiCommand (hubConfig .stagingHttpName , hubConfig .stagingPort ));
321- commands .add (new DeployRestApiCommand (hubConfig .finalHttpName , hubConfig .finalPort ));
322- commands .add (new DeployRestApiCommand (hubConfig .tracingHttpName , hubConfig .tracePort ));
317+ commands .add (new DeployRestApiCommand (hubConfig .stagingHttpName , hubConfig .stagingPort , hubConfig . stagingDbName , hubConfig . stagingForestsPerHost ));
318+ commands .add (new DeployRestApiCommand (hubConfig .finalHttpName , hubConfig .finalPort , hubConfig . finalDbName , hubConfig . finalForestsPerHost ));
319+ commands .add (new DeployRestApiCommand (hubConfig .tracingHttpName , hubConfig .tracePort , hubConfig . tracingDbName , hubConfig . tracingForestsPerHost ));
323320
324321 commands .add (new UpdateRestApiServersCommand (hubConfig .stagingHttpName ));
325322 commands .add (new UpdateRestApiServersCommand (hubConfig .finalHttpName ));
@@ -331,23 +328,35 @@ private List<Command> getCommands(AppConfig config) {
331328 return commands ;
332329 }
333330
334-
331+ private AdminManager getAdminManager () {
332+ AdminConfig adminConfig = new AdminConfig ();
333+ adminConfig .setHost (hubConfig .host );
334+ adminConfig .setUsername (hubConfig .adminUsername );
335+ adminConfig .setPassword (hubConfig .adminPassword );
336+ AdminManager manager = new AdminManager (adminConfig );
337+ return manager ;
338+ }
335339
336340 /**
337341 * Uninstalls the data hub configuration and server-side modules from MarkLogic
338342 * @throws IOException
339343 */
340344 public void uninstall () throws IOException {
345+ long startTime = System .nanoTime ();
341346 LOGGER .debug ("Uninstalling the Data Hub from MarkLogic" );
342- AdminManager manager = new AdminManager ();
343347 AppConfig config = getAppConfig ();
344- SimpleAppDeployer deployer = new SimpleAppDeployer (client , manager );
348+ AdminManager adminManager = getAdminManager ();
349+ adminManager .setWaitForRestartCheckInterval (250 );
350+ SimpleAppDeployer deployer = new SimpleAppDeployer (client , adminManager );
345351 deployer .setCommands (getCommands (config ));
346352 deployer .undeploy (config );
347353
348354 // clean up any lingering cache for deployed modules
349355 PropertiesModuleManager moduleManager = new PropertiesModuleManager (this .assetInstallTimeFile );
350356 moduleManager .deletePropertiesFile ();
357+ long endTime = System .nanoTime ();
358+ long duration = (endTime - startTime );
359+ LOGGER .info ("Uninstall took: " + (duration / 1000000000 ) + " seconds" );
351360 }
352361
353362 class EntitiesValidator extends ResourceManager {
0 commit comments