ArbaazKhan1 commented on code in PR #6458: URL: https://github.com/apache/accumulo/pull/6458#discussion_r3590149475
########## server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooProps.java: ########## @@ -0,0 +1,208 @@ +/* + * 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 + * + * https://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.accumulo.server.conf.util; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.accumulo.core.cli.ServerOpts; +import org.apache.accumulo.server.conf.store.impl.ReadyMonitor; +import org.apache.accumulo.server.conf.util.ZooInfoViewer.ViewerOpts; +import org.apache.accumulo.server.conf.util.ZooPropEditor.EditorOpts; +import org.apache.accumulo.server.util.ServerKeywordExecutable; +import org.apache.accumulo.start.spi.CommandGroup; +import org.apache.accumulo.start.spi.CommandGroups; +import org.apache.accumulo.start.spi.KeywordExecutable; + +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import com.google.auto.service.AutoService; + +@AutoService(KeywordExecutable.class) +public class ZooProps extends ServerKeywordExecutable<ZooProps.PropsOpts> { + + public ZooProps() { + super(new PropsOpts()); + } + + @Override + public String keyword() { + return "props"; + } + + @Override + public String description() { + return "Inspect and edit ZooKeeper-backed Accumulo properties. " + + "Default prints properties for the resolved scope (ZooPropEditor output). " + + "Use --get for a multi-scope report with --system/--namespaces/--tables filters " + + "(ZooInfoViewer output). Use --set or --delete to mutate."; + } + + @Override + public CommandGroup commandGroup() { + return CommandGroups.ZOOKEEPER; + } + + @Override + public void execute(JCommander cl, PropsOpts opts) throws Exception { + + if (!opts.setOpt.isEmpty() && !opts.deleteOpt.isEmpty()) { + throw new IllegalArgumentException("Cannot use --set and --delete together."); + } + + if (!opts.setOpt.isEmpty()) { + ZooPropEditor editor = buildEditor(); + var context = getServerContext(); + EditorOpts editorOpts = toEditorOpts(opts); + editorOpts.setOpt = opts.setOpt; + editor.setProperty(context, editor.getPropKey(context, editorOpts), editorOpts); + + } else if (!opts.deleteOpt.isEmpty()) { + ZooPropEditor editor = buildEditor(); + var context = getServerContext(); + var zrw = context.getZooSession().asReaderWriter(); + EditorOpts editorOpts = toEditorOpts(opts); + editorOpts.deleteOpt = opts.deleteOpt; + var propKey = editor.getPropKey(context, editorOpts); + editor.deleteProperty(context, propKey, editor.readPropNode(propKey, zrw), editorOpts); + + } else if (opts.getOpt) { + ZooInfoViewer viewer = buildViewer(); + ViewerOpts viewerOpts = toViewerOpts(opts); + viewerOpts.printProps = true; + + // TODO + // Add PR #6419 Json hook + + viewer.generateReport(getServerContext(), viewerOpts); + + } else { + ZooPropEditor editor = buildEditor(); + var context = getServerContext(); + var zrw = context.getZooSession().asReaderWriter(); + EditorOpts editorOpts = toEditorOpts(opts); + var propKey = editor.getPropKey(context, editorOpts); + editor.printProperties(context, propKey, editor.readPropNode(propKey, zrw)); + + // TODO + // Add PR #6419 Json hook + + } + } + + private ZooPropEditor buildEditor() { + ZooPropEditor editor = new ZooPropEditor(); + editor.nullWatcher = new ZooPropEditor.NullWatcher( + new ReadyMonitor(ZooPropEditor.class.getSimpleName(), 20_000L)); + return editor; + } + + private ZooInfoViewer buildViewer() { + ZooInfoViewer viewer = new ZooInfoViewer(); + viewer.nullWatcher = new ZooInfoViewer.NullWatcher( + new ReadyMonitor(ZooInfoViewer.class.getSimpleName(), 20_000L)); + return viewer; + } + + private EditorOpts toEditorOpts(PropsOpts opts) { + EditorOpts e = new EditorOpts(); + e.tableOpt = opts.tableOpt; + e.tableIdOpt = opts.tableIdOpt; + e.namespaceOpt = opts.namespaceOpt; + e.namespaceIdOpt = opts.namespaceIdOpt; + e.resourceGroupOpt = opts.resourceGroupOpt.isEmpty() ? "" : opts.resourceGroupOpt.get(0); + return e; + } + + private ViewerOpts toViewerOpts(PropsOpts opts) { + ViewerOpts v = new ViewerOpts(); + v.outfile = opts.outfile; + v.printSystemOpt = opts.systemOpt; + v.tablesOpt.addAll(opts.tablesOpt); + v.namespacesOpt.addAll(opts.namespacesOpt); Review Comment: The singular `--namespace` / `--table` and plural `--nampespaces` / `--tables` are intentionally separate. They are intended to serve the different modes. The singular flags are meant to display a singular Zk scope for `--set` and `--delete` or default display, while the plural is used for filtering multi-scope ZK reports via `--get.` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
