void validate()

in src/main/java/org/opensearch/performanceanalyzer/rca/framework/core/Threshold.java [125:173]


    void validate() throws MalformedThresholdFile {
        if (name == null || defaultVal == null) {
            throw new MalformedThresholdFile(
                    pathToFile, "'name' and 'default' keys are mandatory.");
        }

        String filename = new File(pathToFile).getName();
        if (!filename.split("\\.")[0].equals(name)) {
            throw new MalformedThresholdFile(
                    pathToFile,
                    "The name of the file (without the extension)"
                            + " and the value of the 'name' key in json, should match.");
        }

        if (overrides != null && overridePrecedenceOrder != null) {
            if (overrides.size() != overridePrecedenceOrder.size()) {
                String msg = "Elements in overrides and precedence-order are not the same.";
                throw new OverridesAndPrecedenceOrderCountMismatch(pathToFile, msg);
            }
            // At this point we validateAndProcess that the all the categories of overrides, are
            // present
            // in the precedence-order.
            for (String cat : overridePrecedenceOrder) {
                if (overrides.get(cat) == null) {
                    String msg =
                            String.format(
                                    "'%s' exists in the precedence-order but not in the overrides",
                                    cat);
                    throw new OverridesAndPrecedenceOrderValueMismatch(pathToFile, msg);
                }
            }
        } else {
            // If we are here then either overrides is null or overridesPrecedenceOrder is null or
            // both
            // are null. If both are null, then its a valid case, else we throw error.
            if (!(overrides == null && overridePrecedenceOrder == null)) {
                String msg =
                        "Between overrides and precedence-order, either you specify both or none.";
                throw new OverridesAndPrecedenceOrderValueMismatch(pathToFile, msg);
            } else {
                // We don't like nulls and null pointer exceptions. So we will initialize these with
                // isEmpty
                // maps and
                // lists.
                overrides = new HashMap<>();
                overridePrecedenceOrder = new ArrayList<>();
            }
        }
    }