Search in sources :

Example 1 with DLOutputStream

use of org.apache.pulsar.functions.worker.dlog.DLOutputStream in project incubator-pulsar by apache.

the class Utils method uploadToBookeeper.

public static void uploadToBookeeper(Namespace dlogNamespace, InputStream uploadedInputStream, String destPkgPath) throws IOException {
    // if the dest directory does not exist, create it.
    if (dlogNamespace.logExists(destPkgPath)) {
        // if the destination file exists, write a log message
        log.info(String.format("Target function file already exists at '%s'. Overwriting it now", destPkgPath));
        dlogNamespace.deleteLog(destPkgPath);
    }
    // copy the topology package to target working directory
    log.info(String.format("Uploading function package to '%s'", destPkgPath));
    try (DistributedLogManager dlm = dlogNamespace.openLog(destPkgPath)) {
        try (AppendOnlyStreamWriter writer = dlm.getAppendOnlyStreamWriter()) {
            try (OutputStream out = new DLOutputStream(dlm, writer)) {
                int read = 0;
                byte[] bytes = new byte[1024];
                while ((read = uploadedInputStream.read(bytes)) != -1) {
                    out.write(bytes, 0, read);
                }
                out.flush();
            }
        }
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AppendOnlyStreamWriter(org.apache.distributedlog.AppendOnlyStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DLOutputStream(org.apache.pulsar.functions.worker.dlog.DLOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) DLOutputStream(org.apache.pulsar.functions.worker.dlog.DLOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 AppendOnlyStreamWriter (org.apache.distributedlog.AppendOnlyStreamWriter)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 DLOutputStream (org.apache.pulsar.functions.worker.dlog.DLOutputStream)1