Java Code Examples for org.apache.pulsar.common.policies.data.TenantInfo#setAllowedClusters()

The following examples show how to use org.apache.pulsar.common.policies.data.TenantInfo#setAllowedClusters() . 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: PulsarClientTest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  if (!isJdkSupported)
    return;

  bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, TestUtil::nextFreePort);
  bkEnsemble.start();

  final int brokerWebServicePort = TestUtil.nextFreePort();
  final int brokerServicePort = TestUtil.nextFreePort();

  final ServiceConfiguration config = new ServiceConfiguration();
  config.setClusterName(CLUSTER_NAME);
  final Set<String> superUsers = Sets.newHashSet("superUser");
  config.setSuperUserRoles(superUsers);
  config.setWebServicePort(brokerWebServicePort);
  config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
  config.setBrokerServicePort(brokerServicePort);
  config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
  config.setTlsAllowInsecureConnection(true);
  config.setAdvertisedAddress("localhost");

  pulsarService = new PulsarService(config);
  pulsarService.start();

  try (final PulsarAdmin admin = pulsarService.getAdminClient()) {
    final ClusterData clusterData = new ClusterData(pulsarService.getBrokerServiceUrl());
    admin.clusters().createCluster(CLUSTER_NAME, clusterData);

    final TenantInfo propAdmin = new TenantInfo();
    propAdmin.getAdminRoles().add("superUser");
    propAdmin.setAllowedClusters(Sets.newHashSet(Lists.newArrayList(CLUSTER_NAME)));

    admin.tenants().createTenant("public", propAdmin);
    admin.namespaces().createNamespace("public/default", Sets.newHashSet(CLUSTER_NAME));
  }
}
 
Example 2
Source File: SLAMonitoringTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private void createTenant(PulsarAdmin pulsarAdmin)
        throws PulsarClientException, MalformedURLException, PulsarAdminException {
    ClusterData clusterData = new ClusterData();
    clusterData.setServiceUrl(pulsarAdmin.getServiceUrl());
    pulsarAdmins[0].clusters().createCluster("my-cluster", clusterData);
    Set<String> allowedClusters = new HashSet<>();
    allowedClusters.add("my-cluster");
    TenantInfo adminConfig = new TenantInfo();
    adminConfig.setAllowedClusters(allowedClusters);
    Set<String> adminRoles = new HashSet<>();
    adminRoles.add("");
    adminConfig.setAdminRoles(adminRoles);
    pulsarAdmin.tenants().createTenant("sla-monitor", adminConfig);
}
 
Example 3
Source File: TopicOwnerTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: SchemaCompatibilityCheckTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: SchemaTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 6
Source File: PulsarFunctionE2ETest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "validRoleName")
public void testAuthorization(boolean validRoleName) throws Exception {

    final String namespacePortion = "io";
    final String replNamespace = tenant + "/" + namespacePortion;
    final String sinkTopic = "persistent://" + replNamespace + "/output";
    final String functionName = "PulsarSink-test";
    final String subscriptionName = "test-sub";
    admin.namespaces().createNamespace(replNamespace);
    Set<String> clusters = Sets.newHashSet(Lists.newArrayList("use"));
    admin.namespaces().setNamespaceReplicationClusters(replNamespace, clusters);

    String roleName = validRoleName ? "superUser" : "invalid";
    TenantInfo propAdmin = new TenantInfo();
    propAdmin.getAdminRoles().add(roleName);
    propAdmin.setAllowedClusters(Sets.newHashSet(Lists.newArrayList("use")));
    admin.tenants().updateTenant(tenant, propAdmin);

    String jarFilePathUrl = Utils.FILE + ":" + getClass().getClassLoader().getResource("pulsar-functions-api-examples.jar").getFile();
    FunctionConfig functionConfig = createFunctionConfig(tenant, namespacePortion, functionName,
            "my.*", sinkTopic, subscriptionName);
    try {
        admin.functions().createFunctionWithUrl(functionConfig, jarFilePathUrl);
        assertTrue(validRoleName);
    } catch (org.apache.pulsar.client.admin.PulsarAdminException.NotAuthorizedException ne) {
        assertFalse(validRoleName);
    }
}
 
Example 7
Source File: PulsarFunctionsITest.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
static void start() throws Exception {
  // Start local bookkeeper ensemble
  final LocalBookkeeperEnsemble bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT,TestUtil::nextFreePort);
  bkEnsemble.start();

  final String brokerServiceUrl = "http://127.0.0.1:" + brokerWebServicePort;

  final ServiceConfiguration config = spy(new ServiceConfiguration());
  config.setClusterName(CLUSTER_NAME);
  final Set<String> superUsers = Sets.newHashSet("superUser");
  config.setSuperUserRoles(superUsers);
  config.setWebServicePort(Optional.of(brokerWebServicePort));
  config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
  config.setBrokerServicePort(Optional.of(brokerServicePort));
  config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
  config.setTlsAllowInsecureConnection(true);
  config.setAdvertisedAddress("localhost");

  config.setAuthenticationEnabled(false);
  config.setAuthorizationEnabled(false);

  config.setBrokerClientTlsEnabled(false);
  config.setAllowAutoTopicCreationType("non-partitioned");

  final WorkerService functionsWorkerService = createPulsarFunctionWorker(config);
  final URL urlTls = new URL(brokerServiceUrl);
  final Optional<WorkerService> functionWorkerService = Optional.of(functionsWorkerService);
  try (final PulsarService pulsar = new PulsarService(config, functionWorkerService)) {
    pulsar.start();
    try (final PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(brokerServiceUrl).allowTlsInsecureConnection(true).build()) {
      // update cluster metadata
      final ClusterData clusterData = new ClusterData(urlTls.toString());
      admin.clusters().updateCluster(config.getClusterName(), clusterData);

      final TenantInfo propAdmin = new TenantInfo();
      propAdmin.getAdminRoles().add("superUser");
      propAdmin.setAllowedClusters(Sets.newHashSet(CLUSTER_NAME));
      admin.tenants().updateTenant(tenant, propAdmin);

      final String jarFilePathUrl = Utils.FILE + ":" + ExclamationFunction.class.getProtectionDomain().getCodeSource().getLocation().getPath();

      final ClientBuilder clientBuilder = PulsarClient.builder().serviceUrl(workerConfig.getPulsarServiceUrl());
      try (final PulsarClient pulsarClient = clientBuilder.build()) {
        testE2EPulsarFunction(jarFilePathUrl, admin, pulsarClient);
      }
    }
  }
}
 
Example 8
Source File: PulsarFunctionsITest.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
static void start() throws Exception {
  // Start local bookkeeper ensemble
  final LocalBookkeeperEnsemble bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, TestUtil::nextFreePort);
  bkEnsemble.start();

  final String brokerServiceUrl = "http://127.0.0.1:" + brokerWebServicePort;

  final ServiceConfiguration config = new ServiceConfiguration();
  config.setClusterName(CLUSTER_NAME);
  final Set<String> superUsers = Sets.newHashSet("superUser");
  config.setSuperUserRoles(superUsers);

  config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
  config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
  config.setWebServicePort(brokerWebServicePort);
  config.setBrokerServicePort(brokerServicePort);

  config.setAuthenticationEnabled(false);
  config.setTlsEnabled(false);
  config.setTlsAllowInsecureConnection(true);
  config.setAdvertisedAddress("localhost");

  final WorkerService functionsWorkerService = createPulsarFunctionWorker(config);
  final URL urlTls = new URL(brokerServiceUrl);
  final Optional<WorkerService> functionWorkerService = Optional.of(functionsWorkerService);
  try (final PulsarService pulsar = new PulsarService(config, functionWorkerService)) {
    pulsar.start();
    try (final PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(brokerServiceUrl).allowTlsInsecureConnection(true).build()) {
      // update cluster metadata
      final ClusterData clusterData = new ClusterData(urlTls.toString());
      admin.clusters().updateCluster(config.getClusterName(), clusterData);

      final ClientBuilder clientBuilder = PulsarClient.builder().serviceUrl(workerConfig.getPulsarServiceUrl());
      try (final PulsarClient pulsarClient = clientBuilder.build()) {
        final TenantInfo propAdmin = new TenantInfo();
        propAdmin.getAdminRoles().add("superUser");
        propAdmin.setAllowedClusters(Sets.newHashSet(CLUSTER_NAME));
        admin.tenants().updateTenant(tenant, propAdmin);

        testPulsarFunction(admin, pulsarClient);
      }
    }
  }
}
 
Example 9
Source File: ClientDeduplicationFailureTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod(timeOut = 300000)
void setup(Method method) throws Exception {
    log.info("--- Setting up method {} ---", method.getName());

    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();

    config = spy(new ServiceConfiguration());
    config.setClusterName("use");
    config.setWebServicePort(Optional.of(0));
    config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerServicePort(Optional.of(0));
    config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    config.setTlsAllowInsecureConnection(true);
    config.setAdvertisedAddress("localhost");
    config.setLoadBalancerSheddingEnabled(false);
    config.setLoadBalancerAutoBundleSplitEnabled(false);
    config.setLoadBalancerEnabled(false);
    config.setLoadBalancerAutoUnloadSplitBundlesEnabled(false);

    config.setAllowAutoTopicCreationType("non-partitioned");


    pulsar = new PulsarService(config);
    pulsar.start();

    String brokerServiceUrl = pulsar.getWebServiceAddress();
    url = new URL(brokerServiceUrl);

    admin = PulsarAdmin.builder().serviceHttpUrl(brokerServiceUrl).build();

    brokerStatsClient = admin.brokerStats();
    primaryHost = pulsar.getWebServiceAddress();

    // update cluster metadata
    ClusterData clusterData = new ClusterData(url.toString());
    admin.clusters().createCluster(config.getClusterName(), clusterData);

    ClientBuilder clientBuilder = PulsarClient.builder().serviceUrl(pulsar.getBrokerServiceUrl()).maxBackoffInterval(1, TimeUnit.SECONDS);
    pulsarClient = clientBuilder.build();

    TenantInfo tenantInfo = new TenantInfo();
    tenantInfo.setAllowedClusters(Sets.newHashSet(Lists.newArrayList("use")));
    admin.tenants().createTenant(tenant, tenantInfo);
}
 
Example 10
Source File: WebServiceTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Test
public void testMaxRequestSize() throws Exception {
    setupEnv(true, "1.0", true, false, false, false);

    String url = pulsar.getWebServiceAddress() + "/admin/v2/tenants/my-tenant" + System.currentTimeMillis();

    @Cleanup
    CloseableHttpClient client = HttpClients.createDefault();
    HttpPut httpPut = new HttpPut(url);
    httpPut.setHeader("Content-Type", "application/json");
    httpPut.setHeader("Accept", "application/json");

    // HTTP server is configured to reject everything > 10K
    TenantInfo info1 = new TenantInfo();
    info1.setAdminRoles(Collections.singleton(StringUtils.repeat("*", 20 * 1024)));
    httpPut.setEntity(new ByteArrayEntity(ObjectMapperFactory.getThreadLocal().writeValueAsBytes(info1)));

    CloseableHttpResponse response = client.execute(httpPut);
    // This should have failed
    assertEquals(response.getStatusLine().getStatusCode(), 400);

    // Create local cluster
    String localCluster = "test";
    String clusterPath = PulsarWebResource.path("clusters", localCluster);
    byte[] content = ObjectMapperFactory.getThreadLocal().writeValueAsBytes(new ClusterData());
    pulsar.getGlobalZkCache().getZooKeeper().create(clusterPath, content, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    TenantInfo info2 = new TenantInfo();
    info2.setAdminRoles(Collections.singleton(StringUtils.repeat("*", 1 * 1024)));
    info2.setAllowedClusters(Sets.newHashSet(localCluster));
    httpPut.setEntity(new ByteArrayEntity(ObjectMapperFactory.getThreadLocal().writeValueAsBytes(info2)));

    response = client.execute(httpPut);
    assertEquals(response.getStatusLine().getStatusCode(), 204);

    // Simple GET without content size should go through
    HttpGet httpGet = new HttpGet(url);
    httpGet.setHeader("Content-Type", "application/json");
    httpGet.setHeader("Accept", "application/json");
    response = client.execute(httpGet);
    assertEquals(response.getStatusLine().getStatusCode(), 200);
}
 
Example 11
Source File: PulsarFunctionPublishTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
void setup(Method method) throws Exception {

    // delete all function temp files
    File dir = new File(System.getProperty("java.io.tmpdir"));
    File[] foundFiles = dir.listFiles((ignoredDir, name) -> name.startsWith("function"));

    for (File file : foundFiles) {
        file.delete();
    }

    log.info("--- Setting up method {} ---", method.getName());

    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();

    config = spy(new ServiceConfiguration());
    config.setClusterName("use");
    Set<String> superUsers = Sets.newHashSet("superUser");
    config.setSuperUserRoles(superUsers);
    config.setWebServicePort(Optional.of(0));
    config.setWebServicePortTls(Optional.of(0));
    config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerServicePort(Optional.of(0));
    config.setBrokerServicePortTls(Optional.of(0));
    config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    config.setTlsAllowInsecureConnection(true);
    config.setAdvertisedAddress("localhost");

    Set<String> providers = new HashSet<>();
    providers.add(AuthenticationProviderTls.class.getName());
    config.setAuthenticationEnabled(true);
    config.setAuthenticationProviders(providers);

    config.setAuthorizationEnabled(true);
    config.setAuthorizationProvider(PulsarAuthorizationProvider.class.getName());

    config.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    config.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
    config.setTlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);

    config.setBrokerClientAuthenticationPlugin(AuthenticationTls.class.getName());
    config.setBrokerClientAuthenticationParameters(
            "tlsCertFile:" + TLS_CLIENT_CERT_FILE_PATH + "," + "tlsKeyFile:" + TLS_CLIENT_KEY_FILE_PATH);
    config.setBrokerClientTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);
    config.setBrokerClientTlsEnabled(true);
    config.setAllowAutoTopicCreationType("non-partitioned");

    functionsWorkerService = createPulsarFunctionWorker(config);

    Optional<WorkerService> functionWorkerService = Optional.of(functionsWorkerService);
    pulsar = new PulsarService(config, functionWorkerService, (exitCode) -> {});
    pulsar.start();

    String brokerServiceUrl = pulsar.getWebServiceAddressTls();
    urlTls = new URL(brokerServiceUrl);


    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);

    admin = spy(
            PulsarAdmin.builder().serviceHttpUrl(brokerServiceUrl).tlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH)
                    .allowTlsInsecureConnection(true).authentication(authTls).build());

    brokerStatsClient = admin.brokerStats();
    primaryHost = pulsar.getWebServiceAddress();

    // update cluster metadata
    ClusterData clusterData = new ClusterData(urlTls.toString());
    admin.clusters().updateCluster(config.getClusterName(), clusterData);

    ClientBuilder clientBuilder = PulsarClient.builder().serviceUrl(this.workerConfig.getPulsarServiceUrl());
    if (isNotBlank(workerConfig.getClientAuthenticationPlugin())
            && isNotBlank(workerConfig.getClientAuthenticationParameters())) {
        clientBuilder.enableTls(workerConfig.isUseTls());
        clientBuilder.allowTlsInsecureConnection(workerConfig.isTlsAllowInsecureConnection());
        clientBuilder.authentication(workerConfig.getClientAuthenticationPlugin(),
                workerConfig.getClientAuthenticationParameters());
    }
    pulsarClient = clientBuilder.build();

    TenantInfo propAdmin = new TenantInfo();
    propAdmin.getAdminRoles().add("superUser");
    propAdmin.setAllowedClusters(Sets.newHashSet(Lists.newArrayList("use")));
    admin.tenants().updateTenant(tenant, propAdmin);

    System.setProperty(JAVA_INSTANCE_JAR_PROPERTY,
            FutureUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath());

    functionWorkerService.get().getLeaderService().waitLeaderInit();
}
 
Example 12
Source File: PulsarWorkerAssignmentTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod(timeOut = 60000)
void setup(Method method) throws Exception {

    log.info("--- Setting up method {} ---", method.getName());

    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();

    config = spy(new ServiceConfiguration());
    config.setClusterName("use");
    final Set<String> superUsers = Sets.newHashSet("superUser");
    config.setSuperUserRoles(superUsers);
    config.setWebServicePort(Optional.of(0));
    config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerServicePort(Optional.of(0));
    config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
    config.setAdvertisedAddress("localhost");

    functionsWorkerService = createPulsarFunctionWorker(config);
    final Optional<WorkerService> functionWorkerService = Optional.of(functionsWorkerService);
    pulsar = new PulsarService(config, functionWorkerService, (exitCode) -> {});
    pulsar.start();

    admin = spy(PulsarAdmin.builder().serviceHttpUrl(pulsar.getWebServiceAddress()).build());

    brokerStatsClient = admin.brokerStats();
    primaryHost = pulsar.getWebServiceAddress();

    // update cluster metadata
    final ClusterData clusterData = new ClusterData(pulsar.getBrokerServiceUrl());
    admin.clusters().updateCluster(config.getClusterName(), clusterData);

    final ClientBuilder clientBuilder = PulsarClient.builder().serviceUrl(this.workerConfig.getPulsarServiceUrl());
    pulsarClient = clientBuilder.build();

    final TenantInfo propAdmin = new TenantInfo();
    propAdmin.getAdminRoles().add("superUser");
    propAdmin.setAllowedClusters(Sets.newHashSet(Lists.newArrayList("use")));
    admin.tenants().updateTenant(tenant, propAdmin);

    Thread.sleep(100);
}
 
Example 13
Source File: PulsarFunctionAdminTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
void setup(Method method) throws Exception {

    log.info("--- Setting up method {} ---", method.getName());

    // Start local bookkeeper ensemble
    bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
    bkEnsemble.start();

    config = spy(new ServiceConfiguration());
    config.setClusterName("use");
    Set<String> superUsers = Sets.newHashSet("superUser");
    config.setSuperUserRoles(superUsers);
    config.setWebServicePort(Optional.of(0));
    config.setWebServicePortTls(Optional.of(0));
    config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerServicePort(Optional.of(0));
    config.setBrokerServicePortTls(Optional.of(0));
    config.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());


    Set<String> providers = new HashSet<>();
    providers.add(AuthenticationProviderTls.class.getName());
    config.setAuthenticationEnabled(true);
    config.setAuthenticationProviders(providers);
    config.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    config.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
    config.setTlsAllowInsecureConnection(true);


    functionsWorkerService = createPulsarFunctionWorker(config);
    Optional<WorkerService> functionWorkerService = Optional.of(functionsWorkerService);
    pulsar = new PulsarService(config, functionWorkerService, (exitCode) -> {});
    pulsar.start();
    urlTls = new URL(pulsar.getBrokerServiceUrlTls());

    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);

    admin = spy(
            PulsarAdmin.builder()
                    .serviceHttpUrl(pulsar.getWebServiceAddressTls())
                    .tlsTrustCertsFilePath(TLS_CLIENT_CERT_FILE_PATH)
                    .allowTlsInsecureConnection(true)
                    .authentication(authTls)
                    .build());

    brokerStatsClient = admin.brokerStats();
    primaryHost = pulsar.getWebServiceAddress();

    // update cluster metadata
    ClusterData clusterData = new ClusterData(urlTls.toString());
    admin.clusters().updateCluster(config.getClusterName(), clusterData);

    ClientBuilder clientBuilder = PulsarClient.builder().serviceUrl(this.workerConfig.getPulsarServiceUrl());
    if (isNotBlank(workerConfig.getClientAuthenticationPlugin())
            && isNotBlank(workerConfig.getClientAuthenticationParameters())) {
        clientBuilder.enableTls(workerConfig.isUseTls());
        clientBuilder.allowTlsInsecureConnection(workerConfig.isTlsAllowInsecureConnection());
        clientBuilder.authentication(workerConfig.getClientAuthenticationPlugin(),
                workerConfig.getClientAuthenticationParameters());
    }
    pulsarClient = clientBuilder.build();

    TenantInfo propAdmin = new TenantInfo();
    propAdmin.setAllowedClusters(Sets.newHashSet(Lists.newArrayList("use")));
    admin.tenants().updateTenant(tenant, propAdmin);

    Thread.sleep(100);
}