Skip to content

Commit

Permalink
Merge pull request #763 from marklogic-community/refactor-install-info
Browse files Browse the repository at this point in the history
Refactor install info
  • Loading branch information
aebadirad authored Feb 27, 2018
2 parents 4e1e95c + 90b776c commit e2643dd
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 260 deletions.
63 changes: 10 additions & 53 deletions marklogic-data-hub/src/main/java/com/marklogic/hub/InstallInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,24 @@ static InstallInfo create() {

String toString();

boolean isStagingAppServerExists();
boolean isAppServerExistent(DatabaseKind kind);

void setStagingAppServerExists(boolean stagingAppServerExists);
void setAppServerExistent(DatabaseKind kind, boolean stagingAppServerExists);

boolean isFinalAppServerExists();
boolean isDbExistent(DatabaseKind kind);

void setFinalAppServerExists(boolean finalAppServerExists);
void setDbExistent(DatabaseKind kind, boolean stagingDbExists);

boolean isTraceAppServerExists();
boolean isTripleIndexOn(DatabaseKind kind);

void setTraceAppServerExists(boolean traceAppServerExists);
void setTripleIndexOn(DatabaseKind kind, boolean stagingTripleIndexOn);

boolean isJobAppServerExists();
boolean isCollectionLexiconOn(DatabaseKind kind);

void setJobAppServerExists(boolean jobAppServerExists);
void setCollectionLexiconOn(DatabaseKind kind, boolean stagingCollectionLexiconOn);

boolean isStagingDbExists();
boolean areForestsExistent(DatabaseKind kind);

void setStagingDbExists(boolean stagingDbExists);
void setForestsExistent(DatabaseKind kind, boolean stagingForestsExist);

boolean isFinalDbExists();

void setFinalDbExists(boolean finalDbExists);

boolean isTraceDbExists();

void setTraceDbExists(boolean traceDbExists);

boolean isJobDbExists();

void setJobDbExists(boolean jobDbExists);

boolean isStagingTripleIndexOn();

void setStagingTripleIndexOn(boolean stagingTripleIndexOn);

boolean isStagingCollectionLexiconOn();

void setStagingCollectionLexiconOn(boolean stagingCollectionLexiconOn);

boolean isFinalTripleIndexOn();

void setFinalTripleIndexOn(boolean finalTripleIndexOn);

boolean isFinalCollectionLexiconOn();

void setFinalCollectionLexiconOn(boolean finalCollectionLexiconOn);

boolean isStagingForestsExist();

void setStagingForestsExist(boolean stagingForestsExist);

boolean isFinalForestsExist();

void setFinalForestsExist(boolean finalForestsExist);

boolean isTraceForestsExist();

void setTraceForestsExist(boolean traceForestsExist);

boolean isJobForestsExist();

void setJobForestsExist(boolean jobForestsExist);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.marklogic.hub.error;

import com.marklogic.hub.DatabaseKind;

public class InvalidDBOperationError extends Error {
public InvalidDBOperationError(DatabaseKind kind, String operation) {
super("Attempt to " + operation + " on the " + kind + " database");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import com.marklogic.appdeployer.command.forests.DeployCustomForestsCommand;
import com.marklogic.client.FailedRequestException;
import com.marklogic.client.eval.ServerEvaluationCall;
import com.marklogic.hub.DataHub;
import com.marklogic.hub.FlowManager;
import com.marklogic.hub.HubConfig;
import com.marklogic.hub.InstallInfo;
import com.marklogic.hub.*;
import com.marklogic.hub.deploy.HubAppDeployer;
import com.marklogic.hub.deploy.commands.*;
import com.marklogic.hub.deploy.util.HubDeployStatusListener;
Expand Down Expand Up @@ -114,39 +111,39 @@ private ServerManager getServerManager() {
InstallInfo installInfo = InstallInfo.create();

ResourcesFragment srf = getServerManager().getAsXml();
installInfo.setStagingAppServerExists(srf.resourceExists(hubConfig.getStagingHttpName()));
installInfo.setFinalAppServerExists(srf.resourceExists(hubConfig.getFinalHttpName()));
installInfo.setTraceAppServerExists(srf.resourceExists(hubConfig.getTraceHttpName()));
installInfo.setJobAppServerExists(srf.resourceExists(hubConfig.getJobHttpName()));
installInfo.setAppServerExistent(DatabaseKind.STAGING, srf.resourceExists(hubConfig.getStagingHttpName()));
installInfo.setAppServerExistent(DatabaseKind.FINAL, srf.resourceExists(hubConfig.getFinalHttpName()));
installInfo.setAppServerExistent(DatabaseKind.TRACE, srf.resourceExists(hubConfig.getTraceHttpName()));
installInfo.setAppServerExistent(DatabaseKind.JOB, srf.resourceExists(hubConfig.getJobHttpName()));

ResourcesFragment drf = getDatabaseManager().getAsXml();
installInfo.setStagingDbExists(drf.resourceExists(hubConfig.getStagingDbName()));
installInfo.setFinalDbExists(drf.resourceExists(hubConfig.getFinalDbName()));
installInfo.setTraceDbExists(drf.resourceExists(hubConfig.getTraceDbName()));
installInfo.setJobDbExists(drf.resourceExists(hubConfig.getJobDbName()));
installInfo.setDbExistent(DatabaseKind.STAGING, drf.resourceExists(hubConfig.getStagingDbName()));
installInfo.setDbExistent(DatabaseKind.FINAL, drf.resourceExists(hubConfig.getFinalDbName()));
installInfo.setDbExistent(DatabaseKind.TRACE, drf.resourceExists(hubConfig.getTraceDbName()));
installInfo.setDbExistent(DatabaseKind.JOB, drf.resourceExists(hubConfig.getJobDbName()));

if (installInfo.isStagingDbExists()) {
if (installInfo.isDbExistent(DatabaseKind.STAGING)) {
Fragment f = getDatabaseManager().getPropertiesAsXml(hubConfig.getStagingDbName());
installInfo.setStagingTripleIndexOn(Boolean.parseBoolean(f.getElementValue("//m:triple-index")));
installInfo.setStagingCollectionLexiconOn(Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon")));
installInfo.setStagingForestsExist((f.getElements("//m:forest").size() > 0));
installInfo.setTripleIndexOn(DatabaseKind.STAGING, Boolean.parseBoolean(f.getElementValue("//m:triple-index")));
installInfo.setCollectionLexiconOn(DatabaseKind.STAGING, Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon")));
installInfo.setForestsExistent(DatabaseKind.STAGING, (f.getElements("//m:forest").size() > 0));
}

if (installInfo.isFinalDbExists()) {
if (installInfo.isDbExistent(DatabaseKind.FINAL)) {
Fragment f = getDatabaseManager().getPropertiesAsXml(hubConfig.getFinalDbName());
installInfo.setFinalTripleIndexOn(Boolean.parseBoolean(f.getElementValue("//m:triple-index")));
installInfo.setFinalCollectionLexiconOn(Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon")));
installInfo.setFinalForestsExist((f.getElements("//m:forest").size() > 0));
installInfo.setTripleIndexOn(DatabaseKind.FINAL, Boolean.parseBoolean(f.getElementValue("//m:triple-index")));
installInfo.setCollectionLexiconOn(DatabaseKind.FINAL, Boolean.parseBoolean(f.getElementValue("//m:collection-lexicon")));
installInfo.setForestsExistent(DatabaseKind.FINAL, (f.getElements("//m:forest").size() > 0));
}

if (installInfo.isTraceDbExists()) {
if (installInfo.isDbExistent(DatabaseKind.TRACE)) {
Fragment f = getDatabaseManager().getPropertiesAsXml(hubConfig.getTraceDbName());
installInfo.setTraceForestsExist((f.getElements("//m:forest").size() > 0));
installInfo.setForestsExistent(DatabaseKind.TRACE, (f.getElements("//m:forest").size() > 0));
}

if (installInfo.isJobDbExists()) {
if (installInfo.isDbExistent(DatabaseKind.JOB)) {
Fragment f = getDatabaseManager().getPropertiesAsXml(hubConfig.getJobDbName());
installInfo.setJobForestsExist((f.getElements("//m:forest").size() > 0));
installInfo.setForestsExistent(DatabaseKind.JOB, (f.getElements("//m:forest").size() > 0));
}

logger.info(installInfo.toString());
Expand Down
Loading

0 comments on commit e2643dd

Please sign in to comment.