Search in sources :

Example 1 with Sink

use of org.apache.pulsar.client.admin.Sink in project pulsar by apache.

the class SinksImpl method updateSinkAsync.

@Override
public CompletableFuture<Void> updateSinkAsync(SinkConfig sinkConfig, String fileName, UpdateOptions updateOptions) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    if (!validateSinkName(sinkConfig.getTenant(), sinkConfig.getNamespace(), sinkConfig.getName(), future)) {
        return future;
    }
    try {
        RequestBuilder builder = put(sink.path(sinkConfig.getTenant()).path(sinkConfig.getNamespace()).path(sinkConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("sinkConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(sinkConfig), MediaType.APPLICATION_JSON));
        UpdateOptionsImpl options = (UpdateOptionsImpl) updateOptions;
        if (options != null) {
            builder.addBodyPart(new StringPart("updateOptions", ObjectMapperFactory.getThreadLocal().writeValueAsString(options), MediaType.APPLICATION_JSON));
        }
        if (fileName != null && !fileName.startsWith("builtin://")) {
            // If the function code is built in, we don't need to submit here
            builder.addBodyPart(new FilePart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM));
        }
        asyncHttpClient.executeRequest(addAuthHeaders(sink, builder).build()).toCompletableFuture().thenAccept(response -> {
            if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) {
                future.completeExceptionally(getApiException(Response.status(response.getStatusCode()).entity(response.getResponseBody()).build()));
            } else {
                future.complete(null);
            }
        }).exceptionally(throwable -> {
            future.completeExceptionally(getApiException(throwable));
            return null;
        });
    } catch (Exception e) {
        future.completeExceptionally(getApiException(e));
    }
    return future;
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) ConnectorDefinition(org.apache.pulsar.common.io.ConnectorDefinition) UpdateOptions(org.apache.pulsar.common.functions.UpdateOptions) ObjectMapperFactory(org.apache.pulsar.common.util.ObjectMapperFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Sink(org.apache.pulsar.client.admin.Sink) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) Gson(com.google.gson.Gson) InvocationCallback(javax.ws.rs.client.InvocationCallback) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) RequestBuilder(org.asynchttpclient.RequestBuilder) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) SinkConfig(org.apache.pulsar.common.io.SinkConfig) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) Sinks(org.apache.pulsar.client.admin.Sinks) FilePart(org.asynchttpclient.request.body.multipart.FilePart) Entity(javax.ws.rs.client.Entity) File(java.io.File) Dsl.post(org.asynchttpclient.Dsl.post) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Dsl.put(org.asynchttpclient.Dsl.put) Response(javax.ws.rs.core.Response) Authentication(org.apache.pulsar.client.api.Authentication) StringPart(org.asynchttpclient.request.body.multipart.StringPart) WebTarget(javax.ws.rs.client.WebTarget) CompletableFuture(java.util.concurrent.CompletableFuture) RequestBuilder(org.asynchttpclient.RequestBuilder) StringPart(org.asynchttpclient.request.body.multipart.StringPart) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) File(java.io.File) FilePart(org.asynchttpclient.request.body.multipart.FilePart) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 2 with Sink

use of org.apache.pulsar.client.admin.Sink in project incubator-pulsar by apache.

the class SinksImpl method updateSinkAsync.

@Override
public CompletableFuture<Void> updateSinkAsync(SinkConfig sinkConfig, String fileName, UpdateOptions updateOptions) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    if (!validateSinkName(sinkConfig.getTenant(), sinkConfig.getNamespace(), sinkConfig.getName(), future)) {
        return future;
    }
    try {
        RequestBuilder builder = put(sink.path(sinkConfig.getTenant()).path(sinkConfig.getNamespace()).path(sinkConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("sinkConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(sinkConfig), MediaType.APPLICATION_JSON));
        UpdateOptionsImpl options = (UpdateOptionsImpl) updateOptions;
        if (options != null) {
            builder.addBodyPart(new StringPart("updateOptions", ObjectMapperFactory.getThreadLocal().writeValueAsString(options), MediaType.APPLICATION_JSON));
        }
        if (fileName != null && !fileName.startsWith("builtin://")) {
            // If the function code is built in, we don't need to submit here
            builder.addBodyPart(new FilePart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM));
        }
        asyncHttpClient.executeRequest(addAuthHeaders(sink, builder).build()).toCompletableFuture().thenAccept(response -> {
            if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) {
                future.completeExceptionally(getApiException(Response.status(response.getStatusCode()).entity(response.getResponseBody()).build()));
            } else {
                future.complete(null);
            }
        }).exceptionally(throwable -> {
            future.completeExceptionally(getApiException(throwable));
            return null;
        });
    } catch (Exception e) {
        future.completeExceptionally(getApiException(e));
    }
    return future;
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) ConnectorDefinition(org.apache.pulsar.common.io.ConnectorDefinition) UpdateOptions(org.apache.pulsar.common.functions.UpdateOptions) ObjectMapperFactory(org.apache.pulsar.common.util.ObjectMapperFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Sink(org.apache.pulsar.client.admin.Sink) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) Gson(com.google.gson.Gson) InvocationCallback(javax.ws.rs.client.InvocationCallback) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) RequestBuilder(org.asynchttpclient.RequestBuilder) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) SinkConfig(org.apache.pulsar.common.io.SinkConfig) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) Sinks(org.apache.pulsar.client.admin.Sinks) FilePart(org.asynchttpclient.request.body.multipart.FilePart) Entity(javax.ws.rs.client.Entity) File(java.io.File) Dsl.post(org.asynchttpclient.Dsl.post) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Dsl.put(org.asynchttpclient.Dsl.put) Response(javax.ws.rs.core.Response) Authentication(org.apache.pulsar.client.api.Authentication) StringPart(org.asynchttpclient.request.body.multipart.StringPart) WebTarget(javax.ws.rs.client.WebTarget) CompletableFuture(java.util.concurrent.CompletableFuture) RequestBuilder(org.asynchttpclient.RequestBuilder) StringPart(org.asynchttpclient.request.body.multipart.StringPart) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) File(java.io.File) FilePart(org.asynchttpclient.request.body.multipart.FilePart) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 3 with Sink

use of org.apache.pulsar.client.admin.Sink in project incubator-pulsar by apache.

the class SinksImpl method createSinkAsync.

@Override
public CompletableFuture<Void> createSinkAsync(SinkConfig sinkConfig, String fileName) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    if (!validateSinkName(sinkConfig.getTenant(), sinkConfig.getNamespace(), sinkConfig.getName(), future)) {
        return future;
    }
    try {
        RequestBuilder builder = post(sink.path(sinkConfig.getTenant()).path(sinkConfig.getNamespace()).path(sinkConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("sinkConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(sinkConfig), MediaType.APPLICATION_JSON));
        if (fileName != null && !fileName.startsWith("builtin://")) {
            // If the function code is built in, we don't need to submit here
            builder.addBodyPart(new FilePart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM));
        }
        asyncHttpClient.executeRequest(addAuthHeaders(sink, builder).build()).toCompletableFuture().thenAccept(response -> {
            if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) {
                future.completeExceptionally(getApiException(Response.status(response.getStatusCode()).entity(response.getResponseBody()).build()));
            } else {
                future.complete(null);
            }
        }).exceptionally(throwable -> {
            future.completeExceptionally(getApiException(throwable));
            return null;
        });
    } catch (Exception e) {
        future.completeExceptionally(getApiException(e));
    }
    return future;
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) ConnectorDefinition(org.apache.pulsar.common.io.ConnectorDefinition) UpdateOptions(org.apache.pulsar.common.functions.UpdateOptions) ObjectMapperFactory(org.apache.pulsar.common.util.ObjectMapperFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Sink(org.apache.pulsar.client.admin.Sink) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) Gson(com.google.gson.Gson) InvocationCallback(javax.ws.rs.client.InvocationCallback) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) RequestBuilder(org.asynchttpclient.RequestBuilder) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) SinkConfig(org.apache.pulsar.common.io.SinkConfig) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) Sinks(org.apache.pulsar.client.admin.Sinks) FilePart(org.asynchttpclient.request.body.multipart.FilePart) Entity(javax.ws.rs.client.Entity) File(java.io.File) Dsl.post(org.asynchttpclient.Dsl.post) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Dsl.put(org.asynchttpclient.Dsl.put) Response(javax.ws.rs.core.Response) Authentication(org.apache.pulsar.client.api.Authentication) StringPart(org.asynchttpclient.request.body.multipart.StringPart) WebTarget(javax.ws.rs.client.WebTarget) CompletableFuture(java.util.concurrent.CompletableFuture) RequestBuilder(org.asynchttpclient.RequestBuilder) StringPart(org.asynchttpclient.request.body.multipart.StringPart) File(java.io.File) FilePart(org.asynchttpclient.request.body.multipart.FilePart) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 4 with Sink

use of org.apache.pulsar.client.admin.Sink in project pulsar by yahoo.

the class SinksImpl method updateSinkAsync.

@Override
public CompletableFuture<Void> updateSinkAsync(SinkConfig sinkConfig, String fileName, UpdateOptions updateOptions) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    if (!validateSinkName(sinkConfig.getTenant(), sinkConfig.getNamespace(), sinkConfig.getName(), future)) {
        return future;
    }
    try {
        RequestBuilder builder = put(sink.path(sinkConfig.getTenant()).path(sinkConfig.getNamespace()).path(sinkConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("sinkConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(sinkConfig), MediaType.APPLICATION_JSON));
        UpdateOptionsImpl options = (UpdateOptionsImpl) updateOptions;
        if (options != null) {
            builder.addBodyPart(new StringPart("updateOptions", ObjectMapperFactory.getThreadLocal().writeValueAsString(options), MediaType.APPLICATION_JSON));
        }
        if (fileName != null && !fileName.startsWith("builtin://")) {
            // If the function code is built in, we don't need to submit here
            builder.addBodyPart(new FilePart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM));
        }
        asyncHttpClient.executeRequest(addAuthHeaders(sink, builder).build()).toCompletableFuture().thenAccept(response -> {
            if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) {
                future.completeExceptionally(getApiException(Response.status(response.getStatusCode()).entity(response.getResponseBody()).build()));
            } else {
                future.complete(null);
            }
        }).exceptionally(throwable -> {
            future.completeExceptionally(getApiException(throwable));
            return null;
        });
    } catch (Exception e) {
        future.completeExceptionally(getApiException(e));
    }
    return future;
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) ConnectorDefinition(org.apache.pulsar.common.io.ConnectorDefinition) UpdateOptions(org.apache.pulsar.common.functions.UpdateOptions) ObjectMapperFactory(org.apache.pulsar.common.util.ObjectMapperFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Sink(org.apache.pulsar.client.admin.Sink) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) Gson(com.google.gson.Gson) InvocationCallback(javax.ws.rs.client.InvocationCallback) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) RequestBuilder(org.asynchttpclient.RequestBuilder) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) SinkConfig(org.apache.pulsar.common.io.SinkConfig) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) Sinks(org.apache.pulsar.client.admin.Sinks) FilePart(org.asynchttpclient.request.body.multipart.FilePart) Entity(javax.ws.rs.client.Entity) File(java.io.File) Dsl.post(org.asynchttpclient.Dsl.post) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Dsl.put(org.asynchttpclient.Dsl.put) Response(javax.ws.rs.core.Response) Authentication(org.apache.pulsar.client.api.Authentication) StringPart(org.asynchttpclient.request.body.multipart.StringPart) WebTarget(javax.ws.rs.client.WebTarget) CompletableFuture(java.util.concurrent.CompletableFuture) RequestBuilder(org.asynchttpclient.RequestBuilder) StringPart(org.asynchttpclient.request.body.multipart.StringPart) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) File(java.io.File) FilePart(org.asynchttpclient.request.body.multipart.FilePart) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Example 5 with Sink

use of org.apache.pulsar.client.admin.Sink in project pulsar by yahoo.

the class SinksImpl method createSinkAsync.

@Override
public CompletableFuture<Void> createSinkAsync(SinkConfig sinkConfig, String fileName) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    if (!validateSinkName(sinkConfig.getTenant(), sinkConfig.getNamespace(), sinkConfig.getName(), future)) {
        return future;
    }
    try {
        RequestBuilder builder = post(sink.path(sinkConfig.getTenant()).path(sinkConfig.getNamespace()).path(sinkConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("sinkConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(sinkConfig), MediaType.APPLICATION_JSON));
        if (fileName != null && !fileName.startsWith("builtin://")) {
            // If the function code is built in, we don't need to submit here
            builder.addBodyPart(new FilePart("data", new File(fileName), MediaType.APPLICATION_OCTET_STREAM));
        }
        asyncHttpClient.executeRequest(addAuthHeaders(sink, builder).build()).toCompletableFuture().thenAccept(response -> {
            if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) {
                future.completeExceptionally(getApiException(Response.status(response.getStatusCode()).entity(response.getResponseBody()).build()));
            } else {
                future.complete(null);
            }
        }).exceptionally(throwable -> {
            future.completeExceptionally(getApiException(throwable));
            return null;
        });
    } catch (Exception e) {
        future.completeExceptionally(getApiException(e));
    }
    return future;
}
Also used : AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) ConnectorDefinition(org.apache.pulsar.common.io.ConnectorDefinition) UpdateOptions(org.apache.pulsar.common.functions.UpdateOptions) ObjectMapperFactory(org.apache.pulsar.common.util.ObjectMapperFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Sink(org.apache.pulsar.client.admin.Sink) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) Gson(com.google.gson.Gson) InvocationCallback(javax.ws.rs.client.InvocationCallback) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) RequestBuilder(org.asynchttpclient.RequestBuilder) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) SinkConfig(org.apache.pulsar.common.io.SinkConfig) SinkStatus(org.apache.pulsar.common.policies.data.SinkStatus) Sinks(org.apache.pulsar.client.admin.Sinks) FilePart(org.asynchttpclient.request.body.multipart.FilePart) Entity(javax.ws.rs.client.Entity) File(java.io.File) Dsl.post(org.asynchttpclient.Dsl.post) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Dsl.put(org.asynchttpclient.Dsl.put) Response(javax.ws.rs.core.Response) Authentication(org.apache.pulsar.client.api.Authentication) StringPart(org.asynchttpclient.request.body.multipart.StringPart) WebTarget(javax.ws.rs.client.WebTarget) CompletableFuture(java.util.concurrent.CompletableFuture) RequestBuilder(org.asynchttpclient.RequestBuilder) StringPart(org.asynchttpclient.request.body.multipart.StringPart) File(java.io.File) FilePart(org.asynchttpclient.request.body.multipart.FilePart) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException)

Aggregations

Gson (com.google.gson.Gson)6 File (java.io.File)6 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Entity (javax.ws.rs.client.Entity)6 InvocationCallback (javax.ws.rs.client.InvocationCallback)6 WebTarget (javax.ws.rs.client.WebTarget)6 GenericType (javax.ws.rs.core.GenericType)6 MediaType (javax.ws.rs.core.MediaType)6 Response (javax.ws.rs.core.Response)6 Slf4j (lombok.extern.slf4j.Slf4j)6 StringUtils (org.apache.commons.lang3.StringUtils)6 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)6 Sink (org.apache.pulsar.client.admin.Sink)6 Sinks (org.apache.pulsar.client.admin.Sinks)6 Authentication (org.apache.pulsar.client.api.Authentication)6 UpdateOptions (org.apache.pulsar.common.functions.UpdateOptions)6 UpdateOptionsImpl (org.apache.pulsar.common.functions.UpdateOptionsImpl)6 ConnectorDefinition (org.apache.pulsar.common.io.ConnectorDefinition)6 SinkConfig (org.apache.pulsar.common.io.SinkConfig)6