Fix array index problems on the ACL command.

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/75d06e9e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/75d06e9e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/75d06e9e

Branch: refs/heads/feature/systemvm-persistent-config
Commit: 75d06e9ed7a826eff00fd6078a93cdfa05d9f4f8
Parents: 07f1ed5
Author: wilderrodrigues <wrodrig...@schubergphilis.com>
Authored: Thu Jan 29 14:55:06 2015 +0100
Committer: wilderrodrigues <wrodrig...@schubergphilis.com>
Committed: Mon Feb 16 16:08:41 2015 +0100

----------------------------------------------------------------------
 .../facade/SetNetworkAclConfigItem.java               | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/75d06e9e/core/src/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java
----------------------------------------------------------------------
diff --git 
a/core/src/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java
 
b/core/src/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java
index d1afb7c..7247766 100644
--- 
a/core/src/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java
+++ 
b/core/src/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java
@@ -22,6 +22,8 @@ package com.cloud.agent.resource.virtualnetwork.facade;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.log4j.Logger;
+
 import com.cloud.agent.api.routing.NetworkElementCommand;
 import com.cloud.agent.api.routing.SetNetworkACLCommand;
 import com.cloud.agent.api.to.NicTO;
@@ -39,6 +41,8 @@ import com.cloud.utils.net.NetUtils;
 
 public class SetNetworkAclConfigItem extends AbstractConfigItemFacade {
 
+    public static final Logger s_logger = 
Logger.getLogger(SetNetworkAclConfigItem.class.getName());
+
     @Override
     public List<ConfigItem> generateConfig(final NetworkElementCommand cmd) {
         final SetNetworkACLCommand command = (SetNetworkACLCommand) cmd;
@@ -71,7 +75,15 @@ public class SetNetworkAclConfigItem extends 
AbstractConfigItemFacade {
                 aclRule = new AllAclRule(ruleParts[4], 
"ACCEPT".equals(ruleParts[5]));
                 break;
             default:
-                aclRule = new ProtocolAclRule(ruleParts[4], 
"ACCEPT".equals(ruleParts[5]), Integer.parseInt(ruleParts[1]));
+                // Fuzzy logic in cloudstack: if we do not handle it here, it 
will throw an exception and work okay (with a stack trace on the console).
+                // If we check the size of the array, it will fail to setup 
the network.
+                // So, let's catch the exception and continue in the loop.
+                try {
+                    aclRule = new ProtocolAclRule(ruleParts[5], false, 
Integer.parseInt(ruleParts[1]));
+                } catch (final Exception e) {
+                    s_logger.warn("Problem occured when reading the entries in 
the ruleParts array. Actual array size is '" + ruleParts.length + "', but 
trying to read from index 5.");
+                    continue;
+                }
             }
             if ("Ingress".equals(ruleParts[0])) {
                 ingressRules.add(aclRule);

Reply via email to