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  /** {@inheritDoc} */
171  public BackupBackendCfgClient createClientConfiguration(
172      ManagedObject<? extends BackupBackendCfgClient> impl) {
173    return new BackupBackendCfgClientImpl(impl);
174  }
175
176
177
178  /** {@inheritDoc} */
179  public BackupBackendCfg createServerConfiguration(
180      ServerManagedObject<? extends BackupBackendCfg> impl) {
181    return new BackupBackendCfgServerImpl(impl);
182  }
183
184
185
186  /** {@inheritDoc} */
187  public Class<BackupBackendCfg> getServerConfigurationClass() {
188    return BackupBackendCfg.class;
189  }
190
191
192
193  /**
194   * Get the "backend-id" property definition.
195   * <p>
196   * Specifies a name to identify the associated backend.
197   * <p>
198   * The name must be unique among all backends in the server. The
199   * backend ID may not be altered after the backend is created in the
200   * server.
201   *
202   * @return Returns the "backend-id" property definition.
203   */
204  public StringPropertyDefinition getBackendIdPropertyDefinition() {
205    return BackendCfgDefn.getInstance().getBackendIdPropertyDefinition();
206  }
207
208
209
210  /**
211   * Get the "backup-directory" property definition.
212   * <p>
213   * Specifies the path to a backup directory containing one or more
214   * backups for a particular backend.
215   * <p>
216   * This is a multivalued property. Each value may specify a
217   * different backup directory if desired (one for each backend for
218   * which backups are taken). Values may be either absolute paths or
219   * paths that are relative to the base of the OpenDJ directory server
220   * installation.
221   *
222   * @return Returns the "backup-directory" property definition.
223   */
224  public StringPropertyDefinition getBackupDirectoryPropertyDefinition() {
225    return PD_BACKUP_DIRECTORY;
226  }
227
228
229
230  /**
231   * Get the "base-dn" property definition.
232   * <p>
233   * Specifies the base DN(s) for the data that the backend handles.
234   * <p>
235   * A single backend may be responsible for one or more base DNs.
236   * Note that no two backends may have the same base DN although one
237   * backend may have a base DN that is below a base DN provided by
238   * another backend (similar to the use of sub-suffixes in the Sun
239   * Java System Directory Server). If any of the base DNs is
240   * subordinate to a base DN for another backend, then all base DNs
241   * for that backend must be subordinate to that same base DN.
242   *
243   * @return Returns the "base-dn" property definition.
244   */
245  public DNPropertyDefinition getBaseDNPropertyDefinition() {
246    return BackendCfgDefn.getInstance().getBaseDNPropertyDefinition();
247  }
248
249
250
251  /**
252   * Get the "enabled" property definition.
253   * <p>
254   * Indicates whether the backend is enabled in the server.
255   * <p>
256   * If a backend is not enabled, then its contents are not accessible
257   * when processing operations.
258   *
259   * @return Returns the "enabled" property definition.
260   */
261  public BooleanPropertyDefinition getEnabledPropertyDefinition() {
262    return BackendCfgDefn.getInstance().getEnabledPropertyDefinition();
263  }
264
265
266
267  /**
268   * Get the "java-class" property definition.
269   * <p>
270   * Specifies the fully-qualified name of the Java class that
271   * provides the backend implementation.
272   *
273   * @return Returns the "java-class" property definition.
274   */
275  public ClassPropertyDefinition getJavaClassPropertyDefinition() {
276    return PD_JAVA_CLASS;
277  }
278
279
280
281  /**
282   * Get the "writability-mode" property definition.
283   * <p>
284   * Specifies the behavior that the backend should use when
285   * processing write operations.
286   *
287   * @return Returns the "writability-mode" property definition.
288   */
289  public EnumPropertyDefinition<WritabilityMode> getWritabilityModePropertyDefinition() {
290    return PD_WRITABILITY_MODE;
291  }
292
293
294
295  /**
296   * Managed object client implementation.
297   */
298  private static class BackupBackendCfgClientImpl implements
299    BackupBackendCfgClient {
300
301    /** Private implementation. */
302    private ManagedObject<? extends BackupBackendCfgClient> impl;
303
304
305
306    /** Private constructor. */
307    private BackupBackendCfgClientImpl(
308        ManagedObject<? extends BackupBackendCfgClient> impl) {
309      this.impl = impl;
310    }
311
312
313
314    /** {@inheritDoc} */
315    public String getBackendId() {
316      return impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
317    }
318
319
320
321    /** {@inheritDoc} */
322    public void setBackendId(String value) throws PropertyException {
323      impl.setPropertyValue(INSTANCE.getBackendIdPropertyDefinition(), value);
324    }
325
326
327
328    /** {@inheritDoc} */
329    public SortedSet<String> getBackupDirectory() {
330      return impl.getPropertyValues(INSTANCE.getBackupDirectoryPropertyDefinition());
331    }
332
333
334
335    /** {@inheritDoc} */
336    public void setBackupDirectory(Collection<String> values) {
337      impl.setPropertyValues(INSTANCE.getBackupDirectoryPropertyDefinition(), values);
338    }
339
340
341
342    /** {@inheritDoc} */
343    public SortedSet<DN> getBaseDN() {
344      return impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
345    }
346
347
348
349    /** {@inheritDoc} */
350    public void setBaseDN(Collection<DN> values) {
351      impl.setPropertyValues(INSTANCE.getBaseDNPropertyDefinition(), values);
352    }
353
354
355
356    /** {@inheritDoc} */
357    public Boolean isEnabled() {
358      return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
359    }
360
361
362
363    /** {@inheritDoc} */
364    public void setEnabled(boolean value) {
365      impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value);
366    }
367
368
369
370    /** {@inheritDoc} */
371    public String getJavaClass() {
372      return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
373    }
374
375
376
377    /** {@inheritDoc} */
378    public void setJavaClass(String value) {
379      impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value);
380    }
381
382
383
384    /** {@inheritDoc} */
385    public WritabilityMode getWritabilityMode() {
386      return impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
387    }
388
389
390
391    /** {@inheritDoc} */
392    public void setWritabilityMode(WritabilityMode value) {
393      impl.setPropertyValue(INSTANCE.getWritabilityModePropertyDefinition(), value);
394    }
395
396
397
398    /** {@inheritDoc} */
399    public ManagedObjectDefinition<? extends BackupBackendCfgClient, ? extends BackupBackendCfg> definition() {
400      return INSTANCE;
401    }
402
403
404
405    /** {@inheritDoc} */
406    public PropertyProvider properties() {
407      return impl;
408    }
409
410
411
412    /** {@inheritDoc} */
413    public void commit() throws ManagedObjectAlreadyExistsException,
414        MissingMandatoryPropertiesException, ConcurrentModificationException,
415        OperationRejectedException, LdapException {
416      impl.commit();
417    }
418
419
420
421    /** {@inheritDoc} */
422    public String toString() {
423      return impl.toString();
424    }
425  }
426
427
428
429  /**
430   * Managed object server implementation.
431   */
432  private static class BackupBackendCfgServerImpl implements
433    BackupBackendCfg {
434
435    /** Private implementation. */
436    private ServerManagedObject<? extends BackupBackendCfg> impl;
437
438    /** The value of the "backend-id" property. */
439    private final String pBackendId;
440
441    /** The value of the "backup-directory" property. */
442    private final SortedSet<String> pBackupDirectory;
443
444    /** The value of the "base-dn" property. */
445    private final SortedSet<DN> pBaseDN;
446
447    /** The value of the "enabled" property. */
448    private final boolean pEnabled;
449
450    /** The value of the "java-class" property. */
451    private final String pJavaClass;
452
453    /** The value of the "writability-mode" property. */
454    private final WritabilityMode pWritabilityMode;
455
456
457
458    /** Private constructor. */
459    private BackupBackendCfgServerImpl(ServerManagedObject<? extends BackupBackendCfg> impl) {
460      this.impl = impl;
461      this.pBackendId = impl.getPropertyValue(INSTANCE.getBackendIdPropertyDefinition());
462      this.pBackupDirectory = impl.getPropertyValues(INSTANCE.getBackupDirectoryPropertyDefinition());
463      this.pBaseDN = impl.getPropertyValues(INSTANCE.getBaseDNPropertyDefinition());
464      this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition());
465      this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition());
466      this.pWritabilityMode = impl.getPropertyValue(INSTANCE.getWritabilityModePropertyDefinition());
467    }
468
469
470
471    /** {@inheritDoc} */
472    public void addBackupChangeListener(
473        ConfigurationChangeListener<BackupBackendCfg> listener) {
474      impl.registerChangeListener(listener);
475    }
476
477
478
479    /** {@inheritDoc} */
480    public void removeBackupChangeListener(
481        ConfigurationChangeListener<BackupBackendCfg> listener) {
482      impl.deregisterChangeListener(listener);
483    }
484    /** {@inheritDoc} */
485    public void addChangeListener(
486        ConfigurationChangeListener<BackendCfg> listener) {
487      impl.registerChangeListener(listener);
488    }
489
490
491
492    /** {@inheritDoc} */
493    public void removeChangeListener(
494        ConfigurationChangeListener<BackendCfg> listener) {
495      impl.deregisterChangeListener(listener);
496    }
497
498
499
500    /** {@inheritDoc} */
501    public String getBackendId() {
502      return pBackendId;
503    }
504
505
506
507    /** {@inheritDoc} */
508    public SortedSet<String> getBackupDirectory() {
509      return pBackupDirectory;
510    }
511
512
513
514    /** {@inheritDoc} */
515    public SortedSet<DN> getBaseDN() {
516      return pBaseDN;
517    }
518
519
520
521    /** {@inheritDoc} */
522    public boolean isEnabled() {
523      return pEnabled;
524    }
525
526
527
528    /** {@inheritDoc} */
529    public String getJavaClass() {
530      return pJavaClass;
531    }
532
533
534
535    /** {@inheritDoc} */
536    public WritabilityMode getWritabilityMode() {
537      return pWritabilityMode;
538    }
539
540
541
542    /** {@inheritDoc} */
543    public Class<? extends BackupBackendCfg> configurationClass() {
544      return BackupBackendCfg.class;
545    }
546
547
548
549    /** {@inheritDoc} */
550    public DN dn() {
551      return impl.getDN();
552    }
553
554
555
556    /** {@inheritDoc} */
557    public String toString() {
558      return impl.toString();
559    }
560  }
561}