Search in sources :

Example 6 with LocalBookkeeperEnsemble

use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.

the class LocalBookkeeperEnsembleTest method testStartStop.

@Test
void testStartStop() throws Exception {
    final int numBk = 1;
    final int zkPort = PortManager.nextFreePort();
    final int bkPort = PortManager.nextFreePort();
    // Start local Bookies/ZooKeepers and confirm that they are running at specified ports
    LocalBookkeeperEnsemble ensemble = new LocalBookkeeperEnsemble(numBk, zkPort, bkPort);
    ensemble.start();
    assertTrue(ensemble.getZkServer().isRunning());
    assertEquals(ensemble.getZkServer().getClientPort(), zkPort);
    assertTrue(ensemble.getZkClient().getState().isConnected());
    assertTrue(ensemble.getBookies()[0].isRunning());
    assertEquals(ensemble.getBookies()[0].getLocalAddress().getPort(), bkPort);
    // Stop local Bookies/ZooKeepers and confirm that they are correctly closed
    ensemble.stop();
    assertFalse(ensemble.getZkServer().isRunning());
    assertFalse(ensemble.getZkClient().getState().isConnected());
    assertFalse(ensemble.getBookies()[0].isRunning());
}
Also used : LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) Test(org.testng.annotations.Test)

Example 7 with LocalBookkeeperEnsemble

use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.

the class PulsarStandaloneStarter method start.

void start() throws Exception {
    if (config == null) {
        System.exit(1);
    }
    log.debug("--- setup PulsarStandaloneStarter ---");
    if (!onlyBroker) {
        // Start LocalBookKeeper
        bkEnsemble = new LocalBookkeeperEnsemble(numOfBk, zkPort, bkPort, zkDir, bkDir, wipeData);
        bkEnsemble.start();
    }
    if (noBroker) {
        return;
    }
    // Start Broker
    broker = new PulsarService(config);
    broker.start();
    // Create a sample namespace
    URL webServiceUrl = new URL(String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort()));
    String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(), config.getBrokerServicePort());
    admin = new PulsarAdmin(webServiceUrl, config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters());
    String property = "sample";
    String cluster = config.getClusterName();
    String namespace = property + "/" + cluster + "/ns1";
    try {
        ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, /* serviceUrlTls */
        brokerServiceUrl, null);
        if (!admin.clusters().getClusters().contains(cluster)) {
            admin.clusters().createCluster(cluster, clusterData);
        } else {
            admin.clusters().updateCluster(cluster, clusterData);
        }
        if (!admin.properties().getProperties().contains(property)) {
            admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList(config.getSuperUserRoles()), Sets.newHashSet(cluster)));
        }
        if (!admin.namespaces().getNamespaces(property).contains(namespace)) {
            admin.namespaces().createNamespace(namespace);
        }
    } catch (PulsarAdminException e) {
        log.info(e.getMessage());
    }
    log.debug("--- setup completed ---");
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) PulsarService(com.yahoo.pulsar.broker.PulsarService) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL)

Example 8 with LocalBookkeeperEnsemble

use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.

the class AdvertisedAddressTest method setup.

@Before
public void setup() throws Exception {
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
    bkEnsemble.start();
    ServiceConfiguration config = new ServiceConfiguration();
    config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config.setWebServicePort(BROKER_WEBSERVICE_PORT);
    config.setClusterName("usc");
    config.setBrokerServicePort(BROKER_SERVICE_PORT);
    config.setAdvertisedAddress(advertisedAddress);
    config.setManagedLedgerMaxEntriesPerLedger(5);
    config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
    pulsar = new PulsarService(config);
    pulsar.start();
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) Before(org.junit.Before)

Example 9 with LocalBookkeeperEnsemble

use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.

the class LocalBookkeeperEnsembleTest method testDataDirectoryCreatingAndRemoving.

@Test
void testDataDirectoryCreatingAndRemoving() throws Exception {
    final int numBk = 1;
    final int zkPort = PortManager.nextFreePort();
    final int bkPort = PortManager.nextFreePort();
    final String zkDirName = "/tmp/data/zookeeper";
    File zkDir = new File(zkDirName);
    final String bkDirName = "/tmp/data/bookkeeper";
    File bkDir = new File(bkDirName + "0");
    // At first delete existing data directories
    FileUtils.deleteDirectory(zkDir);
    FileUtils.deleteDirectory(bkDir);
    assertFalse(zkDir.exists());
    assertFalse(bkDir.exists());
    // Start local Bookies/ZooKeepers and confirm that specified data directories are created
    LocalBookkeeperEnsemble ensemble1 = new LocalBookkeeperEnsemble(numBk, zkPort, bkPort, zkDirName, bkDirName, true);
    ensemble1.start();
    assertTrue(zkDir.exists());
    assertTrue(bkDir.exists());
    ensemble1.stop();
    // Restart local Bookies/ZooKeepers without refreshing data
    LocalBookkeeperEnsemble ensemble2 = new LocalBookkeeperEnsemble(numBk, zkPort, bkPort, zkDirName, bkDirName, false);
    ensemble2.start();
    assertTrue(ensemble2.getZkServer().isRunning());
    assertEquals(ensemble2.getZkServer().getClientPort(), zkPort);
    assertTrue(ensemble2.getZkClient().getState().isConnected());
    assertTrue(ensemble2.getBookies()[0].isRunning());
    assertEquals(ensemble2.getBookies()[0].getLocalAddress().getPort(), bkPort);
    // Stop local Bookies/ZooKeepers and confirm that they are correctly closed
    ensemble2.stop();
    assertFalse(ensemble2.getZkServer().isRunning());
    assertFalse(ensemble2.getZkClient().getState().isConnected());
    assertFalse(ensemble2.getBookies()[0].isRunning());
    // Finaly delete data directories
    FileUtils.deleteDirectory(zkDir);
    FileUtils.deleteDirectory(bkDir);
}
Also used : File(java.io.File) LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) Test(org.testng.annotations.Test)

Aggregations

LocalBookkeeperEnsemble (com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble)9 PulsarService (com.yahoo.pulsar.broker.PulsarService)6 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)6 URL (java.net.URL)6 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)5 Authentication (com.yahoo.pulsar.client.api.Authentication)5 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)3 PropertyAdmin (com.yahoo.pulsar.common.policies.data.PropertyAdmin)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 Test (org.testng.annotations.Test)2 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)1 ZookeeperServerTest (com.yahoo.pulsar.zookeeper.ZookeeperServerTest)1 File (java.io.File)1 Before (org.junit.Before)1 BeforeClass (org.testng.annotations.BeforeClass)1