|
3 | 3 | import com.redis.om.spring.annotations.Document;
|
4 | 4 | import com.redis.om.spring.annotations.Indexed;
|
5 | 5 | import lombok.Data;
|
| 6 | +import org.slf4j.Logger; |
6 | 7 | import org.springframework.data.annotation.Id;
|
7 | 8 |
|
8 | 9 | @Document
|
9 | 10 | @Data
|
10 | 11 | public class Rule {
|
| 12 | + private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(Rule.class); |
| 13 | + |
11 | 14 | @Indexed
|
12 | 15 | protected String dbId;
|
13 | 16 |
|
@@ -37,40 +40,60 @@ public String toString(){
|
37 | 40 | }
|
38 | 41 |
|
39 | 42 |
|
40 |
| - public boolean isValid(){ |
| 43 | + public String getValidationError(){ |
| 44 | + LOG.info("Validating rule: {}", this); |
| 45 | + |
41 | 46 | if(this.ruleType == RuleType.IncreaseMemory){
|
42 | 47 | if(scaleType == ScaleType.Deterministic || scaleType == ScaleType.Step){
|
43 | 48 | if(scaleValue > scaleCeiling){
|
44 |
| - return false; |
| 49 | + return "Scale value is greater than scale ceiling"; |
45 | 50 | }
|
46 | 51 |
|
47 | 52 | }
|
48 | 53 |
|
49 | 54 | if(scaleType == ScaleType.Deterministic) {
|
50 | 55 | if(!isMultipleOfPointOne()){
|
51 |
| - return false; |
| 56 | + return "Memory Scale must be a multiple of 0.1"; |
52 | 57 | }
|
53 | 58 | }
|
54 | 59 | }
|
55 | 60 |
|
56 | 61 | if(this.ruleType == RuleType.DecreaseMemory){
|
57 | 62 | if(scaleType == ScaleType.Deterministic){
|
58 | 63 | if(scaleValue < scaleFloor){
|
59 |
| - return false; |
| 64 | + return "Scale value is less than scale floor"; |
60 | 65 | }
|
| 66 | + } else { |
| 67 | + return "Non-deterministic Scale in Operations are not supported"; // non-deterministic decrease rules are not allowed |
61 | 68 | }
|
62 | 69 |
|
63 |
| - if(scaleType == ScaleType.Deterministic) { |
64 |
| - if(!isMultipleOfPointOne()){ |
65 |
| - return false; |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + if(this.ruleType == RuleType.IncreaseThroughput){ |
| 74 | + if(scaleType == ScaleType.Deterministic || scaleType == ScaleType.Step){ |
| 75 | + if(scaleValue > scaleCeiling){ |
| 76 | + return "Scale value is greater than scale ceiling"; |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + if(this.ruleType == RuleType.DecreaseThroughput){ |
| 82 | + if(scaleType == ScaleType.Deterministic ){ |
| 83 | + if(scaleValue < scaleFloor){ |
| 84 | + return "Scale value is less than scale floor"; |
66 | 85 | }
|
| 86 | + } else { |
| 87 | + LOG.info("Non-deterministic decrease rules are not allowed: rule type: {}", ruleType); |
| 88 | + return "Non-deterministic Scale in Operations are not supported"; // non-deterministic decrease rules are not allowed |
67 | 89 | }
|
68 | 90 | }
|
69 | 91 |
|
70 |
| - return true; |
| 92 | + return ""; |
71 | 93 | }
|
72 | 94 |
|
73 | 95 | protected boolean isMultipleOfPointOne() {
|
| 96 | + LOG.info("Validating scale value: {}", scaleValue); |
74 | 97 | double compValue = scaleValue - Math.floor(scaleValue);
|
75 | 98 | double epsilon = 1e-9; // Small tolerance for floating-point precision
|
76 | 99 | return Math.abs(compValue % 0.1) < epsilon;
|
|
0 commit comments