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