Skip to content

Commit

Permalink
refact all getHostAddress to NetUtils.getHostname() method
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Aug 5, 2021
1 parent 834ba4c commit 5303a03
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private Collection<IOnsListenerStatus> initIncrTransferStateCollect() throws Exc
}
getAllTransferChannel(result);
});
// "/tis/incr-transfer-group/incr-state-collect"

ZkUtils.registerAddress2ZK(// "/tis/incr-transfer-group/incr-state-collect"
this.zkClient, // "/tis/incr-transfer-group/incr-state-collect"
ZkUtils.ZK_ASSEMBLE_LOG_COLLECT_PATH, exportPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,6 @@ private com.qlangtech.tis.grpc.MasterJob pollJob(com.qlangtech.tis.grpc.UpdateCo
// InetSocketAddress address = server.getListenerAddress();
// // NetUtils.createSocketAddrForHost(null,
// // server.getListenerAddress().getPort());
// System.out.println(InetAddress.getLocalHost().getHostAddress());
// System.out.println(address.getHostName());
// System.out.println(address.getAddress().getHostName());
// } catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.qlangtech.tis.manage.common.HttpUtils;
import com.qlangtech.tis.pubhook.common.IPreTriggerProcess;
import com.qlangtech.tis.pubhook.common.RunEnvironment;
import com.qlangtech.tis.realtime.utils.NetUtils;
import com.qlangtech.tis.trigger.biz.dal.dao.AppTrigger;
import com.qlangtech.tis.trigger.biz.dal.dao.IJobMetaDataDAO;
import com.qlangtech.tis.trigger.biz.dal.dao.ITerminatorTriggerBizDalDAOFacade;
Expand All @@ -49,10 +50,8 @@

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.Inet4Address;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.rmi.RemoteException;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -215,11 +214,8 @@ private byte[] parseCurrnetTimeStamp(Date date) throws JSONException {
JSONObject result = new JSONObject();
result.put("view_time", format.format(date));
result.put(TIMESTAMP_PROPERTY, String.valueOf(date.getTime()));
try {
result.put("execute_ip", Inet4Address.getLocalHost().getHostAddress());
} catch (UnknownHostException e) {
log.error(e.getMessage(), e);
}
result.put("execute_ip", NetUtils.getHost());

return result.toString().getBytes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void testReportStatus() {

private UpdateCounterMap createUpdateCounterMap(String uuid, boolean incrProcessPaused) {
UpdateCounterMap updateCt = new UpdateCounterMap();
updateCt.setFrom(NetUtils.getHostname());
updateCt.setFrom(NetUtils.getHost());
updateCt.setGcCounter(12);
updateCt.setUpdateTime(System.currentTimeMillis() / 1000);
TableSingleDataIndexStatus tableUpdateCounter = new TableSingleDataIndexStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.qlangtech.tis.manage.biz.dal.pojo.Application;
import com.qlangtech.tis.manage.biz.dal.pojo.ApplicationCriteria;
import com.qlangtech.tis.manage.common.SendSMSUtils;
import com.qlangtech.tis.realtime.utils.NetUtils;
import com.qlangtech.tis.solrj.extend.AbstractTisCloudSolrClient;
import com.qlangtech.tis.solrj.util.ZkUtils;
import com.tis.zookeeper.ZkPathUtils;
Expand All @@ -40,8 +41,6 @@
import org.springframework.beans.factory.InitializingBean;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -527,11 +526,7 @@ private byte[] parseCurrnetTimeStamp(Date date) throws JSONException {
JSONObject result = new JSONObject();
result.put("view_time", format.format(date));
result.put(TIMESTAMP_PROPERTY, String.valueOf(date.getTime()));
try {
result.put("execute_ip", Inet4Address.getLocalHost().getHostAddress());
} catch (UnknownHostException e) {
log.error(e.getMessage(), e);
}
result.put("execute_ip", NetUtils.getHost());
return result.toString().getBytes();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.qlangtech.tis.pubhook.common.Nullable;
import com.qlangtech.tis.pubhook.common.RunEnvironment;
import com.qlangtech.tis.realtime.utils.NetUtils;
import com.qlangtech.tis.runtime.module.action.BasicModule;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -101,7 +102,7 @@ public static boolean isInPauseState(TriggerCrontab crontab) {


public static String getServerIp() throws UnknownHostException {
return InetAddress.getLocalHost().getHostAddress();
return NetUtils.getHost();
}

public static boolean isInPauseState(boolean hasfulldump, boolean fulljobStop, boolean hasincrdump, boolean incrjobStop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,12 @@ public void setFieldVal(String val) {
if (!Validator.validate(handler, context, validateRule)) {
return false;
}
// Integer parentid = this.getInt("parentid");
// String dptName = this.getString("dptName");
// if (StringUtils.isEmpty(dptName)) {
// this.addErrorMessage(context, "部门名称不能为空");
// return;
// }

Department parentDpt = this.getDepartmentDAO().selectByPrimaryKey(dpt.getParentId());
dpt.setFullName("/" + parentDpt.getName() + "/" + dpt.getName());
dpt.setGmtCreate(new Date());
dpt.setGmtModified(new Date());
dpt.setLeaf(true);
// dpt.setName(dptName);
// dpt.setParentId(parentid);
dptProcess.process(dpt);
this.setBizResult(context, dpt);
return true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected Map<String, String> extractHeaders(ILoggingEvent eventObject) {

@Override
protected String resolveHostname() throws UnknownHostException {
return NetUtils.getHostname();
return NetUtils.getHost();
}

// @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.alibaba.fastjson.JSON;
import com.qlangtech.tis.manage.common.ConfigFileContext.StreamProcess;
import com.qlangtech.tis.pubhook.common.RunEnvironment;
import com.qlangtech.tis.realtime.utils.NetUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.json.JSONObject;
Expand Down Expand Up @@ -91,7 +92,7 @@ public static void send(String content, Contact... contact) {
}
// 发送丁丁消息
URL url = new URL("http://sm.2dfire-inc.com/sm-soa/sm/send_msg?msg="
+ URLEncoder.encode("from:" + Inet4Address.getLocalHost().getHostAddress() + "|" + content, TisUTF8.getName())
+ URLEncoder.encode("from:" + NetUtils.getHost() + "|" + content, TisUTF8.getName())
+ "&tos=" + URLEncoder.encode(email.toString(), TisUTF8.getName()));
logger.info("dingding url:" + url);
ConfigFileContext.processContent(url, new StreamProcess<Object>() {
Expand Down Expand Up @@ -121,7 +122,7 @@ public Object p(int status, InputStream stream, Map<String, List<String>> header
logger.info("sms url:" + url);
StringBuffer buffer = new StringBuffer();
Map<String, String> paramString = new HashMap<>();
paramString.put("fromip", StringUtils.replace(Inet4Address.getLocalHost().getHostAddress(), ".", "-"));
paramString.put("fromip", StringUtils.replace(NetUtils.getHost(), ".", "-"));
paramString.put("collection", "#");
paramString.put("msg", content);
Map<String, String> params = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public class NetUtils {

public static final String LOCAL_HOST_VALUE = "127.0.0.1";

public static void main(String[] args) {
System.out.println(getHostname());

System.out.println(getHost());
}

/**
* net system properties
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package com.qlangtech.tis.plugin;

import com.qlangtech.tis.extension.Describable;
import com.qlangtech.tis.extension.Descriptor;

import java.util.Objects;

/**
* The plugin global unique identity name
Expand All @@ -40,7 +43,9 @@ public interface IdentityName {
*/
default String identityValue() {
Describable plugin = (Describable) this;
return plugin.getDescriptor().getIdentityValue(plugin);
Descriptor des = plugin.getDescriptor();
Objects.requireNonNull(des, " Descriptor of Describable instance of " + plugin.getClass().getName());
return des.getIdentityValue(plugin);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.impl.DefaultContext;
import com.alibaba.fastjson.annotation.JSONField;
import com.qlangtech.tis.realtime.utils.NetUtils;
import com.qlangtech.tis.runtime.module.misc.IMessageHandler;
import com.qlangtech.tis.runtime.module.misc.impl.AdapterMessageHandler;
import org.apache.commons.lang.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public void afterPropertiesSet() throws Exception {
// "/consume";
// .toString();
String uuid = String.valueOf(UUID.randomUUID());
// String ip = Inet4Address.getLocalHost().getHostAddress();
// if (StringUtils.equals("127.0.0.1", ip)) {
// throw new IllegalStateException("ip can not be 127.0.0.1");
// }
Expand All @@ -135,7 +134,6 @@ public String getUniqueId(String collection) {
}

public static void main(String[] args) throws Exception {
System.out.println(new String(Inet4Address.getLocalHost().getHostAddress()));
System.out.println(new String(Inet4Address.getLocalHost().getHostName()));

}
}
Loading

0 comments on commit 5303a03

Please sign in to comment.