use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class VespaRecordWriter method initialize.
private void initialize() {
if (!configuration.dryrun() && configuration.randomStartupSleepMs() > 0) {
int delay = new Random().nextInt(configuration.randomStartupSleepMs());
log.info("VespaStorage: Delaying startup by " + delay + " ms");
try {
Thread.sleep(delay);
} catch (Exception e) {
}
}
ConnectionParams.Builder connParamsBuilder = configureConnectionParams();
FeedParams.Builder feedParamsBuilder = configureFeedParams();
SessionParams.Builder sessionParams = configureSessionParams();
sessionParams.setConnectionParams(connParamsBuilder.build());
sessionParams.setFeedParams(feedParamsBuilder.build());
String endpoints = configuration.endpoint();
StringTokenizer tokenizer = new StringTokenizer(endpoints, ",");
while (tokenizer.hasMoreTokens()) {
String endpoint = tokenizer.nextToken().trim();
sessionParams.addCluster(new Cluster.Builder().addEndpoint(Endpoint.create(endpoint, configuration.defaultPort(), configuration.useSSL())).build());
}
ResultCallback resultCallback = new ResultCallback(counters);
feedClient = FeedClientFactory.create(sessionParams.build(), resultCallback);
initialized = true;
log.info("VespaStorage configuration:\n" + configuration.toString());
log.info(feedClient.getStatsAsJson());
}
use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class IOThread method close.
@Override
public void close() {
documentQueue.close();
if (stopSignal.getCount() == 0) {
return;
}
stopSignal.countDown();
log.finer("Closed called.");
// Make a last attempt to get results from previous operations, we have already waited quite a bit before getting here.
int size = resultQueue.getPendingSize();
if (size > 0) {
log.info("We have outstanding operations (" + size + ") , trying to fetch responses.");
try {
processResponse(client.drain());
} catch (Throwable e) {
log.log(Level.SEVERE, "Some failures while trying to get latest responses from vespa.", e);
}
}
try {
client.close();
} finally {
// If there is still documents in the queue, fail them.
drainDocumentQueueWhenFailingPermanently(new Exception("Closed call, did not manage to process everything so failing this document."));
}
log.fine("Session to " + endpoint + " closed.");
}
use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class IOThread method processResponse.
private ProcessResponse processResponse(InputStream serverResponse) throws IOException {
final Collection<EndpointResult> endpointResults = EndPointResultFactory.createResult(endpoint, serverResponse);
statusReceivedCounter.addAndGet(endpointResults.size());
int transientErrors = 0;
for (EndpointResult endpointResult : endpointResults) {
if (endpointResult.getDetail().getResultType() == Result.ResultType.TRANSITIVE_ERROR) {
transientErrors++;
}
resultQueue.resultReceived(endpointResult, clusterId);
}
return new ProcessResponse(transientErrors, endpointResults.size());
}
use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method testBadConfigParameters.
@Test(expected = RuntimeException.class)
public void testBadConfigParameters() throws Exception {
final Endpoint endpoint = Endpoint.create("hostname", 666, false);
final FeedParams feedParams = new FeedParams.Builder().setDataFormat(FeedParams.DataFormat.JSON_UTF8).build();
final String clusterSpecificRoute = "";
final ConnectionParams connectionParams = new ConnectionParams.Builder().setEnableV3Protocol(true).build();
final ApacheGatewayConnection.HttpClientFactory mockFactory = mock(ApacheGatewayConnection.HttpClientFactory.class);
new ApacheGatewayConnection(endpoint, feedParams, clusterSpecificRoute, connectionParams, mockFactory, null);
}
use of com.yahoo.vespa.http.client.config.Endpoint in project vespa by vespa-engine.
the class ApacheGatewayConnectionTest method testJsonDocumentHeader.
@Test
public void testJsonDocumentHeader() throws Exception {
final Endpoint endpoint = Endpoint.create("hostname", 666, false);
final FeedParams feedParams = new FeedParams.Builder().setDataFormat(FeedParams.DataFormat.JSON_UTF8).build();
final String clusterSpecificRoute = "";
final ConnectionParams connectionParams = new ConnectionParams.Builder().setUseCompression(true).build();
final List<Document> documents = new ArrayList<>();
final CountDownLatch verifyContentSentLatch = new CountDownLatch(1);
final String vespaDocContent = "Hello, I a JSON doc.";
final String docId = "42";
final AtomicInteger requestsReceived = new AtomicInteger(0);
// This is the fake server, checks that DATA_FORMAT header is set properly.
ApacheGatewayConnection.HttpClientFactory mockFactory = mockHttpClientFactory(post -> {
final Header header = post.getFirstHeader(Headers.DATA_FORMAT);
if (requestsReceived.incrementAndGet() == 1) {
// This is handshake, it is not json.
assert (header == null);
return httpResponse("clientId", "3");
}
assertNotNull(header);
assertThat(header.getValue(), is(FeedParams.DataFormat.JSON_UTF8.name()));
// Test is done.
verifyContentSentLatch.countDown();
return httpResponse("clientId", "3");
});
ApacheGatewayConnection apacheGatewayConnection = new ApacheGatewayConnection(endpoint, feedParams, clusterSpecificRoute, connectionParams, mockFactory, "clientId");
apacheGatewayConnection.connect();
apacheGatewayConnection.handshake();
documents.add(createDoc(docId, vespaDocContent, true));
apacheGatewayConnection.writeOperations(documents);
assertTrue(verifyContentSentLatch.await(10, TimeUnit.SECONDS));
}
Aggregations