cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [1/3] git commit: updated refs/heads/vpc-toolkit-hugo to 2838723
Date Fri, 11 Jul 2014 15:50:47 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/vpc-toolkit-hugo [created] 2838723df


Improve applyConfig function and make ConfigItem a separate class

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

Branch: refs/heads/vpc-toolkit-hugo
Commit: 4dcf107ad86bb893af9d3c38196190ceadf8b852
Parents: 8cf94c9
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Fri Jul 11 09:09:32 2014 +0200
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Fri Jul 11 09:09:32 2014 +0200

----------------------------------------------------------------------
 .../resource/virtualnetwork/ConfigItem.java     |  77 ++++++++
 .../virtualnetwork/VirtualRoutingResource.java  | 182 +++++--------------
 2 files changed, 124 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4dcf107a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigItem.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/ConfigItem.java b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigItem.java
new file mode 100644
index 0000000..745ecab
--- /dev/null
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/ConfigItem.java
@@ -0,0 +1,77 @@
+package com.cloud.agent.resource.virtualnetwork;
+
+public class ConfigItem {
+    private String script;
+    private String args;
+    private String info;
+    private String filePath;
+    private String fileName;
+    private String fileContents;
+    private boolean isFile;
+
+    public ConfigItem(String script, String args) {
+        this.script = script;
+        this.args = args;
+        isFile = false;
+    }
+
+    public ConfigItem(String filePath, String fileName, String fileContents) {
+        this.filePath = filePath;
+        this.fileName = fileName;
+        this.fileContents = fileContents;
+        isFile = true;
+    }
+
+    public String getScript() {
+        return script;
+    }
+
+    public void setScript(String script) {
+        this.script = script;
+    }
+
+    public String getArgs() {
+        return args;
+    }
+
+    public void setArgs(String args) {
+        this.args = args;
+    }
+
+    public String getInfo() {
+        return info;
+    }
+
+    public void setInfo(String info) {
+        this.info = info;
+    }
+
+    public String getFilePath() {
+        return filePath;
+    }
+
+    public void setFilePath(String filePath) {
+        this.filePath = filePath;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public String getFileContents() {
+        return fileContents;
+    }
+
+    public void setFileContents(String fileContents) {
+        this.fileContents = fileContents;
+    }
+
+    public boolean isFile() {
+        return isFile;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4dcf107a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
index de1049b..a56abe6 100755
--- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
+++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java
@@ -16,6 +16,27 @@
 // under the License.
 package com.cloud.agent.resource.virtualnetwork;
 
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.channels.SocketChannel;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.UUID;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+
+import com.google.gson.Gson;
+
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.BumpUpPriorityCommand;
 import com.cloud.agent.api.CheckRouterAnswer;
@@ -24,6 +45,7 @@ import com.cloud.agent.api.CheckS2SVpnConnectionsAnswer;
 import com.cloud.agent.api.CheckS2SVpnConnectionsCommand;
 import com.cloud.agent.api.GetDomRVersionAnswer;
 import com.cloud.agent.api.GetDomRVersionCmd;
+import com.cloud.agent.api.GetRouterAlertsAnswer;
 import com.cloud.agent.api.SetupGuestNetworkCommand;
 import com.cloud.agent.api.routing.AggregationControlCommand;
 import com.cloud.agent.api.routing.AggregationControlCommand.Action;
@@ -31,9 +53,8 @@ import com.cloud.agent.api.routing.CreateIpAliasCommand;
 import com.cloud.agent.api.routing.DeleteIpAliasCommand;
 import com.cloud.agent.api.routing.DhcpEntryCommand;
 import com.cloud.agent.api.routing.DnsMasqConfigCommand;
-import com.cloud.agent.api.routing.GroupAnswer;
 import com.cloud.agent.api.routing.GetRouterAlertsCommand;
-import com.cloud.agent.api.GetRouterAlertsAnswer;
+import com.cloud.agent.api.routing.GroupAnswer;
 import com.cloud.agent.api.routing.IpAliasTO;
 import com.cloud.agent.api.routing.IpAssocCommand;
 import com.cloud.agent.api.routing.IpAssocVpcCommand;
@@ -64,23 +85,6 @@ import com.cloud.network.rules.FirewallRule;
 import com.cloud.utils.ExecutionResult;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.net.NetUtils;
-import com.google.gson.Gson;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
-
-import javax.naming.ConfigurationException;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.channels.SocketChannel;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.UUID;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
 
 /**
  * VirtualNetworkResource controls and configures virtual networking
@@ -91,6 +95,9 @@ import java.util.concurrent.locks.ReentrantLock;
  *  }
  **/
 public class VirtualRoutingResource {
+    private final static String CONFIG_PERSIST_LOCATION = "/etc/cloudstack";
+    private final static String IP_ASSOCIATION_CONFIG = "ip_associations.json";
+
     protected class VRScripts {
         protected static final String S2SVPN_CHECK = "checkbatchs2svpn.sh";
         protected static final String S2SVPN_IPSEC = "ipsectunnel.sh";
@@ -139,7 +146,7 @@ public class VirtualRoutingResource {
     private String _cfgVersion = "1.0";
 
     public VirtualRoutingResource(VirtualRouterDeployer deployer) {
-        this._vrDeployer = deployer;
+        _vrDeployer = deployer;
     }
 
     public Answer executeRequest(final NetworkElementCommand cmd) {
@@ -198,81 +205,6 @@ public class VirtualRoutingResource {
         }
     }
 
-    protected class ConfigItem {
-        private String script;
-        private String args;
-        private String info;
-        private String filePath;
-        private String fileName;
-        private String fileContents;
-        private boolean isFile;
-
-        public ConfigItem(String script, String args) {
-            this.script = script;
-            this.args = args;
-            this.isFile = false;
-        }
-
-        public ConfigItem(String filePath, String fileName, String fileContents) {
-            this.filePath = filePath;
-            this.fileName = fileName;
-            this.fileContents = fileContents;
-            this.isFile = true;
-        }
-
-        public String getScript() {
-            return script;
-        }
-
-        public void setScript(String script) {
-            this.script = script;
-        }
-
-        public String getArgs() {
-            return args;
-        }
-
-        public void setArgs(String args) {
-            this.args = args;
-        }
-
-        public String getInfo() {
-            return info;
-        }
-
-        public void setInfo(String info) {
-            this.info = info;
-        }
-
-        public String getFilePath() {
-            return filePath;
-        }
-
-        public void setFilePath(String filePath) {
-            this.filePath = filePath;
-        }
-
-        public String getFileName() {
-            return fileName;
-        }
-
-        public void setFileName(String fileName) {
-            this.fileName = fileName;
-        }
-
-        public String getFileContents() {
-            return fileContents;
-        }
-
-        public void setFileContents(String fileContents) {
-            this.fileContents = fileContents;
-        }
-
-        public boolean isFile() {
-            return isFile;
-        }
-    }
-
     private Answer executeQueryCommand(NetworkElementCommand cmd) {
         if (cmd instanceof CheckRouterCommand) {
             return execute((CheckRouterCommand)cmd);
@@ -297,48 +229,25 @@ public class VirtualRoutingResource {
     }
 
     private Answer applyConfig(NetworkElementCommand cmd, List<ConfigItem> cfg) {
-        int answersCount = cmd.getAnswersCount();
-
-        // Use the last answer as final answer
-        if (answersCount == 1) {
-            ExecutionResult result = new ExecutionResult(true, "No configure to be applied");
-            for (ConfigItem c : cfg) {
-                result = applyConfigToVR(cmd, c);
-                if (!result.isSuccess()) {
-                    break;
-                }
-            }
-            return new Answer(cmd, result.isSuccess(), result.getDetails());
+        List<ExecutionResult> results = new ArrayList<ExecutionResult>();
+        List<String> details = new ArrayList<String>();
+        boolean finalResult = false;
+        for (ConfigItem configItem : cfg) {
+            ExecutionResult result = applyConfigToVR(cmd, configItem);
+            details.add(configItem.getInfo() + (result.isSuccess() ? " - success: " : " -
failed: ") + result.getDetails());
+            finalResult = result.isSuccess();
         }
 
-        ExecutionResult[] results = new ExecutionResult[answersCount];
-        String[] resultsString = new String[answersCount];
-        boolean finalResult = true;
-        int i = 0, j;
-        for (ConfigItem c : cfg) {
-            results[i] = applyConfigToVR(cmd, c);
-            if (c.getInfo() != null) {
-                if (results[i].isSuccess()) {
-                    results[i].setDetails(c.getInfo() + " - success: " + results[i].getDetails());
-                } else {
-                    results[i].setDetails(c.getInfo() + " - failed: " + results[i].getDetails());
-                }
-            }
-            i ++;
+        // Not sure why this matters, but log it anyway
+        if (cmd.getAnswersCount() != results.size()) {
+            s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing
" + cmd.getClass().getSimpleName() + " but received " + results.size());
         }
-        i = 0; j = 0;
-        while (j < answersCount) {
-            resultsString[j] = results[i].getDetails();
-            if (!results[i].isSuccess()) {
-                finalResult = false;
-            }
-            // Fill the resultsString with the last result of execution, mostly in 1:n
-            if (i < cfg.size() - 1) {
-                i ++;
-            }
-            j ++;
+
+        if (results.size() == 1) {
+            return new Answer(cmd, finalResult, results.get(0).getDetails());
+        } else {
+            return new GroupAnswer(cmd, finalResult, results.size(), details.toArray(new
String[details.size()]));
         }
-        return new GroupAnswer(cmd, finalResult, answersCount, resultsString);
     }
 
     private List<ConfigItem> generateConfig(VpnUsersCfgCommand cmd) {
@@ -608,7 +517,6 @@ public class VirtualRoutingResource {
     private List<ConfigItem> generateConfig(DeleteIpAliasCommand cmd) {
         LinkedList<ConfigItem> cfg = new LinkedList<>();
 
-        String args = "";
         StringBuffer buff = new StringBuffer();
         List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
         for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
@@ -618,7 +526,7 @@ public class VirtualRoutingResource {
             buff.append(":");
             buff.append(ipAliasTO.getNetmask());
             buff.append("-");
-         }
+        }
         //this is to ensure that thre is some argument passed to the deleteipAlias script
 when there are no revoked rules.
         buff.append("- ");
         List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
@@ -908,6 +816,10 @@ public class VirtualRoutingResource {
         LinkedList<ConfigItem> cfg = new LinkedList<>();
         ConfigItem c;
 
+        Gson gson = new Gson();
+        ConfigItem ipAssociationsFile = new ConfigItem(CONFIG_PERSIST_LOCATION, IP_ASSOCIATION_CONFIG,
gson.toJson(cmd.getIpAddresses()));
+        cfg.add(ipAssociationsFile);
+
         if (cmd instanceof IpAssocVpcCommand) {
             for (IpAddressTO ip : cmd.getIpAddresses()) {
                 String args = "";


Mime
View raw message