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));
}
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"));
}
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());
}
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();
}
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.");
}
Aggregations