|
37 | 37 | import javax.net.ssl.SSLSession; |
38 | 38 | import javax.net.ssl.TrustManager; |
39 | 39 |
|
| 40 | +import com.cloud.utils.exception.CloudRuntimeException; |
40 | 41 | import com.cloud.utils.nio.TrustAllManager; |
| 42 | +import com.google.gson.JsonElement; |
41 | 43 | import org.apache.commons.httpclient.HttpStatus; |
42 | 44 | import org.apache.commons.lang3.StringUtils; |
43 | 45 | import org.apache.http.HttpResponse; |
@@ -84,6 +86,7 @@ public class RedfishClient { |
84 | 86 | private final static String ACCEPT = "accept"; |
85 | 87 | private final static String ODATA_ID = "@odata.id"; |
86 | 88 | private final static String MEMBERS = "Members"; |
| 89 | + private final static String LINKS = "Links"; |
87 | 90 | private final static String EXPECTED_HTTP_STATUS = "2XX"; |
88 | 91 | private final static int WAIT_FOR_REQUEST_RETRY = 2; |
89 | 92 |
|
@@ -306,8 +309,8 @@ public void executeComputerSystemReset(String hostAddress, RedfishResetCmd reset |
306 | 309 |
|
307 | 310 | int statusCode = response.getStatusLine().getStatusCode(); |
308 | 311 | if (statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) { |
309 | | - throw new RedfishException(String.format("Failed to get System power state for host '%s' with request '%s: %s'. The expected HTTP status code is '%s' but it got '%s'.", |
310 | | - HttpGet.METHOD_NAME, url, hostAddress, EXPECTED_HTTP_STATUS, statusCode)); |
| 312 | + throw new RedfishException(String.format("Failed to execute System power command for host by performing '%s' request on URL '%s' and host address '%s'. The expected HTTP status code is '%s' but it got '%s'.", |
| 313 | + HttpPost.METHOD_NAME, url, hostAddress, EXPECTED_HTTP_STATUS, statusCode)); |
311 | 314 | } |
312 | 315 | logger.debug(String.format("Sending ComputerSystem.Reset Command '%s' to host '%s' with request '%s %s'", resetCommand, hostAddress, HttpPost.METHOD_NAME, url)); |
313 | 316 | } |
@@ -348,9 +351,18 @@ protected String processGetSystemIdResponse(CloseableHttpResponse response) { |
348 | 351 |
|
349 | 352 | // retrieving the system ID (e.g. 'System.Embedded.1') via JsonParser: |
350 | 353 | // (...) Members":[{"@odata.id":"/redfish/v1/Systems/System.Embedded.1"}] (...) |
351 | | - JsonArray jArray = new JsonParser().parse(jsonString).getAsJsonObject().get(MEMBERS).getAsJsonArray(); |
352 | | - JsonObject jsonnObject = jArray.get(0).getAsJsonObject(); |
353 | | - String jsonObjectAsString = jsonnObject.get(ODATA_ID).getAsString(); |
| 354 | + JsonArray jArray = null; |
| 355 | + JsonElement jsonElement = new JsonParser().parse(jsonString); |
| 356 | + if (jsonElement.getAsJsonObject().get(MEMBERS) != null) { |
| 357 | + jArray = jsonElement.getAsJsonObject().get(MEMBERS).getAsJsonArray(); |
| 358 | + } else if (jsonElement.getAsJsonObject().get(LINKS) != null){ |
| 359 | + jArray = jsonElement.getAsJsonObject().get(LINKS).getAsJsonObject().get(MEMBERS).getAsJsonArray(); |
| 360 | + } |
| 361 | + if (jArray == null || jArray.size() < 1) { |
| 362 | + throw new CloudRuntimeException("Members not found in the Redfish Systems JSON, unable to determine Redfish system ID"); |
| 363 | + } |
| 364 | + JsonObject jsonObject = jArray.get(0).getAsJsonObject(); |
| 365 | + String jsonObjectAsString = jsonObject.get(ODATA_ID).getAsString(); |
354 | 366 | String[] arrayOfStrings = StringUtils.split(jsonObjectAsString, '/'); |
355 | 367 |
|
356 | 368 | return arrayOfStrings[arrayOfStrings.length - 1]; |
|
0 commit comments