From 5c9c35ab226fac37f607fb27f1424c1798bdfb51 Mon Sep 17 00:00:00 2001 From: KomachiSion Date: Fri, 26 Aug 2022 17:20:04 +0800 Subject: [PATCH] Remove some unused classes in misc. --- .../alibaba/nacos/naming/misc/Message.java | 35 -- .../nacos/naming/misc/NamingProxy.java | 356 ------------------ .../alibaba/nacos/naming/misc/NetUtils.java | 39 -- .../nacos/naming/misc/UtilsAndCommons.java | 12 - 4 files changed, 442 deletions(-) delete mode 100644 naming/src/main/java/com/alibaba/nacos/naming/misc/Message.java delete mode 100644 naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java delete mode 100644 naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/Message.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/Message.java deleted file mode 100644 index 0efafd5d7..000000000 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/Message.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * 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.alibaba.nacos.naming.misc; - -/** - * message. - * - * @author nacos - */ -public class Message { - - private String data; - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - } -} diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java deleted file mode 100644 index 83a23538a..000000000 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/NamingProxy.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * 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.alibaba.nacos.naming.misc; - -import com.alibaba.nacos.common.constant.HttpHeaderConsts; -import com.alibaba.nacos.common.http.Callback; -import com.alibaba.nacos.common.model.RestResult; -import com.alibaba.nacos.common.utils.InternetAddressUtil; -import com.alibaba.nacos.common.utils.JacksonUtils; -import com.alibaba.nacos.common.utils.VersionUtils; -import com.alibaba.nacos.sys.env.EnvUtil; -import com.alibaba.nacos.common.utils.StringUtils; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.alibaba.nacos.common.constant.RequestUrlConstants.HTTP_PREFIX; - -/** - * Naming http proxy. - * - * @author nacos - */ -public class NamingProxy { - - private static final String DATA_ON_SYNC_URL = "/distro/datum"; - - private static final String DATA_GET_URL = "/distro/datum"; - - private static final String ALL_DATA_GET_URL = "/distro/datums"; - - private static final String TIMESTAMP_SYNC_URL = "/distro/checksum"; - - /** - * Synchronize check sums. - * - * @param checksumMap checksum map - * @param server server address - */ - public static void syncCheckSums(Map checksumMap, String server) { - syncCheckSums(JacksonUtils.toJsonBytes(checksumMap), server); - } - - /** - * Synchronize check sums. - * - * @param checksums checksum map bytes - * @param server server address - */ - public static void syncCheckSums(byte[] checksums, String server) { - try { - Map headers = new HashMap<>(128); - - headers.put(HttpHeaderConsts.CLIENT_VERSION_HEADER, VersionUtils.version); - headers.put(HttpHeaderConsts.USER_AGENT_HEADER, UtilsAndCommons.SERVER_VERSION); - headers.put(HttpHeaderConsts.CONNECTION, "Keep-Alive"); - - HttpClient.asyncHttpPutLarge( - HTTP_PREFIX + server + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT - + TIMESTAMP_SYNC_URL + "?source=" + NetUtils.localServer(), headers, checksums, - new Callback() { - @Override - public void onReceive(RestResult result) { - if (!result.ok()) { - Loggers.DISTRO.error("failed to req API: {}, code: {}, msg: {}", - HTTP_PREFIX + server + EnvUtil.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + TIMESTAMP_SYNC_URL, - result.getCode(), result.getMessage()); - } - } - - @Override - public void onError(Throwable throwable) { - Loggers.DISTRO.error("failed to req API:" + HTTP_PREFIX + server + EnvUtil.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + TIMESTAMP_SYNC_URL, throwable); - } - - @Override - public void onCancel() { - - } - }); - } catch (Exception e) { - Loggers.DISTRO.warn("NamingProxy", e); - } - } - - /** - * Get Data from other server. - * - * @param keys keys of datum - * @param server target server address - * @return datum byte array - * @throws Exception exception - */ - public static byte[] getData(List keys, String server) throws Exception { - - Map params = new HashMap<>(8); - params.put("keys", StringUtils.join(keys, ",")); - RestResult result = HttpClient.httpGetLarge( - HTTP_PREFIX + server + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + DATA_GET_URL, - new HashMap<>(8), JacksonUtils.toJson(params)); - - if (result.ok()) { - return result.getData().getBytes(); - } - - throw new IOException("failed to req API: " + HTTP_PREFIX + server + EnvUtil.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + DATA_GET_URL + ". code: " + result.getCode() + " msg: " - + result.getMessage()); - } - - /** - * Get all datum from target server. - * - * @param server target server address - * @return all datum byte array - * @throws Exception exception - */ - public static byte[] getAllData(String server) throws Exception { - - Map params = new HashMap<>(8); - RestResult result = HttpClient.httpGet( - HTTP_PREFIX + server + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + ALL_DATA_GET_URL, - new ArrayList<>(), params); - - if (result.ok()) { - return result.getData().getBytes(); - } - - throw new IOException("failed to req API: " + HTTP_PREFIX + server + EnvUtil.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + ALL_DATA_GET_URL + ". code: " + result.getCode() + " msg: " - + result.getMessage()); - } - - /** - * Synchronize datum to target server. - * - * @param data datum - * @param curServer target server address - * @return true if sync successfully, otherwise false - */ - public static boolean syncData(byte[] data, String curServer) { - Map headers = new HashMap<>(128); - - headers.put(HttpHeaderConsts.CLIENT_VERSION_HEADER, VersionUtils.version); - headers.put(HttpHeaderConsts.USER_AGENT_HEADER, UtilsAndCommons.SERVER_VERSION); - headers.put(HttpHeaderConsts.ACCEPT_ENCODING, "gzip,deflate,sdch"); - headers.put(HttpHeaderConsts.CONNECTION, "Keep-Alive"); - headers.put(HttpHeaderConsts.CONTENT_ENCODING, "gzip"); - - try { - RestResult result = HttpClient.httpPutLarge( - HTTP_PREFIX + curServer + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT - + DATA_ON_SYNC_URL, headers, data); - if (result.ok()) { - return true; - } - if (HttpURLConnection.HTTP_NOT_MODIFIED == result.getCode()) { - return true; - } - throw new IOException("failed to req API:" + HTTP_PREFIX + curServer + EnvUtil.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + DATA_ON_SYNC_URL + ". code:" + result.getCode() + " msg: " - + result.getData()); - } catch (Exception e) { - Loggers.SRV_LOG.warn("NamingProxy", e); - } - return false; - } - - /** - * request api. - * - * @param api api path - * @param params parameters of api - * @param curServer target server address - * @return content if request successfully and response has content, otherwise {@link StringUtils#EMPTY} - * @throws Exception exception - */ - public static String reqApi(String api, Map params, String curServer) throws Exception { - try { - List headers = Arrays.asList(HttpHeaderConsts.CLIENT_VERSION_HEADER, VersionUtils.version, - HttpHeaderConsts.USER_AGENT_HEADER, UtilsAndCommons.SERVER_VERSION, "Accept-Encoding", - "gzip,deflate,sdch", "Connection", "Keep-Alive", "Content-Encoding", "gzip"); - - RestResult result; - - if (!InternetAddressUtil.containsPort(curServer)) { - curServer = curServer + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil.getPort(); - } - - result = HttpClient.httpGet(HTTP_PREFIX + curServer + api, headers, params); - - if (result.ok()) { - return result.getData(); - } - - if (HttpURLConnection.HTTP_NOT_MODIFIED == result.getCode()) { - return StringUtils.EMPTY; - } - - throw new IOException( - "failed to req API:" + HTTP_PREFIX + curServer + api + ". code:" + result.getCode() + " msg: " - + result.getMessage()); - } catch (Exception e) { - Loggers.SRV_LOG.warn("NamingProxy", e); - } - return StringUtils.EMPTY; - } - - /** - * request api. - * - * @param api api path - * @param params parameters of api - * @param curServer target server address - * @param isPost whether use post method to request - * @return content if request successfully and response has content, otherwise {@link StringUtils#EMPTY} - * @throws Exception exception - */ - public static String reqApi(String api, Map params, String curServer, boolean isPost) - throws Exception { - try { - List headers = Arrays.asList(HttpHeaderConsts.CLIENT_VERSION_HEADER, VersionUtils.version, - HttpHeaderConsts.USER_AGENT_HEADER, UtilsAndCommons.SERVER_VERSION, "Accept-Encoding", - "gzip,deflate,sdch", "Connection", "Keep-Alive", "Content-Encoding", "gzip"); - - RestResult result; - - if (!InternetAddressUtil.containsPort(curServer)) { - curServer = curServer + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil.getPort(); - } - - if (isPost) { - result = HttpClient.httpPost( - HTTP_PREFIX + curServer + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT - + "/api/" + api, headers, params); - } else { - result = HttpClient.httpGet( - HTTP_PREFIX + curServer + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT - + "/api/" + api, headers, params); - } - - if (result.ok()) { - return result.getData(); - } - - if (HttpURLConnection.HTTP_NOT_MODIFIED == result.getCode()) { - return StringUtils.EMPTY; - } - - throw new IOException("failed to req API:" + HTTP_PREFIX + curServer + EnvUtil.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + "/api/" + api + ". code:" + result.getCode() + " msg: " - + result.getMessage()); - } catch (Exception e) { - Loggers.SRV_LOG.warn("NamingProxy", e); - } - return StringUtils.EMPTY; - } - - /** - * request api with common way. - * - * @param path api path - * @param params parameters - * @param curServer target server address - * @param isPost whether use post method to request - * @return content if request successfully and response has content, otherwise {@link StringUtils#EMPTY} - * @throws Exception exception - */ - public static String reqCommon(String path, Map params, String curServer, boolean isPost) - throws Exception { - try { - List headers = Arrays.asList("Client-Version", UtilsAndCommons.SERVER_VERSION, "User-Agent", - UtilsAndCommons.SERVER_VERSION, "Accept-Encoding", "gzip,deflate,sdch", "Connection", "Keep-Alive", - "Content-Encoding", "gzip"); - - RestResult result; - - if (!InternetAddressUtil.containsPort(curServer)) { - curServer = curServer + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil.getPort(); - } - - if (isPost) { - result = HttpClient.httpPost( - HTTP_PREFIX + curServer + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + path, - headers, params); - } else { - result = HttpClient.httpGet( - HTTP_PREFIX + curServer + EnvUtil.getContextPath() + UtilsAndCommons.NACOS_NAMING_CONTEXT + path, - headers, params); - } - - if (result.ok()) { - return result.getData(); - } - - if (HttpURLConnection.HTTP_NOT_MODIFIED == result.getCode()) { - return StringUtils.EMPTY; - } - - throw new IOException("failed to req API:" + HTTP_PREFIX + curServer + EnvUtil.getContextPath() - + UtilsAndCommons.NACOS_NAMING_CONTEXT + path + ". code:" + result.getCode() + " msg: " + result - .getMessage()); - } catch (Exception e) { - Loggers.SRV_LOG.warn("NamingProxy", e); - } - return StringUtils.EMPTY; - } - - public static class Request { - - private Map params = new HashMap<>(8); - - public static Request newRequest() { - return new Request(); - } - - public Request appendParam(String key, String value) { - params.put(key, value); - return this; - } - - /** - * Transfer to Url string. - * - * @return request url string - */ - public String toUrl() { - StringBuilder sb = new StringBuilder(); - for (Map.Entry entry : params.entrySet()) { - sb.append(entry.getKey()).append('=').append(entry.getValue()).append('&'); - } - return sb.toString(); - } - } -} diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java deleted file mode 100644 index 513ea10b0..000000000 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/NetUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * 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.alibaba.nacos.naming.misc; - -import com.alibaba.nacos.common.utils.InternetAddressUtil; -import com.alibaba.nacos.sys.env.EnvUtil; -import com.alibaba.nacos.sys.utils.InetUtils; - -/** - * Net Utils. - * - * @author nacos - */ -public class NetUtils { - - /** - * Get local server address. - * - * @return local server address - */ - public static String localServer() { - return InetUtils.getSelfIP() + InternetAddressUtil.IP_PORT_SPLITER + EnvUtil.getPort(); - } - -} diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java index 792e2b45b..b8172e850 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/UtilsAndCommons.java @@ -63,10 +63,6 @@ public class UtilsAndCommons { public static final String NACOS_NAMING_HEALTH_CONTEXT = "/health"; - public static final String NACOS_NAMING_RAFT_CONTEXT = "/raft"; - - public static final String NACOS_NAMING_PARTITION_CONTEXT = "/distro"; - public static final String NACOS_NAMING_OPERATOR_CONTEXT = "/operator"; // ********************** Nacos HTTP Context ************************ // @@ -75,12 +71,6 @@ public class UtilsAndCommons { public static final String NACOS_VERSION = VersionUtils.version; - public static final String SUPER_TOKEN = "xy"; - - public static final String DOMAINS_DATA_ID_PRE = "com.alibaba.nacos.naming.domains.meta."; - - public static final String IPADDRESS_DATA_ID_PRE = "com.alibaba.nacos.naming.iplist."; - public static final String SWITCH_DOMAIN_NAME = "00-00---000-NACOS_SWITCH_DOMAIN-000---00-00"; public static final String CIDR_REGEX = "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/[0-9]+"; @@ -91,8 +81,6 @@ public class UtilsAndCommons { public static final String LOCALHOST_SITE = UtilsAndCommons.UNKNOWN_SITE; - public static final int RAFT_PUBLISH_TIMEOUT = 5000; - public static final String SERVER_VERSION = NACOS_SERVER_HEADER + ":" + NACOS_VERSION; public static final String SELF_SERVICE_CLUSTER_ENV = "naming_self_service_cluster_ips";