Java Code Examples for org.apache.pulsar.broker.ServiceConfiguration#setAllowAutoTopicCreationType()

The following examples show how to use org.apache.pulsar.broker.ServiceConfiguration#setAllowAutoTopicCreationType() . 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: BkEnsemblesTestBase.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@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 2
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 3
Source File: BacklogQuotaManagerTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
void setup() throws Exception {
    try {
        // start local bookie and zookeeper
        bkEnsemble = new LocalBookkeeperEnsemble(3, 0, () -> 0);
        bkEnsemble.start();

        // start pulsar service
        config = new ServiceConfiguration();
        config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
        config.setAdvertisedAddress("localhost");
        config.setWebServicePort(Optional.ofNullable(0));
        config.setClusterName("usc");
        config.setBrokerServicePort(Optional.ofNullable(0));
        config.setAuthorizationEnabled(false);
        config.setAuthenticationEnabled(false);
        config.setBacklogQuotaCheckIntervalInSeconds(TIME_TO_CHECK_BACKLOG_QUOTA);
        config.setManagedLedgerMaxEntriesPerLedger(MAX_ENTRIES_PER_LEDGER);
        config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
        config.setAllowAutoTopicCreationType("non-partitioned");

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

        adminUrl = new URL("http://127.0.0.1" + ":" + pulsar.getListenPortHTTP().get());
        admin = PulsarAdmin.builder().serviceHttpUrl(adminUrl.toString()).build();

        admin.clusters().createCluster("usc", new ClusterData(adminUrl.toString()));
        admin.tenants().createTenant("prop",
                new TenantInfo(Sets.newHashSet("appid1"), Sets.newHashSet("usc")));
        admin.namespaces().createNamespace("prop/ns-quota");
        admin.namespaces().setNamespaceReplicationClusters("prop/ns-quota", Sets.newHashSet("usc"));
        admin.namespaces().createNamespace("prop/quotahold");
        admin.namespaces().setNamespaceReplicationClusters("prop/quotahold", Sets.newHashSet("usc"));
        admin.namespaces().createNamespace("prop/quotaholdasync");
        admin.namespaces().setNamespaceReplicationClusters("prop/quotaholdasync", Sets.newHashSet("usc"));
    } catch (Throwable t) {
        LOG.error("Error setting up broker test", t);
        fail("Broker test setup failed");
    }
}
 
Example 4
Source File: BrokerBookieIsolationTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeleteIsolationGroup() throws Exception {

    final String tenant1 = "tenant1";
    final String cluster = "use";
    final String ns2 = String.format("%s/%s/%s", tenant1, cluster, "ns2");
    final String ns3 = String.format("%s/%s/%s", tenant1, cluster, "ns3");

    final String brokerBookkeeperClientIsolationGroups = "default-group";
    final String tenantNamespaceIsolationGroupsPrimary = "tenant1-isolation-primary";
    final String tenantNamespaceIsolationGroupsSecondary = "tenant1-isolation=secondary";

    BookieServer[] bookies = bkEnsemble.getBookies();
    ZooKeeper zkClient = bkEnsemble.getZkClient();

    Set<BookieSocketAddress> defaultBookies = Sets.newHashSet(bookies[0].getLocalAddress(),
            bookies[1].getLocalAddress());
    Set<BookieSocketAddress> isolatedBookies = Sets.newHashSet(bookies[2].getLocalAddress(),
            bookies[3].getLocalAddress());

    setDefaultIsolationGroup(brokerBookkeeperClientIsolationGroups, zkClient, defaultBookies);
    // primary group empty
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsPrimary, zkClient, Sets.newHashSet());
    setDefaultIsolationGroup(tenantNamespaceIsolationGroupsSecondary, zkClient, isolatedBookies);

    ServiceConfiguration config = new ServiceConfiguration();
    config.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
    config.setClusterName(cluster);
    config.setWebServicePort(Optional.of(0));
    config.setZookeeperServers("127.0.0.1" + ":" + bkEnsemble.getZookeeperPort());
    config.setBrokerServicePort(Optional.of(0));
    config.setAdvertisedAddress("localhost");
    config.setBookkeeperClientIsolationGroups(brokerBookkeeperClientIsolationGroups);

    config.setManagedLedgerDefaultEnsembleSize(2);
    config.setManagedLedgerDefaultWriteQuorum(2);
    config.setManagedLedgerDefaultAckQuorum(2);
    config.setAllowAutoTopicCreationType("non-partitioned");

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

    PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarService.getWebServiceAddress()).build();

    ClusterData clusterData = new ClusterData(pulsarService.getWebServiceAddress());
    admin.clusters().createCluster(cluster, clusterData);
    TenantInfo tenantInfo = new TenantInfo(null, Sets.newHashSet(cluster));
    admin.tenants().createTenant(tenant1, tenantInfo);
    admin.namespaces().createNamespace(ns2);
    admin.namespaces().createNamespace(ns3);

    // (1) set affinity-group
    admin.namespaces().setBookieAffinityGroup(ns2, new BookieAffinityGroupData(
            tenantNamespaceIsolationGroupsPrimary, tenantNamespaceIsolationGroupsSecondary));
    admin.namespaces().setBookieAffinityGroup(ns3, new BookieAffinityGroupData(
            tenantNamespaceIsolationGroupsPrimary, tenantNamespaceIsolationGroupsSecondary));

    // (2) get affinity-group
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns2), new BookieAffinityGroupData(
            tenantNamespaceIsolationGroupsPrimary, tenantNamespaceIsolationGroupsSecondary));
    assertEquals(admin.namespaces().getBookieAffinityGroup(ns3), new BookieAffinityGroupData(
            tenantNamespaceIsolationGroupsPrimary, tenantNamespaceIsolationGroupsSecondary));

    // (3) delete affinity-group
    admin.namespaces().deleteBookieAffinityGroup(ns2);

    try {
        admin.namespaces().getBookieAffinityGroup(ns2);
        fail("should have fail due to affinity-group not present");
    } catch (NotFoundException e) {
        // Ok
    }

    assertEquals(admin.namespaces().getBookieAffinityGroup(ns3), new BookieAffinityGroupData(
            tenantNamespaceIsolationGroupsPrimary, tenantNamespaceIsolationGroupsSecondary));

}