Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix non-pir service publish auth bug #188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# WeDPR

![](https://wedpr-lab.readthedocs.io/zh_CN/latest/_static/images/wedpr_logo.png)
![](./static/images/wedpr_logo.png)


[![CodeFactor](https://www.codefactor.io/repository/github/webankblockchain/wedpr/badge?s=a4c3fb6ffd39e7618378fe13b6bd06c5846cc103)](https://www.codefactor.io/repository/github/webankblockchain/wedpr)
Expand Down
Binary file added static/images/wedpr_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.webank.wedpr.components.hook.ServiceHook;
import com.webank.wedpr.components.loadbalancer.LoadBalancer;
import com.webank.wedpr.components.publish.helper.PublishServiceHelper;
import com.webank.wedpr.components.publish.hook.PirServicePublishCallback;
import com.webank.wedpr.components.publish.hook.ServicePublishCallback;
import com.webank.wedpr.components.publish.sync.PublishSyncer;
import com.webank.wedpr.components.publish.sync.PublishSyncerCommitHandler;
import com.webank.wedpr.components.publish.sync.api.PublishSyncerApi;
Expand Down Expand Up @@ -47,10 +47,15 @@ public class ServicePublisherLoader {
@PostConstruct
public void init() {
logger.info("Register serviceCallback");
serviceHook.registerServiceCallback(
PublishServiceHelper.PublishType.PIR.getType(),
new PirServicePublishCallback(
loadBalancer, new WeDPRResponseFactory(), serviceAuthMapper));

ServicePublishCallback callback =
new ServicePublishCallback(
loadBalancer, new WeDPRResponseFactory(), serviceAuthMapper);

for (PublishServiceHelper.PublishType publishType :
PublishServiceHelper.PublishType.values()) {
serviceHook.registerServiceCallback(publishType.getType(), callback);
}
logger.info("Register serviceCallback success");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@
import com.webank.wedpr.components.loadbalancer.LoadBalancer;
import com.webank.wedpr.components.publish.config.ServicePublisherConfig;
import com.webank.wedpr.components.publish.entity.request.PublishCreateRequest;
import com.webank.wedpr.components.publish.helper.PublishServiceHelper;
import com.webank.wedpr.sdk.jni.transport.model.ServiceMeta;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;

public class PirServicePublishCallback implements ServiceHook.ServiceCallback {
private static final Logger logger = LoggerFactory.getLogger(PirServicePublishCallback.class);
public class ServicePublishCallback implements ServiceHook.ServiceCallback {
private static final Logger logger = LoggerFactory.getLogger(ServicePublishCallback.class);

private final LoadBalancer loadBalancer;
private final BaseResponseFactory responseFactory;
private final ServiceAuthMapper serviceAuthMapper;

public PirServicePublishCallback(
public ServicePublishCallback(
LoadBalancer loadBalancer,
BaseResponseFactory responseFactory,
ServiceAuthMapper serviceAuthMapper) {
Expand Down Expand Up @@ -71,50 +72,56 @@ public void batchInsertServiceAuthInfo(
@Override
public void onPublish(Object serviceInfo) throws Exception {
PublishCreateRequest publishedServiceInfo = (PublishCreateRequest) serviceInfo;
ServiceMeta.EntryPointMeta selectedEntryPoint =
loadBalancer.selectService(
LoadBalancer.Policy.ROUND_ROBIN,
Common.getServiceName(
WeDPRCommonConfig.getAgency(), ServiceName.PIR.getValue()),
WeDPRCommonConfig.getWedprZone(),
null);
if (selectedEntryPoint == null) {
throw new WeDPRException(
"Publish service "
+ publishedServiceInfo.getServiceId()
+ " failed for not found "
+ publishedServiceInfo.getServiceId()
+ " service!");
}
String url =
selectedEntryPoint.getUrl(ServicePublisherConfig.getPirPublishServiceUriPath());
logger.info("onPublish, serviceInfo: {}, target: {}", publishedServiceInfo.toString(), url);
HttpClientImpl httpClient =
new HttpClientImpl(
url,
ServicePublisherConfig.getMaxTotalConnection(),
ServicePublisherConfig.buildConfig(),
responseFactory);
BaseResponse response = httpClient.executePost(publishedServiceInfo, HttpStatus.OK.value());
if (response == null) {
throw new WeDPRException(
"publish service: "
+ publishedServiceInfo.getServiceId()
+ " for no response received!");
}
if (!response.statusOk()) {
throw new WeDPRException(
"publish service: "
+ publishedServiceInfo.getServiceId()
+ " failed, response: "
+ response.serialize());
if (publishedServiceInfo.getPublishType() == PublishServiceHelper.PublishType.PIR) {
ServiceMeta.EntryPointMeta selectedEntryPoint =
loadBalancer.selectService(
LoadBalancer.Policy.ROUND_ROBIN,
Common.getServiceName(
WeDPRCommonConfig.getAgency(), ServiceName.PIR.getValue()),
WeDPRCommonConfig.getWedprZone(),
null);
if (selectedEntryPoint == null) {
throw new WeDPRException(
"Publish service "
+ publishedServiceInfo.getServiceId()
+ " failed for not found "
+ publishedServiceInfo.getServiceId()
+ " service!");
}
String url =
selectedEntryPoint.getUrl(ServicePublisherConfig.getPirPublishServiceUriPath());
logger.info(
"onPublish, serviceInfo: {}, target: {}", publishedServiceInfo.toString(), url);
HttpClientImpl httpClient =
new HttpClientImpl(
url,
ServicePublisherConfig.getMaxTotalConnection(),
ServicePublisherConfig.buildConfig(),
responseFactory);
BaseResponse response =
httpClient.executePost(publishedServiceInfo, HttpStatus.OK.value());
if (response == null) {
throw new WeDPRException(
"publish service: "
+ publishedServiceInfo.getServiceId()
+ " for no response received!");
}
if (!response.statusOk()) {
throw new WeDPRException(
"publish service: "
+ publishedServiceInfo.getServiceId()
+ " failed, response: "
+ response.serialize());
}
logger.info(
"pir onPublish success, service: {}, target: {}",
publishedServiceInfo.getServiceId(),
url);
}
// register auth information
batchInsertServiceAuthInfo(publishedServiceInfo.getServiceId(), publishedServiceInfo);
logger.info(
"onPublish success, service: {}, target: {}",
publishedServiceInfo.getServiceId(),
url);
"onPublish success, service: {}, target: {}", publishedServiceInfo.getServiceId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.webank.wedpr.components.publish.entity.request.PublishSearchRequest;
import com.webank.wedpr.components.publish.entity.response.WedprPublishCreateResponse;
import com.webank.wedpr.components.publish.entity.response.WedprPublishSearchResponse;
import com.webank.wedpr.components.publish.helper.PublishServiceHelper;
import com.webank.wedpr.components.publish.service.WedprPublishedServiceService;
import com.webank.wedpr.components.publish.sync.api.PublishSyncerApi;
import java.util.Arrays;
Expand Down Expand Up @@ -71,9 +72,9 @@ public WeDPRResponse createPublishService(String username, PublishCreateRequest
publishCreate.checkServiceConfig(datasetMapper, username, WeDPRCommonConfig.getAgency());
publishCreate.setStatus(ServiceStatus.Publishing.getStatus());
this.publishedServiceMapper.insertServiceInfo(publishCreate);
boolean hasHook = this.serviceHook.onPublish(publishCreate.getServiceType(), publishCreate);
// without hook, set the status to success directly
if (!hasHook) {
this.serviceHook.onPublish(publishCreate.getServiceType(), publishCreate);
// non-pir service publish, set the status to success directly
if (!publishCreate.getPublishType().equals(PublishServiceHelper.PublishType.PIR)) {
PublishedServiceInfo updatedServiceInfo =
new PublishedServiceInfo(publishCreate.getServiceId());
updatedServiceInfo.setServiceStatus(ServiceStatus.PublishSuccess);
Expand Down
Loading