1
2
3
4
5
6
7 package net.kwfgrid.gwes.operationmapper;
8
9 import net.kwfgrid.gworkflowdl.structure.Operation;
10 import org.apache.log4j.Logger;
11 import net.kwfgrid.gwes.GenericWorkflowHandler;
12 import net.kwfgrid.gwes.Constants;
13 import net.kwfgrid.gwes.exception.OperationMapperException;
14 import net.kwfgrid.gwes.exception.StateTransitionException;
15 import net.kwfgrid.gworkflowdl.structure.Transition;
16 import net.kwfgrid.gworkflowdl.structure.Workflow;
17 import net.kwfgrid.gworkflowdl.structure.OperationClass;
18 import de.fraunhofer.first.resmatch.client.ResourceMatcherClient;
19
20 import java.util.ArrayList;
21
22
23
24
25
26
27
28 public class Yellow2BlueResourceMatcherOperationMapper extends OperationMapper {
29
30
31
32
33 final static Logger logger = Logger.getLogger(Yellow2BlueResourceMatcherOperationMapper.class);
34
35
36
37
38
39
40
41 public boolean processTransition(GenericWorkflowHandler handler, Transition transition) throws OperationMapperException {
42 if (transition.getAbstractionLevel() != Operation.YELLOW) {
43 logger.warn("Invoked Yellow2BlueResourceMatcherOperationMapper for operation on transition \""+transition.getID()+"\" that is not Yellow! ");
44 return false;
45 }
46 boolean modification = false;
47 if (!(handler.getWorkflow() instanceof Workflow))
48 throw new OperationMapperException("Workflow class not supported.");
49
50 Workflow workflow = (Workflow) handler.getWorkflow();
51 String operationClass = ((OperationClass) transition.getOperation().get()).getName();
52 logger.info("processing yellow transition \"" + transition.getID() + "\" ...");
53
54 if (transition.getProperties().get(Constants.PROP_TRANSITION_RESOURCEMATCHER_REFINEMENT_FAILED) != null
55 || transition.getProperties().get(Constants.PROP_TRANSITION_YELLOW2BLUE_REFINEMENT_FAILED) != null) {
56 logger.warn("This workflow contains yellow transitions that cannot be refined automatically. There are no matching operation and resource instances registered for operation class \"" + operationClass + "\"");
57 workflow.getProperties().put(Constants.PROP_WARN_ + handler.createNewErrorID(),
58 "This workflow contains yellow transitions that cannot be refined automatically. There are no matching operation and resource instances registered for operation class \"" + operationClass + "\"");
59 try {
60 handler.suspendWorkflowAsync();
61 } catch (StateTransitionException e) {
62 logger.warn("exception:\n" + e, e);
63 }
64
65 transition.getProperties().remove("resourcematcher.refinement.failed");
66 transition.getProperties().remove("yellow2blue.refinement.failed");
67 } else {
68 try {
69 logger.info("Workflow refinement: invoking ResourceMatcher (yellow -> blue) ...");
70
71 String newWorkflow = ResourceMatcherClient.getInstance().match(handler.getWorkflowDescription());
72 if (newWorkflow == null) {
73 logger.warn("This workflow contains yellow transitions that cannot be refined automatically. The resource matcher returned \"null\" for operation class \"" + operationClass + "\"");
74 workflow.getProperties().put(Constants.PROP_WARN_ + handler.createNewErrorID(),
75 "This workflow contains yellow transitions that cannot be refined automatically. The resource matcher returned \"null\" for operation class \"" + operationClass + "\"");
76 handler.suspendWorkflowAsync();
77
78
79
80
81 } else if (newWorkflow.startsWith("<soapenv:Fault")) {
82 logger.warn("This workflow contains yellow transitions that cannot be refined automatically due transition an error with the resource matcher.");
83 workflow.getProperties().put(Constants.PROP_WARN_ + handler.createNewErrorID(),
84 "This workflow contains yellow transitions that cannot be refined automatically due transition an error with the resource matcher.");
85 handler.suspendWorkflowAsync();
86 } else {
87
88 handler.setWorkflowDescription(newWorkflow);
89 modification = true;
90 logger.info("Workflow refinement by ResourceMatcher done.");
91 if (logger.isDebugEnabled())
92 logger.debug("==========> new ResourceMatcher Workflow <==========\n" + newWorkflow);
93 }
94 } catch (Exception e) {
95 logger.error("Invocation of ResourceMatcher failed: " + e, e);
96 try {
97 handler.abortWorkflowAsync();
98 } catch (StateTransitionException e1) {
99 logger.error("exception:\n" + e1, e1);
100 }
101 workflow.getProperties().put(Constants.PROP_ERROR_ + handler.createNewErrorID(), "Invocation of ResourceMatcher failed: " + e);
102 }
103 }
104
105 return modification;
106 }
107
108
109
110
111
112
113
114
115
116
117 public boolean processTransitions(GenericWorkflowHandler handler, ArrayList<Transition> transitions) throws OperationMapperException {
118
119 return false;
120 }
121 }