Skip to content

Commit 0cc1eb4

Browse files
committed
build: fix the L5 support build
1 parent fb84e1b commit 0cc1eb4

File tree

4 files changed

+118
-110
lines changed

4 files changed

+118
-110
lines changed

pom.xml

+2-5
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<profile>
9090
<id>normal</id>
9191
<activation>
92-
<activeByDefault>false</activeByDefault>
92+
<activeByDefault>true</activeByDefault>
9393
</activation>
9494
<build>
9595
<plugins>
@@ -98,7 +98,7 @@
9898
<artifactId>maven-compiler-plugin</artifactId>
9999
<configuration>
100100
<excludes>
101-
<exclude>org/apache/hadoop/fs/cosn/TencentCloudL5EndpointResolver.java</exclude>
101+
<exclude>org/apache/hadoop/fs/cosn/TencentCloudL5EndpointResolverImpl.java</exclude>
102102
</excludes>
103103
</configuration>
104104
</plugin>
@@ -109,9 +109,6 @@
109109
<!-- Tencent cloud supports internal configurations, including L5 domain name resolution. -->
110110
<profile>
111111
<id>internal</id>
112-
<activation>
113-
<activeByDefault>true</activeByDefault>
114-
</activation>
115112
<dependencies>
116113
<dependency>
117114
<groupId>com.tencent.jungle</groupId>

src/main/java/org/apache/hadoop/fs/CosNativeFileSystemStore.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class CosNativeFileSystemStore implements NativeFileSystemStore {
5555
private boolean isMergeBucket;
5656
private CustomerDomainEndpointResolver customerDomainEndpointResolver;
5757

58-
private EndpointResolver l5EndpointResolver;
58+
private TencentCloudL5EndpointResolver l5EndpointResolver;
5959
private boolean useL5Id = false;
6060
private int l5UpdateMaxRetryTimes;
6161

@@ -104,10 +104,10 @@ private void initCOSClient(URI uri, Configuration conf) throws IOException {
104104

105105
Class<?> l5EndpointResolverClass;
106106
try {
107-
l5EndpointResolverClass = Class.forName("org.apache.hadoop.fs.cosn.TencentCloudL5EndpointResolver");
108-
this.l5EndpointResolver = (EndpointResolver) l5EndpointResolverClass.newInstance();
109-
((TencentCloudL5EndpointResolver)this.l5EndpointResolver).setModId(l5modId);
110-
((TencentCloudL5EndpointResolver)this.l5EndpointResolver).setCmdId(l5cmdId);
107+
l5EndpointResolverClass = Class.forName("org.apache.hadoop.fs.cosn.TencentCloudL5EndpointResolverImpl");
108+
this.l5EndpointResolver = (TencentCloudL5EndpointResolver) l5EndpointResolverClass.newInstance();
109+
this.l5EndpointResolver.setModId(l5modId);
110+
this.l5EndpointResolver.setCmdId(l5cmdId);
111111
} catch (ClassNotFoundException e) {
112112
throw new IOException("The current version does not support L5 resolver.", e);
113113
} catch (InstantiationException e) {
@@ -1435,7 +1435,7 @@ private <X> Object callCOSClientWithRetry(X request) throws CosServiceException,
14351435
if (useL5Id) {
14361436
if( l5ErrorCodeRetryIndex>= this.l5UpdateMaxRetryTimes) {
14371437
// L5上报,进行重试
1438-
((TencentCloudL5EndpointResolver)l5EndpointResolver).l5RouteResultUpdate(-1);
1438+
l5EndpointResolver.updateRouteResult(-1);
14391439
l5ErrorCodeRetryIndex = 1;
14401440
} else {
14411441
l5ErrorCodeRetryIndex = l5ErrorCodeRetryIndex + 1;
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,9 @@
11
package org.apache.hadoop.fs.cosn;
22

33
import com.qcloud.cos.endpoint.EndpointResolver;
4-
import com.tencent.jungle.lb2.L5API;
5-
import com.tencent.jungle.lb2.L5APIException;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
84

9-
import java.util.concurrent.ThreadLocalRandom;
10-
11-
/**
12-
* 这个类是专供于腾讯云 L5 解析方式
13-
*/
14-
public class TencentCloudL5EndpointResolver implements EndpointResolver {
15-
private static final Logger LOG = LoggerFactory.getLogger(TencentCloudL5EndpointResolver.class);
16-
17-
private int modId;
18-
private int cmdId;
19-
private String l5IP;
20-
private int l5Port;
21-
private long l5Start;
22-
23-
public TencentCloudL5EndpointResolver() {
24-
this(-1, -1);
25-
}
26-
27-
public TencentCloudL5EndpointResolver(int modId, int cmdId) {
28-
this.modId = modId;
29-
this.cmdId = cmdId;
30-
this.l5IP = null;
31-
this.l5Port = -1;
32-
this.l5Start = 0;
33-
}
34-
35-
public int getModId() {
36-
return modId;
37-
}
38-
39-
public void setModId(int modId) {
40-
this.modId = modId;
41-
}
42-
43-
public int getCmdId() {
44-
return cmdId;
45-
}
46-
47-
public void setCmdId(int cmdId) {
48-
this.cmdId = cmdId;
49-
}
50-
51-
public void l5RouteResultUpdate(int status) {
52-
if (null != l5IP && l5Port > 0) {
53-
L5API.L5QOSPacket packet = new L5API.L5QOSPacket();
54-
packet.ip = this.l5IP;
55-
packet.port = l5Port;
56-
packet.cmdid = this.cmdId;
57-
packet.modid = this.modId;
58-
packet.start = this.l5Start;
59-
60-
for (int i = 0; i < 5; ++i) {
61-
L5API.updateRoute(packet, status);
62-
}
63-
} else {
64-
LOG.error("Update l5 modid: {} cmdid: {} ip: {} port {} failed.",
65-
this.modId, this.cmdId, this.l5IP, this.l5Port);
66-
}
67-
}
68-
69-
@Override
70-
public String resolveGeneralApiEndpoint(String s) {
71-
float timeout = 0.2F;
72-
String cgiIpAddr = null;
73-
L5API.L5QOSPacket packet = new L5API.L5QOSPacket();
74-
packet.modid = this.modId;
75-
packet.cmdid = this.cmdId;
76-
77-
78-
for (int i = 0; i < 5; ++i) {
79-
try {
80-
packet = L5API.getRoute(packet, timeout);
81-
if (!packet.ip.isEmpty() && packet.port > 0) {
82-
this.l5IP = packet.ip;
83-
this.l5Port = packet.port;
84-
this.l5Start = packet.start;
85-
cgiIpAddr = String.format("%s:%d", packet.ip, packet.port);
86-
break;
87-
}
88-
} catch (L5APIException e) {
89-
LOG.error("Get l5 modid: {} cmdid: {} failed.", this.modId, this.cmdId);
90-
try {
91-
Thread.sleep(ThreadLocalRandom.current().nextLong(10L, 1000L));
92-
} catch (InterruptedException var) {
93-
}
94-
}
95-
}
96-
97-
return cgiIpAddr;
98-
}
99-
100-
@Override
101-
public String resolveGetServiceApiEndpoint(String s) {
102-
return "service.cos.myqcloud.com";
103-
}
5+
public interface TencentCloudL5EndpointResolver extends EndpointResolver {
6+
public void setModId(int modId);
7+
public void setCmdId(int cmdId);
8+
public void updateRouteResult(int status);
1049
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package org.apache.hadoop.fs.cosn;
2+
3+
import com.tencent.jungle.lb2.L5API;
4+
import com.tencent.jungle.lb2.L5APIException;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import java.util.concurrent.ThreadLocalRandom;
9+
10+
/**
11+
* 这个类是专供于腾讯云 L5 解析方式
12+
*/
13+
public class TencentCloudL5EndpointResolverImpl implements TencentCloudL5EndpointResolver {
14+
private static final Logger LOG = LoggerFactory.getLogger(TencentCloudL5EndpointResolverImpl.class);
15+
16+
private int modId;
17+
private int cmdId;
18+
private String l5IP;
19+
private int l5Port;
20+
private long l5Start;
21+
22+
public TencentCloudL5EndpointResolverImpl() {
23+
this(-1, -1);
24+
}
25+
26+
public TencentCloudL5EndpointResolverImpl(int modId, int cmdId) {
27+
this.modId = modId;
28+
this.cmdId = cmdId;
29+
this.l5IP = null;
30+
this.l5Port = -1;
31+
this.l5Start = 0;
32+
}
33+
34+
public int getModId() {
35+
return modId;
36+
}
37+
38+
@Override
39+
public void setModId(int modId) {
40+
this.modId = modId;
41+
}
42+
43+
public int getCmdId() {
44+
return cmdId;
45+
}
46+
47+
@Override
48+
public void setCmdId(int cmdId) {
49+
this.cmdId = cmdId;
50+
}
51+
52+
@Override
53+
public void updateRouteResult(int status) {
54+
if (null != l5IP && l5Port > 0) {
55+
L5API.L5QOSPacket packet = new L5API.L5QOSPacket();
56+
packet.ip = this.l5IP;
57+
packet.port = l5Port;
58+
packet.cmdid = this.cmdId;
59+
packet.modid = this.modId;
60+
packet.start = this.l5Start;
61+
62+
for (int i = 0; i < 5; ++i) {
63+
L5API.updateRoute(packet, status);
64+
}
65+
} else {
66+
LOG.error("Update l5 modid: {} cmdid: {} ip: {} port {} failed.",
67+
this.modId, this.cmdId, this.l5IP, this.l5Port);
68+
}
69+
}
70+
71+
@Override
72+
public String resolveGeneralApiEndpoint(String s) {
73+
float timeout = 0.2F;
74+
String cgiIpAddr = null;
75+
L5API.L5QOSPacket packet = new L5API.L5QOSPacket();
76+
packet.modid = this.modId;
77+
packet.cmdid = this.cmdId;
78+
79+
80+
for (int i = 0; i < 5; ++i) {
81+
try {
82+
packet = L5API.getRoute(packet, timeout);
83+
if (!packet.ip.isEmpty() && packet.port > 0) {
84+
this.l5IP = packet.ip;
85+
this.l5Port = packet.port;
86+
this.l5Start = packet.start;
87+
cgiIpAddr = String.format("%s:%d", packet.ip, packet.port);
88+
break;
89+
}
90+
} catch (L5APIException e) {
91+
LOG.error("Get l5 modid: {} cmdid: {} failed.", this.modId, this.cmdId);
92+
try {
93+
Thread.sleep(ThreadLocalRandom.current().nextLong(10L, 1000L));
94+
} catch (InterruptedException var) {
95+
}
96+
}
97+
}
98+
99+
return cgiIpAddr;
100+
}
101+
102+
@Override
103+
public String resolveGetServiceApiEndpoint(String s) {
104+
return "service.cos.myqcloud.com";
105+
}
106+
}

0 commit comments

Comments
 (0)