entry : labels.entrySet()) {
- finalGroup.append(LABEL_PREFIX)
- .append(buildSingleLabel(entry.getKey(), entry.getValue()))
- .append(GROUP_SEPARATOR);
- }
- return finalGroup.deleteCharAt(finalGroup.length() - 1).toString();
- }
-
- private static String buildSingleLabel(String key, String value) {
- try {
- return URLEncoder.encode(key + LABEL_QUERY_SEPARATOR + value, "UTF-8");
- } catch (UnsupportedEncodingException ignored) {
- // ignored
- }
- return StringUtils.EMPTY;
- }
-}
diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/service/dynamicconfig/zookeeper/ZookeeperDynamicConfigurationService.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/service/dynamicconfig/zookeeper/ZookeeperDynamicConfigurationService.java
deleted file mode 100644
index 753e9c5ccc..0000000000
--- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/service/dynamicconfig/zookeeper/ZookeeperDynamicConfigurationService.java
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * Copyright (C) 2021-2021 Huawei Technologies Co., Ltd. All rights reserved.
- *
- * Licensed 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.huaweicloud.sermant.backend.service.dynamicconfig.zookeeper;
-
-import com.huaweicloud.sermant.backend.common.exception.ZookeeperDynamicConfigurationException;
-import com.huaweicloud.sermant.backend.service.dynamicconfig.Config;
-import com.huaweicloud.sermant.backend.service.dynamicconfig.service.ConfigChangeType;
-import com.huaweicloud.sermant.backend.service.dynamicconfig.service.ConfigChangedEvent;
-import com.huaweicloud.sermant.backend.service.dynamicconfig.service.ConfigurationListener;
-import com.huaweicloud.sermant.backend.service.dynamicconfig.service.DynamicConfigurationService;
-
-import org.apache.zookeeper.AddWatchMode;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.ZooDefs;
-import org.apache.zookeeper.ZooKeeper;
-import org.apache.zookeeper.data.Stat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Locale;
-import java.util.Vector;
-
-/**
- * Zookeeper implementation for DynamicConfigurationService
- */
-public class ZookeeperDynamicConfigurationService implements DynamicConfigurationService {
-
- private static final Logger logger = LoggerFactory.getLogger(ZookeeperDynamicConfigurationService.class);
-
- ZooKeeper zkClient;
-
- static private ZookeeperDynamicConfigurationService serviceInst;
-
- private ZookeeperDynamicConfigurationService() {
-
- }
-
- @Override
- public String getDefaultGroup() {
- return Config.getDefaultGroup();
- }
-
- @Override
- public long getDefaultTimeout() {
- return Config.getTimeout_value();
- }
-
- /**
- * zookeeper 动态配置实现
- *
- * @return 配置实现
- * @throws ZookeeperDynamicConfigurationException 异常
- */
- public static synchronized ZookeeperDynamicConfigurationService getInstance()
- throws ZookeeperDynamicConfigurationException {
- if (serviceInst == null) {
- serviceInst = new ZookeeperDynamicConfigurationService();
- URI zkUri;
-
- try {
- zkUri = new URI(Config.getZookeeperUri());
- } catch (URISyntaxException e) {
- logger.error(e.getMessage(), e);
- throw new ZookeeperDynamicConfigurationException(e.getMessage());
- }
-
- String zkConStr = zkUri.getHost();
- if (zkUri.getPort() > 0) {
- zkConStr = zkConStr + ":" + zkUri.getPort();
- }
-
- ZooKeeper zkInst;
- try {
- zkInst = new ZooKeeper(zkConStr, Config.getTimeout_value(), new Watcher() {
- @Override
- public void process(WatchedEvent event) {
- }
- });
- } catch (IOException e) {
- logger.error(e.getMessage(), e);
- throw new ZookeeperDynamicConfigurationException(e.getMessage());
- }
-
- serviceInst.zkClient = zkInst;
- }
-
- return serviceInst;
- }
-
- private String getPath(String key, String group) {
- group = fixGroup(group);
- return group.startsWith("/") ? group + key : '/' + group + key;
- }
-
- private String fixGroup(String group) {
- return group == null ? getDefaultGroup() : group;
- }
-
- private ConfigChangeType transEventType(Watcher.Event.EventType type) {
- switch (type) {
- case NodeCreated:
- return ConfigChangeType.ADDED;
- case NodeDeleted:
- return ConfigChangeType.DELETED;
- case None:
- case NodeDataChanged:
- case DataWatchRemoved:
- case ChildWatchRemoved:
- case NodeChildrenChanged:
- case PersistentWatchRemoved:
- default:
- return ConfigChangeType.MODIFIED;
- }
- }
-
- /**
- * 添加组监听
- * 若由Kie配置中心转换而来,则配置路径为/group/key
- *
- * 其中:
- * group: 由{@link LabelGroupUtils#createLabelGroup(Map)}生成
- * key: 则是对应kie的键名
- *
- * 第一次添加会将group下的所有子路径的数据通知给监听器
- *
- * @param group 分组
- * @param listener 监听器
- * @return boolean
- */
- @Override
- public boolean addGroupListener(String group, ConfigurationListener listener) {
- try {
- if (listener == null) {
- return false;
- }
- // 监听group底下所有的子节点数据变更
- final String path = getPath("", fixGroup(group));
- zkClient.addWatch(path, new Watcher() {
- @Override
- public void process(WatchedEvent event) {
- if (event.getPath() == null || event.getPath().equals(path)
- || !event.getPath().startsWith(path)) {
- return;
- }
- // 带有分隔符"/"的键
- String keyWithSeparator = event.getPath().substring(group.length() + 1);
- if (keyWithSeparator.length() < 1) {
- return;
- }
- final String content = getConfig(keyWithSeparator, group);
- listener.process(new ConfigChangedEvent(keyWithSeparator.substring(1), group, content,
- transEventType(event.getType())));
- }
- }, AddWatchMode.PERSISTENT_RECURSIVE);
- notifyGroup(group, listener);
- } catch (KeeperException.NoNodeException ignored) {
- // ignored
- } catch (Exception e) {
- logger.warn(
- String.format(Locale.ENGLISH, "Added zookeeper group listener failed, %s", e.getMessage()), e);
- return false;
- }
- return true;
- }
-
- @Override
- public boolean removeGroupListener(String key, String group, ConfigurationListener listener) {
- return true;
- }
-
- /**
- * 添加zookeeper路径监听
- * 将会监听路径/group/key
的数据变更
- * 一次添加将会将节点数据通知给监听器
- *
- * @param key 子路径
- * @param group 父路径
- * @param listener 监听器
- * @return 当连接zk失败返回false
- */
- @Override
- public boolean addConfigListener(String key, String group, ConfigurationListener listener) {
-
- if (listener == null) {
- return false;
- }
-
- final String finalGroup = fixGroup(group);
- final String fullPath = getPath(key, finalGroup);
- Watcher wc = new Watcher() {
- @Override
- public void process(WatchedEvent event) {
- if (!fullPath.equals(event.getPath())) {
- logger.warn("unexpected event " + event + " for " + key + ":" + finalGroup);
- }
- String content = getConfig(key, finalGroup);
- ConfigChangeType changeType = transEventType(event.getType());
- ConfigChangedEvent cce = new ConfigChangedEvent(key, finalGroup, content, changeType);
- listener.process(cce);
- }
- };
-
- try {
- zkClient.addWatch(fullPath, wc, AddWatchMode.PERSISTENT);
- notifyKey(key, group, listener);
- } catch (KeeperException.NoNodeException ignored) {
- // ignored
- } catch (Exception e) {
- logger.warn(e.getMessage(), e);
- return false;
- }
- return true;
- }
-
- /**
- * @param key postfix of key path
- * @param group prefix of key path
- * @param listener configuration listener
- */
- @Override
- public boolean removeConfigListener(String key, String group, ConfigurationListener listener) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @param key key path
- */
- @Override
- public String getConfig(String key, String group) {
-
- final String fullPath = getPath(key, group);
-
- String rs = null;
- try {
- Stat st = new Stat();
- rs = new String(zkClient.getData(fullPath, false, st));
- } catch (Exception e) {
- logger.warn(e.getMessage(), e);
- return null;
- }
- return rs;
- }
-
-
- @Override
- public boolean publishConfig(String key, String group, String content) {
-
- final String fullPath = getPath(key, group);
-
- boolean rs = false;
- try {
- rs = this.updateNode(fullPath, content.getBytes(StandardCharsets.UTF_8), -1);
- } catch (Exception e) {
- logger.warn(e.getMessage(), e);
- return false;
- }
- return rs;
- }
-
-
- protected boolean createRecursivly(String path) {
- try {
- if (zkClient.exists(path, null) == null && path.length() > 0) {
- String temp = path.substring(0, path.lastIndexOf("/"));
- if (temp != null && temp.length() > 1) {
- createRecursivly(temp);
- }
- zkClient.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
- }
- } catch (KeeperException e) {
- logger.warn(e.getMessage(), e);
- return false;
- } catch (InterruptedException e) {
- logger.warn(e.getMessage(), e);
- return false;
- }
- return true;
-
- }
-
- protected boolean updateNode(String path, byte[] data, int version) {
- try {
- if (zkClient.exists(path, null) == null) {
- createRecursivly(path);
- }
- zkClient.setData(path, data, version);
- } catch (KeeperException e) {
- logger.warn(e.getMessage(), e);
- return false;
- } catch (InterruptedException e) {
- logger.warn(e.getMessage(), e);
- return false;
- }
- return true;
-
- }
-
- @Override
- public void close() {
- try {
- this.zkClient.close();
- } catch (InterruptedException e) {
- logger.error(e.getMessage(), e);
- }
- }
-
- @Override
- public List listConfigsFromGroup(String group) {
- group = group.trim();
- if (!group.startsWith("/")) {
- group = "/" + group;
- }
- List strArray = null;
- try {
- strArray = listNodesFromNode(group);
- } catch (Exception e) {
- logger.warn(e.getMessage(), e);
- }
- return strArray;
- }
-
- @Override
- public List listConfigsFromConfig(String key, String group) {
- group = group.trim();
- if (!group.startsWith("/")) {
- group = "/" + group;
- }
- key = key.trim();
- if (!key.startsWith("/")) {
- key = "/" + key;
- }
-
- List strArray = null;
- try {
- strArray = listNodesFromNode(group + key);
- } catch (Exception e) {
- logger.warn(e.getMessage(), e);
- }
- return strArray;
- }
-
- private List listNodesFromNode(String node) {
- List strArray = new Vector();
- try {
- if (zkClient.exists(node, false) != null) {
- strArray = zkClient.getChildren(node, null);
- }
- } catch (Exception e) {
- logger.warn(e.getMessage(), e);
- }
- for (int len = 0; len < strArray.size(); len++) {
- String str = strArray.get(len);
- for (String grandChild : listNodesFromNode(node + "/" + str)) {
- strArray.add(str + '/' + grandChild);
- }
- }
-
- return strArray;
- }
-
- /**
- * 第一次增加监听器时,将关联查询的数据传给listener
- *
- * @param group 分组
- * @param listener 监听器
- */
- private void notifyGroup(String group, ConfigurationListener listener) {
- final List keys = listConfigsFromGroup(group);
- if (keys != null) {
- for (String key : keys) {
- notifyKey(key, group, listener);
- }
- }
- }
-
- private void notifyKey(String key, String group, ConfigurationListener listener) {
- final String content = getConfig(fixKey(key), group);
- listener.process(new ConfigChangedEvent(key, group, content, ConfigChangeType.ADDED));
- }
-
- private String fixKey(String key) {
- if (key == null) {
- return null;
- }
- return key.startsWith("/") ? key : "/" + key;
- }
-}
diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/cache/DeleteTimeoutData.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/timer/DeleteTimeoutDataTask.java
similarity index 51%
rename from sermant-backend/src/main/java/com/huaweicloud/sermant/backend/cache/DeleteTimeoutData.java
rename to sermant-backend/src/main/java/com/huaweicloud/sermant/backend/timer/DeleteTimeoutDataTask.java
index 65a1f6c5ed..95c69d92a0 100644
--- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/cache/DeleteTimeoutData.java
+++ b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/timer/DeleteTimeoutDataTask.java
@@ -14,11 +14,13 @@
* limitations under the License.
*/
-package com.huaweicloud.sermant.backend.cache;
+package com.huaweicloud.sermant.backend.timer;
+import com.huaweicloud.sermant.backend.cache.CollectorCache;
+import com.huaweicloud.sermant.backend.cache.HeartbeatCache;
import com.huaweicloud.sermant.backend.common.conf.VisibilityConfig;
-import com.huaweicloud.sermant.backend.entity.HeartbeatEntity;
-import com.huaweicloud.sermant.backend.entity.ServerInfo;
+import com.huaweicloud.sermant.backend.entity.heartbeat.HeartbeatMessage;
+import com.huaweicloud.sermant.backend.entity.visibility.ServerInfo;
import java.util.Iterator;
import java.util.Map;
@@ -30,20 +32,25 @@
* @author xuezechao
* @since 2022-03-14
*/
-public class DeleteTimeoutData extends TimerTask {
+public class DeleteTimeoutDataTask extends TimerTask {
+ private final long maxEffectiveTime;
- private static final int MAX_EFFECTIVE_TIME = 6000;
+ private final long maxCacheTime;
- private VisibilityConfig visibilityConfig;
+ private final VisibilityConfig visibilityConfig;
/**
- * 初始化任务
+ * 构造方法
*
+ * @param maxEffectiveTime 最大有效时间
+ * @param maxCacheTime 最大缓存时间
* @param visibilityConfig 服务可见性配置
*/
- public DeleteTimeoutData(VisibilityConfig visibilityConfig) {
- deleteHeartbeatCache();
+ public DeleteTimeoutDataTask(long maxEffectiveTime, long maxCacheTime, VisibilityConfig visibilityConfig) {
+ this.maxEffectiveTime = maxEffectiveTime;
+ this.maxCacheTime = maxCacheTime;
this.visibilityConfig = visibilityConfig;
+ deleteHeartbeatCache();
}
@Override
@@ -53,15 +60,18 @@ public void run() {
}
private void deleteHeartbeatCache() {
- Map heartbeatMessages = HeartbeatCache.getHeartbeatMessages();
- for (Iterator> it = heartbeatMessages.entrySet().iterator();
- it.hasNext(); ) {
- Map.Entry heartbeatEntityEntry = it.next();
+ Map heartbeatMessages = HeartbeatCache.getHeartbeatMessageMap();
+ for (Iterator> it = heartbeatMessages.entrySet().iterator();
+ it.hasNext();) {
+ Map.Entry heartbeatMessageEntry = it.next();
long nowTime = System.currentTimeMillis();
- long lastHeartbeatTime = heartbeatEntityEntry.getValue().getLastHeartbeat();
- if ((nowTime - lastHeartbeatTime) > MAX_EFFECTIVE_TIME) {
+ long receiveTime = heartbeatMessageEntry.getValue().getReceiveTime();
+ if ((nowTime - receiveTime) > maxCacheTime) {
it.remove();
}
+ if ((nowTime - receiveTime) > maxEffectiveTime) {
+ heartbeatMessageEntry.getValue().setHealth(false);
+ }
}
}
@@ -69,12 +79,12 @@ private void deleteHeartbeatCache() {
* 清理服务可见性采集的信息
*/
private void deleteCollectorCache() {
- Map heartbeatMessages = HeartbeatCache.getHeartbeatDate();
- for (Iterator> it = heartbeatMessages.entrySet().iterator(); it.hasNext(); ) {
+ for (Iterator> it =
+ CollectorCache.SERVER_VALIDITY_PERIOD_MAP.entrySet().iterator(); it.hasNext();) {
Map.Entry heartbeatEntityEntry = it.next();
long nowTime = System.currentTimeMillis();
- if ((nowTime - heartbeatEntityEntry.getValue().getValidateDate().getTime())
- > visibilityConfig.getEffectiveTimes()) {
+ if ((nowTime - heartbeatEntityEntry.getValue().getValidateDate().getTime()) > visibilityConfig
+ .getEffectiveTimes()) {
CollectorCache.removeServer(heartbeatEntityEntry.getValue());
it.remove();
}
diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/BackendThreadFactory.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/BackendThreadFactory.java
deleted file mode 100644
index 6516b3bddb..0000000000
--- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/BackendThreadFactory.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2021-2021 Huawei Technologies Co., Ltd. All rights reserved.
- *
- * Licensed 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.huaweicloud.sermant.backend.util;
-
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicInteger;
-
-public class BackendThreadFactory implements ThreadFactory {
- private final static AtomicInteger FACTORY_NUMBER = new AtomicInteger(0);
-
- private final AtomicInteger threadNumber = new AtomicInteger(0);
-
- private final String threadPrefix;
-
- private final boolean daemon;
-
- public BackendThreadFactory() {
- this("backend", true);
- }
-
- public BackendThreadFactory(String threadName) {
- this(threadName, true);
- }
-
- public BackendThreadFactory(String threadName, boolean daemon) {
- this.threadPrefix = prefix(threadName, FACTORY_NUMBER.getAndIncrement());
- this.daemon = daemon;
- }
-
- public static ThreadFactory createThreadFactory(String threadName) {
- return createThreadFactory(threadName, false);
- }
-
- public static ThreadFactory createThreadFactory(String threadName, boolean daemon) {
- return new BackendThreadFactory(threadName, daemon);
- }
-
- private String prefix(String threadName, int factoryId) {
- return threadName + '(' + factoryId + ')';
- }
-
- @Override
- public Thread newThread(Runnable job) {
- String newThreadName = createThreadName();
- Thread thread = new Thread(job, newThreadName);
- if (daemon) {
- thread.setDaemon(true);
- }
- return thread;
- }
-
- private String createThreadName() {
- return threadPrefix + threadNumber.getAndIncrement() + ')';
- }
-}
diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/DateUtil.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/DateUtil.java
deleted file mode 100644
index 9a1bcd3099..0000000000
--- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/DateUtil.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
- *
- * Licensed 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.huaweicloud.sermant.backend.util;
-
-import java.text.SimpleDateFormat;
-
-/**
- * 日期格式化
- *
- * @author xuezechao
- * @since 2022-03-11
- */
-public class DateUtil {
-
- private DateUtil() {
- }
-
- /**
- * 格式化日期
- *
- * @param times
- * @return 格式化后日期
- */
- public static String getFormatDate(Long times) {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- return formatter.format(times);
- }
-}
diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/common/util/GzipUtils.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/GzipUtils.java
similarity index 98%
rename from sermant-backend/src/main/java/com/huaweicloud/sermant/backend/common/util/GzipUtils.java
rename to sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/GzipUtils.java
index 4c7ddfea0e..5d7a0a459d 100644
--- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/common/util/GzipUtils.java
+++ b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/GzipUtils.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.huaweicloud.sermant.backend.common.util;
+package com.huaweicloud.sermant.backend.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +40,9 @@ public class GzipUtils {
// 缓冲区大小
private static final int BUFFER = 1024;
+ private GzipUtils() {
+ }
+
/**
* 数据压缩
*
diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/RandomUtil.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/RandomUtil.java
deleted file mode 100644
index 8b23b58018..0000000000
--- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/RandomUtil.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2021-2021 Huawei Technologies Co., Ltd. All rights reserved.
- *
- * Licensed 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.huaweicloud.sermant.backend.util;
-
-import org.apache.commons.lang.RandomStringUtils;
-
-import java.util.Random;
-
-public class RandomUtil {
-
- private final Random random = new Random();
-
- public Integer getRandomInt(Integer range) {
- return random.nextInt(range) + 1;
- }
-
- public String getRandomStr(Integer len) {
- return RandomStringUtils.randomAlphanumeric(len);
- }
-
- public Long getRandomLong(Integer min, Integer max) {
- return min + (((long) (random.nextDouble() * (max - min))));
- }
-}
diff --git a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/UuidUtil.java b/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/UuidUtil.java
deleted file mode 100644
index e46f397fdb..0000000000
--- a/sermant-backend/src/main/java/com/huaweicloud/sermant/backend/util/UuidUtil.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
- *
- * Licensed 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.huaweicloud.sermant.backend.util;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * uuid
- *
- * @author xuezechao
- * @since 2022-02-28
- */
-public class UuidUtil {
-
- private UuidUtil() {
-
- }
-
- /**
- * 生成Long 类型唯一ID
- *
- * @return uuid
- */
- public static long getId() {
- long nowTime = Long.parseLong(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));
- AtomicLong instanceId = new AtomicLong(nowTime);
- if (instanceId.get() < 0) {
- return -instanceId.get();
- }
- return instanceId.get();
- }
-}
diff --git a/sermant-backend/src/main/proto/Message.proto b/sermant-backend/src/main/proto/Message.proto
index dfc047788c..22292a51d0 100644
--- a/sermant-backend/src/main/proto/Message.proto
+++ b/sermant-backend/src/main/proto/Message.proto
@@ -1,38 +1,21 @@
syntax = "proto3";
-option java_package = "com.huawei.sermant.backend.pojo";
+option java_package = "com.huaweicloud.sermant.backend.pojo";
message NettyMessage{
-
enum MessageType {
- HEARTBEAT_PING = 0;
- HEARTBEAT_PONG = 1;
- SERVICE_DATA = 2;
+ SERVICE_DATA = 0;
}
-
MessageType messageType = 1;
- HeartBeat heartBeat = 2;
- repeated ServiceData serviceData = 3;
-
-
+ repeated ServiceData serviceData = 2;
}
-message HeartBeat{
-}
message ServiceData{
enum DataType{
- SERVICE_HEARTBEAT = 0;
- LOG = 1;
- PLUGIN_FLOW_CONTROL_DATA = 2;
- PLUGIN_FLOW_RECORD_DATA = 3;
- SERVER_MONITOR = 4;
- ORACLE_JVM_MONITOR = 5;
- IBM_JVM_MONITOR = 6;
- AGENT_REGISTRATION = 7;
- AGENT_MONITOR = 8;
- AGENT_SPAN_EVENT = 9;
- DRUID_MONITOR = 10;
- VISIBILITY = 12;
+ HEARTBEAT_DATA = 0;
+ EVENT_DATA = 1;
+ TRACING_DATA = 2;
+ VISIBILITY_DATA = 3;
}
DataType dataType = 1;
bytes data = 2;
-}
\ No newline at end of file
+}
diff --git a/sermant-backend/src/main/resources/application.properties b/sermant-backend/src/main/resources/application.properties
index d4220d35ba..8f48aec594 100644
--- a/sermant-backend/src/main/resources/application.properties
+++ b/sermant-backend/src/main/resources/application.properties
@@ -1,48 +1,13 @@
server.port=8900
-# kafka address
-spring.kafka.bootstrap-servers=127.0.0.1:9092
-kafka.pool.timeoutMs=1000
-kafka.key.deserializer=org.apache.kafka.common.serialization.StringDeserializer
-kafka.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer
-kafka.group.id=test
-kafka.enable.auto.commit=true
-kafka.auto.commit.interval.ms=1000
-kafka.auto.offset.reset=latest
-kafka.session.timeout.ms=30000
-fetch.min.bytes=1048576
-fetch.max.wait.ms=2000
-
-kafka.key.serializer=org.apache.kafka.common.serialization.StringSerializer
-kafka.value.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
-kafka.acks=1
-kafka.max.request.size=1048576
-kafka.buffer.memory=33554432
-kafka.retries=0
-kafka.request.timeout.ms=10000
-kafka.max.block.ms=60000
-
-# heartbeat topic name
-kafka.heartbeat.topic=topic-heartbeat
-
-# netty config
+# netty
netty.port=6888
netty.wait.time=60
+netty.connection.size=1024
-heartbeat.cache=true
-
-datatype.topic.mapping.0=topic-heartbeat
-datatype.topic.mapping.1=topic-log
-datatype.topic.mapping.2=topic-flowcontrol
-datatype.topic.mapping.3=topic-flowecord
-datatype.topic.mapping.4=topic-server-monitor
-datatype.topic.mapping.5=topic-open-jdk-jvm-monitor
-datatype.topic.mapping.6=topic-ibm-jvm-monitor
-datatype.topic.mapping.7=topic-agent-registration
-datatype.topic.mapping.8=topic-agent-monitor
-datatype.topic.mapping.9=topic-agent-span-event
-datatype.topic.mapping.10=topic-druid-monitor
-datatype.topic.mapping.11=topic-flowcontrol-metric
-datatype.topic.mapping.12=topic-visibility
+# heartbeat
+max.effective.time=60000
+max.cache.time=600000
+# visibility
visibility.effectiveTimes=60000
diff --git a/sermant-backend/src/test/java/com/huaweicloud/sermant/backend/NettyServerTest.java b/sermant-backend/src/test/java/com/huaweicloud/sermant/backend/NettyServerTest.java
deleted file mode 100644
index d469cee650..0000000000
--- a/sermant-backend/src/test/java/com/huaweicloud/sermant/backend/NettyServerTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.huaweicloud.sermant.backend;
-
-import static org.mockito.Mockito.mock;
-
-import com.huaweicloud.sermant.backend.common.conf.DataTypeTopicMapping;
-import com.huawei.sermant.backend.pojo.Message;
-import com.huaweicloud.sermant.backend.server.ServerHandler;
-
-import io.netty.channel.embedded.EmbeddedChannel;
-
-import org.apache.kafka.clients.consumer.KafkaConsumer;
-import org.apache.kafka.clients.producer.KafkaProducer;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.jupiter.api.Test;
-
-public class NettyServerTest {
- private KafkaProducer producer;
- private KafkaConsumer consumer;
- private String isHeartBeatCache = "false";
-
- private DataTypeTopicMapping topicMapping;
-
- @Before
- public void setUp() {
- producer = mock(KafkaProducer.class);
- topicMapping = mock(DataTypeTopicMapping.class);
- }
-
- /**
- * 测试入站消息
- */
- @Test
- public void testWriteInBound() {
- EmbeddedChannel embeddedChannel = new EmbeddedChannel(
- new ServerHandler(producer, consumer, topicMapping, isHeartBeatCache));
- boolean writeInbound = embeddedChannel.writeInbound(Message.ServiceData.newBuilder().build());
- Assert.assertTrue(writeInbound);
- Assert.assertTrue(embeddedChannel.finish());
-
- Object object = embeddedChannel.readInbound();
- Assert.assertNotNull(object);
- }
-
- /**
- * 测试出站消息
- */
- @Test
- public void testWriteOutBound() {
- EmbeddedChannel embeddedChannel = new EmbeddedChannel(
- new ServerHandler(producer, consumer, topicMapping, isHeartBeatCache));
- boolean writeOutBound = embeddedChannel.writeOutbound(Message.ServiceData.newBuilder().build());
- Assert.assertTrue(writeOutBound);
- Assert.assertTrue(embeddedChannel.finish());
-
- Object object = embeddedChannel.readOutbound();
- Assert.assertNotNull(object);
- }
-
-}
diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/test/java/com/huawei/registry/interceptors/DynamicServerListInterceptorTest.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/test/java/com/huawei/registry/interceptors/DynamicServerListInterceptorTest.java
index 8caa34860a..6cd937d14b 100644
--- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/test/java/com/huawei/registry/interceptors/DynamicServerListInterceptorTest.java
+++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/test/java/com/huawei/registry/interceptors/DynamicServerListInterceptorTest.java
@@ -16,6 +16,7 @@
package com.huawei.registry.interceptors;
+import com.huawei.registry.config.RegisterDynamicConfig;
import com.huawei.registry.context.RegisterContext;
import com.huawei.registry.entity.MicroServiceInstance;
import com.huawei.registry.interceptors.cloud3.x.ZookeeperInstanceSupplierInterceptorTest;
@@ -78,11 +79,13 @@ public void setUp() throws Exception {
@Test
public void doBefore() throws NoSuchMethodException {
+ RegisterDynamicConfig.INSTANCE.setClose(false);
RegisterContext.INSTANCE.setAvailable(true);
final ExecuteContext context = interceptor.doBefore(buildContext(serverListLoadBalancer, null));
Assert.assertTrue(context.isSkip());
Mockito.verify(serverList, Mockito.times(1)).getUpdatedListOfServers();
RegisterContext.INSTANCE.setAvailable(false);
+ RegisterDynamicConfig.INSTANCE.setClose(true);
}
@Override