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