use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueServiceError.ErrorCode in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueue method bulkAdd.
/**
* BulkAdd RPC implementation.
*/
@LatencyPercentiles(latency50th = 4)
public TaskQueueBulkAddResponse bulkAdd(Status status, TaskQueueBulkAddRequest bulkAddRequest) {
TaskQueueBulkAddResponse.Builder bulkAddResponse = TaskQueueBulkAddResponse.newBuilder();
if (bulkAddRequest.getAddRequestCount() == 0) {
return bulkAddResponse.build();
}
TaskQueueBulkAddRequest.Builder bulkAddRequestBuilder = bulkAddRequest.toBuilder();
DevQueue queue = getQueueByName(bulkAddRequestBuilder.getAddRequest(0).getQueueName().toStringUtf8());
Map<TaskQueueBulkAddResponse.TaskResult.Builder, String> chosenNames = new IdentityHashMap<>();
boolean errorFound = false;
for (TaskQueueAddRequest.Builder addRequest : bulkAddRequestBuilder.getAddRequestBuilderList()) {
TaskQueueBulkAddResponse.TaskResult.Builder taskResult = bulkAddResponse.addTaskResultBuilder();
ErrorCode error = validateAddRequest(addRequest);
taskResult.setResult(error);
if (error == ErrorCode.OK) {
if (!addRequest.hasTaskName() || addRequest.getTaskName().isEmpty()) {
addRequest.setTaskName(ByteString.copyFromUtf8(DevQueue.genTaskName()));
chosenNames.put(taskResult, addRequest.getTaskName().toStringUtf8());
}
// Initialize the result as SKIPPED - this will be set to the actual result value if the
// request does not contain any errors and proceeds to the AddActions/BulkAdd stage.
taskResult.setResult(ErrorCode.SKIPPED);
} else {
taskResult.setResult(error);
errorFound = true;
}
}
if (errorFound) {
return bulkAddResponse.build();
}
if (bulkAddRequestBuilder.getAddRequest(0).hasTransaction() || bulkAddRequestBuilder.getAddRequest(0).hasDatastoreTransaction()) {
// rather than an apphosting_datastore_v3.AddActionsRequest.
try {
ApiProxy.makeSyncCall("datastore_v3", "addActions", bulkAddRequestBuilder.build().toByteArray());
} catch (ApiProxy.ApplicationException exception) {
throw new ApiProxy.ApplicationException(exception.getApplicationError() + ErrorCode.DATASTORE_ERROR_VALUE, exception.getErrorDetail());
}
} else {
for (int i = 0; i < bulkAddRequestBuilder.getAddRequestCount(); ++i) {
TaskQueueAddRequest.Builder addRequest = bulkAddRequestBuilder.getAddRequestBuilder(i);
TaskQueueBulkAddResponse.TaskResult.Builder taskResult = bulkAddResponse.getTaskResultBuilder(i);
try {
// Validation of task mode will be performed in DevQueue object.
queue.add(addRequest);
} catch (ApiProxy.ApplicationException exception) {
taskResult.setResult(ErrorCode.forNumber(exception.getApplicationError()));
}
}
}
for (TaskQueueBulkAddResponse.TaskResult.Builder taskResult : bulkAddResponse.getTaskResultBuilderList()) {
if (taskResult.getResult() == ErrorCode.SKIPPED) {
taskResult.setResult(ErrorCode.OK);
if (chosenNames.containsKey(taskResult)) {
taskResult.setChosenTaskName(ByteString.copyFromUtf8(chosenNames.get(taskResult)));
}
}
}
return bulkAddResponse.build();
}
use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueServiceError.ErrorCode in project appengine-java-standard by GoogleCloudPlatform.
the class QueueApiHelper method translateError.
// Translates error codes and details to exceptions.
// Corresponds to __TranslateError in taskqueue.py. Keep in sync!
static RuntimeException translateError(int error, String detail) {
ErrorCode errorCode = ErrorCode.forNumber(error);
// Handles datastore exceptions which are tunneled via TaskQueue API by
// shifting their error codes. For details see DATASTORE_ERROR description
// in apphosting/api/taskqueue/taskqueue_service.proto
int datastoreErrorCode = ErrorCode.DATASTORE_ERROR_VALUE;
if (error >= datastoreErrorCode) {
ApiProxy.ApplicationException datastoreApplicationException = new ApiProxy.ApplicationException(error - datastoreErrorCode, detail);
TransactionalTaskException taskqueueException = new TransactionalTaskException();
taskqueueException.initCause(DatastoreApiHelper.translateError(datastoreApplicationException));
return taskqueueException;
}
switch(errorCode) {
case UNKNOWN_QUEUE:
return new IllegalStateException("The specified queue is unknown : " + detail);
case TRANSIENT_ERROR:
return new TransientFailureException(detail);
case INTERNAL_ERROR:
return new InternalFailureException(detail);
case TASK_TOO_LARGE:
return new IllegalArgumentException("Task size is too large : " + detail);
case INVALID_TASK_NAME:
return new IllegalArgumentException("Invalid task name : " + detail);
case INVALID_QUEUE_NAME:
return new IllegalArgumentException("Invalid queue name : " + detail);
case INVALID_URL:
return new IllegalArgumentException("Invalid URL : " + detail);
case INVALID_QUEUE_RATE:
return new IllegalArgumentException("Invalid queue rate : " + detail);
case PERMISSION_DENIED:
return new SecurityException("Permission for requested operation is denied : " + detail);
case TASK_ALREADY_EXISTS:
return new TaskAlreadyExistsException("Task name already exists : " + detail);
case TOMBSTONED_TASK:
// state.
return new TaskAlreadyExistsException("Task name is tombstoned : " + detail);
case INVALID_ETA:
return new IllegalArgumentException("ETA is invalid : " + detail);
case INVALID_REQUEST:
return new IllegalArgumentException("Invalid request : " + detail);
case UNKNOWN_TASK:
return new TaskNotFoundException("Task does not exist : " + detail);
case TOMBSTONED_QUEUE:
// exception e.g. if the ability to delete queues is added.
return new IllegalStateException("The queue has been marked for deletion and is no longer usable : " + detail);
case DUPLICATE_TASK_NAME:
return new IllegalArgumentException("Identical task names in request : " + detail);
// SKIPPED will never be translated into an exception.
case TOO_MANY_TASKS:
return new IllegalArgumentException("Request contains too many tasks : " + detail);
case INVALID_QUEUE_MODE:
return new InvalidQueueModeException("Target queue mode does not support this operation : " + detail);
case TASK_LEASE_EXPIRED:
return new IllegalStateException("The task lease has expired : " + detail);
case QUEUE_PAUSED:
return new IllegalStateException("The queue is paused and cannot process the request : " + detail);
default:
return new QueueFailureException("Unspecified error (" + errorCode + ") : " + detail);
}
}
Aggregations