Skip to content

Commit d890396

Browse files
abmodideepakdamri
authored andcommitted
HADOOP-16093. Move DurationInfo from hadoop-aws to hadoop-common org.apache.hadoop.util.
Contributed by Abhishek Modi
1 parent 01b6239 commit d890396

File tree

17 files changed

+85
-23
lines changed

17 files changed

+85
-23
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/DurationInfo.java renamed to hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/DurationInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
* limitations under the License.
1717
*/
1818

19-
package org.apache.hadoop.fs.s3a.commit;
19+
package org.apache.hadoop.util;
2020

2121
import org.slf4j.Logger;
2222

2323
import org.apache.hadoop.classification.InterfaceAudience;
24+
import org.apache.hadoop.classification.InterfaceStability;
2425

2526
/**
2627
* A duration with logging of final state at info or debug
@@ -29,7 +30,8 @@
2930
* duration automatically logged.
3031
*/
3132
@InterfaceAudience.Private
32-
public class DurationInfo extends Duration
33+
@InterfaceStability.Unstable
34+
public class DurationInfo extends OperationDuration
3335
implements AutoCloseable {
3436
private final String text;
3537

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/Duration.java renamed to hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/OperationDuration.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,22 @@
1616
* limitations under the License.
1717
*/
1818

19-
package org.apache.hadoop.fs.s3a.commit;
19+
package org.apache.hadoop.util;
20+
21+
import org.apache.hadoop.classification.InterfaceAudience;
22+
import org.apache.hadoop.classification.InterfaceStability;
2023

2124
/**
2225
* Little duration counter.
2326
*/
24-
public class Duration {
27+
@InterfaceAudience.Private
28+
@InterfaceStability.Unstable
29+
public class OperationDuration {
2530

2631
private final long started;
2732
private long finished;
2833

29-
public Duration() {
34+
public OperationDuration() {
3035
started = time();
3136
finished = started;
3237
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.util;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
/**
26+
* The class to test DurationInfo.
27+
*/
28+
public class TestDurationInfo {
29+
private final Logger log = LoggerFactory.getLogger(TestDurationInfo.class);
30+
31+
@Test
32+
public void testDurationInfoCreation() throws Exception {
33+
DurationInfo info = new DurationInfo(log, "test");
34+
Assert.assertTrue(info.value() >= 0);
35+
Thread.sleep(1000);
36+
info.finished();
37+
Assert.assertTrue(info.value() > 0);
38+
}
39+
40+
@Test
41+
public void testDurationInfoWithMultipleClose() throws Exception {
42+
DurationInfo info = new DurationInfo(log, "test");
43+
Thread.sleep(1000);
44+
info.close();
45+
info.close();
46+
Assert.assertTrue(info.value() > 0);
47+
}
48+
49+
@Test(expected = NullPointerException.class)
50+
public void testDurationInfoCreationWithNullMsg() {
51+
DurationInfo info = new DurationInfo(log, null);
52+
info.close();
53+
}
54+
}

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/WriteOperationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
import org.apache.hadoop.classification.InterfaceAudience;
4949
import org.apache.hadoop.classification.InterfaceStability;
5050
import org.apache.hadoop.fs.Path;
51-
import org.apache.hadoop.fs.s3a.commit.DurationInfo;
5251
import org.apache.hadoop.fs.s3a.select.SelectBinding;
52+
import org.apache.hadoop.util.DurationInfo;
5353

5454
import static com.google.common.base.Preconditions.checkArgument;
5555
import static com.google.common.base.Preconditions.checkNotNull;

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/auth/delegation/AbstractDelegationTokenBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
import org.apache.hadoop.fs.s3a.AWSCredentialProviderList;
3131
import org.apache.hadoop.fs.s3a.S3AFileSystem;
3232
import org.apache.hadoop.fs.s3a.auth.RoleModel;
33-
import org.apache.hadoop.fs.s3a.commit.DurationInfo;
3433
import org.apache.hadoop.io.Text;
3534
import org.apache.hadoop.security.token.SecretManager;
3635
import org.apache.hadoop.security.token.Token;
36+
import org.apache.hadoop.util.DurationInfo;
3737

3838
import static java.util.Objects.requireNonNull;
3939
import static org.apache.hadoop.fs.s3a.auth.delegation.DelegationConstants.DURATION_LOG_AT_INFO;

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/auth/delegation/S3ADelegationTokens.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
import org.apache.hadoop.fs.s3a.S3AFileSystem;
3838
import org.apache.hadoop.fs.s3a.S3AInstrumentation;
3939
import org.apache.hadoop.fs.s3a.auth.RoleModel;
40-
import org.apache.hadoop.fs.s3a.commit.DurationInfo;
4140
import org.apache.hadoop.io.Text;
4241
import org.apache.hadoop.security.Credentials;
4342
import org.apache.hadoop.security.UserGroupInformation;
4443
import org.apache.hadoop.security.token.Token;
4544
import org.apache.hadoop.service.ServiceOperations;
45+
import org.apache.hadoop.util.DurationInfo;
4646

4747
import static com.google.common.base.Preconditions.checkArgument;
4848
import static com.google.common.base.Preconditions.checkState;

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/AbstractS3ACommitter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.hadoop.mapreduce.TaskAttemptContext;
4949
import org.apache.hadoop.mapreduce.lib.output.PathOutputCommitter;
5050
import org.apache.hadoop.net.NetUtils;
51+
import org.apache.hadoop.util.DurationInfo;
5152

5253
import static org.apache.hadoop.fs.s3a.Invoker.ignoreIOExceptions;
5354
import static org.apache.hadoop.fs.s3a.S3AUtils.*;

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/magic/MagicS3GuardCommitter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import org.apache.hadoop.fs.s3a.commit.CommitOperations;
3636
import org.apache.hadoop.fs.s3a.commit.CommitConstants;
3737
import org.apache.hadoop.fs.s3a.commit.CommitUtilsWithMR;
38-
import org.apache.hadoop.fs.s3a.commit.DurationInfo;
3938
import org.apache.hadoop.fs.s3a.commit.files.PendingSet;
4039
import org.apache.hadoop.fs.s3a.commit.files.SinglePendingCommit;
4140
import org.apache.hadoop.mapreduce.JobContext;
4241
import org.apache.hadoop.mapreduce.TaskAttemptContext;
4342
import org.apache.hadoop.mapreduce.TaskAttemptID;
43+
import org.apache.hadoop.util.DurationInfo;
4444

4545
import static org.apache.hadoop.fs.s3a.S3AUtils.*;
4646
import static org.apache.hadoop.fs.s3a.commit.CommitUtils.*;

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/commit/staging/StagingCommitter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.apache.hadoop.fs.s3a.S3AFileSystem;
4242
import org.apache.hadoop.fs.s3a.commit.AbstractS3ACommitter;
4343
import org.apache.hadoop.fs.s3a.commit.CommitConstants;
44-
import org.apache.hadoop.fs.s3a.commit.DurationInfo;
4544
import org.apache.hadoop.fs.s3a.commit.InternalCommitterConstants;
4645
import org.apache.hadoop.fs.s3a.commit.Tasks;
4746
import org.apache.hadoop.fs.s3a.commit.files.PendingSet;
@@ -50,6 +49,7 @@
5049
import org.apache.hadoop.mapreduce.JobID;
5150
import org.apache.hadoop.mapreduce.TaskAttemptContext;
5251
import org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter;
52+
import org.apache.hadoop.util.DurationInfo;
5353

5454
import static com.google.common.base.Preconditions.*;
5555
import static org.apache.hadoop.fs.s3a.Constants.*;

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/select/SelectTool.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
import org.apache.hadoop.fs.Path;
4242
import org.apache.hadoop.fs.impl.FutureIOSupport;
4343
import org.apache.hadoop.fs.s3a.S3AFileSystem;
44-
import org.apache.hadoop.fs.s3a.commit.Duration;
45-
import org.apache.hadoop.fs.s3a.commit.DurationInfo;
4644
import org.apache.hadoop.fs.s3a.s3guard.S3GuardTool;
4745
import org.apache.hadoop.fs.shell.CommandFormat;
46+
import org.apache.hadoop.util.DurationInfo;
4847
import org.apache.hadoop.util.ExitUtil;
48+
import org.apache.hadoop.util.OperationDuration;
4949

5050
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
5151
import static org.apache.hadoop.io.IOUtils.cleanupWithLogger;
@@ -102,7 +102,7 @@ public class SelectTool extends S3GuardTool {
102102

103103
static final String SELECT_IS_DISABLED = "S3 Select is disabled";
104104

105-
private Duration selectDuration;
105+
private OperationDuration selectDuration;
106106

107107
private long bytesRead;
108108

@@ -130,7 +130,7 @@ public String getUsage() {
130130
return USAGE;
131131
}
132132

133-
public Duration getSelectDuration() {
133+
public OperationDuration getSelectDuration() {
134134
return selectDuration;
135135
}
136136

@@ -241,7 +241,7 @@ public int run(String[] args, PrintStream out)
241241
}
242242
linesRead = 0;
243243

244-
selectDuration = new Duration();
244+
selectDuration = new OperationDuration();
245245

246246
// open and scan the stream.
247247
final FutureDataInputStreamBuilder builder = fs.openFile(path)

0 commit comments

Comments
 (0)