smiklosovic commented on code in PR #4242: URL: https://github.com/apache/cassandra/pull/4242#discussion_r2207308019
########## src/java/org/apache/cassandra/tools/nodetool/GuardrailsConfigCommand.java: ########## @@ -0,0 +1,445 @@ +/* + * 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.cassandra.tools.nodetool; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +import io.airlift.airline.Arguments; +import io.airlift.airline.Command; +import io.airlift.airline.Option; +import org.apache.cassandra.db.guardrails.GuardrailsMBean; +import org.apache.cassandra.tools.NodeProbe; +import org.apache.cassandra.tools.NodeTool; +import org.apache.cassandra.tools.nodetool.formatter.TableBuilder; +import org.apache.cassandra.utils.LocalizeString; + +import static java.lang.String.format; +import static java.util.Arrays.stream; +import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.toList; + +public abstract class GuardrailsConfigCommand extends NodeTool.NodeToolCmd +{ + @Command(name = "getguardrailsconfig", description = "Print current guardrails configuration.") + public static class GetGuardrailsConfig extends GuardrailsConfigCommand + { + @Option(name = { "--category", "-c" }, + description = "Category of guardrails to filter, can be one of 'values', 'thresholds', 'flags', 'other'") + private String guardrailCategory; + + @Arguments(description = "Specific names or guardrails to get configuration of.") + private List<String> args = new ArrayList<>(); + + @Override + public void execute(NodeProbe probe) + { + if (!args.isEmpty() && guardrailCategory != null) + throw new IllegalStateException("Do not specify additional arguments when --category/-c is set."); + + validateCategory(guardrailCategory); + + List<Method> allGetters = stream(probe.getGuardrailsMBean().getClass().getDeclaredMethods()) + .filter(method -> method.getName().startsWith("get") Review Comment: This is a good question and I was battling with it myself. In this PR I was just following the approach in the original PR. Another option is to enumerate absolutely every guardrail and map it to getter / setter in MBean. Basically a monstrous map of guardrail name as key and getters /setters as a value. How it is done currently does require specific naming but on the other hand it seems to me that we are already following this convention subconsciously and even if we diverged from that upon an implementation of yet another guardrail it would be detected in tests. If there is a guardrail added and respective MBean methods added as well, it would be automatically returned when parsed and then it would appear in the output and it would fail the test because there would not be such an entry in expected test data. That would be the chance to see that naming is wrong / strange and a developer would know that MBean method name needs to be accommodated. Based on the naming convention of get / set methods in MBean I think it is pretty safe to assume that we will be indeed adding get/set prefix to every method. It is the camel part after it which translates to snake which needs attention a bit. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org