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