Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Detailed error message from MAQL async execution
Browse files Browse the repository at this point in the history
  • Loading branch information
zsvoboda committed Mar 20, 2013
1 parent 3d53bfe commit 794c3c4
Showing 1 changed file with 97 additions and 9 deletions.
Expand Up @@ -1426,15 +1426,23 @@ public void executeMAQLAsync(String projectId, String maql) throws GdcRestApiExc
}
if(taskmanUri != null && taskmanUri.length()>0) {
l.debug("Checking async MAQL DDL execution status.");
String status = "";
while (!"OK".equalsIgnoreCase(status) && !"ERROR".equalsIgnoreCase(status) && !"WARNING".equalsIgnoreCase(status)) {
status = getTaskManStatus(taskmanUri);
l.debug("Async MAQL DDL status = " + status);
TaskmanStatus status = new TaskmanStatus("",new String[]{});
while (!"OK".equalsIgnoreCase(status.getStatus()) && !"ERROR".equalsIgnoreCase(status.getStatus()) &&
!"WARNING".equalsIgnoreCase(status.getStatus())) {
status = getDetailedTaskManStatus(taskmanUri);
l.debug("Async MAQL DDL status = " + status.getStatus());
Thread.sleep(Constants.POLL_INTERVAL);
}
l.info("Async MAQL DDL finished with status " + status);
if (!("OK".equalsIgnoreCase(status) || "WARNING".equalsIgnoreCase(status))) {
throw new GdcRestApiException("Async MAQL execution failed with status "+status);
l.info("Async MAQL DDL finished with status " + status.getStatus());
if (!("OK".equalsIgnoreCase(status.getStatus()) || "WARNING".equalsIgnoreCase(status.getStatus()))) {
String[] messages = status.getMessage();
String message = "";
for(String msg : messages) {
if(message.length()>0) message += "\n";
message += msg;
}
throw new GdcRestApiException("Async MAQL execution failed with status "+status.getStatus() +
". Errors: "+message);
}
}
} catch (HttpMethodException ex) {
Expand Down Expand Up @@ -3010,8 +3018,88 @@ public String getTaskManStatus(String link) throws HttpMethodException {
l.debug("TaskMan status=" + status);
return status;
} else {
l.debug("No wTaskStatus structure in the migration status!");
throw new GdcRestApiException("No wTaskStatus structure in the migration status!");
l.debug("No wTaskStatus structure in the taskman status!");
throw new GdcRestApiException("No wTaskStatus structure in the taskman status!");
}
} finally {
ptm.releaseConnection();
}
}

public static class TaskmanStatus {

private String[] message;
private String status;

public TaskmanStatus(String s, String[] m) {
this.status = s;
this.message = m;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String[] getMessage() {
return message;
}

public void setMessage(String[] message) {
this.message = message;
}

}

public TaskmanStatus getDetailedTaskManStatus(String link) throws HttpMethodException {
l.debug("Getting TaskMan status uri=" + link);
HttpMethod ptm = createGetMethod(getServerUrl() + link);
try {
String response = "";
boolean isFinished = false;
while (!isFinished) {
try {
response = executeMethodOk(ptm);
isFinished = true;
} catch (HttpMethodNotFinishedYetException e) {
l.debug("getTaskManStatus: Waiting for status");
try {
Thread.sleep(Constants.POLL_INTERVAL);
} catch (InterruptedException ex) {
// do nothing
}
}
}
JSONObject task = JSONObject.fromObject(response);
JSONObject state = task.getJSONObject("wTaskStatus");
if (state != null && !state.isNullObject() && !state.isEmpty()) {
String status = state.getString("status");
ArrayList<String> messages = new ArrayList<String>();
l.debug("TaskMan status=" + status);
JSONArray msgs = state.getJSONArray("messages");
if(msgs != null && !msgs.isEmpty()) {
for (Object msgo : msgs) {
JSONObject msg = (JSONObject)msgo;
String root = (String)msg.keys().next();
JSONObject inner = msg.getJSONObject(root);
JSONArray prms = inner.getJSONArray("parameters");
String message = inner.getString("message");
if(prms != null && !prms.isEmpty()) {
for(Object prmo : prms) {
String prm = (String)prmo;
message = message.replaceFirst("\\%s",prm);
}
}
messages.add(message);
}
}
return new TaskmanStatus(status, (String[])messages.toArray(new String[]{}));
} else {
l.debug("No wTaskStatus structure in the taskman status!");
throw new GdcRestApiException("No wTaskStatus structure in the taskman status!");
}
} finally {
ptm.releaseConnection();
Expand Down

0 comments on commit 794c3c4

Please sign in to comment.