Skip to content

Commit

Permalink
[INLONG-4924][TubeMQ] Add admin_get_methods method (apache#4925)
Browse files Browse the repository at this point in the history
  • Loading branch information
gosonzhang authored and bruceneenhl committed Aug 12, 2022
1 parent 55a6c67 commit 82d271e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.apache.inlong.tubemq.server.common.webbase.WebMethodMapper.getWebApiRegInfo;
import static org.apache.inlong.tubemq.server.common.webbase.WebMethodMapper.registerWebMethod;
import java.io.IOException;
import java.util.Set;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -43,8 +42,8 @@ protected void doGet(HttpServletRequest req,
doPost(req, resp);
}

public Set<String> getSupportedMethod() {
return getRegisteredWebMethod();
public int getSupportedMethod(StringBuilder sBuffer) {
return getRegisteredWebMethod(sBuffer);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,9 @@ public void registerWebApiMethod() {
*/
public void adminQueryAllMethods(HttpServletRequest req,
StringBuilder sBuffer) {
int index = 0;
Set<String> methods = getSupportedMethod();
sBuffer.append("{\"result\":true,\"errCode\":0,\"errMsg\":\"Success!\",\"dataSet\":[");
for (String method : methods) {
if (index++ > 0) {
sBuffer.append(",");
}
sBuffer.append("{\"id\":").append(index)
.append(",\"method\":\"").append(method).append("\"}");
}
sBuffer.append("],\"totalCnt\":").append(index).append("}");
int totalCnt = getSupportedMethod(sBuffer);
sBuffer.append("],\"totalCnt\":").append(totalCnt).append("}");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -54,8 +53,23 @@ public static void registerWebMethod(String webMethodName,
.append(webHandler.getClass().getName()).toString());
}

public static Set<String> getRegisteredWebMethod() {
return WEB_METHOD_MAP.keySet();
public static int getRegisteredWebMethod(StringBuilder sBuffer) {
int totalCnt = 0;
if (WEB_METHOD_MAP.isEmpty()) {
return totalCnt;
}
for (Map.Entry<String, WebMethodMapper.WebApiRegInfo> entry : WEB_METHOD_MAP.entrySet()) {
if (entry == null || entry.getKey() == null || entry.getValue() == null) {
continue;
}
if (totalCnt++ > 0) {
sBuffer.append(",");
}
sBuffer.append("{\"method\":\"").append(entry.getKey())
.append("\",\"needAuth\":").append(entry.getValue().needAuthToken)
.append("}");
}
return totalCnt;
}

public static class WebApiRegInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.inlong.tubemq.server.master.web.handler;

import static org.apache.inlong.tubemq.server.common.webbase.WebMethodMapper.getRegisteredWebMethod;
import static org.apache.inlong.tubemq.server.common.webbase.WebMethodMapper.registerWebMethod;
import org.apache.inlong.tubemq.server.master.TMaster;
import org.apache.inlong.tubemq.server.master.metamanage.MetaDataService;
Expand All @@ -43,12 +44,15 @@ protected void registerModifyWebMethod(String webMethodName,
innRegisterWebMethod(webMethodName, clsMethodName, true, true);
}

protected int getRegisteredMethods(StringBuilder sBuffer) {
return getRegisteredWebMethod(sBuffer);
}

private void innRegisterWebMethod(String webMethodName,
String clsMethodName,
boolean onlyMasterOp,
boolean needAuthToken) {
registerWebMethod(webMethodName, clsMethodName,
onlyMasterOp, needAuthToken, this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public WebOtherInfoHandler(TMaster master) {
@Override
public void registerWebApiMethod() {
// register query method
registerQueryWebMethod("admin_get_methods",
"adminQueryAllMethods");
registerQueryWebMethod("admin_query_sub_info",
"getSubscribeInfo");
registerQueryWebMethod("admin_query_consume_group_detail",
Expand All @@ -81,6 +83,23 @@ public void registerWebApiMethod() {
"adminDisableAllStats");
}

/**
* Get all API methods supported by this version.
*
* @param req Http Servlet Request
* @param sBuffer string buffer
* @param result process result
* @return process result
*/
public StringBuilder adminQueryAllMethods(HttpServletRequest req,
StringBuilder sBuffer,
ProcessResult result) {
WebParameterUtils.buildSuccessWithDataRetBegin(sBuffer);
int totalCnt = getRegisteredMethods(sBuffer);
WebParameterUtils.buildSuccessWithDataRetEnd(sBuffer, totalCnt);
return sBuffer;
}

/**
* Get subscription info
*
Expand Down Expand Up @@ -526,5 +545,4 @@ private void getConsumerInfoList(final List<ConsumerInfo> consumerList,
}
strBuffer.append("]");
}

}

0 comments on commit 82d271e

Please sign in to comment.