org.apache.pulsar.common.policies.data.TenantInfo Java Examples
The following examples show how to use
org.apache.pulsar.common.policies.data.TenantInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TenantsBase.java From pulsar with Apache License 2.0 | 6 votes |
@GET @Path("/{tenant}") @ApiOperation(value = "Get the admin configuration for a given tenant.") @ApiResponses(value = { @ApiResponse(code = 403, message = "The requester doesn't have admin permissions"), @ApiResponse(code = 404, message = "Tenant does not exist") }) public TenantInfo getTenantAdmin( @ApiParam(value = "The tenant name") @PathParam("tenant") String tenant) { validateSuperUserAccess(); try { return tenantsCache().get(path(POLICIES, tenant)) .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Tenant does not exist")); } catch (Exception e) { log.error("[{}] Failed to get tenant {}", clientAppId(), tenant, e); throw new RestException(e); } }
Example #2
Source File: AdminApiKeyStoreTlsAuthTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testPersistentList() throws Exception { log.info("-- Starting {} test --", methodName); try (PulsarAdmin admin = buildAdminClient()) { admin.clusters().createCluster("test", new ClusterData(brokerUrl.toString())); admin.tenants().createTenant("tenant1", new TenantInfo(ImmutableSet.of("foobar"), ImmutableSet.of("test"))); Assert.assertEquals(ImmutableSet.of("tenant1"), admin.tenants().getTenants()); admin.namespaces().createNamespace("tenant1/ns1"); // this will calls internal admin to list nonpersist topics. admin.topics().getList("tenant1/ns1"); } catch (PulsarAdminException ex) { ex.printStackTrace(); fail("Should not have thrown an exception"); } }
Example #3
Source File: KeyStoreTlsProducerConsumerTestWithAuth.java From pulsar with Apache License 2.0 | 6 votes |
protected void internalSetUpForNamespace() throws Exception { Map<String, String> authParams = new HashMap<>(); authParams.put(AuthenticationKeyStoreTls.KEYSTORE_PATH, CLIENT_KEYSTORE_FILE_PATH); authParams.put(AuthenticationKeyStoreTls.KEYSTORE_PW, CLIENT_KEYSTORE_PW); if (admin != null) { admin.close(); } admin = spy(PulsarAdmin.builder().serviceHttpUrl(brokerUrlTls.toString()) .useKeyStoreTls(true) .tlsTrustStorePath(BROKER_TRUSTSTORE_FILE_PATH) .tlsTrustStorePassword(BROKER_TRUSTSTORE_PW) .allowTlsInsecureConnection(false) .authentication(AuthenticationKeyStoreTls.class.getName(), authParams).build()); admin.clusters().createCluster(clusterName, new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), pulsar.getBrokerServiceUrl(), pulsar.getBrokerServiceUrlTls())); admin.tenants().createTenant("my-property", new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("use"))); admin.namespaces().createNamespace("my-property/my-ns"); }
Example #4
Source File: TlsProducerConsumerBase.java From pulsar with Apache License 2.0 | 6 votes |
protected void internalSetUpForNamespace() throws Exception { Map<String, String> authParams = new HashMap<>(); authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH); authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH); if (admin != null) { admin.close(); } admin = spy(PulsarAdmin.builder().serviceHttpUrl(brokerUrlTls.toString()) .tlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH).allowTlsInsecureConnection(false) .authentication(AuthenticationTls.class.getName(), authParams).build()); admin.clusters().createCluster(clusterName, new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), pulsar.getBrokerServiceUrl(), pulsar.getBrokerServiceUrlTls())); admin.tenants().createTenant("my-property", new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("use"))); admin.namespaces().createNamespace("my-property/my-ns"); }
Example #5
Source File: PulsarWebResource.java From pulsar with Apache License 2.0 | 6 votes |
protected void validateClusterForTenant(String tenant, String cluster) { TenantInfo tenantInfo; try { tenantInfo = pulsar().getConfigurationCache().propertiesCache().get(path(POLICIES, tenant)) .orElseThrow(() -> new RestException(Status.NOT_FOUND, "Tenant does not exist")); } catch (Exception e) { log.error("Failed to get tenant admin data for tenant"); throw new RestException(e); } // Check if tenant is allowed on the cluster if (!tenantInfo.getAllowedClusters().contains(cluster)) { String msg = String.format("Cluster [%s] is not in the list of allowed clusters list for tenant [%s]", cluster, tenant); log.info(msg); throw new RestException(Status.FORBIDDEN, msg); } log.info("Successfully validated clusters on tenant [{}]", tenant); }
Example #6
Source File: KeyStoreTlsProducerConsumerTestWithoutAuth.java From pulsar with Apache License 2.0 | 6 votes |
protected void internalSetUpForNamespace() throws Exception { Map<String, String> authParams = new HashMap<>(); authParams.put(AuthenticationKeyStoreTls.KEYSTORE_PATH, CLIENT_KEYSTORE_FILE_PATH); authParams.put(AuthenticationKeyStoreTls.KEYSTORE_PW, CLIENT_KEYSTORE_PW); if (admin != null) { admin.close(); } admin = spy(PulsarAdmin.builder().serviceHttpUrl(brokerUrlTls.toString()) .useKeyStoreTls(true) .tlsTrustStorePath(BROKER_TRUSTSTORE_FILE_PATH) .tlsTrustStorePassword(BROKER_TRUSTSTORE_PW) .allowTlsInsecureConnection(true) .authentication(AuthenticationKeyStoreTls.class.getName(), authParams).build()); admin.clusters().createCluster(clusterName, new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), pulsar.getBrokerServiceUrl(), pulsar.getBrokerServiceUrlTls())); admin.tenants().createTenant("my-property", new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("use"))); admin.namespaces().createNamespace("my-property/my-ns"); }
Example #7
Source File: AdminApiTlsAuthTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testAuthorizedUserAsOriginalPrincipalButProxyNotAuthorized() throws Exception { try (PulsarAdmin admin = buildAdminClient("admin")) { admin.tenants().createTenant("tenant1", new TenantInfo(ImmutableSet.of("user1"), ImmutableSet.of("test"))); admin.namespaces().createNamespace("tenant1/ns1"); } WebTarget root = buildWebClient("proxy"); try { root.path("/admin/v2/namespaces").path("tenant1") .request(MediaType.APPLICATION_JSON) .header("X-Original-Principal", "user1") .get(new GenericType<List<String>>() {}); Assert.fail("Shouldn't be able to list namespaces"); } catch (NotAuthorizedException e) { // expected } }
Example #8
Source File: TlsProducerConsumerBase.java From pulsar with Apache License 2.0 | 6 votes |
protected void internalSetUpForNamespace() throws Exception { Map<String, String> authParams = new HashMap<>(); authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH); authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH); if (admin != null) { admin.close(); } admin = spy(PulsarAdmin.builder().serviceHttpUrl(brokerUrlTls.toString()) .tlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH).allowTlsInsecureConnection(false) .authentication(AuthenticationTls.class.getName(), authParams).build()); admin.clusters().createCluster(clusterName, new ClusterData(brokerUrl.toString(), brokerUrlTls.toString(), pulsar.getBrokerServiceUrl(), pulsar.getBrokerServiceUrlTls())); admin.tenants().createTenant("my-property", new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("use"))); admin.namespaces().createNamespace("my-property/my-ns"); }
Example #9
Source File: CmdTenants.java From pulsar with Apache License 2.0 | 6 votes |
@Override void run() throws PulsarAdminException { String tenant = getOneArgument(params); if (adminRoles == null) { adminRoles = Collections.emptyList(); } if (allowedClusters == null || allowedClusters.isEmpty()) { // Default to all available cluster allowedClusters = admin.clusters().getClusters(); } TenantInfo tenantInfo = new TenantInfo(new HashSet<>(adminRoles), new HashSet<>(allowedClusters)); admin.tenants().createTenant(tenant, tenantInfo); }
Example #10
Source File: V1_AdminApiTest2.java From pulsar with Apache License 2.0 | 6 votes |
@BeforeMethod @Override public void setup() throws Exception { conf.setLoadBalancerEnabled(true); super.internalSetup(); // create otherbroker to test redirect on calls that need // namespace ownership mockPulsarSetup = new MockedPulsarService(this.conf); mockPulsarSetup.setup(); // Setup namespaces admin.clusters().createCluster("use", new ClusterData(pulsar.getWebServiceAddress())); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("use")); admin.tenants().createTenant("prop-xyz", tenantInfo); admin.namespaces().createNamespace("prop-xyz/use/ns1"); }
Example #11
Source File: V1_AdminApiTest2.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testTenantNameWithUnderscore() throws Exception { TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("use")); admin.tenants().createTenant("prop_xyz", tenantInfo); admin.namespaces().createNamespace("prop_xyz/use/my-namespace"); String topic = "persistent://prop_xyz/use/my-namespace/my-topic"; Producer<byte[]> producer = pulsarClient.newProducer() .topic(topic) .enableBatching(false) .messageRoutingMode(MessageRoutingMode.SinglePartition) .create(); TopicStats stats = admin.topics().getStats(topic); assertEquals(stats.publishers.size(), 1); producer.close(); }
Example #12
Source File: TenantsBase.java From pulsar with Apache License 2.0 | 6 votes |
private void validateClusters(TenantInfo info) { // empty cluster shouldn't be allowed if (info == null || info.getAllowedClusters().stream().filter(c -> !StringUtils.isBlank(c)).collect(Collectors.toSet()).isEmpty() || info.getAllowedClusters().stream().anyMatch(ac -> StringUtils.isBlank(ac))) { log.warn("[{}] Failed to validate due to clusters are empty", clientAppId()); throw new RestException(Status.PRECONDITION_FAILED, "Clusters can not be empty"); } List<String> nonexistentClusters; try { Set<String> availableClusters = clustersListCache().get(); Set<String> allowedClusters = info.getAllowedClusters(); nonexistentClusters = allowedClusters.stream() .filter(cluster -> !(availableClusters.contains(cluster) || Constants.GLOBAL_CLUSTER.equals(cluster))) .collect(Collectors.toList()); } catch (Exception e) { log.error("[{}] Failed to get available clusters", clientAppId(), e); throw new RestException(e); } if (nonexistentClusters.size() > 0) { log.warn("[{}] Failed to validate due to clusters {} do not exist", clientAppId(), nonexistentClusters); throw new RestException(Status.PRECONDITION_FAILED, "Clusters do not exist"); } }
Example #13
Source File: AdminApiTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testObjectWithUnknowProperties() { class CustomTenantAdmin extends TenantInfo { @SuppressWarnings("unused") public int newTenant; } TenantInfo pa = new TenantInfo(Sets.newHashSet("test_appid1", "test_appid2"), Sets.newHashSet("test")); CustomTenantAdmin cpa = new CustomTenantAdmin(); cpa.setAdminRoles(pa.getAdminRoles()); cpa.setAllowedClusters(pa.getAllowedClusters()); cpa.newTenant = 100; try { admin.tenants().createTenant("test-property", cpa); } catch (Exception e) { fail("Should not happen : ", e); } }
Example #14
Source File: V1_AdminApiTest.java From pulsar with Apache License 2.0 | 6 votes |
@Test public void testObjectWithUnknowProperties() { class CustomPropertyAdmin extends TenantInfo { @SuppressWarnings("unused") public int newProperty; } TenantInfo pa = new TenantInfo(Sets.newHashSet("test_appid1", "test_appid2"), Sets.newHashSet("use")); CustomPropertyAdmin cpa = new CustomPropertyAdmin(); cpa.setAdminRoles(pa.getAdminRoles()); cpa.setAllowedClusters(pa.getAllowedClusters()); cpa.newProperty = 100; try { admin.tenants().createTenant("test-property", cpa); } catch (Exception e) { fail("Should not happen : ", e); } }
Example #15
Source File: SystemTopicBasedTopicPoliciesServiceTest.java From pulsar with Apache License 2.0 | 6 votes |
private void prepareData() throws PulsarAdminException { admin.clusters().createCluster("test", new ClusterData(pulsar.getBrokerServiceUrl())); admin.tenants().createTenant("system-topic", new TenantInfo(Sets.newHashSet(), Sets.newHashSet("test"))); admin.namespaces().createNamespace(NAMESPACE1); admin.namespaces().createNamespace(NAMESPACE2); admin.namespaces().createNamespace(NAMESPACE3); admin.lookups().lookupTopic(TOPIC1.toString()); admin.lookups().lookupTopic(TOPIC2.toString()); admin.lookups().lookupTopic(TOPIC3.toString()); admin.lookups().lookupTopic(TOPIC4.toString()); admin.lookups().lookupTopic(TOPIC5.toString()); admin.lookups().lookupTopic(TOPIC6.toString()); systemTopicFactory = new NamespaceEventsSystemTopicFactory(pulsarClient); systemTopicBasedTopicPoliciesService = (SystemTopicBasedTopicPoliciesService) pulsar.getTopicPoliciesService(); }
Example #16
Source File: TenantsImpl.java From pulsar with Apache License 2.0 | 6 votes |
@Override public CompletableFuture<TenantInfo> getTenantInfoAsync(String tenant) { WebTarget path = adminTenants.path(tenant); final CompletableFuture<TenantInfo> future = new CompletableFuture<>(); asyncGetRequest(path, new InvocationCallback<TenantInfo>() { @Override public void completed(TenantInfo tenantInfo) { future.complete(tenantInfo); } @Override public void failed(Throwable throwable) { future.completeExceptionally(getApiException(throwable.getCause())); } }); return future; }
Example #17
Source File: AdminApiSchemaValidationEnforced.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod @Override public void setup() throws Exception { super.internalSetup(); admin.clusters().createCluster("test", new ClusterData(pulsar.getWebServiceAddress())); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test")); admin.tenants().createTenant("schema-validation-enforced", tenantInfo); }
Example #18
Source File: V1_AdminApiTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testTopicBundleRangeLookup() throws PulsarAdminException, PulsarServerException, Exception { admin.clusters().createCluster("usw", new ClusterData()); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("use", "usw")); admin.tenants().updateTenant("prop-xyz", tenantInfo); admin.namespaces().createNamespace("prop-xyz/use/getBundleNs", 100); assertEquals(admin.namespaces().getPolicies("prop-xyz/use/getBundleNs").bundles.numBundles, 100); // (1) create a topic final String topicName = "persistent://prop-xyz/use/getBundleNs/topic1"; String bundleRange = admin.lookups().getBundleRange(topicName); assertEquals(bundleRange, pulsar.getNamespaceService().getBundle(TopicName.get(topicName)).getBundleRange()); }
Example #19
Source File: AdminApiMaxUnackedMessages.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod @Override public void setup() throws Exception { super.internalSetup(); admin.clusters().createCluster("test", new ClusterData(pulsar.getWebServiceAddress())); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test")); admin.tenants().createTenant("max-unacked-messages", tenantInfo); }
Example #20
Source File: V1_AdminApiTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(enabled = true) public void properties() throws PulsarAdminException { Set<String> allowedClusters = Sets.newHashSet("use"); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), allowedClusters); admin.tenants().updateTenant("prop-xyz", tenantInfo); assertEquals(admin.tenants().getTenants(), Lists.newArrayList("prop-xyz")); assertEquals(admin.tenants().getTenantInfo("prop-xyz"), tenantInfo); TenantInfo newPropertyAdmin = new TenantInfo(Sets.newHashSet("role3", "role4"), allowedClusters); admin.tenants().updateTenant("prop-xyz", newPropertyAdmin); assertEquals(admin.tenants().getTenantInfo("prop-xyz"), newPropertyAdmin); admin.namespaces().deleteNamespace("prop-xyz/use/ns1"); admin.tenants().deleteTenant("prop-xyz"); assertEquals(admin.tenants().getTenants(), Lists.newArrayList()); // Check name validation try { admin.tenants().createTenant("prop-xyz&", tenantInfo); fail("should have failed"); } catch (PulsarAdminException e) { assertTrue(e instanceof PreconditionFailedException); } }
Example #21
Source File: V1_AdminApiTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod @Override public void setup() throws Exception { conf.setLoadBalancerEnabled(true); conf.setBrokerServicePortTls(Optional.of(0)); conf.setWebServicePortTls(Optional.of(0)); conf.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH); conf.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH); super.internalSetup(); bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32()); adminTls = spy(PulsarAdmin.builder().tlsTrustCertsFilePath(TLS_SERVER_CERT_FILE_PATH) .serviceHttpUrl(brokerUrlTls.toString()).build()); // create otherbroker to test redirect on calls that need // namespace ownership mockPulsarSetup = new MockedPulsarService(this.conf); mockPulsarSetup.setup(); otherPulsar = mockPulsarSetup.getPulsar(); otheradmin = mockPulsarSetup.getAdmin(); // Setup namespaces admin.clusters().createCluster("use", new ClusterData(pulsar.getWebServiceAddress())); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("use")); admin.tenants().createTenant("prop-xyz", tenantInfo); admin.namespaces().createNamespace("prop-xyz/use/ns1"); }
Example #22
Source File: ProxyTlsTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testPartitions() throws Exception { PulsarClient client = PulsarClient.builder() .serviceUrl(proxyService.getServiceUrlTls()) .allowTlsInsecureConnection(false).tlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH).build(); TenantInfo tenantInfo = createDefaultTenantInfo(); admin.tenants().createTenant("sample", tenantInfo); admin.topics().createPartitionedTopic("persistent://sample/test/local/partitioned-topic", 2); Producer<byte[]> producer = client.newProducer(Schema.BYTES).topic("persistent://sample/test/local/partitioned-topic") .messageRoutingMode(MessageRoutingMode.RoundRobinPartition).create(); // Create a consumer directly attached to broker Consumer<byte[]> consumer = pulsarClient.newConsumer().topic("persistent://sample/test/local/partitioned-topic") .subscriptionName("my-sub").subscribe(); for (int i = 0; i < 10; i++) { producer.send("test".getBytes()); } for (int i = 0; i < 10; i++) { Message<byte[]> msg = consumer.receive(1, TimeUnit.SECONDS); checkNotNull(msg); } client.close(); }
Example #23
Source File: ProxyKeyStoreTlsTestWithAuth.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testPartitions() throws Exception { @Cleanup PulsarClient client = internalSetUpForClient(true, proxyService.getServiceUrlTls()); String topicName = "persistent://sample/test/local/partitioned-topic" + System.currentTimeMillis(); TenantInfo tenantInfo = createDefaultTenantInfo(); admin.tenants().createTenant("sample", tenantInfo); admin.topics().createPartitionedTopic(topicName, 2); @Cleanup Producer<byte[]> producer = client.newProducer(Schema.BYTES).topic(topicName) .messageRoutingMode(MessageRoutingMode.RoundRobinPartition).create(); // Create a consumer directly attached to broker @Cleanup Consumer<byte[]> consumer = pulsarClient.newConsumer().topic(topicName) .subscriptionName("my-sub").subscribe(); for (int i = 0; i < 10; i++) { producer.send("test".getBytes()); } for (int i = 0; i < 10; i++) { Message<byte[]> msg = consumer.receive(1, TimeUnit.SECONDS); checkNotNull(msg); } }
Example #24
Source File: AdminApiTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(enabled = true) public void properties() throws PulsarAdminException { Set<String> allowedClusters = Sets.newHashSet("test"); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), allowedClusters); admin.tenants().updateTenant("prop-xyz", tenantInfo); assertEquals(admin.tenants().getTenants(), Lists.newArrayList("prop-xyz")); assertEquals(admin.tenants().getTenantInfo("prop-xyz"), tenantInfo); TenantInfo newTenantAdmin = new TenantInfo(Sets.newHashSet("role3", "role4"), allowedClusters); admin.tenants().updateTenant("prop-xyz", newTenantAdmin); assertEquals(admin.tenants().getTenantInfo("prop-xyz"), newTenantAdmin); admin.namespaces().deleteNamespace("prop-xyz/ns1"); admin.tenants().deleteTenant("prop-xyz"); assertEquals(admin.tenants().getTenants(), Lists.newArrayList()); // Check name validation try { admin.tenants().createTenant("prop-xyz&", tenantInfo); fail("should have failed"); } catch (PulsarAdminException e) { assertTrue(e instanceof PreconditionFailedException); } }
Example #25
Source File: ReaderTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod @Override protected void setup() throws Exception { super.internalSetup(); admin.clusters().createCluster("test", new ClusterData(pulsar.getWebServiceAddress())); admin.tenants().createTenant("my-property", new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test"))); admin.namespaces().createNamespace("my-property/my-ns", Sets.newHashSet("test")); }
Example #26
Source File: MessageParserTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod @Override public void setup() throws Exception { super.internalSetup(); admin.clusters().createCluster("test", new ClusterData(pulsar.getWebServiceAddress())); admin.tenants().createTenant("my-tenant", new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test"))); admin.namespaces().createNamespace("my-tenant/my-ns", Sets.newHashSet("test")); }
Example #27
Source File: TopicOwnerTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testConnectToInvalidateBundleCacheBroker() throws Exception { pulsarAdmins[0].clusters().createCluster("my-cluster", new ClusterData(pulsarServices[0].getWebServiceAddress())); TenantInfo tenantInfo = new TenantInfo(); tenantInfo.setAllowedClusters(Sets.newHashSet("my-cluster")); pulsarAdmins[0].tenants().createTenant("my-tenant", tenantInfo); pulsarAdmins[0].namespaces().createNamespace("my-tenant/my-ns", 16); Assert.assertEquals(pulsarAdmins[0].namespaces().getPolicies("my-tenant/my-ns").bundles.getNumBundles(), 16); final String topic1 = "persistent://my-tenant/my-ns/topic-1"; final String topic2 = "persistent://my-tenant/my-ns/topic-2"; // Do topic lookup here for broker to own namespace bundles String serviceUrlForTopic1 = pulsarAdmins[0].lookups().lookupTopic(topic1); String serviceUrlForTopic2 = pulsarAdmins[0].lookups().lookupTopic(topic2); while (serviceUrlForTopic1.equals(serviceUrlForTopic2)) { // Retry for bundle distribution, should make sure bundles for topic1 and topic2 are maintained in different brokers. pulsarAdmins[0].namespaces().unload("my-tenant/my-ns"); serviceUrlForTopic1 = pulsarAdmins[0].lookups().lookupTopic(topic1); serviceUrlForTopic2 = pulsarAdmins[0].lookups().lookupTopic(topic2); } // All brokers will invalidate bundles cache after namespace bundle split pulsarAdmins[0].namespaces().splitNamespaceBundle("my-tenant/my-ns", pulsarServices[0].getNamespaceService().getBundle(TopicName.get(topic1)).getBundleRange(), true, null); PulsarClient client = PulsarClient.builder(). serviceUrl(serviceUrlForTopic1) .build(); // Check connect to a topic which owner broker invalidate all namespace bundles cache Consumer<byte[]> consumer = client.newConsumer().topic(topic2).subscriptionName("test").subscribe(); Assert.assertTrue(consumer.isConnected()); }
Example #28
Source File: RawReaderTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod @Override public void setup() throws Exception { super.internalSetup(); admin.clusters().createCluster("test", new ClusterData(pulsar.getWebServiceAddress())); admin.tenants().createTenant("my-property", new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test"))); admin.namespaces().createNamespace("my-property/my-ns", Sets.newHashSet("test")); }
Example #29
Source File: BkEnsemblesTestBase.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod protected void setup() throws Exception { try { // start local bookie and zookeeper bkEnsemble = new LocalBookkeeperEnsemble(numberOfBookies, 0, () -> 0); bkEnsemble.start(); // start pulsar service config = new ServiceConfiguration(); config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort()); config.setAdvertisedAddress("localhost"); config.setWebServicePort(Optional.of(0)); config.setClusterName("usc"); config.setBrokerServicePort(Optional.of(0)); config.setAuthorizationEnabled(false); config.setAuthenticationEnabled(false); config.setManagedLedgerMaxEntriesPerLedger(5); config.setManagedLedgerMinLedgerRolloverTimeMinutes(0); config.setAdvertisedAddress("127.0.0.1"); config.setAllowAutoTopicCreationType("non-partitioned"); pulsar = new PulsarService(config); pulsar.start(); admin = PulsarAdmin.builder().serviceHttpUrl(pulsar.getWebServiceAddress()).build(); admin.clusters().createCluster("usc", new ClusterData(pulsar.getWebServiceAddress())); admin.tenants().createTenant("prop", new TenantInfo(Sets.newHashSet("appid1"), Sets.newHashSet("usc"))); } catch (Throwable t) { log.error("Error setting up broker test", t); Assert.fail("Broker test setup failed"); } }
Example #30
Source File: AdminApiSchemaTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod @Override public void setup() throws Exception { super.internalSetup(); // Setup namespaces admin.clusters().createCluster("test", new ClusterData(pulsar.getWebServiceAddress())); TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test")); admin.tenants().createTenant("schematest", tenantInfo); admin.namespaces().createNamespace("schematest/test", Sets.newHashSet("test")); }