001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 */ 026package org.forgerock.opendj.server.config.meta; 027 028 029 030import java.util.Collection; 031import java.util.SortedSet; 032import org.forgerock.opendj.config.AdministratorAction; 033import org.forgerock.opendj.config.AliasDefaultBehaviorProvider; 034import org.forgerock.opendj.config.BooleanPropertyDefinition; 035import org.forgerock.opendj.config.ClassPropertyDefinition; 036import org.forgerock.opendj.config.client.ConcurrentModificationException; 037import org.forgerock.opendj.config.client.ManagedObject; 038import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException; 039import org.forgerock.opendj.config.client.OperationRejectedException; 040import org.forgerock.opendj.config.DefaultBehaviorProvider; 041import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider; 042import org.forgerock.opendj.config.EnumPropertyDefinition; 043import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 044import org.forgerock.opendj.config.ManagedObjectDefinition; 045import org.forgerock.opendj.config.PropertyOption; 046import org.forgerock.opendj.config.PropertyProvider; 047import org.forgerock.opendj.config.server.ConfigurationChangeListener; 048import org.forgerock.opendj.config.server.ServerManagedObject; 049import org.forgerock.opendj.config.StringPropertyDefinition; 050import org.forgerock.opendj.config.Tag; 051import org.forgerock.opendj.ldap.DN; 052import org.forgerock.opendj.ldap.LdapException; 053import org.forgerock.opendj.server.config.client.ErrorLogPublisherCfgClient; 054import org.forgerock.opendj.server.config.server.ErrorLogPublisherCfg; 055import org.forgerock.opendj.server.config.server.LogPublisherCfg; 056 057 058 059/** 060 * An interface for querying the Error Log Publisher managed object 061 * definition meta information. 062 * <p> 063 * Error Log Publishers are responsible for distributing error log 064 * messages from the error logger to a destination. 065 */ 066public final class ErrorLogPublisherCfgDefn extends ManagedObjectDefinition<ErrorLogPublisherCfgClient, ErrorLogPublisherCfg> { 067 068 /** The singleton configuration definition instance. */ 069 private static final ErrorLogPublisherCfgDefn INSTANCE = new ErrorLogPublisherCfgDefn(); 070 071 072 073 /** 074 * Defines the set of permissable values for the "default-severity" property. 075 * <p> 076 * Specifies the default severity levels for the logger. 077 */ 078 public static enum DefaultSeverity { 079 080 /** 081 * Messages of all severity levels are logged. 082 */ 083 ALL("all"), 084 085 086 087 /** 088 * The error log severity that is used for messages that provide 089 * debugging information triggered during processing. 090 */ 091 DEBUG("debug"), 092 093 094 095 /** 096 * The error log severity that is used for messages that provide 097 * information about errors which may force the server to shut down 098 * or operate in a significantly degraded state. 099 */ 100 ERROR("error"), 101 102 103 104 /** 105 * The error log severity that is used for messages that provide 106 * information about significant events within the server that are 107 * not warnings or errors. 108 */ 109 INFO("info"), 110 111 112 113 /** 114 * No messages of any severity are logged by default. This value 115 * is intended to be used in conjunction with the override-severity 116 * property to define an error logger that will publish no error 117 * message beside the errors of a given category. 118 */ 119 NONE("none"), 120 121 122 123 /** 124 * The error log severity that is used for the most important 125 * informational messages (i.e., information that should almost 126 * always be logged but is not associated with a warning or error 127 * condition). 128 */ 129 NOTICE("notice"), 130 131 132 133 /** 134 * The error log severity that is used for messages that provide 135 * information about warnings triggered during processing. 136 */ 137 WARNING("warning"); 138 139 140 141 /** String representation of the value. */ 142 private final String name; 143 144 145 146 /** Private constructor. */ 147 private DefaultSeverity(String name) { this.name = name; } 148 149 150 151 /** {@inheritDoc} */ 152 public String toString() { return name; } 153 154 } 155 156 157 158 /** The "default-severity" property definition. */ 159 private static final EnumPropertyDefinition<DefaultSeverity> PD_DEFAULT_SEVERITY; 160 161 162 163 /** The "java-class" property definition. */ 164 private static final ClassPropertyDefinition PD_JAVA_CLASS; 165 166 167 168 /** The "override-severity" property definition. */ 169 private static final StringPropertyDefinition PD_OVERRIDE_SEVERITY; 170 171 172 173 /** Build the "default-severity" property definition. */ 174 static { 175 EnumPropertyDefinition.Builder<DefaultSeverity> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "default-severity"); 176 builder.setOption(PropertyOption.MULTI_VALUED); 177 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "default-severity")); 178 DefaultBehaviorProvider<DefaultSeverity> provider = new DefinedDefaultBehaviorProvider<DefaultSeverity>("error", "warning"); 179 builder.setDefaultBehaviorProvider(provider); 180 builder.setEnumClass(DefaultSeverity.class); 181 PD_DEFAULT_SEVERITY = builder.getInstance(); 182 INSTANCE.registerPropertyDefinition(PD_DEFAULT_SEVERITY); 183 } 184 185 186 187 /** Build the "java-class" property definition. */ 188 static { 189 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 190 builder.setOption(PropertyOption.MANDATORY); 191 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 192 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.ErrorLogPublisher"); 193 builder.setDefaultBehaviorProvider(provider); 194 builder.addInstanceOf("org.opends.server.loggers.LogPublisher"); 195 PD_JAVA_CLASS = builder.getInstance(); 196 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 197 } 198 199 200 201 /** Build the "override-severity" property definition. */ 202 static { 203 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "override-severity"); 204 builder.setOption(PropertyOption.MULTI_VALUED); 205 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "override-severity")); 206 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "override-severity")); 207 builder.setPattern(".*", "STRING"); 208 PD_OVERRIDE_SEVERITY = builder.getInstance(); 209 INSTANCE.registerPropertyDefinition(PD_OVERRIDE_SEVERITY); 210 } 211 212 213 214 // Register the tags associated with this managed object definition. 215 static { 216 INSTANCE.registerTag(Tag.valueOf("logging")); 217 } 218 219 220 221 /** 222 * Get the Error Log Publisher configuration definition singleton. 223 * 224 * @return Returns the Error Log Publisher configuration definition 225 * singleton. 226 */ 227 public static ErrorLogPublisherCfgDefn getInstance() { 228 return INSTANCE; 229 } 230 231 232 233 /** 234 * Private constructor. 235 */ 236 private ErrorLogPublisherCfgDefn() { 237 super("error-log-publisher", LogPublisherCfgDefn.getInstance()); 238 } 239 240 241 242 /** {@inheritDoc} */ 243 public ErrorLogPublisherCfgClient createClientConfiguration( 244 ManagedObject<? extends ErrorLogPublisherCfgClient> impl) { 245 return new ErrorLogPublisherCfgClientImpl(impl); 246 } 247 248 249 250 /** {@inheritDoc} */ 251 public ErrorLogPublisherCfg createServerConfiguration( 252 ServerManagedObject<? extends ErrorLogPublisherCfg> impl) { 253 return new ErrorLogPublisherCfgServerImpl(impl); 254 } 255 256 257 258 /** {@inheritDoc} */ 259 public Class<ErrorLogPublisherCfg> getServerConfigurationClass() { 260 return ErrorLogPublisherCfg.class; 261 } 262 263 264 265 /** 266 * Get the "default-severity" property definition. 267 * <p> 268 * Specifies the default severity levels for the logger. 269 * 270 * @return Returns the "default-severity" property definition. 271 */ 272 public EnumPropertyDefinition<DefaultSeverity> getDefaultSeverityPropertyDefinition() { 273 return PD_DEFAULT_SEVERITY; 274 } 275 276 277 278 /** 279 * Get the "enabled" property definition. 280 * <p> 281 * Indicates whether the Error Log Publisher is enabled for use. 282 * 283 * @return Returns the "enabled" property definition. 284 */ 285 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 286 return LogPublisherCfgDefn.getInstance().getEnabledPropertyDefinition(); 287 } 288 289 290 291 /** 292 * Get the "java-class" property definition. 293 * <p> 294 * The fully-qualified name of the Java class that provides the 295 * Error Log Publisher implementation. 296 * 297 * @return Returns the "java-class" property definition. 298 */ 299 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 300 return PD_JAVA_CLASS; 301 } 302 303 304 305 /** 306 * Get the "override-severity" property definition. 307 * <p> 308 * Specifies the override severity levels for the logger based on 309 * the category of the messages. 310 * <p> 311 * Each override severity level should include the category and the 312 * severity levels to log for that category, for example, 313 * core=error,info,warning. Valid categories are: core, extensions, 314 * protocol, config, log, util, schema, plugin, jeb, backend, tools, 315 * task, access-control, admin, sync, version, quicksetup, 316 * admin-tool, dsconfig, user-defined. Valid severities are: all, 317 * error, info, warning, notice, debug. 318 * 319 * @return Returns the "override-severity" property definition. 320 */ 321 public StringPropertyDefinition getOverrideSeverityPropertyDefinition() { 322 return PD_OVERRIDE_SEVERITY; 323 } 324 325 326 327 /** 328 * Managed object client implementation. 329 */ 330 private static class ErrorLogPublisherCfgClientImpl implements 331 ErrorLogPublisherCfgClient { 332 333 /** Private implementation. */ 334 private ManagedObject<? extends ErrorLogPublisherCfgClient> impl; 335 336 337 338 /** Private constructor. */ 339 private ErrorLogPublisherCfgClientImpl( 340 ManagedObject<? extends ErrorLogPublisherCfgClient> impl) { 341 this.impl = impl; 342 } 343 344 345 346 /** {@inheritDoc} */ 347 public SortedSet<DefaultSeverity> getDefaultSeverity() { 348 return impl.getPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition()); 349 } 350 351 352 353 /** {@inheritDoc} */ 354 public void setDefaultSeverity(Collection<DefaultSeverity> values) { 355 impl.setPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition(), values); 356 } 357 358 359 360 /** {@inheritDoc} */ 361 public Boolean isEnabled() { 362 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 363 } 364 365 366 367 /** {@inheritDoc} */ 368 public void setEnabled(boolean value) { 369 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 370 } 371 372 373 374 /** {@inheritDoc} */ 375 public String getJavaClass() { 376 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 377 } 378 379 380 381 /** {@inheritDoc} */ 382 public void setJavaClass(String value) { 383 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 384 } 385 386 387 388 /** {@inheritDoc} */ 389 public SortedSet<String> getOverrideSeverity() { 390 return impl.getPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition()); 391 } 392 393 394 395 /** {@inheritDoc} */ 396 public void setOverrideSeverity(Collection<String> values) { 397 impl.setPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition(), values); 398 } 399 400 401 402 /** {@inheritDoc} */ 403 public ManagedObjectDefinition<? extends ErrorLogPublisherCfgClient, ? extends ErrorLogPublisherCfg> definition() { 404 return INSTANCE; 405 } 406 407 408 409 /** {@inheritDoc} */ 410 public PropertyProvider properties() { 411 return impl; 412 } 413 414 415 416 /** {@inheritDoc} */ 417 public void commit() throws ManagedObjectAlreadyExistsException, 418 MissingMandatoryPropertiesException, ConcurrentModificationException, 419 OperationRejectedException, LdapException { 420 impl.commit(); 421 } 422 423 424 425 /** {@inheritDoc} */ 426 public String toString() { 427 return impl.toString(); 428 } 429 } 430 431 432 433 /** 434 * Managed object server implementation. 435 */ 436 private static class ErrorLogPublisherCfgServerImpl implements 437 ErrorLogPublisherCfg { 438 439 /** Private implementation. */ 440 private ServerManagedObject<? extends ErrorLogPublisherCfg> impl; 441 442 /** The value of the "default-severity" property. */ 443 private final SortedSet<DefaultSeverity> pDefaultSeverity; 444 445 /** The value of the "enabled" property. */ 446 private final boolean pEnabled; 447 448 /** The value of the "java-class" property. */ 449 private final String pJavaClass; 450 451 /** The value of the "override-severity" property. */ 452 private final SortedSet<String> pOverrideSeverity; 453 454 455 456 /** Private constructor. */ 457 private ErrorLogPublisherCfgServerImpl(ServerManagedObject<? extends ErrorLogPublisherCfg> impl) { 458 this.impl = impl; 459 this.pDefaultSeverity = impl.getPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition()); 460 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 461 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 462 this.pOverrideSeverity = impl.getPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition()); 463 } 464 465 466 467 /** {@inheritDoc} */ 468 public void addErrorChangeListener( 469 ConfigurationChangeListener<ErrorLogPublisherCfg> listener) { 470 impl.registerChangeListener(listener); 471 } 472 473 474 475 /** {@inheritDoc} */ 476 public void removeErrorChangeListener( 477 ConfigurationChangeListener<ErrorLogPublisherCfg> listener) { 478 impl.deregisterChangeListener(listener); 479 } 480 /** {@inheritDoc} */ 481 public void addChangeListener( 482 ConfigurationChangeListener<LogPublisherCfg> listener) { 483 impl.registerChangeListener(listener); 484 } 485 486 487 488 /** {@inheritDoc} */ 489 public void removeChangeListener( 490 ConfigurationChangeListener<LogPublisherCfg> listener) { 491 impl.deregisterChangeListener(listener); 492 } 493 494 495 496 /** {@inheritDoc} */ 497 public SortedSet<DefaultSeverity> getDefaultSeverity() { 498 return pDefaultSeverity; 499 } 500 501 502 503 /** {@inheritDoc} */ 504 public boolean isEnabled() { 505 return pEnabled; 506 } 507 508 509 510 /** {@inheritDoc} */ 511 public String getJavaClass() { 512 return pJavaClass; 513 } 514 515 516 517 /** {@inheritDoc} */ 518 public SortedSet<String> getOverrideSeverity() { 519 return pOverrideSeverity; 520 } 521 522 523 524 /** {@inheritDoc} */ 525 public Class<? extends ErrorLogPublisherCfg> configurationClass() { 526 return ErrorLogPublisherCfg.class; 527 } 528 529 530 531 /** {@inheritDoc} */ 532 public DN dn() { 533 return impl.getDN(); 534 } 535 536 537 538 /** {@inheritDoc} */ 539 public String toString() { 540 return impl.toString(); 541 } 542 } 543}