Search in sources :

Example 16 with Authentication

use of org.apache.pulsar.client.api.Authentication in project incubator-pulsar by apache.

the class PulsarClientKafkaConfig method getClientBuilder.

public static ClientBuilder getClientBuilder(Properties properties) {
    ClientBuilder clientBuilder = PulsarClient.builder();
    if (properties.containsKey(AUTHENTICATION_CLASS)) {
        String className = properties.getProperty(AUTHENTICATION_CLASS);
        try {
            @SuppressWarnings("unchecked") Class<Authentication> clazz = (Class<Authentication>) Class.forName(className);
            Authentication auth = clazz.newInstance();
            clientBuilder.authentication(auth);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    clientBuilder.enableTls(Boolean.parseBoolean(properties.getProperty(USE_TLS, "false")));
    clientBuilder.allowTlsInsecureConnection(Boolean.parseBoolean(properties.getProperty(TLS_ALLOW_INSECURE_CONNECTION, "false")));
    clientBuilder.enableTlsHostnameVerification(Boolean.parseBoolean(properties.getProperty(TLS_HOSTNAME_VERIFICATION, "false")));
    if (properties.containsKey(TLS_TRUST_CERTS_FILE_PATH)) {
        clientBuilder.tlsTrustCertsFilePath(properties.getProperty(TLS_TRUST_CERTS_FILE_PATH));
    }
    if (properties.containsKey(OPERATION_TIMEOUT_MS)) {
        clientBuilder.operationTimeout(Integer.parseInt(properties.getProperty(OPERATION_TIMEOUT_MS)), TimeUnit.MILLISECONDS);
    }
    if (properties.containsKey(STATS_INTERVAL_SECONDS)) {
        clientBuilder.statsInterval(Integer.parseInt(properties.getProperty(STATS_INTERVAL_SECONDS)), TimeUnit.SECONDS);
    }
    if (properties.containsKey(NUM_IO_THREADS)) {
        clientBuilder.ioThreads(Integer.parseInt(properties.getProperty(NUM_IO_THREADS)));
    }
    if (properties.containsKey(CONNECTIONS_PER_BROKER)) {
        clientBuilder.connectionsPerBroker(Integer.parseInt(properties.getProperty(CONNECTIONS_PER_BROKER)));
    }
    if (properties.containsKey(USE_TCP_NODELAY)) {
        clientBuilder.enableTcpNoDelay(Boolean.parseBoolean(properties.getProperty(USE_TCP_NODELAY)));
    }
    if (properties.containsKey(CONCURRENT_LOOKUP_REQUESTS)) {
        clientBuilder.maxConcurrentLookupRequests(Integer.parseInt(properties.getProperty(CONCURRENT_LOOKUP_REQUESTS)));
    }
    if (properties.containsKey(MAX_NUMBER_OF_REJECTED_REQUESTS_PER_CONNECTION)) {
        clientBuilder.maxNumberOfRejectedRequestPerConnection(Integer.parseInt(properties.getProperty(MAX_NUMBER_OF_REJECTED_REQUESTS_PER_CONNECTION)));
    }
    return clientBuilder;
}
Also used : Authentication(org.apache.pulsar.client.api.Authentication) ClientBuilder(org.apache.pulsar.client.api.ClientBuilder)

Example 17 with Authentication

use of org.apache.pulsar.client.api.Authentication in project incubator-pulsar by apache.

the class AntiAffinityNamespaceGroupTest method setup.

@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
    bkEnsemble.start();
    // Start broker 1
    ServiceConfiguration config1 = new ServiceConfiguration();
    config1.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config1.setClusterName("use");
    config1.setWebServicePort(PRIMARY_BROKER_WEBSERVICE_PORT);
    config1.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config1.setBrokerServicePort(PRIMARY_BROKER_PORT);
    config1.setFailureDomainsEnabled(true);
    config1.setLoadBalancerEnabled(true);
    config1.setAdvertisedAddress("localhost");
    createCluster(bkEnsemble.getZkClient(), config1);
    pulsar1 = new PulsarService(config1);
    pulsar1.start();
    primaryHost = String.format("%s:%d", "localhost", PRIMARY_BROKER_WEBSERVICE_PORT);
    url1 = new URL("http://127.0.0.1" + ":" + PRIMARY_BROKER_WEBSERVICE_PORT);
    admin1 = new PulsarAdmin(url1, (Authentication) null);
    // Start broker 2
    ServiceConfiguration config2 = new ServiceConfiguration();
    config2.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config2.setClusterName("use");
    config2.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    config2.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config2.setBrokerServicePort(SECONDARY_BROKER_PORT);
    config2.setFailureDomainsEnabled(true);
    pulsar2 = new PulsarService(config2);
    secondaryHost = String.format("%s:%d", "localhost", SECONDARY_BROKER_WEBSERVICE_PORT);
    pulsar2.start();
    url2 = new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT);
    admin2 = new PulsarAdmin(url2, (Authentication) null);
    primaryLoadManager = (ModularLoadManagerImpl) getField(pulsar1.getLoadManager().get(), "loadManager");
    secondaryLoadManager = (ModularLoadManagerImpl) getField(pulsar2.getLoadManager().get(), "loadManager");
    nsFactory = new NamespaceBundleFactory(pulsar1, Hashing.crc32());
    Thread.sleep(100);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 18 with Authentication

use of org.apache.pulsar.client.api.Authentication in project incubator-pulsar by apache.

the class ModularLoadManagerImplTest method setup.

@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
    bkEnsemble.start();
    // Start broker 1
    ServiceConfiguration config1 = new ServiceConfiguration();
    config1.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config1.setClusterName("use");
    config1.setWebServicePort(PRIMARY_BROKER_WEBSERVICE_PORT);
    config1.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config1.setBrokerServicePort(PRIMARY_BROKER_PORT);
    pulsar1 = new PulsarService(config1);
    pulsar1.start();
    primaryHost = String.format("%s:%d", InetAddress.getLocalHost().getHostName(), PRIMARY_BROKER_WEBSERVICE_PORT);
    url1 = new URL("http://127.0.0.1" + ":" + PRIMARY_BROKER_WEBSERVICE_PORT);
    admin1 = new PulsarAdmin(url1, (Authentication) null);
    // Start broker 2
    ServiceConfiguration config2 = new ServiceConfiguration();
    config2.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config2.setClusterName("use");
    config2.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    config2.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config2.setBrokerServicePort(SECONDARY_BROKER_PORT);
    pulsar2 = new PulsarService(config2);
    secondaryHost = String.format("%s:%d", InetAddress.getLocalHost().getHostName(), SECONDARY_BROKER_WEBSERVICE_PORT);
    pulsar2.start();
    url2 = new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT);
    admin2 = new PulsarAdmin(url2, (Authentication) null);
    primaryLoadManager = (ModularLoadManagerImpl) getField(pulsar1.getLoadManager().get(), "loadManager");
    secondaryLoadManager = (ModularLoadManagerImpl) getField(pulsar2.getLoadManager().get(), "loadManager");
    nsFactory = new NamespaceBundleFactory(pulsar1, Hashing.crc32());
    Thread.sleep(100);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication) NamespaceBundleFactory(org.apache.pulsar.common.naming.NamespaceBundleFactory) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) ModularLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 19 with Authentication

use of org.apache.pulsar.client.api.Authentication in project incubator-pulsar by apache.

the class SimpleLoadManagerImplTest method setup.

@BeforeMethod
void setup() throws Exception {
    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, PortManager.nextFreePort());
    bkEnsemble.start();
    // Start broker 1
    ServiceConfiguration config1 = spy(new ServiceConfiguration());
    config1.setClusterName("use");
    config1.setWebServicePort(PRIMARY_BROKER_WEBSERVICE_PORT);
    config1.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config1.setBrokerServicePort(PRIMARY_BROKER_PORT);
    config1.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    pulsar1 = new PulsarService(config1);
    pulsar1.start();
    url1 = new URL("http://127.0.0.1" + ":" + PRIMARY_BROKER_WEBSERVICE_PORT);
    admin1 = new PulsarAdmin(url1, (Authentication) null);
    brokerStatsClient1 = admin1.brokerStats();
    primaryHost = String.format("http://%s:%d", InetAddress.getLocalHost().getHostName(), PRIMARY_BROKER_WEBSERVICE_PORT);
    // Start broker 2
    ServiceConfiguration config2 = new ServiceConfiguration();
    config2.setClusterName("use");
    config2.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    config2.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
    config2.setBrokerServicePort(SECONDARY_BROKER_PORT);
    config2.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    pulsar2 = new PulsarService(config2);
    pulsar2.start();
    url2 = new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT);
    admin2 = new PulsarAdmin(url2, (Authentication) null);
    brokerStatsClient2 = admin2.brokerStats();
    secondaryHost = String.format("http://%s:%d", InetAddress.getLocalHost().getHostName(), SECONDARY_BROKER_WEBSERVICE_PORT);
    Thread.sleep(100);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) SimpleLoadManagerImpl(org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Authentication(org.apache.pulsar.client.api.Authentication) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 20 with Authentication

use of org.apache.pulsar.client.api.Authentication 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)

Aggregations

Authentication (org.apache.pulsar.client.api.Authentication)20 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)11 AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)10 URL (java.net.URL)9 PulsarService (org.apache.pulsar.broker.PulsarService)9 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)8 LocalBookkeeperEnsemble (org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble)8 BeforeMethod (org.testng.annotations.BeforeMethod)6 HashMap (java.util.HashMap)5 PulsarClient (org.apache.pulsar.client.api.PulsarClient)5 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)5 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)5 Test (org.testng.annotations.Test)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 Cleanup (lombok.Cleanup)3 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)3