Commit 690a2f81 by 房斌

1日志更改 2目录变更 3属性读对象中读取

parent 23e97c41
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.secoo.mall.dubbo.monitor.config;
import com.secoo.mall.common.util.string.StringUtil;
import com.secoo.mall.dubbo.monitor.dubbo.Constants.Constants;
import com.secoo.mall.dubbo.monitor.dubbo.exception.ConfigurationException;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ConfigCenter {
@Value("${dubbo.registry.address:}")
public String registryAddress;
@Value("${dubbo.protocol.name}")
public String registryGroup;
@Value("${dubbo.registry.username:}")
public String username;
@Value("${dubbo.registry.password:}")
public String password;
@Value("${dubbo.monitorpatch:}")
public String patch;
@Value("${dubbo.application.timeout:}")
public String timeout;
public URL registryUrl;
@Bean
Registry getRegistry() {
Registry registry = null;
if (registryUrl == null) {
if (StringUtils.isBlank(registryAddress)) {
throw new ConfigurationException("Either config center or registry address is needed, please refer to https://github.com/apache/incubator-dubbo-admin/wiki/Dubbo-Admin-configuration");
}
registryUrl = formUrl(registryAddress, registryGroup, username, password,timeout);
// registryUrl.setPath(patch);
}
RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
registry = registryFactory.getRegistry(registryUrl);
return registry;
}
public URL formUrl(String config, String group, String username, String password,String timeout) {
URL url = URL.valueOf(config);
if (StringUtils.isNotEmpty(group)) {
url = url.addParameter(Constants.GROUP_KEY, group);
}
if(StringUtil.isEmpty(timeout)){
url=url.addParameter("timeout",20000);
}else{
url=url.addParameter("timeout", Integer.valueOf(timeout).intValue());
}
if (StringUtils.isNotEmpty(username)) {
url = url.setUsername(username);
}
if (StringUtils.isNotEmpty(password)) {
url = url.setPassword(password);
}
return url;
}
}
package com.secoo.mall.dubbo.service; package com.secoo.mall.gracefulshutdown.component;
import com.secoo.mall.common.core.service.StopService; import com.secoo.mall.common.core.service.StopService;
import com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail; import com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail;
......
package com.secoo.mall.dubbo.service.impl; package com.secoo.mall.gracefulshutdown.component.hook;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail; 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.dubbo.monitor.dubbo.service.ProviderService; import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.ProviderService;
import com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync; import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.RegistryServerSync;
import com.secoo.mall.dubbo.monitor.utils.Stack; import com.secoo.mall.gracefulshutdown.monitor.utils.Stack;
import com.secoo.mall.dubbo.service.AbstractShutDown; import com.secoo.mall.gracefulshutdown.component.AbstractShutDown;
import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.NetUtils;
...@@ -56,7 +56,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -56,7 +56,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("dubboDownHock1058"); detail.setServiceName("dubboDownHock1061");
List<String> str = new ArrayList<String>(); List<String> str = new ArrayList<String>();
detail.setDetail(str); detail.setDetail(str);
detail.setCode(0); detail.setCode(0);
...@@ -73,17 +73,16 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -73,17 +73,16 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
while (iterator.hasNext()) { while (iterator.hasNext()) {
Registry r = iterator.next(); Registry r = iterator.next();
zookperRegster = (ZookeeperRegistry) r; zookperRegster = (ZookeeperRegistry) r;
str.add(" DubboCustomerShutDownHook zookperRegstered-------------->"+zookperRegster.getRegistered().toString()+StringUtil.line()); logger.info(" DubboCustomerShutDownHook ip:{},name :{}, zookperRegstered ,:{}",ip,name,zookperRegster.getRegistered().toString()+StringUtil.line());
if (zookperRegster.getRegistered() != null && zookperRegster.getRegistered().size() > 0) { if (zookperRegster.getRegistered() != null && zookperRegster.getRegistered().size() > 0) {
urls = zookperRegster.getRegistered(); urls = zookperRegster.getRegistered();
str.add(" DubboCustomerShutDownHook zookperRegstered urls-------------->"+((urls!=null&&urls.size()>0)?JSON.toJSONString(urls):"url si null")+StringUtil.line()); logger.info(" DubboCustomerShutDownHook ip:{},name :{},zookperRegstered urls :{}",ip,name,((urls!=null&&urls.size()>0)?JSON.toJSONString(urls):"url si null")+StringUtil.line());
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) {
checks.add(value); checks.add(value);
try { try {
str.add("provider url executer unregister before:" + value.getServiceInterface() + " time:" + 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());
// throw new IllegalStateException("failed to tet");
zookperRegster.unregister((URL) value); zookperRegster.unregister((URL) value);
registryServerSync.setSignal(true); registryServerSync.setSignal(true);
...@@ -91,13 +90,13 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -91,13 +90,13 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
str.add("delete provider url success:" + value.getServiceInterface() + " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line()); str.add("delete provider url success:" + value.getServiceInterface() + " time:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()) +StringUtil.line());
} catch (Exception e) { } catch (Exception e) {
LoggerUtil.error("matirx-monitor deleteService error:", e); LoggerUtil.error("matirx-monitor deleteService error:", e);
str.add("matirx-monitor delete Service error service:"+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());
}finally { }finally {
registryServerSync.setSignal(true); registryServerSync.setSignal(true);
} }
} }
}else{ }else{
str.add("warn:matrix-monitor no dubbo registered for delete ip " + ip + " name :" +name+ StringUtil.line()); str.add("warn:matrix-monitor no gracefulshutdown registered for delete ip " + ip + " name :" +name+ StringUtil.line());
detail.setCode(-1); detail.setCode(-1);
} }
break; break;
...@@ -113,10 +112,9 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -113,10 +112,9 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
long startTime=System.currentTimeMillis(); //获取开始时间 long startTime=System.currentTimeMillis(); //获取开始时间
detail = checkNoticed(detail, str, checks, sessionExpireMs);//通过通知进行检查 detail = checkNoticed(detail, str, checks, sessionExpireMs);//通过通知进行检查
long endTime=System.currentTimeMillis(); //获取结束时间 long endTime=System.currentTimeMillis(); //获取结束时间
logger.info("程序运行时间------------>: "+(endTime-startTime)+"ms"); logger.info(" check time ip:{},name:{} ",ip,name,(endTime-startTime)+"ms");
if (checks.size() > 0) { // 处理 没有接到通知的场景 if (checks.size() > 0) { // 处理 没有接到通知的场景
logger.info("NNNNNNNNNNNNNNNNNNNNNNNNOOOOOOOOOOOO!"+JSON.toJSONString(checks));
for (URL check : checks) { for (URL check : checks) {
checkService(check, checks, detail, str); checkService(check, checks, detail, str);
} }
...@@ -135,7 +133,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -135,7 +133,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
DubboShutdownHook.getDubboShutdownHook().doDestroy(); DubboShutdownHook.getDubboShutdownHook().doDestroy();
} }
detail.setEndTime(DateUtil.getDateTime()); detail.setEndTime(DateUtil.getDateTime());
logger.info("GracefulShutDown dubbo end execute:name:" + name + " ip:" + ip + " time:" + DateUtil.getDateTime()); logger.info("gracefulshutdown gracefulshutdown end execute:name:" + name + " ip:" + ip + " time:" + DateUtil.getDateTime());
return detail; return detail;
} }
...@@ -209,28 +207,27 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -209,28 +207,27 @@ 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 {
// throw new IllegalStateException("failed to tet");
result = providerService.findServicesByAddressAndName(url.getAddress(), name); 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 :matirx-monitor checko Dubbo service " + StringUtil.line() + Stack.errInfo(e) + StringUtil.line()); content.add(" error :matirx-monitor check Dubbo service " + StringUtil.line() + Stack.errInfo(e) + StringUtil.line());
} }
if (result != null && result.size() > 0) { if (result != null && result.size() > 0) {
content.add("warn:matrix-monitor check service failure " + url.getServiceKey() + " reason zk notice failed " + StringUtil.line()); content.add("warn:matrix-monitor check service failure " + url.getServiceKey() + " reason zk notice failed " + StringUtil.line());
detail.setCode(-1); detail.setCode(-1);
} else { } else {
if (result != null && result.size() == 0) { if (result != null && result.size() == 0) {
content.add("matrix-monitor dubbo check service ok " + url.getServiceKey() + StringUtil.line()); content.add("matrix-monitor gracefulshutdown check service ok " + url.getServiceKey() + StringUtil.line());
} }
} }
logger.info("checkServicecheckServicecheckServicecheckServicecheckServicecheckServicecheckServicecheckService!!!!!");
return result; return result;
} }
private class CheckDubbo implements Callable<ExecutorDetail> { private class CheckDubbo implements Callable<ExecutorDetail> {
ExecutorDetail detail; ExecutorDetail detail;
List<String> str; List<String> str;
//待检查接口
List<URL> checks; List<URL> checks;
int time; int time;
...@@ -276,7 +273,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser ...@@ -276,7 +273,7 @@ public class DubboCustomerShutDownHook extends AbstractShutDown implements Obser
} }
Thread.sleep(500);//休息500毫秒 Thread.sleep(500);//休息500毫秒
} }
logger.info("checks size!!!!!"+checks.size()); logger.info("checks size ip,name!!!!!",ip,name,checks.size());
return detail; return detail;
} }
} }
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.secoo.mall.gracefulshutdown.monitor.config;
import org.springframework.core.env.Environment;
public class ConfigCenter {
public String registryAddress;
public String registryGroup;
public String username;
public String password;
public String patch;
public String timeout;
public void init(Environment env) {
registryAddress = env.getProperty("dubbo.registry.address");
registryGroup = env.getProperty("dubbo.protocol.name");
username = env.getProperty("dubbo.registry.username");
password = env.getProperty("dubbo.registry.password");
timeout = env.getProperty("dubbo.application.timeout");
patch = env.getProperty("dubbo.monitorpatch");
}
public String getRegistryAddress() {
return registryAddress;
}
public void setRegistryAddress(String registryAddress) {
this.registryAddress = registryAddress;
}
public String getRegistryGroup() {
return registryGroup;
}
public void setRegistryGroup(String registryGroup) {
this.registryGroup = registryGroup;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPatch() {
return patch;
}
public void setPatch(String patch) {
this.patch = patch;
}
public String getTimeout() {
return timeout;
}
public void setTimeout(String timeout) {
this.timeout = timeout;
}
}
package com.secoo.mall.dubbo.monitor.dubbo.Constants; package com.secoo.mall.gracefulshutdown.monitor.dubbo.Constants;
import java.util.HashSet; import java.util.HashSet;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.secoo.mall.dubbo.monitor.dubbo.exception; package com.secoo.mall.gracefulshutdown.monitor.dubbo.exception;
public class ConfigurationException extends RuntimeException { public class ConfigurationException extends RuntimeException {
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.secoo.mall.dubbo.monitor.dubbo.service.impl; package com.secoo.mall.gracefulshutdown.monitor.dubbo.service.impl;
import com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync; import com.secoo.mall.gracefulshutdown.monitor.dubbo.service.RegistryServerSync;
import org.apache.dubbo.common.URL; import org.apache.dubbo.common.URL;
import java.util.Map; import java.util.Map;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.secoo.mall.dubbo.monitor.utils; package com.secoo.mall.gracefulshutdown.monitor.utils;
import org.apache.dubbo.common.io.Bytes; import org.apache.dubbo.common.io.Bytes;
import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.Logger;
......
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