Skip to content

Commit

Permalink
add: separate each level of config as class
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Jul 24, 2023
1 parent bcaf8ec commit 042c87d
Show file tree
Hide file tree
Showing 21 changed files with 631 additions and 597 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,9 @@ public ConfigLoader(
String userid,
String domain
) {
// Initialize UserDatabase
this.contextRootPath = request.getContextPath();
this.initializeUserDatabase();

// Initialize portal config
portalConfig.initializePortalConfig(request);

// Initialize user config
this.initializeUserConfig(request, userid, domain);
}

Expand All @@ -104,7 +99,7 @@ private void initializeUserConfig(
if (this.domainId != null) this.userDomainUrl =
this.contextRootPath +
"/" +
PortalConfig.USERS_RELATIVE_DIR +
MainConfig.USERS_RELATIVE_DIR +
"/" +
this.getUserId() +
"/" +
Expand All @@ -120,28 +115,25 @@ private void initializeUserConfig(
if (!this.checkUser(null)) return;

this.exportUserUrl =
portalConfig.serverUrl +
portalConfig.mainConfig.serverUrl +
contextRootPath +
PortalConfig.EXPORT_SERVLET_PATH +
MainConfig.EXPORT_SERVLET_PATH +
"/" +
PortalConfig.USERS_RELATIVE_DIR +
MainConfig.USERS_RELATIVE_DIR +
"/" +
userId;
this.userDir =
portalConfig.storageDirectory +
portalConfig.storageConfig.storageDirectory +
File.separator +
PortalConfig.USERS_RELATIVE_DIR +
MainConfig.USERS_RELATIVE_DIR +
File.separator +
userId;

this.userPath =
contextRootPath + "/" + PortalConfig.USERS_RELATIVE_DIR + "/" + userId;
contextRootPath + "/" + MainConfig.USERS_RELATIVE_DIR + "/" + userId;

// Create userDir (if it doesn't exist)
File uf = new File(this.userDir);
if (!uf.exists() && !uf.mkdirs()) System.err.println(
"Cannot create user directory : " + uf.getAbsolutePath()
);
StorageConfig.createStorageDirectory(this.userDir);

// Get domain and user list
DomainController dc = new DomainController(this);
Expand All @@ -165,7 +157,7 @@ private void initializeUserConfig(
this.userDomainUrl =
this.contextRootPath +
"/" +
PortalConfig.USERS_RELATIVE_DIR +
MainConfig.USERS_RELATIVE_DIR +
"/" +
this.getUserId() +
"/" +
Expand Down Expand Up @@ -318,52 +310,57 @@ public Properties getProperties() {
// Return Properties that are currently used by catalogs & planners
public Properties getProperties(Domain domain) {
Properties props = new Properties();
StorageConfig storageConfig = portalConfig.storageConfig;
OntologyConfig ontologyConfig = portalConfig.getOntologyConfig();
MainConfig mainConfig = portalConfig.mainConfig;
if (domain != null) {
props = domain.getProperties();
if (domain.isLegacy()) return props;
props.setProperty(ONT_DIR_URL, PortalConfig.ONT_DIR_URL);
props.setProperty(ONT_DIR_URL, OntologyConfig.ONT_DIR_URL);
if (!domain.getUseSharedTripleStore()) props.setProperty(
ONT_DIR_MAP,
"file:" + domain.getDomainDirectory() + File.separator + "ontology"
);

props.setProperty("ont.data.url", portalConfig.getDataOntologyUrl());
props.setProperty("ont.data.url", ontologyConfig.getDataOntologyUrl());
props.setProperty(
"ont.component.url",
portalConfig.getComponentOntologyUrl()
ontologyConfig.getComponentOntologyUrl()
);
props.setProperty(
"ont.workflow.url",
portalConfig.getWorkflowOntologyUrl()
ontologyConfig.getWorkflowOntologyUrl()
);
props.setProperty(
"ont.execution.url",
portalConfig.getExecutionOntologyUrl()
ontologyConfig.getExecutionOntologyUrl()
);
props.setProperty(
"ont.resource.url",
ontologyConfig.getResourceOntologyUrl()
);

if (domain.getUseSharedTripleStore()) props.setProperty(
"tdb.repository.dir",
portalConfig.getTdbDirectory()
storageConfig.getTdbDirectory()
);

HashMap<String, ExeEngine> engines = portalConfig.getEngines();
ExeEngine pengine = engines.get(domain.getPlanEngine());
ExeEngine sengine = engines.get(domain.getStepEngine());
HashMap<String, ExecutionEngine> engines =
portalConfig.executionConfig.getEngines();
ExecutionEngine pengine = engines.get(domain.getPlanEngine());
ExecutionEngine sengine = engines.get(domain.getStepEngine());
props.putAll(pengine.getProperties());
props.putAll(sengine.getProperties());
} else {
props.setProperty("tdb.repository.dir", portalConfig.getTdbDirectory());
props.setProperty("tdb.repository.dir", storageConfig.getTdbDirectory());
}
props.setProperty("logs.dir", portalConfig.getLogsDirectory());
props.setProperty("dot.path", portalConfig.getDotFile());
props.setProperty(
"ont.resource.url",
portalConfig.getResourceOntologyUrl()
);
props.setProperty("logs.dir", storageConfig.getLogsDirectory());
props.setProperty("dot.path", mainConfig.getDotFile());

props.setProperty(
"lib.resource.url",
this.portalConfig.getExportCommunityUrl() + "/resource/library.owl"
this.portalConfig.mainConfig.getExportCommunityUrl() +
"/resource/library.owl"
);

if (domain != null && !domain.getUseSharedTripleStore()) props.setProperty(
Expand All @@ -380,7 +377,8 @@ public Properties getProperties(Domain domain) {

props.setProperty(
"lib.provenance.url",
this.portalConfig.getExportCommunityUrl() + "/provenance/library.owl"
this.portalConfig.mainConfig.getExportCommunityUrl() +
"/provenance/library.owl"
);

if (this.viewerId != null) props.setProperty("viewer.id", this.viewerId);
Expand All @@ -394,20 +392,24 @@ public Properties getProperties(Domain domain) {
}

public PlanExecutionEngine getDomainExecutionEngine() {
ExeEngine pengine = portalConfig.engines.get(domain.getPlanEngine());
ExeEngine sengine = portalConfig.engines.get(domain.getStepEngine());
ExecutionEngine planEngine = portalConfig.executionConfig.engines.get(
domain.getPlanEngine()
);
ExecutionEngine stepEngine = portalConfig.executionConfig.engines.get(
domain.getStepEngine()
);
try {
pengine.getProperties().putAll(this.getProperties());
sengine.getProperties().putAll(this.getProperties());
planEngine.getProperties().putAll(this.getProperties());
stepEngine.getProperties().putAll(this.getProperties());
// TODO: Check if the selected engines are compatible
// and can be used as plan and step engines respectively
PlanExecutionEngine pee = ExecutionFactory.createPlanExecutionEngine(
pengine.getImplementation(),
pengine.getProperties()
planEngine.getImplementation(),
planEngine.getProperties()
);
StepExecutionEngine see = ExecutionFactory.createStepExecutionEngine(
sengine.getImplementation(),
sengine.getProperties()
stepEngine.getImplementation(),
stepEngine.getProperties()
);
ExecutionLoggerAPI logger = ExecutionToolsFactory.createLogger(
this.getProperties()
Expand All @@ -418,7 +420,9 @@ public PlanExecutionEngine getDomainExecutionEngine() {
ExecutionResourceAPI resource = ExecutionToolsFactory.getResourceAPI(
this.getProperties()
);
resource.setLocalStorageFolder(portalConfig.getStorageDirectory());
resource.setLocalStorageFolder(
portalConfig.storageConfig.getStorageDirectory()
);
pee.setStepExecutionEngine(see);
pee.setExecutionLogger(logger);
pee.setExecutionMonitor(monitor);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package edu.isi.wings.portal.classes.config;

import java.io.File;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.configuration.plist.PropertyListConfiguration;

public class MainConfig {

public static final String MAIN_LIGHT_REASONER_KEY = "light-reasoner";
public static final String MAIN_CLIENTS_KEY = "clients";
public static final String MAIN_GRAPHVIZ_KEY = "graphviz";
public static final String MAIN_METAWORKFLOWS_KEY = "metaworkflows";
public static final String MAIN_SERVER_KEY = "server";
public static final String USERS_RELATIVE_DIR = "users";
public static final String EXPORT_SERVLET_PATH = "/export";

public String dotFile;
public String serverUrl;
public boolean hasMetaWorkflows;
public String clients;
public String contextRootPath;
public String exportCommunityUrl;

public String communityPath;

public MainConfig(
PropertyListConfiguration serverConfig,
HttpServletRequest request
) {
this.serverUrl = serverConfig.getString(MAIN_SERVER_KEY);
this.dotFile = serverConfig.getString(MAIN_GRAPHVIZ_KEY);
this.clients = serverConfig.getString(MAIN_CLIENTS_KEY);
this.contextRootPath = request.getContextPath();
if (
serverConfig.containsKey(MAIN_METAWORKFLOWS_KEY)
) this.hasMetaWorkflows = serverConfig.getBoolean(MAIN_METAWORKFLOWS_KEY);
this.exportCommunityUrl =
this.serverUrl +
contextRootPath +
EXPORT_SERVLET_PATH +
"/" +
StorageConfig.COMMUNITY_RELATIVE_DIR;
this.communityPath =
contextRootPath +
"/" +
USERS_RELATIVE_DIR +
"/" +
StorageConfig.COMMUNITY_RELATIVE_DIR;
}

public MainConfig(String defaultServer, HttpServletRequest request) {
this.serverUrl = defaultServer;
File loc1 = new File("/usr/bin/dot");
File loc2 = new File("/usr/local/bin/dot");
dotFile = loc2.exists() ? loc2.getAbsolutePath() : loc1.getAbsolutePath();
this.contextRootPath = request.getContextPath();
this.exportCommunityUrl =
this.serverUrl +
contextRootPath +
EXPORT_SERVLET_PATH +
"/" +
StorageConfig.COMMUNITY_RELATIVE_DIR;
this.communityPath =
contextRootPath +
"/" +
USERS_RELATIVE_DIR +
"/" +
StorageConfig.COMMUNITY_RELATIVE_DIR;
}

public static String getMainLightReasonerKey() {
return MAIN_LIGHT_REASONER_KEY;
}

public static String getMainClientsKey() {
return MAIN_CLIENTS_KEY;
}

public static String getMainGraphvizKey() {
return MAIN_GRAPHVIZ_KEY;
}

public static String getMainMetaworkflowsKey() {
return MAIN_METAWORKFLOWS_KEY;
}

public static String getMainServerKey() {
return MAIN_SERVER_KEY;
}

public String getDotFile() {
return dotFile;
}

public String getServerUrl() {
return serverUrl;
}

public boolean hasMetaWorkflows() {
return hasMetaWorkflows;
}

public String getClients() {
return clients;
}

public String getExportCommunityUrl() {
return exportCommunityUrl;
}

public static String getUsersRelativeDir() {
return USERS_RELATIVE_DIR;
}

public static String getExportServletPath() {
return EXPORT_SERVLET_PATH;
}

public boolean isHasMetaWorkflows() {
return hasMetaWorkflows;
}

public String getContextRootPath() {
return contextRootPath;
}

public String getCommunityPath() {
return communityPath;
}
}
Loading

0 comments on commit 042c87d

Please sign in to comment.