ibessonov commented on a change in pull request #67:
URL: https://github.com/apache/ignite-3/pull/67#discussion_r596586117



##########
File path: 
modules/configuration/src/main/java/org/apache/ignite/configuration/internal/validation/MaxValidator.java
##########
@@ -17,28 +17,21 @@
 
 package org.apache.ignite.configuration.internal.validation;
 
-import org.apache.ignite.configuration.internal.DynamicConfiguration;
-import 
org.apache.ignite.configuration.validation.ConfigurationValidationException;
-import org.apache.ignite.configuration.validation.FieldValidator;
+import javax.validation.constraints.Max;
+import org.apache.ignite.configuration.validation.ValidationContext;
+import org.apache.ignite.configuration.validation.ValidationIssue;
+import org.apache.ignite.configuration.validation.Validator;
 
 /**
  * Validate that field value is not greater than some maximum value.
- *
- * @param <C> Root configuration type.
  */
-public class MaxValidator<C extends DynamicConfiguration<?, ?, ?>> extends 
FieldValidator<Number, C> {
-    /** Maximum value. */
-    private final long maxValue;
-
-    /** Constructor. */
-    public MaxValidator(long maxValue, String message) {
-        super(message);
-        this.maxValue = maxValue;
-    }
-
+public class MaxValidator implements Validator<Max, Number> {
     /** {@inheritDoc} */
-    @Override public void validate(Number value, C newRoot, C oldRoot) throws 
ConfigurationValidationException {
-        if (value.longValue() > maxValue)
-            throw new ConfigurationValidationException(message);
+    @Override public void validate(Max annotation, ValidationContext<Number> 
ctx) {
+        if (ctx.getNewValue().longValue() > annotation.value()) {
+            ctx.addIssue(new ValidationIssue(
+                "Configuration value '" + ctx.currentKey() + "' cannot be more 
then " + annotation.value()

Review comment:
       Done

##########
File path: 
modules/configuration/src/main/java/org/apache/ignite/configuration/internal/validation/MinValidator.java
##########
@@ -17,28 +17,21 @@
 
 package org.apache.ignite.configuration.internal.validation;
 
-import org.apache.ignite.configuration.internal.DynamicConfiguration;
-import 
org.apache.ignite.configuration.validation.ConfigurationValidationException;
-import org.apache.ignite.configuration.validation.FieldValidator;
+import javax.validation.constraints.Min;
+import org.apache.ignite.configuration.validation.ValidationContext;
+import org.apache.ignite.configuration.validation.ValidationIssue;
+import org.apache.ignite.configuration.validation.Validator;
 
 /**
  * Validate that field value is not less than some minimal value.
- *
- * @param <C> Root configuration type.
  */
-public class MinValidator<C extends DynamicConfiguration<?, ?, ?>> extends 
FieldValidator<Number, C> {
-    /** Minimal value. */
-    private final long minValue;
-
-    /** Constructor. */
-    public MinValidator(long minValue, String message) {
-        super(message);
-        this.minValue = minValue;
-    }
-
+public class MinValidator implements Validator<Min, Number> {
     /** {@inheritDoc} */
-    @Override public void validate(Number value, C newRoot, C oldRoot) throws 
ConfigurationValidationException {
-        if (value.longValue() < minValue)
-            throw new ConfigurationValidationException(message);
+    @Override public void validate(Min annotation, ValidationContext<Number> 
ctx) {
+        if (ctx.getNewValue().longValue() < annotation.value()) {
+            ctx.addIssue(new ValidationIssue(
+                "Configuration value '" + ctx.currentKey() + "' cannot be less 
then " + annotation.value()

Review comment:
       Done

##########
File path: 
modules/configuration/src/main/java/org/apache/ignite/configuration/internal/validation/ValidationContextImpl.java
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.ignite.configuration.internal.validation;
+
+import java.util.List;
+import java.util.function.Function;
+import org.apache.ignite.configuration.RootKey;
+import org.apache.ignite.configuration.internal.RootsNode;
+import org.apache.ignite.configuration.tree.InnerNode;
+import org.apache.ignite.configuration.tree.TraversableTreeNode;
+import org.apache.ignite.configuration.validation.ValidationContext;
+import org.apache.ignite.configuration.validation.ValidationIssue;
+
+import static 
org.apache.ignite.configuration.internal.util.ConfigurationUtil.find;
+
+/**
+ * Validation context implementation.
+ */
+class ValidationContextImpl<VIEW> implements ValidationContext<VIEW> {
+    /** Cached storage roots with the current version of data. */
+    private final RootsNode oldRoots;
+
+    /** Updated values that need to be validated. */
+    private final RootsNode newRoots;
+
+    /** Provider for arbitrary roots that might not be accociated with the 
same storage. */
+    private final Function<RootKey<?, ?>, InnerNode> otherRoots;
+
+    /**
+     * Current node/configuration value.
+     *
+     * @see #getNewValue()
+     */
+    private final VIEW val;
+
+    /** */
+    private final String currentKey;
+
+    /** */
+    private final List<String> currentPath;
+
+    /** */
+    private final List<ValidationIssue> issues;
+
+    /**
+     * Constructor.
+     *  @param oldRoots Old roots.
+     * @param newRoots New roots.
+     * @param otherRoots Provider for arbitrary roots that might not be 
accociated with the same storage.
+     * @param val New value of currently validated configuration.
+     * @param currentKey Key corresponding to the value.
+     * @param currentPath Key corresponding to the value.

Review comment:
       Done




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to