10
10
import com .google .common .collect .ImmutableMap ;
11
11
import io .fabric8 .kubernetes .api .model .Service ;
12
12
import io .fabric8 .kubernetes .api .model .ServicePort ;
13
- import net .minidev .json .JSONObject ;
13
+ import org .apache .commons .lang3 .ArrayUtils ;
14
+ import org .apache .commons .lang3 .StringUtils ;
14
15
import org .hango .cloud .core .k8s .K8sResourceEnum ;
15
16
import org .hango .cloud .core .k8s .KubernetesClient ;
16
17
import org .hango .cloud .meta .Endpoint ;
17
- import org .hango .cloud .meta .dto .PortalServiceDTO ;
18
18
import org .hango .cloud .util .Const ;
19
19
import org .hango .cloud .util .exception .ApiPlaneException ;
20
- import org .apache .commons .lang3 .ArrayUtils ;
21
- import org .apache .commons .lang3 .StringUtils ;
22
20
import org .hango .cloud .util .exception .ExceptionConst ;
23
21
import org .slf4j .Logger ;
24
22
import org .slf4j .LoggerFactory ;
31
29
import org .springframework .web .client .RestTemplate ;
32
30
33
31
import javax .annotation .PostConstruct ;
34
- import java .util .*;
32
+ import java .util .ArrayList ;
33
+ import java .util .HashMap ;
34
+ import java .util .List ;
35
+ import java .util .Map ;
35
36
import java .util .concurrent .ExecutionException ;
36
37
import java .util .concurrent .TimeUnit ;
37
38
import java .util .stream .Collectors ;
@@ -51,7 +52,7 @@ public class PilotHttpClient {
51
52
@ Value (value = "${istioName:istiod}" )
52
53
private String ISTIO_NAME ;
53
54
54
- @ Value (value = "${meshRegistryName:galley }" )
55
+ @ Value (value = "${meshRegistryName:slime }" )
55
56
private String MESH_REGISTRY_NAME ;
56
57
57
58
private static final String GET_ENDPOINTZ_PATH = "/debug/endpointz?brief=true&servicePort=true" ;
@@ -87,6 +88,9 @@ public class PilotHttpClient {
87
88
88
89
public static final Integer ERROR_PORT = -1 ;
89
90
91
+ private static final String ISTIOD_DEBUG_PORT_NAME = "http-legacy-discovery" ;
92
+ private static final String MESH_REGISTRY_DEBUG_PORT_NAME = "aux-port" ;
93
+
90
94
@ PostConstruct
91
95
void cacheInit () {
92
96
endpointsCache = CacheBuilder .newBuilder ()
@@ -104,12 +108,12 @@ public Object load(String key) throws Exception {
104
108
105
109
private String getIstioUrl () {
106
110
if (!StringUtils .isEmpty (istioHttpUrl )) return istioHttpUrl ;
107
- return getSvcUrl (ISTIO_NAME );
111
+ return getSvcUrl (ISTIO_NAME , ISTIOD_DEBUG_PORT_NAME );
108
112
}
109
113
110
114
private String getMeshRegistryUrl () {
111
115
if (!StringUtils .isEmpty (meshRegistryHttpUrl )) return meshRegistryHttpUrl ;
112
- return getSvcUrl (MESH_REGISTRY_NAME );
116
+ return getSvcUrl (MESH_REGISTRY_NAME , MESH_REGISTRY_DEBUG_PORT_NAME );
113
117
}
114
118
115
119
public List <Endpoint > getDubboEndpoints (String igv ){
@@ -266,15 +270,15 @@ public <T> ResponseEntity<T> getForEntity(String str, Class<T> clz) {
266
270
return entity ;
267
271
}
268
272
269
- public String getSvcUrl (String svcName ) {
273
+ public String getSvcUrl (String svcName , String portName ) {
270
274
List <Service > pilotServices = client .getObjectList (K8sResourceEnum .Service .name (), NAMESPACE , ImmutableMap .of ("app" , svcName ));
271
275
if (CollectionUtils .isEmpty (pilotServices )) throw new ApiPlaneException (ExceptionConst .PILOT_SERVICE_NON_EXIST );
272
276
Service service = pilotServices .get (0 );
273
277
String ip = service .getSpec ().getClusterIP ();
274
278
List <ServicePort > ports = service .getSpec ().getPorts ();
275
279
//get port by name equal http-legacy-discovery
276
280
for (ServicePort port : ports ) {
277
- if ("http-legacy-discovery" .equalsIgnoreCase (port .getName ())) {
281
+ if (StringUtils .equalsIgnoreCase (portName , port .getName ())){
278
282
return String .format ("http://%s:%s" , ip , port .getPort ());
279
283
}
280
284
}
0 commit comments