Search in sources :

Example 1 with PackagesManagementException

use of org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException in project pulsar by yahoo.

the class PackagesManagementImpl method getMeta.

@Override
public CompletableFuture<PackageMetadata> getMeta(PackageName packageName) {
    CompletableFuture<PackageMetadata> future = new CompletableFuture<>();
    String metadataPath = metadataPath(packageName);
    checkMetadataNotExistsAndThrowException(packageName).whenComplete((ignore, throwable) -> {
        if (throwable != null) {
            future.completeExceptionally(throwable);
            return;
        }
        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            storage.readAsync(metadataPath, outputStream).thenCompose(aVoid -> metadataReadFromStream(outputStream)).whenComplete((metadata, t) -> {
                if (t != null) {
                    future.completeExceptionally(t);
                } else {
                    future.complete(metadata);
                }
            });
        } catch (IOException e) {
            future.completeExceptionally(new PackagesManagementException(String.format("Read package '%s' metadata failed", packageName.toString()), e));
        }
    });
    return future;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) PackageMetadataUtil(org.apache.pulsar.packages.management.core.common.PackageMetadataUtil) PackageMetadata(org.apache.pulsar.packages.management.core.common.PackageMetadata) PackageType(org.apache.pulsar.packages.management.core.common.PackageType) List(java.util.List) PackagesStorage(org.apache.pulsar.packages.management.core.PackagesStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) NotFoundException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException.NotFoundException) PackagesManagement(org.apache.pulsar.packages.management.core.PackagesManagement) PackageName(org.apache.pulsar.packages.management.core.common.PackageName) InputStream(java.io.InputStream) CompletableFuture(java.util.concurrent.CompletableFuture) PackageMetadata(org.apache.pulsar.packages.management.core.common.PackageMetadata) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with PackagesManagementException

use of org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException in project incubator-pulsar by apache.

the class PackagesManagementImpl method writeMeta.

private CompletableFuture<Void> writeMeta(PackageName packageName, PackageMetadata metadata) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    String metadataPath = metadataPath(packageName);
    try (ByteArrayInputStream inputStream = new ByteArrayInputStream(PackageMetadataUtil.toBytes(metadata))) {
        storage.writeAsync(metadataPath, inputStream).whenComplete((aVoid, t) -> {
            if (t != null) {
                future.completeExceptionally(new PackagesManagementException(String.format("Update package '%s' metadata failed", packageName.toString()), t));
            } else {
                future.complete(null);
            }
        });
    } catch (IOException e) {
        future.completeExceptionally(new PackagesManagementException(String.format("Read package '%s' metadata failed", packageName.toString()), e));
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ByteArrayInputStream(java.io.ByteArrayInputStream) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) IOException(java.io.IOException)

Example 3 with PackagesManagementException

use of org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException in project incubator-pulsar by apache.

the class PackagesManagementImpl method updateMeta.

@Override
public CompletableFuture<Void> updateMeta(PackageName packageName, PackageMetadata metadata) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    String metadataPath = metadataPath(packageName);
    checkMetadataNotExistsAndThrowException(packageName).whenComplete((ignore, throwable) -> {
        if (throwable != null) {
            future.completeExceptionally(throwable);
            return;
        }
        try (ByteArrayInputStream inputStream = new ByteArrayInputStream(PackageMetadataUtil.toBytes(metadata))) {
            storage.deleteAsync(metadataPath).thenCompose(aVoid -> storage.writeAsync(metadataPath, inputStream)).whenComplete((aVoid, t) -> {
                if (t != null) {
                    future.completeExceptionally(new PackagesManagementException(String.format("Update package '%s' metadata failed", packageName.toString()), t));
                } else {
                    future.complete(null);
                }
            });
        } catch (IOException e) {
            future.completeExceptionally(new PackagesManagementException(String.format("Read package '%s' metadata failed", packageName.toString()), e));
        }
    });
    return future;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) PackageMetadataUtil(org.apache.pulsar.packages.management.core.common.PackageMetadataUtil) PackageMetadata(org.apache.pulsar.packages.management.core.common.PackageMetadata) PackageType(org.apache.pulsar.packages.management.core.common.PackageType) List(java.util.List) PackagesStorage(org.apache.pulsar.packages.management.core.PackagesStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) NotFoundException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException.NotFoundException) PackagesManagement(org.apache.pulsar.packages.management.core.PackagesManagement) PackageName(org.apache.pulsar.packages.management.core.common.PackageName) InputStream(java.io.InputStream) CompletableFuture(java.util.concurrent.CompletableFuture) ByteArrayInputStream(java.io.ByteArrayInputStream) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) IOException(java.io.IOException)

Example 4 with PackagesManagementException

use of org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException in project incubator-pulsar by apache.

the class PackagesManagementImpl method getMeta.

@Override
public CompletableFuture<PackageMetadata> getMeta(PackageName packageName) {
    CompletableFuture<PackageMetadata> future = new CompletableFuture<>();
    String metadataPath = metadataPath(packageName);
    checkMetadataNotExistsAndThrowException(packageName).whenComplete((ignore, throwable) -> {
        if (throwable != null) {
            future.completeExceptionally(throwable);
            return;
        }
        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            storage.readAsync(metadataPath, outputStream).thenCompose(aVoid -> metadataReadFromStream(outputStream)).whenComplete((metadata, t) -> {
                if (t != null) {
                    future.completeExceptionally(t);
                } else {
                    future.complete(metadata);
                }
            });
        } catch (IOException e) {
            future.completeExceptionally(new PackagesManagementException(String.format("Read package '%s' metadata failed", packageName.toString()), e));
        }
    });
    return future;
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) PackageMetadataUtil(org.apache.pulsar.packages.management.core.common.PackageMetadataUtil) PackageMetadata(org.apache.pulsar.packages.management.core.common.PackageMetadata) PackageType(org.apache.pulsar.packages.management.core.common.PackageType) List(java.util.List) PackagesStorage(org.apache.pulsar.packages.management.core.PackagesStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) NotFoundException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException.NotFoundException) PackagesManagement(org.apache.pulsar.packages.management.core.PackagesManagement) PackageName(org.apache.pulsar.packages.management.core.common.PackageName) InputStream(java.io.InputStream) CompletableFuture(java.util.concurrent.CompletableFuture) PackageMetadata(org.apache.pulsar.packages.management.core.common.PackageMetadata) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with PackagesManagementException

use of org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException in project pulsar by yahoo.

the class PackagesManagementImpl method writeMeta.

private CompletableFuture<Void> writeMeta(PackageName packageName, PackageMetadata metadata) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    String metadataPath = metadataPath(packageName);
    try (ByteArrayInputStream inputStream = new ByteArrayInputStream(PackageMetadataUtil.toBytes(metadata))) {
        storage.writeAsync(metadataPath, inputStream).whenComplete((aVoid, t) -> {
            if (t != null) {
                future.completeExceptionally(new PackagesManagementException(String.format("Update package '%s' metadata failed", packageName.toString()), t));
            } else {
                future.complete(null);
            }
        });
    } catch (IOException e) {
        future.completeExceptionally(new PackagesManagementException(String.format("Read package '%s' metadata failed", packageName.toString()), e));
    }
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ByteArrayInputStream(java.io.ByteArrayInputStream) PackagesManagementException(org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException) IOException(java.io.IOException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)9 IOException (java.io.IOException)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 PackagesManagementException (org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 List (java.util.List)6 PackagesManagement (org.apache.pulsar.packages.management.core.PackagesManagement)6 PackagesStorage (org.apache.pulsar.packages.management.core.PackagesStorage)6 PackageMetadata (org.apache.pulsar.packages.management.core.common.PackageMetadata)6 PackageMetadataUtil (org.apache.pulsar.packages.management.core.common.PackageMetadataUtil)6 PackageName (org.apache.pulsar.packages.management.core.common.PackageName)6 PackageType (org.apache.pulsar.packages.management.core.common.PackageType)6 NotFoundException (org.apache.pulsar.packages.management.core.exceptions.PackagesManagementException.NotFoundException)6