diff --git a/test/src/com/cloud/test/demo/CloudStackHttpClient.java b/test/src/com/cloud/test/demo/CloudStackHttpClient.java index 97ae1fe4f62..2c414053f4b 100644 --- a/test/src/com/cloud/test/demo/CloudStackHttpClient.java +++ b/test/src/com/cloud/test/demo/CloudStackHttpClient.java @@ -57,14 +57,12 @@ public class CloudStackHttpClient { if(followToAsyncResult) { long startMs = System.currentTimeMillis(); - - String queryJobResult = "http://localhost:8096/client/api?command=queryAsyncJobResult&response=json&jobId="; - + JsonElement response = getChildElement(jsonElement, responseName); JsonElement jobIdEle = getChildElement(response, "jobid"); String jobId = jobIdEle.getAsString(); - queryJobResult = queryJobResult+jobId; + String queryJobResult = Demo.getQueryAsyncCommandString(jobId); while(System.currentTimeMillis() - startMs < _pollTimeoutMs) { @@ -77,9 +75,10 @@ public class CloudStackHttpClient { int jobStatus = jobStatusEle.getAsInt(); switch(jobStatus) { case 2: - throw new Exception();//queryAsyncJobResponse.getAsString("queryasyncjobresultresponse.jobresult.errorcode") + " " + - //queryAsyncJobResponse.getAsString("queryasyncjobresultresponse.jobresult.errortext")); - + JsonElement joberrorObj = getChildElement(response2,"jobresult"); + JsonElement errorCodeObj = getChildElement(joberrorObj,"errorcode"); + JsonElement errorTextObj = getChildElement(joberrorObj,"errortext"); + throw new Exception("Error: "+errorCodeObj.getAsString() + " " + errorTextObj.getAsString()); case 0 : try { Thread.sleep( _pollIntervalMs ); @@ -120,6 +119,7 @@ public class CloudStackHttpClient { } } + private JsonElement execute(String request) throws Exception { JsonParser parser = new JsonParser(); URL url = new URL(request); diff --git a/test/src/com/cloud/test/demo/Demo.java b/test/src/com/cloud/test/demo/Demo.java index 4bd5b6cb720..d1d0cddf71a 100644 --- a/test/src/com/cloud/test/demo/Demo.java +++ b/test/src/com/cloud/test/demo/Demo.java @@ -341,5 +341,13 @@ public class Demo { return url; } + public static String getQueryAsyncCommandString(String jobId){ + String req = "command=queryAsyncJobResult&response=json&jobId=" + jobId; + String url = signUrl(req, properties.getProperty("apikey"), + properties.getProperty("secretkey")); + String requestUrl = _host + url; + return requestUrl; + } + }