Search in sources :

Example 31 with PulsarService

use of org.apache.pulsar.broker.PulsarService in project incubator-pulsar by apache.

the class AdminApiTest2 method testLoadReportApi.

/**
 * It verifies that pulsar with different load-manager generates different load-report and returned by admin-api
 *
 * @throws Exception
 */
@Test
public void testLoadReportApi() throws Exception {
    this.conf.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    MockedPulsarService mockPulsarSetup1 = new MockedPulsarService(this.conf);
    mockPulsarSetup1.setup();
    PulsarService simpleLoadManager = mockPulsarSetup1.getPulsar();
    PulsarAdmin simpleLoadManagerAdmin = mockPulsarSetup1.getAdmin();
    assertNotNull(simpleLoadManagerAdmin.brokerStats().getLoadReport());
    this.conf.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    MockedPulsarService mockPulsarSetup2 = new MockedPulsarService(this.conf);
    mockPulsarSetup2.setup();
    PulsarService modularLoadManager = mockPulsarSetup2.getPulsar();
    PulsarAdmin modularLoadManagerAdmin = mockPulsarSetup2.getAdmin();
    assertNotNull(modularLoadManagerAdmin.brokerStats().getLoadReport());
    simpleLoadManagerAdmin.close();
    simpleLoadManager.close();
    modularLoadManagerAdmin.close();
    modularLoadManager.close();
    mockPulsarSetup1.cleanup();
    mockPulsarSetup2.cleanup();
}
Also used : SimpleLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) MockedPulsarService(org.apache.pulsar.broker.admin.AdminApiTest.MockedPulsarService) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) MockedPulsarService(org.apache.pulsar.broker.admin.AdminApiTest.MockedPulsarService) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 32 with PulsarService

use of org.apache.pulsar.broker.PulsarService in project incubator-pulsar by apache.

the class BacklogQuotaManagerTest method setup.

@BeforeMethod
void setup() throws Exception {
    try {
        // start local bookie and zookeeper
        bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
        bkEnsemble.start();
        // start pulsar service
        config = new ServiceConfiguration();
        config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
        config.setAdvertisedAddress("localhost");
        config.setWebServicePort(BROKER_WEBSERVICE_PORT);
        config.setClusterName("usc");
        config.setBrokerServicePort(BROKER_SERVICE_PORT);
        config.setAuthorizationEnabled(false);
        config.setAuthenticationEnabled(false);
        config.setBacklogQuotaCheckIntervalInSeconds(TIME_TO_CHECK_BACKLOG_QUOTA);
        config.setManagedLedgerMaxEntriesPerLedger(5);
        config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
        pulsar = new PulsarService(config);
        pulsar.start();
        adminUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
        admin = new PulsarAdmin(adminUrl, (Authentication) null);
        admin.clusters().createCluster("usc", new ClusterData(adminUrl.toString()));
        admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("usc")));
        admin.namespaces().createNamespace("prop/usc/ns-quota");
        admin.namespaces().createNamespace("prop/usc/quotahold");
        admin.namespaces().createNamespace("prop/usc/quotaholdasync");
    } catch (Throwable t) {
        LOG.error("Error setting up broker test", t);
        Assert.fail("Broker test setup failed");
    }
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) Authentication(org.apache.pulsar.client.api.Authentication) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 33 with PulsarService

use of org.apache.pulsar.broker.PulsarService in project flink by apache.

the class PulsarEmbeddedRuntime method startPulsarService.

private void startPulsarService() throws Exception {
    ServiceConfiguration config;
    try (FileInputStream inputStream = new FileInputStream(CONFIG_FILE_PATH)) {
        config = PulsarConfigurationLoader.create(inputStream, ServiceConfiguration.class);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    // Use runtime dynamic ports for broker.
    config.setAdvertisedAddress("127.0.0.1");
    config.setClusterName("standalone");
    // Use random port.
    config.setBrokerServicePort(Optional.of(0));
    config.setWebServicePort(Optional.of(0));
    // Select available port for bookkeeper and zookeeper.
    int zkPort = getZkPort();
    String zkConnect = "127.0.0.1" + ":" + zkPort;
    config.setZookeeperServers(zkConnect);
    config.setConfigurationStoreServers(zkConnect);
    config.setRunningStandalone(true);
    this.pulsarService = new PulsarService(config);
    // Start Pulsar Broker.
    pulsarService.start();
    // Create sample data environment.
    String webServiceUrl = getWebServiceUrl();
    String brokerUrl = getBrokerUrl();
    try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl).build()) {
        ClusterData clusterData = ClusterData.builder().serviceUrl(webServiceUrl).brokerServiceUrl(brokerUrl).build();
        String cluster = config.getClusterName();
        createSampleNameSpace(admin, clusterData, cluster);
        // Create default namespace
        createNameSpace(admin, cluster, TopicName.PUBLIC_TENANT, TopicName.PUBLIC_TENANT + "/" + TopicName.DEFAULT_NAMESPACE);
        // Create Pulsar system namespace
        createNameSpace(admin, cluster, SYSTEM_NAMESPACE.getTenant(), SYSTEM_NAMESPACE.toString());
        // Enable transaction
        if (config.isTransactionCoordinatorEnabled() && !admin.namespaces().getTopics(SYSTEM_NAMESPACE.toString()).contains(TRANSACTION_COORDINATOR_ASSIGN.getPartition(0).toString())) {
            admin.topics().createPartitionedTopic(TRANSACTION_COORDINATOR_ASSIGN.toString(), 1);
        }
    }
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

PulsarService (org.apache.pulsar.broker.PulsarService)33 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)22 URL (java.net.URL)14 BeforeMethod (org.testng.annotations.BeforeMethod)13 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)12 Test (org.testng.annotations.Test)12 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)10 LocalBookkeeperEnsemble (org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble)10 Authentication (org.apache.pulsar.client.api.Authentication)9 TopicName (org.apache.pulsar.common.naming.TopicName)8 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)8 URI (java.net.URI)7 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)7 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)7 Field (java.lang.reflect.Field)6 LoadManager (org.apache.pulsar.broker.loadbalance.LoadManager)6 ModularLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl)6 SimpleResourceUnit (org.apache.pulsar.broker.loadbalance.impl.SimpleResourceUnit)5 ServiceUnitId (org.apache.pulsar.common.naming.ServiceUnitId)5 Optional (java.util.Optional)4