| | |
| | | import org.opends.admin.ads.ADSContext.ServerGroupProperty; |
| | | import org.opends.admin.ads.ADSContext.ServerProperty; |
| | | import org.opends.admin.ads.ADSContextException.ErrorType; |
| | | import org.opends.server.admin.client.cli.DsFrameworkCliReturnCode.ReturnCode; |
| | | import org.opends.server.util.args.ArgumentException; |
| | | import org.opends.server.util.args.BooleanArgument; |
| | | import org.opends.server.util.args.StringArgument; |
| | | import org.opends.server.util.args.SubCommand; |
| | | |
| | | import static org.opends.server.admin.client.cli.DsFrameworkCliReturnCode.*; |
| | | /** |
| | | * This class is handling server group CLI. |
| | | */ |
| | |
| | | private StringArgument listMembersGroupNameArg; |
| | | |
| | | /** |
| | | * The 'mlist-membership' subcommand. |
| | | * The 'list-membership' subcommand. |
| | | */ |
| | | private SubCommand listMembershipSubCmd; |
| | | |
| | | /** |
| | | * The 'meber-name' argument of the 'list-membership' subcommand. |
| | | * The 'member-name' argument of the 'list-membership' subcommand. |
| | | */ |
| | | private StringArgument listMembershipMemberNameArg; |
| | | |
| | |
| | | |
| | | /** |
| | | * Get the display attribute name for a given attribute. |
| | | * @param prop The server prperty |
| | | * @param prop The server property |
| | | * @return the display attribute name for a given attribute |
| | | */ |
| | | public String getAttributeDisplayName(ServerGroupProperty prop) |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public ReturnCode performSubCommand(SubCommand subCmd, OutputStream outStream, |
| | | OutputStream errStream) |
| | | public DsFrameworkCliReturnCode performSubCommand(SubCommand subCmd, |
| | | OutputStream outStream, OutputStream errStream) |
| | | throws ADSContextException, ArgumentException |
| | | { |
| | | ADSContext adsCtx = null ; |
| | | InitialLdapContext ctx = null ; |
| | | |
| | | ReturnCode returnCode = ReturnCode.ERROR_UNEXPECTED; |
| | | DsFrameworkCliReturnCode returnCode = ERROR_UNEXPECTED; |
| | | try |
| | | { |
| | | // ----------------------- |
| | |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | adsCtx.createServerGroup(serverGroupProperties); |
| | | returnCode = ReturnCode.SUCCESSFUL; |
| | | returnCode = SUCCESSFUL; |
| | | } |
| | | // ----------------------- |
| | | // delete-group subcommand |
| | | // ----------------------- |
| | | else if (subCmd.getName().equals(deleteGroupSubCmd.getName())) |
| | | { |
| | | returnCode = ReturnCode.SUCCESSFUL; |
| | | returnCode = SUCCESSFUL; |
| | | String groupId = deleteGroupGroupNameArg.getValue(); |
| | | if (groupId.equals(ADSContext.ALL_SERVERGROUP_NAME)) |
| | | { |
| | | return ReturnCode.ACCESS_PERMISSION ; |
| | | return ACCESS_PERMISSION ; |
| | | } |
| | | HashMap<ServerGroupProperty, Object> serverGroupProperties = |
| | | new HashMap<ServerGroupProperty, Object>(); |
| | |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | |
| | |
| | | Set<String> serverList = adsCtx.getServerGroupMemberList(groupId); |
| | | for (String serverId : serverList) |
| | | { |
| | | // serverId conatins "cn=" string, just remove it. |
| | | // serverId contains "cn=" string, just remove it. |
| | | removeServerFromGroup(adsCtx, groupId,serverId.substring(3)); |
| | | } |
| | | |
| | |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | |
| | |
| | | catch (IOException e) |
| | | { |
| | | } |
| | | returnCode = ReturnCode.SUCCESSFUL; |
| | | returnCode = SUCCESSFUL; |
| | | } |
| | | // ----------------------- |
| | | // modify-group subcommand |
| | |
| | | // Update the server group |
| | | if ( ! (updateRequired || removeRequired ) ) |
| | | { |
| | | returnCode = ReturnCode.SUCCESSFUL_NOP; |
| | | returnCode = SUCCESSFUL_NOP; |
| | | } |
| | | |
| | | // We need to perform an update |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | |
| | |
| | | serverGroupPropertiesToRemove); |
| | | } |
| | | |
| | | returnCode = ReturnCode.SUCCESSFUL; |
| | | returnCode = SUCCESSFUL; |
| | | } |
| | | // ----------------------- |
| | | // add-to-group subcommand |
| | |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | |
| | |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | |
| | |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | |
| | |
| | | Set<String> memberList = adsCtx.getServerGroupMemberList(groupId); |
| | | if (memberList == null) |
| | | { |
| | | returnCode = ReturnCode.SUCCESSFUL; |
| | | returnCode = SUCCESSFUL; |
| | | } |
| | | StringBuffer buffer = new StringBuffer(); |
| | | for (String member : memberList) |
| | |
| | | { |
| | | } |
| | | |
| | | returnCode = ReturnCode.SUCCESSFUL; |
| | | returnCode = SUCCESSFUL; |
| | | } |
| | | // ----------------------- |
| | | // list-membership subcommand |
| | |
| | | ctx = argParser.getContext(outStream, errStream); |
| | | if (ctx == null) |
| | | { |
| | | return ReturnCode.CANNOT_CONNECT_TO_ADS; |
| | | return CANNOT_CONNECT_TO_ADS; |
| | | } |
| | | adsCtx = new ADSContext(ctx) ; |
| | | |
| | |
| | | // Get the group name; |
| | | String groupId = groupProps.get(ServerGroupProperty.UID).toString(); |
| | | |
| | | // look for memeber list attribute |
| | | // look for member list attribute |
| | | for (ServerGroupProperty propName : groupProps.keySet()) |
| | | { |
| | | if (propName.compareTo(ServerGroupProperty.MEMBERS) != 0) |
| | |
| | | catch (IOException e) |
| | | { |
| | | } |
| | | returnCode = ReturnCode.SUCCESSFUL; |
| | | returnCode = SUCCESSFUL; |
| | | } |
| | | else |
| | | { |
| | | // Should never occurs: If we are here, it means that the code to |
| | | // handle to subcommand is not yet written. |
| | | returnCode = ReturnCode.ERROR_UNEXPECTED; |
| | | returnCode = ERROR_UNEXPECTED; |
| | | } |
| | | } |
| | | catch (ADSContextException e) |
| | |
| | | * If there is a problem with any of the parameters used |
| | | * to create this argument. |
| | | */ |
| | | static ReturnCode removeServerFromGroup(ADSContext adsCtx, String groupId, |
| | | String serverId) |
| | | static DsFrameworkCliReturnCode removeServerFromGroup(ADSContext adsCtx, |
| | | String groupId, String serverId) |
| | | throws ADSContextException |
| | | { |
| | | ReturnCode returnCode = ReturnCode.SUCCESSFUL; |
| | | DsFrameworkCliReturnCode returnCode = SUCCESSFUL; |
| | | |
| | | // get the current group member list |
| | | Set<String> memberList = adsCtx.getServerGroupMemberList(groupId); |
| | | if (memberList == null) |
| | | { |
| | | returnCode = ReturnCode.NOT_YET_REGISTERED; |
| | | returnCode = NOT_YET_REGISTERED; |
| | | } |
| | | String memberToRemove = "cn=" |
| | | + Rdn.escapeValue(serverId); |
| | | if (!memberList.contains(memberToRemove)) |
| | | { |
| | | returnCode = ReturnCode.NOT_YET_REGISTERED; |
| | | returnCode = NOT_YET_REGISTERED; |
| | | } |
| | | |
| | | memberList.remove(memberToRemove); |
| | |
| | | } |
| | | if ( ! found ) |
| | | { |
| | | return returnCode.SERVER_NOT_REGISTERED ; |
| | | return SERVER_NOT_REGISTERED ; |
| | | } |
| | | |
| | | Set rawGroupList = (Set) serverProperties.get(ServerProperty.GROUPS); |
| | |
| | | * If there is a problem with any of the parameters used |
| | | * to create this argument. |
| | | */ |
| | | static ReturnCode addServerTogroup(ADSContext adsCtx, String groupId, |
| | | Map<ServerProperty, Object> map) throws ADSContextException |
| | | static DsFrameworkCliReturnCode addServerTogroup(ADSContext adsCtx, |
| | | String groupId, Map<ServerProperty, Object> map) |
| | | throws ADSContextException |
| | | { |
| | | ReturnCode returnCode = ReturnCode.SUCCESSFUL; |
| | | DsFrameworkCliReturnCode returnCode = SUCCESSFUL; |
| | | String serverId = (String) map.get(ServerProperty.ID); |
| | | |
| | | // Add the server inside the group |
| | |
| | | + Rdn.escapeValue(serverId); |
| | | if (memberList.contains(newMember)) |
| | | { |
| | | returnCode = ReturnCode.ALREADY_REGISTERED; |
| | | returnCode = ALREADY_REGISTERED; |
| | | } |
| | | memberList.add(newMember); |
| | | serverGroupProperties.put(ServerGroupProperty.MEMBERS, memberList); |