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