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