Search in sources :

Example 1 with ServiceConfiguration

use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.

the class PulsarConfigurationLoader method convertFrom.

/**
 * Converts a PulsarConfiguration object to a ServiceConfiguration object.
 *
 * @param conf
 * @param ignoreNonExistMember
 * @return
 * @throws IllegalArgumentException
 *             if conf has the field whose name is not contained in ServiceConfiguration and ignoreNonExistMember is false.
 * @throws RuntimeException
 */
public static ServiceConfiguration convertFrom(PulsarConfiguration conf, boolean ignoreNonExistMember) throws RuntimeException {
    try {
        final ServiceConfiguration convertedConf = ServiceConfiguration.class.newInstance();
        Field[] confFields = conf.getClass().getDeclaredFields();
        Arrays.stream(confFields).forEach(confField -> {
            try {
                Field convertedConfField = ServiceConfiguration.class.getDeclaredField(confField.getName());
                confField.setAccessible(true);
                convertedConfField.setAccessible(true);
                convertedConfField.set(convertedConf, confField.get(conf));
            } catch (NoSuchFieldException e) {
                if (!ignoreNonExistMember) {
                    throw new IllegalArgumentException("Exception caused while converting configuration: " + e.getMessage());
                }
            } catch (IllegalAccessException e) {
                throw new RuntimeException("Exception caused while converting configuration: " + e.getMessage());
            }
        });
        return convertedConf;
    } catch (InstantiationException e) {
        throw new RuntimeException("Exception caused while converting configuration: " + e.getMessage());
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Exception caused while converting configuration: " + e.getMessage());
    }
}
Also used : Field(java.lang.reflect.Field) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration)

Example 2 with ServiceConfiguration

use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.

the class PulsarConfigurationLoaderTest method testConfigurationConverting.

@Test
public void testConfigurationConverting() throws Exception {
    MockConfiguration mockConfiguration = new MockConfiguration();
    ServiceConfiguration serviceConfiguration = PulsarConfigurationLoader.convertFrom(mockConfiguration);
    // check whether converting correctly
    assertEquals(serviceConfiguration.getZookeeperServers(), "localhost:2181");
    assertEquals(serviceConfiguration.getGlobalZookeeperServers(), "localhost:2184");
    assertEquals(serviceConfiguration.getBrokerServicePort(), 7650);
    assertEquals(serviceConfiguration.getBrokerServicePortTls(), 7651);
    assertEquals(serviceConfiguration.getWebServicePort(), 9080);
    assertEquals(serviceConfiguration.getWebServicePortTls(), 9443);
    // check whether exception causes
    try {
        PulsarConfigurationLoader.convertFrom(mockConfiguration, false);
        fail();
    } catch (Exception e) {
        assertEquals(e.getClass(), IllegalArgumentException.class);
    }
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Test(org.testng.annotations.Test)

Example 3 with ServiceConfiguration

use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.

the class PulsarConfigurationLoaderTest method testPulsarConfiguraitonLoadingStream.

@Test
public void testPulsarConfiguraitonLoadingStream() throws Exception {
    File testConfigFile = new File("tmp." + System.currentTimeMillis() + ".properties");
    if (testConfigFile.exists()) {
        testConfigFile.delete();
    }
    final String zkServer = "z1.example.com,z2.example.com,z3.example.com";
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(testConfigFile)));
    printWriter.println("zookeeperServers=" + zkServer);
    printWriter.println("globalZookeeperServers=gz1.example.com,gz2.example.com,gz3.example.com/foo");
    printWriter.println("brokerDeleteInactiveTopicsEnabled=true");
    printWriter.println("statusFilePath=/tmp/status.html");
    printWriter.println("managedLedgerDefaultEnsembleSize=1");
    printWriter.println("backlogQuotaDefaultLimitGB=18");
    printWriter.println("clusterName=usc");
    printWriter.println("brokerClientAuthenticationPlugin=test.xyz.client.auth.plugin");
    printWriter.println("brokerClientAuthenticationParameters=role:my-role");
    printWriter.println("superUserRoles=appid1,appid2");
    printWriter.println("brokerServicePort=7777");
    printWriter.println("managedLedgerDefaultMarkDeleteRateLimit=5.0");
    printWriter.println("managedLedgerDigestType=CRC32C");
    printWriter.close();
    testConfigFile.deleteOnExit();
    InputStream stream = new FileInputStream(testConfigFile);
    final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(stream, ServiceConfiguration.class);
    assertNotNull(serviceConfig);
    assertEquals(serviceConfig.getZookeeperServers(), zkServer);
    assertEquals(serviceConfig.isBrokerDeleteInactiveTopicsEnabled(), true);
    assertEquals(serviceConfig.getBacklogQuotaDefaultLimitGB(), 18);
    assertEquals(serviceConfig.getClusterName(), "usc");
    assertEquals(serviceConfig.getBrokerClientAuthenticationParameters(), "role:my-role");
    assertEquals(serviceConfig.getBrokerServicePort(), 7777);
    assertEquals(serviceConfig.getManagedLedgerDigestType(), DigestType.CRC32C);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 4 with ServiceConfiguration

use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.

the class PulsarConfigurationLoaderTest method testPulsarConfiguraitonLoadingProp.

@Test
public void testPulsarConfiguraitonLoadingProp() throws Exception {
    final String zk = "localhost:2184";
    final Properties prop = new Properties();
    prop.setProperty("zookeeperServers", zk);
    final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(prop, ServiceConfiguration.class);
    assertNotNull(serviceConfig);
    assertEquals(serviceConfig.getZookeeperServers(), zk);
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 5 with ServiceConfiguration

use of org.apache.pulsar.broker.ServiceConfiguration in project incubator-pulsar by apache.

the class PulsarConfigurationLoaderTest method testPulsarConfiguraitonComplete.

@Test
public void testPulsarConfiguraitonComplete() throws Exception {
    final String zk = "localhost:2184";
    final Properties prop = new Properties();
    prop.setProperty("zookeeperServers", zk);
    final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(prop, ServiceConfiguration.class);
    try {
        isComplete(serviceConfig);
        fail("it should fail as config is not complete");
    } catch (IllegalArgumentException e) {
    // Ok
    }
}
Also used : ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Aggregations

ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)58 Test (org.testng.annotations.Test)28 PulsarService (org.apache.pulsar.broker.PulsarService)24 BeforeMethod (org.testng.annotations.BeforeMethod)14 URL (java.net.URL)11 ClusterData (org.apache.pulsar.common.policies.data.ClusterData)10 Field (java.lang.reflect.Field)9 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)9 TopicName (org.apache.pulsar.common.naming.TopicName)9 LoadManager (org.apache.pulsar.broker.loadbalance.LoadManager)8 Authentication (org.apache.pulsar.client.api.Authentication)8 NamespaceBundle (org.apache.pulsar.common.naming.NamespaceBundle)8 Policies (org.apache.pulsar.common.policies.data.Policies)8 LocalBookkeeperEnsemble (org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble)8 InputStream (java.io.InputStream)7 URI (java.net.URI)7 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)7 IOException (java.io.IOException)6 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)6 Map (java.util.Map)5