bug 6168: throw a runtime exception when unable to schedule Async job instead of returning jobId=0L

status 6168: resolved fixed
This commit is contained in:
alena 2010-12-27 16:05:10 -08:00
parent 719f3984d2
commit 7b3b9076b0
3 changed files with 38 additions and 24 deletions

View File

@ -82,11 +82,11 @@ public class ApiDispatcher {
s_logger.info(t.getMessage());
errorMsg = "Parameter error";
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
}else if (t instanceof PermissionDeniedException) {
} else if (t instanceof PermissionDeniedException) {
s_logger.info("PermissionDenied: " + t.getMessage());
errorMsg = "Permission denied";
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
}else if (t instanceof AccountLimitException) {
} else if (t instanceof AccountLimitException) {
s_logger.info(t.getMessage());
errorMsg = "Account resource limit error";
throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
@ -94,24 +94,27 @@ public class ApiDispatcher {
s_logger.info(t.getMessage());
errorMsg = "Insufficient capacity";
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
}else if (t instanceof ResourceAllocationException) {
} else if (t instanceof ResourceAllocationException) {
s_logger.info(t.getMessage());
errorMsg = "Resource allocation error";
throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
}else if (t instanceof ResourceUnavailableException) {
} else if (t instanceof ResourceUnavailableException) {
s_logger.warn("Exception: ", t);
errorMsg = "Resource unavailable error";
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
}else if (t instanceof ServerApiException) {
} else if (t instanceof AsyncCommandQueued) {
throw (AsyncCommandQueued)t;
} else if (t instanceof ServerApiException) {
s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription());
errorMsg = ((ServerApiException) t).getDescription();
throw new ServerApiException(((ServerApiException) t).getErrorCode(), ((ServerApiException) t).getDescription());
}else if (t instanceof AsyncCommandQueued) {
throw (AsyncCommandQueued)t;
}else {
if (UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN)
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
else
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
} else {
errorMsg = "Internal error";
s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t);
if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN)
if (UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN)
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
else
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
@ -142,36 +145,39 @@ public class ApiDispatcher {
s_logger.info(t.getMessage());
errorMsg = "Parameter error";
throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
}else if (t instanceof PermissionDeniedException) {
} else if (t instanceof PermissionDeniedException) {
s_logger.info("PermissionDenied: " + t.getMessage());
errorMsg = "Permission denied";
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
}else if (t instanceof AccountLimitException) {
} else if (t instanceof AccountLimitException) {
s_logger.info(t.getMessage());
errorMsg = "Account resource limit error";
throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
}else if (t instanceof InsufficientCapacityException) {
} else if (t instanceof InsufficientCapacityException) {
s_logger.info(t.getMessage());
errorMsg = "Insufficient capacity";
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
}else if (t instanceof ResourceAllocationException) {
} else if (t instanceof ResourceAllocationException) {
s_logger.warn("Exception: ", t);
errorMsg = "Resource allocation error";
throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
}else if (t instanceof ResourceUnavailableException) {
} else if (t instanceof ResourceUnavailableException) {
s_logger.warn("Exception: ", t);
errorMsg = "Resource unavailable error";
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
}else if (t instanceof ServerApiException) {
errorMsg = ((ServerApiException) t).getDescription();
s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription());
throw new ServerApiException(((ServerApiException) t).getErrorCode(), ((ServerApiException) t).getDescription());
} else if (t instanceof AsyncCommandQueued) {
throw (AsyncCommandQueued)t;
}else {
} else if (t instanceof ServerApiException) {
errorMsg = ((ServerApiException) t).getDescription();
s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription());
if (UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN)
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
else
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
} else {
errorMsg = "Internal error";
s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t);
if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN)
if (UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN)
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
else
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);

View File

@ -412,6 +412,13 @@ public class ApiServer implements HttpRequestHandler {
job.setCmdInfo(ApiGsonHelper.getBuilder().create().toJson(params));
long jobId = _asyncMgr.submitAsyncJob(job);
if (jobId == 0L) {
String errorMsg = "Unable to schedule async job for command " + job.getCmd();
s_logger.warn(errorMsg);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errorMsg);
}
if (objectId != null) {
return ((BaseAsyncCreateCmd)asyncCmd).getResponse(jobId, objectId);
}

View File

@ -127,11 +127,12 @@ public class AsyncJobManagerImpl implements AsyncJobManager {
s_logger.debug("submit async job-" + job.getId() + ", details: " + job.toString());
}
return job.getId();
} catch(Exception e) {
s_logger.error("Unexpected exception: ", e);
} catch(Exception e) {
txt.rollback();
String errMsg = "Unable to schedule async job for command " + job.getCmd() + ", unexpected exception.";
s_logger.warn(errMsg, e);
throw new CloudRuntimeException(errMsg);
}
return 0L;
}
@Override @DB