Skip to content

Commit

Permalink
Merge pull request alibaba#93 from hxy1991/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz authored Oct 9, 2018
2 parents a5e9528 + 77a162d commit df2d28d
Showing 1 changed file with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
Expand Down Expand Up @@ -65,26 +63,27 @@
*/
@Controller
@RequestMapping(Constants.CONFIG_CONTROLLER_PATH)
public class ConfigController extends HttpServlet {
/**
* uid
*/
private static final long serialVersionUID = 4339468526746635388L;
public class ConfigController {

private static final Logger log = LoggerFactory.getLogger(ConfigController.class);

@Autowired
private transient ConfigServletInner inner;
private final transient ConfigServletInner inner;

@Autowired
private transient PersistService persistService;
private final transient PersistService persistService;

@Autowired
private transient MergeDatumService mergeService;
private final transient MergeDatumService mergeService;

private final transient ConfigSubService configSubService;

@Autowired
private transient ConfigSubService configSubService;

public ConfigController(ConfigServletInner configServletInner, PersistService persistService, MergeDatumService mergeService,
ConfigSubService configSubService) {
this.inner = configServletInner;
this.persistService = persistService;
this.mergeService = mergeService;
this.configSubService = configSubService;
}

/**
* 增加或更新非聚合数据。
*
Expand Down Expand Up @@ -133,7 +132,7 @@ public Boolean publishConfig(HttpServletRequest request, HttpServletResponse res

if (AggrWhitelist.isAggrDataId(dataId)) {
log.warn("[aggr-conflict] {} attemp to publish single data, {}, {}",
new Object[] { RequestUtil.getRemoteIp(request), dataId, group });
RequestUtil.getRemoteIp(request), dataId, group);
throw new NacosException(NacosException.NO_RIGHT, "dataId:" + dataId + " is aggr");
}

Expand Down Expand Up @@ -181,17 +180,15 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,

/**
* 取数据
*
* @throws ServletException
* @throws IOException
*
* @throws NacosException
*/
@RequestMapping(params = "show=all", method = RequestMethod.GET)
@ResponseBody
public ConfigAllInfo detailConfigInfo(HttpServletRequest request, HttpServletResponse response,
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant)
throws IOException, ServletException, NacosException {
throws NacosException {
// check params
ParamUtils.checkParam(dataId, group, "datumId", "content");
return persistService.findConfigAllInfo(dataId, group, tenant);
Expand Down Expand Up @@ -224,8 +221,7 @@ public Boolean deleteConfig(HttpServletRequest request, HttpServletResponse resp
@ResponseBody
public RestResult<ConfigAdvanceInfo> getConfigAdvanceInfo(HttpServletRequest request, HttpServletResponse response,
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
ModelMap modelMap) {
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) {
RestResult<ConfigAdvanceInfo> rr = new RestResult<ConfigAdvanceInfo>();
ConfigAdvanceInfo configInfo = persistService.findConfigAdvanceInfo(dataId, group, tenant);
rr.setCode(200);
Expand All @@ -237,8 +233,7 @@ public RestResult<ConfigAdvanceInfo> getConfigAdvanceInfo(HttpServletRequest req
* 比较MD5
*/
@RequestMapping(value = "/listener", method = RequestMethod.POST)
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
public void listener(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
String probeModify = request.getParameter("Listening-Configs");
Expand All @@ -248,7 +243,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)

probeModify = URLDecoder.decode(probeModify, Constants.ENCODE);

Map<String, String> clientMd5Map = null;
Map<String, String> clientMd5Map;
try {
clientMd5Map = MD5Util.getClientMd5Map(probeModify);
} catch (Throwable e) {
Expand All @@ -267,8 +262,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
public GroupkeyListenserStatus getListeners(HttpServletRequest request, HttpServletResponse response,
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam(value = "tenant", required = false) String tenant,
@RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime, ModelMap modelMap)
throws IOException, ServletException, Exception {
@RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime)
throws Exception {
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group;
SampleResult collectSampleResult = configSubService.getCollectSampleResult(dataId, group, tenant, sampleTime);
GroupkeyListenserStatus gls = new GroupkeyListenserStatus();
Expand All @@ -292,7 +287,7 @@ public Page<ConfigInfo> searchConfig(HttpServletRequest request,
@RequestParam(value = "tenant", required = false, defaultValue=StringUtils.EMPTY) String tenant,
@RequestParam(value = "config_tags", required = false) String configTags,
@RequestParam("pageNo") int pageNo,
@RequestParam("pageSize") int pageSize, ModelMap modelMap) {
@RequestParam("pageSize") int pageSize) {
Map<String, Object> configAdvanceInfo = new HashMap<String, Object>(100);
if (StringUtils.isNotBlank(appName)) {
configAdvanceInfo.put("appName", appName);
Expand All @@ -301,9 +296,8 @@ public Page<ConfigInfo> searchConfig(HttpServletRequest request,
configAdvanceInfo.put("config_tags", configTags);
}
try {
Page<ConfigInfo> page = persistService.findConfigInfo4Page(pageNo, pageSize, dataId, group, tenant,
return persistService.findConfigInfo4Page(pageNo, pageSize, dataId, group, tenant,
configAdvanceInfo);
return page;
} catch (Exception e) {
String errorMsg = "serialize page error, dataId=" + dataId + ", group=" + group;
log.error(errorMsg, e);
Expand All @@ -317,14 +311,13 @@ public Page<ConfigInfo> searchConfig(HttpServletRequest request,
@RequestMapping(params = "search=blur", method = RequestMethod.GET)
@ResponseBody
public Page<ConfigInfo> fuzzySearchConfig(HttpServletRequest request, HttpServletResponse response,
@RequestParam("dataId") String dataId, //
@RequestParam("group") String group, //
@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "config_tags", required = false) String configTags,
@RequestParam("pageNo") int pageNo, //
@RequestParam("pageSize") int pageSize, //
ModelMap modelMap) {
@RequestParam("pageNo") int pageNo,
@RequestParam("pageSize") int pageSize) {
Map<String, Object> configAdvanceInfo = new HashMap<String, Object>(50);
if (StringUtils.isNotBlank(appName)) {
configAdvanceInfo.put("appName", appName);
Expand All @@ -333,9 +326,8 @@ public Page<ConfigInfo> fuzzySearchConfig(HttpServletRequest request, HttpServle
configAdvanceInfo.put("config_tags", configTags);
}
try {
Page<ConfigInfo> page = persistService.findConfigInfoLike4Page(pageNo, pageSize, dataId, group, tenant,
return persistService.findConfigInfoLike4Page(pageNo, pageSize, dataId, group, tenant,
configAdvanceInfo);
return page;
} catch (Exception e) {
String errorMsg = "serialize page error, dataId=" + dataId + ", group=" + group;
log.error(errorMsg, e);
Expand Down

0 comments on commit df2d28d

Please sign in to comment.