Skip to content

Commit

Permalink
Make broker module gradually conform the checkstyle (apache#8592)
Browse files Browse the repository at this point in the history
  • Loading branch information
Renkai authored Dec 1, 2020
1 parent 4d8974d commit fb61a0f
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 284 deletions.
151 changes: 0 additions & 151 deletions buildtools/src/main/resources/pulsar/checkstyle-pulsar-broker.xml

This file was deleted.

6 changes: 6 additions & 0 deletions buildtools/src/main/resources/pulsar/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<!-- suppress all checks in the copied code -->
<suppress checks=".*" files=".+[\\/]com[\\/]scurrilous[\\/]circe[\\/].+\.java"/>

<!-- TODO: gradually delete below lines to make the whole project conform the checkstyle rule -->
<suppress checks=".*" files="MLDataFormats.java"/>
<suppress checks=".*" files="BitSetRecyclable.java"/>
<suppress checks=".*" files="Schema.java"/>
Expand All @@ -47,4 +48,9 @@
<suppress checks="ConstantName" files="MessageId.java"/>
<suppress checks="MethodName" files="TopicsImpl.java"/>
<suppress checks="MemberName" files="TopicsImpl.java"/>
<suppress checks="ImportOrder" files="src/main/java/org/apache/pulsar/common/.*.java"/>
<suppress checks="ImportOrder" files="src/main/java/org/apache/pulsar/client/.*.java"/>
<suppress checks="ImportOrder" files="src/main/java/org/apache/pulsar/transaction/.*.java"/>
<suppress checks=".*" files="src/main/java/org/apache/pulsar/broker/.*.java"/>
<suppress checks=".*" files="src/main/java/org/apache/pulsar/compaction/.*.java"/>
</suppressions>
2 changes: 1 addition & 1 deletion pulsar-broker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
<id>check-style</id>
<phase>verify</phase>
<configuration>
<configLocation>../buildtools/src/main/resources/pulsar/checkstyle-pulsar-broker.xml</configLocation>
<configLocation>../buildtools/src/main/resources/pulsar/checkstyle.xml</configLocation>
<suppressionsLocation>../buildtools/src/main/resources/pulsar/suppressions.xml</suppressionsLocation>
<encoding>UTF-8</encoding>
<excludes>**/proto/*</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,26 @@ private static ServiceConfiguration loadConfig(String configFile) throws Excepti
@VisibleForTesting
private static class StarterArguments {
@Parameter(names = {"-c", "--broker-conf"}, description = "Configuration file for Broker")
private String brokerConfigFile = Paths.get("").toAbsolutePath().normalize().toString() + "/conf/broker.conf";
private String brokerConfigFile =
Paths.get("").toAbsolutePath().normalize().toString() + "/conf/broker.conf";

@Parameter(names = {"-rb", "--run-bookie"}, description = "Run Bookie together with Broker")
private boolean runBookie = false;

@Parameter(names = {"-ra", "--run-bookie-autorecovery"}, description = "Run Bookie Autorecovery together with broker")
@Parameter(names = {"-ra", "--run-bookie-autorecovery"},
description = "Run Bookie Autorecovery together with broker")
private boolean runBookieAutoRecovery = false;

@Parameter(names = {"-bc", "--bookie-conf"}, description = "Configuration file for Bookie")
private String bookieConfigFile = Paths.get("").toAbsolutePath().normalize().toString() + "/conf/bookkeeper.conf";
private String bookieConfigFile =
Paths.get("").toAbsolutePath().normalize().toString() + "/conf/bookkeeper.conf";

@Parameter(names = {"-rfw", "--run-functions-worker"}, description = "Run functions worker with Broker")
private boolean runFunctionsWorker = false;

@Parameter(names = {"-fwc", "--functions-worker-conf"}, description = "Configuration file for Functions Worker")
private String fnWorkerConfigFile = Paths.get("").toAbsolutePath().normalize().toString() + "/conf/functions_worker.yml";
private String fnWorkerConfigFile =
Paths.get("").toAbsolutePath().normalize().toString() + "/conf/functions_worker.yml";

@Parameter(names = {"-h", "--help"}, description = "Show this help message")
private boolean help = false;
Expand Down Expand Up @@ -151,13 +155,17 @@ private static class BrokerStarter {
throw new IllegalArgumentException("Max message size need smaller than jvm directMemory");
}

if (!NamespaceBundleSplitAlgorithm.availableAlgorithms.containsAll(brokerConfig.getSupportedNamespaceBundleSplitAlgorithms())) {
throw new IllegalArgumentException("The given supported namespace bundle split algorithm has unavailable algorithm. " +
"Available algorithms are " + NamespaceBundleSplitAlgorithm.availableAlgorithms);
if (!NamespaceBundleSplitAlgorithm.AVAILABLE_ALGORITHMS.containsAll(
brokerConfig.getSupportedNamespaceBundleSplitAlgorithms())) {
throw new IllegalArgumentException(
"The given supported namespace bundle split algorithm has unavailable algorithm. "
+ "Available algorithms are " + NamespaceBundleSplitAlgorithm.AVAILABLE_ALGORITHMS);
}

if (!brokerConfig.getSupportedNamespaceBundleSplitAlgorithms().contains(brokerConfig.getDefaultNamespaceBundleSplitAlgorithm())) {
throw new IllegalArgumentException("Supported namespace bundle split algorithms must contains the default namespace bundle split algorithm");
if (!brokerConfig.getSupportedNamespaceBundleSplitAlgorithms().contains(
brokerConfig.getDefaultNamespaceBundleSplitAlgorithm())) {
throw new IllegalArgumentException("Supported namespace bundle split algorithms "
+ "must contains the default namespace bundle split algorithm");
}

// init functions worker
Expand Down Expand Up @@ -193,7 +201,8 @@ private static class BrokerStarter {

// client in worker will use this config to authenticate with broker
workerConfig.setBrokerClientAuthenticationPlugin(brokerConfig.getBrokerClientAuthenticationPlugin());
workerConfig.setBrokerClientAuthenticationParameters(brokerConfig.getBrokerClientAuthenticationParameters());
workerConfig.setBrokerClientAuthenticationParameters(
brokerConfig.getBrokerClientAuthenticationParameters());

// inherit super users
workerConfig.setSuperUserRoles(brokerConfig.getSuperUserRoles());
Expand All @@ -214,13 +223,13 @@ private static class BrokerStarter {

// if no argument to run bookie in cmd line, read from pulsar config
if (!argsContains(args, "-rb") && !argsContains(args, "--run-bookie")) {
checkState(starterArguments.runBookie == false,
"runBookie should be false if has no argument specified");
checkState(!starterArguments.runBookie,
"runBookie should be false if has no argument specified");
starterArguments.runBookie = brokerConfig.isEnableRunBookieTogether();
}
if (!argsContains(args, "-ra") && !argsContains(args, "--run-bookie-autorecovery")) {
checkState(starterArguments.runBookieAutoRecovery == false,
"runBookieAutoRecovery should be false if has no argument specified");
checkState(!starterArguments.runBookieAutoRecovery,
"runBookieAutoRecovery should be false if has no argument specified");
starterArguments.runBookieAutoRecovery = brokerConfig.isEnableRunBookieAutoRecoveryTogether();
}

Expand All @@ -246,7 +255,8 @@ && isBlank(starterArguments.bookieConfigFile)) {
if (starterArguments.runBookie) {
checkNotNull(bookieConfig, "No ServerConfiguration for Bookie");
checkNotNull(bookieStatsProvider, "No Stats Provider for Bookie");
bookieServer = new BookieServer(bookieConfig, bookieStatsProvider.getStatsLogger(""), BookieServiceInfo.NO_INFO);
bookieServer = new BookieServer(
bookieConfig, bookieStatsProvider.getStatsLogger(""), BookieServiceInfo.NO_INFO);
} else {
bookieServer = null;
}
Expand Down Expand Up @@ -323,7 +333,9 @@ public void shutdown() {
public static void main(String[] args) throws Exception {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS");
Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> {
System.out.println(String.format("%s [%s] error Uncaught exception in thread %s: %s", dateFormat.format(new Date()), thread.getContextClassLoader(), thread.getName(), exception.getMessage()));
System.out.println(String.format("%s [%s] error Uncaught exception in thread %s: %s",
dateFormat.format(new Date()), thread.getContextClassLoader(),
thread.getName(), exception.getMessage()));
});

BrokerStarter starter = new BrokerStarter(args);
Expand Down
Loading

0 comments on commit fb61a0f

Please sign in to comment.