Search in sources :

Example 1 with TaskQueueFetchQueueStatsResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse in project appengine-java-standard by GoogleCloudPlatform.

the class QueueStatistics method fetchForQueuesAsync.

/**
 * See {@link Queue#fetchStatistics()}.
 */
static Future<List<QueueStatistics>> fetchForQueuesAsync(final List<Queue> queues, QueueApiHelper helper, double deadlineInSeconds) {
    TaskQueueFetchQueueStatsRequest.Builder statsRequest = TaskQueueFetchQueueStatsRequest.newBuilder();
    for (Queue queue : queues) {
        statsRequest.addQueueName(ByteString.copyFromUtf8(queue.getQueueName()));
    }
    statsRequest.setMaxNumTasks(0);
    ApiConfig apiConfig = new ApiConfig();
    apiConfig.setDeadlineInSeconds(deadlineInSeconds);
    Future<TaskQueueFetchQueueStatsResponse> responseFuture = helper.makeAsyncCall("FetchQueueStats", statsRequest.build(), TaskQueueFetchQueueStatsResponse.getDefaultInstance(), apiConfig);
    return new FutureAdapter<TaskQueueFetchQueueStatsResponse, List<QueueStatistics>>(responseFuture) {

        @Override
        protected List<QueueStatistics> wrap(TaskQueueFetchQueueStatsResponse statsResponse) {
            if (statsResponse.getQueueStatsCount() != queues.size()) {
                throw new QueueFailureException("Unable to obtain queue statistics");
            }
            List<QueueStatistics> resultList = new ArrayList<QueueStatistics>();
            for (int i = 0; i < statsResponse.getQueueStatsCount(); ++i) {
                TaskQueueFetchQueueStatsResponse.QueueStats stats = statsResponse.getQueueStats(i);
                if (!stats.hasScannerInfo()) {
                    throw new TransientFailureException("Queue statistics temporarily unavailable");
                }
                TaskQueueScannerQueueInfo scannerInfo = stats.getScannerInfo();
                if (!scannerInfo.hasRequestsInFlight()) {
                    throw new TransientFailureException("Queue statistics temporarily unavailable");
                }
                if (!scannerInfo.hasEnforcedRate()) {
                    throw new TransientFailureException("Queue statistics temporarily unavailable");
                }
                resultList.add(new QueueStatistics(queues.get(i).getQueueName(), stats));
            }
            return resultList;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) ApiConfig(com.google.apphosting.api.ApiProxy.ApiConfig) TaskQueueScannerQueueInfo(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueScannerQueueInfo) TaskQueueFetchQueueStatsResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse) TaskQueueFetchQueueStatsRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsRequest)

Example 2 with TaskQueueFetchQueueStatsResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testFetchQueueStats.

@Test
public void testFetchQueueStats() throws Exception {
    TaskQueueFetchQueueStatsRequest request = TaskQueueFetchQueueStatsRequest.newBuilder().addQueueName(ByteString.copyFromUtf8("default")).build();
    TaskQueueFetchQueueStatsResponse response = localService.fetchQueueStats(new Status(), request);
    assertThat(response.getQueueStatsCount()).isEqualTo(1);
    TaskQueueFetchQueueStatsResponse.QueueStats stats = response.getQueueStats(0);
    assertThat(stats.hasScannerInfo()).isTrue();
    TaskQueueScannerQueueInfo scannerInfo = stats.getScannerInfo();
    assertThat(scannerInfo.hasRequestsInFlight()).isTrue();
    assertThat(scannerInfo.hasEnforcedRate()).isTrue();
    assertThat((0 == stats.getNumTasks() && -1 == stats.getOldestEtaUsec()) || (0 < stats.getNumTasks() && 0 <= stats.getOldestEtaUsec())).isTrue();
    assertThat(scannerInfo.getEnforcedRate()).isAtLeast(0);
    assertThat(scannerInfo.getExecutedLastMinute()).isAtLeast(0);
    assertThat(scannerInfo.getRequestsInFlight()).isAtLeast(0);
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) TaskQueueFetchQueueStatsResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse) TaskQueueScannerQueueInfo(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueScannerQueueInfo) TaskQueueFetchQueueStatsRequest(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsRequest) Test(org.junit.Test)

Example 3 with TaskQueueFetchQueueStatsResponse

use of com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse 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

TaskQueueFetchQueueStatsResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsResponse)3 TaskQueueScannerQueueInfo (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueScannerQueueInfo)3 TaskQueueFetchQueueStatsRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueFetchQueueStatsRequest)2 LatencyPercentiles (com.google.appengine.tools.development.LatencyPercentiles)1 Status (com.google.appengine.tools.development.LocalRpcService.Status)1 ApiConfig (com.google.apphosting.api.ApiProxy.ApiConfig)1 ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1