Search in sources :

Example 1 with FetchResponse

use of io.zulia.message.ZuliaServiceOuterClass.FetchResponse in project zuliasearch by zuliaio.

the class Fetch method execute.

@Override
public FetchResult execute(ZuliaConnection zuliaConnection) {
    ZuliaServiceBlockingStub service = zuliaConnection.getService();
    FetchResponse fetchResponse = service.fetch(getRequest());
    return new FetchResult(fetchResponse);
}
Also used : ZuliaServiceBlockingStub(io.zulia.message.ZuliaServiceGrpc.ZuliaServiceBlockingStub) FetchResult(io.zulia.client.result.FetchResult) FetchResponse(io.zulia.message.ZuliaServiceOuterClass.FetchResponse)

Example 2 with FetchResponse

use of io.zulia.message.ZuliaServiceOuterClass.FetchResponse in project zuliasearch by zuliaio.

the class BatchFetch method execute.

@Override
public BatchFetchResult execute(ZuliaConnection zuliaConnection) {
    ZuliaServiceBlockingStub service = zuliaConnection.getService();
    Iterator<FetchResponse> batchFetchResponse = service.batchFetch(getRequest());
    return new BatchFetchResult(batchFetchResponse);
}
Also used : ZuliaServiceBlockingStub(io.zulia.message.ZuliaServiceGrpc.ZuliaServiceBlockingStub) BatchFetchResult(io.zulia.client.result.BatchFetchResult) FetchResponse(io.zulia.message.ZuliaServiceOuterClass.FetchResponse)

Example 3 with FetchResponse

use of io.zulia.message.ZuliaServiceOuterClass.FetchResponse in project zuliasearch by zuliaio.

the class FetchController method get.

@Get
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public HttpResponse<?> get(@QueryValue(ZuliaConstants.ID) final String uniqueId, @QueryValue(ZuliaConstants.INDEX) final String indexName, @QueryValue(value = ZuliaConstants.PRETTY, defaultValue = "true") Boolean pretty) {
    ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
    FetchRequest.Builder fetchRequest = FetchRequest.newBuilder();
    fetchRequest.setIndexName(indexName);
    fetchRequest.setUniqueId(uniqueId);
    FetchResponse fetchResponse;
    try {
        fetchResponse = indexManager.fetch(fetchRequest.build());
        if (fetchResponse.hasResultDocument()) {
            Document document = ResultHelper.getDocumentFromResultDocument(fetchResponse.getResultDocument());
            if (document != null) {
                String docString;
                if (pretty) {
                    docString = document.toJson(JsonWriterSettings.builder().indent(true).build());
                } else {
                    docString = document.toJson();
                }
                if (pretty) {
                    docString = JsonWriter.formatJson(docString);
                }
                return HttpResponse.ok(docString).status(ZuliaConstants.SUCCESS);
            }
            return HttpResponse.ok("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">").status(ZuliaConstants.NOT_FOUND);
        } else {
            return HttpResponse.ok("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">").status(ZuliaConstants.NOT_FOUND);
        }
    } catch (Exception e) {
        return HttpResponse.serverError("Failed to fetch uniqueId <" + uniqueId + "> for index <" + indexName + ">: " + e.getMessage()).status(ZuliaConstants.INTERNAL_ERROR);
    }
}
Also used : ZuliaIndexManager(io.zulia.server.index.ZuliaIndexManager) FetchRequest(io.zulia.message.ZuliaServiceOuterClass.FetchRequest) FetchResponse(io.zulia.message.ZuliaServiceOuterClass.FetchResponse) Document(org.bson.Document) Produces(io.micronaut.http.annotation.Produces) Get(io.micronaut.http.annotation.Get)

Example 4 with FetchResponse

use of io.zulia.message.ZuliaServiceOuterClass.FetchResponse in project zuliasearch by zuliaio.

the class BatchFetchServerRequest method handleRequest.

public void handleRequest(BatchFetchRequest request, StreamObserver<FetchResponse> responseObserver) {
    try {
        for (FetchRequest fetchRequest : request.getFetchRequestList()) {
            FetchResponse fetchResponse = indexManager.fetch(fetchRequest);
            responseObserver.onNext(fetchResponse);
        }
        responseObserver.onCompleted();
    } catch (Exception e) {
        responseObserver.onError(e);
        onError(e);
    }
}
Also used : BatchFetchRequest(io.zulia.message.ZuliaServiceOuterClass.BatchFetchRequest) FetchRequest(io.zulia.message.ZuliaServiceOuterClass.FetchRequest) FetchResponse(io.zulia.message.ZuliaServiceOuterClass.FetchResponse)

Aggregations

FetchResponse (io.zulia.message.ZuliaServiceOuterClass.FetchResponse)4 ZuliaServiceBlockingStub (io.zulia.message.ZuliaServiceGrpc.ZuliaServiceBlockingStub)2 FetchRequest (io.zulia.message.ZuliaServiceOuterClass.FetchRequest)2 Get (io.micronaut.http.annotation.Get)1 Produces (io.micronaut.http.annotation.Produces)1 BatchFetchResult (io.zulia.client.result.BatchFetchResult)1 FetchResult (io.zulia.client.result.FetchResult)1 BatchFetchRequest (io.zulia.message.ZuliaServiceOuterClass.BatchFetchRequest)1 ZuliaIndexManager (io.zulia.server.index.ZuliaIndexManager)1 Document (org.bson.Document)1