-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-2240. Command line tool for OM Admin #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /** | ||
| * 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.ozone.admin; | ||
|
|
||
| import org.apache.hadoop.hdds.cli.GenericCli; | ||
| import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
| import org.apache.hadoop.ozone.admin.om.OMAdmin; | ||
| 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, | ||
| subcommands = { | ||
| OMAdmin.class | ||
| }, | ||
| mixinStandardHelpOptions = true) | ||
| public class OzoneAdmin extends GenericCli { | ||
| private OzoneConfiguration ozoneConf; | ||
|
|
||
| public OzoneConfiguration getOzoneConf() { | ||
| if (ozoneConf == null) { | ||
| ozoneConf = createOzoneConfiguration(); | ||
| } | ||
| return ozoneConf; | ||
| } | ||
|
|
||
| /** | ||
| * Main for the Ozone Admin shell Command handling. | ||
| * | ||
| * @param argv - System Args Strings[] | ||
| * @throws Exception | ||
| */ | ||
| public static void main(String[] argv) throws Exception { | ||
| LogManager.resetConfiguration(); | ||
| Logger.getRootLogger().setLevel(Level.WARN); | ||
| 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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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 | ||
| * | ||
| * 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.ozone.admin.om; | ||
|
|
||
| import org.apache.hadoop.hdds.cli.HddsVersionProvider; | ||
| import org.apache.hadoop.ozone.client.protocol.ClientProtocol; | ||
| import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRoleInfo; | ||
| import picocli.CommandLine; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| /** | ||
| * Handler of om get-service-roles command. | ||
| */ | ||
| @CommandLine.Command( | ||
| name = "getserviceroles", | ||
| description = "List all OMs and their respective Ratis server roles", | ||
| mixinStandardHelpOptions = true, | ||
| versionProvider = HddsVersionProvider.class) | ||
| public class GetServiceRolesSubcommand implements Callable<Void> { | ||
|
|
||
| @CommandLine.ParentCommand | ||
| private OMAdmin parent; | ||
|
|
||
| @CommandLine.Option(names = {"-id", "--service-id"}, | ||
| description = "OM Service ID", | ||
| required = true) | ||
| private String omServiceId; | ||
|
|
||
| @Override | ||
| public Void call() throws Exception { | ||
| ClientProtocol client = parent.createClient(omServiceId); | ||
| getOmServerRoles(client.getOmRoleInfos()); | ||
| return null; | ||
| } | ||
|
|
||
| private void getOmServerRoles(List<OMRoleInfo> roleInfos) { | ||
| for (OMRoleInfo roleInfo : roleInfos) { | ||
| System.out.println( | ||
| roleInfo.getNodeId() + " : " + roleInfo.getServerRole()); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.