Simplifying validators
[groupbasedpolicy.git] / renderers / ofoverlay / src / main / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / sf / ChainAction.java
index 8e423638e29fb4a45a712f5c65c8ebe3474ddbe0..3b249562bc67e7eaee79ca9dfe275b8a3683515d 100755 (executable)
@@ -26,6 +26,13 @@ import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeade
 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.SfcNshHeaderBuilder;
 import org.opendaylight.groupbasedpolicy.sf.actions.ChainActionDefinition;
 import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.PolicyEnforcer.PolicyPair;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcIidFactory;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader;
+import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.SfcNshHeaderBuilder;
+import org.opendaylight.groupbasedpolicy.resolver.validator.ValidationResult;
+import org.opendaylight.groupbasedpolicy.resolver.validator.ValidationResultBuilder;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
 import org.opendaylight.sfc.provider.api.SfcProviderRenderedPathAPI;
 import org.opendaylight.sfc.provider.api.SfcProviderServiceChainAPI;
 import org.opendaylight.sfc.provider.api.SfcProviderServicePathAPI;
@@ -87,7 +94,6 @@ public class ChainAction extends Action {
         if (params != null) {
             LOG.debug("updateAction: Searching for named chain");
             for (String name : params.keySet()) {
-                if (name instanceof String) {
                     if (name.equals(ChainActionDefinition.SFC_CHAIN_NAME)) {
                         chainName = (String) params.get(name);
                         if (chainName == null) {
@@ -95,7 +101,6 @@ public class ChainAction extends Action {
                             return null;
                         }
                     }
-                }
             }
         } else {
             LOG.error("updateAction: Parameters null for chain action");
@@ -249,19 +254,25 @@ public class ChainAction extends Action {
     }
 
     @Override
-    public boolean isValid(ActionInstance actionInstance) {
+    public ValidationResult validate(ActionInstance actionInstance) {
         return isValidGbpChain(actionInstance.getParameterValue());
     }
 
-    private boolean isValidGbpChain(List<ParameterValue> paramValue) {
+    private ValidationResult isValidGbpChain(List<ParameterValue> paramValue) {
         ParameterValue pv = getChainNameParameter(paramValue);
         if (pv == null) {
-            return false;
+            return new ValidationResultBuilder().failed().setMessage(
+                    "Chain parameter {" + paramValue + "} not found!").build();
         }
         SfcName sfcName = new SfcName(pv.getStringValue());
         LOG.trace("isValidGbpChain: Invoking RPC for chain {}", pv.getStringValue());
         ServiceFunctionChain chain = SfcProviderServiceChainAPI.readServiceFunctionChain(sfcName);
-        return (chain != null);
+        if (chain != null){
+            return new ValidationResultBuilder().success().build();
+        } else {
+            return new ValidationResultBuilder().failed().setMessage(
+                    "Chain named {" + pv.getStringValue() + "} not found in config DS.").build();
+        }
     }
 
     public ServiceFunctionPath getSfcPath(SfcName chainName) {