Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -19,4 +19,4 @@
/**
* Generic helper class to make instantiate picocli based cli tools.
*/
package org.apache.hadoop.hdds.cli;
package org.apache.hadoop.hdds.cli;
8 changes: 8 additions & 0 deletions hadoop-hdds/tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.cli;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.util.NativeCodeLoader;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import picocli.CommandLine;

/**
* Ozone Admin Command line tool.
*/
@CommandLine.Command(name = "ozone admin",
hidden = true,
description = "Developer tools for Ozone Admin operations",
versionProvider = HddsVersionProvider.class,
mixinStandardHelpOptions = true)
public class OzoneAdmin extends GenericCli {

private OzoneConfiguration ozoneConf;

public OzoneAdmin() {
super(OzoneAdmin.class);
}

public OzoneConfiguration getOzoneConf() {
if (ozoneConf == null) {
ozoneConf = createOzoneConfiguration();
}
return ozoneConf;
}

/**
* Main for the Ozone Admin shell Command handling.
*
* @param argv - System Args Strings[]
*/
public static void main(String[] argv) {
LogManager.resetConfiguration();
Logger.getRootLogger().setLevel(Level.INFO);
Logger.getRootLogger()
.addAppender(new ConsoleAppender(new PatternLayout("%m%n")));
Logger.getLogger(NativeCodeLoader.class).setLevel(Level.ERROR);

new OzoneAdmin().run(argv);
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
/**
/*
* 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>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.scm.client.ScmClient;

/**
* Command which provides a SCM client based on the current config.
* Command-line tools for HDDS.
*/
public interface WithScmClient {

ScmClient createScmClient();

}
package org.apache.hadoop.hdds.cli;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -21,11 +21,12 @@

import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.cli.container.WithScmClient;
import org.apache.hadoop.hdds.cli.OzoneAdmin;
import org.apache.hadoop.hdds.cli.SubcommandWithParent;

import org.kohsuke.MetaInfServices;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.ParentCommand;
import picocli.CommandLine.Spec;

/**
Expand All @@ -41,21 +42,21 @@
ReplicationManagerStopSubcommand.class,
ReplicationManagerStatusSubcommand.class
})
public class ReplicationManagerCommands implements Callable<Void> {
@MetaInfServices(SubcommandWithParent.class)
public class ReplicationManagerCommands implements Callable<Void>,
SubcommandWithParent {

@Spec
private CommandSpec spec;

@ParentCommand
private WithScmClient parent;

public WithScmClient getParent() {
return parent;
}

@Override
public Void call() throws Exception {
GenericCli.missingSubcommand(spec);
return null;
}

@Override
public Class<?> getParentType() {
return OzoneAdmin.class;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -22,32 +22,25 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.ParentCommand;

import java.util.concurrent.Callable;
import java.io.IOException;

/**
* This is the handler that process safe mode check command.
* Handler to start replication manager.
*/
@Command(
name = "start",
description = "Start ReplicationManager",
mixinStandardHelpOptions = true,
versionProvider = HddsVersionProvider.class)
public class ReplicationManagerStartSubcommand implements Callable<Void> {
public class ReplicationManagerStartSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(ReplicationManagerStartSubcommand.class);

@ParentCommand
private ReplicationManagerCommands parent;

@Override
public Void call() throws Exception {
try (ScmClient scmClient = parent.getParent().createScmClient()) {
scmClient.startReplicationManager();
LOG.info("Starting ReplicationManager...");
return null;
}
public void execute(ScmClient scmClient) throws IOException {
scmClient.startReplicationManager();
LOG.info("Starting ReplicationManager...");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -22,39 +22,31 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.ParentCommand;

import java.util.concurrent.Callable;
import java.io.IOException;

/**
* This is the handler that process safe mode check command.
* Handler to query status of replication manager.
*/
@Command(
name = "status",
description = "Check if ReplicationManager is running or not",
mixinStandardHelpOptions = true,
versionProvider = HddsVersionProvider.class)
public class ReplicationManagerStatusSubcommand implements Callable<Void> {
public class ReplicationManagerStatusSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(ReplicationManagerStatusSubcommand.class);

@ParentCommand
private ReplicationManagerCommands parent;

@Override
public Void call() throws Exception {
try (ScmClient scmClient = parent.getParent().createScmClient()) {

boolean execReturn = scmClient.getReplicationManagerStatus();

// Output data list
if(execReturn){
LOG.info("ReplicationManager is Running.");
} else {
LOG.info("ReplicationManager is Not Running.");
}
return null;
public void execute(ScmClient scmClient) throws IOException {
boolean execReturn = scmClient.getReplicationManagerStatus();

// Output data list
if(execReturn){
LOG.info("ReplicationManager is Running.");
} else {
LOG.info("ReplicationManager is Not Running.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand All @@ -22,34 +22,27 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;
import picocli.CommandLine.ParentCommand;

import java.util.concurrent.Callable;
import java.io.IOException;

/**
* This is the handler that process safe mode check command.
* Handler to stop replication manager.
*/
@Command(
name = "stop",
description = "Stop ReplicationManager",
mixinStandardHelpOptions = true,
versionProvider = HddsVersionProvider.class)
public class ReplicationManagerStopSubcommand implements Callable<Void> {
public class ReplicationManagerStopSubcommand extends ScmSubcommand {

private static final Logger LOG =
LoggerFactory.getLogger(ReplicationManagerStopSubcommand.class);

@ParentCommand
private ReplicationManagerCommands parent;

@Override
public Void call() throws Exception {
try (ScmClient scmClient = parent.getParent().createScmClient()) {
scmClient.stopReplicationManager();
LOG.info("Stopping ReplicationManager...");
LOG.info("Requested SCM to stop ReplicationManager, " +
"it might take sometime for the ReplicationManager to stop.");
return null;
}
public void execute(ScmClient scmClient) throws IOException {
scmClient.stopReplicationManager();
LOG.info("Stopping ReplicationManager...");
LOG.info("Requested SCM to stop ReplicationManager, " +
"it might take sometime for the ReplicationManager to stop.");
}
}
Loading