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.DNPropertyDefinition; 043import org.forgerock.opendj.config.DurationPropertyDefinition; 044import org.forgerock.opendj.config.EnumPropertyDefinition; 045import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException; 046import org.forgerock.opendj.config.ManagedObjectDefinition; 047import org.forgerock.opendj.config.ManagedObjectOption; 048import org.forgerock.opendj.config.PropertyException; 049import org.forgerock.opendj.config.PropertyOption; 050import org.forgerock.opendj.config.PropertyProvider; 051import org.forgerock.opendj.config.server.ConfigurationChangeListener; 052import org.forgerock.opendj.config.server.ServerManagedObject; 053import org.forgerock.opendj.config.StringPropertyDefinition; 054import org.forgerock.opendj.config.Tag; 055import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider; 056import org.forgerock.opendj.ldap.DN; 057import org.forgerock.opendj.ldap.LdapException; 058import org.forgerock.opendj.server.config.client.TaskBackendCfgClient; 059import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode; 060import org.forgerock.opendj.server.config.server.BackendCfg; 061import org.forgerock.opendj.server.config.server.TaskBackendCfg; 062 063 064 065/** 066 * An interface for querying the Task Backend managed object 067 * definition meta information. 068 * <p> 069 * The Task Backend provides a mechanism for scheduling tasks in the 070 * OpenDJ directory server. Tasks are intended to provide access to 071 * certain types of administrative functions in the server that may not 072 * be convenient to perform remotely. 073 */ 074public final class TaskBackendCfgDefn extends ManagedObjectDefinition<TaskBackendCfgClient, TaskBackendCfg> { 075 076 // The singleton configuration definition instance. 077 private static final TaskBackendCfgDefn INSTANCE = new TaskBackendCfgDefn(); 078 079 080 081 // The "java-class" property definition. 082 private static final ClassPropertyDefinition PD_JAVA_CLASS; 083 084 085 086 // The "notification-sender-address" property definition. 087 private static final StringPropertyDefinition PD_NOTIFICATION_SENDER_ADDRESS; 088 089 090 091 // The "task-backing-file" property definition. 092 private static final StringPropertyDefinition PD_TASK_BACKING_FILE; 093 094 095 096 // The "task-retention-time" property definition. 097 private static final DurationPropertyDefinition PD_TASK_RETENTION_TIME; 098 099 100 101 // The "writability-mode" property definition. 102 private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE; 103 104 105 106 // Build the "java-class" property definition. 107 static { 108 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 109 builder.setOption(PropertyOption.MANDATORY); 110 builder.setOption(PropertyOption.ADVANCED); 111 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 112 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.task.TaskBackend"); 113 builder.setDefaultBehaviorProvider(provider); 114 builder.addInstanceOf("org.opends.server.api.Backend"); 115 PD_JAVA_CLASS = builder.getInstance(); 116 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 117 } 118 119 120 121 // Build the "notification-sender-address" property definition. 122 static { 123 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "notification-sender-address"); 124 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "notification-sender-address")); 125 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<String>(INSTANCE, "notification-sender-address")); 126 PD_NOTIFICATION_SENDER_ADDRESS = builder.getInstance(); 127 INSTANCE.registerPropertyDefinition(PD_NOTIFICATION_SENDER_ADDRESS); 128 } 129 130 131 132 // Build the "task-backing-file" property definition. 133 static { 134 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "task-backing-file"); 135 builder.setOption(PropertyOption.MANDATORY); 136 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "task-backing-file")); 137 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 138 PD_TASK_BACKING_FILE = builder.getInstance(); 139 INSTANCE.registerPropertyDefinition(PD_TASK_BACKING_FILE); 140 } 141 142 143 144 // Build the "task-retention-time" property definition. 145 static { 146 DurationPropertyDefinition.Builder builder = DurationPropertyDefinition.createBuilder(INSTANCE, "task-retention-time"); 147 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "task-retention-time")); 148 DefaultBehaviorProvider<Long> provider = new DefinedDefaultBehaviorProvider<Long>("24 hours"); 149 builder.setDefaultBehaviorProvider(provider); 150 PD_TASK_RETENTION_TIME = builder.getInstance(); 151 INSTANCE.registerPropertyDefinition(PD_TASK_RETENTION_TIME); 152 } 153 154 155 156 // Build the "writability-mode" property definition. 157 static { 158 EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode"); 159 builder.setOption(PropertyOption.MANDATORY); 160 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode")); 161 DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("enabled"); 162 builder.setDefaultBehaviorProvider(provider); 163 builder.setEnumClass(WritabilityMode.class); 164 PD_WRITABILITY_MODE = builder.getInstance(); 165 INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE); 166 } 167 168 169 170 // Register the options associated with this managed object definition. 171 static { 172 INSTANCE.registerOption(ManagedObjectOption.ADVANCED); 173 } 174 175 176 177 // Register the tags associated with this managed object definition. 178 static { 179 INSTANCE.registerTag(Tag.valueOf("database")); 180 } 181 182 183 184 /** 185 * Get the Task Backend configuration definition singleton. 186 * 187 * @return Returns the Task Backend configuration definition 188 * singleton. 189 */ 190 public static TaskBackendCfgDefn getInstance() { 191 return INSTANCE; 192 } 193 194 195 196 /** 197 * Private constructor. 198 */ 199 private TaskBackendCfgDefn() { 200 super("task-backend", BackendCfgDefn.getInstance()); 201 } 202 203 204 205 /** 206 * {@inheritDoc} 207 */ 208 public TaskBackendCfgClient createClientConfiguration( 209 ManagedObject<? extends TaskBackendCfgClient> impl) { 210 return new TaskBackendCfgClientImpl(impl); 211 } 212 213 214 215 /** 216 * {@inheritDoc} 217 */ 218 public TaskBackendCfg createServerConfiguration( 219 ServerManagedObject<? extends TaskBackendCfg> impl) { 220 return new TaskBackendCfgServerImpl(impl); 221 } 222 223 224 225 /** 226 * {@inheritDoc} 227 */ 228 public Class<TaskBackendCfg> getServerConfigurationClass() { 229 return TaskBackendCfg.class; 230 } 231 232 233 234 /** 235 * Get the "backend-id" property definition. 236 * <p> 237 * Specifies a name to identify the associated backend. 238 * <p> 239 * The name must be unique among all backends in the server. The 240 * backend ID may not be altered after the backend is created in the 241 * server. 242 * 243 * @return Returns the "backend-id" property definition. 244 */ 245 public StringPropertyDefinition getBackendIdPropertyDefinition() { 246 return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition(); 247 } 248 249 250 251 /** 252 * Get the "base-dn" property definition. 253 * <p> 254 * Specifies the base DN(s) for the data that the backend handles. 255 * <p> 256 * A single backend may be responsible for one or more base DNs. 257 * Note that no two backends may have the same base DN although one 258 * backend may have a base DN that is below a base DN provided by 259 * another backend (similar to the use of sub-suffixes in the Sun 260 * Java System Directory Server). If any of the base DNs is 261 * subordinate to a base DN for another backend, then all base DNs 262 * for that backend must be subordinate to that same base DN. 263 * 264 * @return Returns the "base-dn" property definition. 265 */ 266 public DNPropertyDefinition getBaseDNPropertyDefinition() { 267 return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition(); 268 } 269 270 271 272 /** 273 * Get the "enabled" property definition. 274 * <p> 275 * Indicates whether the backend is enabled in the server. 276 * <p> 277 * If a backend is not enabled, then its contents are not accessible 278 * when processing operations. 279 * 280 * @return Returns the "enabled" property definition. 281 */ 282 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 283 return BackendCfgDefn.getInstance().getEnabledPropertyDefinition(); 284 } 285 286 287 288 /** 289 * Get the "java-class" property definition. 290 * <p> 291 * Specifies the fully-qualified name of the Java class that 292 * provides the backend implementation. 293 * 294 * @return Returns the "java-class" property definition. 295 */ 296 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 297 return PD_JAVA_CLASS; 298 } 299 300 301 302 /** 303 * Get the "notification-sender-address" property definition. 304 * <p> 305 * Specifies the email address to use as the sender (that is, the 306 * "From:" address) address for notification mail messages generated 307 * when a task completes execution. 308 * 309 * @return Returns the "notification-sender-address" property definition. 310 */ 311 public StringPropertyDefinition getNotificationSenderAddressPropertyDefinition() { 312 return PD_NOTIFICATION_SENDER_ADDRESS; 313 } 314 315 316 317 /** 318 * Get the "task-backing-file" property definition. 319 * <p> 320 * Specifies the path to the backing file for storing information 321 * about the tasks configured in the server. 322 * <p> 323 * It may be either an absolute path or a relative path to the base 324 * of the OpenDJ directory server instance. 325 * 326 * @return Returns the "task-backing-file" property definition. 327 */ 328 public StringPropertyDefinition getTaskBackingFilePropertyDefinition() { 329 return PD_TASK_BACKING_FILE; 330 } 331 332 333 334 /** 335 * Get the "task-retention-time" property definition. 336 * <p> 337 * Specifies the length of time that task entries should be retained 338 * after processing on the associated task has been completed. 339 * 340 * @return Returns the "task-retention-time" property definition. 341 */ 342 public DurationPropertyDefinition getTaskRetentionTimePropertyDefinition() { 343 return PD_TASK_RETENTION_TIME; 344 } 345 346 347 348 /** 349 * Get the "writability-mode" property definition. 350 * <p> 351 * Specifies the behavior that the backend should use when 352 * processing write operations. 353 * 354 * @return Returns the "writability-mode" property definition. 355 */ 356 public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() { 357 return PD_WRITABILITY_MODE; 358 } 359 360 361 362 /** 363 * Managed object client implementation. 364 */ 365 private static class TaskBackendCfgClientImpl implements 366 TaskBackendCfgClient { 367 368 // Private implementation. 369 private ManagedObject<? extends TaskBackendCfgClient> impl; 370 371 372 373 // Private constructor. 374 private TaskBackendCfgClientImpl( 375 ManagedObject<? extends TaskBackendCfgClient> impl) { 376 this.impl = impl; 377 } 378 379 380 381 /** 382 * {@inheritDoc} 383 */ 384 public String getBackendId() { 385 return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 386 } 387 388 389 390 /** 391 * {@inheritDoc} 392 */ 393 public void setBackendId(String value) throws PropertyException { 394 impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value); 395 } 396 397 398 399 /** 400 * {@inheritDoc} 401 */ 402 public SortedSet<DN> getBaseDN() { 403 return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 404 } 405 406 407 408 /** 409 * {@inheritDoc} 410 */ 411 public void setBaseDN(Collection<DN> values) { 412 impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values); 413 } 414 415 416 417 /** 418 * {@inheritDoc} 419 */ 420 public Boolean isEnabled() { 421 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 422 } 423 424 425 426 /** 427 * {@inheritDoc} 428 */ 429 public void setEnabled(boolean value) { 430 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 431 } 432 433 434 435 /** 436 * {@inheritDoc} 437 */ 438 public String getJavaClass() { 439 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 440 } 441 442 443 444 /** 445 * {@inheritDoc} 446 */ 447 public void setJavaClass(String value) { 448 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 449 } 450 451 452 453 /** 454 * {@inheritDoc} 455 */ 456 public String getNotificationSenderAddress() { 457 return impl.getPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition()); 458 } 459 460 461 462 /** 463 * {@inheritDoc} 464 */ 465 public void setNotificationSenderAddress(String value) { 466 impl.setPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition(), value); 467 } 468 469 470 471 /** 472 * {@inheritDoc} 473 */ 474 public String getTaskBackingFile() { 475 return impl.getPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition()); 476 } 477 478 479 480 /** 481 * {@inheritDoc} 482 */ 483 public void setTaskBackingFile(String value) { 484 impl.setPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition(), value); 485 } 486 487 488 489 /** 490 * {@inheritDoc} 491 */ 492 public long getTaskRetentionTime() { 493 return impl.getPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition()); 494 } 495 496 497 498 /** 499 * {@inheritDoc} 500 */ 501 public void setTaskRetentionTime(Long value) { 502 impl.setPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition(), value); 503 } 504 505 506 507 /** 508 * {@inheritDoc} 509 */ 510 public WritabilityMode getWritabilityMode() { 511 return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 512 } 513 514 515 516 /** 517 * {@inheritDoc} 518 */ 519 public void setWritabilityMode(WritabilityMode value) { 520 impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value); 521 } 522 523 524 525 /** 526 * {@inheritDoc} 527 */ 528 public ManagedObjectDefinition<? extends TaskBackendCfgClient, ? extends TaskBackendCfg> definition() { 529 return INSTANCE; 530 } 531 532 533 534 /** 535 * {@inheritDoc} 536 */ 537 public PropertyProvider properties() { 538 return impl; 539 } 540 541 542 543 /** 544 * {@inheritDoc} 545 */ 546 public void commit() throws ManagedObjectAlreadyExistsException, 547 MissingMandatoryPropertiesException, ConcurrentModificationException, 548 OperationRejectedException, LdapException { 549 impl.commit(); 550 } 551 552 } 553 554 555 556 /** 557 * Managed object server implementation. 558 */ 559 private static class TaskBackendCfgServerImpl implements 560 TaskBackendCfg { 561 562 // Private implementation. 563 private ServerManagedObject<? extends TaskBackendCfg> impl; 564 565 // The value of the "backend-id" property. 566 private final String pBackendId; 567 568 // The value of the "base-dn" property. 569 private final SortedSet<DN> pBaseDN; 570 571 // The value of the "enabled" property. 572 private final boolean pEnabled; 573 574 // The value of the "java-class" property. 575 private final String pJavaClass; 576 577 // The value of the "notification-sender-address" property. 578 private final String pNotificationSenderAddress; 579 580 // The value of the "task-backing-file" property. 581 private final String pTaskBackingFile; 582 583 // The value of the "task-retention-time" property. 584 private final long pTaskRetentionTime; 585 586 // The value of the "writability-mode" property. 587 private final WritabilityMode pWritabilityMode; 588 589 590 591 // Private constructor. 592 private TaskBackendCfgServerImpl(ServerManagedObject<? extends TaskBackendCfg> impl) { 593 this.impl = impl; 594 this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition()); 595 this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition()); 596 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 597 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 598 this.pNotificationSenderAddress = impl.getPropertyValue(INSTANCE.getNotificationSenderAddressPropertyDefinition()); 599 this.pTaskBackingFile = impl.getPropertyValue(INSTANCE.getTaskBackingFilePropertyDefinition()); 600 this.pTaskRetentionTime = impl.getPropertyValue(INSTANCE.getTaskRetentionTimePropertyDefinition()); 601 this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition()); 602 } 603 604 605 606 /** 607 * {@inheritDoc} 608 */ 609 public void addTaskChangeListener( 610 ConfigurationChangeListener<TaskBackendCfg> listener) { 611 impl.registerChangeListener(listener); 612 } 613 614 615 616 /** 617 * {@inheritDoc} 618 */ 619 public void removeTaskChangeListener( 620 ConfigurationChangeListener<TaskBackendCfg> listener) { 621 impl.deregisterChangeListener(listener); 622 } 623 /** 624 * {@inheritDoc} 625 */ 626 public void addChangeListener( 627 ConfigurationChangeListener<BackendCfg> listener) { 628 impl.registerChangeListener(listener); 629 } 630 631 632 633 /** 634 * {@inheritDoc} 635 */ 636 public void removeChangeListener( 637 ConfigurationChangeListener<BackendCfg> listener) { 638 impl.deregisterChangeListener(listener); 639 } 640 641 642 643 /** 644 * {@inheritDoc} 645 */ 646 public String getBackendId() { 647 return pBackendId; 648 } 649 650 651 652 /** 653 * {@inheritDoc} 654 */ 655 public SortedSet<DN> getBaseDN() { 656 return pBaseDN; 657 } 658 659 660 661 /** 662 * {@inheritDoc} 663 */ 664 public boolean isEnabled() { 665 return pEnabled; 666 } 667 668 669 670 /** 671 * {@inheritDoc} 672 */ 673 public String getJavaClass() { 674 return pJavaClass; 675 } 676 677 678 679 /** 680 * {@inheritDoc} 681 */ 682 public String getNotificationSenderAddress() { 683 return pNotificationSenderAddress; 684 } 685 686 687 688 /** 689 * {@inheritDoc} 690 */ 691 public String getTaskBackingFile() { 692 return pTaskBackingFile; 693 } 694 695 696 697 /** 698 * {@inheritDoc} 699 */ 700 public long getTaskRetentionTime() { 701 return pTaskRetentionTime; 702 } 703 704 705 706 /** 707 * {@inheritDoc} 708 */ 709 public WritabilityMode getWritabilityMode() { 710 return pWritabilityMode; 711 } 712 713 714 715 /** 716 * {@inheritDoc} 717 */ 718 public Class<? extends TaskBackendCfg> configurationClass() { 719 return TaskBackendCfg.class; 720 } 721 722 723 724 /** 725 * {@inheritDoc} 726 */ 727 public DN dn() { 728 return impl.getDN(); 729 } 730 731 } 732}