Skip to content

Commit cc725e5

Browse files
Ritu Sabharwalsedukull
authored andcommitted
Fixing Summary:Coverity findings for brocade-plugin
1 parent 1bfb1f6 commit cc725e5

2 files changed

Lines changed: 61 additions & 15 deletions

File tree

‎plugins/network-elements/brocade-vcs/src/com/cloud/api/response/BrocadeVcsDeviceResponse.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ public class BrocadeVcsDeviceResponse extends BaseResponse {
5151
@Param(description = "the principal switch Ip address")
5252
private String hostName;
5353

54+
public String getId() {
55+
return id;
56+
}
57+
58+
public String getPhysicalNetworkId() {
59+
return physicalNetworkId;
60+
}
61+
62+
public String getProviderName() {
63+
return providerName;
64+
}
65+
66+
public String getDeviceName() {
67+
return deviceName;
68+
}
69+
70+
public String getHostName() {
71+
return hostName;
72+
}
73+
5474
public void setId(String vcsDeviceId) {
5575
this.id = vcsDeviceId;
5676
}

‎plugins/network-elements/brocade-vcs/src/com/cloud/network/brocade/BrocadeVcsApi.java‎

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,15 @@ protected <T> boolean executeUpdateObject(T newObject, String uri) throws Brocad
334334
HttpResponse response = executeMethod(pm);
335335

336336
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {
337-
String errorMessage = responseToErrorMessage(response);
337+
338+
String errorMessage;
339+
try {
340+
errorMessage = responseToErrorMessage(response);
341+
} catch (IOException e) {
342+
s_logger.error("Failed to update object : " + e.getMessage());
343+
throw new BrocadeVcsApiException("Failed to update object : " + e.getMessage());
344+
}
345+
338346
pm.releaseConnection();
339347
s_logger.error("Failed to update object : " + errorMessage);
340348
throw new BrocadeVcsApiException("Failed to update object : " + errorMessage);
@@ -405,7 +413,15 @@ protected <T> boolean executeCreateObject(T newObject, String uri) throws Brocad
405413
HttpResponse response = executeMethod(pm);
406414

407415
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
408-
String errorMessage = responseToErrorMessage(response);
416+
417+
String errorMessage;
418+
try {
419+
errorMessage = responseToErrorMessage(response);
420+
} catch (IOException e) {
421+
s_logger.error("Failed to create object : " + e.getMessage());
422+
throw new BrocadeVcsApiException("Failed to create object : " + e.getMessage());
423+
}
424+
409425
pm.releaseConnection();
410426
s_logger.error("Failed to create object : " + errorMessage);
411427
throw new BrocadeVcsApiException("Failed to create object : " + errorMessage);
@@ -421,7 +437,6 @@ protected Output executeRetreiveStatus(String uri) throws BrocadeVcsApiException
421437
throw new BrocadeVcsApiException("Hostname/credentials are null or empty");
422438
}
423439

424-
BufferedReader br = null;
425440
String readLine = null;
426441
StringBuffer sb = null;
427442

@@ -432,14 +447,21 @@ protected Output executeRetreiveStatus(String uri) throws BrocadeVcsApiException
432447
HttpResponse response = executeMethod(pm);
433448

434449
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
435-
String errorMessage = responseToErrorMessage(response);
450+
451+
String errorMessage;
452+
try {
453+
errorMessage = responseToErrorMessage(response);
454+
} catch (IOException e) {
455+
s_logger.error("Failed to retreive status : " + e.getMessage());
456+
throw new BrocadeVcsApiException("Failed to retreive status : " + e.getMessage());
457+
}
458+
436459
pm.releaseConnection();
437460
s_logger.error("Failed to retreive status : " + errorMessage);
438461
throw new BrocadeVcsApiException("Failed to retreive status : " + errorMessage);
439462
}
440463

441-
try {
442-
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")));
464+
try (BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")))) {
443465
sb = new StringBuffer();
444466

445467
while (((readLine = br.readLine()) != null)) {
@@ -448,8 +470,8 @@ protected Output executeRetreiveStatus(String uri) throws BrocadeVcsApiException
448470

449471
}
450472
} catch (Exception e) {
451-
s_logger.error("Failed to get object : " + e.getMessage());
452-
throw new BrocadeVcsApiException("Failed to get object : " + e.getMessage());
473+
s_logger.error("Failed to retreive status : " + e.getMessage());
474+
throw new BrocadeVcsApiException("Failed to retreive status : " + e.getMessage());
453475
}
454476

455477
pm.releaseConnection();
@@ -468,7 +490,15 @@ protected void executeDeleteObject(String uri) throws BrocadeVcsApiException {
468490
HttpResponse response = executeMethod(dm);
469491

470492
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) {
471-
String errorMessage = responseToErrorMessage(response);
493+
494+
String errorMessage;
495+
try {
496+
errorMessage = responseToErrorMessage(response);
497+
} catch (IOException e) {
498+
s_logger.error("Failed to delete object : " + e.getMessage());
499+
throw new BrocadeVcsApiException("Failed to delete object : " + e.getMessage());
500+
}
501+
472502
dm.releaseConnection();
473503
s_logger.error("Failed to delete object : " + errorMessage);
474504
throw new BrocadeVcsApiException("Failed to delete object : " + errorMessage);
@@ -497,22 +527,18 @@ protected HttpResponse executeMethod(HttpRequestBase method) throws BrocadeVcsAp
497527
return response;
498528
}
499529

500-
private String responseToErrorMessage(HttpResponse response) {
530+
private String responseToErrorMessage(HttpResponse response) throws IOException {
501531

502532
if ("text/html".equals(response.getEntity().getContentType().getValue())) {
503-
try {
504533

505-
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")));
534+
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8")))) {
506535

507536
StringBuffer result = new StringBuffer();
508537
String line = "";
509538
while ((line = rd.readLine()) != null) {
510539
result.append(line);
511540
}
512-
513541
return result.toString();
514-
} catch (IOException e) {
515-
s_logger.debug("Error while loading response body", e);
516542
}
517543
}
518544
return null;

0 commit comments

Comments
 (0)