use of com.google.appengine.tools.development.LatencyPercentiles in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueue method add.
@LatencyPercentiles(latency50th = 4)
public TaskQueueAddResponse add(Status status, TaskQueueAddRequest addRequest) {
TaskQueueBulkAddRequest.Builder bulkRequest = TaskQueueBulkAddRequest.newBuilder();
bulkRequest.addAddRequestBuilder().mergeFrom(addRequest);
TaskQueueAddResponse.Builder addResponse = TaskQueueAddResponse.newBuilder();
TaskQueueBulkAddResponse bulkResponse = bulkAdd(status, bulkRequest.build());
if (bulkResponse.getTaskResultCount() != 1) {
throw new InternalFailureException(String.format("expected 1 result from BulkAdd(), got %d", bulkResponse.getTaskResultCount()));
}
int result = bulkResponse.getTaskResult(0).getResult().getNumber();
if (result != ErrorCode.OK_VALUE) {
throw new ApiProxy.ApplicationException(result);
} else if (bulkResponse.getTaskResult(0).hasChosenTaskName()) {
addResponse.setChosenTaskName(bulkResponse.getTaskResult(0).getChosenTaskName());
}
return addResponse.build();
}
use of com.google.appengine.tools.development.LatencyPercentiles 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.tools.development.LatencyPercentiles in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueue method purgeQueue.
/**
* PurgeQueue RPC implementation.
*/
@LatencyPercentiles(latency50th = 3)
public TaskQueuePurgeQueueResponse purgeQueue(Status status, TaskQueuePurgeQueueRequest purgeQueueRequest) {
TaskQueuePurgeQueueResponse purgeQueueResponse = TaskQueuePurgeQueueResponse.getDefaultInstance();
flushQueue(purgeQueueRequest.getQueueName().toStringUtf8());
return purgeQueueResponse;
}
use of com.google.appengine.tools.development.LatencyPercentiles in project appengine-java-standard by GoogleCloudPlatform.
the class LocalMemcacheService method delete.
@LatencyPercentiles(latency50th = 4)
public MemcacheDeleteResponse delete(Status status, MemcacheDeleteRequest req) {
MemcacheDeleteResponse.Builder result = MemcacheDeleteResponse.newBuilder();
final String namespace = req.getNameSpace();
for (int i = 0; i < req.getItemCount(); i++) {
MemcacheDeleteRequest.Item item = req.getItem(i);
Key key = new Key(item.getKey().toByteArray());
CacheEntry ce = internalDelete(namespace, key);
result.addDeleteStatus(ce == null ? DeleteStatusCode.NOT_FOUND : DeleteStatusCode.DELETED);
if (ce != null) {
stats.recordDelete(ce);
}
// open spec whether this happens if there was no deletion
if (item.hasDeleteTime()) {
int millisNoReAdd = item.getDeleteTime() * 1000;
getOrMakeSubMap(deleteHold, namespace).put(key, clock.getCurrentTime() + millisNoReAdd);
}
}
status.setSuccessful(true);
return result.build();
}
use of com.google.appengine.tools.development.LatencyPercentiles in project appengine-java-standard by GoogleCloudPlatform.
the class LocalTaskQueue method fetchQueueStats.
/**
* FetchQueueStats RPC implementation.
*/
@LatencyPercentiles(latency50th = 3)
public TaskQueueFetchQueueStatsResponse fetchQueueStats(Status status, TaskQueueFetchQueueStatsRequest fetchQueueStatsRequest) {
TaskQueueFetchQueueStatsResponse.Builder fetchQueueStatsResponse = TaskQueueFetchQueueStatsResponse.newBuilder();
for (ByteString unused : fetchQueueStatsRequest.getQueueNameList()) {
TaskQueueFetchQueueStatsResponse.QueueStats.Builder stats = TaskQueueFetchQueueStatsResponse.QueueStats.newBuilder();
TaskQueueScannerQueueInfo.Builder scannerInfo = TaskQueueScannerQueueInfo.newBuilder();
// Random statistics.
scannerInfo.setEnforcedRate(rng.nextInt(500) + 1);
scannerInfo.setExecutedLastMinute(rng.nextInt(3000));
scannerInfo.setRequestsInFlight(rng.nextInt(5));
scannerInfo.setExecutedLastHour(0);
scannerInfo.setSamplingDurationSeconds(0.0);
if (rng.nextBoolean()) {
stats.setNumTasks(0);
stats.setOldestEtaUsec(-1);
} else {
stats.setNumTasks(rng.nextInt(2000) + 1);
stats.setOldestEtaUsec(currentTimeMillis() * 1000);
}
stats.setScannerInfo(scannerInfo);
fetchQueueStatsResponse.addQueueStats(stats);
}
return fetchQueueStatsResponse.build();
}
Aggregations