Skip to content

Commit dfed007

Browse files
Remove conflicts and refactor the code to use DeprecatedCliOption class
1 parent 0313e72 commit dfed007

22 files changed

Lines changed: 407 additions & 667 deletions

File tree

hadoop-hdds/cli-common/src/main/java/org/apache/hadoop/hdds/cli/DeprecatedCliOption.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.Objects;
2424

2525
/**
26-
* Emits warnings when deprecated multi-character short CLI options are used.
26+
* Emits warnings when deprecated CLI option aliases are used.
2727
*/
2828
public final class DeprecatedCliOption {
2929

@@ -47,6 +47,35 @@ private static Map<String, String> buildDeprecatedOptions() {
4747
options.put("-tact", "--transaction-apply-check-interval");
4848
options.put("-pct", "--prepare-check-interval");
4949
options.put("-pt", "--prepare-timeout");
50+
options.put("--accessId", "--access-id");
51+
options.put("--bufferSize", "--buffer-size");
52+
options.put("--column_family", "--column-family");
53+
options.put("--dnSchema", "--dn-schema");
54+
options.put("--expectedGeneration", "--expected-generation");
55+
options.put("--fileCount", "--file-count");
56+
options.put("--fileSize", "--file-size");
57+
options.put("--filterByFactor", "--filter-by-factor");
58+
options.put("--filterByState", "--filter-by-state");
59+
options.put("--keySize", "--key-size");
60+
options.put("--maxDatanodesPercentageToInvolvePerIteration",
61+
"--max-datanodes-percentage-to-involve-per-iteration");
62+
options.put("--maxSizeEnteringTargetInGB", "--max-size-entering-target-in-gb");
63+
options.put("--maxSizeLeavingSourceInGB", "--max-size-leaving-source-in-gb");
64+
options.put("--maxSizeToMovePerIterationInGB", "--max-size-to-move-per-iteration-in-gb");
65+
options.put("--nameLen", "--name-len");
66+
options.put("--newLeaderId", "--new-leader-id");
67+
options.put("--numOfBuckets", "--num-of-buckets");
68+
options.put("--numOfKeys", "--num-of-keys");
69+
options.put("--numOfThreads", "--num-of-threads");
70+
options.put("--numOfValidateThreads", "--num-of-validate-threads");
71+
options.put("--numOfVolumes", "--num-of-volumes");
72+
options.put("--onlyFileNames", "--only-file-names");
73+
options.put("--replicationFactor", "--replication-factor");
74+
options.put("--replicationType", "--replication-type");
75+
options.put("--scmHost", "--scm-host");
76+
options.put("--secretKey", "--secret");
77+
options.put("--segmentPath", "--segment-path");
78+
options.put("--validateWrites", "--validate-writes");
5079
return options;
5180
}
5281

hadoop-hdds/cli-common/src/main/java/org/apache/hadoop/hdds/cli/DeprecatedCliOptions.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerBalancerStartSubcommand.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -184,57 +184,8 @@ private Optional<Long> resolveMaxSizeLeavingSourceInGB() {
184184
return deprecatedMaxSizeLeavingSourceInGB;
185185
}
186186

187-
private void warnIfDeprecatedMaxDatanodesPercentageUsed() {
188-
if (deprecatedMaxDatanodesPercentage != null
189-
&& deprecatedMaxDatanodesPercentage.isPresent()
190-
&& (maxDatanodesPercentageToInvolvePerIteration == null
191-
|| !maxDatanodesPercentageToInvolvePerIteration.isPresent())) {
192-
System.err.println("warning: --maxDatanodesPercentageToInvolvePerIteration "
193-
+ "is deprecated, use --max-datanodes-percentage-to-involve-per-iteration "
194-
+ "instead.");
195-
}
196-
}
197-
198-
private void warnIfDeprecatedMaxSizeToMovePerIterationInGBUsed() {
199-
if (deprecatedMaxSizeToMovePerIterationInGB != null
200-
&& deprecatedMaxSizeToMovePerIterationInGB.isPresent()
201-
&& (maxSizeToMovePerIterationInGB == null
202-
|| !maxSizeToMovePerIterationInGB.isPresent())) {
203-
System.err.println("warning: --maxSizeToMovePerIterationInGB is deprecated, "
204-
+ "use --max-size-to-move-per-iteration-in-gb instead.");
205-
}
206-
}
207-
208-
private void warnIfDeprecatedMaxSizeEnteringTargetInGBUsed() {
209-
if (deprecatedMaxSizeEnteringTargetInGB != null
210-
&& deprecatedMaxSizeEnteringTargetInGB.isPresent()
211-
&& (maxSizeEnteringTargetInGB == null
212-
|| !maxSizeEnteringTargetInGB.isPresent())) {
213-
System.err.println("warning: --maxSizeEnteringTargetInGB is deprecated, "
214-
+ "use --max-size-entering-target-in-gb instead.");
215-
}
216-
}
217-
218-
private void warnIfDeprecatedMaxSizeLeavingSourceInGBUsed() {
219-
if (deprecatedMaxSizeLeavingSourceInGB != null
220-
&& deprecatedMaxSizeLeavingSourceInGB.isPresent()
221-
&& (maxSizeLeavingSourceInGB == null
222-
|| !maxSizeLeavingSourceInGB.isPresent())) {
223-
System.err.println("warning: --maxSizeLeavingSourceInGB is deprecated, "
224-
+ "use --max-size-leaving-source-in-gb instead.");
225-
}
226-
}
227-
228-
private void warnIfDeprecatedOptionsUsed() {
229-
warnIfDeprecatedMaxDatanodesPercentageUsed();
230-
warnIfDeprecatedMaxSizeToMovePerIterationInGBUsed();
231-
warnIfDeprecatedMaxSizeEnteringTargetInGBUsed();
232-
warnIfDeprecatedMaxSizeLeavingSourceInGBUsed();
233-
}
234-
235187
@Override
236188
public void execute(ScmClient scmClient) throws IOException {
237-
warnIfDeprecatedOptionsUsed();
238189
StartContainerBalancerResponseProto response = scmClient.
239190
startContainerBalancer(threshold, iterations,
240191
resolveMaxDatanodesPercentageToInvolvePerIteration(),

hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/pipeline/CreatePipelineSubcommand.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.hadoop.hdds.scm.cli.pipeline;
1919

2020
import java.io.IOException;
21-
import org.apache.hadoop.hdds.cli.DeprecatedCliOptions;
2221
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
2322
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
2423
import org.apache.hadoop.hdds.scm.cli.ScmSubcommand;
@@ -36,13 +35,9 @@
3635
versionProvider = HddsVersionProvider.class)
3736
public class CreatePipelineSubcommand extends ScmSubcommand {
3837

39-
@CommandLine.Spec
40-
private CommandLine.Model.CommandSpec spec;
41-
4238
@CommandLine.Option(
4339
names = {"-t", "--replication-type"},
4440
description = "Replication type is RATIS.",
45-
defaultValue = "RATIS",
4641
hidden = true
4742
)
4843
private HddsProtos.ReplicationType type;
@@ -55,8 +50,7 @@ public class CreatePipelineSubcommand extends ScmSubcommand {
5550

5651
@CommandLine.Option(
5752
names = {"-f", "--replication-factor"},
58-
description = "Replication factor for RATIS (ONE, THREE).",
59-
defaultValue = "ONE"
53+
description = "Replication factor for RATIS (ONE, THREE)."
6054
)
6155
private HddsProtos.ReplicationFactor factor;
6256

@@ -66,34 +60,30 @@ public class CreatePipelineSubcommand extends ScmSubcommand {
6660
@CommandLine.Option(names = "--replicationFactor", hidden = true)
6761
private HddsProtos.ReplicationFactor deprecatedReplicationFactor;
6862

69-
private HddsProtos.ReplicationType resolveReplicationType() {
70-
if (DeprecatedCliOptions.hasMatchedOption(spec, "--replicationType")) {
71-
return deprecatedReplicationType != null ? deprecatedReplicationType : type;
63+
private HddsProtos.ReplicationType getReplicationType() {
64+
if (type != null) {
65+
return type;
7266
}
73-
return type;
74-
}
75-
76-
private HddsProtos.ReplicationFactor resolveReplicationFactor() {
77-
if (DeprecatedCliOptions.hasMatchedOption(spec, "--replicationFactor")) {
78-
return deprecatedReplicationFactor != null ? deprecatedReplicationFactor : factor;
67+
if (deprecatedReplicationType != null) {
68+
return deprecatedReplicationType;
7969
}
80-
return factor;
70+
return HddsProtos.ReplicationType.RATIS;
8171
}
8272

83-
private void warnIfDeprecatedOptionsUsed() {
84-
DeprecatedCliOptions.warnIfDeprecatedUsedWithoutCanonical(
85-
"--replicationType", "--replication-type", spec,
86-
"--replication-type", "-t");
87-
DeprecatedCliOptions.warnIfDeprecatedUsedWithoutCanonical(
88-
"--replicationFactor", "--replication-factor", spec,
89-
"--replication-factor", "-f");
73+
private HddsProtos.ReplicationFactor getReplicationFactor() {
74+
if (factor != null) {
75+
return factor;
76+
}
77+
if (deprecatedReplicationFactor != null) {
78+
return deprecatedReplicationFactor;
79+
}
80+
return HddsProtos.ReplicationFactor.ONE;
9081
}
9182

9283
@Override
9384
public void execute(ScmClient scmClient) throws IOException {
94-
warnIfDeprecatedOptionsUsed();
95-
HddsProtos.ReplicationType resolvedType = resolveReplicationType();
96-
HddsProtos.ReplicationFactor resolvedFactor = resolveReplicationFactor();
85+
HddsProtos.ReplicationType resolvedType = getReplicationType();
86+
HddsProtos.ReplicationFactor resolvedFactor = getReplicationFactor();
9787
// Once we support creating EC containers/pipelines from the client, the
9888
// client should check if SCM is able to fulfil the request, and
9989
// understands an EcReplicationConfig. For that we also need to have SCM's

hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/pipeline/FilterPipelineOptions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class FilterPipelineOptions {
4444
defaultValue = "")
4545
private String replication;
4646

47-
4847
@CommandLine.Option(
4948
names = {"--filter-by-factor"},
5049
description = "[deprecated] Filter pipelines by factor (e.g. ONE, THREE) (implies RATIS replication type)")

hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/pipeline/ListPipelinesSubcommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ public void execute(ScmClient scmClient) throws IOException {
6363
if (replicationFilter.isPresent()) {
6464
stream = stream.filter(replicationFilter.get());
6565
}
66+
<<<<<<< HEAD
6667
if (!Strings.isNullOrEmpty(state)) {
68+
=======
69+
String effectiveState = getState();
70+
if (!Strings.isNullOrEmpty(effectiveState)) {
71+
>>>>>>> a71ff80348 (Remove conflicts and refactor the code to use DeprecatedCliOption class)
6772
stream = stream.filter(p -> p.getPipelineState().toString()
6873
.compareToIgnoreCase(state) == 0);
6974
}

hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/om/TransferOmLeaderSubCommand.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.hadoop.ozone.admin.om;
1919

2020
import java.util.concurrent.Callable;
21-
import org.apache.hadoop.hdds.cli.DeprecatedCliOptions;
2221
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
2322
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
2423
import picocli.CommandLine;
@@ -37,9 +36,6 @@ public class TransferOmLeaderSubCommand implements Callable<Void> {
3736
@CommandLine.Mixin
3837
private OmAddressOptions.OptionalServiceIdMixin omServiceOption;
3938

40-
@CommandLine.Spec
41-
private CommandLine.Model.CommandSpec spec;
42-
4339
@CommandLine.ArgGroup(multiplicity = "1")
4440
private TransferOption configGroup;
4541

@@ -59,17 +55,18 @@ static class TransferOption {
5955
@CommandLine.Option(names = {"-r", "--random"},
6056
description = "Randomly choose a follower to transfer leadership.")
6157
private boolean isRandom;
58+
59+
String getOmNodeId() {
60+
return omNodeId != null ? omNodeId : deprecatedOmNodeId;
61+
}
6262
}
6363

6464
@Override
6565
public Void call() throws Exception {
6666
if (configGroup.isRandom) {
6767
configGroup.omNodeId = "";
6868
} else {
69-
DeprecatedCliOptions.warnIfDeprecatedUsedWithoutCanonical(
70-
"--newLeaderId", "--new-leader-id", spec, "--new-leader-id", "-n");
71-
configGroup.omNodeId = DeprecatedCliOptions.resolveString(
72-
configGroup.omNodeId, configGroup.deprecatedOmNodeId);
69+
configGroup.omNodeId = configGroup.getOmNodeId();
7370
}
7471
try (OzoneManagerProtocol client = omServiceOption.newClient()) {
7572
client.transferLeadership(configGroup.omNodeId);

hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/scm/TransferScmLeaderSubCommand.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.hadoop.ozone.admin.scm;
1919

2020
import java.util.concurrent.Callable;
21-
import org.apache.hadoop.hdds.cli.DeprecatedCliOptions;
2221
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
2322
import org.apache.hadoop.hdds.scm.cli.ScmOption;
2423
import org.apache.hadoop.hdds.scm.client.ScmClient;
@@ -42,9 +41,6 @@ public class TransferScmLeaderSubCommand implements Callable<Void> {
4241
@Mixin
4342
private ScmOption scmOption;
4443

45-
@CommandLine.Spec
46-
private CommandLine.Model.CommandSpec spec;
47-
4844
@CommandLine.ArgGroup(multiplicity = "1")
4945
private TransferOption configGroup;
5046

@@ -65,6 +61,10 @@ static class TransferOption {
6561
@CommandLine.Option(names = {"-r", "--random"},
6662
description = "Randomly choose a follower to transfer leadership.")
6763
private boolean isRandom;
64+
65+
String getScmId() {
66+
return scmId != null ? scmId : deprecatedScmId;
67+
}
6868
}
6969

7070
@Override
@@ -74,10 +74,7 @@ public Void call() throws Exception {
7474
if (configGroup.isRandom) {
7575
configGroup.scmId = "";
7676
} else {
77-
DeprecatedCliOptions.warnIfDeprecatedUsedWithoutCanonical(
78-
"--newLeaderId", "--new-leader-id", spec, "--new-leader-id", "-n");
79-
configGroup.scmId = DeprecatedCliOptions.resolveString(
80-
configGroup.scmId, configGroup.deprecatedScmId);
77+
configGroup.scmId = configGroup.getScmId();
8178
}
8279
client.transferLeadership(configGroup.scmId);
8380
System.out.println("Transfer leadership successfully to " +

0 commit comments

Comments
 (0)