use of com.yahoo.vespa.http.client.Result in project vespa by vespa-engine.
the class OperationProcessor method process.
private Result process(EndpointResult endpointResult, int clusterId) {
synchronized (monitor) {
if (!docSendInfoByOperationId.containsKey(endpointResult.getOperationId())) {
log.finer("Received out-of-order or too late result, discarding: " + endpointResult);
return null;
}
DocumentSendInfo documentSendInfo = docSendInfoByOperationId.get(endpointResult.getOperationId());
if (retriedThis(endpointResult, documentSendInfo, clusterId)) {
return null;
}
if (!documentSendInfo.addIfNotAlreadyThere(endpointResult.getDetail(), clusterId)) {
// Duplicate message, we have seen this operation before.
return null;
}
// Is this the last operation we are waiting for?
if (documentSendInfo.detailCount() != numDestinations) {
return null;
}
Result result = documentSendInfo.createResult();
docSendInfoByOperationId.remove(endpointResult.getOperationId());
String documentId = documentSendInfo.getDocument().getDocumentId();
/**
* If we got a pending operation against this document
* dont't remove it from inflightDocuments and send blocked document operation
*/
List<Document> blockedDocuments = blockedDocumentsByDocumentId.get(documentId);
if (blockedDocuments.isEmpty()) {
inflightDocumentIds.remove(documentId);
} else {
sendToClusters(blockedDocuments.remove(0));
}
return result;
}
}
use of com.yahoo.vespa.http.client.Result in project vespa by vespa-engine.
the class OperationProcessor method resultReceived.
public void resultReceived(EndpointResult endpointResult, int clusterId) {
final Result result = process(endpointResult, clusterId);
if (result != null) {
incompleteResultsThrottler.resultReady(result.isSuccess());
resultCallback.onCompletion(result.getDocumentId(), result);
if (traceToStderr && result.hasLocalTrace()) {
System.err.println(result.toString());
}
}
}
use of com.yahoo.vespa.http.client.Result in project vespa by vespa-engine.
the class ExampleUsageFeedClientTest method exampleCode.
// Example usage of FeedClient
public static void exampleCode(String hostNameA, int portServerA, String hostNameB, int portServerB) {
final boolean useSsl = false;
final SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create(hostNameA, portServerA, useSsl)).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create(hostNameB, portServerB, useSsl)).build()).setFeedParams(new FeedParams.Builder().setDataFormat(FeedParams.DataFormat.JSON_UTF8).build()).build();
final AtomicInteger resultsReceived = new AtomicInteger(0);
final AtomicInteger errorsReceived = new AtomicInteger(0);
FeedClient feedClient = FeedClientFactory.create(sessionParams, new FeedClient.ResultCallback() {
@Override
public void onCompletion(String docId, Result documentResult) {
resultsReceived.incrementAndGet();
if (!documentResult.getContext().equals(docId)) {
System.err.println("Context does not work as expected.");
errorsReceived.incrementAndGet();
}
if (!documentResult.isSuccess()) {
System.err.println("Problems with docID " + docId + ":" + documentResult.toString());
errorsReceived.incrementAndGet();
}
}
});
int sentCounter = 0;
final List<String> docIds = Arrays.asList("1", "2", "3", "4");
for (final String docId : docIds) {
CharSequence docData = generateDocument(docId);
feedClient.stream(docId, docData, docId);
sentCounter++;
System.out.println("Sent " + sentCounter + " received results from " + resultsReceived.get());
}
feedClient.close();
System.out.println("Finished, got " + errorsReceived.get() + " errors from " + resultsReceived.get() + " results, sent " + sentCounter + " documents.");
}
use of com.yahoo.vespa.http.client.Result in project vespa by vespa-engine.
the class OperationProcessorTest method testBasic.
@Test
public void testBasic() {
SessionParams sessionParams = new SessionParams.Builder().addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).addCluster(new Cluster.Builder().addEndpoint(Endpoint.create("host")).build()).build();
OperationProcessor q = new OperationProcessor(new IncompleteResultsThrottler(1000, 1000, null, null), (docId, documentResult) -> queue.add(documentResult), sessionParams, null);
q.resultReceived(new EndpointResult("foo", new Result.Detail(null)), 0);
assertThat(queue.size(), is(0));
q.sendDocument(doc1);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("a"))), 0);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("b"))), 1);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("c"))), 2);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("d"))), 3);
assertThat(queue.size(), is(1));
q.resultReceived(new EndpointResult(doc1.getOperationId(), new Result.Detail(Endpoint.create("e"))), 0);
assertThat(queue.size(), is(1));
// check a, b, c, d
Result aggregated = queue.poll();
assertThat(aggregated.getDocumentId(), equalTo("doc:a:b"));
assertThat(aggregated.getDetails().size(), is(4));
assertThat(aggregated.getDetails().get(0).getEndpoint().getHostname(), equalTo("a"));
assertThat(aggregated.getDetails().get(1).getEndpoint().getHostname(), equalTo("b"));
assertThat(aggregated.getDetails().get(2).getEndpoint().getHostname(), equalTo("c"));
assertThat(aggregated.getDetails().get(3).getEndpoint().getHostname(), equalTo("d"));
assertThat(aggregated.getDocumentDataAsCharSequence().toString(), is("data doc 1"));
assertThat(queue.size(), is(0));
q.sendDocument(doc2);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("a"))), 0);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("b"))), 1);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("c"))), 2);
assertThat(queue.size(), is(0));
q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("d"))), 3);
assertThat(queue.size(), is(1));
q.resultReceived(new EndpointResult(doc2.getOperationId(), new Result.Detail(Endpoint.create("e"))), 0);
assertThat(queue.size(), is(1));
// check a, b, c, d
aggregated = queue.poll();
assertThat(aggregated.getDocumentId(), equalTo("doc:a:b2"));
assertThat(aggregated.getDetails().size(), is(4));
assertThat(aggregated.getDetails().get(0).getEndpoint().getHostname(), equalTo("a"));
assertThat(aggregated.getDetails().get(1).getEndpoint().getHostname(), equalTo("b"));
assertThat(aggregated.getDetails().get(2).getEndpoint().getHostname(), equalTo("c"));
assertThat(aggregated.getDetails().get(3).getEndpoint().getHostname(), equalTo("d"));
assertThat(aggregated.getDocumentDataAsCharSequence().toString(), is("data doc 2"));
assertThat(queue.size(), is(0));
}
use of com.yahoo.vespa.http.client.Result in project vespa by vespa-engine.
the class EndPointResultFactory method parseResult.
private static EndpointResult parseResult(String line, Endpoint endpoint) {
try {
OperationStatus reply = OperationStatus.parse(line);
String message;
if (EMPTY_MESSAGE.equals(reply.message)) {
message = null;
} else {
message = reply.message;
}
Exception exception = null;
if (!reply.errorCode.isSuccess() && message != null) {
exception = new RuntimeException(message);
}
if (reply.traceMessage != null && !reply.traceMessage.isEmpty()) {
log.fine("Got trace message: " + reply.traceMessage);
}
return new EndpointResult(reply.operationId, new Result.Detail(endpoint, replyToResultType(reply), reply.traceMessage, exception));
} catch (Throwable t) {
throw new IllegalArgumentException("Bad result line from server: '" + line + "'", t);
}
}
Aggregations