Skip to content

Commit

Permalink
Little bit of cleanup of DeployDatabaseCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Nov 1, 2017
1 parent 406d647 commit 57da88a
Showing 1 changed file with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public class DeployDatabaseCommand extends AbstractCommand implements UndoableCo
private boolean createForestsOnEachHost = true;

private int undoSortOrder;
private boolean isSubDatabase = false;

private boolean subDatabase = false;
private String superDatabaseName;


public DeployDatabaseCommand() {
setExecuteSortOrder(SortOrderConstants.DEPLOY_OTHER_DATABASES);
Expand All @@ -88,30 +88,14 @@ public String toString() {
public Integer getUndoSortOrder() {
return undoSortOrder;
}

public void setIsSubDatabase(boolean isSubDatabase){
this.isSubDatabase = isSubDatabase;
}

public boolean isSubDatabase() {
return this.isSubDatabase;
}

public void setSuperDatabaseName(String name){
this.superDatabaseName = name;
}
public String getSuperDatabaseName() {
return this.superDatabaseName;
}


@Override
public void execute(CommandContext context) {
String payload = buildPayload(context);
if (payload != null) {
DatabaseManager dbMgr = new DatabaseManager(context.getManageClient());
SaveReceipt receipt = dbMgr.save(payload);

databaseName = receipt.getResourceId();
if (shouldCreateForests(context, payload)) {
buildDeployForestsCommand(payload, receipt, context).execute(context);
Expand All @@ -124,7 +108,7 @@ public void execute(CommandContext context) {
if(!isSubDatabase()){
this.addSubDatabases(dbMgr, context, receipt.getResourceId());
}

}
}

Expand All @@ -140,25 +124,25 @@ public void undo(CommandContext context) {
dbMgr.delete(payload);
}
}

/**
* Creates and attaches sub-databases to a the specified database, making it a super-database.
* Note: Sub-databases are expected to have a configuration files in databases/subdatabases/<super-database-name>
* @param dbMgr
* @param context
* @param superDatabaseName Name of the database the sub-databases are to be associated with
* @param superDatabaseName Name of the database the sub-databases are to be associated with
*/
protected void addSubDatabases(DatabaseManager dbMgr, CommandContext context, String superDatabaseName) {
File subdbDir = new File(context.getAppConfig().getConfigDir().getDatabasesDir() + File.separator + "subdatabases" + File.separator + superDatabaseName);
logger.info(format("Checking for Subdatabases in: %s for database: %s", subdbDir.getAbsolutePath(), superDatabaseName));
logger.info(format("Checking for sub-databases in: %s for database: %s", subdbDir.getAbsolutePath(), superDatabaseName));
if(subdbDir.exists()){
List<String> subDbNames = new ArrayList<String>();
for (File f : listFilesInDirectory(subdbDir)) {
logger.info(format("Will process sub database for %s found in file: %s", superDatabaseName, f.getAbsolutePath()));
DeployDatabaseCommand subDbCommand = new DeployDatabaseCommand();
subDbCommand.setDatabaseFilename(f.getName());
subDbCommand.setSuperDatabaseName(superDatabaseName);
subDbCommand.setIsSubDatabase(true);
subDbCommand.setSubDatabase(true);
subDbCommand.execute(context);
subDbNames.add(subDbCommand.getDatabaseName());
logger.info(format("Created subdatabase %s for database %s", subDbCommand.getDatabaseName(), superDatabaseName));
Expand All @@ -168,7 +152,7 @@ protected void addSubDatabases(DatabaseManager dbMgr, CommandContext context, St
}
}
}

/**
* Detaches and deletes all sub-databases for the specified super-database
* @param dbMgr
Expand All @@ -185,13 +169,13 @@ protected void removeSubDatabases(DatabaseManager dbMgr, CommandContext context,
DeployDatabaseCommand subDbCommand = new DeployDatabaseCommand();
subDbCommand.setDatabaseFilename(f.getName());
subDbCommand.setSuperDatabaseName(superDatabaseName);
subDbCommand.setIsSubDatabase(true);
subDbCommand.setSubDatabase(true);
subDbCommand.undo(context);

}
}
}


/**
* Configures the DatabaseManager in terms of how it deletes forests based on properties in the AppConfig instance
Expand Down Expand Up @@ -234,7 +218,6 @@ protected String getPayload(CommandContext context) {
if (databaseFilename != null) {
if(isSubDatabase()){
String subDbFileName =context.getAppConfig().getConfigDir().getDatabasesDir() + File.separator + "subdatabases" + File.separator + this.getSuperDatabaseName() + File.separator + databaseFilename;
logger.info("!!!! getting paylod for: " + subDbFileName);
f = new File(subDbFileName);
}else {
f = new File(context.getAppConfig().getConfigDir().getDatabasesDir(), databaseFilename);
Expand Down Expand Up @@ -396,4 +379,20 @@ public boolean isCheckForCustomForests() {
public void setCheckForCustomForests(boolean checkForCustomForests) {
this.checkForCustomForests = checkForCustomForests;
}

public void setSubDatabase(boolean isSubDatabase){
this.subDatabase = isSubDatabase;
}

public boolean isSubDatabase() {
return this.subDatabase;
}

public void setSuperDatabaseName(String name){
this.superDatabaseName = name;
}

public String getSuperDatabaseName() {
return this.superDatabaseName;
}
}

0 comments on commit 57da88a

Please sign in to comment.