Java源码示例:org.apache.pulsar.common.policies.data.TenantInfo
示例1
@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
}
}
示例2
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");
}
示例3
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);
}
示例4
@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);
}
}
示例5
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");
}
}
示例6
@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);
}
}
示例7
@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;
}
示例8
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();
}
示例9
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");
}
示例10
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");
}
示例11
@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");
}
}
示例12
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");
}
示例13
@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);
}
示例14
@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");
}
示例15
@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();
}
示例16
@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);
}
}
示例17
@Test
public void testPartitions() throws Exception {
TenantInfo tenantInfo = createDefaultTenantInfo();
admin.tenants().createTenant("sample", tenantInfo);
@Cleanup
PulsarClient client = PulsarClient.builder().serviceUrl(proxyService.getServiceUrl())
.build();
admin.topics().createPartitionedTopic("persistent://sample/test/local/partitioned-topic", 2);
@Cleanup
Producer<byte[]> producer = client.newProducer(Schema.BYTES)
.topic("persistent://sample/test/local/partitioned-topic")
.enableBatching(false)
.messageRoutingMode(MessageRoutingMode.RoundRobinPartition).create();
// Create a consumer directly attached to broker
@Cleanup
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);
}
}
示例18
@BeforeMethod
@Override
protected void setup() throws Exception {
sslSetUpForBroker();
super.internalSetup();
log.info("success internal setup");
if (!admin.clusters().getClusters().contains(configClusterName)) {
// so that clients can test short names
admin.clusters().createCluster(configClusterName,
new ClusterData("http://127.0.0.1:" + brokerWebservicePort));
} else {
admin.clusters().updateCluster(configClusterName,
new ClusterData("http://127.0.0.1:" + brokerWebservicePort));
}
if (!admin.tenants().getTenants().contains("public")) {
admin.tenants().createTenant("public",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
} else {
admin.tenants().updateTenant("public",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
}
if (!admin.namespaces().getNamespaces("public").contains("public/default")) {
admin.namespaces().createNamespace("public/default");
admin.namespaces().setNamespaceReplicationClusters("public/default", Sets.newHashSet("test"));
admin.namespaces().setRetention("public/default",
new RetentionPolicies(60, 1000));
}
if (!admin.namespaces().getNamespaces("public").contains("public/__kafka")) {
admin.namespaces().createNamespace("public/__kafka");
admin.namespaces().setNamespaceReplicationClusters("public/__kafka", Sets.newHashSet("test"));
admin.namespaces().setRetention("public/__kafka",
new RetentionPolicies(-1, -1));
}
}
示例19
@BeforeMethod
@Override
public void setup() throws Exception {
super.internalSetup();
// Setup namespaces
admin.clusters().createCluster(CLUSTER_NAME, new ClusterData(pulsar.getBrokerServiceUrl()));
TenantInfo tenantInfo = new TenantInfo();
tenantInfo.setAllowedClusters(Collections.singleton(CLUSTER_NAME));
admin.tenants().createTenant(PUBLIC_TENANT, tenantInfo);
}
示例20
public void baseSetup() throws Exception {
super.internalSetup();
admin.clusters().createCluster("test", new ClusterData(brokerUrl.toString()));
admin.tenants().createTenant("prop",
new TenantInfo(Sets.newHashSet("appid1"), Sets.newHashSet("test")));
admin.namespaces().createNamespace("prop/ns-abc");
admin.namespaces().setNamespaceReplicationClusters("prop/ns-abc", Sets.newHashSet("test"));
}
示例21
@BeforeMethod
@Override
public void setup() throws Exception {
super.internalSetup();
if (!admin.clusters().getClusters().contains(configClusterName)) {
// so that clients can test short names
admin.clusters().createCluster(configClusterName,
new ClusterData("http://127.0.0.1:" + brokerWebservicePort));
} else {
admin.clusters().updateCluster(configClusterName,
new ClusterData("http://127.0.0.1:" + brokerWebservicePort));
}
if (!admin.tenants().getTenants().contains("public")) {
admin.tenants().createTenant("public",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
} else {
admin.tenants().updateTenant("public",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
}
if (!admin.namespaces().getNamespaces("public").contains("public/default")) {
admin.namespaces().createNamespace("public/default");
admin.namespaces().setNamespaceReplicationClusters("public/default", Sets.newHashSet("test"));
admin.namespaces().setRetention("public/default",
new RetentionPolicies(60, 1000));
}
if (!admin.namespaces().getNamespaces("public").contains("public/__kafka")) {
admin.namespaces().createNamespace("public/__kafka");
admin.namespaces().setNamespaceReplicationClusters("public/__kafka", Sets.newHashSet("test"));
admin.namespaces().setRetention("public/__kafka",
new RetentionPolicies(-1, -1));
}
List<String> brokers = admin.brokers().getActiveBrokers(configClusterName);
Assert.assertEquals(brokers.size(), 2);
log.info("broker1: {} broker2: {}", brokers.get(0), brokers.get(1));
}
示例22
@BeforeMethod
@Override
protected void setup() throws Exception {
super.internalSetup();
log.info("success internal setup");
if (!admin.clusters().getClusters().contains(configClusterName)) {
// so that clients can test short names
admin.clusters().createCluster(configClusterName,
new ClusterData("http://127.0.0.1:" + brokerWebservicePort));
} else {
admin.clusters().updateCluster(configClusterName,
new ClusterData("http://127.0.0.1:" + brokerWebservicePort));
}
if (!admin.tenants().getTenants().contains("public")) {
admin.tenants().createTenant("public",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
} else {
admin.tenants().updateTenant("public",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("test")));
}
if (!admin.namespaces().getNamespaces("public").contains("public/default")) {
admin.namespaces().createNamespace("public/default");
admin.namespaces().setNamespaceReplicationClusters("public/default", Sets.newHashSet("test"));
admin.namespaces().setRetention("public/default",
new RetentionPolicies(60, 1000));
}
if (!admin.namespaces().getNamespaces("public").contains("public/__kafka")) {
admin.namespaces().createNamespace("public/__kafka");
admin.namespaces().setNamespaceReplicationClusters("public/__kafka", Sets.newHashSet("test"));
admin.namespaces().setRetention("public/__kafka",
new RetentionPolicies(-1, -1));
}
}
示例23
@Test(dataProvider = "hostnameVerification")
public void testTlsHostVerificationProxyToClient(boolean hostnameVerificationEnabled) throws Exception {
log.info("-- Starting {} test --", methodName);
startProxy();
createAdminClient();
// create a client which connects to proxy over tls and pass authData
PulsarClient proxyClient = createPulsarClient(proxyService.getServiceUrlTls(),
PulsarClient.builder().enableTlsHostnameVerification(hostnameVerificationEnabled));
String namespaceName = "my-property/proxy-authorization/my-ns";
admin.clusters().createCluster("proxy-authorization", new ClusterData(brokerUrl.toString()));
admin.tenants().createTenant("my-property",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("proxy-authorization")));
admin.namespaces().createNamespace(namespaceName);
admin.namespaces().grantPermissionOnNamespace(namespaceName, "Proxy",
Sets.newHashSet(AuthAction.consume, AuthAction.produce));
admin.namespaces().grantPermissionOnNamespace(namespaceName, "Client",
Sets.newHashSet(AuthAction.consume, AuthAction.produce));
try {
proxyClient.newConsumer().topic("persistent://my-property/proxy-authorization/my-ns/my-topic1")
.subscriptionName("my-subscriber-name").subscribe();
if (hostnameVerificationEnabled) {
Assert.fail("Connection should be failed due to hostnameVerification enabled");
}
} catch (PulsarClientException e) {
if (!hostnameVerificationEnabled) {
Assert.fail("Consumer should be created because hostnameverification is disabled");
}
}
log.info("-- Exiting {} test --", methodName);
}
示例24
@Test
public void testSuperProxyUserAndAdminCanListTenants() throws Exception {
try (PulsarAdmin admin = buildAdminClient("admin")) {
admin.tenants().createTenant("tenant1",
new TenantInfo(ImmutableSet.of("user1"),
ImmutableSet.of("test")));
}
WebTarget root = buildWebClient("superproxy");
Assert.assertEquals(ImmutableSet.of("tenant1"),
root.path("/admin/v2/tenants")
.request(MediaType.APPLICATION_JSON)
.header("X-Original-Principal", "admin")
.get(new GenericType<List<String>>() {}));
}
示例25
public Map<String, String> createTenant(String tenant, String role, String cluster, String requestHost) {
TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet(role), Sets.newHashSet(cluster));
Map<String, String> result = Maps.newHashMap();
try {
pulsarAdminService.tenants(requestHost).createTenant(tenant, tenantInfo);
result.put("message", "Create tenant success");
} catch (PulsarAdminException e) {
PulsarAdminOperationException pulsarAdminOperationException
= new PulsarAdminOperationException("Failed to create tenant.");
log.error(pulsarAdminOperationException.getMessage(), e);
result.put("error", "Create tenant failed");
}
return result;
}
示例26
@Test()
public void testGetLastMessageId() throws Exception {
TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"), Sets.newHashSet("test"));
admin.tenants().createTenant("prop-xyz", tenantInfo);
admin.namespaces().createNamespace("prop-xyz/ns1", Sets.newHashSet("test"));
final String topicName = "persistent://prop-xyz/ns1/testGetLastMessageId";
admin.topics().createNonPartitionedTopic(topicName);
Producer<byte[]> batchProducer = pulsarClient.newProducer().topic(topicName)
.enableBatching(true)
.batchingMaxMessages(100)
.batchingMaxPublishDelay(2, TimeUnit.SECONDS)
.create();
admin.topics().createSubscription(topicName, "test", MessageId.earliest);
CompletableFuture<MessageId> completableFuture = new CompletableFuture<>();
for (int i = 0; i < 10; i++) {
completableFuture = batchProducer.sendAsync("test".getBytes());
}
completableFuture.get();
Assert.assertEquals(((BatchMessageIdImpl) admin.topics().getLastMessageId(topicName)).getBatchIndex(), 9);
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName)
.enableBatching(false)
.create();
producer.send("test".getBytes());
Assert.assertTrue(admin.topics().getLastMessageId(topicName) instanceof MessageIdImpl);
}
示例27
@Test
public void testTopicBundleRangeLookup() throws PulsarAdminException, PulsarServerException, Exception {
admin.clusters().createCluster("usw", new ClusterData());
TenantInfo tenantInfo = new TenantInfo(Sets.newHashSet("role1", "role2"),
Sets.newHashSet("test", "usw"));
admin.tenants().updateTenant("prop-xyz", tenantInfo);
admin.namespaces().createNamespace("prop-xyz/getBundleNs", 100);
assertEquals(admin.namespaces().getPolicies("prop-xyz/getBundleNs").bundles.numBundles, 100);
// (1) create a topic
final String topicName = "persistent://prop-xyz/getBundleNs/topic1";
String bundleRange = admin.lookups().getBundleRange(topicName);
assertEquals(bundleRange, pulsar.getNamespaceService().getBundle(TopicName.get(topicName)).getBundleRange());
}
示例28
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);
systemTopicFactory = new NamespaceEventsSystemTopicFactory(pulsarClient);
}
示例29
@BeforeMethod
@Override
public void setup() throws Exception {
super.internalSetup();
admin.clusters().createCluster("use",
new ClusterData(pulsar.getWebServiceAddress()));
admin.tenants().createTenant("my-property",
new TenantInfo(Sets.newHashSet("appid1", "appid2"), Sets.newHashSet("use")));
admin.namespaces().createNamespace("my-property/use/my-ns");
}
示例30
@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"));
}