Java Code Examples for org.apache.pulsar.common.naming.TopicName#PUBLIC_TENANT

The following examples show how to use org.apache.pulsar.common.naming.TopicName#PUBLIC_TENANT . 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: PulsarStandalone.java    From pulsar with Apache License 2.0 6 votes vote down vote up
private void createDefaultNameSpace(String cluster) {
    // Create a public tenant and default namespace
    final String publicTenant = TopicName.PUBLIC_TENANT;
    final String defaultNamespace = TopicName.PUBLIC_TENANT + "/" + TopicName.DEFAULT_NAMESPACE;
    try {
        if (!admin.tenants().getTenants().contains(publicTenant)) {
            admin.tenants().createTenant(publicTenant,
                    new TenantInfo(Sets.newHashSet(config.getSuperUserRoles()), Sets.newHashSet(cluster)));
        }
        if (!admin.namespaces().getNamespaces(publicTenant).contains(defaultNamespace)) {
            admin.namespaces().createNamespace(defaultNamespace);
            admin.namespaces().setNamespaceReplicationClusters(defaultNamespace, Sets.newHashSet(config.getClusterName()));
        }
    } catch (PulsarAdminException e) {
        log.info(e.getMessage());
    }
}
 
Example 2
Source File: DebeziumSource.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public static String topicNamespace(SourceContext sourceContext) {
    String tenant = sourceContext.getTenant();
    String namespace = sourceContext.getNamespace();

    return (StringUtils.isEmpty(tenant) ? TopicName.PUBLIC_TENANT : tenant) + "/" +
        (StringUtils.isEmpty(namespace) ? TopicName.DEFAULT_NAMESPACE : namespace);
}
 
Example 3
Source File: PulsarFunctionsTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private <T extends GenericContainer> void runSinkTester(SinkTester<T> tester, boolean builtin) throws Exception {
    final String tenant = TopicName.PUBLIC_TENANT;
    final String namespace = TopicName.DEFAULT_NAMESPACE;
    final String inputTopicName = "test-sink-connector-"
        + tester.getSinkType() + "-" + functionRuntimeType + "-input-topic-" + randomName(8);
    final String sinkName = "test-sink-connector-"
        + tester.getSinkType().name().toLowerCase() + "-" + functionRuntimeType + "-name-" + randomName(8);
    final int numMessages = 20;

    // prepare the testing environment for sink
    prepareSink(tester);

    ensureSubscriptionCreated(
        inputTopicName,
        String.format("public/default/%s", sinkName),
        tester.getInputTopicSchema());

    // submit the sink connector
    submitSinkConnector(tester, tenant, namespace, sinkName, inputTopicName);

    // get sink info
    getSinkInfoSuccess(tester, tenant, namespace, sinkName, builtin);

    // get sink status
    Failsafe.with(statusRetryPolicy).run(() -> getSinkStatus(tenant, namespace, sinkName));

    // produce messages
    Map<String, String> kvs;
    if (tester instanceof JdbcPostgresSinkTester) {
        kvs = produceSchemaInsertMessagesToInputTopic(inputTopicName, numMessages, AvroSchema.of(JdbcPostgresSinkTester.Foo.class));
        // wait for sink to process messages
        Failsafe.with(statusRetryPolicy).run(() ->
                waitForProcessingSinkMessages(tenant, namespace, sinkName, numMessages));

        // validate the sink result
        tester.validateSinkResult(kvs);

        kvs = produceSchemaUpdateMessagesToInputTopic(inputTopicName, numMessages, AvroSchema.of(JdbcPostgresSinkTester.Foo.class));

        // wait for sink to process messages
        Failsafe.with(statusRetryPolicy).run(() ->
                waitForProcessingSinkMessages(tenant, namespace, sinkName, numMessages + 20));

        // validate the sink result
        tester.validateSinkResult(kvs);

        kvs = produceSchemaDeleteMessagesToInputTopic(inputTopicName, numMessages, AvroSchema.of(JdbcPostgresSinkTester.Foo.class));

        // wait for sink to process messages
        Failsafe.with(statusRetryPolicy).run(() ->
                waitForProcessingSinkMessages(tenant, namespace, sinkName, numMessages + 20 + 20));

        // validate the sink result
        tester.validateSinkResult(kvs);

    } else {
        kvs = produceMessagesToInputTopic(inputTopicName, numMessages);
        // wait for sink to process messages
        Failsafe.with(statusRetryPolicy).run(() ->
                waitForProcessingSinkMessages(tenant, namespace, sinkName, numMessages));
        // validate the sink result
        tester.validateSinkResult(kvs);
    }

    // update the sink
    updateSinkConnector(tester, tenant, namespace, sinkName, inputTopicName);

    // delete the sink
    deleteSink(tenant, namespace, sinkName);

    // get sink info (sink should be deleted)
    getSinkInfoNotFound(tenant, namespace, sinkName);
}
 
Example 4
Source File: PulsarFunctionsTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private <T extends GenericContainer> void testSource(SourceTester<T> tester)  throws Exception {
    final String tenant = TopicName.PUBLIC_TENANT;
    final String namespace = TopicName.DEFAULT_NAMESPACE;
    final String outputTopicName = "test-source-connector-"
        + functionRuntimeType + "-output-topic-" + randomName(8);
    final String sourceName = "test-source-connector-"
        + functionRuntimeType + "-name-" + randomName(8);
    final int numMessages = 20;

    @Cleanup
    PulsarClient client = PulsarClient.builder()
        .serviceUrl(pulsarCluster.getPlainTextServiceUrl())
        .build();

    @Cleanup
    PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarCluster.getHttpServiceUrl()).build();
    admin.topics().createNonPartitionedTopic(outputTopicName);

    @Cleanup
    Consumer<String> consumer = client.newConsumer(Schema.STRING)
        .topic(outputTopicName)
        .subscriptionName("source-tester")
        .subscriptionType(SubscriptionType.Exclusive)
        .subscribe();

    // prepare the testing environment for source
    prepareSource(tester);

    // submit the source connector
    submitSourceConnector(tester, tenant, namespace, sourceName, outputTopicName);

    // get source info
    getSourceInfoSuccess(tester, tenant, namespace, sourceName);

    // get source status
    Failsafe.with(statusRetryPolicy).run(() -> getSourceStatus(tenant, namespace, sourceName));

    // produce messages
    Map<String, String> kvs = tester.produceSourceMessages(numMessages);

    // wait for source to process messages
    Failsafe.with(statusRetryPolicy).run(() ->
            waitForProcessingSourceMessages(tenant, namespace, sourceName, numMessages));

    // validate the source result
    validateSourceResult(consumer, kvs);

    // update the source connector
    updateSourceConnector(tester, tenant, namespace, sourceName, outputTopicName);

    // delete the source
    deleteSource(tenant, namespace, sourceName);

    // get source info (source should be deleted)
    getSourceInfoNotFound(tenant, namespace, sourceName);
}
 
Example 5
Source File: PulsarFunctionsTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private void testDebeziumMySqlConnect(String converterClassName, boolean jsonWithEnvelope) throws Exception {

        final String tenant = TopicName.PUBLIC_TENANT;
        final String namespace = TopicName.DEFAULT_NAMESPACE;
        final String outputTopicName = "debe-output-topic-name";
        boolean isJsonConverter = converterClassName.endsWith("JsonConverter");
        final String consumeTopicName = "debezium/mysql-"
                + (isJsonConverter ? "json" : "avro")
                + "/dbserver1.inventory.products";
        final String sourceName = "test-source-debezium-mysql" + (isJsonConverter ? "json" : "avro")
                + "-" + functionRuntimeType + "-" + randomName(8);

        // This is the binlog count that contained in mysql container.
        final int numMessages = 47;

        if (pulsarCluster == null) {
            super.setupCluster();
            super.setupFunctionWorkers();
        }

        @Cleanup
        PulsarClient client = PulsarClient.builder()
            .serviceUrl(pulsarCluster.getPlainTextServiceUrl())
            .build();

        @Cleanup
        PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarCluster.getHttpServiceUrl()).build();
        initNamespace(admin);

        try {
            SchemaInfo lastSchemaInfo = admin.schemas().getSchemaInfo(consumeTopicName);
            log.info("lastSchemaInfo: {}", lastSchemaInfo == null ? "null" : lastSchemaInfo.toString());
        } catch (Exception e) {
            log.warn("failed to get schemaInfo for topic: {}, exceptions message: {}",
                    consumeTopicName, e.getMessage());
        }

        admin.topics().createNonPartitionedTopic(outputTopicName);

        @Cleanup
        DebeziumMySqlSourceTester sourceTester = new DebeziumMySqlSourceTester(pulsarCluster, converterClassName);
        sourceTester.getSourceConfig().put("json-with-envelope", jsonWithEnvelope);

        // setup debezium mysql server
        DebeziumMySQLContainer mySQLContainer = new DebeziumMySQLContainer(pulsarCluster.getClusterName());
        sourceTester.setServiceContainer(mySQLContainer);

        // prepare the testing environment for source
        prepareSource(sourceTester);

        // submit the source connector
        submitSourceConnector(sourceTester, tenant, namespace, sourceName, outputTopicName);

        // get source info
        getSourceInfoSuccess(sourceTester, tenant, namespace, sourceName);

        // get source status
        Failsafe.with(statusRetryPolicy).run(() -> getSourceStatus(tenant, namespace, sourceName));

        // wait for source to process messages
        Failsafe.with(statusRetryPolicy).run(() ->
                waitForProcessingSourceMessages(tenant, namespace, sourceName, numMessages));

        @Cleanup
        Consumer consumer = client.newConsumer(getSchema(jsonWithEnvelope))
                .topic(consumeTopicName)
                .subscriptionName("debezium-source-tester")
                .subscriptionType(SubscriptionType.Exclusive)
                .subscriptionInitialPosition(SubscriptionInitialPosition.Earliest)
                .subscribe();
        log.info("[debezium mysql test] create consumer finish. converterName: {}", converterClassName);

        // validate the source result
        sourceTester.validateSourceResult(consumer, 9, null, converterClassName);

        // prepare insert event
        sourceTester.prepareInsertEvent();

        // validate the source insert event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.INSERT, converterClassName);

        // prepare update event
        sourceTester.prepareUpdateEvent();

        // validate the source update event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.UPDATE, converterClassName);

        // prepare delete event
        sourceTester.prepareDeleteEvent();

        // validate the source delete event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.DELETE, converterClassName);

        // delete the source
        deleteSource(tenant, namespace, sourceName);

        // get source info (source should be deleted)
        getSourceInfoNotFound(tenant, namespace, sourceName);
    }
 
Example 6
Source File: PulsarFunctionsTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private  void testDebeziumPostgreSqlConnect(String converterClassName, boolean jsonWithEnvelope) throws Exception {

        final String tenant = TopicName.PUBLIC_TENANT;
        final String namespace = TopicName.DEFAULT_NAMESPACE;
        final String outputTopicName = "debe-output-topic-name";
        final String consumeTopicName = "debezium/postgresql/dbserver1.inventory.products";
        final String sourceName = "test-source-debezium-postgersql-" + functionRuntimeType + "-" + randomName(8);


        // This is the binlog count that contained in postgresql container.
        final int numMessages = 26;

        if (pulsarCluster == null) {
            super.setupCluster();
            super.setupFunctionWorkers();
        }

        @Cleanup
        PulsarClient client = PulsarClient.builder()
                .serviceUrl(pulsarCluster.getPlainTextServiceUrl())
                .build();

        @Cleanup
        PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarCluster.getHttpServiceUrl()).build();
        initNamespace(admin);

        admin.topics().createNonPartitionedTopic(consumeTopicName);
        admin.topics().createNonPartitionedTopic(outputTopicName);

        @Cleanup
        Consumer consumer = client.newConsumer(getSchema(jsonWithEnvelope))
                .topic(consumeTopicName)
                .subscriptionName("debezium-source-tester")
                .subscriptionType(SubscriptionType.Exclusive)
                .subscribe();

        @Cleanup
        DebeziumPostgreSqlSourceTester sourceTester = new DebeziumPostgreSqlSourceTester(pulsarCluster);
        sourceTester.getSourceConfig().put("json-with-envelope", jsonWithEnvelope);

        // setup debezium postgresql server
        DebeziumPostgreSqlContainer postgreSqlContainer = new DebeziumPostgreSqlContainer(pulsarCluster.getClusterName());
        sourceTester.setServiceContainer(postgreSqlContainer);

        // prepare the testing environment for source
        prepareSource(sourceTester);

        // submit the source connector
        submitSourceConnector(sourceTester, tenant, namespace, sourceName, outputTopicName);

        // get source info
        getSourceInfoSuccess(sourceTester, tenant, namespace, sourceName);

        // get source status
        Failsafe.with(statusRetryPolicy).run(() -> getSourceStatus(tenant, namespace, sourceName));

        // wait for source to process messages
        Failsafe.with(statusRetryPolicy).run(() ->
                waitForProcessingSourceMessages(tenant, namespace, sourceName, numMessages));

        // validate the source result
        sourceTester.validateSourceResult(consumer, 9, null, converterClassName);

        // prepare insert event
        sourceTester.prepareInsertEvent();

        // validate the source insert event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.INSERT, converterClassName);

        // prepare update event
        sourceTester.prepareUpdateEvent();

        // validate the source update event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.UPDATE, converterClassName);

        // prepare delete event
        sourceTester.prepareDeleteEvent();

        // validate the source delete event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.DELETE, converterClassName);

        // delete the source
        deleteSource(tenant, namespace, sourceName);

        // get source info (source should be deleted)
        getSourceInfoNotFound(tenant, namespace, sourceName);
    }
 
Example 7
Source File: PulsarFunctionsTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private  void testDebeziumMongoDbConnect(String converterClassName, boolean jsonWithEnvelope) throws Exception {

        final String tenant = TopicName.PUBLIC_TENANT;
        final String namespace = TopicName.DEFAULT_NAMESPACE;
        final String outputTopicName = "debe-output-topic-name";
        final String consumeTopicName = "debezium/mongodb/dbserver1.inventory.products";
        final String sourceName = "test-source-connector-"
                + functionRuntimeType + "-name-" + randomName(8);

        // This is the binlog count that contained in mongodb container.
        final int numMessages = 17;

        if (pulsarCluster == null) {
            super.setupCluster();
            super.setupFunctionWorkers();
        }

        @Cleanup
        PulsarClient client = PulsarClient.builder()
                .serviceUrl(pulsarCluster.getPlainTextServiceUrl())
                .build();

        @Cleanup
        PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(pulsarCluster.getHttpServiceUrl()).build();
        initNamespace(admin);

        admin.topics().createNonPartitionedTopic(consumeTopicName);
        admin.topics().createNonPartitionedTopic(outputTopicName);

        @Cleanup
        Consumer consumer = client.newConsumer(getSchema(jsonWithEnvelope))
                .topic(consumeTopicName)
                .subscriptionName("debezium-source-tester")
                .subscriptionType(SubscriptionType.Exclusive)
                .subscribe();

        @Cleanup
        DebeziumMongoDbSourceTester sourceTester = new DebeziumMongoDbSourceTester(pulsarCluster);
        sourceTester.getSourceConfig().put("json-with-envelope", jsonWithEnvelope);

        // setup debezium mongodb server
        DebeziumMongoDbContainer mongoDbContainer = new DebeziumMongoDbContainer(pulsarCluster.getClusterName());
        sourceTester.setServiceContainer(mongoDbContainer);
        // prepare the testing environment for source
        prepareSource(sourceTester);

        // submit the source connector
        submitSourceConnector(sourceTester, tenant, namespace, sourceName, outputTopicName);

        // get source info
        getSourceInfoSuccess(sourceTester, tenant, namespace, sourceName);

        // get source status
        Failsafe.with(statusRetryPolicy).run(() -> getSourceStatus(tenant, namespace, sourceName));

        // wait for source to process messages
        Failsafe.with(statusRetryPolicy).run(() ->
                waitForProcessingSourceMessages(tenant, namespace, sourceName, numMessages));

        // validate the source result
        sourceTester.validateSourceResult(consumer, 9, null, converterClassName);

        // prepare insert event
        sourceTester.prepareInsertEvent();

        // validate the source insert event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.INSERT, converterClassName);

        // prepare update event
        sourceTester.prepareUpdateEvent();

        // validate the source update event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.UPDATE, converterClassName);

        // prepare delete event
        sourceTester.prepareDeleteEvent();

        // validate the source delete event
        sourceTester.validateSourceResult(consumer, 1, SourceTester.DELETE, converterClassName);

        // delete the source
        deleteSource(tenant, namespace, sourceName);

        // get source info (source should be deleted)
        getSourceInfoNotFound(tenant, namespace, sourceName);
    }