diff --git a/core/src/main/java/com/qq/tars/client/support/ServantCacheManager.java b/core/src/main/java/com/qq/tars/client/support/ServantCacheManager.java index f0230cc4..2a493f4b 100644 --- a/core/src/main/java/com/qq/tars/client/support/ServantCacheManager.java +++ b/core/src/main/java/com/qq/tars/client/support/ServantCacheManager.java @@ -20,8 +20,6 @@ import com.qq.tars.common.util.Loader; import com.qq.tars.common.util.StringUtils; import com.qq.tars.support.log.LoggerFactory; -import org.slf4j.Logger; - import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; @@ -38,6 +36,7 @@ import java.util.Properties; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; +import org.slf4j.Logger; public final class ServantCacheManager { private static final Logger LOGGER = LoggerFactory.getClientLogger(); @@ -91,7 +90,12 @@ private File getCacheFile(String dataPath) throws Exception { } File f = new File(path, Constants.SERVER_NODE_CACHE_FILENAME); if (!f.exists()) { - f.createNewFile(); + try { + f.createNewFile(); + }catch(IOException e){ + LOGGER.error("Create TarsClient cachefile error,please check path is correct, path is :{}{}", path , Constants.SERVER_NODE_CACHE_FILENAME ); + throw new IOException(e); + } } return f; } diff --git a/core/src/main/java/com/qq/tars/server/apps/BaseAppContext.java b/core/src/main/java/com/qq/tars/server/apps/BaseAppContext.java index af54bb64..6a42473c 100644 --- a/core/src/main/java/com/qq/tars/server/apps/BaseAppContext.java +++ b/core/src/main/java/com/qq/tars/server/apps/BaseAppContext.java @@ -36,7 +36,6 @@ import com.qq.tars.support.trace.TraceCallbackFilter; import com.qq.tars.support.trace.TraceClientFilter; import com.qq.tars.support.trace.TraceServerFilter; - import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; @@ -67,6 +66,7 @@ public abstract class BaseAppContext implements AppContext { @Override public void init() { try { + loadServants(); //inject om admin servant injectAdminServant(); @@ -79,7 +79,6 @@ public void init() { System.out.println("[SERVER] failed to start the application."); } } - protected abstract void loadServants() throws Exception; @Override diff --git a/core/src/main/java/com/qq/tars/server/config/ServerConfig.java b/core/src/main/java/com/qq/tars/server/config/ServerConfig.java index d139b96e..2b8abf6a 100644 --- a/core/src/main/java/com/qq/tars/server/config/ServerConfig.java +++ b/core/src/main/java/com/qq/tars/server/config/ServerConfig.java @@ -20,8 +20,8 @@ import com.qq.tars.common.support.Endpoint; import com.qq.tars.common.util.Config; import com.qq.tars.support.om.OmConstants; - import java.io.File; +import java.io.IOException; import java.util.LinkedHashMap; import java.util.List; @@ -55,6 +55,14 @@ public class ServerConfig { private LinkedHashMap servantAdapterConfMap; private CommunicatorConfig communicatorConfig; + + public void loadSystemConfig(){ + try { + this.load(Config.parseFile(System.getProperty("config"))); + } catch (IOException e) { + throw new RuntimeException(e); + } + } public ServerConfig load(Config conf) { application = conf.get("/tars/application/server", "UNKNOWN"); serverName = conf.get("/tars/application/server", null); diff --git a/core/src/main/java/com/qq/tars/support/notify/NotifyHelper.java b/core/src/main/java/com/qq/tars/support/notify/NotifyHelper.java index 63ef4737..28981ac0 100644 --- a/core/src/main/java/com/qq/tars/support/notify/NotifyHelper.java +++ b/core/src/main/java/com/qq/tars/support/notify/NotifyHelper.java @@ -48,9 +48,7 @@ private void notify(NOTIFYLEVEL level, String message) { if (communicator == null) { return; } - - NotifyPrx notifyPrx = communicator.stringToProxy(NotifyPrx.class, ConfigurationManager.getInstance().getServerConfig().getNotify()); - notifyPrx.async_notifyServer(null, app + "." + server, level.value(), message); + report( message, level,false); } catch (Exception e) { omLogger.error("RemoteNotify|notify error", e); } @@ -69,23 +67,24 @@ public void notifyError(String info) { } public void syncReport(String result) { - report(result, true); + report(result,NOTIFYLEVEL.NOTIFYNORMAL, true); } public void asyncReport(String result) { - report(result, false); + report(result, NOTIFYLEVEL.NOTIFYNORMAL,false); } - private void report(String result, boolean sync) { + private void report(String result,final NOTIFYLEVEL notifylevel, final Boolean sync) { try { if (communicator == null) { return; } - NotifyPrx notifyPrx = communicator.stringToProxy(NotifyPrx.class, ConfigurationManager.getInstance().getServerConfig().getNotify()); + final NotifyPrx notifyPrx = communicator.stringToProxy(NotifyPrx.class, ConfigurationManager.getInstance().getServerConfig().getNotify()); final ReportInfo reportInfo = new ReportInfo(); reportInfo.setSThreadId(String.valueOf(Thread.currentThread().getId())); reportInfo.setSServer(app + "." + server ); reportInfo.setSMessage( result); + reportInfo.setELevel(notifylevel.value()); if(sync){ notifyPrx.reportNotifyInfo(reportInfo); }else{ diff --git a/core/src/main/java/com/qq/tars/support/notify/prx/NotifyPrx.java b/core/src/main/java/com/qq/tars/support/notify/prx/NotifyPrx.java index 0e012ea1..fa861b7a 100644 --- a/core/src/main/java/com/qq/tars/support/notify/prx/NotifyPrx.java +++ b/core/src/main/java/com/qq/tars/support/notify/prx/NotifyPrx.java @@ -28,90 +28,6 @@ @Servant public interface NotifyPrx { - /** - * The information reported by the framework is stored in the database - * @param sServerName, server name - * @param sThreadId, server current thread id - * @param sMessage, message - **/ - public void reportServer(String sServerName, String sThreadId, String sMessage); - /** - * The information reported by the framework is stored in the database - * @param sServerName, server name - * @param sThreadId, server current thread id - * @param sMessage, message - **/ - public void reportServer(String sServerName, String sThreadId, String sMessage, @TarsContext java.util.Map ctx); - /** - * The information reported by the framework is stored in the database - * @param sServerName, server name - * @param sThreadId, server current thread id - * @param sMessage, message - **/ - public void async_reportServer(@TarsCallback NotifyPrxCallback callback, String sServerName, String sThreadId, String sMessage); - /** - * The information reported by the framework is stored in the database - * @param sServerName, server name - * @param sThreadId, server current thread id - * @param sMessage, message - **/ - public void async_reportServer(@TarsCallback NotifyPrxCallback callback, String sServerName, String sThreadId, String sMessage, @TarsContext java.util.Map ctx); - /** - * Business reported information, used for alarm - * @param sServerName, server name - * @param level, notify level - * @param sMessage, message - **/ - public void notifyServer(String sServerName, int level, String sMessage); - /** - * Business reported information, used for alarm - * @param sServerName, server name - * @param level, notify level - * @param sMessage, message - **/ - public void notifyServer(String sServerName, int level, String sMessage, @TarsContext java.util.Map ctx); - /** - * Business reported information, used for alarm - * @param sServerName, server name - * @param level, notify level - * @param sMessage, message - **/ - public void async_notifyServer(@TarsCallback NotifyPrxCallback callback, String sServerName, int level, String sMessage); - /** - * Business reported information, used for alarm - * @param sServerName, server name - * @param level, notify level - * @param sMessage, message - **/ - public void async_notifyServer(@TarsCallback NotifyPrxCallback callback, String sServerName, int level, String sMessage, @TarsContext java.util.Map ctx); - /** - * Get report information - * @param sServerName, server name - * @param out , notify info detail - * @return int 0=success, others=failed - **/ - public int getNotifyInfo(NotifyKey stKey, @TarsHolder Holder stInfo); - /** - * Get report information - * @param sServerName, server name - * @param out , notify info detail - * @return int 0=success, others=failed - **/ - public int getNotifyInfo(NotifyKey stKey, @TarsHolder Holder stInfo, @TarsContext java.util.Map ctx); - /** - * Get report information - * @param sServerName, server name - * @param out , notify info detail - * @return int 0=success, others=failed - **/ - public void async_getNotifyInfo(@TarsCallback NotifyPrxCallback callback, NotifyKey stKey); - /** - * Get report information - * @param sServerName, server name - * @param out , notify info detail - * @return int 0=success, others=failed - **/ - public void async_getNotifyInfo(@TarsCallback NotifyPrxCallback callback, NotifyKey stKey, @TarsContext java.util.Map ctx); public void reportNotifyInfo(ReportInfo info); diff --git a/core/src/main/java/com/qq/tars/support/om/OmServiceMngr.java b/core/src/main/java/com/qq/tars/support/om/OmServiceMngr.java index 5a072b76..cf08ab39 100644 --- a/core/src/main/java/com/qq/tars/support/om/OmServiceMngr.java +++ b/core/src/main/java/com/qq/tars/support/om/OmServiceMngr.java @@ -45,7 +45,7 @@ public static OmServiceMngr getInstance() { return Instance; } - public void initAndStartOmService() { + public synchronized void initAndStartOmService() { Communicator communicator = CommunicatorFactory.getInstance().getCommunicator(); String app = ConfigurationManager.getInstance().getServerConfig().getApplication(); String serverName = ConfigurationManager.getInstance().getServerConfig().getServerName(); diff --git a/pom.xml b/pom.xml index 96cd3952..d98a8f73 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.tencent.tars tars-parent - ${revision} + ${revision} pom Tars Super POM For Projects diff --git a/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java b/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java index cf4169a5..283a7042 100644 --- a/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java +++ b/spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java @@ -16,10 +16,10 @@ package com.qq.tars.server.apps; -import com.qq.tars.common.support.Endpoint; import com.qq.tars.common.util.StringUtils; import com.qq.tars.protocol.annotation.Servant; import com.qq.tars.protocol.util.TarsHelper; +import com.qq.tars.server.config.ConfigurationException; import com.qq.tars.server.config.ConfigurationManager; import com.qq.tars.server.config.ServantAdapterConfig; import com.qq.tars.server.config.ServerConfig; @@ -28,7 +28,11 @@ import com.qq.tars.spring.annotation.TarsServant; import com.qq.tars.spring.config.TarsClientProperties; import com.qq.tars.spring.config.TarsServerProperties; +import com.qq.tars.support.om.OmServiceMngr; import com.qq.tars.support.trace.TarsTraceZipkinConfiguration; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; @@ -38,10 +42,6 @@ import org.springframework.context.SmartLifecycle; import org.springframework.core.annotation.AnnotatedElementUtils; -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Map; - public class TarsStartLifecycle extends BaseAppContext implements SmartLifecycle, ApplicationContextAware { private static final Log log = LogFactory.getLog(TarsStartLifecycle.class); @@ -82,12 +82,12 @@ public void start() { initConfig(); loadAppServants(); - initServants(); injectAdminServant(); + initServants(); appContextStarted(); startServantAdapter(); setAppContext(); - + OmServiceMngr.getInstance().initAndStartOmService(); this.isRunning = true; } catch (IOException e) { e.printStackTrace(); @@ -119,14 +119,13 @@ private void initConfig() { serverProperties.setServantAdapterConfMap(new LinkedHashMap()); ConfigurationManager.getInstance().setServerConfig(this.serverProperties); ConfigurationManager.getInstance().setCommunicatorConfig(this.clientProperties); + try { + ConfigurationManager.getInstance().init(); + } catch (ConfigurationException e) { + log.error("spring cloud init server config error!" ,e); + throw new RuntimeException(e); + } - servantAdapterConfig = new ServantAdapterConfig(); - servantAdapterConfig.setEndpoint(new Endpoint(serverProperties.isUdp() ? "udp" : "tcp", StringUtils.isEmpty(serverProperties.getLocalIP()) ? "0.0.0.0" : serverProperties.getLocalIP(), serverProperties.getPort(), 0, 0, 0, null)); - servantAdapterConfig.setHandleGroup("default"); - servantAdapterConfig.setMaxConns(serverProperties.getMaxConns()); - servantAdapterConfig.setThreads(serverProperties.getThreads()); - servantAdapterConfig.setQueueCap(serverProperties.getQueueCap()); - servantAdapterConfig.setQueueTimeout(serverProperties.getQueueTimeout()); TarsTraceZipkinConfiguration.getInstance().init(); } @@ -178,7 +177,7 @@ private ServantHomeSkeleton loadServant(Object bean) throws Exception { skeleton = new ServantHomeSkeleton(homeName, homeClassImpl, homeApiClazz, null, null, maxLoadLimit); skeleton.setAppContext(this); - + servantAdapterConfig = ConfigurationManager.getInstance().getServerConfig().getServantAdapterConfMap().get(homeName); ConfigurationManager.getInstance().getServerConfig().getServantAdapterConfMap().put(homeName, servantAdapterConfig); return skeleton;