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

The following examples show how to use org.apache.pulsar.broker.ServiceConfiguration#getClusterName() . 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: PulsarFunctionsTest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static WorkerService createPulsarFunctionWorker(final ServiceConfiguration config) {
  workerConfig = new WorkerConfig();
  workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
  workerConfig.setSchedulerClassName(org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
  workerConfig.setThreadContainerFactory(new WorkerConfig.ThreadContainerFactory().setThreadGroupName("use"));
  // worker talks to local broker
  workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + brokerServicePort);
  workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + brokerWebServicePort);
  workerConfig.setFailureCheckFreqMs(30000);
  workerConfig.setNumFunctionPackageReplicas(0);
  workerConfig.setClusterCoordinationTopicName("coordinate");
  workerConfig.setFunctionAssignmentTopicName("assignment");
  workerConfig.setFunctionMetadataTopicName("metadata");
  workerConfig.setInstanceLivenessCheckFreqMs(30000);
  workerConfig.setWorkerPort(workerServicePort);

  workerConfig.setPulsarFunctionsCluster(config.getClusterName());
  final String hostname = "localhost";
  final String workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-";
  workerConfig.setWorkerHostname(hostname);
  workerConfig.setWorkerId(workerId);

  workerConfig.setUseTls(false);
  workerConfig.setTlsAllowInsecureConnection(true);

  workerConfig.setAuthenticationEnabled(false);
  workerConfig.setAuthorizationEnabled(false);

  return new WorkerService(workerConfig);
}
 
Example 2
Source File: PulsarFunctionsITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static WorkerService createPulsarFunctionWorker(final ServiceConfiguration config) {
  System.setProperty(JAVA_INSTANCE_JAR_PROPERTY, FutureUtil.class.getProtectionDomain().getCodeSource().getLocation().getPath());

  workerConfig = new WorkerConfig();
  final String pulsarFunctionsNamespace = tenant + "/pulsar-function-admin";
  workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
  workerConfig.setSchedulerClassName(org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
  workerConfig.setThreadContainerFactory(new WorkerConfig.ThreadContainerFactory().setThreadGroupName("use"));
  // worker talks to local broker
  workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + brokerServicePort);
  workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + brokerWebServicePort);
  workerConfig.setFailureCheckFreqMs(10000);
  workerConfig.setNumFunctionPackageReplicas(1);
  workerConfig.setClusterCoordinationTopicName("coordinate");
  workerConfig.setFunctionAssignmentTopicName("assignment");
  workerConfig.setFunctionMetadataTopicName("metadata");
  workerConfig.setInstanceLivenessCheckFreqMs(10000);
  workerConfig.setWorkerPort(workerServicePort);
  workerConfig.setPulsarFunctionsCluster(config.getClusterName());
  final String hostname = "localhost";
  final String workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
  workerConfig.setWorkerHostname(hostname);
  workerConfig.setWorkerId(workerId);

  workerConfig.setTlsAllowInsecureConnection(true);

  workerConfig.setAuthenticationEnabled(false);
  workerConfig.setAuthorizationEnabled(false);

  return new WorkerService(workerConfig);
}
 
Example 3
Source File: PulsarFunctionsITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static WorkerService createPulsarFunctionWorker(final ServiceConfiguration config) {
  workerConfig = new WorkerConfig();
  workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
  workerConfig.setSchedulerClassName(org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
  workerConfig.setThreadContainerFactory(new WorkerConfig.ThreadContainerFactory().setThreadGroupName("use"));
  // worker talks to local broker
  workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + brokerServicePort);
  workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + brokerWebServicePort);
  workerConfig.setFailureCheckFreqMs(30000);
  workerConfig.setNumFunctionPackageReplicas(0);
  workerConfig.setClusterCoordinationTopicName("coordinate");
  workerConfig.setFunctionAssignmentTopicName("assignment");
  workerConfig.setFunctionMetadataTopicName("metadata");
  workerConfig.setInstanceLivenessCheckFreqMs(30000);
  workerConfig.setWorkerPort(workerServicePort);

  workerConfig.setPulsarFunctionsCluster(config.getClusterName());
  final String hostname = "localhost";
  final String workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-";
  workerConfig.setWorkerHostname(hostname);
  workerConfig.setWorkerId(workerId);

  workerConfig.setUseTls(false);
  workerConfig.setTlsAllowInsecureConnection(true);

  workerConfig.setAuthenticationEnabled(false);
  workerConfig.setAuthorizationEnabled(false);

  return new WorkerService(workerConfig);
}
 
Example 4
Source File: PulsarFunctionPublishTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private WorkerService createPulsarFunctionWorker(ServiceConfiguration config) {

        workerConfig = new WorkerConfig();
        workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
        workerConfig.setSchedulerClassName(
                org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
        workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
        workerConfig.setFunctionRuntimeFactoryConfigs(
                ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("use"), Map.class));
        // worker talks to local broker
        workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePortTls().get());
        workerConfig.setPulsarWebServiceUrl("https://127.0.0.1:" + config.getWebServicePortTls().get());
        workerConfig.setFailureCheckFreqMs(100);
        workerConfig.setNumFunctionPackageReplicas(1);
        workerConfig.setClusterCoordinationTopicName("coordinate");
        workerConfig.setFunctionAssignmentTopicName("assignment");
        workerConfig.setFunctionMetadataTopicName("metadata");
        workerConfig.setInstanceLivenessCheckFreqMs(100);
        workerConfig.setWorkerPort(0);
        workerConfig.setPulsarFunctionsCluster(config.getClusterName());
        String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
        this.workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
        workerConfig.setWorkerHostname(hostname);
        workerConfig.setWorkerId(workerId);

        workerConfig.setClientAuthenticationPlugin(AuthenticationTls.class.getName());
        workerConfig.setClientAuthenticationParameters(
                String.format("tlsCertFile:%s,tlsKeyFile:%s", TLS_CLIENT_CERT_FILE_PATH, TLS_CLIENT_KEY_FILE_PATH));
        workerConfig.setUseTls(true);
        workerConfig.setTlsAllowInsecureConnection(true);
        workerConfig.setTlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);

        workerConfig.setAuthenticationEnabled(true);
        workerConfig.setAuthorizationEnabled(true);

        return new WorkerService(workerConfig);
    }
 
Example 5
Source File: PulsarWorkerAssignmentTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private WorkerService createPulsarFunctionWorker(ServiceConfiguration config) {
    workerConfig = new WorkerConfig();
    workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
    workerConfig.setSchedulerClassName(
            org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
    workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
    workerConfig.setFunctionRuntimeFactoryConfigs(
            ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("use"), Map.class));
    // worker talks to local broker
    workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePort().get());
    workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + config.getWebServicePort().get());
    workerConfig.setFailureCheckFreqMs(100);
    workerConfig.setNumFunctionPackageReplicas(1);
    workerConfig.setClusterCoordinationTopicName("coordinate");
    workerConfig.setFunctionAssignmentTopicName("assignment");
    workerConfig.setFunctionMetadataTopicName("metadata");
    workerConfig.setInstanceLivenessCheckFreqMs(100);
    workerConfig.setWorkerPort(0);
    workerConfig.setPulsarFunctionsCluster(config.getClusterName());
    final String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
    workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
    workerConfig.setWorkerHostname(hostname);
    workerConfig.setWorkerId(workerId);
    workerConfig.setTopicCompactionFrequencySec(1);

    return new WorkerService(workerConfig);
}
 
Example 6
Source File: PulsarFunctionLocalRunTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private WorkerService createPulsarFunctionWorker(ServiceConfiguration config) {

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

        workerConfig = new WorkerConfig();
        workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
        workerConfig.setSchedulerClassName(
                org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
        workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
        workerConfig.setFunctionRuntimeFactoryConfigs(
                ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName(CLUSTER), Map.class));
        // worker talks to local broker
        workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePortTls().get());
        workerConfig.setPulsarWebServiceUrl("https://127.0.0.1:" + config.getWebServicePortTls().get());
        workerConfig.setFailureCheckFreqMs(100);
        workerConfig.setNumFunctionPackageReplicas(1);
        workerConfig.setClusterCoordinationTopicName("coordinate");
        workerConfig.setFunctionAssignmentTopicName("assignment");
        workerConfig.setFunctionMetadataTopicName("metadata");
        workerConfig.setInstanceLivenessCheckFreqMs(100);
        workerConfig.setWorkerPort(0);
        workerConfig.setPulsarFunctionsCluster(config.getClusterName());
        String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
        this.workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
        workerConfig.setWorkerHostname(hostname);
        workerConfig.setWorkerId(workerId);

        workerConfig.setClientAuthenticationPlugin(AuthenticationTls.class.getName());
        workerConfig.setClientAuthenticationParameters(
                String.format("tlsCertFile:%s,tlsKeyFile:%s", TLS_CLIENT_CERT_FILE_PATH, TLS_CLIENT_KEY_FILE_PATH));
        workerConfig.setUseTls(true);
        workerConfig.setTlsAllowInsecureConnection(true);
        workerConfig.setTlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);

        workerConfig.setAuthenticationEnabled(true);
        workerConfig.setAuthorizationEnabled(true);

        return new WorkerService(workerConfig);
    }
 
Example 7
Source File: PulsarFunctionE2ESecurityTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private WorkerService createPulsarFunctionWorker(ServiceConfiguration config) {

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

        workerConfig = new WorkerConfig();
        workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
        workerConfig.setSchedulerClassName(
                org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
        workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
        workerConfig.setFunctionRuntimeFactoryConfigs(
                ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("use"), Map.class));
        // worker talks to local broker
        workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePort().get());
        workerConfig.setPulsarWebServiceUrl("http://127.0.0.1:" + config.getWebServicePort().get());
        workerConfig.setFailureCheckFreqMs(100);
        workerConfig.setNumFunctionPackageReplicas(1);
        workerConfig.setClusterCoordinationTopicName("coordinate");
        workerConfig.setFunctionAssignmentTopicName("assignment");
        workerConfig.setFunctionMetadataTopicName("metadata");
        workerConfig.setInstanceLivenessCheckFreqMs(100);
        workerConfig.setWorkerPort(0);
        workerConfig.setPulsarFunctionsCluster(config.getClusterName());
        String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
        this.workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
        workerConfig.setWorkerHostname(hostname);
        workerConfig.setWorkerId(workerId);

        workerConfig.setClientAuthenticationPlugin(AuthenticationToken.class.getName());
        workerConfig.setClientAuthenticationParameters(
                String.format("token:%s", adminToken));

        workerConfig.setAuthenticationEnabled(config.isAuthenticationEnabled());
        workerConfig.setAuthenticationProviders(config.getAuthenticationProviders());
        workerConfig.setAuthorizationEnabled(config.isAuthorizationEnabled());
        workerConfig.setAuthorizationProvider(config.getAuthorizationProvider());

        return new WorkerService(workerConfig);
    }
 
Example 8
Source File: PulsarFunctionE2ETest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private WorkerService createPulsarFunctionWorker(ServiceConfiguration config) {

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

        workerConfig = new WorkerConfig();
        workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
        workerConfig.setSchedulerClassName(
                org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
        workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
        workerConfig.setFunctionRuntimeFactoryConfigs(
                ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("use"), Map.class));        // worker talks to local broker
        workerConfig.setFailureCheckFreqMs(100);
        workerConfig.setNumFunctionPackageReplicas(1);
        workerConfig.setClusterCoordinationTopicName("coordinate");
        workerConfig.setFunctionAssignmentTopicName("assignment");
        workerConfig.setFunctionMetadataTopicName("metadata");
        workerConfig.setInstanceLivenessCheckFreqMs(100);
        workerConfig.setWorkerPort(0);
        workerConfig.setPulsarFunctionsCluster(config.getClusterName());
        String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
        this.workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
        workerConfig.setWorkerHostname(hostname);
        workerConfig.setWorkerId(workerId);

        workerConfig.setClientAuthenticationPlugin(AuthenticationTls.class.getName());
        workerConfig.setClientAuthenticationParameters(
                String.format("tlsCertFile:%s,tlsKeyFile:%s", TLS_CLIENT_CERT_FILE_PATH, TLS_CLIENT_KEY_FILE_PATH));
        workerConfig.setUseTls(true);
        workerConfig.setTlsAllowInsecureConnection(true);
        workerConfig.setTlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH);

        workerConfig.setAuthenticationEnabled(true);
        workerConfig.setAuthorizationEnabled(true);

        return new WorkerService(workerConfig);
    }
 
Example 9
Source File: AdminResource.java    From pulsar with Apache License 2.0 4 votes vote down vote up
protected void mergeNamespaceWithDefaults(Policies policies, String namespace, String namespacePath) {
    if (policies.backlog_quota_map.isEmpty()) {
        Policies.setStorageQuota(policies, namespaceBacklogQuota(namespace, namespacePath));
    }

    final ServiceConfiguration config = pulsar().getConfiguration();
    if (policies.max_producers_per_topic < 1) {
        policies.max_producers_per_topic = config.getMaxProducersPerTopic();
    }

    if (policies.max_consumers_per_topic < 1) {
        policies.max_consumers_per_topic = config.getMaxConsumersPerTopic();
    }

    if (policies.max_consumers_per_subscription < 1) {
        policies.max_consumers_per_subscription = config.getMaxConsumersPerSubscription();
    }

    if (policies.max_unacked_messages_per_consumer == -1) {
        policies.max_unacked_messages_per_consumer = config.getMaxUnackedMessagesPerConsumer();
    }

    if (policies.max_unacked_messages_per_subscription == -1) {
        policies.max_unacked_messages_per_subscription = config.getMaxUnackedMessagesPerSubscription();
    }

    final String cluster = config.getClusterName();
    // attach default dispatch rate polices
    if (policies.topicDispatchRate.isEmpty()) {
        policies.topicDispatchRate.put(cluster, dispatchRate());
    }

    if (policies.subscriptionDispatchRate.isEmpty()) {
        policies.subscriptionDispatchRate.put(cluster, subscriptionDispatchRate());
    }

    if (policies.clusterSubscribeRate.isEmpty()) {
        policies.clusterSubscribeRate.put(cluster, subscribeRate());
    }

    if (policies.message_ttl_in_seconds <= 0) {
        policies.message_ttl_in_seconds = config.getTtlDurationDefaultInSeconds();
    }
}
 
Example 10
Source File: PulsarFunctionTlsTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private WorkerService createPulsarFunctionWorker(ServiceConfiguration config) {
    workerConfig = new WorkerConfig();
    workerConfig.setPulsarFunctionsNamespace(pulsarFunctionsNamespace);
    workerConfig.setSchedulerClassName(
            org.apache.pulsar.functions.worker.scheduler.RoundRobinScheduler.class.getName());
    workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
    workerConfig.setFunctionRuntimeFactoryConfigs(
            ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("use"), Map.class));
    // worker talks to local broker
    workerConfig.setPulsarServiceUrl("pulsar://127.0.0.1:" + config.getBrokerServicePort().get());
    workerConfig.setPulsarWebServiceUrl("https://127.0.0.1:" + config.getWebServicePort().get());
    workerConfig.setFailureCheckFreqMs(100);
    workerConfig.setNumFunctionPackageReplicas(1);
    workerConfig.setClusterCoordinationTopicName("coordinate");
    workerConfig.setFunctionAssignmentTopicName("assignment");
    workerConfig.setFunctionMetadataTopicName("metadata");
    workerConfig.setInstanceLivenessCheckFreqMs(100);
    workerConfig.setWorkerPort(0);
    workerConfig.setPulsarFunctionsCluster(config.getClusterName());
    String hostname = ServiceConfigurationUtils.getDefaultOrConfiguredAddress(config.getAdvertisedAddress());
    this.workerId = "c-" + config.getClusterName() + "-fw-" + hostname + "-" + workerConfig.getWorkerPort();
    workerConfig.setWorkerHostname(hostname);
    workerConfig.setWorkerId(workerId);

    workerConfig.setClientAuthenticationPlugin(AuthenticationTls.class.getName());
    workerConfig.setClientAuthenticationParameters(
            String.format("tlsCertFile:%s,tlsKeyFile:%s", TLS_CLIENT_CERT_FILE_PATH, TLS_CLIENT_KEY_FILE_PATH));
    workerConfig.setUseTls(true);
    workerConfig.setTlsAllowInsecureConnection(true);
    workerConfig.setTlsTrustCertsFilePath(TLS_CLIENT_CERT_FILE_PATH);

    workerConfig.setWorkerPortTls(0);
    workerConfig.setTlsEnabled(true);
    workerConfig.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
    workerConfig.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);

    workerConfig.setAuthenticationEnabled(true);
    workerConfig.setAuthorizationEnabled(true);

    return new WorkerService(workerConfig);
}