mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

lutoff
24.53.2007 4a7170c5a0fe84d1250af96e764200c827f771a0
Fix for issue #2011 (dsframework register-server doesn't add the server into the default all-servers group)

When register-server is called, we also add the server inside to "all-servers" group
2 files modified
77 ■■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliServer.java 12 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliServerGroup.java 65 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliServer.java
@@ -580,17 +580,18 @@
      // -----------------------
      if (subCmd.getName().equals(registerServerSubCmd.getName()))
      {
        String serverId ;
        Map<ServerProperty, Object> map =
          mapSetOptionsToMap(registerServerSetArg);
        if (registerServerServerIdArg.isPresent())
        {
          map.put(ServerProperty.ID, registerServerServerIdArg.getValue());
          serverId = registerServerServerIdArg.getValue();
        }
        else
        {
          map.put(ServerProperty.ID, ADSContext
              .getServerIdFromServerProperties(map));
          serverId = ADSContext.getServerIdFromServerProperties(map);
        }
        map.put(ServerProperty.ID, serverId);
        ctx = argParser.getContext(outStream, errStream);
        if (ctx == null)
@@ -599,7 +600,10 @@
        }
        adsCtx = new ADSContext(ctx);
        adsCtx.registerServer(map);
        returnCode = ReturnCode.SUCCESSFUL;
        // Add this server in the default "all-servers" group.
        returnCode = DsFrameworkCliServerGroup.addServerTogroup(adsCtx,
            ADSContext.ALL_SERVERGROUP_NAME, serverId);
      }
      else
      // -----------------------
opendj-sdk/opends/src/server/org/opends/server/admin/client/cli/DsFrameworkCliServerGroup.java
@@ -716,8 +716,6 @@
      else if (subCmd.getName().equals(addToGroupSubCmd.getName()))
      {
        String groupId = addToGroupGroupNameArg.getValue();
        HashMap<ServerGroupProperty, Object> serverGroupProperties =
          new HashMap<ServerGroupProperty, Object>();
        ctx = argParser.getContext(outStream, errStream);
        if (ctx == null)
@@ -745,25 +743,8 @@
          return ReturnCode.SERVER_NOT_REGISTERED;
        }
        // get the current member list
        Set<String> memberList = adsCtx.getServerGroupMemberList(groupId);
        if (memberList == null)
        {
          memberList = new HashSet<String>();
        }
        String newMember = "cn="
            + Rdn.escapeValue(addToGoupMemberNameArg.getValue());
        if (memberList.contains(newMember))
        {
          returnCode = ReturnCode.ALREADY_REGISTERED;
        }
        memberList.add(newMember);
        serverGroupProperties.put(ServerGroupProperty.MEMBERS, memberList);
        // Update the server group
        adsCtx.updateServerGroup(groupId, serverGroupProperties);
        returnCode = ReturnCode.SUCCESSFUL;
        returnCode = addServerTogroup(adsCtx, groupId, addToGoupMemberNameArg
            .getValue());
      }
      // -----------------------
      // remove-from-group subcommand
@@ -930,4 +911,46 @@
    return returnCode;
  }
  /**
   * Add a server inside a group.
   *
   * @param adsCtx
   *          The ADS context to use.
   * @param groupId
   *          The group identifier in which a server has to be added.
   * @param serverId
   *          The server identifier that have to be added to the
   *          group.
   * @return the return code.
   * @throws ADSContextException
   *           If there is a problem with any of the parameters used
   *           to create this argument.
   */
  static ReturnCode addServerTogroup(ADSContext adsCtx, String groupId,
      String serverId) throws ADSContextException
  {
    ReturnCode returnCode = ReturnCode.SUCCESSFUL;
    // get the current member list
    HashMap<ServerGroupProperty, Object> serverGroupProperties =
      new HashMap<ServerGroupProperty, Object>();
    Set<String> memberList = adsCtx.getServerGroupMemberList(groupId);
    if (memberList == null)
    {
      memberList = new HashSet<String>();
    }
    String newMember = "cn="
        + Rdn.escapeValue(serverId);
    if (memberList.contains(newMember))
    {
      returnCode = ReturnCode.ALREADY_REGISTERED;
    }
    memberList.add(newMember);
    serverGroupProperties.put(ServerGroupProperty.MEMBERS, memberList);
    // Update the server group
    adsCtx.updateServerGroup(groupId, serverGroupProperties);
    return returnCode;
  }
}