use of org.apache.pulsar.packages.management.core.common.PackageName in project pulsar by apache.
the class PackagesImpl method listPackageVersionsAsync.
@Override
public CompletableFuture<List<String>> listPackageVersionsAsync(String packageName) {
PackageName name = PackageName.get(packageName);
WebTarget path = packages.path(String.format("%s/%s/%s/%s", name.getPkgType().toString(), name.getTenant(), name.getNamespace(), name.getName()));
final CompletableFuture<List<String>> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<List<String>>() {
@Override
public void completed(List<String> strings) {
future.complete(strings);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.packages.management.core.common.PackageName in project pulsar by apache.
the class PackagesImpl method deleteAsync.
@Override
public CompletableFuture<Void> deleteAsync(String packageName) {
PackageName name = PackageName.get(packageName);
WebTarget path = packages.path(name.toRestPath());
return asyncDeleteRequest(path);
}
use of org.apache.pulsar.packages.management.core.common.PackageName in project pulsar by apache.
the class PackagesManagementImplTest method testPackagesManagementFlow.
@Test
public void testPackagesManagementFlow() {
PackageName packageName = PackageName.get("function://tenant/ns/non-existent-package@v1");
// get a non-existent package metadata should fail
try {
packagesManagement.getMeta(packageName).get();
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// update a non-existent package metadata should fail
PackageMetadata failedUpdateMetadata = PackageMetadata.builder().description("Failed update package metadata").build();
try {
packagesManagement.updateMeta(packageName, failedUpdateMetadata).get();
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// download a non-existent package should fail
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
packagesManagement.download(packageName, outputStream).get();
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// delete a non-existent package should fail
try {
packagesManagement.delete(packageName).get();
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// list a non-existent package version should fail
try {
packagesManagement.list(packageName).get();
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// list the packages in a non-existent namespace should fail
try {
packagesManagement.list(packageName.getPkgType(), packageName.getTenant(), packageName.getNamespace()).get();
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// upload a package
PackageMetadata metadata = PackageMetadata.builder().contact("test@apache.org").description("A mocked test package").createTime(System.currentTimeMillis()).build();
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(PackageMetadataUtil.toBytes(metadata))) {
packagesManagement.upload(packageName, metadata, inputStream).get();
} catch (Exception e) {
Assert.fail("should not throw any exception");
}
// get an existent package metadata should succeed
try {
PackageMetadata getPackageMetadata = packagesManagement.getMeta(packageName).get();
Assert.assertEquals(metadata, getPackageMetadata);
} catch (Exception e) {
Assert.fail("should not throw any exception");
}
// download an existent package should succeed
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
packagesManagement.download(packageName, outputStream).get();
PackageMetadata getPackage = PackageMetadataUtil.fromBytes(outputStream.toByteArray());
Assert.assertEquals(metadata, getPackage);
} catch (Exception e) {
Assert.fail("should not throw any exception");
}
// update an existent package metadata should succeed
metadata.setModificationTime(System.currentTimeMillis());
try {
packagesManagement.updateMeta(packageName, metadata).get();
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// get the updated metadata
try {
PackageMetadata updatedMetadata = packagesManagement.getMeta(packageName).get();
Assert.assertEquals(metadata, updatedMetadata);
} catch (Exception e) {
Assert.fail("should not throw any exception");
}
// list an existent package version should success
try {
List<String> versions = packagesManagement.list(packageName).get();
Assert.assertEquals(1, versions.size());
Assert.assertEquals(packageName.getVersion(), versions.get(0));
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// list the packages in a non-existent namespace should fail
try {
List<String> packageNames = packagesManagement.list(packageName.getPkgType(), packageName.getTenant(), packageName.getNamespace()).get();
Assert.assertEquals(1, packageNames.size());
Assert.assertEquals(packageName.getName(), packageNames.get(0));
} catch (Exception e) {
if (!(e.getCause() instanceof PackagesManagementException.NotFoundException)) {
Assert.fail("should not throw any exception");
}
}
// delete an existent package should succeed
try {
packagesManagement.delete(packageName).get();
} catch (Exception e) {
Assert.fail("should not throw any exception");
}
}
use of org.apache.pulsar.packages.management.core.common.PackageName in project pulsar by yahoo.
the class PackagesBase method getPackageNameAsync.
private CompletableFuture<PackageName> getPackageNameAsync(String type, String tenant, String namespace, String packageName, String version) {
CompletableFuture<PackageName> future = new CompletableFuture<>();
try {
PackageName name = PackageName.get(type, tenant, namespace, packageName, version);
future.complete(name);
} catch (IllegalArgumentException illegalArgumentException) {
future.completeExceptionally(illegalArgumentException);
}
return future;
}
use of org.apache.pulsar.packages.management.core.common.PackageName 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;
}
Aggregations