All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.solr.cloud.autoscaling.TriggerValidationException Maven / Gradle / Ivy

There is a newer version: 9.7.0
Show newest version
/*
 * 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.solr.cloud.autoscaling;

import java.util.HashMap;
import java.util.Map;

/**
 * This class represents errors found when validating trigger configuration.
 */
public class TriggerValidationException extends Exception {
  private final Map details = new HashMap<>();
  private final String name;

  /**
   * Create an exception.
   * @param name name of the trigger / action / listener that caused the exception
   * @param details details of invalid configuration - key is a property name,
   *                value is an error message.
   */
  public TriggerValidationException(String name, Map details) {
    super();
    this.name = name;
    if (details != null) {
      this.details.putAll(details);
    }
  }

  /**
   * Create an exception.
   * @param name name of the trigger / action / listener that caused the exception
   * @param keyValues zero or even number of arguments representing symbolic key
   *                  (eg. property name) and the corresponding validation error message.
   */
  public TriggerValidationException(String name, String... keyValues) {
    super();
    this.name = name;
    if (keyValues == null || keyValues.length == 0) {
      return;
    }
    if (keyValues.length % 2 != 0) {
      throw new IllegalArgumentException("number of arguments representing key & value pairs must be even");
    }
    for (int i = 0; i < keyValues.length; i += 2) {
      details.put(keyValues[i], keyValues[i + 1]);
    }
  }

  public Map getDetails() {
    return details;
  }

  @Override
  public String toString() {
    return "TriggerValidationException{" +
        "name=" + name +
        ", details='" + details + '\'' +
        '}';
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy