Search in sources :

Example 1 with APPLICATION_JSON

use of zipkin.storage.elasticsearch.http.ElasticsearchHttpStorage.APPLICATION_JSON in project zipkin by openzipkin.

the class EnsureIndexTemplate method apply.

/**
   * This is a blocking call, used inside a lazy. That's because no writes should occur until the
   * template is available.
   */
static void apply(HttpCall.Factory callFactory, String name, String indexTemplate) {
    HttpUrl templateUrl = callFactory.baseUrl.newBuilder("_template").addPathSegment(name).build();
    Request getTemplate = new Request.Builder().url(templateUrl).tag("get-template").build();
    try {
        callFactory.execute(getTemplate, b -> null);
    } catch (IllegalStateException e) {
        // TODO: handle 404 slightly more nicely
        Request updateTemplate = new Request.Builder().url(templateUrl).put(RequestBody.create(APPLICATION_JSON, indexTemplate)).tag("update-template").build();
        callFactory.execute(updateTemplate, b -> null);
    }
}
Also used : Request(okhttp3.Request) HttpCall(zipkin.storage.elasticsearch.http.internal.client.HttpCall) APPLICATION_JSON(zipkin.storage.elasticsearch.http.ElasticsearchHttpStorage.APPLICATION_JSON) HttpUrl(okhttp3.HttpUrl) RequestBody(okhttp3.RequestBody) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Example 2 with APPLICATION_JSON

use of zipkin.storage.elasticsearch.http.ElasticsearchHttpStorage.APPLICATION_JSON in project zipkin by openzipkin.

the class HttpBulkIndexer method execute.

/** Creates a bulk request when there is more than one object to store */
void execute(Callback<Void> callback) {
    HttpUrl url = pipeline != null ? http.baseUrl.newBuilder("_bulk").addQueryParameter("pipeline", pipeline).build() : http.baseUrl.resolve("_bulk");
    Request request = new Request.Builder().url(url).tag(tag).post(RequestBody.create(APPLICATION_JSON, body.readByteString())).build();
    http.<Void>newCall(request, b -> {
        if (indices.isEmpty())
            return null;
        ElasticsearchHttpStorage.flush(http, join(indices));
        return null;
    }).submit(callback);
}
Also used : Request(okhttp3.Request) Buffer(okio.Buffer) Iterator(java.util.Iterator) Nullable(zipkin.internal.Nullable) HttpCall(zipkin.storage.elasticsearch.http.internal.client.HttpCall) Collection(java.util.Collection) Set(java.util.Set) APPLICATION_JSON(zipkin.storage.elasticsearch.http.ElasticsearchHttpStorage.APPLICATION_JSON) HttpUrl(okhttp3.HttpUrl) LinkedHashSet(java.util.LinkedHashSet) Callback(zipkin.storage.Callback) RequestBody(okhttp3.RequestBody) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl)

Aggregations

HttpUrl (okhttp3.HttpUrl)2 Request (okhttp3.Request)2 RequestBody (okhttp3.RequestBody)2 APPLICATION_JSON (zipkin.storage.elasticsearch.http.ElasticsearchHttpStorage.APPLICATION_JSON)2 HttpCall (zipkin.storage.elasticsearch.http.internal.client.HttpCall)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Buffer (okio.Buffer)1 Nullable (zipkin.internal.Nullable)1 Callback (zipkin.storage.Callback)1