kevinrr888 commented on code in PR #5348:
URL: https://github.com/apache/accumulo/pull/5348#discussion_r1975857447


##########
server/base/src/main/java/org/apache/accumulo/server/util/checkCommand/ServerConfigCheckRunner.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.util.checkCommand;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.server.ServerContext;
+import org.apache.accumulo.server.cli.ServerUtilOpts;
+import org.apache.accumulo.server.util.Admin;
+
+public class ServerConfigCheckRunner implements CheckRunner {
+  private static final Admin.CheckCommand.Check check = 
Admin.CheckCommand.Check.SERVER_CONFIG;
+
+  @Override
+  public Admin.CheckCommand.CheckStatus runCheck(ServerContext context, 
ServerUtilOpts opts,
+      boolean fixFiles) throws Exception {
+    Admin.CheckCommand.CheckStatus status = Admin.CheckCommand.CheckStatus.OK;
+    printRunning();
+
+    log.trace("********** Checking server configuration **********");
+
+    log.trace("Checking that all configured properties are valid (valid key 
and value)");
+    final Map<String,String> definedProps = new HashMap<>();
+    final var config = context.getConfiguration();
+    config.getProperties(definedProps, s -> true);
+    for (var entry : definedProps.entrySet()) {
+      var key = entry.getKey();
+      var val = entry.getValue();
+      if (!Property.isValidProperty(key, val)) {
+        log.warn("Invalid property (key={} val={}) found in the config", key, 
val);
+        status = Admin.CheckCommand.CheckStatus.FAILED;
+      }
+    }
+
+    log.trace("Checking that all required config properties are present");
+    // there are many properties that should be set (default value or user 
set), identifying them
+    // all and checking them here is unrealistic. Some property that is not 
set but is expected
+    // will likely result in some sort of failure eventually anyway. We will 
just check a few
+    // obvious required properties here.
+    Set<Property> requiredProps = Set.of(Property.INSTANCE_ZK_HOST, 
Property.INSTANCE_ZK_TIMEOUT,
+        Property.INSTANCE_SECRET, Property.INSTANCE_VOLUMES, 
Property.GENERAL_THREADPOOL_SIZE,
+        Property.GENERAL_DELEGATION_TOKEN_LIFETIME,
+        Property.GENERAL_DELEGATION_TOKEN_UPDATE_INTERVAL, 
Property.GENERAL_IDLE_PROCESS_INTERVAL,
+        Property.GENERAL_LOW_MEM_DETECTOR_INTERVAL, 
Property.GENERAL_LOW_MEM_DETECTOR_THRESHOLD,
+        Property.GENERAL_PROCESS_BIND_ADDRESS, 
Property.GENERAL_SERVER_LOCK_VERIFICATION_INTERVAL,
+        Property.MANAGER_CLIENTPORT, Property.TSERV_CLIENTPORT, 
Property.GC_CYCLE_START,
+        Property.GC_CYCLE_DELAY, Property.GC_PORT, Property.MONITOR_PORT, 
Property.TABLE_MAJC_RATIO,
+        Property.TABLE_SPLIT_THRESHOLD);

Review Comment:
   This sounds like a good idea to me. There are a lot of `PropertyType.STRING` 
when a String isn't really what the property is. `PropertyType` exists to check 
that the property is valid; setting the `PropertyType` to `STRING` is just a 
way to ignore this validation. I wonder if it would be best for a 1 to 1 
mapping `Property` to `PropertyType`. This would probably be overkill though, 
another idea could be to analyze the `PropertyType`s that are always valid. 
From briefly looking, `PropertyType.PATH`, `PropertyType.STRING`, 
`PropertyType.URI` are always valid. I don't think any properties should always 
be valid. Those that are `PropertyType.STRING` could probably be given a more 
appropriate existing `PropertyType` or a new one. `PATH` and `URI` could have 
validation.
   
   In addition to this, can analyze all properties, determine if they are 
required or not, and change the validation:
   - Properties that are not required could accept empty string, null, or a 
valid value (where validity is well defined)
   - Properties that are required could only accept a valid value
   
   Like you said, for this PR, can just push this list of required properties 
into `Property`. Maybe for now/in this PR this list of required props is only 
accessed/checked in this `admin check`. Might be a bit of a scope creep to 
start checking this list elsewhere in the code. Could do it in follow on.



-- 
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]

Reply via email to