-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add execution configuration files
- Loading branch information
Showing
2 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
portal/src/main/java/edu/isi/wings/portal/classes/config/ExecutionConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
portal/src/main/java/edu/isi/wings/portal/classes/config/ExecutionEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |