Skip to content

Commit 0e3bf8c

Browse files
Devdeep SinghVijayendra Bhamidipati
authored andcommitted
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
1 parent ab768f0 commit 0e3bf8c

File tree

2 files changed

+27
-56
lines changed

2 files changed

+27
-56
lines changed

utils/src/com/cloud/utils/cisco/n1kv/vsm/NetconfHelper.java

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public class NetconfHelper {
2020

2121
private static final String SSH_NETCONF_TERMINATOR = "]]>]]>";
2222

23-
// Number of times to retry the command on failure.
24-
private static final int s_retryCount = 3;
25-
2623
private Connection _connection;
2724

2825
private Session _session;
@@ -71,28 +68,7 @@ public void addPortProfile(String name, PortProfileType type, BindingType bindin
7168
String command = VsmCommand.getAddPortProfile(name, type, binding, mode, vlanid);
7269
if (command != null) {
7370
command = command.concat(SSH_NETCONF_TERMINATOR);
74-
75-
// This command occasionally fails. On retry it succeeds. Putting in
76-
// retry to handle failures.
77-
for (int i = 0; i < s_retryCount; ++i) {
78-
send(command);
79-
// parse the rpc reply.
80-
// parseOkReply(receive());
81-
VsmOkResponse response = new VsmOkResponse(receive().trim());
82-
if (!response.isResponseOk()) {
83-
if (i >= s_retryCount) {
84-
throw new CloudRuntimeException(response.toString());
85-
}
86-
87-
try {
88-
Thread.sleep(1000);
89-
} catch (final InterruptedException e) {
90-
s_logger.debug("Got interrupted while waiting.");
91-
}
92-
} else {
93-
break;
94-
}
95-
}
71+
parseOkReply(sendAndReceive(command));
9672
} else {
9773
throw new CloudRuntimeException("Error generating rpc request for adding port profile.");
9874
}
@@ -103,9 +79,7 @@ public void updatePortProfile(String name, SwitchPortMode mode,
10379
String command = VsmCommand.getUpdatePortProfile(name, mode, params);
10480
if (command != null) {
10581
command = command.concat(SSH_NETCONF_TERMINATOR);
106-
send(command);
107-
// parse the rpc reply.
108-
parseOkReply(receive());
82+
parseOkReply(sendAndReceive(command));
10983
} else {
11084
throw new CloudRuntimeException("Error generating rpc request for updating port profile.");
11185
}
@@ -115,9 +89,7 @@ public void deletePortProfile(String name) throws CloudRuntimeException {
11589
String command = VsmCommand.getDeletePortProfile(name);
11690
if (command != null) {
11791
command = command.concat(SSH_NETCONF_TERMINATOR);
118-
send(command);
119-
// parse the rpc reply.
120-
parseOkReply(receive());
92+
parseOkReply(sendAndReceive(command));
12193
} else {
12294
throw new CloudRuntimeException("Error generating rpc request for deleting port profile.");
12395
}
@@ -128,9 +100,7 @@ public void addPolicyMap(String name, int averageRate, int maxRate, int burstRat
128100
String command = VsmCommand.getAddPolicyMap(name, averageRate, maxRate, burstRate);
129101
if (command != null) {
130102
command = command.concat(SSH_NETCONF_TERMINATOR);
131-
send(command);
132-
// parse the rpc reply.
133-
parseOkReply(receive());
103+
parseOkReply(sendAndReceive(command));
134104
} else {
135105
throw new CloudRuntimeException("Error generating rpc request for adding/updating policy map.");
136106
}
@@ -140,9 +110,7 @@ public void deletePolicyMap(String name) throws CloudRuntimeException {
140110
String command = VsmCommand.getDeletePolicyMap(name);
141111
if (command != null) {
142112
command = command.concat(SSH_NETCONF_TERMINATOR);
143-
send(command);
144-
// parse the rpc reply.
145-
parseOkReply(receive());
113+
parseOkReply(sendAndReceive(command));
146114
} else {
147115
throw new CloudRuntimeException("Error generating rpc request for deleting policy map.");
148116
}
@@ -159,9 +127,7 @@ public void attachServicePolicy(String policyMap, String portProfile)
159127
String command = VsmCommand.getServicePolicy(policyMap, portProfile, true);
160128
if (command != null) {
161129
command = command.concat(SSH_NETCONF_TERMINATOR);
162-
send(command);
163-
// parse the rpc reply.
164-
parseOkReply(receive());
130+
parseOkReply(sendAndReceive(command));
165131
} else {
166132
throw new CloudRuntimeException("Error generating rpc request for adding policy map.");
167133
}
@@ -172,9 +138,7 @@ public void detachServicePolicy(String policyMap, String portProfile)
172138
String command = VsmCommand.getServicePolicy(policyMap, portProfile, false);
173139
if (command != null) {
174140
command = command.concat(SSH_NETCONF_TERMINATOR);
175-
send(command);
176-
// parse the rpc reply.
177-
parseOkReply(receive());
141+
parseOkReply(sendAndReceive(command));
178142
} else {
179143
throw new CloudRuntimeException("Error generating rpc request for removing policy map.");
180144
}
@@ -184,12 +148,10 @@ public PortProfile getPortProfileByName(String name) throws CloudRuntimeExceptio
184148
String command = VsmCommand.getPortProfile(name);
185149
if (command != null) {
186150
command = command.concat(SSH_NETCONF_TERMINATOR);
187-
send(command);
188-
// parse the rpc reply.
189-
String received = receive();
151+
String received = sendAndReceive(command);
190152
VsmPortProfileResponse response = new VsmPortProfileResponse(received.trim());
191153
if (!response.isResponseOk()) {
192-
throw new CloudRuntimeException("Error response while getting the port profile details.");
154+
throw new CloudRuntimeException(response.toString());
193155
} else {
194156
return response.getPortProfile();
195157
}
@@ -202,12 +164,10 @@ public PolicyMap getPolicyMapByName(String name) throws CloudRuntimeException {
202164
String command = VsmCommand.getPolicyMap(name);
203165
if (command != null) {
204166
command = command.concat(SSH_NETCONF_TERMINATOR);
205-
send(command);
206-
// parse the rpc reply.
207-
String received = receive();
167+
String received = sendAndReceive(command);
208168
VsmPolicyMapResponse response = new VsmPolicyMapResponse(received.trim());
209169
if (!response.isResponseOk()) {
210-
throw new CloudRuntimeException("Error response while getting the port profile details.");
170+
throw new CloudRuntimeException(response.toString());
211171
} else {
212172
return response.getPolicyMap();
213173
}
@@ -222,6 +182,15 @@ private void exchangeHello() {
222182
send(hello);
223183
}
224184

185+
private String sendAndReceive(String command) {
186+
String received;
187+
synchronized (NetconfHelper.class) {
188+
send(command);
189+
received = receive();
190+
}
191+
return received;
192+
}
193+
225194
private void send(String message) {
226195
try {
227196
OutputStream outputStream = _session.getStdin();

utils/src/com/cloud/utils/cisco/n1kv/vsm/VsmCommand.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private static Element policyMapDetails(Document doc, String name,
527527
Element policyMapMode = doc.createElement(s_policymapmode);
528528
policyDetails.appendChild(policyMapMode);
529529

530-
// Create the default class to match all trafic.
530+
// Create the default class to match all traffic.
531531
Element classRoot = doc.createElement("class");
532532
Element classDefault = doc.createElement("class-default");
533533
policyMapMode.appendChild(classRoot);
@@ -544,11 +544,13 @@ private static Element policyMapDetails(Document doc, String name,
544544
// Set the committed information rate and its value in mbps.
545545
Element cir = doc.createElement("cir");
546546
police.appendChild(cir);
547-
Element cirValue = doc.createElement(s_paramvalue);
548-
Element mbps = doc.createElement("mbps");
549-
cirValue.setTextContent(Integer.toString(averageRate));
547+
Element cirValue = doc.createElement("cir-val");
550548
cir.appendChild(cirValue);
551-
cir.appendChild(mbps);
549+
Element value2 = doc.createElement(s_paramvalue);
550+
Element mbps = doc.createElement("mbps");
551+
value2.setTextContent(Integer.toString(averageRate));
552+
cirValue.appendChild(value2);
553+
cirValue.appendChild(mbps);
552554

553555
// Persist the configuration across reboots.
554556
modeConfigure.appendChild(persistConfiguration(doc));

0 commit comments

Comments
 (0)