Skip to content

Commit b51fb54

Browse files
committed
fix error when no dep dropwizard java.lang.NoClassDefFoundError: com/codahale/metrics/Reservoir
1 parent 160297d commit b51fb54

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/server/ZooKeeperServerMain.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.CountDownLatch;
2323
import java.util.concurrent.TimeUnit;
2424
import javax.management.JMException;
25+
2526
import org.apache.yetus.audience.InterfaceAudience;
2627
import org.apache.zookeeper.audit.ZKAuditProvider;
2728
import org.apache.zookeeper.jmx.ManagedUtil;
@@ -115,6 +116,7 @@ protected void initializeAndRun(String[] args) throws ConfigException, IOExcepti
115116

116117
/**
117118
* Run from a ServerConfig.
119+
*
118120
* @param config ServerConfig to use.
119121
* @throws IOException
120122
* @throws AdminServerException
@@ -125,12 +127,13 @@ public void runFromConfig(ServerConfig config) throws IOException, AdminServerEx
125127
try {
126128
try {
127129
metricsProvider = MetricsProviderBootstrap.startMetricsProvider(
128-
config.getMetricsProviderClassName(),
129-
config.getMetricsProviderConfiguration());
130+
config.getMetricsProviderClassName(),
131+
config.getMetricsProviderConfiguration());
130132
} catch (MetricsProviderLifeCycleException error) {
131133
throw new IOException("Cannot boot MetricsProvider " + config.getMetricsProviderClassName(), error);
132134
}
133-
ServerMetrics.metricsProviderInitialized(metricsProvider);
135+
136+
metricsProviderInitialized();
134137
ProviderRegistry.initialize();
135138
// Note that this thread isn't going to be doing anything else,
136139
// so rather than spawning another thread, we will just call
@@ -169,11 +172,11 @@ public void runFromConfig(ServerConfig config) throws IOException, AdminServerEx
169172
}
170173

171174
containerManager = new ContainerManager(
172-
zkServer.getZKDatabase(),
173-
zkServer.firstProcessor,
174-
Integer.getInteger("znode.container.checkIntervalMs", (int) TimeUnit.MINUTES.toMillis(1)),
175-
Integer.getInteger("znode.container.maxPerMinute", 10000),
176-
Long.getLong("znode.container.maxNeverUsedIntervalMs", 0)
175+
zkServer.getZKDatabase(),
176+
zkServer.firstProcessor,
177+
Integer.getInteger("znode.container.checkIntervalMs", (int) TimeUnit.MINUTES.toMillis(1)),
178+
Integer.getInteger("znode.container.maxPerMinute", 10000),
179+
Long.getLong("znode.container.maxNeverUsedIntervalMs", 0)
177180
);
178181
containerManager.start();
179182
ZKAuditProvider.addZKStartStopAuditLog();
@@ -210,6 +213,18 @@ public void runFromConfig(ServerConfig config) throws IOException, AdminServerEx
210213
}
211214
}
212215

216+
private void metricsProviderInitialized() {
217+
try {
218+
ServerMetrics.metricsProviderInitialized(metricsProvider);
219+
} catch (Exception e) {
220+
if (e instanceof ClassNotFoundException) {
221+
LOG.warn("Metrics provider not found, metrics will not be reported");
222+
return;
223+
}
224+
throw e;
225+
}
226+
}
227+
213228
/**
214229
* Shutdown the serving instance
215230
*/

0 commit comments

Comments
 (0)