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 /** 152 * {@inheritDoc} 153 */ 154 public String toString() { return name; } 155 156 } 157 158 159 160 // The "default-severity" property definition. 161 private static final EnumPropertyDefinition<DefaultSeverity> PD_DEFAULT_SEVERITY; 162 163 164 165 // The "java-class" property definition. 166 private static final ClassPropertyDefinition PD_JAVA_CLASS; 167 168 169 170 // The "override-severity" property definition. 171 private static final StringPropertyDefinition PD_OVERRIDE_SEVERITY; 172 173 174 175 // Build the "default-severity" property definition. 176 static { 177 EnumPropertyDefinition.Builder<DefaultSeverity> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "default-severity"); 178 builder.setOption(PropertyOption.MULTI_VALUED); 179 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "default-severity")); 180 DefaultBehaviorProvider<DefaultSeverity> provider = new DefinedDefaultBehaviorProvider<DefaultSeverity>("error", "warning"); 181 builder.setDefaultBehaviorProvider(provider); 182 builder.setEnumClass(DefaultSeverity.class); 183 PD_DEFAULT_SEVERITY = builder.getInstance(); 184 INSTANCE.registerPropertyDefinition(PD_DEFAULT_SEVERITY); 185 } 186 187 188 189 // Build the "java-class" property definition. 190 static { 191 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 192 builder.setOption(PropertyOption.MANDATORY); 193 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 194 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.ErrorLogPublisher"); 195 builder.setDefaultBehaviorProvider(provider); 196 builder.addInstanceOf("org.opends.server.loggers.LogPublisher"); 197 PD_JAVA_CLASS = builder.getInstance(); 198 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 199 } 200 201 202 203 // Build the "override-severity" property definition. 204 static { 205 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "override-severity"); 206 builder.setOption(PropertyOption.MULTI_VALUED); 207 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "override-severity")); 208 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "override-severity")); 209 builder.setPattern(".*", "STRING"); 210 PD_OVERRIDE_SEVERITY = builder.getInstance(); 211 INSTANCE.registerPropertyDefinition(PD_OVERRIDE_SEVERITY); 212 } 213 214 215 216 // Register the tags associated with this managed object definition. 217 static { 218 INSTANCE.registerTag(Tag.valueOf("logging")); 219 } 220 221 222 223 /** 224 * Get the Error Log Publisher configuration definition singleton. 225 * 226 * @return Returns the Error Log Publisher configuration definition 227 * singleton. 228 */ 229 public static ErrorLogPublisherCfgDefn getInstance() { 230 return INSTANCE; 231 } 232 233 234 235 /** 236 * Private constructor. 237 */ 238 private ErrorLogPublisherCfgDefn() { 239 super("error-log-publisher", LogPublisherCfgDefn.getInstance()); 240 } 241 242 243 244 /** 245 * {@inheritDoc} 246 */ 247 public ErrorLogPublisherCfgClient createClientConfiguration( 248 ManagedObject<? extends ErrorLogPublisherCfgClient> impl) { 249 return new ErrorLogPublisherCfgClientImpl(impl); 250 } 251 252 253 254 /** 255 * {@inheritDoc} 256 */ 257 public ErrorLogPublisherCfg createServerConfiguration( 258 ServerManagedObject<? extends ErrorLogPublisherCfg> impl) { 259 return new ErrorLogPublisherCfgServerImpl(impl); 260 } 261 262 263 264 /** 265 * {@inheritDoc} 266 */ 267 public Class<ErrorLogPublisherCfg> getServerConfigurationClass() { 268 return ErrorLogPublisherCfg.class; 269 } 270 271 272 273 /** 274 * Get the "default-severity" property definition. 275 * <p> 276 * Specifies the default severity levels for the logger. 277 * 278 * @return Returns the "default-severity" property definition. 279 */ 280 public EnumPropertyDefinition<DefaultSeverity> getDefaultSeverityPropertyDefinition() { 281 return PD_DEFAULT_SEVERITY; 282 } 283 284 285 286 /** 287 * Get the "enabled" property definition. 288 * <p> 289 * Indicates whether the Error Log Publisher is enabled for use. 290 * 291 * @return Returns the "enabled" property definition. 292 */ 293 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 294 return LogPublisherCfgDefn.getInstance().getEnabledPropertyDefinition(); 295 } 296 297 298 299 /** 300 * Get the "java-class" property definition. 301 * <p> 302 * The fully-qualified name of the Java class that provides the 303 * Error Log Publisher implementation. 304 * 305 * @return Returns the "java-class" property definition. 306 */ 307 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 308 return PD_JAVA_CLASS; 309 } 310 311 312 313 /** 314 * Get the "override-severity" property definition. 315 * <p> 316 * Specifies the override severity levels for the logger based on 317 * the category of the messages. 318 * <p> 319 * Each override severity level should include the category and the 320 * severity levels to log for that category, for example, 321 * core=error,info,warning. Valid categories are: core, extensions, 322 * protocol, config, log, util, schema, plugin, jeb, backend, tools, 323 * task, access-control, admin, sync, version, quicksetup, 324 * admin-tool, dsconfig, user-defined. Valid severities are: all, 325 * error, info, warning, notice, debug. 326 * 327 * @return Returns the "override-severity" property definition. 328 */ 329 public StringPropertyDefinition getOverrideSeverityPropertyDefinition() { 330 return PD_OVERRIDE_SEVERITY; 331 } 332 333 334 335 /** 336 * Managed object client implementation. 337 */ 338 private static class ErrorLogPublisherCfgClientImpl implements 339 ErrorLogPublisherCfgClient { 340 341 // Private implementation. 342 private ManagedObject<? extends ErrorLogPublisherCfgClient> impl; 343 344 345 346 // Private constructor. 347 private ErrorLogPublisherCfgClientImpl( 348 ManagedObject<? extends ErrorLogPublisherCfgClient> impl) { 349 this.impl = impl; 350 } 351 352 353 354 /** 355 * {@inheritDoc} 356 */ 357 public SortedSet<DefaultSeverity> getDefaultSeverity() { 358 return impl.getPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition()); 359 } 360 361 362 363 /** 364 * {@inheritDoc} 365 */ 366 public void setDefaultSeverity(Collection<DefaultSeverity> values) { 367 impl.setPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition(), values); 368 } 369 370 371 372 /** 373 * {@inheritDoc} 374 */ 375 public Boolean isEnabled() { 376 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 377 } 378 379 380 381 /** 382 * {@inheritDoc} 383 */ 384 public void setEnabled(boolean value) { 385 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 386 } 387 388 389 390 /** 391 * {@inheritDoc} 392 */ 393 public String getJavaClass() { 394 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 395 } 396 397 398 399 /** 400 * {@inheritDoc} 401 */ 402 public void setJavaClass(String value) { 403 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 404 } 405 406 407 408 /** 409 * {@inheritDoc} 410 */ 411 public SortedSet<String> getOverrideSeverity() { 412 return impl.getPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition()); 413 } 414 415 416 417 /** 418 * {@inheritDoc} 419 */ 420 public void setOverrideSeverity(Collection<String> values) { 421 impl.setPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition(), values); 422 } 423 424 425 426 /** 427 * {@inheritDoc} 428 */ 429 public ManagedObjectDefinition<? extends ErrorLogPublisherCfgClient, ? extends ErrorLogPublisherCfg> definition() { 430 return INSTANCE; 431 } 432 433 434 435 /** 436 * {@inheritDoc} 437 */ 438 public PropertyProvider properties() { 439 return impl; 440 } 441 442 443 444 /** 445 * {@inheritDoc} 446 */ 447 public void commit() throws ManagedObjectAlreadyExistsException, 448 MissingMandatoryPropertiesException, ConcurrentModificationException, 449 OperationRejectedException, LdapException { 450 impl.commit(); 451 } 452 453 } 454 455 456 457 /** 458 * Managed object server implementation. 459 */ 460 private static class ErrorLogPublisherCfgServerImpl implements 461 ErrorLogPublisherCfg { 462 463 // Private implementation. 464 private ServerManagedObject<? extends ErrorLogPublisherCfg> impl; 465 466 // The value of the "default-severity" property. 467 private final SortedSet<DefaultSeverity> pDefaultSeverity; 468 469 // The value of the "enabled" property. 470 private final boolean pEnabled; 471 472 // The value of the "java-class" property. 473 private final String pJavaClass; 474 475 // The value of the "override-severity" property. 476 private final SortedSet<String> pOverrideSeverity; 477 478 479 480 // Private constructor. 481 private ErrorLogPublisherCfgServerImpl(ServerManagedObject<? extends ErrorLogPublisherCfg> impl) { 482 this.impl = impl; 483 this.pDefaultSeverity = impl.getPropertyValues(INSTANCE.getDefaultSeverityPropertyDefinition()); 484 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 485 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 486 this.pOverrideSeverity = impl.getPropertyValues(INSTANCE.getOverrideSeverityPropertyDefinition()); 487 } 488 489 490 491 /** 492 * {@inheritDoc} 493 */ 494 public void addErrorChangeListener( 495 ConfigurationChangeListener<ErrorLogPublisherCfg> listener) { 496 impl.registerChangeListener(listener); 497 } 498 499 500 501 /** 502 * {@inheritDoc} 503 */ 504 public void removeErrorChangeListener( 505 ConfigurationChangeListener<ErrorLogPublisherCfg> listener) { 506 impl.deregisterChangeListener(listener); 507 } 508 /** 509 * {@inheritDoc} 510 */ 511 public void addChangeListener( 512 ConfigurationChangeListener<LogPublisherCfg> listener) { 513 impl.registerChangeListener(listener); 514 } 515 516 517 518 /** 519 * {@inheritDoc} 520 */ 521 public void removeChangeListener( 522 ConfigurationChangeListener<LogPublisherCfg> listener) { 523 impl.deregisterChangeListener(listener); 524 } 525 526 527 528 /** 529 * {@inheritDoc} 530 */ 531 public SortedSet<DefaultSeverity> getDefaultSeverity() { 532 return pDefaultSeverity; 533 } 534 535 536 537 /** 538 * {@inheritDoc} 539 */ 540 public boolean isEnabled() { 541 return pEnabled; 542 } 543 544 545 546 /** 547 * {@inheritDoc} 548 */ 549 public String getJavaClass() { 550 return pJavaClass; 551 } 552 553 554 555 /** 556 * {@inheritDoc} 557 */ 558 public SortedSet<String> getOverrideSeverity() { 559 return pOverrideSeverity; 560 } 561 562 563 564 /** 565 * {@inheritDoc} 566 */ 567 public Class<? extends ErrorLogPublisherCfg> configurationClass() { 568 return ErrorLogPublisherCfg.class; 569 } 570 571 572 573 /** 574 * {@inheritDoc} 575 */ 576 public DN dn() { 577 return impl.getDN(); 578 } 579 580 } 581}