You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ke...@apache.org on 2012/05/28 00:35:41 UTC

[2/50] [abbrv] 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 receiv

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/87972750
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/87972750
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/87972750

Branch: refs/heads/3.0.x
Commit: 87972750105c76cee9cb4e99cb36cfd5eea437fb
Parents: 9af09bb
Author: Devdeep Singh <de...@citrix.com>
Authored: Sat May 26 04:38:31 2012 +0530
Committer: Devdeep Singh <de...@citrix.com>
Committed: Sat May 26 04:45:18 2012 +0530

----------------------------------------------------------------------
 .../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/87972750/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/87972750/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));