Search in sources :

Example 31 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class TransactionBufferClientTest method setup.

@Override
@BeforeClass(alwaysRun = true)
protected void setup() throws Exception {
    setBrokerCount(3);
    internalSetup();
    String[] brokerServiceUrlArr = getPulsarServiceList().get(0).getBrokerServiceUrl().split(":");
    String webServicePort = brokerServiceUrlArr[brokerServiceUrlArr.length - 1];
    admin.clusters().createCluster(CLUSTER_NAME, ClusterData.builder().serviceUrl("http://localhost:" + webServicePort).build());
    admin.tenants().createTenant("public", new TenantInfoImpl(Sets.newHashSet("appid1"), Sets.newHashSet(CLUSTER_NAME)));
    admin.namespaces().createNamespace(namespace, 10);
    admin.topics().createPartitionedTopic(partitionedTopicName.getPartitionedTopicName(), partitions);
    tbClient = TransactionBufferClientImpl.create(pulsarClient, new HashedWheelTimer(new DefaultThreadFactory("transaction-buffer")));
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) HashedWheelTimer(io.netty.util.HashedWheelTimer) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 32 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class PartitionedSystemTopicTest method testConsumerCreationWhenEnablingTopicPolicy.

@Test(timeOut = 1000 * 60)
public void testConsumerCreationWhenEnablingTopicPolicy() throws Exception {
    String tenant = "tenant-" + RandomStringUtils.randomAlphabetic(4).toLowerCase();
    admin.tenants().createTenant(tenant, new TenantInfoImpl(Sets.newHashSet(), Sets.newHashSet("test")));
    int namespaceCount = 30;
    for (int i = 0; i < namespaceCount; i++) {
        String ns = tenant + "/ns-" + i;
        admin.namespaces().createNamespace(ns, 4);
        String topic = ns + "/t1";
        admin.topics().createPartitionedTopic(topic, 2);
    }
    List<CompletableFuture<Consumer<byte[]>>> futureList = new ArrayList<>();
    for (int i = 0; i < namespaceCount; i++) {
        String topic = tenant + "/ns-" + i + "/t1";
        futureList.add(pulsarClient.newConsumer().topic(topic).subscriptionName("sub").subscribeAsync());
    }
    FutureUtil.waitForAll(futureList).get();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) Test(org.testng.annotations.Test)

Example 33 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class AuthenticatedProducerConsumerTest method testAnonymousSyncProducerAndConsumer.

@Test(dataProvider = "batch")
public void testAnonymousSyncProducerAndConsumer(int batchMessageDelayMs) throws Exception {
    log.info("-- Starting {} test --", methodName);
    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);
    internalSetup(authTls);
    admin.clusters().createCluster("test", ClusterData.builder().serviceUrl(brokerUrl.toString()).serviceUrlTls(brokerUrlTls.toString()).brokerServiceUrl(pulsar.getBrokerServiceUrl()).brokerServiceUrlTls(pulsar.getBrokerServiceUrlTls()).build());
    admin.tenants().createTenant("my-property", new TenantInfoImpl(Sets.newHashSet("anonymousUser"), Sets.newHashSet("test")));
    // make a PulsarAdmin instance as "anonymousUser" for http request
    admin.close();
    admin = spy(PulsarAdmin.builder().serviceHttpUrl(brokerUrl.toString()).build());
    admin.namespaces().createNamespace("my-property/my-ns", Sets.newHashSet("test"));
    admin.topics().grantPermission("persistent://my-property/my-ns/my-topic", "anonymousUser", EnumSet.allOf(AuthAction.class));
    // setup the client
    replacePulsarClient(PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).operationTimeout(1, TimeUnit.SECONDS));
    pulsarClient.newConsumer().topic("persistent://my-property/my-ns/other-topic").subscriptionName("my-subscriber-name").subscribe();
    testSyncProducerAndConsumer(batchMessageDelayMs);
    log.info("-- Exiting {} test --", methodName);
}
Also used : AuthenticationTls(org.apache.pulsar.client.impl.auth.AuthenticationTls) HashMap(java.util.HashMap) TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) AuthAction(org.apache.pulsar.common.policies.data.AuthAction) Test(org.testng.annotations.Test)

Example 34 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class TransactionConsumeTest method setup.

@BeforeMethod(alwaysRun = true)
public void setup() throws Exception {
    setBrokerCount(1);
    super.internalSetup();
    String[] brokerServiceUrlArr = getPulsarServiceList().get(0).getBrokerServiceUrl().split(":");
    String webServicePort = brokerServiceUrlArr[brokerServiceUrlArr.length - 1];
    admin.clusters().createCluster(CLUSTER_NAME, ClusterData.builder().serviceUrl("http://localhost:" + webServicePort).build());
    admin.tenants().createTenant("public", new TenantInfoImpl(Sets.newHashSet(), Sets.newHashSet(CLUSTER_NAME)));
    admin.namespaces().createNamespace("public/txn", 10);
    admin.topics().createNonPartitionedTopic(CONSUME_TOPIC);
    admin.tenants().createTenant(NamespaceName.SYSTEM_NAMESPACE.getTenant(), new TenantInfoImpl(Sets.newHashSet("appid1"), Sets.newHashSet(CLUSTER_NAME)));
    admin.namespaces().createNamespace(NamespaceName.SYSTEM_NAMESPACE.toString());
    admin.topics().createPartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString(), 1);
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 35 with TenantInfoImpl

use of org.apache.pulsar.common.policies.data.TenantInfoImpl in project pulsar by apache.

the class TransactionTestBase method setUpBase.

protected void setUpBase(int numBroker, int numPartitionsOfTC, String topic, int numPartitions) throws Exception {
    setBrokerCount(numBroker);
    internalSetup();
    String[] brokerServiceUrlArr = getPulsarServiceList().get(0).getBrokerServiceUrl().split(":");
    String webServicePort = brokerServiceUrlArr[brokerServiceUrlArr.length - 1];
    admin.clusters().createCluster(CLUSTER_NAME, ClusterData.builder().serviceUrl("http://localhost:" + webServicePort).build());
    admin.tenants().createTenant(NamespaceName.SYSTEM_NAMESPACE.getTenant(), new TenantInfoImpl(Sets.newHashSet("appid1"), Sets.newHashSet(CLUSTER_NAME)));
    admin.namespaces().createNamespace(NamespaceName.SYSTEM_NAMESPACE.toString());
    admin.topics().createPartitionedTopic(TopicName.TRANSACTION_COORDINATOR_ASSIGN.toString(), numPartitionsOfTC);
    if (topic != null) {
        admin.tenants().createTenant(TENANT, new TenantInfoImpl(Sets.newHashSet("appid1"), Sets.newHashSet(CLUSTER_NAME)));
        admin.namespaces().createNamespace(NAMESPACE1);
        if (numPartitions == 0) {
            admin.topics().createNonPartitionedTopic(topic);
        } else {
            admin.topics().createPartitionedTopic(topic, numPartitions);
        }
    }
    if (pulsarClient != null) {
        pulsarClient.shutdown();
    }
    pulsarClient = PulsarClient.builder().serviceUrl(getPulsarServiceList().get(0).getBrokerServiceUrl()).statsInterval(0, TimeUnit.SECONDS).enableTransaction(true).build();
}
Also used : TenantInfoImpl(org.apache.pulsar.common.policies.data.TenantInfoImpl)

Aggregations

TenantInfoImpl (org.apache.pulsar.common.policies.data.TenantInfoImpl)690 Test (org.testng.annotations.Test)458 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)211 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)146 BeforeMethod (org.testng.annotations.BeforeMethod)144 Cleanup (lombok.Cleanup)139 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)136 PulsarClient (org.apache.pulsar.client.api.PulsarClient)91 PulsarClientException (org.apache.pulsar.client.api.PulsarClientException)72 HashSet (java.util.HashSet)55 HashMap (java.util.HashMap)49 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)48 CompletableFuture (java.util.concurrent.CompletableFuture)41 List (java.util.List)38 PulsarService (org.apache.pulsar.broker.PulsarService)37 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)36 ArrayList (java.util.ArrayList)33 WebTarget (javax.ws.rs.client.WebTarget)33 Policies (org.apache.pulsar.common.policies.data.Policies)33 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)31