Search in sources :

Example 1 with MetricShortId

use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.

the class CounterShortIdCacheTest method createMetricShortId.

private MetricShortId createMetricShortId(int index, Long shortId) {
    MetricShortId id = new MetricShortId();
    id.setMetricIndex(index);
    id.setShortId(shortId);
    return id;
}
Also used : MetricShortId(com.google.api.services.dataflow.model.MetricShortId)

Example 2 with MetricShortId

use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.

the class CounterShortIdCacheTest method testValidateNumberStatusesAndStates.

@Test
public void testValidateNumberStatusesAndStates() {
    CounterShortIdCache cache = new CounterShortIdCache();
    ReportWorkItemStatusRequest request = new ReportWorkItemStatusRequest();
    ReportWorkItemStatusResponse reply = new ReportWorkItemStatusResponse();
    request.setWorkItemStatuses(createWorkStatusNameAndKind(new String[] { "counter" }, new String[] { "counter2" }));
    reply.setWorkItemServiceStates(createWorkServiceState(new MetricShortId[] { createMetricShortId(0, 1000L) }));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("RequestWorkItemStatus request and response are unbalanced");
    cache.storeNewShortIds(request, reply);
}
Also used : ReportWorkItemStatusResponse(com.google.api.services.dataflow.model.ReportWorkItemStatusResponse) MetricShortId(com.google.api.services.dataflow.model.MetricShortId) ReportWorkItemStatusRequest(com.google.api.services.dataflow.model.ReportWorkItemStatusRequest) Test(org.junit.Test)

Example 3 with MetricShortId

use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.

the class CounterShortIdCacheTest method testValidateAggregateIndexOutOfRange.

@Test
public void testValidateAggregateIndexOutOfRange() {
    CounterShortIdCache cache = new CounterShortIdCache();
    ReportWorkItemStatusRequest request = new ReportWorkItemStatusRequest();
    ReportWorkItemStatusResponse reply = new ReportWorkItemStatusResponse();
    request.setWorkItemStatuses(createWorkStatusNameAndKind(new String[] { "counter" }));
    reply.setWorkItemServiceStates(createWorkServiceState(new MetricShortId[] { createMetricShortId(1000, 1000L) }));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Received aggregate index outside range of sent update");
    cache.storeNewShortIds(request, reply);
}
Also used : ReportWorkItemStatusResponse(com.google.api.services.dataflow.model.ReportWorkItemStatusResponse) MetricShortId(com.google.api.services.dataflow.model.MetricShortId) ReportWorkItemStatusRequest(com.google.api.services.dataflow.model.ReportWorkItemStatusRequest) Test(org.junit.Test)

Example 4 with MetricShortId

use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.

the class CounterShortIdCache method storeNewShortIds.

/**
 * Add any new short ids received to the table. The outgoing request will have the full counter
 * updates, and the incoming responses have the associated short ids. By matching up short ids
 * with the counters in order we can build a mapping of name -> short_id for future use.
 */
public void storeNewShortIds(final ReportWorkItemStatusRequest request, final ReportWorkItemStatusResponse reply) {
    checkArgument(request.getWorkItemStatuses() != null && reply.getWorkItemServiceStates() != null && request.getWorkItemStatuses().size() == reply.getWorkItemServiceStates().size(), "RequestWorkItemStatus request and response are unbalanced, status: %s, states: %s", request.getWorkItemStatuses(), reply.getWorkItemServiceStates());
    for (int i = 0; i < request.getWorkItemStatuses().size(); i++) {
        WorkItemServiceState state = reply.getWorkItemServiceStates().get(i);
        WorkItemStatus status = request.getWorkItemStatuses().get(i);
        if (state.getMetricShortId() == null) {
            continue;
        }
        checkArgument(status.getCounterUpdates() != null, "Response has shortids but no corresponding CounterUpdate");
        for (MetricShortId shortIdMsg : state.getMetricShortId()) {
            int metricIndex = MoreObjects.firstNonNull(shortIdMsg.getMetricIndex(), 0);
            checkArgument(metricIndex < status.getCounterUpdates().size(), "Received aggregate index outside range of sent update %s >= %s", shortIdMsg.getMetricIndex(), status.getCounterUpdates().size());
            CounterUpdate update = status.getCounterUpdates().get(metricIndex);
            cache.insert(update, checkNotNull(shortIdMsg.getShortId(), "Shortid should be non-null"));
        }
    }
}
Also used : WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) WorkItemServiceState(com.google.api.services.dataflow.model.WorkItemServiceState) MetricShortId(com.google.api.services.dataflow.model.MetricShortId) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate)

Example 5 with MetricShortId

use of com.google.api.services.dataflow.model.MetricShortId in project beam by apache.

the class CounterShortIdCacheTest method createWorkServiceState.

private List<WorkItemServiceState> createWorkServiceState(Long[]... counterIds) {
    List<WorkItemServiceState> states = new ArrayList<>();
    for (Long[] ids : counterIds) {
        WorkItemServiceState state = new WorkItemServiceState();
        List<MetricShortId> shortIds = new ArrayList<>();
        for (int i = 0; i < ids.length; i++) {
            shortIds.add(createMetricShortId(i, ids[i]));
        }
        state.setMetricShortId(shortIds);
        states.add(state);
    }
    return states;
}
Also used : ArrayList(java.util.ArrayList) WorkItemServiceState(com.google.api.services.dataflow.model.WorkItemServiceState) MetricShortId(com.google.api.services.dataflow.model.MetricShortId)

Aggregations

MetricShortId (com.google.api.services.dataflow.model.MetricShortId)6 WorkItemServiceState (com.google.api.services.dataflow.model.WorkItemServiceState)3 ReportWorkItemStatusRequest (com.google.api.services.dataflow.model.ReportWorkItemStatusRequest)2 ReportWorkItemStatusResponse (com.google.api.services.dataflow.model.ReportWorkItemStatusResponse)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)1 WorkItemStatus (com.google.api.services.dataflow.model.WorkItemStatus)1