|
25 | 25 | import com.webank.wedpr.components.loadbalancer.LoadBalancer;
|
26 | 26 | import com.webank.wedpr.components.publish.config.ServicePublisherConfig;
|
27 | 27 | import com.webank.wedpr.components.publish.entity.request.PublishCreateRequest;
|
| 28 | +import com.webank.wedpr.components.publish.helper.PublishServiceHelper; |
28 | 29 | import com.webank.wedpr.sdk.jni.transport.model.ServiceMeta;
|
29 | 30 | import java.util.ArrayList;
|
30 | 31 | import java.util.List;
|
31 | 32 | import org.slf4j.Logger;
|
32 | 33 | import org.slf4j.LoggerFactory;
|
33 | 34 | import org.springframework.http.HttpStatus;
|
34 | 35 |
|
35 |
| -public class PirServicePublishCallback implements ServiceHook.ServiceCallback { |
36 |
| - private static final Logger logger = LoggerFactory.getLogger(PirServicePublishCallback.class); |
| 36 | +public class ServicePublishCallback implements ServiceHook.ServiceCallback { |
| 37 | + private static final Logger logger = LoggerFactory.getLogger(ServicePublishCallback.class); |
37 | 38 |
|
38 | 39 | private final LoadBalancer loadBalancer;
|
39 | 40 | private final BaseResponseFactory responseFactory;
|
40 | 41 | private final ServiceAuthMapper serviceAuthMapper;
|
41 | 42 |
|
42 |
| - public PirServicePublishCallback( |
| 43 | + public ServicePublishCallback( |
43 | 44 | LoadBalancer loadBalancer,
|
44 | 45 | BaseResponseFactory responseFactory,
|
45 | 46 | ServiceAuthMapper serviceAuthMapper) {
|
@@ -71,50 +72,56 @@ public void batchInsertServiceAuthInfo(
|
71 | 72 | @Override
|
72 | 73 | public void onPublish(Object serviceInfo) throws Exception {
|
73 | 74 | PublishCreateRequest publishedServiceInfo = (PublishCreateRequest) serviceInfo;
|
74 |
| - ServiceMeta.EntryPointMeta selectedEntryPoint = |
75 |
| - loadBalancer.selectService( |
76 |
| - LoadBalancer.Policy.ROUND_ROBIN, |
77 |
| - Common.getServiceName( |
78 |
| - WeDPRCommonConfig.getAgency(), ServiceName.PIR.getValue()), |
79 |
| - WeDPRCommonConfig.getWedprZone(), |
80 |
| - null); |
81 |
| - if (selectedEntryPoint == null) { |
82 |
| - throw new WeDPRException( |
83 |
| - "Publish service " |
84 |
| - + publishedServiceInfo.getServiceId() |
85 |
| - + " failed for not found " |
86 |
| - + publishedServiceInfo.getServiceId() |
87 |
| - + " service!"); |
88 |
| - } |
89 |
| - String url = |
90 |
| - selectedEntryPoint.getUrl(ServicePublisherConfig.getPirPublishServiceUriPath()); |
91 |
| - logger.info("onPublish, serviceInfo: {}, target: {}", publishedServiceInfo.toString(), url); |
92 |
| - HttpClientImpl httpClient = |
93 |
| - new HttpClientImpl( |
94 |
| - url, |
95 |
| - ServicePublisherConfig.getMaxTotalConnection(), |
96 |
| - ServicePublisherConfig.buildConfig(), |
97 |
| - responseFactory); |
98 |
| - BaseResponse response = httpClient.executePost(publishedServiceInfo, HttpStatus.OK.value()); |
99 |
| - if (response == null) { |
100 |
| - throw new WeDPRException( |
101 |
| - "publish service: " |
102 |
| - + publishedServiceInfo.getServiceId() |
103 |
| - + " for no response received!"); |
104 |
| - } |
105 |
| - if (!response.statusOk()) { |
106 |
| - throw new WeDPRException( |
107 |
| - "publish service: " |
108 |
| - + publishedServiceInfo.getServiceId() |
109 |
| - + " failed, response: " |
110 |
| - + response.serialize()); |
| 75 | + if (publishedServiceInfo.getPublishType() == PublishServiceHelper.PublishType.PIR) { |
| 76 | + ServiceMeta.EntryPointMeta selectedEntryPoint = |
| 77 | + loadBalancer.selectService( |
| 78 | + LoadBalancer.Policy.ROUND_ROBIN, |
| 79 | + Common.getServiceName( |
| 80 | + WeDPRCommonConfig.getAgency(), ServiceName.PIR.getValue()), |
| 81 | + WeDPRCommonConfig.getWedprZone(), |
| 82 | + null); |
| 83 | + if (selectedEntryPoint == null) { |
| 84 | + throw new WeDPRException( |
| 85 | + "Publish service " |
| 86 | + + publishedServiceInfo.getServiceId() |
| 87 | + + " failed for not found " |
| 88 | + + publishedServiceInfo.getServiceId() |
| 89 | + + " service!"); |
| 90 | + } |
| 91 | + String url = |
| 92 | + selectedEntryPoint.getUrl(ServicePublisherConfig.getPirPublishServiceUriPath()); |
| 93 | + logger.info( |
| 94 | + "onPublish, serviceInfo: {}, target: {}", publishedServiceInfo.toString(), url); |
| 95 | + HttpClientImpl httpClient = |
| 96 | + new HttpClientImpl( |
| 97 | + url, |
| 98 | + ServicePublisherConfig.getMaxTotalConnection(), |
| 99 | + ServicePublisherConfig.buildConfig(), |
| 100 | + responseFactory); |
| 101 | + BaseResponse response = |
| 102 | + httpClient.executePost(publishedServiceInfo, HttpStatus.OK.value()); |
| 103 | + if (response == null) { |
| 104 | + throw new WeDPRException( |
| 105 | + "publish service: " |
| 106 | + + publishedServiceInfo.getServiceId() |
| 107 | + + " for no response received!"); |
| 108 | + } |
| 109 | + if (!response.statusOk()) { |
| 110 | + throw new WeDPRException( |
| 111 | + "publish service: " |
| 112 | + + publishedServiceInfo.getServiceId() |
| 113 | + + " failed, response: " |
| 114 | + + response.serialize()); |
| 115 | + } |
| 116 | + logger.info( |
| 117 | + "pir onPublish success, service: {}, target: {}", |
| 118 | + publishedServiceInfo.getServiceId(), |
| 119 | + url); |
111 | 120 | }
|
112 | 121 | // register auth information
|
113 | 122 | batchInsertServiceAuthInfo(publishedServiceInfo.getServiceId(), publishedServiceInfo);
|
114 | 123 | logger.info(
|
115 |
| - "onPublish success, service: {}, target: {}", |
116 |
| - publishedServiceInfo.getServiceId(), |
117 |
| - url); |
| 124 | + "onPublish success, service: {}, target: {}", publishedServiceInfo.getServiceId()); |
118 | 125 | }
|
119 | 126 |
|
120 | 127 | @Override
|
|
0 commit comments