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