Search in sources :

Example 1 with LatencyPercentiles

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();
}
Also used : InternalFailureException(com.google.appengine.api.taskqueue.InternalFailureException) TaskQueueAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse) TaskQueueBulkAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Example 2 with LatencyPercentiles

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();
}
Also used : TaskQueueAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest) ApiProxy(com.google.apphosting.api.ApiProxy) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) IdentityHashMap(java.util.IdentityHashMap) ByteString(com.google.protobuf.ByteString) TaskQueueBulkAddRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest) ErrorCode(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueServiceError.ErrorCode) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Example 3 with LatencyPercentiles

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;
}
Also used : TaskQueuePurgeQueueResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueuePurgeQueueResponse) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Example 4 with LatencyPercentiles

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();
}
Also used : MemcacheDeleteResponse(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteResponse) MemcacheDeleteRequest(com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteRequest) ByteString(com.google.protobuf.ByteString) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Example 5 with LatencyPercentiles

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();
}
Also used : ByteString(com.google.protobuf.ByteString) TaskQueueFetchQueueStatsResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse) TaskQueueScannerQueueInfo(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueScannerQueueInfo) LatencyPercentiles(com.google.appengine.tools.development.LatencyPercentiles)

Aggregations

LatencyPercentiles (com.google.appengine.tools.development.LatencyPercentiles)7 ByteString (com.google.protobuf.ByteString)4 TaskQueueAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddRequest)2 TaskQueueBulkAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest)2 TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)2 MemcacheDeleteRequest (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteRequest)1 MemcacheDeleteResponse (com.google.appengine.api.memcache.MemcacheServicePb.MemcacheDeleteResponse)1 InternalFailureException (com.google.appengine.api.taskqueue.InternalFailureException)1 TaskQueueAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueAddResponse)1 TaskQueueFetchQueueStatsResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse)1 TaskQueuePurgeQueueResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueuePurgeQueueResponse)1 TaskQueueQueryAndOwnTasksResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueQueryAndOwnTasksResponse)1 TaskQueueScannerQueueInfo (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueScannerQueueInfo)1 ErrorCode (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueServiceError.ErrorCode)1 URLFetchRequest (com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchRequest)1 URLFetchResponse (com.google.appengine.api.urlfetch.URLFetchServicePb.URLFetchResponse)1 ApiProxy (com.google.apphosting.api.ApiProxy)1 ApplicationException (com.google.apphosting.api.ApiProxy.ApplicationException)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1