Skip to content

Commit

Permalink
SCUFL2-126 Parse dispatch layers into Processor config
Browse files Browse the repository at this point in the history
  • Loading branch information
stain committed Oct 24, 2013
1 parent 6c61013 commit 4befaff
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 30 deletions.
Expand Up @@ -78,8 +78,16 @@ public void setCurrentWorkflow(Workflow currentWorkflow) {
private T2FlowParser t2FlowParser; private T2FlowParser t2FlowParser;
private Configuration currentConfiguration; private Configuration currentConfiguration;
private Configurable currentConfigurable; private Configurable currentConfigurable;
private String previousDispatchLayerName;


public final T2FlowParser getT2FlowParser() { /**
* @return the previousDispatchLayerName
*/
public String getPreviousDispatchLayerName() {
return previousDispatchLayerName;
}

public final T2FlowParser getT2FlowParser() {
return t2FlowParser; return t2FlowParser;
} }


Expand All @@ -103,5 +111,9 @@ public Configurable getCurrentConfigurable() {
public void setCurrentConfigurable(Configurable currentConfigurable) { public void setCurrentConfigurable(Configurable currentConfigurable) {
this.currentConfigurable = currentConfigurable; this.currentConfigurable = currentConfigurable;
} }

public void setPreviousDispatchLayerName(String previousDispatchLayerName) {
this.previousDispatchLayerName = previousDispatchLayerName;
}


} }
Expand Up @@ -62,7 +62,6 @@
import uk.org.taverna.scufl2.api.core.DataLink; import uk.org.taverna.scufl2.api.core.DataLink;
import uk.org.taverna.scufl2.api.core.Processor; import uk.org.taverna.scufl2.api.core.Processor;
import uk.org.taverna.scufl2.api.core.Workflow; import uk.org.taverna.scufl2.api.core.Workflow;
import uk.org.taverna.scufl2.api.dispatchstack.DispatchStackLayer;
import uk.org.taverna.scufl2.api.io.ReaderException; import uk.org.taverna.scufl2.api.io.ReaderException;
import uk.org.taverna.scufl2.api.iterationstrategy.IterationStrategyNode; import uk.org.taverna.scufl2.api.iterationstrategy.IterationStrategyNode;
import uk.org.taverna.scufl2.api.iterationstrategy.IterationStrategyStack; import uk.org.taverna.scufl2.api.iterationstrategy.IterationStrategyStack;
Expand Down Expand Up @@ -117,7 +116,8 @@


public class T2FlowParser { public class T2FlowParser {


private static final String TEXT_TURTLE = "text/turtle"; private static final URI INTERNAL_DISPATCH_PREFIX = URI.create("http://ns.taverna.org.uk/2010/scufl2/taverna/dispatchlayer/");
private static final String TEXT_TURTLE = "text/turtle";
private static final String SEMANTIC_ANNOTATION = "net.sf.taverna.t2.annotation.annotationbeans.SemanticAnnotation"; private static final String SEMANTIC_ANNOTATION = "net.sf.taverna.t2.annotation.annotationbeans.SemanticAnnotation";
private static final String IDENTIFICATION_ASSERTION = "net.sf.taverna.t2.annotation.annotationbeans.IdentificationAssertion"; private static final String IDENTIFICATION_ASSERTION = "net.sf.taverna.t2.annotation.annotationbeans.IdentificationAssertion";
private static final String T2FLOW_EXTENDED_XSD = "xsd/t2flow-extended.xsd"; private static final String T2FLOW_EXTENDED_XSD = "xsd/t2flow-extended.xsd";
Expand Down Expand Up @@ -416,26 +416,23 @@ protected enum Configures {
activity, dispatchLayer activity, dispatchLayer
}; };


protected void parseConfigurationAndAddToProfile(ConfigBean configBean, protected Configuration parseConfigurationAndAddToProfile(ConfigBean configBean,
Configures configures) throws JAXBException, ReaderException { Configures configures) throws JAXBException, ReaderException {
Configuration configuration = parseConfiguration(configBean); Configuration configuration = parseConfiguration(configBean);
if (configuration == null) { if (configuration == null) {
return; return null;
} }
if (configures == Configures.activity) { Profile profile = parserState.get().getCurrentProfile();
if (configures == Configures.activity) {
configuration.setName(parserState.get().getCurrentActivity() configuration.setName(parserState.get().getCurrentActivity()
.getName()); .getName());
profile.getConfigurations().addWithUniqueName(configuration);
configuration.setConfigures(parserState.get().getCurrentConfigurable());
} else { } else {
// TODO: Create processor JSON configuration instead // We won't add dispatch layer configs as they are
DispatchStackLayer layer = (DispatchStackLayer) parserState.get().getCurrentConfigurable(); // to be merged into the Processor config
configuration.setName(parserState.get().getCurrentProcessor().getName() +
"-dispatch-" + parserState.get().getCurrentDispatchStack().size());

} }
parserState.get().getCurrentProfile().getConfigurations() return configuration;
.addWithUniqueName(configuration);
configuration.setConfigures(parserState.get().getCurrentConfigurable());
parserState.get().getCurrentProfile().getConfigurations().addWithUniqueName(configuration);


} }


Expand Down Expand Up @@ -960,23 +957,63 @@ protected Set<DataLink> parseDatalinks(Datalinks origLinks)


protected void parseDispatchStack( protected void parseDispatchStack(
DispatchStack dispatchStack) throws ReaderException { DispatchStack dispatchStack) throws ReaderException {
for (DispatchLayer dispatchLayer : dispatchStack.getDispatchLayer()) { Processor processor = parserState.get().getCurrentProcessor();
DispatchStackLayer layer = parseDispatchStack(dispatchLayer); Configuration procConfig = scufl2Tools.createConfigurationFor(processor, parserState.get().getCurrentProfile());
newStack.add(layer); parserState.get().setCurrentConfigurable(processor);
} parserState.get().setCurrentConfiguration(procConfig);
return newStack; parserState.get().setPreviousDispatchLayerName(null);
} try {

for (DispatchLayer dispatchLayer : dispatchStack.getDispatchLayer()) {
protected DispatchStackLayer parseDispatchStack(DispatchLayer dispatchLayer) parseDispatchStack(dispatchLayer);
}
} finally {
parserState.get().setCurrentConfigurable(null);
parserState.get().setCurrentConfiguration(null);
parserState.get().setPreviousDispatchLayerName(null);
}
}

protected void parseDispatchStack(DispatchLayer dispatchLayer)
throws ReaderException { throws ReaderException {
DispatchStackLayer dispatchStackLayer = new DispatchStackLayer();
URI typeUri = mapTypeFromRaven(dispatchLayer.getRaven(), URI typeUri = mapTypeFromRaven(dispatchLayer.getRaven(),
dispatchLayer.getClazz()); dispatchLayer.getClazz());
dispatchStackLayer.setType(typeUri); ObjectNode procConfig = parserState.get().getCurrentConfiguration().getJsonAsObjectNode();
parserState.get().setCurrentConfigurable(dispatchStackLayer);
try { try {
parseConfigurationAndAddToProfile(dispatchLayer.getConfigBean(), Configuration dispatchConfig = parseConfigurationAndAddToProfile(dispatchLayer.getConfigBean(),
Configures.dispatchLayer); Configures.dispatchLayer);
URI relUri = INTERNAL_DISPATCH_PREFIX.relativize(typeUri);
String name;
if (! relUri.isAbsolute()) {
// It's an internal layer. We'll put it under the name which we'll cleverly fish out
// of the URI path, eg. "retry" or "parallelize"
name = relUri.getPath().toLowerCase();
if (dispatchConfig != null && dispatchConfig.getJson().size() > 0) {
// But only if non-empty (non-default)
procConfig.put(name, dispatchConfig.getJson());
}
} else {
ObjectNode json;
if (dispatchConfig != null && dispatchConfig.getJson().isObject()) {
json = dispatchConfig.getJsonAsObjectNode();
} else {
// We'll still need to create an objectNode to keep _type and _after
json = procConfig.objectNode();
if (dispatchConfig != null) {
// We'll put the non-objectnode here
json.put("_config", dispatchConfig.getJson());
}
}

// Not really much to go from here, we don't want to use the typeUri as the name
// as third-party layers in theory could be added several times for same type
name = UUID.randomUUID().toString();
json.put("_type", typeUri.toString());
// Might be null - meaning "top"
json.put("_after", parserState.get().getPreviousDispatchLayerName());
procConfig.put(name, json);
}
parserState.get().setPreviousDispatchLayerName(name);
} catch (JAXBException ex) { } catch (JAXBException ex) {
String message = "Can't parse configuration for dispatch layer in " String message = "Can't parse configuration for dispatch layer in "
+ parserState.get().getCurrentProcessor(); + parserState.get().getCurrentProcessor();
Expand All @@ -986,7 +1023,6 @@ protected DispatchStackLayer parseDispatchStack(DispatchLayer dispatchLayer)
} }


} }
return dispatchStackLayer;
} }


@SuppressWarnings("boxing") @SuppressWarnings("boxing")
Expand Down Expand Up @@ -1132,8 +1168,8 @@ protected Set<Processor> parseProcessors(Processors originalProcessors)
origProc.getInputPorts())); origProc.getInputPorts()));
newProc.setOutputPorts(parseProcessorOutputPorts(newProc, newProc.setOutputPorts(parseProcessorOutputPorts(newProc,
origProc.getOutputPorts())); origProc.getOutputPorts()));
newProc.setDispatchStack(parseDispatchStack(origProc parseDispatchStack(origProc
.getDispatchStack())); .getDispatchStack());
newProc.setIterationStrategyStack(parseIterationStrategyStack(origProc newProc.setIterationStrategyStack(parseIterationStrategyStack(origProc
.getIterationStrategyStack())); .getIterationStrategyStack()));
parseAnnotations(newProc, origProc.getAnnotations()); parseAnnotations(newProc, origProc.getAnnotations());
Expand Down

0 comments on commit 4befaff

Please sign in to comment.