Search in sources :

Example 6 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class CommandLineArgumentsTest method testDefaults.

@Test
public void testDefaults() {
    addMinimum();
    CommandLineArguments arguments = CommandLineArguments.build(asArray());
    SessionParams params = arguments.createSessionParams(false);
    assertThat(params.getClientQueueSize(), is(10000));
    assertThat(params.getThrottlerMinSize(), is(0));
    assertThat(params.getClusters().size(), is(1));
    assertThat(params.getClusters().get(0).getEndpoints().size(), is(1));
    assertThat(params.getClusters().get(0).getEndpoints().get(0).getHostname(), is("hostValue"));
    assertThat(params.getClusters().get(0).getEndpoints().get(0).getPort(), is(4080));
    assertThat(params.getClusters().get(0).getEndpoints().get(0).isUseSsl(), is(false));
    assertThat(params.getConnectionParams().getUseCompression(), is(false));
    assertThat(params.getConnectionParams().getNumPersistentConnectionsPerEndpoint(), is(16));
    assertThat(params.getFeedParams().getRoute(), is("default"));
    assertThat(params.getFeedParams().getDataFormat(), is(FeedParams.DataFormat.XML_UTF8));
    assertThat(params.getFeedParams().getLocalQueueTimeOut(), is(180000L));
    assertThat(params.getFeedParams().getMaxInFlightRequests(), is(10000));
    assertThat(params.getFeedParams().getClientTimeout(TimeUnit.MILLISECONDS), is(180000L));
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) Test(org.junit.Test)

Example 7 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class CommandLineArgumentsTest method testMultiHost.

@Test
public void testMultiHost() {
    add("file", "fileValue.json");
    add("port", "1234");
    add("host", "hostValue1,hostValue2,      hostValue3");
    CommandLineArguments arguments = CommandLineArguments.build(asArray());
    SessionParams params = arguments.createSessionParams(true);
    assertThat(params.getClusters().size(), is(3));
    final Set<String> hosts = new HashSet<>();
    for (Cluster cluster : params.getClusters()) {
        assertThat(cluster.getEndpoints().size(), is(1));
        hosts.add(cluster.getEndpoints().get(0).getHostname());
        assertThat(cluster.getEndpoints().get(0).getPort(), is(1234));
    }
    assertThat(hosts, hasItem("hostValue1"));
    assertThat(hosts, hasItem("hostValue2"));
    assertThat(hosts, hasItem("hostValue3"));
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) Cluster(com.yahoo.vespa.http.client.config.Cluster) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams 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 9 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams in project vespa by vespa-engine.

the class CommandLineArguments method createSessionParams.

SessionParams createSessionParams(boolean useJson) {
    final int minThrottleValue = useDynamicThrottlingArg ? 10 : 0;
    SessionParams.Builder builder = new SessionParams.Builder().setFeedParams(new FeedParams.Builder().setDataFormat(useJson ? FeedParams.DataFormat.JSON_UTF8 : FeedParams.DataFormat.XML_UTF8).setRoute(routeArg).setMaxInFlightRequests(maxPendingOperationCountArg).setClientTimeout(timeoutArg, TimeUnit.SECONDS).setServerTimeout(timeoutArg, TimeUnit.SECONDS).setLocalQueueTimeOut(timeoutArg * 1000).setPriority(priorityArg).setMaxChunkSizeBytes(maxChunkSizeBytes).build()).setConnectionParams(new ConnectionParams.Builder().setNumPersistentConnectionsPerEndpoint(16).setEnableV3Protocol(!enableV2Protocol).setUseCompression(useCompressionArg).setMaxRetries(noRetryArg ? 0 : 100).setMinTimeBetweenRetries(retrydelayArg, TimeUnit.SECONDS).setDryRun(validateArg).setTraceLevel(traceArg).setTraceEveryXOperation(traceEveryXOperation).setPrintTraceToStdErr(traceArg > 0).setNumPersistentConnectionsPerEndpoint(numPersistentConnectionsPerEndpoint).build()).setThrottlerMinSize(minThrottleValue).setClientQueueSize(maxPendingOperationCountArg);
    Iterable<String> hosts = Splitter.on(',').trimResults().split(hostArg);
    for (String host : hosts) {
        builder.addCluster(new Cluster.Builder().addEndpoint(Endpoint.create(host, portArg, useTls)).build());
    }
    return builder.build();
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) Cluster(com.yahoo.vespa.http.client.config.Cluster) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) FeedParams(com.yahoo.vespa.http.client.config.FeedParams)

Example 10 with SessionParams

use of com.yahoo.vespa.http.client.config.SessionParams 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.");
}
Also used : SessionParams(com.yahoo.vespa.http.client.config.SessionParams) Cluster(com.yahoo.vespa.http.client.config.Cluster) Endpoint(com.yahoo.vespa.http.client.config.Endpoint) Result(com.yahoo.vespa.http.client.Result) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FeedClient(com.yahoo.vespa.http.client.FeedClient)

Aggregations

SessionParams (com.yahoo.vespa.http.client.config.SessionParams)15 Test (org.junit.Test)12 Cluster (com.yahoo.vespa.http.client.config.Cluster)11 EndpointResult (com.yahoo.vespa.http.client.core.EndpointResult)8 Endpoint (com.yahoo.vespa.http.client.config.Endpoint)5 Result (com.yahoo.vespa.http.client.Result)2 FeedParams (com.yahoo.vespa.http.client.config.FeedParams)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 FeedClient (com.yahoo.vespa.http.client.FeedClient)1 ConnectionParams (com.yahoo.vespa.http.client.config.ConnectionParams)1 Document (com.yahoo.vespa.http.client.core.Document)1 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 StringTokenizer (java.util.StringTokenizer)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 XMLStreamException (javax.xml.stream.XMLStreamException)1