Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 41925CE78 for ; Sun, 27 May 2012 22:30:45 +0000 (UTC) Received: (qmail 87928 invoked by uid 500); 27 May 2012 22:30:44 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 87850 invoked by uid 500); 27 May 2012 22:30:44 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 87473 invoked by uid 99); 27 May 2012 22:30:43 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 May 2012 22:30:43 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8B40C183FD; Sun, 27 May 2012 22:30:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ke4qqq@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer 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 Message-Id: <20120527223043.8B40C183FD@tyr.zones.apache.org> Date: Sun, 27 May 2012 22:30:43 +0000 (UTC) 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 Authored: Sat May 26 04:38:31 2012 +0530 Committer: Vijayendra Bhamidipati 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));