Skip to content

Commit

Permalink
fix: add execution configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Jul 24, 2023
1 parent 042c87d commit 53129a5
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package edu.isi.wings.portal.classes.config;

import edu.isi.wings.execution.engine.api.impl.distributed.DistributedExecutionEngine;
import edu.isi.wings.execution.engine.api.impl.local.LocalExecutionEngine;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.plist.PropertyListConfiguration;

public class ExecutionConfig {

public HashMap<String, ExecutionEngine> engines;

public ExecutionConfig(PropertyListConfiguration serverConfig) {
this.engines = new HashMap<String, ExecutionEngine>();
List<HierarchicalConfiguration> engineNodes = serverConfig.configurationsAt(
"execution.engine"
);
for (HierarchicalConfiguration engineNode : engineNodes) {
ExecutionEngine engine = this.getExeEngine(engineNode);
this.engines.put(engine.getName(), engine);
}
}

public ExecutionConfig() {
this.engines = new HashMap<String, ExecutionEngine>();
ExecutionEngine defaultLocal = new ExecutionEngine(
"Local",
LocalExecutionEngine.class.getCanonicalName(),
ExecutionEngine.Type.BOTH
);
ExecutionEngine defaultDistrubited = new ExecutionEngine(
"Distributed",
DistributedExecutionEngine.class.getCanonicalName(),
ExecutionEngine.Type.BOTH
);

this.engines.put(defaultLocal.getName(), defaultLocal);
this.engines.put(defaultDistrubited.getName(), defaultDistrubited);
}

@SuppressWarnings("rawtypes")
private ExecutionEngine getExeEngine(HierarchicalConfiguration node) {
String name = node.getString("name");
String impl = node.getString("implementation");
ExecutionEngine.Type type = ExecutionEngine.Type.valueOf(
node.getString("type")
);
ExecutionEngine engine = new ExecutionEngine(name, impl, type);
for (Iterator it = node.getKeys("properties"); it.hasNext();) {
String key = (String) it.next();
String value = node.getString(key);
engine.addProperty(key.replace("properties.", ""), value);
}
return engine;
}

public void addDefaultEngineConfig(PropertyListConfiguration config) {
// loop engines and add them to config
for (Entry<String, ExecutionEngine> entryEngine : this.engines.entrySet()) {
ExecutionEngine engine = entryEngine.getValue();
config.addProperty("execution.engine(-1).name", engine.getName());
config.addProperty(
"execution.engine.implementation",
engine.getImplementation()
);
config.addProperty("execution.engine.type", engine.getType());
for (Entry<Object, Object> entryProperty : engine
.getProperties()
.entrySet()) {
config.addProperty(
"execution.engine.properties." + entryProperty.getKey(),
entryProperty.getValue()
);
}
}
}

public HashMap<String, ExecutionEngine> getEngines() {
return engines;
}

public Set<String> getEnginesList() {
return this.engines.keySet();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package edu.isi.wings.portal.classes.config;

import java.util.Properties;

/**
* Created by varun on 13/07/2015.
*/
public class ExecutionEngine {

public static enum Type {
PLAN,
STEP,
BOTH,
}

ExecutionEngine.Type type;
String name;
String implementation;
Properties props;

public ExecutionEngine(
String name,
String implementation,
ExecutionEngine.Type type
) {
this.type = type;
this.name = name;
this.implementation = implementation;
props = new Properties();
}

public String getName() {
return name;
}

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

public ExecutionEngine.Type getType() {
return type;
}

public void setType(ExecutionEngine.Type type) {
this.type = type;
}

public String getImplementation() {
return implementation;
}

public void setImplementation(String implementation) {
this.implementation = implementation;
}

public Properties getProperties() {
return props;
}

public void setProperties(Properties props) {
this.props = props;
}

public void addProperty(String key, String value) {
this.props.setProperty(key, value);
}
}

0 comments on commit 53129a5

Please sign in to comment.