Commit 496a4e03 by 房斌

1去掉多余的unregisteryed2 zookper 上传协议改成http方式

parent 8a3086ff
...@@ -2,6 +2,7 @@ package com.secoo.mall.common.util.http; ...@@ -2,6 +2,7 @@ package com.secoo.mall.common.util.http;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.secoo.mall.common.util.date.DateUtil;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
...@@ -35,10 +36,8 @@ import java.nio.charset.Charset; ...@@ -35,10 +36,8 @@ import java.nio.charset.Charset;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
/** /**
* httpClient封装 * httpClient封装
...@@ -498,13 +497,15 @@ public class HttpClientUtils { ...@@ -498,13 +497,15 @@ public class HttpClientUtils {
final String[] content = new String[1]; final String[] content = new String[1];
content[0]=""; content[0]="";
// 传入HttpPost request // 传入HttpPost request
CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault(); CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig).build();
LOG.info("httpclient test begin time:{}", DateUtil.getDateTime());
httpclient.start(); httpclient.start();
httpclient.execute(request, new FutureCallback<HttpResponse>() { httpclient.execute(request, new FutureCallback<HttpResponse>() {
@Override @Override
public void completed(final HttpResponse response) { public void completed(final HttpResponse response) {
LOG.info(request.getRequestLine() + "->" + response.getStatusLine());
LOG.info(request.getRequestLine() + "->" + response.getStatusLine());
LOG.info("httpclient test received content time:{}",DateUtil.getDateTime());
try { try {
content[0] = EntityUtils.toString(response.getEntity(), "UTF-8"); content[0] = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (IOException e) { } catch (IOException e) {
...@@ -513,13 +514,16 @@ public class HttpClientUtils { ...@@ -513,13 +514,16 @@ public class HttpClientUtils {
} }
@Override @Override
public void failed(final Exception ex) { public void failed(final Exception ex) {
LOG.info("httpclient test received failed time:{}",DateUtil.getDateTime());
LOG.error(request.getRequestLine() + "->" + ex); LOG.error(request.getRequestLine() + "->" + ex);
} }
@Override @Override
public void cancelled() { public void cancelled() {
LOG.info("httpclient test received cancelled time:{}",DateUtil.getDateTime());
LOG.error(request.getRequestLine() + " cancelled"); LOG.error(request.getRequestLine() + " cancelled");
} }
}); });
LOG.info("httpclient test end time:{}",DateUtil.getDateTime());
return content[0]; return content[0];
} }
......
...@@ -27,6 +27,7 @@ public class ShutDownDataReportAsyncHttp implements UpDatas<ExecutorDetails> { ...@@ -27,6 +27,7 @@ public class ShutDownDataReportAsyncHttp implements UpDatas<ExecutorDetails> {
nvps.add(new BasicNameValuePair("gracefulresult", result)); nvps.add(new BasicNameValuePair("gracefulresult", result));
HttpClientUtils.setHttpParam(ConfigConstant.CONNECT_TIMEOUT,ConfigConstant.SOCKET_TIMEOUT,ConfigConstant.REQUEST_TIMEOUT); HttpClientUtils.setHttpParam(ConfigConstant.CONNECT_TIMEOUT,ConfigConstant.SOCKET_TIMEOUT,ConfigConstant.REQUEST_TIMEOUT);
httpPost.setEntity(new UrlEncodedFormEntity(nvps)); httpPost.setEntity(new UrlEncodedFormEntity(nvps));
logger.info("test in http start");
String back= HttpClientUtils.asynchronousPost(httpPost); String back= HttpClientUtils.asynchronousPost(httpPost);
return true; return true;
}catch (Exception e){ }catch (Exception e){
......
...@@ -34,6 +34,7 @@ public class TomcatGracefulShutDown implements TomcatConnectorCustomizer , Appli ...@@ -34,6 +34,7 @@ public class TomcatGracefulShutDown implements TomcatConnectorCustomizer , Appli
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.context = applicationContext; this.context = applicationContext;
logger.info("11111111111111111111 tomcat set Application");
} }
public TomcatShutDownHook getTomcatShutDownHook() { public TomcatShutDownHook getTomcatShutDownHook() {
return tomcatShutDownHook; return tomcatShutDownHook;
......
...@@ -5,6 +5,7 @@ import com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail; ...@@ -5,6 +5,7 @@ import com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail;
import com.secoo.mall.common.util.date.DateUtil; import com.secoo.mall.common.util.date.DateUtil;
import com.secoo.mall.common.util.log.LoggerUtil; import com.secoo.mall.common.util.log.LoggerUtil;
import com.secoo.mall.common.util.string.StringUtil; import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.gracefulshutdown.monitor.dubbo.Constants.Constants;
import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.ProviderService; import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.ProviderService;
import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.RegistryServerSync; import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.RegistryServerSync;
import com.secoo.mall.gracefulshutdown.monitor.utils.Stack; import com.secoo.mall.gracefulshutdown.monitor.utils.Stack;
...@@ -56,7 +57,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -56,7 +57,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
public ExecutorDetail stop() { public ExecutorDetail stop() {
ExecutorDetail detail = new ExecutorDetail(); ExecutorDetail detail = new ExecutorDetail();
detail.setBeginTime(DateUtil.getDateTime()); detail.setBeginTime(DateUtil.getDateTime());
detail.setServiceName("dubboDownHock1061"); detail.setServiceName("dubboDownHock1066");
List<String> str = new ArrayList<String>(); List<String> str = new ArrayList<String>();
detail.setDetail(str); detail.setDetail(str);
detail.setCode(0); detail.setCode(0);
...@@ -80,6 +81,10 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -80,6 +81,10 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
if (urls != null && urls.size() > 0) { if (urls != null && urls.size() > 0) {
checks=new ArrayList<URL>(); checks=new ArrayList<URL>();
for (URL value : urls) { for (URL value : urls) {
if(value!=null&&StringUtil.isNotEmpty(value.getParameter(Constants.CATEGORY_KEY))&&value.getParameter(Constants.CATEGORY_KEY).equals(Constants.PROVIDERS_CONSUMERS)){
logger.info("matrix gracefulshutdown delete before service:{},category:{}",value.getServiceKey(),value.getParameter(Constants.CATEGORY_KEY)); //消费者不用处理,走默认优雅停机就可以
continue;
}
checks.add(value); checks.add(value);
try { try {
logger.info("provider url executer ip:{},name :{} unregister before:{} time:{}" , ip,name,value.getServiceInterface() , new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line()); logger.info("provider url executer ip:{},name :{} unregister before:{} time:{}" , ip,name,value.getServiceInterface() , new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line());
...@@ -89,8 +94,8 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -89,8 +94,8 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
LoggerUtil.info("provider url unregister success :" + value.getServiceInterface() + " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line()); LoggerUtil.info("provider url unregister success :" + value.getServiceInterface() + " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line());
str.add("delete" + value.getServiceInterface() + " success: " +StringUtil.line()); str.add("delete" + value.getServiceInterface() + " success: " +StringUtil.line());
} catch (Exception e) { } catch (Exception e) {
LoggerUtil.error("matirx-monitor deleteService error:", e); logger.error("matirx-monitor delete Service error service:{} trigger error",value.getServiceInterface() + StringUtil.line() +Stack.errInfo(e)+StringUtil.line());
logger.info("matirx-monitor delete Service error service:{}",value.getServiceInterface() + StringUtil.line() +Stack.errInfo(e)+StringUtil.line()); str.add("delete" + value.getServiceInterface() + " trigger error: " +StringUtil.line());
}finally { }finally {
registryServerSync.setSignal(true); registryServerSync.setSignal(true);
} }
...@@ -105,6 +110,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -105,6 +110,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
} }
} }
//step3 check检查 //step3 check检查
if(checks!=null&&checks.size()>0) { if(checks!=null&&checks.size()>0) {
CuratorZookeeperClient client = (CuratorZookeeperClient) getFieldValueByFieldName("zkClient", zookperRegster); CuratorZookeeperClient client = (CuratorZookeeperClient) getFieldValueByFieldName("zkClient", zookperRegster);
...@@ -207,11 +213,13 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -207,11 +213,13 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
public List<String> checkService(URL url, List<URL> urls, ExecutorDetail detail, List<String> content) { public List<String> checkService(URL url, List<URL> urls, ExecutorDetail detail, List<String> content) {
List<String> result = null; List<String> result = null;
try { try {
result = providerService.findServicesByAddressAndName(url.getAddress(), name); // throw new IllegalStateException(" delete trigger error");
result = providerService.findServicesByAddressAndName(url.getAddress(), name);
} catch (Exception e) { } catch (Exception e) {
urls.remove(url); urls.remove(url);
detail.setCode(-1); detail.setCode(-1);
content.add(" error:check Dubbo service " + Stack.errInfo(e) + StringUtil.line()); logger.info(" error:check Dubbo service " + Stack.errInfo(e) + StringUtil.line());
content.add(" error:check Dubbo service triggering " + url.getServiceKey());
} }
if (result != null && result.size() > 0) { if (result != null && result.size() > 0) {
content.add("check " + url.getServiceKey() + " failure reason zk notice failed " + StringUtil.line()); content.add("check " + url.getServiceKey() + " failure reason zk notice failed " + StringUtil.line());
......
...@@ -9,12 +9,15 @@ public class Constants { ...@@ -9,12 +9,15 @@ public class Constants {
public static final String GROUP_KEY = "group"; public static final String GROUP_KEY = "group";
public static final String CATEGORY_KEY = "category"; public static final String CATEGORY_KEY = "category";
public static final String WEIGHT = "weight"; public static final String WEIGHT = "weight";
public static final String BALANCING = "balancing"; public static final String BALANCING = "balancing";
public static final String ANY_VALUE = "*"; public static final String ANY_VALUE = "*";
public static final String EMPTY_PROTOCOL = "empty"; public static final String EMPTY_PROTOCOL = "empty";
public static final String VERSION_KEY = "version"; public static final String VERSION_KEY = "version";
public static final String PROVIDERS_CATEGORY = "providers"; public static final String PROVIDERS_CATEGORY = "providers";
public static final String PROVIDERS_CONSUMERS = "consumers";
public static final Set<String> CONFIGS = new HashSet<>(); public static final Set<String> CONFIGS = new HashSet<>();
static { static {
......
...@@ -29,7 +29,6 @@ public class RegistryServerSync extends Observable implements InitializingBean, ...@@ -29,7 +29,6 @@ public class RegistryServerSync extends Observable implements InitializingBean,
private final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass()); private final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());
private static final AtomicLong ID = new AtomicLong();
private final ConcurrentHashMap<String, String> URL_IDS_MAPPER = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, String> URL_IDS_MAPPER = new ConcurrentHashMap<>();
private final ConcurrentMap<String, ConcurrentMap<String, Map<String, URL>>> registryCache = new ConcurrentHashMap<>(); private final ConcurrentMap<String, ConcurrentMap<String, Map<String, URL>>> registryCache = new ConcurrentHashMap<>();
...@@ -59,11 +58,11 @@ public class RegistryServerSync extends Observable implements InitializingBean, ...@@ -59,11 +58,11 @@ public class RegistryServerSync extends Observable implements InitializingBean,
@Override @Override
public void destroy() throws Exception { public void destroy() throws Exception {
if (subscribedUrl != null && subscribedUrl.size() > 0) { // if (subscribedUrl != null && subscribedUrl.size() > 0) {
for (URL url : subscribedUrl) { // for (URL url : subscribedUrl) {
registry.unsubscribe(url, this); // registry.unsubscribe(url, this);
} // }
} // }
} }
//通知处理方法 //通知处理方法
...@@ -166,7 +165,11 @@ public class RegistryServerSync extends Observable implements InitializingBean, ...@@ -166,7 +165,11 @@ public class RegistryServerSync extends Observable implements InitializingBean,
subscribedUrl = new ArrayList<URL>(); subscribedUrl = new ArrayList<URL>();
for(URL value: urls){ for(URL value: urls){
try { try {
logger.info("RegistryServerSync subscribe urls " + JSON.toJSONString(value)); if(value!=null&&StringUtil.isNotEmpty(value.getParameter(Constants.CATEGORY_KEY))&&value.getParameter(Constants.CATEGORY_KEY).equals(Constants.PROVIDERS_CONSUMERS)){
logger.info("matrix RegistryServerSync service:{},category:{}",value.getServiceKey(),value.getParameter(Constants.CATEGORY_KEY)); //消费者不用处理,走默认优雅停机就可以
continue;
}
logger.info("RegistryServerSync subscribe service:{},category:{} " ,value.getServiceKey(),value.getParameter(Constants.CATEGORY_KEY));
registry.subscribe(value,this); registry.subscribe(value,this);
subscribedUrl.add(value); subscribedUrl.add(value);
}catch (Exception e){ }catch (Exception e){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment