Search in sources :

Example 26 with PulsarAdmin

use of org.apache.pulsar.client.admin.PulsarAdmin in project incubator-pulsar by apache.

the class PulsarAdminToolTest method resourceQuotas.

@Test
void resourceQuotas() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    ResourceQuotas mockResourceQuotas = mock(ResourceQuotas.class);
    when(admin.resourceQuotas()).thenReturn(mockResourceQuotas);
    CmdResourceQuotas cmdResourceQuotas = new CmdResourceQuotas(admin);
    ResourceQuota quota = new ResourceQuota();
    quota.setMsgRateIn(10);
    quota.setMsgRateOut(20);
    quota.setBandwidthIn(10000);
    quota.setBandwidthOut(20000);
    quota.setMemory(100);
    quota.setDynamic(false);
    cmdResourceQuotas.run(split("get"));
    verify(mockResourceQuotas).getDefaultResourceQuota();
    cmdResourceQuotas.run(split("set -mi 10 -mo 20 -bi 10000 -bo 20000 -mem 100"));
    verify(mockResourceQuotas).setDefaultResourceQuota(quota);
    // reset mocks
    mockResourceQuotas = mock(ResourceQuotas.class);
    when(admin.resourceQuotas()).thenReturn(mockResourceQuotas);
    cmdResourceQuotas = new CmdResourceQuotas(admin);
    cmdResourceQuotas.run(split("get --namespace myprop/clust/ns1 --bundle 0x80000000_0xffffffff"));
    verify(mockResourceQuotas).getNamespaceBundleResourceQuota("myprop/clust/ns1", "0x80000000_0xffffffff");
    cmdResourceQuotas.run(split("set --namespace myprop/clust/ns1 --bundle 0x80000000_0xffffffff -mi 10 -mo 20 -bi 10000 -bo 20000 -mem 100"));
    verify(mockResourceQuotas).setNamespaceBundleResourceQuota("myprop/clust/ns1", "0x80000000_0xffffffff", quota);
    cmdResourceQuotas.run(split("reset-namespace-bundle-quota --namespace myprop/clust/ns1 --bundle 0x80000000_0xffffffff"));
    verify(mockResourceQuotas).resetNamespaceBundleResourceQuota("myprop/clust/ns1", "0x80000000_0xffffffff");
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) ResourceQuota(org.apache.pulsar.common.policies.data.ResourceQuota) ResourceQuotas(org.apache.pulsar.client.admin.ResourceQuotas) Test(org.testng.annotations.Test)

Example 27 with PulsarAdmin

use of org.apache.pulsar.client.admin.PulsarAdmin in project incubator-pulsar by apache.

the class PulsarAdminToolTest method brokers.

@Test
void brokers() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    Brokers mockBrokers = mock(Brokers.class);
    doReturn(mockBrokers).when(admin).brokers();
    CmdBrokers brokers = new CmdBrokers(admin);
    brokers.run(split("list use"));
    verify(mockBrokers).getActiveBrokers("use");
    brokers.run(split("get-all-dynamic-config"));
    verify(mockBrokers).getAllDynamicConfigurations();
    brokers.run(split("list-dynamic-config"));
    verify(mockBrokers).getDynamicConfigurationNames();
    brokers.run(split("update-dynamic-config --config brokerShutdownTimeoutMs --value 100"));
    verify(mockBrokers).updateDynamicConfiguration("brokerShutdownTimeoutMs", "100");
    brokers.run(split("get-internal-config"));
    verify(mockBrokers).getInternalConfigurationData();
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) Brokers(org.apache.pulsar.client.admin.Brokers) Test(org.testng.annotations.Test)

Example 28 with PulsarAdmin

use of org.apache.pulsar.client.admin.PulsarAdmin in project incubator-pulsar by apache.

the class PulsarAdminToolTest method brokerStats.

@Test
void brokerStats() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    BrokerStats mockBrokerStats = mock(BrokerStats.class);
    doReturn(mockBrokerStats).when(admin).brokerStats();
    CmdBrokerStats brokerStats = new CmdBrokerStats(admin);
    brokerStats.run(split("topics"));
    verify(mockBrokerStats).getTopics();
    brokerStats.run(split("load-report"));
    verify(mockBrokerStats).getLoadReport();
    brokerStats.run(split("mbeans"));
    verify(mockBrokerStats).getMBeans();
    brokerStats.run(split("monitoring-metrics"));
    verify(mockBrokerStats).getMetrics();
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) BrokerStats(org.apache.pulsar.client.admin.BrokerStats) Test(org.testng.annotations.Test)

Example 29 with PulsarAdmin

use of org.apache.pulsar.client.admin.PulsarAdmin in project incubator-pulsar by apache.

the class AuthenticationTlsHostnameVerificationTest method setupClient.

protected void setupClient() throws Exception {
    Map<String, String> authParams = new HashMap<>();
    authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
    Authentication authTls = new AuthenticationTls();
    authTls.configure(authParams);
    org.apache.pulsar.client.api.ClientConfiguration clientConf = new org.apache.pulsar.client.api.ClientConfiguration();
    clientConf.setStatsInterval(0, TimeUnit.SECONDS);
    clientConf.setTlsTrustCertsFilePath(TLS_MIM_TRUST_CERT_FILE_PATH);
    clientConf.setTlsAllowInsecureConnection(true);
    clientConf.setAuthentication(authTls);
    clientConf.setUseTls(true);
    clientConf.setTlsHostnameVerificationEnable(hostnameVerificationEnabled);
    admin = spy(new PulsarAdmin(brokerUrlTls, clientConf));
    String lookupUrl;
    lookupUrl = new URI("pulsar+ssl://" + brokerHostName + ":" + BROKER_PORT_TLS).toString();
    pulsarClient = PulsarClient.builder().serviceUrl(lookupUrl).statsInterval(0, TimeUnit.SECONDS).tlsTrustCertsFilePath(TLS_MIM_TRUST_CERT_FILE_PATH).allowTlsInsecureConnection(true).authentication(authTls).enableTls(true).enableTlsHostnameVerification(hostnameVerificationEnabled).build();
    admin.properties().createProperty("my-property", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("my-property/use/my-ns");
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) HashMap(java.util.HashMap) URI(java.net.URI) AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin)

Example 30 with PulsarAdmin

use of org.apache.pulsar.client.admin.PulsarAdmin in project incubator-pulsar by apache.

the class AuthorizationProducerConsumerTest method testSubscriptionPrefixAuthorization.

@Test
public void testSubscriptionPrefixAuthorization() throws Exception {
    log.info("-- Starting {} test --", methodName);
    conf.setAuthorizationProvider(TestAuthorizationProviderWithSubscriptionPrefix.class.getName());
    setup();
    ClientConfiguration adminConf = new ClientConfiguration();
    Authentication adminAuthentication = new ClientAuthentication("superUser");
    adminConf.setAuthentication(adminAuthentication);
    admin = spy(new PulsarAdmin(brokerUrl, adminConf));
    String lookupUrl;
    lookupUrl = new URI("pulsar://localhost:" + BROKER_PORT).toString();
    Authentication authentication = new ClientAuthentication(clientRole);
    pulsarClient = PulsarClient.builder().serviceUrl(lookupUrl).authentication(authentication).build();
    admin.properties().createProperty("prop-prefix", new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
    admin.namespaces().createNamespace("prop-prefix/use/ns");
    // (1) Valid subscription name will be approved by authorization service
    Consumer<byte[]> consumer = pulsarClient.newConsumer().topic("persistent://prop-prefix/use/ns/t1").subscriptionName(clientRole + "-sub1").subscribe();
    consumer.close();
    // (2) InValid subscription name will be rejected by authorization service
    try {
        consumer = pulsarClient.newConsumer().topic("persistent://prop-prefix/use/ns/t1").subscriptionName("sub1").subscribe();
        Assert.fail("should have failed with authorization error");
    } catch (PulsarClientException.AuthorizationException pa) {
    // Ok
    }
    log.info("-- Exiting {} test --", methodName);
}
Also used : PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)39 URL (java.net.URL)15 Test (org.testng.annotations.Test)14 PulsarService (org.apache.pulsar.broker.PulsarService)12 Authentication (org.apache.pulsar.client.api.Authentication)11 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)11 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)10 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)9 LocalBookkeeperEnsemble (org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble)9 BeforeMethod (org.testng.annotations.BeforeMethod)7 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)6 AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 URI (java.net.URI)3 ModularLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.ModularLoadManagerImpl)3 SimpleLoadManagerImpl (org.apache.pulsar.broker.loadbalance.impl.SimpleLoadManagerImpl)3 MalformedURLException (java.net.MalformedURLException)2 Brokers (org.apache.pulsar.client.admin.Brokers)2 ClientConfiguration (org.apache.pulsar.client.api.ClientConfiguration)2