Skip to content

Commit 36074a0

Browse files
committed
ApiBoot Logging 支持指定Admin路径上报日志列表
1 parent 7a783cf commit 36074a0

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.plugin.logging.admin.discovery;
19+
20+
import org.minbox.framework.api.boot.common.exception.ApiBootException;
21+
22+
/**
23+
* Look Up ApiBoot Logging Admin Service Urls
24+
* 1. single api-boot-logging-admin service
25+
* 2. pull api-boot-logging-admin services from registry center
26+
*
27+
* @author:恒宇少年 - 于起宇
28+
* <p>
29+
* DateTime:2019-07-19 15:29
30+
* Blog:http://blog.yuqiyu.com
31+
* WebSite:http://www.jianshu.com/u/092df3f77bca
32+
* Gitee:https://gitee.com/hengboy
33+
* GitHub:https://github.com/hengboy
34+
*/
35+
public interface LoggingAdminDiscovery {
36+
/**
37+
* lookup a api-boot-logging-admin service url
38+
*
39+
* @return service url
40+
* @throws ApiBootException ApiBoot Exception
41+
*/
42+
String lookup() throws ApiBootException;
43+
44+
/**
45+
* get basic auth info
46+
* if config spring security user
47+
*
48+
* @return spring security user info
49+
* @throws ApiBootException ApiBoot Exception
50+
*/
51+
String getBasicAuth() throws ApiBootException;
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.plugin.logging.admin.discovery.support;
19+
20+
import org.minbox.framework.api.boot.common.exception.ApiBootException;
21+
import org.springframework.util.Assert;
22+
import org.springframework.util.ObjectUtils;
23+
24+
/**
25+
* ApiBoot Logging Appoint Admin Discovery
26+
* Support multiple admins
27+
*
28+
* @author:恒宇少年 - 于起宇
29+
* <p>
30+
* DateTime:2019-07-19 15:44
31+
* Blog:http://blog.yuqiyu.com
32+
* WebSite:http://www.jianshu.com/u/092df3f77bca
33+
* Gitee:https://gitee.com/hengboy
34+
* GitHub:https://github.com/hengboy
35+
*/
36+
public class LoggingAppointAdminDiscovery extends LoggingAbstractAdminDiscovery {
37+
/**
38+
* basic user split
39+
*/
40+
private static final String BASIC_SPLIT = "@";
41+
/**
42+
* http prefix
43+
*/
44+
private static final String HTTP_PREFIX = "http://";
45+
/**
46+
* ApiBoot Logging Admin Server Address
47+
*/
48+
private String[] adminServerAddress;
49+
/**
50+
* ApiBoot Logging Admin Server Address
51+
* To Current Thread
52+
*/
53+
private final ThreadLocal<String> CURRENT_SERVER_ADDRESS = new ThreadLocal();
54+
55+
public LoggingAppointAdminDiscovery(String[] adminServerAddress) {
56+
this.adminServerAddress = adminServerAddress;
57+
}
58+
59+
/**
60+
* load balance lookup admin server address
61+
*
62+
* @return admin server address
63+
* @throws ApiBootException ApiBoot Exception
64+
*/
65+
@Override
66+
public String lookup() throws ApiBootException {
67+
Assert.notNull(adminServerAddress, "ApiBoot Logging Admin Server Address Is Null.");
68+
String serverAddress = adminServerAddress[0];
69+
CURRENT_SERVER_ADDRESS.set(serverAddress);
70+
// have basic auth
71+
if (serverAddress.indexOf(BASIC_SPLIT) > 0) {
72+
serverAddress = serverAddress.substring(serverAddress.indexOf(BASIC_SPLIT) + 1);
73+
}
74+
// append http prefix
75+
return HTTP_PREFIX + serverAddress;
76+
}
77+
78+
/**
79+
* get basic auth
80+
*
81+
* @return basic auth base64
82+
* @throws ApiBootException ApiBoot Exception
83+
*/
84+
@Override
85+
public String getBasicAuth() throws ApiBootException {
86+
String serverAddress = CURRENT_SERVER_ADDRESS.get();
87+
if (serverAddress.indexOf(BASIC_SPLIT) > 0) {
88+
String basicInfo = serverAddress.substring(0, serverAddress.indexOf(BASIC_SPLIT));
89+
CURRENT_SERVER_ADDRESS.remove();
90+
if (!ObjectUtils.isEmpty(basicInfo)) {
91+
return getBasicBase64(basicInfo);
92+
}
93+
}
94+
return null;
95+
}
96+
}

0 commit comments

Comments
 (0)