Search in sources :

Example 16 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class BrokerServiceLookupTest method testMultipleBrokerLookup.

/**
     * UsecaseL Multiple Broker => Lookup Redirection test
     * 
     * 1. Broker1 is a leader
     * 2. Lookup request reaches to Broker2 which redirects to leader (Broker1) with authoritative = false
     * 3. Leader (Broker1) finds out least loaded broker as Broker2 and redirects request to Broker2 with authoritative = true
     * 4. Broker2 receives final request to own a bundle with authoritative = true and client connects to Broker2
     * 
     * @throws Exception
     */
@Test
public void testMultipleBrokerLookup() throws Exception {
    log.info("-- Starting {} test --", methodName);
    /**** start broker-2 ****/
    ServiceConfiguration conf2 = new ServiceConfiguration();
    conf2.setBrokerServicePort(PortManager.nextFreePort());
    conf2.setBrokerServicePortTls(PortManager.nextFreePort());
    conf2.setWebServicePort(PortManager.nextFreePort());
    conf2.setWebServicePortTls(PortManager.nextFreePort());
    conf2.setAdvertisedAddress("localhost");
    conf2.setClusterName(conf.getClusterName());
    PulsarService pulsar2 = startBroker(conf2);
    pulsar.getLoadManager().writeLoadReportOnZookeeper();
    pulsar2.getLoadManager().writeLoadReportOnZookeeper();
    LoadManager loadManager1 = spy(pulsar.getLoadManager());
    LoadManager loadManager2 = spy(pulsar2.getLoadManager());
    Field loadManagerField = NamespaceService.class.getDeclaredField("loadManager");
    loadManagerField.setAccessible(true);
    // mock: redirect request to leader [2]
    doReturn(true).when(loadManager2).isCentralized();
    loadManagerField.set(pulsar2.getNamespaceService(), loadManager2);
    // mock: return Broker2 as a Least-loaded broker when leader receies request [3] 
    doReturn(true).when(loadManager1).isCentralized();
    SimpleResourceUnit resourceUnit = new SimpleResourceUnit(pulsar2.getWebServiceAddress(), null);
    doReturn(resourceUnit).when(loadManager1).getLeastLoaded(any(ServiceUnitId.class));
    loadManagerField.set(pulsar.getNamespaceService(), loadManager1);
    /**** started broker-2 ****/
    URI brokerServiceUrl = new URI("pulsar://localhost:" + conf2.getBrokerServicePort());
    PulsarClient pulsarClient2 = PulsarClient.create(brokerServiceUrl.toString(), new ClientConfiguration());
    // load namespace-bundle by calling Broker2
    Consumer consumer = pulsarClient2.subscribe("persistent://my-property/use/my-ns/my-topic1", "my-subscriber-name", new ConsumerConfiguration());
    Producer producer = pulsarClient.createProducer("persistent://my-property/use/my-ns/my-topic1", new ProducerConfiguration());
    for (int i = 0; i < 10; i++) {
        String message = "my-message-" + i;
        producer.send(message.getBytes());
    }
    Message msg = null;
    Set<String> messageSet = Sets.newHashSet();
    for (int i = 0; i < 10; i++) {
        msg = consumer.receive(5, TimeUnit.SECONDS);
        String receivedMessage = new String(msg.getData());
        log.debug("Received message: [{}]", receivedMessage);
        String expectedMessage = "my-message-" + i;
        testMessageOrderAndDuplicates(messageSet, receivedMessage, expectedMessage);
    }
    // Acknowledge the consumption of all messages at once
    consumer.acknowledgeCumulative(msg);
    consumer.close();
    producer.close();
    pulsarClient2.close();
    pulsar2.close();
    loadManager1 = null;
    loadManager2 = null;
}
Also used : LoadManager(com.yahoo.pulsar.broker.loadbalance.LoadManager) URI(java.net.URI) Field(java.lang.reflect.Field) SimpleResourceUnit(com.yahoo.pulsar.broker.loadbalance.impl.SimpleResourceUnit) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) ServiceUnitId(com.yahoo.pulsar.common.naming.ServiceUnitId) Test(org.testng.annotations.Test)

Example 17 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class PulsarConfigurationLoaderTest method testPulsarConfiguraitonLoadingStream.

@Test
public void testPulsarConfiguraitonLoadingStream() throws Exception {
    File testConfigFile = new File("tmp." + System.currentTimeMillis() + ".properties");
    if (testConfigFile.exists()) {
        testConfigFile.delete();
    }
    final String zkServer = "z1.example.com,z2.example.com,z3.example.com";
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(testConfigFile)));
    printWriter.println("zookeeperServers=" + zkServer);
    printWriter.println("globalZookeeperServers=gz1.example.com,gz2.example.com,gz3.example.com/foo");
    printWriter.println("brokerDeleteInactiveTopicsEnabled=true");
    printWriter.println("statusFilePath=/tmp/status.html");
    printWriter.println("managedLedgerDefaultEnsembleSize=1");
    printWriter.println("backlogQuotaDefaultLimitGB=18");
    printWriter.println("clusterName=usc");
    printWriter.println("brokerClientAuthenticationPlugin=test.xyz.client.auth.plugin");
    printWriter.println("brokerClientAuthenticationParameters=role:my-role");
    printWriter.println("superUserRoles=appid1,appid2");
    printWriter.println("brokerServicePort=7777");
    printWriter.println("managedLedgerDefaultMarkDeleteRateLimit=5.0");
    printWriter.close();
    testConfigFile.deleteOnExit();
    InputStream stream = new FileInputStream(testConfigFile);
    final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(stream, ServiceConfiguration.class);
    assertNotNull(serviceConfig);
    assertEquals(serviceConfig.getZookeeperServers(), zkServer);
    assertEquals(serviceConfig.isBrokerDeleteInactiveTopicsEnabled(), true);
    assertEquals(serviceConfig.getBacklogQuotaDefaultLimitGB(), 18);
    assertEquals(serviceConfig.getClusterName(), "usc");
    assertEquals(serviceConfig.getBrokerClientAuthenticationParameters(), "role:my-role");
    assertEquals(serviceConfig.getBrokerServicePort(), 7777);
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 18 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class PulsarConfigurationLoaderTest method testPulsarConfiguraitonLoadingProp.

@Test
public void testPulsarConfiguraitonLoadingProp() throws Exception {
    final String zk = "localhost:2184";
    final Properties prop = new Properties();
    prop.setProperty("zookeeperServers", zk);
    final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(prop, ServiceConfiguration.class);
    assertNotNull(serviceConfig);
    assertEquals(serviceConfig.getZookeeperServers(), zk);
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 19 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class PulsarBrokerStarter method loadConfig.

private static ServiceConfiguration loadConfig(String configFile) throws Exception {
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    ServiceConfiguration config = create((new FileInputStream(configFile)), ServiceConfiguration.class);
    // it validates provided configuration is completed
    isComplete(config);
    return config;
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) FileInputStream(java.io.FileInputStream)

Example 20 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class WebSocketService method createServiceConfiguration.

private static ServiceConfiguration createServiceConfiguration(WebSocketProxyConfiguration config) {
    ServiceConfiguration serviceConfig = new ServiceConfiguration();
    serviceConfig.setClusterName(config.getClusterName());
    serviceConfig.setWebServicePort(config.getWebServicePort());
    serviceConfig.setWebServicePortTls(config.getWebServicePortTls());
    serviceConfig.setAuthenticationEnabled(config.isAuthenticationEnabled());
    serviceConfig.setAuthenticationProviders(config.getAuthenticationProviders());
    serviceConfig.setBrokerClientAuthenticationPlugin(config.getBrokerClientAuthenticationPlugin());
    serviceConfig.setBrokerClientAuthenticationParameters(config.getBrokerClientAuthenticationParameters());
    serviceConfig.setAuthorizationEnabled(config.isAuthorizationEnabled());
    serviceConfig.setSuperUserRoles(config.getSuperUserRoles());
    serviceConfig.setGlobalZookeeperServers(config.getGlobalZookeeperServers());
    serviceConfig.setZooKeeperSessionTimeoutMillis(config.getZooKeeperSessionTimeoutMillis());
    serviceConfig.setTlsEnabled(config.isTlsEnabled());
    serviceConfig.setTlsCertificateFilePath(config.getTlsCertificateFilePath());
    serviceConfig.setTlsKeyFilePath(config.getTlsKeyFilePath());
    return serviceConfig;
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration)

Aggregations

ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)36 PulsarService (com.yahoo.pulsar.broker.PulsarService)18 Test (org.testng.annotations.Test)15 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)8 BeforeMethod (org.testng.annotations.BeforeMethod)8 AuthenticationService (com.yahoo.pulsar.broker.authentication.AuthenticationService)7 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)7 URL (java.net.URL)7 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)6 Authentication (com.yahoo.pulsar.client.api.Authentication)6 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)6 Field (java.lang.reflect.Field)6 ConfigurationCacheService (com.yahoo.pulsar.broker.cache.ConfigurationCacheService)5 NamespaceService (com.yahoo.pulsar.broker.namespace.NamespaceService)5 Policies (com.yahoo.pulsar.common.policies.data.Policies)5 LocalBookkeeperEnsemble (com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble)5 InetSocketAddress (java.net.InetSocketAddress)5 URI (java.net.URI)5 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)5 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)4