HDDS-2183. Container and pipline subcommands of scmcli should be grouped
Closes #1532
This commit is contained in:
parent
760b523e58
commit
d6b0a8da77
@ -27,15 +27,8 @@
|
||||
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
|
||||
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
||||
import org.apache.hadoop.hdds.scm.XceiverClientManager;
|
||||
import org.apache.hadoop.hdds.scm.cli.container.CloseSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.container.CreateSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.container.DeleteSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.container.InfoSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.container.ListSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.pipeline.ActivatePipelineSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.pipeline.ClosePipelineSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.pipeline.DeactivatePipelineSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.pipeline.ListPipelinesSubcommand;
|
||||
import org.apache.hadoop.hdds.scm.cli.container.ContainerCommands;
|
||||
import org.apache.hadoop.hdds.scm.cli.pipeline.PipelineCommands;
|
||||
import org.apache.hadoop.hdds.scm.client.ContainerOperationClient;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
|
||||
@ -80,15 +73,8 @@
|
||||
versionProvider = HddsVersionProvider.class,
|
||||
subcommands = {
|
||||
SafeModeCommands.class,
|
||||
ListSubcommand.class,
|
||||
InfoSubcommand.class,
|
||||
DeleteSubcommand.class,
|
||||
CreateSubcommand.class,
|
||||
CloseSubcommand.class,
|
||||
ListPipelinesSubcommand.class,
|
||||
ActivatePipelineSubcommand.class,
|
||||
DeactivatePipelineSubcommand.class,
|
||||
ClosePipelineSubcommand.class,
|
||||
ContainerCommands.class,
|
||||
PipelineCommands.class,
|
||||
TopologySubcommand.class,
|
||||
ReplicationManagerCommands.class
|
||||
},
|
||||
|
@ -20,7 +20,6 @@
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
|
||||
import picocli.CommandLine.Command;
|
||||
@ -38,15 +37,15 @@
|
||||
public class CloseSubcommand implements Callable<Void> {
|
||||
|
||||
@ParentCommand
|
||||
private SCMCLI parent;
|
||||
private ContainerCommands parent;
|
||||
|
||||
@Parameters(description = "Id of the container to close")
|
||||
private long containerId;
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
parent.checkContainerExists(scmClient, containerId);
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
parent.getParent().checkContainerExists(scmClient, containerId);
|
||||
scmClient.closeContainer(containerId);
|
||||
return null;
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.hdds.scm.cli.container;
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.cli.MissingSubcommandException;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.ParentCommand;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Subcommand to group container related operations.
|
||||
*/
|
||||
@Command(
|
||||
name = "container",
|
||||
description = "Container specific operations",
|
||||
mixinStandardHelpOptions = true,
|
||||
versionProvider = HddsVersionProvider.class,
|
||||
subcommands = {
|
||||
ListSubcommand.class,
|
||||
InfoSubcommand.class,
|
||||
DeleteSubcommand.class,
|
||||
CreateSubcommand.class,
|
||||
CloseSubcommand.class
|
||||
})
|
||||
public class ContainerCommands implements Callable<Void> {
|
||||
|
||||
@ParentCommand
|
||||
private SCMCLI parent;
|
||||
|
||||
public SCMCLI getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
throw new MissingSubcommandException(
|
||||
this.parent.getCmd().getSubcommands().get("container"));
|
||||
}
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import org.apache.hadoop.hdds.scm.container.common.helpers
|
||||
.ContainerWithPipeline;
|
||||
@ -45,7 +44,7 @@ public class CreateSubcommand implements Callable<Void> {
|
||||
LoggerFactory.getLogger(CreateSubcommand.class);
|
||||
|
||||
@ParentCommand
|
||||
private SCMCLI parent;
|
||||
private ContainerCommands parent;
|
||||
|
||||
@Option(description = "Owner of the new container", defaultValue = "OZONE",
|
||||
required = false, names = {
|
||||
@ -55,7 +54,7 @@ public class CreateSubcommand implements Callable<Void> {
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
ContainerWithPipeline container = scmClient.createContainer(owner);
|
||||
LOG.info("Container {} is created.",
|
||||
container.getContainerInfo().getContainerID());
|
||||
|
@ -21,7 +21,6 @@
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
|
||||
import picocli.CommandLine.Command;
|
||||
@ -47,12 +46,12 @@ public class DeleteSubcommand implements Callable<Void> {
|
||||
private boolean force;
|
||||
|
||||
@ParentCommand
|
||||
private SCMCLI parent;
|
||||
private ContainerCommands parent;
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
parent.checkContainerExists(scmClient, containerId);
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
parent.getParent().checkContainerExists(scmClient, containerId);
|
||||
scmClient.deleteContainer(containerId, force);
|
||||
return null;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
|
||||
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
|
||||
.ContainerDataProto;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import org.apache.hadoop.hdds.scm.container.common.helpers
|
||||
.ContainerWithPipeline;
|
||||
@ -50,14 +49,14 @@ public class InfoSubcommand implements Callable<Void> {
|
||||
LoggerFactory.getLogger(InfoSubcommand.class);
|
||||
|
||||
@ParentCommand
|
||||
private SCMCLI parent;
|
||||
private ContainerCommands parent;
|
||||
|
||||
@Parameters(description = "Decimal id of the container.")
|
||||
private long containerID;
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
ContainerWithPipeline container = scmClient.
|
||||
getContainerWithPipeline(containerID);
|
||||
Preconditions.checkNotNull(container, "Container cannot be null");
|
||||
|
@ -22,7 +22,6 @@
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import org.apache.hadoop.hdds.scm.container.ContainerInfo;
|
||||
import org.apache.hadoop.ozone.web.utils.JsonUtils;
|
||||
@ -48,7 +47,7 @@ public class ListSubcommand implements Callable<Void> {
|
||||
LoggerFactory.getLogger(ListSubcommand.class);
|
||||
|
||||
@ParentCommand
|
||||
private SCMCLI parent;
|
||||
private ContainerCommands parent;
|
||||
|
||||
@Option(names = {"-s", "--start"},
|
||||
description = "Container id to start the iteration", required = true)
|
||||
@ -68,7 +67,7 @@ private void outputContainerInfo(ContainerInfo containerInfo)
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
|
||||
List<ContainerInfo> containerList =
|
||||
scmClient.listContainer(startId, count);
|
||||
|
@ -20,34 +20,33 @@
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Handler of activatePipeline command.
|
||||
* Handler of activate pipeline command.
|
||||
*/
|
||||
@CommandLine.Command(
|
||||
name = "activatePipeline",
|
||||
name = "activate",
|
||||
description = "Activates the given Pipeline",
|
||||
mixinStandardHelpOptions = true,
|
||||
versionProvider = HddsVersionProvider.class)
|
||||
public class ActivatePipelineSubcommand implements Callable<Void> {
|
||||
|
||||
@CommandLine.ParentCommand
|
||||
private SCMCLI parent;
|
||||
private PipelineCommands parent;
|
||||
|
||||
@CommandLine.Parameters(description = "ID of the pipeline to activate")
|
||||
private String pipelineId;
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
scmClient.activatePipeline(
|
||||
HddsProtos.PipelineID.newBuilder().setId(pipelineId).build());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,34 +20,33 @@
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Handler of closePipeline command.
|
||||
* Handler of close pipeline command.
|
||||
*/
|
||||
@CommandLine.Command(
|
||||
name = "closePipeline",
|
||||
name = "close",
|
||||
description = "Close pipeline",
|
||||
mixinStandardHelpOptions = true,
|
||||
versionProvider = HddsVersionProvider.class)
|
||||
public class ClosePipelineSubcommand implements Callable<Void> {
|
||||
|
||||
@CommandLine.ParentCommand
|
||||
private SCMCLI parent;
|
||||
private PipelineCommands parent;
|
||||
|
||||
@CommandLine.Parameters(description = "ID of the pipeline to close")
|
||||
private String pipelineId;
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
scmClient.closePipeline(
|
||||
HddsProtos.PipelineID.newBuilder().setId(pipelineId).build());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,34 +20,33 @@
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Handler of deactivatePipeline command.
|
||||
* Handler of deactivate pipeline command.
|
||||
*/
|
||||
@CommandLine.Command(
|
||||
name = "deactivatePipeline",
|
||||
name = "deactivate",
|
||||
description = "Deactivates the given Pipeline",
|
||||
mixinStandardHelpOptions = true,
|
||||
versionProvider = HddsVersionProvider.class)
|
||||
public class DeactivatePipelineSubcommand implements Callable<Void> {
|
||||
|
||||
@CommandLine.ParentCommand
|
||||
private SCMCLI parent;
|
||||
private PipelineCommands parent;
|
||||
|
||||
@CommandLine.Parameters(description = "ID of the pipeline to deactivate")
|
||||
private String pipelineId;
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
scmClient.deactivatePipeline(
|
||||
HddsProtos.PipelineID.newBuilder().setId(pipelineId).build());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,24 +19,23 @@
|
||||
package org.apache.hadoop.hdds.scm.cli.pipeline;
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import org.apache.hadoop.hdds.scm.client.ScmClient;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Handler of listPipelines command.
|
||||
* Handler of list pipelines command.
|
||||
*/
|
||||
@CommandLine.Command(
|
||||
name = "listPipelines",
|
||||
name = "list",
|
||||
description = "List all active pipelines",
|
||||
mixinStandardHelpOptions = true,
|
||||
versionProvider = HddsVersionProvider.class)
|
||||
public class ListPipelinesSubcommand implements Callable<Void> {
|
||||
|
||||
@CommandLine.ParentCommand
|
||||
private SCMCLI parent;
|
||||
private PipelineCommands parent;
|
||||
|
||||
@CommandLine.Option(names = {"-ffc", "--filterByFactor"},
|
||||
description = "Filter listed pipelines by Factor(ONE/one)",
|
||||
@ -53,7 +52,7 @@ public class ListPipelinesSubcommand implements Callable<Void> {
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
try (ScmClient scmClient = parent.createScmClient()) {
|
||||
try (ScmClient scmClient = parent.getParent().createScmClient()) {
|
||||
if (isNullOrEmpty(factor) && isNullOrEmpty(state)) {
|
||||
scmClient.listPipelines().forEach(System.out::println);
|
||||
} else {
|
||||
@ -72,4 +71,4 @@ public Void call() throws Exception {
|
||||
protected static boolean isNullOrEmpty(String str) {
|
||||
return ((str == null) || str.trim().isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.hdds.scm.cli.pipeline;
|
||||
|
||||
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
|
||||
import org.apache.hadoop.hdds.cli.MissingSubcommandException;
|
||||
import org.apache.hadoop.hdds.scm.cli.SCMCLI;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.ParentCommand;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Subcommand to group pipeline related operations.
|
||||
*/
|
||||
@Command(
|
||||
name = "pipeline",
|
||||
description = "Pipeline specific operations",
|
||||
mixinStandardHelpOptions = true,
|
||||
versionProvider = HddsVersionProvider.class,
|
||||
subcommands = {
|
||||
ListPipelinesSubcommand.class,
|
||||
ActivatePipelineSubcommand.class,
|
||||
DeactivatePipelineSubcommand.class,
|
||||
ClosePipelineSubcommand.class
|
||||
})
|
||||
public class PipelineCommands implements Callable<Void> {
|
||||
|
||||
@ParentCommand
|
||||
private SCMCLI parent;
|
||||
|
||||
public SCMCLI getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
throw new MissingSubcommandException(
|
||||
this.parent.getCmd().getSubcommands().get("pipeline"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user