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());
}
}
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);
}
}
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);
}
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);
}
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
}
}
Aggregations