Search in sources :

Example 11 with Endpoint

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());
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) Cluster(com.yahoo.vespa.http.client.config.Cluster) ConnectionParams(com.yahoo.vespa.http.client.config.ConnectionParams) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) XMLStreamException(javax.xml.stream.XMLStreamException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) StringTokenizer(java.util.StringTokenizer) Random(java.util.Random)

Example 12 with Endpoint

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.");
}
Also used : Endpoint(com.yahoo.vespa.http.client.config.Endpoint) IOException(java.io.IOException) ServerResponseException(com.yahoo.vespa.http.client.core.ServerResponseException)

Example 13 with Endpoint

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());
}
Also used : EndpointResult(com.yahoo.vespa.http.client.core.EndpointResult) Endpoint(com.yahoo.vespa.http.client.config.Endpoint)

Example 14 with Endpoint

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);
}
Also used : Endpoint(com.yahoo.vespa.http.client.config.Endpoint) ConnectionParams(com.yahoo.vespa.http.client.config.ConnectionParams) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Test(org.junit.Test)

Example 15 with Endpoint

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));
}
Also used : ArrayList(java.util.ArrayList) Document(com.yahoo.vespa.http.client.core.Document) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectionParams(com.yahoo.vespa.http.client.config.ConnectionParams) FeedParams(com.yahoo.vespa.http.client.config.FeedParams) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Header(org.apache.http.Header) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Aggregations

Endpoint (com.yahoo.vespa.http.client.config.Endpoint)25 Test (org.junit.Test)22 Cluster (com.yahoo.vespa.http.client.config.Cluster)16 SessionParams (com.yahoo.vespa.http.client.config.SessionParams)15 V3MockParsingRequestHandler (com.yahoo.vespa.http.client.handlers.V3MockParsingRequestHandler)14 HashMap (java.util.HashMap)14 FeedParams (com.yahoo.vespa.http.client.config.FeedParams)10 ConnectionParams (com.yahoo.vespa.http.client.config.ConnectionParams)6 Document (com.yahoo.vespa.http.client.core.Document)4 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Header (org.apache.http.Header)3 OperationProcessor (com.yahoo.vespa.http.client.core.operationProcessor.OperationProcessor)2 IOException (java.io.IOException)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 ServerResponseException (com.yahoo.vespa.http.client.core.ServerResponseException)1 Random (java.util.Random)1