Commit includes ControlLoopPolicy API and bugfixes
[policy/engine.git] / ECOMP-ControlloopPolicy / src / main / java / org / openecomp / policy / controlloop / compiler / ControlLoopCompiler.java
index fca2292..799371a 100644 (file)
 package org.openecomp.policy.controlloop.compiler;
 
 import java.io.InputStream;
+import java.io.Serializable;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import org.jgrapht.DirectedGraph;
 import org.jgrapht.graph.ClassBasedEdgeFactory;
 import org.jgrapht.graph.DefaultEdge;
 import org.jgrapht.graph.DirectedMultigraph;
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
 import org.openecomp.policy.controlloop.policy.ControlLoop;
 import org.openecomp.policy.controlloop.policy.ControlLoopPolicy;
 import org.openecomp.policy.controlloop.policy.FinalResult;
@@ -43,16 +47,18 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
 public class ControlLoopCompiler {
+       private static Logger LOGGER = FlexLogger.getLogger(ControlLoopCompiler.class.getName());
        
        public static ControlLoopPolicy compile(ControlLoopPolicy policy, ControlLoopCompilerCallback callback) throws CompilerException {
                //
                // Ensure the control loop is sane
                //
-               validateControlLoop(policy.controlLoop, callback);
+               validateControlLoop(policy.getControlLoop(), callback);
                //
                // Validate the policies
                //
                validatePolicies(policy, callback);
+               
                return policy;
        }
        
@@ -69,25 +75,18 @@ public class ControlLoopCompiler {
        }
        
        private static void validateControlLoop(ControlLoop controlLoop, ControlLoopCompilerCallback callback) throws CompilerException {
-               if (controlLoop == null) {
-                       if (callback != null) {
-                               callback.onError("controlLoop cannot be null");
-                       }
+               if (controlLoop == null && callback != null) {
+                       callback.onError("controlLoop cannot be null");
                }
-               if (controlLoop.controlLoopName == null | controlLoop.controlLoopName.length() < 1) {
-                       if (callback != null) {
-                               callback.onError("Missing controlLoopName");
-                       }
+               if ((controlLoop.getControlLoopName() == null || controlLoop.getControlLoopName().length() < 1) && callback != null) {
+                       callback.onError("Missing controlLoopName");
                }
-               if (! controlLoop.version.contentEquals(ControlLoop.VERSION)) {
-                       if (callback != null) {
-                               callback.onError("Unsupported version for this compiler");
-                       }
+               if ((!controlLoop.getVersion().contentEquals(ControlLoop.getVERSION())) && callback != null) {
+                       callback.onError("Unsupported version for this compiler");
                }
-               if (controlLoop.trigger_policy == null || controlLoop.trigger_policy.length() < 1) {
+               if (controlLoop.getTrigger_policy() == null || controlLoop.getTrigger_policy().length() < 1) {
                        throw new CompilerException("trigger_policy is not valid");
                }
-           //
        }
 
        private static void validatePolicies(ControlLoopPolicy policy, ControlLoopCompilerCallback callback) throws CompilerException {
@@ -97,29 +96,27 @@ public class ControlLoopCompiler {
                //
                // verify controlLoop overall timeout should be no less than the sum of operational policy timeouts
                //
-               if (policy.policies == null) {
+               if (policy.getPolicies() == null) {
             callback.onWarning("controlLoop is an open loop.");   
         }
         else{
             int sum = 0;
-                   for (Policy operPolicy : policy.policies) {
-                       sum += operPolicy.timeout.intValue();
+                   for (Policy operPolicy : policy.getPolicies()) {
+                       sum += operPolicy.getTimeout().intValue();
                    }
-                   if (policy.controlLoop.timeout.intValue() < sum) {
-                       if (callback != null) {
-                               callback.onError("controlLoop overall timeout is less than the sum of operational policy timeouts.");
-                       }
+                   if (policy.getControlLoop().getTimeout().intValue() < sum && callback != null) {
+                       callback.onError("controlLoop overall timeout is less than the sum of operational policy timeouts.");
                    }
                    //
                    // For this version we can use a directed multigraph, in the future we may not be able to
                    //
-                   DirectedGraph<NodeWrapper, LabeledEdge> graph = new DirectedMultigraph<NodeWrapper, LabeledEdge>(new ClassBasedEdgeFactory<NodeWrapper, LabeledEdge>(LabeledEdge.class));
+                   DirectedGraph<NodeWrapper, LabeledEdge> graph = new DirectedMultigraph<>(new ClassBasedEdgeFactory<NodeWrapper, LabeledEdge>(LabeledEdge.class));
                    //
                    // Check to see if the trigger Event is for OpenLoop, we do so by
                    // attempting to create a FinalResult object from it. If its a policy id, this should
                    // return null.
                    //
-                   FinalResult triggerResult = FinalResult.toResult(policy.controlLoop.trigger_policy);
+                   FinalResult triggerResult = FinalResult.toResult(policy.getControlLoop().getTrigger_policy());
                    TriggerNodeWrapper triggerNode;
                    //
                    // Did this turn into a FinalResult object?
@@ -134,10 +131,8 @@ public class ControlLoopCompiler {
                        //
                        // They really shouldn't have any policies attached.
                        //
-                       if (policy.policies != null || policy.policies.size() > 0) {
-                               if (callback != null) {
-                                       callback.onWarning("Open Loop policy contains policies. The policies will never be invoked.");
-                               }
+                       if ((policy.getPolicies() != null || policy.getPolicies().isEmpty())&& callback != null ) {
+                               callback.onWarning("Open Loop policy contains policies. The policies will never be invoked.");
                        }
                        return;
                        //
@@ -145,7 +140,7 @@ public class ControlLoopCompiler {
                        //
                        // Ok, not a FinalResult object so let's assume that it is a Policy. Which it should be.
                        //
-                       triggerNode = new TriggerNodeWrapper(policy.controlLoop.controlLoopName);
+                       triggerNode = new TriggerNodeWrapper(policy.getControlLoop().getControlLoopName());
                    }
                    //
                    // Add in the trigger node
@@ -169,132 +164,12 @@ public class ControlLoopCompiler {
                    //
                    // Work through the policies and add them in as nodes.
                    //
-                   Map<Policy, PolicyNodeWrapper> mapNodes = new HashMap<Policy, PolicyNodeWrapper>();
-                   for (Policy operPolicy : policy.policies) {
-                       //
-                       // Check the policy id and make sure its sane
-                       //
-                       boolean okToAdd = true;
-                       if (operPolicy.id == null || operPolicy.id.length() < 1) {
-                               if (callback != null) {
-                                       callback.onError("Operational Policy has an bad ID");
-                               }
-                               okToAdd = false;
-                       }
-                       //
-                       // Check if they decided to make the ID a result object
-                       //
-                       if (PolicyResult.toResult(operPolicy.id) != null) {
-                               if (callback != null) {
-                                       callback.onError("Policy id is set to a PolicyResult " + operPolicy.id);
-                               }
-                               okToAdd = false;
-                       }
-                       if (FinalResult.toResult(operPolicy.id) != null) {
-                               if (callback != null) {
-                                       callback.onError("Policy id is set to a FinalResult " + operPolicy.id);
-                               }
-                               okToAdd = false;
-                       }
-                       //
-                       // Check that the actor/recipe/target are valid
-                       // 
-                       if (operPolicy.actor == null) {
-                               if (callback != null) {
-                                       callback.onError("Policy actor is null");
-                               }
-                               okToAdd = false;
-                       }
-                       //
-                       // Construct a list for all valid actors
-                       //
-                       ImmutableList<String> actors = ImmutableList.of("APPC", "AOTS", "MSO", "SDNO", "SDNR", "AAI");
-                       //
-                       if (operPolicy.actor != null && (!actors.contains(operPolicy.actor)) ) {
-                               if (callback != null) {
-                                       callback.onError("Policy actor is invalid");
-                               }
-                               okToAdd = false;
-                       }
-                       if (operPolicy.recipe == null) {
-                               if (callback != null) {
-                                       callback.onError("Policy recipe is null");
-                               }
-                               okToAdd = false;
-                       }
-                       //
-                       // TODO:
-                       // NOTE: We need a way to find the acceptable recipe values (either Enum or a database that has these)
-                       // 
-                       ImmutableMap<String, List<String>> recipes = new ImmutableMap.Builder<String, List<String>>()
-                                               .put("APPC", ImmutableList.of("Restart", "Rebuild", "Migrate", "ModifyConfig"))
-                                       .put("AOTS", ImmutableList.of("checkMaintenanceWindow", "checkENodeBTicketHours", "checkEquipmentStatus", "checkEimStatus", "checkEquipmentMaintenance"))
-                                       .put("MSO", ImmutableList.of("VF Module Create"))
-                                       .put("SDNO", ImmutableList.of("health-diagnostic-type", "health-diagnostic", "health-diagnostic-history", "health-diagnostic-commands", "health-diagnostic-aes"))
-                                       .put("SDNR", ImmutableList.of("Restart", "Reboot"))
-                                       .build();
-                       //
-                       if (operPolicy.recipe != null && (!recipes.getOrDefault(operPolicy.actor, Collections.emptyList()).contains(operPolicy.recipe))) {
-                               if (callback != null) {
-                                       callback.onError("Policy recipe is invalid");
-                               }
-                               okToAdd = false;
-                       }
-                       if (operPolicy.target == null) {
-                               if (callback != null) {
-                                       callback.onError("Policy target is null");
-                               }
-                               okToAdd = false;
-                       }
-                       if (operPolicy.target != null && operPolicy.target.type != TargetType.VM && operPolicy.target.type != TargetType.VFC && operPolicy.target.type != TargetType.PNF) {
-                               if (callback != null) {
-                                       callback.onError("Policy target is invalid");
-                               }
-                               okToAdd = false;
-                       }
-                       //
-                       // Check that policy results are connected to either default final * or another policy
-                       //
-                       if (FinalResult.toResult(operPolicy.success) != null && operPolicy.success != FinalResult.FINAL_SUCCESS.toString()) {
-                               if (callback != null) {
-                                       callback.onError("Policy success is neither another policy nor FINAL_SUCCESS");
-                               }
-                               okToAdd = false;
-                       }
-                       if (FinalResult.toResult(operPolicy.failure) != null && operPolicy.failure != FinalResult.FINAL_FAILURE.toString()) {
-                               if (callback != null) {
-                                       callback.onError("Policy failure is neither another policy nor FINAL_FAILURE");
-                               }
-                               okToAdd = false;
-                       }
-                       if (FinalResult.toResult(operPolicy.failure_retries) != null && operPolicy.failure_retries != FinalResult.FINAL_FAILURE_RETRIES.toString()) {
-                               if (callback != null) {
-                                       callback.onError("Policy failure retries is neither another policy nor FINAL_FAILURE_RETRIES");
-                               }
-                               okToAdd = false;
-                       }
-                       if (FinalResult.toResult(operPolicy.failure_timeout) != null && operPolicy.failure_timeout != FinalResult.FINAL_FAILURE_TIMEOUT.toString()) {
-                               if (callback != null) {
-                                       callback.onError("Policy failure timeout is neither another policy nor FINAL_FAILURE_TIMEOUT");
-                               }
-                               okToAdd = false;
-                       }
-                       if (FinalResult.toResult(operPolicy.failure_exception) != null && operPolicy.failure_exception != FinalResult.FINAL_FAILURE_EXCEPTION.toString()) {
-                               if (callback != null) {
-                                       callback.onError("Policy failure exception is neither another policy nor FINAL_FAILURE_EXCEPTION");
-                               }
-                               okToAdd = false;
-                       }
-                       if (FinalResult.toResult(operPolicy.failure_guard) != null && operPolicy.failure_guard != FinalResult.FINAL_FAILURE_GUARD.toString()) {
-                               if (callback != null) {
-                                       callback.onError("Policy failure guard is neither another policy nor FINAL_FAILURE_GUARD");
-                               }
-                               okToAdd = false;
-                       }
+                   Map<Policy, PolicyNodeWrapper> mapNodes = new HashMap<>();
+                   for (Policy operPolicy : policy.getPolicies()) {
                        //
                        // Is it still ok to add?
                        //
-                       if (okToAdd == false) {
+                       if (!okToAdd(operPolicy, callback)) {
                                //
                                // Do not add it in
                                //
@@ -310,7 +185,7 @@ public class ControlLoopCompiler {
                        //
                        // Is this the trigger policy?
                        //
-                       if (operPolicy.id.equals(policy.controlLoop.trigger_policy)) {
+                       if (operPolicy.getId().equals(policy.getControlLoop().getTrigger_policy())) {
                                //
                                // Yes add an edge from our trigger event node to this policy
                                //
@@ -320,7 +195,7 @@ public class ControlLoopCompiler {
                    //
                    // last sweep to connect remaining edges for policy results
                    //
-                   for (Policy operPolicy : policy.policies) {
+                   for (Policy operPolicy : policy.getPolicies()) {
                        PolicyNodeWrapper node = mapNodes.get(operPolicy);
                        //
                        // Just ensure this has something
@@ -328,62 +203,62 @@ public class ControlLoopCompiler {
                        if (node == null) {
                                continue;
                        }
-                       if (FinalResult.isResult(operPolicy.success, FinalResult.FINAL_SUCCESS)) {
+                       if (FinalResult.isResult(operPolicy.getSuccess(), FinalResult.FINAL_SUCCESS)) {
                                graph.addEdge(node, finalSuccess, new LabeledEdge(node, finalSuccess, new FinalResultEdgeWrapper(FinalResult.FINAL_SUCCESS)));
                        } else {
-                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.success);
+                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getSuccess());
                                if (toNode == null) {
-                                       throw new CompilerException("Operation Policy " + operPolicy.id + " success is connected to unknown policy " + operPolicy.success);
+                                       throw new CompilerException("Operation Policy " + operPolicy.getId() + " success is connected to unknown policy " + operPolicy.getSuccess());
                                } else {
                                 graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.SUCCESS)));
                                }
                        }
-                       if (FinalResult.isResult(operPolicy.failure, FinalResult.FINAL_FAILURE)) {
+                       if (FinalResult.isResult(operPolicy.getFailure(), FinalResult.FINAL_FAILURE)) {
                                graph.addEdge(node, finalFailure, new LabeledEdge(node, finalFailure, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE)));
                        } else {
-                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.failure);
+                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure());
                                if (toNode == null) {
-                                       throw new CompilerException("Operation Policy " + operPolicy.id + " failure is connected to unknown policy " + operPolicy.failure);
+                                       throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure is connected to unknown policy " + operPolicy.getFailure());
                                } else {
                                        graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE)));
                                }
                        }
-                       if (FinalResult.isResult(operPolicy.failure_timeout, FinalResult.FINAL_FAILURE_TIMEOUT)) {
+                       if (FinalResult.isResult(operPolicy.getFailure_timeout(), FinalResult.FINAL_FAILURE_TIMEOUT)) {
                                graph.addEdge(node, finalFailureTimeout, new LabeledEdge(node, finalFailureTimeout, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_TIMEOUT)));
                        } else {
-                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.failure_timeout);
+                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_timeout());
                                if (toNode == null) {
-                                       throw new CompilerException("Operation Policy " + operPolicy.id + " failure_timeout is connected to unknown policy " + operPolicy.failure_timeout);
+                                       throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_timeout is connected to unknown policy " + operPolicy.getFailure_timeout());
                                } else {
                                        graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_TIMEOUT)));
                                }
                        }
-                       if (FinalResult.isResult(operPolicy.failure_retries, FinalResult.FINAL_FAILURE_RETRIES)) {
+                       if (FinalResult.isResult(operPolicy.getFailure_retries(), FinalResult.FINAL_FAILURE_RETRIES)) {
                                graph.addEdge(node, finalFailureRetries, new LabeledEdge(node, finalFailureRetries, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_RETRIES)));
                        } else {
-                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.failure_retries);
+                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_retries());
                                if (toNode == null) {
-                                       throw new CompilerException("Operation Policy " + operPolicy.id + " failure_retries is connected to unknown policy " + operPolicy.failure_retries);
+                                       throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_retries is connected to unknown policy " + operPolicy.getFailure_retries());
                                } else {
                                        graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_RETRIES)));
                                }
                        }
-                       if (FinalResult.isResult(operPolicy.failure_exception, FinalResult.FINAL_FAILURE_EXCEPTION)) {
+                       if (FinalResult.isResult(operPolicy.getFailure_exception(), FinalResult.FINAL_FAILURE_EXCEPTION)) {
                                graph.addEdge(node, finalFailureException, new LabeledEdge(node, finalFailureException, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_EXCEPTION)));
                        } else {
-                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.failure_exception);
+                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_exception());
                                if (toNode == null) {
-                                       throw new CompilerException("Operation Policy " + operPolicy.id + " failure_exception is connected to unknown policy " + operPolicy.failure_exception);
+                                       throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_exception is connected to unknown policy " + operPolicy.getFailure_exception());
                                } else {
                                        graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_EXCEPTION)));
                                }
                        }
-                       if (FinalResult.isResult(operPolicy.failure_guard, FinalResult.FINAL_FAILURE_GUARD)) {
+                       if (FinalResult.isResult(operPolicy.getFailure_guard(), FinalResult.FINAL_FAILURE_GUARD)) {
                                graph.addEdge(node, finalFailureGuard, new LabeledEdge(node, finalFailureGuard, new FinalResultEdgeWrapper(FinalResult.FINAL_FAILURE_GUARD)));
                        } else {
-                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.failure_guard);
+                               PolicyNodeWrapper toNode = findPolicyNode(mapNodes, operPolicy.getFailure_guard());
                                if (toNode == null) {
-                                       throw new CompilerException("Operation Policy " + operPolicy.id + " failure_guard is connected to unknown policy " + operPolicy.failure_guard);
+                                       throw new CompilerException("Operation Policy " + operPolicy.getId() + " failure_guard is connected to unknown policy " + operPolicy.getFailure_guard());
                                } else {
                                        graph.addEdge(node, toNode, new LabeledEdge(node, toNode, new PolicyResultEdgeWrapper(PolicyResult.FAILURE_GUARD)));
                                }
@@ -394,7 +269,7 @@ public class ControlLoopCompiler {
                    //
                    for (NodeWrapper node : graph.vertexSet()) {
                        if (node instanceof TriggerNodeWrapper) {
-                               System.out.println("Trigger Node " + node.toString());
+                               LOGGER.info("Trigger Node " + node.toString());
                                if (graph.inDegreeOf(node) > 0 ) {
                                        //
                                        // Really should NEVER get here unless someone messed up the code above.
@@ -408,7 +283,7 @@ public class ControlLoopCompiler {
                                        throw new CompilerException("The event trigger should only go to ONE node");
                                }
                        } else if (node instanceof FinalResultNodeWrapper) {
-                               System.out.println("FinalResult Node " + node.toString());
+                               LOGGER.info("FinalResult Node " + node.toString());
                                //
                                // FinalResult nodes should NEVER have an out edge
                                //
@@ -416,7 +291,7 @@ public class ControlLoopCompiler {
                                        throw new CompilerException("FinalResult nodes should never have any out edges.");
                                }
                        } else if (node instanceof PolicyNodeWrapper) {
-                               System.out.println("Policy Node " + node.toString());
+                               LOGGER.info("Policy Node " + node.toString());
                                //
                                // All Policy Nodes should have the 5 out degrees defined.
                                //
@@ -424,38 +299,159 @@ public class ControlLoopCompiler {
                                        throw new CompilerException("Policy node should ALWAYS have 6 out degrees.");
                                }
                                //
-                               // Chenfei: All Policy Nodes should have at least 1 in degrees 
+                               // All Policy Nodes should have at least 1 in degrees 
                                // 
-                               if (graph.inDegreeOf(node) == 0) {
-                                       if (callback != null) {
-                                               callback.onWarning("Policy " + node.getID() + " is not reachable.");
-                                       }
+                               if (graph.inDegreeOf(node) == 0 && callback != null) {
+                                       callback.onWarning("Policy " + node.getID() + " is not reachable.");
                                }
                        }
                        for (LabeledEdge edge : graph.outgoingEdgesOf(node)){
-                               System.out.println(edge.from.getID() + " invokes " + edge.to.getID() + " upon " + edge.edge.getID());
+                               LOGGER.info(edge.from.getID() + " invokes " + edge.to.getID() + " upon " + edge.edge.getID());
                        }
                    }
            }   
        }
        
+       private static boolean okToAdd(Policy operPolicy, ControlLoopCompilerCallback callback) {
+               //
+       // Check the policy id and make sure its sane
+       //
+       boolean okToAdd = true;
+       if (operPolicy.getId() == null || operPolicy.getId().length() < 1) {
+               if (callback != null) {
+                       callback.onError("Operational Policy has an bad ID");
+               }
+               okToAdd = false;
+       }
+       //
+       // Check if they decided to make the ID a result object
+       //
+       if (PolicyResult.toResult(operPolicy.getId()) != null) {
+               if (callback != null) {
+                       callback.onError("Policy id is set to a PolicyResult " + operPolicy.getId());
+               }
+               okToAdd = false;
+       }
+       if (FinalResult.toResult(operPolicy.getId()) != null) {
+               if (callback != null) {
+                       callback.onError("Policy id is set to a FinalResult " + operPolicy.getId());
+               }
+               okToAdd = false;
+       }
+       //
+       // Check that the actor/recipe/target are valid
+       // 
+       if (operPolicy.getActor() == null) {
+               if (callback != null) {
+                       callback.onError("Policy actor is null");
+               }
+               okToAdd = false;
+       }
+       //
+       // Construct a list for all valid actors
+       //
+       ImmutableList<String> actors = ImmutableList.of("APPC", "AOTS", "MSO", "SDNO", "SDNR", "AAI");
+       //
+       if (operPolicy.getActor() != null && (!actors.contains(operPolicy.getActor())) ) {
+               if (callback != null) {
+                       callback.onError("Policy actor is invalid");
+               }
+               okToAdd = false;
+       }
+       if (operPolicy.getRecipe() == null) {
+               if (callback != null) {
+                       callback.onError("Policy recipe is null");
+               }
+               okToAdd = false;
+       }
+       //
+       // NOTE: We need a way to find the acceptable recipe values (either Enum or a database that has these)
+       // 
+       ImmutableMap<String, List<String>> recipes = new ImmutableMap.Builder<String, List<String>>()
+                               .put("APPC", ImmutableList.of("Restart", "Rebuild", "Migrate", "ModifyConfig"))
+                       .put("AOTS", ImmutableList.of("checkMaintenanceWindow", "checkENodeBTicketHours", "checkEquipmentStatus", "checkEimStatus", "checkEquipmentMaintenance"))
+                       .put("MSO", ImmutableList.of("VF Module Create"))
+                       .put("SDNO", ImmutableList.of("health-diagnostic-type", "health-diagnostic", "health-diagnostic-history", "health-diagnostic-commands", "health-diagnostic-aes"))
+                       .put("SDNR", ImmutableList.of("Restart", "Reboot"))
+                       .build();
+       //
+       if (operPolicy.getRecipe() != null && (!recipes.getOrDefault(operPolicy.getActor(), Collections.emptyList()).contains(operPolicy.getRecipe()))) {
+               if (callback != null) {
+                       callback.onError("Policy recipe is invalid");
+               }
+               okToAdd = false;
+       }
+       if (operPolicy.getTarget() == null) {
+               if (callback != null) {
+                       callback.onError("Policy target is null");
+               }
+               okToAdd = false;
+       }
+       if (operPolicy.getTarget() != null && operPolicy.getTarget().getType() != TargetType.VM && operPolicy.getTarget().getType() != TargetType.VFC && operPolicy.getTarget().getType() != TargetType.PNF) {
+               if (callback != null) {
+                       callback.onError("Policy target is invalid");
+               }
+               okToAdd = false;
+       }
+       //
+       // Check that policy results are connected to either default final * or another policy
+       //
+       if (FinalResult.toResult(operPolicy.getSuccess()) != null && operPolicy.getSuccess() != FinalResult.FINAL_SUCCESS.toString()) {
+               if (callback != null) {
+                       callback.onError("Policy success is neither another policy nor FINAL_SUCCESS");
+               }
+               okToAdd = false;
+       }
+       if (FinalResult.toResult(operPolicy.getFailure()) != null && operPolicy.getFailure() != FinalResult.FINAL_FAILURE.toString()) {
+               if (callback != null) {
+                       callback.onError("Policy failure is neither another policy nor FINAL_FAILURE");
+               }
+               okToAdd = false;
+       }
+       if (FinalResult.toResult(operPolicy.getFailure_retries()) != null && operPolicy.getFailure_retries() != FinalResult.FINAL_FAILURE_RETRIES.toString()) {
+               if (callback != null) {
+                       callback.onError("Policy failure retries is neither another policy nor FINAL_FAILURE_RETRIES");
+               }
+               okToAdd = false;
+       }
+       if (FinalResult.toResult(operPolicy.getFailure_timeout()) != null && operPolicy.getFailure_timeout() != FinalResult.FINAL_FAILURE_TIMEOUT.toString()) {
+               if (callback != null) {
+                       callback.onError("Policy failure timeout is neither another policy nor FINAL_FAILURE_TIMEOUT");
+               }
+               okToAdd = false;
+       }
+       if (FinalResult.toResult(operPolicy.getFailure_exception()) != null && operPolicy.getFailure_exception() != FinalResult.FINAL_FAILURE_EXCEPTION.toString()) {
+               if (callback != null) {
+                       callback.onError("Policy failure exception is neither another policy nor FINAL_FAILURE_EXCEPTION");
+               }
+               okToAdd = false;
+       }
+       if (FinalResult.toResult(operPolicy.getFailure_guard()) != null && operPolicy.getFailure_guard() != FinalResult.FINAL_FAILURE_GUARD.toString()) {
+               if (callback != null) {
+                       callback.onError("Policy failure guard is neither another policy nor FINAL_FAILURE_GUARD");
+               }
+               okToAdd = false;
+       }
+       return okToAdd;
+       }
+
        private static PolicyNodeWrapper findPolicyNode(Map<Policy, PolicyNodeWrapper> mapNodes, String id) {
-               for (Policy key : mapNodes.keySet()) {
-                       if (key.id.equals(id)) {
-                               return mapNodes.get(key);
+               for (Entry<Policy, PolicyNodeWrapper> entry : mapNodes.entrySet()) {
+                       if (entry.getKey().getId().equals(id)) {
+                               return entry.getValue();
                        }
                }
                return null;
        }
-
-       private interface NodeWrapper {
-               
+       
+       @FunctionalInterface
+       private interface NodeWrapper extends Serializable{
                public String   getID();
-               
        }
        
        private static class TriggerNodeWrapper implements NodeWrapper {
-               public String closedLoopControlName;
+               private static final long serialVersionUID = -187644087811478349L;
+               private String closedLoopControlName;
                
                public TriggerNodeWrapper(String closedLoopControlName) {
                        this.closedLoopControlName = closedLoopControlName;
@@ -474,8 +470,8 @@ public class ControlLoopCompiler {
        }
                
        private static class FinalResultNodeWrapper implements NodeWrapper {
-
-               public FinalResult result;
+               private static final long serialVersionUID = 8540008796302474613L;
+               private FinalResult result;
 
                public FinalResultNodeWrapper(FinalResult result) {
                        this.result = result;
@@ -493,8 +489,8 @@ public class ControlLoopCompiler {
        }
        
        private static class PolicyNodeWrapper implements NodeWrapper {
-
-               public Policy policy;
+               private static final long serialVersionUID = 8170162175653823082L;
+               private Policy policy;
                
                public PolicyNodeWrapper(Policy operPolicy) {
                        this.policy = operPolicy;
@@ -507,18 +503,18 @@ public class ControlLoopCompiler {
 
                @Override
                public String getID() {
-                       return policy.id;
+                       return policy.getId();
                }
        }
        
-       private interface EdgeWrapper {
-               
+       @FunctionalInterface
+       private interface EdgeWrapper extends Serializable{
                public String getID();
                
        }
        
        private static class TriggerEdgeWrapper implements EdgeWrapper {
-               
+               private static final long serialVersionUID = 2678151552623278863L;
                private String trigger;
                
                public TriggerEdgeWrapper(String trigger) {
@@ -538,7 +534,8 @@ public class ControlLoopCompiler {
        }
        
        private static class PolicyResultEdgeWrapper implements EdgeWrapper {
-               public PolicyResult policyResult;
+               private static final long serialVersionUID = 6078569477021558310L;
+               private PolicyResult policyResult;
 
                public PolicyResultEdgeWrapper(PolicyResult policyResult) {
                        super();
@@ -559,8 +556,8 @@ public class ControlLoopCompiler {
        }
        
        private static class FinalResultEdgeWrapper implements EdgeWrapper {
-
-               public FinalResult finalResult;
+               private static final long serialVersionUID = -1486381946896779840L;
+               private FinalResult finalResult;
                public FinalResultEdgeWrapper(FinalResult result) {
                        this.finalResult = result;
                }
@@ -578,10 +575,6 @@ public class ControlLoopCompiler {
        
        
        private static class LabeledEdge extends DefaultEdge {
-
-               /**
-                * 
-                */
                private static final long serialVersionUID = 579384429573385524L;
                
                private NodeWrapper from;