Search in sources :

Example 1 with PackagesStorageProvider

use of org.apache.pulsar.packages.management.core.PackagesStorageProvider in project pulsar by apache.

the class PulsarService method startPackagesManagementService.

private void startPackagesManagementService() throws IOException {
    // TODO: using provider to initialize the packages management service.
    PackagesManagement packagesManagementService = new PackagesManagementImpl();
    this.packagesManagement = Optional.of(packagesManagementService);
    PackagesStorageProvider storageProvider = PackagesStorageProvider.newProvider(config.getPackagesManagementStorageProvider());
    DefaultPackagesStorageConfiguration storageConfiguration = new DefaultPackagesStorageConfiguration();
    storageConfiguration.setProperty(config.getProperties());
    PackagesStorage storage = storageProvider.getStorage(storageConfiguration);
    storage.initialize();
    packagesManagementService.initialize(storage);
}
Also used : PackagesStorage(org.apache.pulsar.packages.management.core.PackagesStorage) PackagesStorageProvider(org.apache.pulsar.packages.management.core.PackagesStorageProvider) PackagesManagementImpl(org.apache.pulsar.packages.management.core.impl.PackagesManagementImpl) PackagesManagement(org.apache.pulsar.packages.management.core.PackagesManagement) DefaultPackagesStorageConfiguration(org.apache.pulsar.packages.management.core.impl.DefaultPackagesStorageConfiguration)

Example 2 with PackagesStorageProvider

use of org.apache.pulsar.packages.management.core.PackagesStorageProvider in project pulsar by apache.

the class BookKeeperPackagesStorageTest method setup.

@BeforeMethod()
public void setup() throws Exception {
    PackagesStorageProvider provider = PackagesStorageProvider.newProvider(BookKeeperPackagesStorageProvider.class.getName());
    DefaultPackagesStorageConfiguration configuration = new DefaultPackagesStorageConfiguration();
    configuration.setProperty("metadataStoreUrl", zkUtil.getZooKeeperConnectString());
    configuration.setProperty("packagesReplicas", "1");
    configuration.setProperty("packagesManagementLedgerRootPath", "/ledgers");
    storage = provider.getStorage(configuration);
    storage.initialize();
}
Also used : PackagesStorageProvider(org.apache.pulsar.packages.management.core.PackagesStorageProvider) DefaultPackagesStorageConfiguration(org.apache.pulsar.packages.management.core.impl.DefaultPackagesStorageConfiguration) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with PackagesStorageProvider

use of org.apache.pulsar.packages.management.core.PackagesStorageProvider in project pulsar by apache.

the class BookKeeperPackagesStorageTest method testReadWriteOperationsWithSeparatedBkCluster.

@Test(timeOut = 60000)
public void testReadWriteOperationsWithSeparatedBkCluster() throws Exception {
    PackagesStorageProvider provider = PackagesStorageProvider.newProvider(BookKeeperPackagesStorageProvider.class.getName());
    DefaultPackagesStorageConfiguration configuration = new DefaultPackagesStorageConfiguration();
    // set the unavailable bk cluster with mock zookeeper path
    configuration.setProperty("metadataStoreUrl", zkUtil.getZooKeeperConnectString() + "/mock");
    configuration.setProperty("packagesReplicas", "1");
    configuration.setProperty("packagesManagementLedgerRootPath", "/ledgers");
    PackagesStorage storage1 = provider.getStorage(configuration);
    storage1.initialize();
    String mockData = "mock-data";
    ByteArrayInputStream mockDataStream = new ByteArrayInputStream(mockData.getBytes(StandardCharsets.UTF_8));
    String mockPath = "mock-path";
    // write some data to the dlog will fail
    try {
        storage1.writeAsync(mockPath, mockDataStream).get();
    } catch (Exception e) {
        String errMsg = e.getCause().getMessage();
        assertTrue(errMsg.contains("Error on allocating ledger") || errMsg.contains("Write rejected"));
    } finally {
        storage1.closeAsync().get();
    }
    // set the available bk cluster with bookkeeperMetadataServiceUri using actual zookeeper path
    String bookkeeperMetadataServiceUri = String.format("zk+null://%s/ledgers", zkUtil.getZooKeeperConnectString());
    DefaultPackagesStorageConfiguration configuration2 = new DefaultPackagesStorageConfiguration();
    configuration2.setProperty("metadataStoreUrl", zkUtil.getZooKeeperConnectString());
    configuration2.setProperty("bookkeeperMetadataServiceUri", bookkeeperMetadataServiceUri);
    configuration2.setProperty("packagesReplicas", "1");
    PackagesStorage storage2 = provider.getStorage(configuration2);
    storage2.initialize();
    String testData = "test-data";
    ByteArrayInputStream testDataStream = new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8));
    String testPath = "test-path";
    // write some data to the dlog will success
    try {
        storage2.writeAsync(testPath, testDataStream).get();
        // read the data from the dlog
        ByteArrayOutputStream readData = new ByteArrayOutputStream();
        storage2.readAsync(testPath, readData).get();
        String readResult = new String(readData.toByteArray(), StandardCharsets.UTF_8);
        assertEquals(testData, readResult);
    } finally {
        storage2.closeAsync().get();
    }
}
Also used : PackagesStorage(org.apache.pulsar.packages.management.core.PackagesStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) PackagesStorageProvider(org.apache.pulsar.packages.management.core.PackagesStorageProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultPackagesStorageConfiguration(org.apache.pulsar.packages.management.core.impl.DefaultPackagesStorageConfiguration) ZKException(org.apache.distributedlog.exceptions.ZKException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 4 with PackagesStorageProvider

use of org.apache.pulsar.packages.management.core.PackagesStorageProvider in project pulsar by apache.

the class PackagesManagementImplTest method setup.

@BeforeClass
public static void setup() throws IOException {
    PackagesStorageProvider storageProvider = PackagesStorageProvider.newProvider(MockedPackagesStorageProvider.class.getName());
    DefaultPackagesStorageConfiguration packagesStorageConfiguration = new DefaultPackagesStorageConfiguration();
    storage = storageProvider.getStorage(packagesStorageConfiguration);
    packagesManagement = new PackagesManagementImpl();
    packagesManagement.initialize(storage);
}
Also used : MockedPackagesStorageProvider(org.apache.pulsar.packages.management.core.MockedPackagesStorageProvider) MockedPackagesStorageProvider(org.apache.pulsar.packages.management.core.MockedPackagesStorageProvider) PackagesStorageProvider(org.apache.pulsar.packages.management.core.PackagesStorageProvider) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with PackagesStorageProvider

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

the class BookKeeperPackagesStorageTest method testReadWriteOperationsWithSeparatedBkCluster.

@Test(timeOut = 60000)
public void testReadWriteOperationsWithSeparatedBkCluster() throws Exception {
    PackagesStorageProvider provider = PackagesStorageProvider.newProvider(BookKeeperPackagesStorageProvider.class.getName());
    DefaultPackagesStorageConfiguration configuration = new DefaultPackagesStorageConfiguration();
    // set the unavailable bk cluster with mock zookeeper path
    configuration.setProperty("metadataStoreUrl", zkUtil.getZooKeeperConnectString() + "/mock");
    configuration.setProperty("packagesReplicas", "1");
    configuration.setProperty("packagesManagementLedgerRootPath", "/ledgers");
    PackagesStorage storage1 = provider.getStorage(configuration);
    storage1.initialize();
    String mockData = "mock-data";
    ByteArrayInputStream mockDataStream = new ByteArrayInputStream(mockData.getBytes(StandardCharsets.UTF_8));
    String mockPath = "mock-path";
    // write some data to the dlog will fail
    try {
        storage1.writeAsync(mockPath, mockDataStream).get();
    } catch (Exception e) {
        String errMsg = e.getCause().getMessage();
        assertTrue(errMsg.contains("Error on allocating ledger") || errMsg.contains("Write rejected"));
    } finally {
        storage1.closeAsync().get();
    }
    // set the available bk cluster with bookkeeperMetadataServiceUri using actual zookeeper path
    String bookkeeperMetadataServiceUri = String.format("zk+null://%s/ledgers", zkUtil.getZooKeeperConnectString());
    DefaultPackagesStorageConfiguration configuration2 = new DefaultPackagesStorageConfiguration();
    configuration2.setProperty("metadataStoreUrl", zkUtil.getZooKeeperConnectString());
    configuration2.setProperty("bookkeeperMetadataServiceUri", bookkeeperMetadataServiceUri);
    configuration2.setProperty("packagesReplicas", "1");
    PackagesStorage storage2 = provider.getStorage(configuration2);
    storage2.initialize();
    String testData = "test-data";
    ByteArrayInputStream testDataStream = new ByteArrayInputStream(testData.getBytes(StandardCharsets.UTF_8));
    String testPath = "test-path";
    // write some data to the dlog will success
    try {
        storage2.writeAsync(testPath, testDataStream).get();
        // read the data from the dlog
        ByteArrayOutputStream readData = new ByteArrayOutputStream();
        storage2.readAsync(testPath, readData).get();
        String readResult = new String(readData.toByteArray(), StandardCharsets.UTF_8);
        assertEquals(testData, readResult);
    } finally {
        storage2.closeAsync().get();
    }
}
Also used : PackagesStorage(org.apache.pulsar.packages.management.core.PackagesStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) PackagesStorageProvider(org.apache.pulsar.packages.management.core.PackagesStorageProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultPackagesStorageConfiguration(org.apache.pulsar.packages.management.core.impl.DefaultPackagesStorageConfiguration) ZKException(org.apache.distributedlog.exceptions.ZKException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Aggregations

PackagesStorageProvider (org.apache.pulsar.packages.management.core.PackagesStorageProvider)15 DefaultPackagesStorageConfiguration (org.apache.pulsar.packages.management.core.impl.DefaultPackagesStorageConfiguration)12 BeforeMethod (org.testng.annotations.BeforeMethod)8 PackagesStorage (org.apache.pulsar.packages.management.core.PackagesStorage)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ExecutionException (java.util.concurrent.ExecutionException)3 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)3 ZKException (org.apache.distributedlog.exceptions.ZKException)3 MockedPackagesStorageProvider (org.apache.pulsar.packages.management.core.MockedPackagesStorageProvider)3 PackagesManagement (org.apache.pulsar.packages.management.core.PackagesManagement)3 PackagesManagementImpl (org.apache.pulsar.packages.management.core.impl.PackagesManagementImpl)3 Test (org.testng.annotations.Test)3 BeforeClass (org.testng.annotations.BeforeClass)1