cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke4...@apache.org
Subject [3/50] git commit: CS-14956: Fixing an issue that surfaced while testing rate limiting policies. An error was getting reported during policy map creation that config operation was in progress, Added synchronization to make sure sending and receiving comm
Date Sun, 27 May 2012 22:30:43 GMT
CS-14956: Fixing an issue that surfaced while testing rate limiting
policies. An error was getting reported during policy map creation that
config operation was in progress, Added synchronization to make sure
sending and receiving commands are seralized. Also removed the retry logic
as after this change it is not needed.

Reviewed-By: Vijay


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

Branch: refs/heads/master
Commit: 0e3bf8cabb845bf10005f5fe3320544f596344ff
Parents: ab768f0
Author: Devdeep Singh <devdeep.singh@citrix.com>
Authored: Sat May 26 04:38:31 2012 +0530
Committer: Vijayendra Bhamidipati <vijayendra.bhamidipati@citrix.com>
Committed: Fri May 25 19:35:34 2012 -0700

----------------------------------------------------------------------
 .../cloud/utils/cisco/n1kv/vsm/NetconfHelper.java  |   71 ++++-----------
 .../com/cloud/utils/cisco/n1kv/vsm/VsmCommand.java |   12 ++-
 2 files changed, 27 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0e3bf8ca/utils/src/com/cloud/utils/cisco/n1kv/vsm/NetconfHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/cisco/n1kv/vsm/NetconfHelper.java b/utils/src/com/cloud/utils/cisco/n1kv/vsm/NetconfHelper.java
index 0ad368a..7561796 100644
--- a/utils/src/com/cloud/utils/cisco/n1kv/vsm/NetconfHelper.java
+++ b/utils/src/com/cloud/utils/cisco/n1kv/vsm/NetconfHelper.java
@@ -20,9 +20,6 @@ public class NetconfHelper {
 
     private static final String SSH_NETCONF_TERMINATOR = "]]>]]>";
 
-    // Number of times to retry the command on failure.
-    private static final int s_retryCount = 3;
-
     private Connection _connection;
 
     private Session _session;
@@ -71,28 +68,7 @@ public class NetconfHelper {
         String command = VsmCommand.getAddPortProfile(name, type, binding, mode, vlanid);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-
-            // This command occasionally fails. On retry it succeeds. Putting in
-            // retry to handle failures.
-            for (int i = 0; i < s_retryCount; ++i) {
-                send(command);
-                // parse the rpc reply.
-                // parseOkReply(receive());
-                VsmOkResponse response = new VsmOkResponse(receive().trim());
-                if (!response.isResponseOk()) {
-                    if (i >= s_retryCount) {
-                        throw new CloudRuntimeException(response.toString());
-                    }
-
-                    try {
-                        Thread.sleep(1000);
-                    } catch (final InterruptedException e) {
-                        s_logger.debug("Got interrupted while waiting.");
-                    }
-                } else {
-                    break;
-                }
-            }
+            parseOkReply(sendAndReceive(command));
         } else {
             throw new CloudRuntimeException("Error generating rpc request for adding port
profile.");
         }
@@ -103,9 +79,7 @@ public class NetconfHelper {
         String command = VsmCommand.getUpdatePortProfile(name, mode, params);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            parseOkReply(receive());
+            parseOkReply(sendAndReceive(command));
         } else {
             throw new CloudRuntimeException("Error generating rpc request for updating port
profile.");
         }
@@ -115,9 +89,7 @@ public class NetconfHelper {
         String command = VsmCommand.getDeletePortProfile(name);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            parseOkReply(receive());
+            parseOkReply(sendAndReceive(command));
         } else {
             throw new CloudRuntimeException("Error generating rpc request for deleting port
profile.");
         }
@@ -128,9 +100,7 @@ public class NetconfHelper {
         String command = VsmCommand.getAddPolicyMap(name, averageRate, maxRate, burstRate);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            parseOkReply(receive());
+            parseOkReply(sendAndReceive(command));
         } else {
             throw new CloudRuntimeException("Error generating rpc request for adding/updating
policy map.");
         }
@@ -140,9 +110,7 @@ public class NetconfHelper {
         String command = VsmCommand.getDeletePolicyMap(name);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            parseOkReply(receive());
+            parseOkReply(sendAndReceive(command));
         } else {
             throw new CloudRuntimeException("Error generating rpc request for deleting policy
map.");
         }
@@ -159,9 +127,7 @@ public class NetconfHelper {
         String command = VsmCommand.getServicePolicy(policyMap, portProfile, true);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            parseOkReply(receive());
+            parseOkReply(sendAndReceive(command));
         } else {
             throw new CloudRuntimeException("Error generating rpc request for adding policy
map.");
         }
@@ -172,9 +138,7 @@ public class NetconfHelper {
         String command = VsmCommand.getServicePolicy(policyMap, portProfile, false);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            parseOkReply(receive());
+            parseOkReply(sendAndReceive(command));
         } else {
             throw new CloudRuntimeException("Error generating rpc request for removing policy
map.");
         }
@@ -184,12 +148,10 @@ public class NetconfHelper {
         String command = VsmCommand.getPortProfile(name);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            String received = receive();
+            String received = sendAndReceive(command);
             VsmPortProfileResponse response = new VsmPortProfileResponse(received.trim());
             if (!response.isResponseOk()) {
-                throw new CloudRuntimeException("Error response while getting the port profile
details.");
+                throw new CloudRuntimeException(response.toString());
             } else {
                 return response.getPortProfile();
             }
@@ -202,12 +164,10 @@ public class NetconfHelper {
         String command = VsmCommand.getPolicyMap(name);
         if (command != null) {
             command = command.concat(SSH_NETCONF_TERMINATOR);
-            send(command);
-            // parse the rpc reply.
-            String received = receive();
+            String received = sendAndReceive(command);
             VsmPolicyMapResponse response = new VsmPolicyMapResponse(received.trim());
             if (!response.isResponseOk()) {
-                throw new CloudRuntimeException("Error response while getting the port profile
details.");
+                throw new CloudRuntimeException(response.toString());
             } else {
                 return response.getPolicyMap();
             }
@@ -222,6 +182,15 @@ public class NetconfHelper {
         send(hello);
     }
 
+    private String sendAndReceive(String command) {
+        String received;
+        synchronized (NetconfHelper.class) {
+            send(command);
+            received = receive();
+        }
+        return received;
+    }
+
     private void send(String message) {
         try {
             OutputStream outputStream = _session.getStdin();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/0e3bf8ca/utils/src/com/cloud/utils/cisco/n1kv/vsm/VsmCommand.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/cisco/n1kv/vsm/VsmCommand.java b/utils/src/com/cloud/utils/cisco/n1kv/vsm/VsmCommand.java
index d510d6d..1136a0e 100644
--- a/utils/src/com/cloud/utils/cisco/n1kv/vsm/VsmCommand.java
+++ b/utils/src/com/cloud/utils/cisco/n1kv/vsm/VsmCommand.java
@@ -527,7 +527,7 @@ public class VsmCommand {
         Element policyMapMode = doc.createElement(s_policymapmode);
         policyDetails.appendChild(policyMapMode);
 
-        // Create the default class to match all trafic.
+        // Create the default class to match all traffic.
         Element classRoot = doc.createElement("class");
         Element classDefault = doc.createElement("class-default");
         policyMapMode.appendChild(classRoot);
@@ -544,11 +544,13 @@ public class VsmCommand {
         // Set the committed information rate and its value in mbps.
         Element cir = doc.createElement("cir");
         police.appendChild(cir);
-        Element cirValue = doc.createElement(s_paramvalue);
-        Element mbps = doc.createElement("mbps");
-        cirValue.setTextContent(Integer.toString(averageRate));
+        Element cirValue = doc.createElement("cir-val");
         cir.appendChild(cirValue);
-        cir.appendChild(mbps);
+        Element value2 = doc.createElement(s_paramvalue);
+        Element mbps = doc.createElement("mbps");
+        value2.setTextContent(Integer.toString(averageRate));
+        cirValue.appendChild(value2);
+        cirValue.appendChild(mbps);
 
         // Persist the configuration across reboots.
         modeConfigure.appendChild(persistConfiguration(doc));


Mime
View raw message