Search in sources :

Example 1 with GetDataResponse

use of org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataResponse in project beam by apache.

the class FakeWindmillServer method getData.

@Override
public Windmill.GetDataResponse getData(Windmill.GetDataRequest request) {
    LOG.info("getDataRequest: {}", request.toString());
    validateGetDataRequest(request);
    ++numGetDataRequests;
    GetDataResponse response;
    Function<GetDataRequest, GetDataResponse> responseFn = dataToOffer.poll();
    if (responseFn == null) {
        response = Windmill.GetDataResponse.newBuilder().build();
    } else {
        response = responseFn.apply(request);
        try {
            // Sleep for a little bit to ensure that *-windmill-read state-sampled counters
            // show up.
            sleepMillis(500);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
    LOG.debug("getDataResponse: {}", response.toString());
    return response;
}
Also used : GetDataResponse(org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataResponse) ComputationGetDataRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.ComputationGetDataRequest) KeyedGetDataRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.KeyedGetDataRequest) GetDataRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataRequest)

Example 2 with GetDataResponse

use of org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataResponse in project beam by apache.

the class FakeWindmillServer method getDataStream.

@Override
public GetDataStream getDataStream() {
    Instant startTime = Instant.now();
    return new GetDataStream() {

        @Override
        public Windmill.KeyedGetDataResponse requestKeyedData(String computation, KeyedGetDataRequest request) {
            Windmill.GetDataRequest getDataRequest = GetDataRequest.newBuilder().addRequests(ComputationGetDataRequest.newBuilder().setComputationId(computation).addRequests(request).build()).build();
            GetDataResponse getDataResponse = getData(getDataRequest);
            if (getDataResponse.getDataList().isEmpty()) {
                return null;
            }
            assertEquals(1, getDataResponse.getDataCount());
            if (getDataResponse.getData(0).getDataList().isEmpty()) {
                return null;
            }
            assertEquals(1, getDataResponse.getData(0).getDataCount());
            return getDataResponse.getData(0).getData(0);
        }

        @Override
        public Windmill.GlobalData requestGlobalData(Windmill.GlobalDataRequest request) {
            Windmill.GetDataRequest getDataRequest = GetDataRequest.newBuilder().addGlobalDataFetchRequests(request).build();
            GetDataResponse getDataResponse = getData(getDataRequest);
            if (getDataResponse.getGlobalDataList().isEmpty()) {
                return null;
            }
            assertEquals(1, getDataResponse.getGlobalDataCount());
            return getDataResponse.getGlobalData(0);
        }

        @Override
        public void refreshActiveWork(Map<String, List<KeyedGetDataRequest>> active) {
        }

        @Override
        public void close() {
        }

        @Override
        public boolean awaitTermination(int time, TimeUnit unit) {
            return true;
        }

        @Override
        public Instant startTime() {
            return startTime;
        }
    };
}
Also used : GetDataRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataRequest) Instant(org.joda.time.Instant) Windmill(org.apache.beam.runners.dataflow.worker.windmill.Windmill) GetDataResponse(org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataResponse) TimeUnit(java.util.concurrent.TimeUnit) KeyedGetDataRequest(org.apache.beam.runners.dataflow.worker.windmill.Windmill.KeyedGetDataRequest) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

GetDataRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataRequest)2 GetDataResponse (org.apache.beam.runners.dataflow.worker.windmill.Windmill.GetDataResponse)2 KeyedGetDataRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.KeyedGetDataRequest)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 Windmill (org.apache.beam.runners.dataflow.worker.windmill.Windmill)1 ComputationGetDataRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.ComputationGetDataRequest)1 Instant (org.joda.time.Instant)1