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