710ca01658b09d37a98e85681723e16c7da181e5
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-yaml
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.compiler;
22
23 import java.io.InputStream;
24 import java.io.Serializable;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Map.Entry;
30
31 import org.jgrapht.DirectedGraph;
32 import org.jgrapht.graph.ClassBasedEdgeFactory;
33 import org.jgrapht.graph.DefaultEdge;
34 import org.jgrapht.graph.DirectedMultigraph;
35 import org.onap.policy.controlloop.policy.ControlLoop;
36 import org.onap.policy.controlloop.policy.ControlLoopPolicy;
37 import org.onap.policy.controlloop.policy.FinalResult;
38 import org.onap.policy.controlloop.policy.Policy;
39 import org.onap.policy.controlloop.policy.PolicyResult;
40 import org.onap.policy.controlloop.policy.TargetType;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.yaml.snakeyaml.Yaml;
44 import org.yaml.snakeyaml.constructor.Constructor;
45
46 import com.google.common.collect.ImmutableList;
47 import com.google.common.collect.ImmutableMap;
48
49 public class ControlLoopCompiler implements Serializable{
50     private static final long serialVersionUID = 1L;
51     private static Logger LOGGER = LoggerFactory.getLogger(ControlLoopCompiler.class.getName());
52     
53     public static ControlLoopPolicy compile(ControlLoopPolicy policy, ControlLoopCompilerCallback callback) throws CompilerException {
54         //
55         // Ensure the control loop is sane
56         //
57         validateControlLoop(policy.getControlLoop(), callback);
58         //
59         // Validate the policies
60         //
61         validatePolicies(policy, callback);
62         
63         return policy;
64     }
65     
66     public static ControlLoopPolicy compile(InputStream yamlSpecification, ControlLoopCompilerCallback callback) throws CompilerException {
67         Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
68         Object obj = yaml.load(yamlSpecification);
69         if (obj == null) {
70             throw new CompilerException("Could not parse yaml specification.");
71         }
72         if (! (obj instanceof ControlLoopPolicy)) {
73             throw new CompilerException("Yaml could not parse specification into required ControlLoopPolicy object");
74         }
75         return ControlLoopCompiler.compile((ControlLoopPolicy) obj, callback);
76     }
77     
78     private static void validateControlLoop(ControlLoop controlLoop, ControlLoopCompilerCallback callback) throws CompilerException {
79         if (controlLoop == null && callback != null) {
80             callback.onError("controlLoop cannot be null");
81         }
82         if (controlLoop!=null){
83             if ((controlLoop.getControlLoopName() == null || controlLoop.getControlLoopName().length() < 1) && callback != null) {
84                 callback.onError("Missing controlLoopName");
85             }
86             if ((!controlLoop.getVersion().contentEquals(ControlLoop.getVERSION())) && callback != null) {
87                 callback.onError("Unsupported version for this compiler");
88             }
89             if (controlLoop.getTrigger_policy() == null || controlLoop.getTrigger_policy().length() < 1) {
90                 throw new CompilerException("trigger_policy is not valid");
91             }
92         }
93     }
94
95     private static void validatePolicies(ControlLoopPolicy policy, ControlLoopCompilerCallback callback) throws CompilerException {
96         if (policy == null) {
97             throw new CompilerException("policy cannot be null");
98         }
99         //
100         // verify controlLoop overall timeout should be no less than the sum of operational policy timeouts
101         //
102         if (policy.getPolicies() == null) {
103             callback.onWarning("controlLoop is an open loop.");   
104         }
105         else{
106             int sum = 0;
107             for (Policy operPolicy : policy.getPolicies()) {
108                 sum += operPolicy.getTimeout().intValue();
109             }
110             if (policy.getControlLoop().getTimeout().intValue() < sum && callback != null) {
111                 callback.onError("controlLoop overall timeout is less than the sum of operational policy timeouts.");
112             }
113             //
114             // For this version we can use a directed multigraph, in the future we may not be able to
115             //
116             DirectedGraph<NodeWrapper, LabeledEdge> graph = new DirectedMultigraph<>(new ClassBasedEdgeFactory<NodeWrapper, LabeledEdge>(LabeledEdge.class));
117             //
118             // Check to see if the trigger Event is for OpenLoop, we do so by
119             // attempting to create a FinalResult object from it. If its a policy id, this should
120             // return null.
121             //
122             FinalResult triggerResult = FinalResult.toResult(policy.getControlLoop().getTrigger_policy());
123             TriggerNodeWrapper triggerNode;
124             //
125             // Did this turn into a FinalResult object?
126             //
127             if (triggerResult != null) {
128                 //
129                 // Ensure they didn't use some other FinalResult code
130                 //
131                 if (triggerResult != FinalResult.FINAL_OPENLOOP) {
132                     throw new CompilerException("Unexpected Final Result for trigger_policy, should only be " + FinalResult.FINAL_OPENLOOP.toString() + " or a valid Policy ID");
133                 }
134                 //
135                 // They really shouldn't have any policies attached.
136                 //
137                 if ((policy.getPolicies() != null || policy.getPolicies().isEmpty())&& callback != null ) {
138                     callback.onWarning("Open Loop policy contains policies. The policies will never be invoked.");
139                 }
140                 return;
141                 //
142             } else {
143                 //
144                 // Ok, not a FinalResult object so let's assume that it is a Policy. Which it should be.
145                 //
146                 triggerNode = new TriggerNodeWrapper(policy.getControlLoop().getControlLoopName());
147             }
148             //
149             // Add in the trigger node
150             //
151             graph.addVertex(triggerNode);
152             //
153             // Add in our Final Result nodes. All paths should end to these nodes.
154             //
155             FinalResultNodeWrapper finalSuccess = new FinalResultNodeWrapper(FinalResult.FINAL_SUCCESS);
156             FinalResultNodeWrapper finalFailure = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE);
157             FinalResultNodeWrapper finalFailureTimeout = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_TIMEOUT);
158             FinalResultNodeWrapper finalFailureRetries = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_RETRIES);
159             FinalResultNodeWrapper finalFailureException = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_EXCEPTION);
160             FinalResultNodeWrapper finalFailureGuard = new FinalResultNodeWrapper(FinalResult.FINAL_FAILURE_GUARD);
161             graph.addVertex(finalSuccess);
162             graph.addVertex(finalFailure);
163             graph.addVertex(finalFailureTimeout);
164             graph.addVertex(finalFailureRetries);
165             graph.addVertex(finalFailureException);
166             graph.addVertex(finalFailureGuard);
167             //
168             // Work through the policies and add them in as nodes.
169             //
170             Map<Policy, PolicyNodeWrapper> mapNodes = new HashMap<>();
171             for (Policy operPolicy : policy.getPolicies()) {
172                 //
173                 // Is it still ok to add?
174                 //
175                 if (!okToAdd(operPolicy, callback)) {
176                     //
177                     // Do not add it in
178                     //
179                     continue;
180                 }
181                 //
182                 // Create wrapper policy node and save it into our map so we can
183                 // easily retrieve it.
184                 //
185                 PolicyNodeWrapper node = new PolicyNodeWrapper(operPolicy);
186                 mapNodes.put(operPolicy, node);
187                 graph.addVertex(node);
188                 //
189                 // Is this the trigger policy?
190                 //
191                 if (operPolicy.getId().equals(policy.getControlLoop().getTrigger_policy())) {
192                     //
193                     // Yes add an edge from our trigger event node to this policy
194                     //
195                     graph.addEdge(triggerNode, node, new LabeledEdge(triggerNode, node, new TriggerEdgeWrapper("ONSET")));
196                 }
197             }
198             //
199             // last sweep to connect remaining edges for policy results
200             //
201             for (Policy operPolicy : policy.getPolicies()) {
202                 PolicyNodeWrapper node = mapNodes.get(operPolicy);
203                 //
204                 // Just ensure this has something
205                 //
206                 if (node == null) {
207                     continue;
208                 }
209                 if (FinalResult.isResult(operPolicy.getSuccess(), FinalResult.FINAL_SUCCESS)) {
210                     graph.addEdge(node, finalSuccess, new LabeledEdge(node, finalSuccess, new FinalResultEdgeWrapper(FinalResult.FINAL_SUCCESS)));
211                 } else {
212                     PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getSuccess());
213                     if (toNode == null) {
214                         throw new CompilerException("Operation Policy " + operPolicy.getId() + " success is connected to unknown policy " + operPolicy.getSuccess());
215                     } else {
216                      graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.SUCCESS)));
217                     }
218                 }
219                 if (FinalResult.isResult(operPolicy.getFailure(), FinalResult.FINAL_FAILURE)) {
220                     graph.addEdge(node, finalFailure, new LabeledEdge(node, finalFailure, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE)));
221                 } else {
222                     PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure());
223                     if (toNode == null) {
224                         throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure is connected to unknown policy " + operPolicy.getFailure());
225                     } else {
226                         graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE)));
227                     }
228                 }
229                 if (FinalResult.isResult(operPolicy.getFailure_timeout(), FinalResult.FINAL_FAILURE_TIMEOUT)) {
230                     graph.addEdge(node, finalFailureTimeout, new LabeledEdge(node, finalFailureTimeout, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_TIMEOUT)));
231                 } else {
232                     PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_timeout());
233                     if (toNode == null) {
234                         throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_timeout is connected to unknown policy " + operPolicy.getFailure_timeout());
235                     } else {
236                         graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_TIMEOUT)));
237                     }
238                 }
239                 if (FinalResult.isResult(operPolicy.getFailure_retries(), FinalResult.FINAL_FAILURE_RETRIES)) {
240                     graph.addEdge(node, finalFailureRetries, new LabeledEdge(node, finalFailureRetries, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_RETRIES)));
241                 } else {
242                     PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_retries());
243                     if (toNode == null) {
244                         throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_retries is connected to unknown policy " + operPolicy.getFailure_retries());
245                     } else {
246                         graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_RETRIES)));
247                     }
248                 }
249                 if (FinalResult.isResult(operPolicy.getFailure_exception(), FinalResult.FINAL_FAILURE_EXCEPTION)) {
250                     graph.addEdge(node, finalFailureException, new LabeledEdge(node, finalFailureException, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_EXCEPTION)));
251                 } else {
252                     PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_exception());
253                     if (toNode == null) {
254                         throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_exception is connected to unknown policy " + operPolicy.getFailure_exception());
255                     } else {
256                         graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_EXCEPTION)));
257                     }
258                 }
259                 if (FinalResult.isResult(operPolicy.getFailure_guard(), FinalResult.FINAL_FAILURE_GUARD)) {
260                     graph.addEdge(node, finalFailureGuard, new LabeledEdge(node, finalFailureGuard, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_GUARD)));
261                 } else {
262                     PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_guard());
263                     if (toNode == null) {
264                         throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_guard is connected to unknown policy " + operPolicy.getFailure_guard());
265                     } else {
266                         graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_GUARD)));
267                     }
268                 }
269             }
270             //
271             // Now validate all the nodes/edges
272             //
273             for (NodeWrapper node : graph.vertexSet()) {
274                 if (node instanceof TriggerNodeWrapper) {
275                     LOGGER.info("Trigger Node " + node.toString());
276                     if (graph.inDegreeOf(node) > 0 ) {
277                         //
278                         // Really should NEVER get here unless someone messed up the code above.
279                         //
280                         throw new CompilerException("No inputs to event trigger");
281                     }
282                     //
283                     // Should always be 1, except in the future we may support multiple events
284                     //
285                     if (graph.outDegreeOf(node) > 1) {
286                         throw new CompilerException("The event trigger should only go to ONE node");
287                     }
288                 } else if (node instanceof FinalResultNodeWrapper) {
289                     LOGGER.info("FinalResult Node " + node.toString());
290                     //
291                     // FinalResult nodes should NEVER have an out edge
292                     //
293                     if (graph.outDegreeOf(node) > 0) {
294                         throw new CompilerException("FinalResult nodes should never have any out edges.");
295                     }
296                 } else if (node instanceof PolicyNodeWrapper) {
297                     LOGGER.info("Policy Node " + node.toString());
298                     //
299                     // All Policy Nodes should have the 5 out degrees defined.
300                     //
301                     if (graph.outDegreeOf(node) != 6) {
302                         throw new CompilerException("Policy node should ALWAYS have 6 out degrees.");
303                     }
304                     //
305                     // All Policy Nodes should have at least 1 in degrees 
306                     // 
307                     if (graph.inDegreeOf(node) == 0 && callback != null) {
308                         callback.onWarning("Policy " + node.getID() + " is not reachable.");
309                     }
310                 }
311                 for (LabeledEdge edge : graph.outgoingEdgesOf(node)){
312                     LOGGER.info(edge.from.getID() + " invokes " + edge.to.getID() + " upon " + edge.edge.getID());
313                 }
314             }
315         }   
316     }
317     
318     private static boolean okToAdd(Policy operPolicy, ControlLoopCompilerCallback callback) {
319         //
320         // Check the policy id and make sure its sane
321         //
322         boolean okToAdd = true;
323         if (operPolicy.getId() == null || operPolicy.getId().length() < 1) {
324             if (callback != null) {
325                 callback.onError("Operational Policy has an bad ID");
326             }
327             okToAdd = false;
328         }
329         //
330         // Check if they decided to make the ID a result object
331         //
332         if (PolicyResult.toResult(operPolicy.getId()) != null) {
333             if (callback != null) {
334                 callback.onError("Policy id is set to a PolicyResult " + operPolicy.getId());
335             }
336             okToAdd = false;
337         }
338         if (FinalResult.toResult(operPolicy.getId()) != null) {
339             if (callback != null) {
340                 callback.onError("Policy id is set to a FinalResult " + operPolicy.getId());
341             }
342             okToAdd = false;
343         }
344         //
345         // Check that the actor/recipe/target are valid
346         // 
347         if (operPolicy.getActor() == null) {
348             if (callback != null) {
349                 callback.onError("Policy actor is null");
350             }
351             okToAdd = false;
352         }
353         //
354         // Construct a list for all valid actors
355         //
356         ImmutableList<String> actors = ImmutableList.of("APPC", "AOTS", "MSO", "SDNO", "SDNR", "AAI");
357         //
358         if (operPolicy.getActor() != null && (!actors.contains(operPolicy.getActor())) ) {
359             if (callback != null) {
360                 callback.onError("Policy actor is invalid");
361             }
362             okToAdd = false;
363         }
364         if (operPolicy.getRecipe() == null) {
365             if (callback != null) {
366                 callback.onError("Policy recipe is null");
367             }
368             okToAdd = false;
369         }
370         //
371         // NOTE: We need a way to find the acceptable recipe values (either Enum or a database that has these)
372         // 
373         ImmutableMap<String, List<String>> recipes = new ImmutableMap.Builder<String, List<String>>()
374                 .put("APPC", ImmutableList.of("Restart", "Rebuild", "Migrate", "ModifyConfig"))
375                 .put("AOTS", ImmutableList.of("checkMaintenanceWindow", "checkENodeBTicketHours", "checkEquipmentStatus", "checkEimStatus", "checkEquipmentMaintenance"))
376                 .put("MSO", ImmutableList.of("VF Module Create"))
377                 .put("SDNO", ImmutableList.of("health-diagnostic-type", "health-diagnostic", "health-diagnostic-history", "health-diagnostic-commands", "health-diagnostic-aes"))
378                 .put("SDNR", ImmutableList.of("Restart", "Reboot"))
379                 .build();
380         //
381         if (operPolicy.getRecipe() != null && (!recipes.getOrDefault(operPolicy.getActor(), Collections.emptyList()).contains(operPolicy.getRecipe()))) {
382             if (callback != null) {
383                 callback.onError("Policy recipe is invalid");
384             }
385             okToAdd = false;
386         }
387         if (operPolicy.getTarget() == null) {
388             if (callback != null) {
389                 callback.onError("Policy target is null");
390             }
391             okToAdd = false;
392         }
393         if (operPolicy.getTarget() != null && operPolicy.getTarget().getType() != TargetType.VM && operPolicy.getTarget().getType() != TargetType.VFC && operPolicy.getTarget().getType() != TargetType.PNF) {
394             if (callback != null) {
395                 callback.onError("Policy target is invalid");
396             }
397             okToAdd = false;
398         }
399         //
400         // Check that policy results are connected to either default final * or another policy
401         //
402         if (FinalResult.toResult(operPolicy.getSuccess()) != null && operPolicy.getSuccess() != FinalResult.FINAL_SUCCESS.toString()) {
403             if (callback != null) {
404                 callback.onError("Policy success is neither another policy nor FINAL_SUCCESS");
405             }
406             okToAdd = false;
407         }
408         if (FinalResult.toResult(operPolicy.getFailure()) != null && operPolicy.getFailure() != FinalResult.FINAL_FAILURE.toString()) {
409             if (callback != null) {
410                 callback.onError("Policy failure is neither another policy nor FINAL_FAILURE");
411             }
412             okToAdd = false;
413         }
414         if (FinalResult.toResult(operPolicy.getFailure_retries()) != null && operPolicy.getFailure_retries() != FinalResult.FINAL_FAILURE_RETRIES.toString()) {
415             if (callback != null) {
416                 callback.onError("Policy failure retries is neither another policy nor FINAL_FAILURE_RETRIES");
417             }
418             okToAdd = false;
419         }
420         if (FinalResult.toResult(operPolicy.getFailure_timeout()) != null && operPolicy.getFailure_timeout() != FinalResult.FINAL_FAILURE_TIMEOUT.toString()) {
421             if (callback != null) {
422                 callback.onError("Policy failure timeout is neither another policy nor FINAL_FAILURE_TIMEOUT");
423             }
424             okToAdd = false;
425         }
426         if (FinalResult.toResult(operPolicy.getFailure_exception()) != null && operPolicy.getFailure_exception() != FinalResult.FINAL_FAILURE_EXCEPTION.toString()) {
427             if (callback != null) {
428                 callback.onError("Policy failure exception is neither another policy nor FINAL_FAILURE_EXCEPTION");
429             }
430             okToAdd = false;
431         }
432         if (FinalResult.toResult(operPolicy.getFailure_guard()) != null && operPolicy.getFailure_guard() != FinalResult.FINAL_FAILURE_GUARD.toString()) {
433             if (callback != null) {
434                 callback.onError("Policy failure guard is neither another policy nor FINAL_FAILURE_GUARD");
435             }
436             okToAdd = false;
437         }
438         return okToAdd;
439     }
440
441     private static PolicyNodeWrapper findPolicyNode(Map<Policy, PolicyNodeWrapper> mapNodes, String id) {
442         for (Entry<Policy, PolicyNodeWrapper> entry : mapNodes.entrySet()) {
443             if (entry.getKey().getId().equals(id)) {
444                 return entry.getValue();
445             }
446         }
447         return null;
448     }
449     
450     @FunctionalInterface
451     private interface NodeWrapper extends Serializable{
452         public String   getID();
453     }
454     
455     private static class TriggerNodeWrapper implements NodeWrapper {
456         private static final long serialVersionUID = -187644087811478349L;
457         private String closedLoopControlName;
458         
459         public TriggerNodeWrapper(String closedLoopControlName) {
460             this.closedLoopControlName = closedLoopControlName;
461         }
462
463         @Override
464         public String toString() {
465             return "TriggerNodeWrapper [closedLoopControlName=" + closedLoopControlName + "]";
466         }
467
468         @Override
469         public String getID() {
470             return closedLoopControlName;
471         }
472         
473     }
474         
475     private static class FinalResultNodeWrapper implements NodeWrapper {
476         private static final long serialVersionUID = 8540008796302474613L;
477         private FinalResult result;
478
479         public FinalResultNodeWrapper(FinalResult result) {
480             this.result = result;
481         }
482
483         @Override
484         public String toString() {
485             return "FinalResultNodeWrapper [result=" + result + "]";
486         }
487
488         @Override
489         public String getID() {
490             return result.toString();
491         }
492     }
493     
494     private static class PolicyNodeWrapper implements NodeWrapper {
495         private static final long serialVersionUID = 8170162175653823082L;
496         private transient Policy policy;
497         
498         public PolicyNodeWrapper(Policy operPolicy) {
499             this.policy = operPolicy;
500         }
501
502         @Override
503         public String toString() {
504             return "PolicyNodeWrapper [policy=" + policy + "]";
505         }
506
507         @Override
508         public String getID() {
509             return policy.getId();
510         }
511     }
512     
513     @FunctionalInterface
514     private interface EdgeWrapper extends Serializable{
515         public String getID();
516         
517     }
518     
519     private static class TriggerEdgeWrapper implements EdgeWrapper {
520         private static final long serialVersionUID = 2678151552623278863L;
521         private String trigger;
522         
523         public TriggerEdgeWrapper(String trigger) {
524             this.trigger = trigger;
525         }
526
527         @Override
528         public String getID() {
529             return trigger;
530         }
531
532         @Override
533         public String toString() {
534             return "TriggerEdgeWrapper [trigger=" + trigger + "]";
535         }
536         
537     }
538     
539     private static class PolicyResultEdgeWrapper implements EdgeWrapper {
540         private static final long serialVersionUID = 6078569477021558310L;
541         private PolicyResult policyResult;
542
543         public PolicyResultEdgeWrapper(PolicyResult policyResult) {
544             super();
545             this.policyResult = policyResult;
546         }
547
548         @Override
549         public String toString() {
550             return "PolicyResultEdgeWrapper [policyResult=" + policyResult + "]";
551         }
552
553         @Override
554         public String getID() {
555             return policyResult.toString();
556         }
557         
558         
559     }
560     
561     private static class FinalResultEdgeWrapper implements EdgeWrapper {
562         private static final long serialVersionUID = -1486381946896779840L;
563         private FinalResult finalResult;
564         public FinalResultEdgeWrapper(FinalResult result) {
565             this.finalResult = result;
566         }
567
568         @Override
569         public String toString() {
570             return "FinalResultEdgeWrapper [finalResult=" + finalResult + "]";
571         }
572         
573         @Override
574         public String getID() {
575             return finalResult.toString();
576         }
577     }
578     
579     
580     private static class LabeledEdge extends DefaultEdge {
581         private static final long serialVersionUID = 579384429573385524L;
582         
583         private NodeWrapper from;
584         private NodeWrapper to;
585         private EdgeWrapper edge;
586         
587         public LabeledEdge(NodeWrapper from, NodeWrapper to, EdgeWrapper edge) {
588             this.from = from;
589             this.to = to;
590             this.edge = edge;
591         }
592         
593         @SuppressWarnings("unused")
594         public NodeWrapper from() {
595             return from;
596         }
597         
598         @SuppressWarnings("unused")
599         public NodeWrapper to() {
600             return to;
601         }
602         
603         @SuppressWarnings("unused")
604         public EdgeWrapper edge() {
605             return edge;
606         }
607
608         @Override
609         public String toString() {
610             return "LabeledEdge [from=" + from + ", to=" + to + ", edge=" + edge + "]";
611         }
612     }
613
614 }