Search in sources :

Example 1 with UpdateOptions

use of org.apache.pulsar.common.functions.UpdateOptions in project pulsar by apache.

the class FunctionsImpl method updateFunctionAsync.

@Override
public CompletableFuture<Void> updateFunctionAsync(FunctionConfig functionConfig, String fileName, UpdateOptions updateOptions) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    try {
        RequestBuilder builder = put(functions.path(functionConfig.getTenant()).path(functionConfig.getNamespace()).path(functionConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("functionConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(functionConfig), 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(functions, 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 : FileDataBodyPart(org.glassfish.jersey.media.multipart.file.FileDataBodyPart) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) 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) FunctionInstanceStatsData(org.apache.pulsar.common.policies.data.FunctionInstanceStatsData) CompletableFuture(java.util.concurrent.CompletableFuture) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) MediaType(javax.ws.rs.core.MediaType) FunctionStatus(org.apache.pulsar.common.policies.data.FunctionStatus) Gson(com.google.gson.Gson) InvocationCallback(javax.ws.rs.client.InvocationCallback) FunctionConfig(org.apache.pulsar.common.functions.FunctionConfig) FunctionInstanceStatsDataImpl(org.apache.pulsar.common.policies.data.FunctionInstanceStatsDataImpl) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) Functions(org.apache.pulsar.client.admin.Functions) WorkerInfo(org.apache.pulsar.common.functions.WorkerInfo) FunctionState(org.apache.pulsar.common.functions.FunctionState) RequestBuilder(org.asynchttpclient.RequestBuilder) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) FunctionStats(org.apache.pulsar.common.policies.data.FunctionStats) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) AsyncHandler(org.asynchttpclient.AsyncHandler) IOException(java.io.IOException) ByteArrayPart(org.asynchttpclient.request.body.multipart.ByteArrayPart) FilePart(org.asynchttpclient.request.body.multipart.FilePart) Collectors(java.util.stream.Collectors) 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) FunctionStatsImpl(org.apache.pulsar.common.policies.data.FunctionStatsImpl) Authentication(org.apache.pulsar.client.api.Authentication) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart) Dsl.get(org.asynchttpclient.Dsl.get) StringPart(org.asynchttpclient.request.body.multipart.StringPart) WebTarget(javax.ws.rs.client.WebTarget) FileChannel(java.nio.channels.FileChannel) 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) IOException(java.io.IOException)

Example 2 with UpdateOptions

use of org.apache.pulsar.common.functions.UpdateOptions 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 3 with UpdateOptions

use of org.apache.pulsar.common.functions.UpdateOptions 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 4 with UpdateOptions

use of org.apache.pulsar.common.functions.UpdateOptions in project incubator-pulsar by apache.

the class SourcesImpl method updateSourceAsync.

@Override
public CompletableFuture<Void> updateSourceAsync(SourceConfig sourceConfig, String fileName, UpdateOptions updateOptions) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    try {
        RequestBuilder builder = put(source.path(sourceConfig.getTenant()).path(sourceConfig.getNamespace()).path(sourceConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("sourceConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(sourceConfig), 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(source, 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) SourceStatus(org.apache.pulsar.common.policies.data.SourceStatus) CompletableFuture(java.util.concurrent.CompletableFuture) Source(org.apache.pulsar.client.admin.Source) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) 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) SourceConfig(org.apache.pulsar.common.io.SourceConfig) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Sources(org.apache.pulsar.client.admin.Sources) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) 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 UpdateOptions

use of org.apache.pulsar.common.functions.UpdateOptions in project incubator-pulsar by apache.

the class FunctionsImpl method updateFunctionAsync.

@Override
public CompletableFuture<Void> updateFunctionAsync(FunctionConfig functionConfig, String fileName, UpdateOptions updateOptions) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    try {
        RequestBuilder builder = put(functions.path(functionConfig.getTenant()).path(functionConfig.getNamespace()).path(functionConfig.getName()).getUri().toASCIIString()).addBodyPart(new StringPart("functionConfig", ObjectMapperFactory.getThreadLocal().writeValueAsString(functionConfig), 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(functions, 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 : FileDataBodyPart(org.glassfish.jersey.media.multipart.file.FileDataBodyPart) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) 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) FunctionInstanceStatsData(org.apache.pulsar.common.policies.data.FunctionInstanceStatsData) CompletableFuture(java.util.concurrent.CompletableFuture) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) StringUtils(org.apache.commons.lang3.StringUtils) HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) MediaType(javax.ws.rs.core.MediaType) FunctionStatus(org.apache.pulsar.common.policies.data.FunctionStatus) Gson(com.google.gson.Gson) InvocationCallback(javax.ws.rs.client.InvocationCallback) FunctionConfig(org.apache.pulsar.common.functions.FunctionConfig) FunctionInstanceStatsDataImpl(org.apache.pulsar.common.policies.data.FunctionInstanceStatsDataImpl) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) Functions(org.apache.pulsar.client.admin.Functions) WorkerInfo(org.apache.pulsar.common.functions.WorkerInfo) FunctionState(org.apache.pulsar.common.functions.FunctionState) RequestBuilder(org.asynchttpclient.RequestBuilder) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) FunctionStats(org.apache.pulsar.common.policies.data.FunctionStats) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) UpdateOptionsImpl(org.apache.pulsar.common.functions.UpdateOptionsImpl) AsyncHandler(org.asynchttpclient.AsyncHandler) IOException(java.io.IOException) ByteArrayPart(org.asynchttpclient.request.body.multipart.ByteArrayPart) FilePart(org.asynchttpclient.request.body.multipart.FilePart) Collectors(java.util.stream.Collectors) 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) FunctionStatsImpl(org.apache.pulsar.common.policies.data.FunctionStatsImpl) Authentication(org.apache.pulsar.client.api.Authentication) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart) Dsl.get(org.asynchttpclient.Dsl.get) StringPart(org.asynchttpclient.request.body.multipart.StringPart) WebTarget(javax.ws.rs.client.WebTarget) FileChannel(java.nio.channels.FileChannel) 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) IOException(java.io.IOException)

Aggregations

Gson (com.google.gson.Gson)9 File (java.io.File)9 List (java.util.List)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 Entity (javax.ws.rs.client.Entity)9 InvocationCallback (javax.ws.rs.client.InvocationCallback)9 WebTarget (javax.ws.rs.client.WebTarget)9 GenericType (javax.ws.rs.core.GenericType)9 MediaType (javax.ws.rs.core.MediaType)9 Response (javax.ws.rs.core.Response)9 Slf4j (lombok.extern.slf4j.Slf4j)9 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)9 Authentication (org.apache.pulsar.client.api.Authentication)9 UpdateOptions (org.apache.pulsar.common.functions.UpdateOptions)9 UpdateOptionsImpl (org.apache.pulsar.common.functions.UpdateOptionsImpl)9 ConnectorDefinition (org.apache.pulsar.common.io.ConnectorDefinition)9 ObjectMapperFactory (org.apache.pulsar.common.util.ObjectMapperFactory)9 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)9 Dsl.post (org.asynchttpclient.Dsl.post)9 Dsl.put (org.asynchttpclient.Dsl.put)9