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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations