| | |
| | | * Portions Copyright 2007 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.server.tools.dsconfig; |
| | | import org.opends.messages.Message; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.messages.DSConfigMessages.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.server.admin.DefinitionDecodingException; |
| | | import org.opends.server.admin.IllegalPropertyValueStringException; |
| | | import org.opends.server.admin.InstantiableRelationDefinition; |
| | |
| | | import org.opends.server.admin.client.ConcurrentModificationException; |
| | | import org.opends.server.admin.client.ManagedObject; |
| | | import org.opends.server.admin.client.ManagedObjectDecodingException; |
| | | import org.opends.server.admin.client.ManagementContext; |
| | | import org.opends.server.admin.client.MissingMandatoryPropertiesException; |
| | | import org.opends.server.admin.client.OperationRejectedException; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | |
| | | import org.opends.server.util.args.StringArgument; |
| | | import org.opends.server.util.args.SubCommand; |
| | | import org.opends.server.util.args.SubCommandArgumentParser; |
| | | import org.opends.server.util.cli.CLIException; |
| | | import org.opends.server.util.cli.ConsoleApplication; |
| | | import org.opends.server.util.cli.MenuResult; |
| | | |
| | | |
| | | |
| | |
| | | * Creates a new set-xxx-prop sub-command for an instantiable |
| | | * relation. |
| | | * |
| | | * @param app |
| | | * The console application. |
| | | * @param parser |
| | | * The sub-command argument parser. |
| | | * @param path |
| | |
| | | * @throws ArgumentException |
| | | * If the sub-command could not be created successfully. |
| | | */ |
| | | public static SetPropSubCommandHandler create(ConsoleApplication app, |
| | | public static SetPropSubCommandHandler create( |
| | | SubCommandArgumentParser parser, ManagedObjectPath<?, ?> path, |
| | | InstantiableRelationDefinition<?, ?> r) throws ArgumentException { |
| | | return new SetPropSubCommandHandler(app, parser, path.child(r, "DUMMY"), r); |
| | | return new SetPropSubCommandHandler(parser, path.child(r, "DUMMY"), r); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * Creates a new set-xxx-prop sub-command for an optional relation. |
| | | * |
| | | * @param app |
| | | * The console application. |
| | | * @param parser |
| | | * The sub-command argument parser. |
| | | * @param path |
| | |
| | | * @throws ArgumentException |
| | | * If the sub-command could not be created successfully. |
| | | */ |
| | | public static SetPropSubCommandHandler create(ConsoleApplication app, |
| | | public static SetPropSubCommandHandler create( |
| | | SubCommandArgumentParser parser, ManagedObjectPath<?, ?> path, |
| | | OptionalRelationDefinition<?, ?> r) throws ArgumentException { |
| | | return new SetPropSubCommandHandler(app, parser, path.child(r), r); |
| | | return new SetPropSubCommandHandler(parser, path.child(r), r); |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * Creates a new set-xxx-prop sub-command for a singleton relation. |
| | | * |
| | | * @param app |
| | | * The console application. |
| | | * @param parser |
| | | * The sub-command argument parser. |
| | | * @param path |
| | |
| | | * @throws ArgumentException |
| | | * If the sub-command could not be created successfully. |
| | | */ |
| | | public static SetPropSubCommandHandler create(ConsoleApplication app, |
| | | public static SetPropSubCommandHandler create( |
| | | SubCommandArgumentParser parser, ManagedObjectPath<?, ?> path, |
| | | SingletonRelationDefinition<?, ?> r) throws ArgumentException { |
| | | return new SetPropSubCommandHandler(app, parser, path.child(r), r); |
| | | return new SetPropSubCommandHandler(parser, path.child(r), r); |
| | | } |
| | | |
| | | // The sub-commands naming arguments. |
| | |
| | | |
| | | |
| | | // Private constructor. |
| | | private SetPropSubCommandHandler(ConsoleApplication app, |
| | | private SetPropSubCommandHandler( |
| | | SubCommandArgumentParser parser, ManagedObjectPath<?, ?> path, |
| | | RelationDefinition<?, ?> r) throws ArgumentException { |
| | | super(app); |
| | | |
| | | this.path = path; |
| | | |
| | | // Create the sub-command. |
| | | String name = "set-" + r.getName() + "-prop"; |
| | | Message description = INFO_DSCFG_DESCRIPTION_SUBCMD_SETPROP.get( |
| | | r.getChildDefinition().getUserFriendlyName()); |
| | | Message description = INFO_DSCFG_DESCRIPTION_SUBCMD_SETPROP.get(r |
| | | .getChildDefinition().getUserFriendlyName()); |
| | | this.subCommand = new SubCommand(parser, name, false, 0, 0, null, |
| | | description); |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Gets the relation definition associated with the type of |
| | | * component that this sub-command handles. |
| | | * |
| | | * @return Returns the relation definition associated with the type |
| | | * of component that this sub-command handles. |
| | | */ |
| | | public RelationDefinition<?, ?> getRelationDefinition() { |
| | | return path.getRelationDefinition(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | | public int run() |
| | | throws ArgumentException, ClientException { |
| | | public MenuResult<Integer> run(ConsoleApplication app, |
| | | ManagementContextFactory factory) throws ArgumentException, |
| | | ClientException, CLIException { |
| | | // Get the naming argument values. |
| | | List<String> names = getNamingArgValues(namingArgs); |
| | | List<String> names = getNamingArgValues(app, namingArgs); |
| | | |
| | | ManagedObject<?> child; |
| | | // Get the targeted managed object. |
| | | Message ufn = path.getRelationDefinition().getUserFriendlyName(); |
| | | ManagementContext context = factory.getManagementContext(app); |
| | | MenuResult<ManagedObject<?>> result; |
| | | try { |
| | | child = getManagedObject(path, names); |
| | | result = getManagedObject(app, context, path, names); |
| | | } catch (AuthorizationException e) { |
| | | Message ufn = path.getManagedObjectDefinition().getUserFriendlyName(); |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_AUTHZ.get(ufn); |
| | | throw new ClientException(LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS, |
| | | msg); |
| | | throw new ClientException(LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS, msg); |
| | | } catch (DefinitionDecodingException e) { |
| | | Message ufn = path.getManagedObjectDefinition().getUserFriendlyName(); |
| | | Message msg = ERR_DSCFG_ERROR_GET_CHILD_DDE.get(ufn, ufn, ufn); |
| | | throw new ClientException(LDAPResultCode.OPERATIONS_ERROR, msg); |
| | | } catch (ManagedObjectDecodingException e) { |
| | | // FIXME: should not abort here. Instead, display the errors (if |
| | | // verbose) and apply the changes to the partial managed object. |
| | | Message ufn = path.getManagedObjectDefinition().getUserFriendlyName(); |
| | | Message msg = ERR_DSCFG_ERROR_GET_CHILD_MODE.get(ufn); |
| | | throw new ClientException(LDAPResultCode.OPERATIONS_ERROR, msg); |
| | | } catch (CommunicationException e) { |
| | | Message ufn = path.getManagedObjectDefinition().getUserFriendlyName(); |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(LDAPResultCode.OPERATIONS_ERROR, msg); |
| | | } catch (ConcurrentModificationException e) { |
| | | Message ufn = path.getManagedObjectDefinition().getUserFriendlyName(); |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_CME.get(ufn); |
| | | throw new ClientException(LDAPResultCode.CONSTRAINT_VIOLATION, |
| | | msg); |
| | | throw new ClientException(LDAPResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | Message ufn = path.getManagedObjectDefinition().getUserFriendlyName(); |
| | | Message msg = ERR_DSCFG_ERROR_GET_CHILD_MONFE.get(ufn); |
| | | throw new ClientException(LDAPResultCode.NO_SUCH_OBJECT, msg); |
| | | } |
| | | |
| | | if (result.isQuit()) { |
| | | if (!app.isMenuDrivenMode()) { |
| | | // User chose to quit. |
| | | Message msg = INFO_DSCFG_CONFIRM_MODIFY_FAIL.get(ufn); |
| | | app.printVerboseMessage(msg); |
| | | } |
| | | return MenuResult.quit(); |
| | | } else if (result.isCancel()) { |
| | | return MenuResult.cancel(); |
| | | } |
| | | |
| | | ManagedObject<?> child = result.getValue(); |
| | | ManagedObjectDefinition<?, ?> d = child.getManagedObjectDefinition(); |
| | | Map<String, ModificationType> lastModTypes = |
| | | new HashMap<String, ModificationType>(); |
| | |
| | | } |
| | | } else { |
| | | lastModTypes.put(propertyName, ModificationType.REMOVE); |
| | | modifyPropertyValues(child, pd, changes, |
| | | ModificationType.REMOVE, value); |
| | | modifyPropertyValues(child, pd, changes, ModificationType.REMOVE, |
| | | value); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // Interactively set properties if applicable. |
| | | if (getConsoleApplication().isInteractive()) { |
| | | if (app.isInteractive()) { |
| | | SortedSet<PropertyDefinition<?>> properties = |
| | | new TreeSet<PropertyDefinition<?>>(); |
| | | |
| | |
| | | continue; |
| | | } |
| | | |
| | | if (pd.hasOption(PropertyOption.READ_ONLY)) { |
| | | continue; |
| | | } |
| | | |
| | | if (pd.hasOption(PropertyOption.MONITORING)) { |
| | | continue; |
| | | } |
| | | |
| | | if (!isAdvancedMode() && pd.hasOption(PropertyOption.ADVANCED)) { |
| | | continue; |
| | | } |
| | |
| | | properties.add(pd); |
| | | } |
| | | |
| | | PropertyValueReader reader = |
| | | new PropertyValueReader(getConsoleApplication()); |
| | | reader.readAll(child, properties); |
| | | PropertyValueEditor editor = new PropertyValueEditor(app); |
| | | MenuResult<Void> result2 = editor.edit(child, properties, true); |
| | | if (result2.isQuit()) { |
| | | if (!app.isMenuDrivenMode()) { |
| | | // User chose to cancel any changes. |
| | | Message msg = INFO_DSCFG_CONFIRM_MODIFY_FAIL.get(ufn); |
| | | app.printVerboseMessage(msg); |
| | | } |
| | | return MenuResult.quit(); |
| | | } else if (result2.isCancel()) { |
| | | return MenuResult.cancel(); |
| | | } |
| | | } |
| | | |
| | | try { |
| | | // Confirm commit. |
| | | Message prompt = INFO_DSCFG_CONFIRM_MODIFY.get(d.getUserFriendlyName()); |
| | | if (!getConsoleApplication().confirmAction(prompt)) { |
| | | // Output failure message. |
| | | Message msg = |
| | | INFO_DSCFG_CONFIRM_MODIFY_FAIL.get(d.getUserFriendlyName()); |
| | | getConsoleApplication().printVerboseMessage(msg); |
| | | return 1; |
| | | } |
| | | |
| | | child.commit(); |
| | | |
| | | // Output success message. |
| | | Message msg = |
| | | INFO_DSCFG_CONFIRM_MODIFY_SUCCESS.get(d.getUserFriendlyName()); |
| | | getConsoleApplication().printVerboseMessage(msg); |
| | | Message msg = INFO_DSCFG_CONFIRM_MODIFY_SUCCESS.get(ufn); |
| | | app.printVerboseMessage(msg); |
| | | } catch (MissingMandatoryPropertiesException e) { |
| | | throw ArgumentExceptionFactory.adaptMissingMandatoryPropertiesException( |
| | | e, d); |
| | | } catch (AuthorizationException e) { |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_AUTHZ.get(d.getUserFriendlyName()); |
| | | throw new ClientException(LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS, |
| | | msg); |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_AUTHZ.get(ufn); |
| | | throw new ClientException(LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS, msg); |
| | | } catch (ConcurrentModificationException e) { |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_CME.get(d.getUserFriendlyName()); |
| | | throw new ClientException(LDAPResultCode.CONSTRAINT_VIOLATION, |
| | | msg); |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_CME.get(ufn); |
| | | throw new ClientException(LDAPResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (OperationRejectedException e) { |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_ORE.get( |
| | | d.getUserFriendlyName(), e.getMessage()); |
| | | throw new ClientException(LDAPResultCode.CONSTRAINT_VIOLATION, |
| | | msg); |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_ORE.get(ufn, e.getMessage()); |
| | | throw new ClientException(LDAPResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } catch (CommunicationException e) { |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_CE.get( |
| | | d.getUserFriendlyName(), e.getMessage()); |
| | | Message msg = ERR_DSCFG_ERROR_MODIFY_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(LDAPResultCode.OPERATIONS_ERROR, msg); |
| | | } catch (ManagedObjectAlreadyExistsException e) { |
| | | // Should never happen. |
| | | throw new IllegalStateException(e); |
| | | } |
| | | |
| | | return 0; |
| | | return MenuResult.success(0); |
| | | } |
| | | |
| | | |