Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
D
data-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
licc
data-server
Commits
590b1a41
Commit
590b1a41
authored
Mar 11, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
0e6b8355
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
120 additions
and
1 deletion
+120
-1
IpUtil.java
...ommon/src/main/java/cn/wisenergy/common/utils/IpUtil.java
+54
-0
XxlJobConfig.java
...n/src/main/java/cn/wisenergy/web/config/XxlJobConfig.java
+65
-0
application.yml
wisenergy-web-admin/src/main/resources/application.yml
+1
-1
No files found.
wisenergy-common/src/main/java/cn/wisenergy/common/utils/IpUtil.java
0 → 100644
View file @
590b1a41
package
cn
.
wisenergy
.
common
.
utils
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.UnknownHostException
;
import
java.util.Enumeration
;
public
class
IpUtil
{
/**
* 正确的IP拿法,即优先拿site-local地址
*
* @return
* @throws UnknownHostException
*/
public
static
InetAddress
getLocalHostLANAddress
()
throws
UnknownHostException
{
try
{
InetAddress
candidateAddress
=
null
;
// 遍历所有的网络接口
for
(
Enumeration
<
NetworkInterface
>
ifaces
=
NetworkInterface
.
getNetworkInterfaces
();
ifaces
.
hasMoreElements
();
)
{
NetworkInterface
iface
=
ifaces
.
nextElement
();
// 在所有的接口下再遍历IP
for
(
Enumeration
<
InetAddress
>
inetAddrs
=
iface
.
getInetAddresses
();
inetAddrs
.
hasMoreElements
();
)
{
InetAddress
inetAddr
=
inetAddrs
.
nextElement
();
if
(!
inetAddr
.
isLoopbackAddress
())
{
// 排除loopback类型地址
if
(
inetAddr
.
isSiteLocalAddress
())
{
// 如果是site-local地址,就是它了
return
inetAddr
;
}
else
if
(
candidateAddress
==
null
)
{
// site-local类型的地址未被发现,先记录候选地址
candidateAddress
=
inetAddr
;
}
}
}
}
if
(
candidateAddress
!=
null
)
{
return
candidateAddress
;
}
// 如果没有发现 non-loopback地址.只能用最次选的方案
InetAddress
jdkSuppliedAddress
=
InetAddress
.
getLocalHost
();
if
(
jdkSuppliedAddress
==
null
)
{
throw
new
UnknownHostException
(
"The JDK InetAddress.getLocalHost() method unexpectedly returned null."
);
}
return
jdkSuppliedAddress
;
}
catch
(
Exception
e
)
{
UnknownHostException
unknownHostException
=
new
UnknownHostException
(
"Failed to determine LAN address: "
+
e
);
unknownHostException
.
initCause
(
e
);
throw
unknownHostException
;
}
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/config/XxlJobConfig.java
0 → 100644
View file @
590b1a41
package
cn
.
wisenergy
.
web
.
config
;
import
cn.wisenergy.common.utils.IpUtil
;
import
com.xxl.job.core.executor.impl.XxlJobSpringExecutor
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.net.UnknownHostException
;
@Configuration
public
class
XxlJobConfig
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
XxlJobConfig
.
class
);
@Value
(
"${xxl.job.admin.addresses}"
)
private
String
adminAddresses
;
@Value
(
"${xxl.job.accessToken}"
)
private
String
accessToken
;
@Value
(
"${xxl.job.executor.appname}"
)
private
String
appname
;
@Value
(
"${xxl.job.executor.address}"
)
private
String
address
;
@Value
(
"${xxl.job.executor.ip}"
)
private
String
ip
;
@Value
(
"${xxl.job.executor.port}"
)
private
int
port
;
@Value
(
"${xxl.job.executor.logpath}"
)
private
String
logPath
;
@Value
(
"${xxl.job.executor.logretentiondays}"
)
private
int
logRetentionDays
;
@Bean
public
XxlJobSpringExecutor
xxlJobExecutor
()
{
LOGGER
.
info
(
">>>>>>>>>>> xxl-job config init."
);
XxlJobSpringExecutor
xxlJobSpringExecutor
=
new
XxlJobSpringExecutor
();
xxlJobSpringExecutor
.
setAdminAddresses
(
adminAddresses
);
xxlJobSpringExecutor
.
setAppname
(
appname
);
xxlJobSpringExecutor
.
setAddress
(
address
);
String
ip
=
null
;
try
{
ip
=
IpUtil
.
getLocalHostLANAddress
().
getHostAddress
();
}
catch
(
UnknownHostException
e
)
{
LOGGER
.
error
(
"UnknownHostException "
,
e
);
}
LOGGER
.
info
(
"XxlJobSpringExecutor ip:"
+
ip
);
xxlJobSpringExecutor
.
setIp
(
ip
);
xxlJobSpringExecutor
.
setIp
(
ip
);
xxlJobSpringExecutor
.
setPort
(
port
);
xxlJobSpringExecutor
.
setAccessToken
(
accessToken
);
xxlJobSpringExecutor
.
setLogPath
(
logPath
);
xxlJobSpringExecutor
.
setLogRetentionDays
(
logRetentionDays
);
return
xxlJobSpringExecutor
;
}
}
wisenergy-web-admin/src/main/resources/application.yml
View file @
590b1a41
...
...
@@ -60,7 +60,7 @@ xxl:
executor
:
address
:
appname
:
shop-mall
ip
:
172.24.252.165
ip
:
logpath
:
/var/logs/xxl-job/jobhandler
logretentiondays
:
30
port
:
9999
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment