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