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