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.BooleanPropertyDefinition;
034import org.forgerock.opendj.config.ClassPropertyDefinition;
035import org.forgerock.opendj.config.client.ConcurrentModificationException;
036import org.forgerock.opendj.config.client.ManagedObject;
037import org.forgerock.opendj.config.client.MissingMandatoryPropertiesException;
038import org.forgerock.opendj.config.client.OperationRejectedException;
039import org.forgerock.opendj.config.DefaultBehaviorProvider;
040import org.forgerock.opendj.config.DefinedDefaultBehaviorProvider;
041import org.forgerock.opendj.config.DNPropertyDefinition;
042import org.forgerock.opendj.config.EnumPropertyDefinition;
043import org.forgerock.opendj.config.ManagedObjectAlreadyExistsException;
044import org.forgerock.opendj.config.ManagedObjectDefinition;
045import org.forgerock.opendj.config.ManagedObjectOption;
046import org.forgerock.opendj.config.PropertyException;
047import org.forgerock.opendj.config.PropertyOption;
048import org.forgerock.opendj.config.PropertyProvider;
049import org.forgerock.opendj.config.server.ConfigurationChangeListener;
050import org.forgerock.opendj.config.server.ServerManagedObject;
051import org.forgerock.opendj.config.StringPropertyDefinition;
052import org.forgerock.opendj.config.Tag;
053import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
054import org.forgerock.opendj.ldap.DN;
055import org.forgerock.opendj.ldap.LdapException;
056import org.forgerock.opendj.server.config.client.BackupBackendCfgClient;
057import org.forgerock.opendj.server.config.meta.BackendCfgDefn.WritabilityMode;
058import org.forgerock.opendj.server.config.server.BackendCfg;
059import org.forgerock.opendj.server.config.server.BackupBackendCfg;
060
061
062
063/**
064 * An interface for querying the Backup Backend managed object
065 * definition meta information.
066 * <p>
067 * The Backup Backend provides read-only access to the set of backups
068 * that are available for OpenDJ.
069 */
070public final class BackupBackendCfgDefn extends ManagedObjectDefinition<BackupBackendCfgClient, BackupBackendCfg> {
071
072  // The singleton configuration definition instance.
073  private static final BackupBackendCfgDefn INSTANCE = new BackupBackendCfgDefn();
074
075
076
077  // The "backup-directory" property definition.
078  private static final StringPropertyDefinition PD_BACKUP_DIRECTORY;
079
080
081
082  // The "java-class" property definition.
083  private static final ClassPropertyDefinition PD_JAVA_CLASS;
084
085
086
087  // The "writability-mode" property definition.
088  private static final EnumPropertyDefinition<WritabilityMode> PD_WRITABILITY_MODE;
089
090
091
092  // Build the "backup-directory" property definition.
093  static {
094      StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "backup-directory");
095      builder.setOption(PropertyOption.MULTI_VALUED);
096      builder.setOption(PropertyOption.MANDATORY);
097      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "backup-directory"));
098      builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>());
099      PD_BACKUP_DIRECTORY = builder.getInstance();
100      INSTANCE.registerPropertyDefinition(PD_BACKUP_DIRECTORY);
101  }
102
103
104
105  // Build the "java-class" property definition.
106  static {
107      ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class");
108      builder.setOption(PropertyOption.MANDATORY);
109      builder.setOption(PropertyOption.ADVANCED);
110      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class"));
111      DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.backends.BackupBackend");
112      builder.setDefaultBehaviorProvider(provider);
113      builder.addInstanceOf("org.opends.server.api.Backend");
114      PD_JAVA_CLASS = builder.getInstance();
115      INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS);
116  }
117
118
119
120  // Build the "writability-mode" property definition.
121  static {
122      EnumPropertyDefinition.Builder<WritabilityMode> builder = EnumPropertyDefinition.createBuilder(INSTANCE, "writability-mode");
123      builder.setOption(PropertyOption.MANDATORY);
124      builder.setOption(PropertyOption.ADVANCED);
125      builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "writability-mode"));
126      DefaultBehaviorProvider<WritabilityMode> provider = new DefinedDefaultBehaviorProvider<WritabilityMode>("disabled");
127      builder.setDefaultBehaviorProvider(provider);
128      builder.setEnumClass(WritabilityMode.class);
129      PD_WRITABILITY_MODE = builder.getInstance();
130      INSTANCE.registerPropertyDefinition(PD_WRITABILITY_MODE);
131  }
132
133
134
135  // Register the options associated with this managed object definition.
136  static {
137    INSTANCE.registerOption(ManagedObjectOption.ADVANCED);
138  }
139
140
141
142  // Register the tags associated with this managed object definition.
143  static {
144    INSTANCE.registerTag(Tag.valueOf("database"));
145  }
146
147
148
149  /**
150   * Get the Backup Backend configuration definition singleton.
151   *
152   * @return Returns the Backup Backend configuration definition
153   *         singleton.
154   */
155  public static BackupBackendCfgDefn getInstance() {
156    return INSTANCE;
157  }
158
159
160
161  /**
162   * Private constructor.
163   */
164  private BackupBackendCfgDefn() {
165    super("backup-backend", BackendCfgDefn.getInstance());
166  }
167
168
169
170  /**
171   * {@inheritDoc}
172   */
173  public BackupBackendCfgClient createClientConfiguration(
174      ManagedObject<? extends BackupBackendCfgClient> impl) {
175    return new BackupBackendCfgClientImpl(impl);
176  }
177
178
179
180  /**
181   * {@inheritDoc}
182   */
183  public BackupBackendCfg createServerConfiguration(
184      ServerManagedObject<? extends BackupBackendCfg> impl) {
185    return new BackupBackendCfgServerImpl(impl);
186  }
187
188
189
190  /**
191   * {@inheritDoc}
192   */
193  public Class<BackupBackendCfg> getServerConfigurationClass() {
194    return BackupBackendCfg.class;
195  }
196
197
198
199  /**
200   * Get the "backend-id" property definition.
201   * <p>
202   * Specifies a name to identify the associated backend.
203   * <p>
204   * The name must be unique among all backends in the server. The
205   * backend ID may not be altered after the backend is created in the
206   * server.
207   *
208   * @return Returns the "backend-id" property definition.
209   */
210  public StringPropertyDefinition getBackendIdPropertyDefinition() {
211    return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
212  }
213
214
215
216  /**
217   * Get the "backup-directory" property definition.
218   * <p>
219   * Specifies the path to a backup directory containing one or more
220   * backups for a particular backend.
221   * <p>
222   * This is a multivalued property. Each value may specify a
223   * different backup directory if desired (one for each backend for
224   * which backups are taken). Values may be either absolute paths or
225   * paths that are relative to the base of the OpenDJ directory server
226   * installation.
227   *
228   * @return Returns the "backup-directory" property definition.
229   */
230  public StringPropertyDefinition getBackupDirectoryPropertyDefinition() {
231    return PD_BACKUP_DIRECTORY;
232  }
233
234
235
236  /**
237   * Get the "base-dn" property definition.
238   * <p>
239   * Specifies the base DN(s) for the data that the backend handles.
240   * <p>
241   * A single backend may be responsible for one or more base DNs.
242   * Note that no two backends may have the same base DN although one
243   * backend may have a base DN that is below a base DN provided by
244   * another backend (similar to the use of sub-suffixes in the Sun
245   * Java System Directory Server). If any of the base DNs is
246   * subordinate to a base DN for another backend, then all base DNs
247   * for that backend must be subordinate to that same base DN.
248   *
249   * @return Returns the "base-dn" property definition.
250   */
251  public DNPropertyDefinition getBaseDNPropertyDefinition() {
252    return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
253  }
254
255
256
257  /**
258   * Get the "enabled" property definition.
259   * <p>
260   * Indicates whether the backend is enabled in the server.
261   * <p>
262   * If a backend is not enabled, then its contents are not accessible
263   * when processing operations.
264   *
265   * @return Returns the "enabled" property definition.
266   */
267  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
268    return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
269  }
270
271
272
273  /**
274   * Get the "java-class" property definition.
275   * <p>
276   * Specifies the fully-qualified name of the Java class that
277   * provides the backend implementation.
278   *
279   * @return Returns the "java-class" property definition.
280   */
281  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
282    return PD_JAVA_CLASS;
283  }
284
285
286
287  /**
288   * Get the "writability-mode" property definition.
289   * <p>
290   * Specifies the behavior that the backend should use when
291   * processing write operations.
292   *
293   * @return Returns the "writability-mode" property definition.
294   */
295  public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
296    return PD_WRITABILITY_MODE;
297  }
298
299
300
301  /**
302   * Managed object client implementation.
303   */
304  private static class BackupBackendCfgClientImpl implements
305    BackupBackendCfgClient {
306
307    // Private implementation.
308    private ManagedObject<? extends BackupBackendCfgClient> impl;
309
310
311
312    // Private constructor.
313    private BackupBackendCfgClientImpl(
314        ManagedObject<? extends BackupBackendCfgClient> impl) {
315      this.impl = impl;
316    }
317
318
319
320    /**
321     * {@inheritDoc}
322     */
323    public String getBackendId() {
324      return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
325    }
326
327
328
329    /**
330     * {@inheritDoc}
331     */
332    public void setBackendId(String value) throws PropertyException {
333      impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
334    }
335
336
337
338    /**
339     * {@inheritDoc}
340     */
341    public SortedSet<String> getBackupDirectory() {
342      return impl.getPropertyValues(INSTANCE.getBackupDirectoryPropertyDefinition());
343    }
344
345
346
347    /**
348     * {@inheritDoc}
349     */
350    public void setBackupDirectory(Collection<String> values) {
351      impl.setPropertyValues(INSTANCE.getBackupDirectoryPropertyDefinition(), values);
352    }
353
354
355
356    /**
357     * {@inheritDoc}
358     */
359    public SortedSet<DN> getBaseDN() {
360      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
361    }
362
363
364
365    /**
366     * {@inheritDoc}
367     */
368    public void setBaseDN(Collection<DN> values) {
369      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
370    }
371
372
373
374    /**
375     * {@inheritDoc}
376     */
377    public Boolean isEnabled() {
378      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
379    }
380
381
382
383    /**
384     * {@inheritDoc}
385     */
386    public void setEnabled(boolean value) {
387      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
388    }
389
390
391
392    /**
393     * {@inheritDoc}
394     */
395    public String getJavaClass() {
396      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
397    }
398
399
400
401    /**
402     * {@inheritDoc}
403     */
404    public void setJavaClass(String value) {
405      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
406    }
407
408
409
410    /**
411     * {@inheritDoc}
412     */
413    public WritabilityMode getWritabilityMode() {
414      return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
415    }
416
417
418
419    /**
420     * {@inheritDoc}
421     */
422    public void setWritabilityMode(WritabilityMode value) {
423      impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
424    }
425
426
427
428    /**
429     * {@inheritDoc}
430     */
431    public ManagedObjectDefinition<? extends BackupBackendCfgClient, ? extends BackupBackendCfg> definition() {
432      return INSTANCE;
433    }
434
435
436
437    /**
438     * {@inheritDoc}
439     */
440    public PropertyProvider properties() {
441      return impl;
442    }
443
444
445
446    /**
447     * {@inheritDoc}
448     */
449    public void commit() throws ManagedObjectAlreadyExistsException,
450        MissingMandatoryPropertiesException, ConcurrentModificationException,
451        OperationRejectedException, LdapException {
452      impl.commit();
453    }
454
455  }
456
457
458
459  /**
460   * Managed object server implementation.
461   */
462  private static class BackupBackendCfgServerImpl implements
463    BackupBackendCfg {
464
465    // Private implementation.
466    private ServerManagedObject<? extends BackupBackendCfg> impl;
467
468    // The value of the "backend-id" property.
469    private final String pBackendId;
470
471    // The value of the "backup-directory" property.
472    private final SortedSet<String> pBackupDirectory;
473
474    // The value of the "base-dn" property.
475    private final SortedSet<DN> pBaseDN;
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 "writability-mode" property.
484    private final WritabilityMode pWritabilityMode;
485
486
487
488    // Private constructor.
489    private BackupBackendCfgServerImpl(ServerManagedObject<? extends BackupBackendCfg> impl) {
490      this.impl = impl;
491      this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
492      this.pBackupDirectory = impl.getPropertyValues(INSTANCE.getBackupDirectoryPropertyDefinition());
493      this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
494      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
495      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
496      this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
497    }
498
499
500
501    /**
502     * {@inheritDoc}
503     */
504    public void addBackupChangeListener(
505        ConfigurationChangeListener<BackupBackendCfg> listener) {
506      impl.registerChangeListener(listener);
507    }
508
509
510
511    /**
512     * {@inheritDoc}
513     */
514    public void removeBackupChangeListener(
515        ConfigurationChangeListener<BackupBackendCfg> listener) {
516      impl.deregisterChangeListener(listener);
517    }
518    /**
519     * {@inheritDoc}
520     */
521    public void addChangeListener(
522        ConfigurationChangeListener<BackendCfg> listener) {
523      impl.registerChangeListener(listener);
524    }
525
526
527
528    /**
529     * {@inheritDoc}
530     */
531    public void removeChangeListener(
532        ConfigurationChangeListener<BackendCfg> listener) {
533      impl.deregisterChangeListener(listener);
534    }
535
536
537
538    /**
539     * {@inheritDoc}
540     */
541    public String getBackendId() {
542      return pBackendId;
543    }
544
545
546
547    /**
548     * {@inheritDoc}
549     */
550    public SortedSet<String> getBackupDirectory() {
551      return pBackupDirectory;
552    }
553
554
555
556    /**
557     * {@inheritDoc}
558     */
559    public SortedSet<DN> getBaseDN() {
560      return pBaseDN;
561    }
562
563
564
565    /**
566     * {@inheritDoc}
567     */
568    public boolean isEnabled() {
569      return pEnabled;
570    }
571
572
573
574    /**
575     * {@inheritDoc}
576     */
577    public String getJavaClass() {
578      return pJavaClass;
579    }
580
581
582
583    /**
584     * {@inheritDoc}
585     */
586    public WritabilityMode getWritabilityMode() {
587      return pWritabilityMode;
588    }
589
590
591
592    /**
593     * {@inheritDoc}
594     */
595    public Class<? extends BackupBackendCfg> configurationClass() {
596      return BackupBackendCfg.class;
597    }
598
599
600
601    /**
602     * {@inheritDoc}
603     */
604    public DN dn() {
605      return impl.getDN();
606    }
607
608  }
609}