Search in sources :

Example 1 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class ServiceConfigurationTest method testInit.

/**
     * test {@link ServiceConfiguration} initialization
     * 
     * @throws Exception
     */
@Test
public void testInit() throws Exception {
    final String zookeeperServer = "localhost:2184";
    final int brokerServicePort = 1000;
    InputStream newStream = updateProp(zookeeperServer, String.valueOf(brokerServicePort), "ns1,ns2");
    final ServiceConfiguration config = PulsarConfigurationLoader.create(newStream, ServiceConfiguration.class);
    assertTrue(isNotBlank(config.getZookeeperServers()));
    assertTrue(config.getBrokerServicePort() == brokerServicePort);
    assertEquals(config.getBootstrapNamespaces().get(1), "ns2");
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.testng.annotations.Test)

Example 2 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class PulsarBrokerStarterTest method testGlobalZooKeeperConfig.

/**
     * Tests the private static <code>loadConfig</code> method of {@link PulsarBrokerStarter} class: verifies (1) if the
     * method returns a non-null {@link ServiceConfiguration} instance where all required settings are filled in and (2)
     * if the property variables inside the given property file are correctly referred to that returned object.
     */
@Test
public void testGlobalZooKeeperConfig() throws SecurityException, NoSuchMethodException, IOException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    File testConfigFile = new File("tmp." + System.currentTimeMillis() + ".properties");
    if (testConfigFile.exists()) {
        testConfigFile.delete();
    }
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(testConfigFile)));
    printWriter.println("zookeeperServers=z1.example.com,z2.example.com,z3.example.com");
    printWriter.println("globalZookeeperServers=");
    printWriter.println("brokerDeleteInactiveTopicsEnabled=false");
    printWriter.println("statusFilePath=/tmp/status.html");
    printWriter.println("managedLedgerDefaultEnsembleSize=1");
    printWriter.println("managedLedgerDefaultWriteQuorum=1");
    printWriter.println("managedLedgerDefaultAckQuorum=1");
    printWriter.println("managedLedgerMaxEntriesPerLedger=25");
    printWriter.println("managedLedgerCursorMaxEntriesPerLedger=50");
    printWriter.println("managedLedgerCursorRolloverTimeInSeconds=3000");
    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("pulsar.broker.enableClientVersionCheck=true");
    printWriter.println("pulsar.broker.allowUnversionedClients=true");
    printWriter.println("clientLibraryVersionCheckEnabled=true");
    printWriter.println("clientLibraryVersionCheckAllowUnversioned=true");
    printWriter.println("replicationConnectionsPerBroker=12");
    printWriter.close();
    testConfigFile.deleteOnExit();
    Method targetMethod = PulsarBrokerStarter.class.getDeclaredMethod("loadConfig", String.class);
    targetMethod.setAccessible(true);
    Object returnValue = targetMethod.invoke(PulsarBrokerStarter.class, testConfigFile.getAbsolutePath());
    Assert.assertTrue(ServiceConfiguration.class.isInstance(returnValue));
    ServiceConfiguration serviceConfig = (ServiceConfiguration) returnValue;
    Assert.assertEquals(serviceConfig.getZookeeperServers(), "z1.example.com,z2.example.com,z3.example.com");
    Assert.assertEquals(serviceConfig.getGlobalZookeeperServers(), "z1.example.com,z2.example.com,z3.example.com");
    Assert.assertFalse(serviceConfig.isBrokerDeleteInactiveTopicsEnabled());
    Assert.assertEquals(serviceConfig.getStatusFilePath(), "/tmp/status.html");
    Assert.assertEquals(serviceConfig.getBacklogQuotaDefaultLimitGB(), 18);
    Assert.assertEquals(serviceConfig.getClusterName(), "usc");
    Assert.assertEquals(serviceConfig.getBrokerClientAuthenticationPlugin(), "test.xyz.client.auth.plugin");
    Assert.assertEquals(serviceConfig.getBrokerClientAuthenticationParameters(), "role:my-role");
    Assert.assertEquals(serviceConfig.getSuperUserRoles(), Sets.newHashSet("appid1", "appid2"));
    Assert.assertEquals(serviceConfig.getManagedLedgerCursorRolloverTimeInSeconds(), 3000);
    Assert.assertEquals(serviceConfig.getManagedLedgerMaxEntriesPerLedger(), 25);
    Assert.assertEquals(serviceConfig.getManagedLedgerCursorMaxEntriesPerLedger(), 50);
    Assert.assertTrue(serviceConfig.isClientLibraryVersionCheckAllowUnversioned());
    Assert.assertTrue(serviceConfig.isClientLibraryVersionCheckEnabled());
    Assert.assertEquals(serviceConfig.getReplicationConnectionsPerBroker(), 12);
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Method(java.lang.reflect.Method) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 3 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class PulsarBrokerStarterTest method testLoadBalancerConfig.

/**
     * Tests the private static <code>loadConfig</code> method of {@link PulsarBrokerStarter} class: verifies (1) if the
     * method returns a non-null {@link ServiceConfiguration} instance where all required settings are filled in and (2)
     * if the property variables inside the given property file are correctly referred to that returned object.
     */
@Test
public void testLoadBalancerConfig() throws SecurityException, NoSuchMethodException, IOException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    File testConfigFile = new File("tmp." + System.currentTimeMillis() + ".properties");
    if (testConfigFile.exists()) {
        testConfigFile.delete();
    }
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(testConfigFile)));
    printWriter.println("zookeeperServers=z1.example.com,z2.example.com,z3.example.com");
    printWriter.println("statusFilePath=/usr/share/pulsar_broker/status.html");
    printWriter.println("clusterName=test");
    printWriter.println("managedLedgerDefaultEnsembleSize=1");
    printWriter.println("managedLedgerDefaultWriteQuorum=1");
    printWriter.println("managedLedgerDefaultAckQuorum=1");
    printWriter.println("loadBalancerEnabled=false");
    printWriter.println("loadBalancerHostUsageCheckIntervalMinutes=4");
    printWriter.println("loadBalancerReportUpdateThresholdPercentage=15");
    printWriter.println("loadBalancerReportUpdateMaxIntervalMinutes=20");
    printWriter.println("loadBalancerBrokerOverloadedThresholdPercentage=80");
    printWriter.println("loadBalancerBrokerUnderloadedThresholdPercentage=40");
    printWriter.println("loadBalancerSheddingIntervalMinutes=8");
    printWriter.println("loadBalancerSheddingGracePeriodMinutes=29");
    printWriter.close();
    testConfigFile.deleteOnExit();
    Method targetMethod = PulsarBrokerStarter.class.getDeclaredMethod("loadConfig", String.class);
    targetMethod.setAccessible(true);
    Object returnValue = targetMethod.invoke(PulsarBrokerStarter.class, testConfigFile.getAbsolutePath());
    Assert.assertTrue(ServiceConfiguration.class.isInstance(returnValue));
    ServiceConfiguration serviceConfig = (ServiceConfiguration) returnValue;
    Assert.assertEquals(serviceConfig.isLoadBalancerEnabled(), false);
    Assert.assertEquals(serviceConfig.getLoadBalancerHostUsageCheckIntervalMinutes(), 4);
    Assert.assertEquals(serviceConfig.getLoadBalancerReportUpdateThresholdPercentage(), 15);
    Assert.assertEquals(serviceConfig.getLoadBalancerReportUpdateMaxIntervalMinutes(), 20);
    Assert.assertEquals(serviceConfig.getLoadBalancerBrokerOverloadedThresholdPercentage(), 80);
    Assert.assertEquals(serviceConfig.getLoadBalancerBrokerUnderloadedThresholdPercentage(), 40);
    Assert.assertEquals(serviceConfig.getLoadBalancerSheddingIntervalMinutes(), 8);
    Assert.assertEquals(serviceConfig.getLoadBalancerSheddingGracePeriodMinutes(), 29);
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Method(java.lang.reflect.Method) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 4 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class PulsarBrokerStarterTest method testLoadConfig.

/**
     * Tests the private static <code>loadConfig</code> method of {@link PulsarBrokerStarter} class: verifies (1) if the
     * method returns a non-null {@link ServiceConfiguration} instance where all required settings are filled in and (2)
     * if the property variables inside the given property file are correctly referred to that returned object.
     */
@Test
public void testLoadConfig() throws SecurityException, NoSuchMethodException, IOException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    File testConfigFile = new File("tmp." + System.currentTimeMillis() + ".properties");
    if (testConfigFile.exists()) {
        testConfigFile.delete();
    }
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(testConfigFile)));
    printWriter.println("zookeeperServers=z1.example.com,z2.example.com,z3.example.com");
    printWriter.println("globalZookeeperServers=gz1.example.com,gz2.example.com,gz3.example.com/foo");
    printWriter.println("brokerDeleteInactiveTopicsEnabled=false");
    printWriter.println("statusFilePath=/tmp/status.html");
    printWriter.println("managedLedgerDefaultEnsembleSize=1");
    printWriter.println("managedLedgerDefaultWriteQuorum=1");
    printWriter.println("managedLedgerDefaultAckQuorum=1");
    printWriter.println("managedLedgerMaxEntriesPerLedger=25");
    printWriter.println("managedLedgerCursorMaxEntriesPerLedger=50");
    printWriter.println("managedLedgerCursorRolloverTimeInSeconds=3000");
    printWriter.println("bookkeeperClientHealthCheckEnabled=true");
    printWriter.println("bookkeeperClientHealthCheckErrorThresholdPerInterval=5");
    printWriter.println("bookkeeperClientRackawarePolicyEnabled=true");
    printWriter.println("bookkeeperClientIsolationGroups=group1,group2");
    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("clientLibraryVersionCheckEnabled=true");
    printWriter.println("clientLibraryVersionCheckAllowUnversioned=true");
    printWriter.println("managedLedgerMinLedgerRolloverTimeMinutes=34");
    printWriter.println("managedLedgerMaxLedgerRolloverTimeMinutes=34");
    printWriter.println("brokerServicePort=7777");
    printWriter.println("managedLedgerDefaultMarkDeleteRateLimit=5.0");
    printWriter.println("replicationProducerQueueSize=50");
    printWriter.println("bookkeeperClientTimeoutInSeconds=12345");
    printWriter.println("bookkeeperClientSpeculativeReadTimeoutInMillis=3000");
    printWriter.close();
    testConfigFile.deleteOnExit();
    Method targetMethod = PulsarBrokerStarter.class.getDeclaredMethod("loadConfig", String.class);
    targetMethod.setAccessible(true);
    Object returnValue = targetMethod.invoke(PulsarBrokerStarter.class, testConfigFile.getAbsolutePath());
    Assert.assertTrue(ServiceConfiguration.class.isInstance(returnValue));
    ServiceConfiguration serviceConfig = (ServiceConfiguration) returnValue;
    Assert.assertEquals(serviceConfig.getZookeeperServers(), "z1.example.com,z2.example.com,z3.example.com");
    Assert.assertEquals(serviceConfig.getGlobalZookeeperServers(), "gz1.example.com,gz2.example.com,gz3.example.com/foo");
    Assert.assertFalse(serviceConfig.isBrokerDeleteInactiveTopicsEnabled());
    Assert.assertEquals(serviceConfig.getStatusFilePath(), "/tmp/status.html");
    Assert.assertEquals(serviceConfig.getBacklogQuotaDefaultLimitGB(), 18);
    Assert.assertEquals(serviceConfig.getClusterName(), "usc");
    Assert.assertEquals(serviceConfig.getBrokerClientAuthenticationPlugin(), "test.xyz.client.auth.plugin");
    Assert.assertEquals(serviceConfig.getBrokerClientAuthenticationParameters(), "role:my-role");
    Assert.assertEquals(serviceConfig.getSuperUserRoles(), Sets.newHashSet("appid1", "appid2"));
    Assert.assertEquals(serviceConfig.getManagedLedgerCursorRolloverTimeInSeconds(), 3000);
    Assert.assertEquals(serviceConfig.getManagedLedgerMaxEntriesPerLedger(), 25);
    Assert.assertEquals(serviceConfig.getManagedLedgerCursorMaxEntriesPerLedger(), 50);
    Assert.assertTrue(serviceConfig.isClientLibraryVersionCheckAllowUnversioned());
    Assert.assertTrue(serviceConfig.isClientLibraryVersionCheckEnabled());
    Assert.assertEquals(serviceConfig.getManagedLedgerMinLedgerRolloverTimeMinutes(), 34);
    Assert.assertEquals(serviceConfig.isBacklogQuotaCheckEnabled(), true);
    Assert.assertEquals(serviceConfig.getManagedLedgerDefaultMarkDeleteRateLimit(), 5.0);
    Assert.assertEquals(serviceConfig.getReplicationProducerQueueSize(), 50);
    Assert.assertEquals(serviceConfig.isReplicationMetricsEnabled(), false);
    Assert.assertEquals(serviceConfig.isBookkeeperClientHealthCheckEnabled(), true);
    Assert.assertEquals(serviceConfig.getBookkeeperClientHealthCheckErrorThresholdPerInterval(), 5);
    Assert.assertEquals(serviceConfig.isBookkeeperClientRackawarePolicyEnabled(), true);
    Assert.assertEquals(serviceConfig.getBookkeeperClientIsolationGroups(), "group1,group2");
    Assert.assertEquals(serviceConfig.getBookkeeperClientSpeculativeReadTimeoutInMillis(), 3000);
    Assert.assertEquals(serviceConfig.getBookkeeperClientTimeoutInSeconds(), 12345);
}
Also used : ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Method(java.lang.reflect.Method) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 5 with ServiceConfiguration

use of com.yahoo.pulsar.broker.ServiceConfiguration in project pulsar by yahoo.

the class AdminApiTest method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    conf.setLoadBalancerEnabled(true);
    super.internalSetup();
    bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
    // create otherbroker to test redirect on calls that need
    // namespace ownership
    ServiceConfiguration otherconfig = new ServiceConfiguration();
    otherconfig.setBrokerServicePort(SECONDARY_BROKER_PORT);
    otherconfig.setWebServicePort(SECONDARY_BROKER_WEBSERVICE_PORT);
    otherconfig.setLoadBalancerEnabled(false);
    otherconfig.setClusterName("test");
    otherPulsar = startBroker(otherconfig);
    otheradmin = new PulsarAdmin(new URL("http://127.0.0.1" + ":" + SECONDARY_BROKER_WEBSERVICE_PORT), (Authentication) null);
    // Setup namespaces
    admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
    PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
    admin.properties().createProperty("prop-xyz", propertyAdmin);
    admin.namespaces().createNamespace("prop-xyz/use/ns1");
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) Authentication(com.yahoo.pulsar.client.api.Authentication) NamespaceBundleFactory(com.yahoo.pulsar.common.naming.NamespaceBundleFactory) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)36 PulsarService (com.yahoo.pulsar.broker.PulsarService)18 Test (org.testng.annotations.Test)15 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)8 BeforeMethod (org.testng.annotations.BeforeMethod)8 AuthenticationService (com.yahoo.pulsar.broker.authentication.AuthenticationService)7 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)7 URL (java.net.URL)7 PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)6 Authentication (com.yahoo.pulsar.client.api.Authentication)6 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)6 Field (java.lang.reflect.Field)6 ConfigurationCacheService (com.yahoo.pulsar.broker.cache.ConfigurationCacheService)5 NamespaceService (com.yahoo.pulsar.broker.namespace.NamespaceService)5 Policies (com.yahoo.pulsar.common.policies.data.Policies)5 LocalBookkeeperEnsemble (com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble)5 InetSocketAddress (java.net.InetSocketAddress)5 URI (java.net.URI)5 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)5 AuthorizationManager (com.yahoo.pulsar.broker.authorization.AuthorizationManager)4