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