| | |
| | | * Portions Copyright 2006-2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.config; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.ErrorLogCategory; |
| | | import org.opends.server.types.ErrorLogSeverity; |
| | | import org.opends.server.types.DebugLogLevel; |
| | | |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.loggers.ErrorLogger.*; |
| | | import static org.opends.server.loggers.debug.DebugLogger.*; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | | import static org.opends.server.messages.ConfigMessages.*; |
| | | import static org.opends.server.messages.MessageHandler.*; |
| | | |
| | | |
| | | import org.opends.server.loggers.ErrorLogger; |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | /** |
| | | * This class defines a configuration attribute that stores both an integer |
| | | * value and an associated unit. The unit will contain both a string and a |
| | |
| | | * enforced for the calculated value. |
| | | * @param upperBound The upper bound for the calculated value. |
| | | */ |
| | | public IntegerWithUnitConfigAttribute(String name, String description, |
| | | public IntegerWithUnitConfigAttribute(String name, Message description, |
| | | boolean requiresAdminAction, |
| | | HashMap<String,Double> units, |
| | | boolean hasLowerBound, long lowerBound, |
| | |
| | | * @param selectedUnit The selected unit for this configuration |
| | | * attribute. |
| | | */ |
| | | public IntegerWithUnitConfigAttribute(String name, String description, |
| | | public IntegerWithUnitConfigAttribute(String name, Message description, |
| | | boolean requiresAdminAction, |
| | | HashMap<String,Double> units, |
| | | boolean hasLowerBound, long lowerBound, |
| | |
| | | * @param pendingSelectedUnit The pending selected unit for this |
| | | * configuration attribute. |
| | | */ |
| | | public IntegerWithUnitConfigAttribute(String name, String description, |
| | | public IntegerWithUnitConfigAttribute(String name, Message description, |
| | | boolean requiresAdminAction, |
| | | HashMap<String,Double> units, |
| | | boolean hasLowerBound, long lowerBound, |
| | |
| | | { |
| | | if ((unit == null) || (! units.containsKey(unit))) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INVALID_UNIT; |
| | | String message = getMessage(msgID, unit, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INVALID_UNIT.get(unit, getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | | long calculatedValue = (long) (intValue * units.get(unit)); |
| | | if (hasLowerBound && (calculatedValue < lowerBound)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INT_BELOW_LOWER_BOUND; |
| | | String message = getMessage(msgID, getName(), calculatedValue, |
| | | lowerBound); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get( |
| | | getName(), calculatedValue, lowerBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (hasUpperBound && (calculatedValue > upperBound)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND; |
| | | String message = getMessage(msgID, getName(), calculatedValue, |
| | | upperBound); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get( |
| | | getName(), calculatedValue, upperBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | int spacePos = value.indexOf(' '); |
| | | if (spacePos <= 0) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_NO_UNIT_DELIMITER; |
| | | String message = getMessage(msgID, String.valueOf(value), getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_NO_UNIT_DELIMITER.get( |
| | | String.valueOf(value), getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | int msgID = MSGID_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT; |
| | | String message = getMessage(msgID, String.valueOf(value), getName(), |
| | | String.valueOf(e)); |
| | | throw new ConfigException(msgID, message, e); |
| | | Message message = ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get( |
| | | String.valueOf(value), getName(), String.valueOf(e)); |
| | | throw new ConfigException(message, e); |
| | | } |
| | | |
| | | setValue(longValue, value.substring(spacePos+1)); |
| | |
| | | int spacePos = lowerValue.indexOf(' '); |
| | | if (spacePos < 0) |
| | | { |
| | | rejectReason.append(getMessage(MSGID_CONFIG_ATTR_NO_UNIT_DELIMITER, |
| | | lowerValue, getName())); |
| | | rejectReason.append(ERR_CONFIG_ATTR_NO_UNIT_DELIMITER.get( |
| | | lowerValue, getName())); |
| | | return false; |
| | | } |
| | | |
| | |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | |
| | | rejectReason.append(getMessage(MSGID_CONFIG_ATTR_INT_COULD_NOT_PARSE, |
| | | lowerValue, getName(), String.valueOf(e))); |
| | | rejectReason.append(ERR_CONFIG_ATTR_INT_COULD_NOT_PARSE.get( |
| | | lowerValue, getName(), String.valueOf(e))); |
| | | return false; |
| | | } |
| | | |
| | |
| | | double multiplier; |
| | | if (! units.containsKey(unit)) |
| | | { |
| | | rejectReason.append(getMessage(MSGID_CONFIG_ATTR_INVALID_UNIT, unit, |
| | | rejectReason.append(ERR_CONFIG_ATTR_INVALID_UNIT.get(unit, |
| | | getName())); |
| | | return false; |
| | | } |
| | |
| | | long calculatedValue = (long) (longValue * multiplier); |
| | | if (hasLowerBound && (calculatedValue < lowerBound)) |
| | | { |
| | | rejectReason.append(getMessage(MSGID_CONFIG_ATTR_INT_BELOW_LOWER_BOUND, |
| | | getName(), calculatedValue, lowerBound)); |
| | | rejectReason.append(ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get( |
| | | getName(), calculatedValue, lowerBound)); |
| | | return false; |
| | | } |
| | | |
| | | if (hasUpperBound && (calculatedValue > upperBound)) |
| | | { |
| | | rejectReason.append(getMessage(MSGID_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND, |
| | | getName(), calculatedValue, upperBound)); |
| | | rejectReason.append(ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get( |
| | | getName(), calculatedValue, upperBound)); |
| | | return false; |
| | | } |
| | | |
| | |
| | | { |
| | | if (isRequired()) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | | { |
| | |
| | | int numValues = valueStrings.size(); |
| | | if ((! isMultiValued()) && (numValues > 1)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | if ((valueString == null) || (valueString.length() == 0)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_EMPTY_STRING_VALUE; |
| | | String message = getMessage(msgID, getName()); |
| | | |
| | | Message message = ERR_CONFIG_ATTR_EMPTY_STRING_VALUE.get(getName()); |
| | | if (allowFailures) |
| | | { |
| | | logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.MILD_ERROR, |
| | | message, msgID); |
| | | ErrorLogger.logError(message); |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | throw new ConfigException(msgID, message); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | |
| | |
| | | StringBuilder rejectReason = new StringBuilder(); |
| | | if (! valueIsAcceptable(valueString.toLowerCase(), rejectReason)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INVALID_VALUE_WITH_UNIT; |
| | | String message = getMessage(msgID, valueString, getName(), |
| | | rejectReason.toString()); |
| | | Message message = ERR_CONFIG_ATTR_INVALID_VALUE_WITH_UNIT.get( |
| | | valueString, getName(), |
| | | rejectReason.toString()); |
| | | |
| | | if (allowFailures) |
| | | { |
| | | logError(ErrorLogCategory.CONFIGURATION, ErrorLogSeverity.MILD_ERROR, |
| | | message, msgID); |
| | | ErrorLogger.logError(message); |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | throw new ConfigException(msgID, message); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | |
| | |
| | | // attribute and if so deal with it accordingly. |
| | | if ((isRequired()) && valueSet.isEmpty()) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | if (pendingUnit != null) |
| | | { |
| | | // We cannot have multiple pending value sets. |
| | | int msgID = MSGID_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_PENDING_VALUE_SETS.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | if (values.isEmpty()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | | { |
| | |
| | | if (iterator.hasNext()) |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | int msgID = MSGID_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | try |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT; |
| | | String message = getMessage(msgID, valueString, a.getName(), |
| | | String.valueOf(e)); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT. |
| | | get(valueString, a.getName(), String.valueOf(e)); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | // multiplier. |
| | | if (! units.containsKey(pendingUnit)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INVALID_UNIT; |
| | | String message = getMessage(msgID, pendingUnit, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_INVALID_UNIT.get(pendingUnit, a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | double multiplier = units.get(activeUnit); |
| | |
| | | // Check the bounds set for this attribute. |
| | | if (hasLowerBound && (pendingCalculatedValue < lowerBound)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INT_BELOW_LOWER_BOUND; |
| | | String message = getMessage(msgID, a.getName(), |
| | | pendingCalculatedValue, lowerBound); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get( |
| | | a.getName(), pendingCalculatedValue, lowerBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (hasUpperBound && (pendingCalculatedValue > upperBound)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND; |
| | | String message = getMessage(msgID, a.getName(), |
| | | pendingCalculatedValue, upperBound); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get( |
| | | a.getName(), pendingCalculatedValue, upperBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | // This is illegal -- only the pending option is allowed for |
| | | // configuration attributes. |
| | | int msgID = MSGID_CONFIG_ATTR_OPTIONS_NOT_ALLOWED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_OPTIONS_NOT_ALLOWED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | else |
| | |
| | | if (activeUnit != null) |
| | | { |
| | | // We cannot have multiple active value sets. |
| | | int msgID = MSGID_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_MULTIPLE_ACTIVE_VALUE_SETS.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | |
| | | if (values.isEmpty()) |
| | | { |
| | | // This is illegal -- it must have a value. |
| | | int msgID = MSGID_CONFIG_ATTR_IS_REQUIRED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_IS_REQUIRED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | else |
| | | { |
| | |
| | | if (iterator.hasNext()) |
| | | { |
| | | // This is illegal -- the attribute is single-valued. |
| | | int msgID = MSGID_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED; |
| | | String message = getMessage(msgID, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_SET_VALUES_IS_SINGLE_VALUED.get(a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | try |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT; |
| | | String message = getMessage(msgID, valueString, a.getName(), |
| | | String.valueOf(e)); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_COULD_NOT_PARSE_INT_COMPONENT.get( |
| | | valueString, a.getName(), String.valueOf(e)); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | |
| | | // Get the unit and use it to determine the corresponding multiplier. |
| | | if (! units.containsKey(activeUnit)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INVALID_UNIT; |
| | | String message = getMessage(msgID, activeUnit, a.getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = |
| | | ERR_CONFIG_ATTR_INVALID_UNIT.get(activeUnit, a.getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | double multiplier = units.get(activeUnit); |
| | |
| | | // Check the bounds set for this attribute. |
| | | if (hasLowerBound && (activeCalculatedValue < lowerBound)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INT_BELOW_LOWER_BOUND; |
| | | String message = getMessage(msgID, a.getName(), |
| | | activeCalculatedValue, lowerBound); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INT_BELOW_LOWER_BOUND.get( |
| | | a.getName(), activeCalculatedValue, lowerBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (hasUpperBound && (activeCalculatedValue > upperBound)) |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND; |
| | | String message = getMessage(msgID, a.getName(), |
| | | activeCalculatedValue, upperBound); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INT_ABOVE_UPPER_BOUND.get( |
| | | a.getName(), activeCalculatedValue, upperBound); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (activeUnit == null) |
| | | { |
| | | // This is not OK. The value set must contain an active value. |
| | | int msgID = MSGID_CONFIG_ATTR_NO_ACTIVE_VALUE_SET; |
| | | String message = getMessage(msgID, getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_NO_ACTIVE_VALUE_SET.get(getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | |
| | | if (pendingUnit == null) |
| | |
| | | { |
| | | attributeInfoList.add(new MBeanAttributeInfo(getName(), |
| | | String.class.getName(), |
| | | getDescription(), true, true, |
| | | false)); |
| | | String.valueOf( |
| | | getDescription()), |
| | | true, true, false)); |
| | | |
| | | if (requiresAdminAction()) |
| | | { |
| | | String name = getName() + ";" + OPTION_PENDING_VALUES; |
| | | attributeInfoList.add(new MBeanAttributeInfo(name, |
| | | String.class.getName(), |
| | | getDescription(), true, |
| | | false, false)); |
| | | String.valueOf( |
| | | getDescription()), |
| | | true, false, false)); |
| | | } |
| | | } |
| | | |
| | |
| | | public MBeanParameterInfo toJMXParameterInfo() |
| | | { |
| | | return new MBeanParameterInfo(getName(), String.class.getName(), |
| | | getDescription()); |
| | | String.valueOf(getDescription())); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | int msgID = MSGID_CONFIG_ATTR_INT_WITH_UNIT_INVALID_TYPE; |
| | | String message = getMessage(msgID, String.valueOf(value), getName(), |
| | | value.getClass().getName()); |
| | | throw new ConfigException(msgID, message); |
| | | Message message = ERR_CONFIG_ATTR_INT_WITH_UNIT_INVALID_TYPE.get( |
| | | String.valueOf(value), getName(), value.getClass().getName()); |
| | | throw new ConfigException(message); |
| | | } |
| | | } |
| | | |