Skip to content

Commit 57bc479

Browse files
slfan1989HarshitGupta11
authored andcommitted
HADOOP-18302. Remove WhiteBox in hadoop-common module. (apache#4457)
Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
1 parent 4368cad commit 57bc479

File tree

16 files changed

+420
-391
lines changed

16 files changed

+420
-391
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,4 +1326,9 @@ public boolean hasPathCapability(final Path path, final String capability)
13261326
return super.hasPathCapability(path, capability);
13271327
}
13281328
}
1329+
1330+
@VisibleForTesting
1331+
static void setUseDeprecatedFileStatus(boolean useDeprecatedFileStatus) {
1332+
RawLocalFileSystem.useDeprecatedFileStatus = useDeprecatedFileStatus;
1333+
}
13291334
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,4 +1967,8 @@ HttpServer2Metrics getMetrics() {
19671967
return metrics;
19681968
}
19691969

1970+
@VisibleForTesting
1971+
List<ServerConnector> getListeners() {
1972+
return listeners;
1973+
}
19701974
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Server.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4111,4 +4111,18 @@ public synchronized void run() {
41114111
}
41124112
}
41134113

4114+
@VisibleForTesting
4115+
CallQueueManager<Call> getCallQueue() {
4116+
return callQueue;
4117+
}
4118+
4119+
@VisibleForTesting
4120+
void setCallQueue(CallQueueManager<Call> callQueue) {
4121+
this.callQueue = callQueue;
4122+
}
4123+
4124+
@VisibleForTesting
4125+
void setRpcRequestClass(Class<? extends Writable> rpcRequestClass) {
4126+
this.rpcRequestClass = rpcRequestClass;
4127+
}
41144128
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/metrics/RpcMetrics.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,9 @@ public double getDeferredRpcProcessingStdDev() {
364364
public MetricsTag getTag(String tagName) {
365365
return registry.getTag(tagName);
366366
}
367+
368+
@VisibleForTesting
369+
public MutableCounterLong getRpcAuthorizationSuccesses() {
370+
return rpcAuthorizationSuccesses;
371+
}
367372
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsRecordImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222

2323
import static org.apache.hadoop.util.Preconditions.*;
2424

25+
import org.apache.hadoop.classification.VisibleForTesting;
2526
import org.apache.hadoop.metrics2.MetricsInfo;
2627
import org.apache.hadoop.metrics2.AbstractMetric;
2728
import org.apache.hadoop.metrics2.MetricsTag;
2829
import static org.apache.hadoop.metrics2.util.Contracts.*;
2930

30-
class MetricsRecordImpl extends AbstractMetricsRecord {
31+
@VisibleForTesting
32+
public class MetricsRecordImpl extends AbstractMetricsRecord {
3133
protected static final String DEFAULT_CONTEXT = "default";
3234

3335
private final long timestamp;

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java

Lines changed: 136 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.commons.configuration2.SubsetConfiguration;
2222
import org.apache.hadoop.classification.InterfaceAudience;
2323
import org.apache.hadoop.classification.InterfaceStability;
24+
import org.apache.hadoop.classification.VisibleForTesting;
2425
import org.apache.hadoop.metrics2.AbstractMetric;
2526
import org.apache.hadoop.metrics2.MetricsException;
2627
import org.apache.hadoop.metrics2.MetricsRecord;
@@ -37,171 +38,173 @@
3738
import java.nio.charset.StandardCharsets;
3839

3940
/**
40-
* A metrics sink that writes to a Graphite server
41+
* A metrics sink that writes to a Graphite server.
4142
*/
4243
@InterfaceAudience.Public
4344
@InterfaceStability.Evolving
4445
public class GraphiteSink implements MetricsSink, Closeable {
45-
private static final Logger LOG =
46-
LoggerFactory.getLogger(GraphiteSink.class);
47-
private static final String SERVER_HOST_KEY = "server_host";
48-
private static final String SERVER_PORT_KEY = "server_port";
49-
private static final String METRICS_PREFIX = "metrics_prefix";
50-
private String metricsPrefix = null;
51-
private Graphite graphite = null;
52-
53-
@Override
54-
public void init(SubsetConfiguration conf) {
55-
// Get Graphite host configurations.
56-
final String serverHost = conf.getString(SERVER_HOST_KEY);
57-
final int serverPort = Integer.parseInt(conf.getString(SERVER_PORT_KEY));
58-
59-
// Get Graphite metrics graph prefix.
60-
metricsPrefix = conf.getString(METRICS_PREFIX);
61-
if (metricsPrefix == null)
62-
metricsPrefix = "";
63-
64-
graphite = new Graphite(serverHost, serverPort);
65-
graphite.connect();
46+
private static final Logger LOG =
47+
LoggerFactory.getLogger(GraphiteSink.class);
48+
private static final String SERVER_HOST_KEY = "server_host";
49+
private static final String SERVER_PORT_KEY = "server_port";
50+
private static final String METRICS_PREFIX = "metrics_prefix";
51+
private String metricsPrefix = null;
52+
private Graphite graphite = null;
53+
54+
@Override
55+
public void init(SubsetConfiguration conf) {
56+
// Get Graphite host configurations.
57+
final String serverHost = conf.getString(SERVER_HOST_KEY);
58+
final int serverPort = Integer.parseInt(conf.getString(SERVER_PORT_KEY));
59+
60+
// Get Graphite metrics graph prefix.
61+
metricsPrefix = conf.getString(METRICS_PREFIX);
62+
if (metricsPrefix == null) {
63+
metricsPrefix = "";
6664
}
6765

68-
@Override
69-
public void putMetrics(MetricsRecord record) {
70-
StringBuilder lines = new StringBuilder();
71-
StringBuilder metricsPathPrefix = new StringBuilder();
72-
73-
// Configure the hierarchical place to display the graph.
74-
metricsPathPrefix.append(metricsPrefix).append(".")
75-
.append(record.context()).append(".").append(record.name());
76-
77-
for (MetricsTag tag : record.tags()) {
78-
if (tag.value() != null) {
79-
metricsPathPrefix.append(".")
80-
.append(tag.name())
81-
.append("=")
82-
.append(tag.value());
83-
}
84-
}
85-
86-
// The record timestamp is in milliseconds while Graphite expects an epoc time in seconds.
87-
long timestamp = record.timestamp() / 1000L;
66+
graphite = new Graphite(serverHost, serverPort);
67+
graphite.connect();
68+
}
69+
70+
@Override
71+
public void putMetrics(MetricsRecord record) {
72+
StringBuilder lines = new StringBuilder();
73+
StringBuilder metricsPathPrefix = new StringBuilder();
74+
75+
// Configure the hierarchical place to display the graph.
76+
metricsPathPrefix.append(metricsPrefix).append(".")
77+
.append(record.context()).append(".").append(record.name());
78+
79+
for (MetricsTag tag : record.tags()) {
80+
if (tag.value() != null) {
81+
metricsPathPrefix.append(".")
82+
.append(tag.name())
83+
.append("=")
84+
.append(tag.value());
85+
}
86+
}
8887

89-
// Collect datapoints.
90-
for (AbstractMetric metric : record.metrics()) {
91-
lines.append(
92-
metricsPathPrefix.toString() + "."
93-
+ metric.name().replace(' ', '.')).append(" ")
94-
.append(metric.value()).append(" ").append(timestamp)
95-
.append("\n");
96-
}
88+
// The record timestamp is in milliseconds while Graphite expects an epoc time in seconds.
89+
long timestamp = record.timestamp() / 1000L;
9790

98-
try {
99-
graphite.write(lines.toString());
100-
} catch (Exception e) {
101-
LOG.warn("Error sending metrics to Graphite", e);
102-
try {
103-
graphite.close();
104-
} catch (Exception e1) {
105-
throw new MetricsException("Error closing connection to Graphite", e1);
106-
}
107-
}
91+
// Collect datapoints.
92+
for (AbstractMetric metric : record.metrics()) {
93+
lines.append(metricsPathPrefix + "." + metric.name().replace(' ', '.')).append(" ")
94+
.append(metric.value()).append(" ").append(timestamp)
95+
.append("\n");
10896
}
10997

110-
@Override
111-
public void flush() {
98+
try {
99+
graphite.write(lines.toString());
100+
} catch (Exception e) {
101+
LOG.warn("Error sending metrics to Graphite.", e);
112102
try {
113-
graphite.flush();
114-
} catch (Exception e) {
115-
LOG.warn("Error flushing metrics to Graphite", e);
116-
try {
117-
graphite.close();
118-
} catch (Exception e1) {
119-
throw new MetricsException("Error closing connection to Graphite", e1);
120-
}
103+
graphite.close();
104+
} catch (Exception e1) {
105+
throw new MetricsException("Error closing connection to Graphite", e1);
121106
}
122107
}
123-
124-
@Override
125-
public void close() throws IOException {
126-
graphite.close();
108+
}
109+
110+
@Override
111+
public void flush() {
112+
try {
113+
graphite.flush();
114+
} catch (Exception e) {
115+
LOG.warn("Error flushing metrics to Graphite.", e);
116+
try {
117+
graphite.close();
118+
} catch (Exception e1) {
119+
throw new MetricsException("Error closing connection to Graphite.", e1);
120+
}
127121
}
122+
}
128123

129-
public static class Graphite {
130-
private final static int MAX_CONNECTION_FAILURES = 5;
124+
@Override
125+
public void close() throws IOException {
126+
graphite.close();
127+
}
131128

132-
private String serverHost;
133-
private int serverPort;
134-
private Writer writer = null;
135-
private Socket socket = null;
136-
private int connectionFailures = 0;
129+
public static class Graphite {
130+
private final static int MAX_CONNECTION_FAILURES = 5;
137131

138-
public Graphite(String serverHost, int serverPort) {
139-
this.serverHost = serverHost;
140-
this.serverPort = serverPort;
141-
}
132+
private String serverHost;
133+
private int serverPort;
134+
private Writer writer = null;
135+
private Socket socket = null;
136+
private int connectionFailures = 0;
142137

143-
public void connect() {
144-
if (isConnected()) {
145-
throw new MetricsException("Already connected to Graphite");
146-
}
147-
if (tooManyConnectionFailures()) {
148-
// return silently (there was ERROR in logs when we reached limit for the first time)
149-
return;
150-
}
151-
try {
138+
public Graphite(String serverHost, int serverPort) {
139+
this.serverHost = serverHost;
140+
this.serverPort = serverPort;
141+
}
142+
143+
public void connect() {
144+
if (isConnected()) {
145+
throw new MetricsException("Already connected to Graphite");
146+
}
147+
if (tooManyConnectionFailures()) {
148+
// return silently (there was ERROR in logs when we reached limit for the first time)
149+
return;
150+
}
151+
try {
152152
// Open a connection to Graphite server.
153-
socket = new Socket(serverHost, serverPort);
153+
socket = new Socket(serverHost, serverPort);
154154
writer = new OutputStreamWriter(socket.getOutputStream(),
155155
StandardCharsets.UTF_8);
156-
} catch (Exception e) {
157-
connectionFailures++;
158-
if (tooManyConnectionFailures()) {
159-
// first time when connection limit reached, report to logs
160-
LOG.error("Too many connection failures, would not try to connect again.");
161-
}
162-
throw new MetricsException("Error creating connection, "
163-
+ serverHost + ":" + serverPort, e);
156+
} catch (Exception e) {
157+
connectionFailures++;
158+
if (tooManyConnectionFailures()) {
159+
// first time when connection limit reached, report to logs
160+
LOG.error("Too many connection failures, would not try to connect again.");
164161
}
162+
throw new MetricsException("Error creating connection, " +
163+
serverHost + ":" + serverPort, e);
165164
}
165+
}
166166

167-
public void write(String msg) throws IOException {
168-
if (!isConnected()) {
169-
connect();
170-
}
171-
if (isConnected()) {
172-
writer.write(msg);
173-
}
167+
public void write(String msg) throws IOException {
168+
if (!isConnected()) {
169+
connect();
174170
}
175-
176-
public void flush() throws IOException {
177-
if (isConnected()) {
178-
writer.flush();
179-
}
171+
if (isConnected()) {
172+
writer.write(msg);
180173
}
174+
}
181175

182-
public boolean isConnected() {
183-
return socket != null && socket.isConnected() && !socket.isClosed();
176+
public void flush() throws IOException {
177+
if (isConnected()) {
178+
writer.flush();
184179
}
180+
}
185181

186-
public void close() throws IOException {
187-
try {
188-
if (writer != null) {
189-
writer.close();
190-
}
191-
} catch (IOException ex) {
192-
if (socket != null) {
193-
socket.close();
194-
}
195-
} finally {
196-
socket = null;
197-
writer = null;
198-
}
199-
}
182+
public boolean isConnected() {
183+
return socket != null && socket.isConnected() && !socket.isClosed();
184+
}
200185

201-
private boolean tooManyConnectionFailures() {
202-
return connectionFailures > MAX_CONNECTION_FAILURES;
186+
public void close() throws IOException {
187+
try {
188+
if (writer != null) {
189+
writer.close();
190+
}
191+
} catch (IOException ex) {
192+
if (socket != null) {
193+
socket.close();
194+
}
195+
} finally {
196+
socket = null;
197+
writer = null;
203198
}
199+
}
204200

201+
private boolean tooManyConnectionFailures() {
202+
return connectionFailures > MAX_CONNECTION_FAILURES;
205203
}
204+
}
206205

206+
@VisibleForTesting
207+
void setGraphite(Graphite graphite) {
208+
this.graphite = graphite;
209+
}
207210
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/StatsDSink.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.commons.configuration2.SubsetConfiguration;
2929
import org.apache.hadoop.classification.InterfaceAudience;
3030
import org.apache.hadoop.classification.InterfaceStability;
31+
import org.apache.hadoop.classification.VisibleForTesting;
3132
import org.apache.hadoop.metrics2.AbstractMetric;
3233
import org.apache.hadoop.metrics2.MetricType;
3334
import org.apache.hadoop.metrics2.MetricsException;
@@ -214,5 +215,8 @@ public void close() throws IOException {
214215
}
215216

216217
}
217-
218+
@VisibleForTesting
219+
void setStatsd(StatsD statsd) {
220+
this.statsd = statsd;
221+
}
218222
}

0 commit comments

Comments
 (0)