Skip to content

Commit aaab545

Browse files
authored
fix service publish (#159)
* fix service publish * fix dataset upload
1 parent e30925d commit aaab545

File tree

6 files changed

+35
-25
lines changed

6 files changed

+35
-25
lines changed

wedpr-components/dataset/src/main/java/com/webank/wedpr/components/dataset/common/DatasetStatus.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.webank.wedpr.components.dataset.common;
22

3+
import com.webank.wedpr.components.db.mapper.dataset.dao.Dataset;
34
import lombok.AllArgsConstructor;
45
import lombok.Getter;
56

67
@AllArgsConstructor
78
@Getter
89
public enum DatasetStatus {
9-
Success(0, "Success"),
10+
Success(0, "Success"), // Note: 0 is the valid status
1011
Failure(-1, "Failure"), // dataset is in failure and can be processed by retrying
1112
Fatal(-2, "Fatal"), // dataset is in failure and can not be processed by retrying
1213
Created(1, "Created"), // dataset is created and waiting for data source processing
@@ -18,7 +19,8 @@ public enum DatasetStatus {
1819
UploadingChunkData(5, "UploadingChunkData"), // chunk data is being uploaded
1920
LoadingDBData(6, "LoadingDBData"), // upload database data
2021
LoadingExcelData(7, "LoadingExcelData"), // loading excel data
21-
MergingChunkData(8, "MergingChunkData"); // merge chunk data
22+
MergingChunkData(8, "MergingChunkData"), // merge chunk data
23+
InvalidStatus(Dataset.INVALID_DATASET_STATUS, "InvalidStatus");
2224

2325
private final Integer code;
2426
private final String message;

wedpr-components/db-mapper/dataset/src/main/java/com/webank/wedpr/components/db/mapper/dataset/dao/Dataset.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@Data
2323
public class Dataset {
2424
private static final Logger logger = LoggerFactory.getLogger(Dataset.class);
25+
public static final Integer INVALID_DATASET_STATUS = -100000;
2526

2627
@Data
2728
@NoArgsConstructor
@@ -75,7 +76,7 @@ public static class StoragePathMeta {
7576
private String approvalChain;
7677

7778
// status, 0:valid
78-
private int status;
79+
private Integer status = INVALID_DATASET_STATUS;
7980

8081
private String statusDesc;
8182

@@ -105,6 +106,13 @@ public void resetMeta() {
105106
permissions = null;
106107
}
107108

109+
public void setStatus(Integer status) {
110+
if (status == null) {
111+
return;
112+
}
113+
this.status = status;
114+
}
115+
108116
@SneakyThrows(Exception.class)
109117
public void setDatasetStoragePath(String datasetStoragePath) {
110118
this.datasetStoragePath = datasetStoragePath;

wedpr-components/db-mapper/dataset/src/main/resources/mapper/DatasetMapper.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,22 @@
301301
<if test="dataset.datasetStoragePath != null and dataset.datasetStoragePath !=''">
302302
dataset_storage_path = #{dataset.datasetStoragePath},
303303
</if>
304+
<if test="dataset.status != null and dataset.status != -100000">
305+
status = #{dataset.status},
306+
</if>
307+
<if test="dataset.statusDesc != null and dataset.statusDesc !=''">
308+
status_desc = #{dataset.statusDesc},
309+
</if>
310+
<if test="dataset.datasetVersionHash != null and dataset.datasetVersionHash !=''">
311+
dataset_version_hash = #{dataset.datasetVersionHash},
312+
</if>
304313
</set>
305314
WHERE dataset_id = #{dataset.datasetId}
306315
<if test="dataset.ownerAgencyName != null and dataset.ownerAgencyName !=''">
307-
owner_agency_name = #{dataset.ownerAgencyName},
316+
and owner_agency_name = #{dataset.ownerAgencyName}
308317
</if>
309318
<if test="dataset.ownerUserName != null and dataset.ownerUserName !=''">
310-
owner_user_name = #{dataset.ownerUserName},
319+
and owner_user_name = #{dataset.ownerUserName}
311320
</if>
312321
</update>
313322
</mapper>

wedpr-components/service-publish/src/main/java/com/webank/wedpr/components/publish/config/ServicePublisherLoader.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.webank.wedpr.common.config.WeDPRCommonConfig;
44
import com.webank.wedpr.common.utils.WeDPRResponseFactory;
5+
import com.webank.wedpr.components.db.mapper.service.publish.dao.PublishedServiceMapper;
56
import com.webank.wedpr.components.db.mapper.service.publish.dao.ServiceAuthMapper;
67
import com.webank.wedpr.components.hook.ServiceHook;
78
import com.webank.wedpr.components.loadbalancer.LoadBalancer;
@@ -32,10 +33,6 @@ public class ServicePublisherLoader {
3233
@Qualifier("resourceSyncer")
3334
private ResourceSyncer resourceSyncer;
3435

35-
@Autowired
36-
@Qualifier("publishSyncerCommitHandler")
37-
PublishSyncerCommitHandler publishSyncerCommitHandler;
38-
3936
@Autowired
4037
@Qualifier("loadBalancer")
4138
private LoadBalancer loadBalancer;
@@ -45,6 +42,7 @@ public class ServicePublisherLoader {
4542
private ServiceHook serviceHook;
4643

4744
@Autowired private ServiceAuthMapper serviceAuthMapper;
45+
@Autowired private PublishedServiceMapper publishedServiceMapper;
4846

4947
@PostConstruct
5048
public void init() {
@@ -68,6 +66,9 @@ public PublishSyncerApi newPublishSyncer() {
6866
new ResourceActionRecorderBuilder(agency, resourceType);
6967
publishSyncer.setResourceSyncer(resourceSyncer);
7068
publishSyncer.setResourceBuilder(resourceBuilder);
69+
70+
PublishSyncerCommitHandler publishSyncerCommitHandler =
71+
new PublishSyncerCommitHandler(publishedServiceMapper);
7172
resourceSyncer.registerCommitHandler(resourceType, publishSyncerCommitHandler);
7273
return publishSyncer;
7374
}

wedpr-components/service-publish/src/main/java/com/webank/wedpr/components/publish/sync/PublishSyncerCommitHandler.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,21 @@
1313
import java.util.Map;
1414
import org.slf4j.Logger;
1515
import org.slf4j.LoggerFactory;
16-
import org.springframework.beans.factory.annotation.Autowired;
17-
import org.springframework.stereotype.Component;
1816

1917
/**
2018
* @author zachma
2119
* @date 2024/8/28
2220
*/
23-
@Component("publishSyncerCommitHandler")
2421
public class PublishSyncerCommitHandler implements ResourceSyncer.CommitHandler {
2522
private static final Logger logger = LoggerFactory.getLogger(PublishSyncerCommitHandler.class);
2623

27-
@Autowired private PublishedServiceMapper publishedServiceMapper;
24+
private PublishedServiceMapper publishedServiceMapper;
2825

2926
private final PublishSyncerImpl syncer;
3027
private final Map<String, PublishActionHandler> actionHandlerMap = new HashMap<>();
3128

32-
public PublishSyncerCommitHandler() {
29+
public PublishSyncerCommitHandler(PublishedServiceMapper publishedServiceMapper) {
30+
this.publishedServiceMapper = publishedServiceMapper;
3331
this.syncer = new PublishSyncerImpl(publishedServiceMapper);
3432
actionHandlerMap.put(PublishSyncAction.SYNC.getAction(), new SyncPublishActionHandler());
3533
actionHandlerMap.put(
@@ -46,15 +44,7 @@ public void call(ResourceSyncer.CommitArgs args) throws WeDPRException {
4644
String agency = resourceActionRecord.getAgency();
4745
String action = resourceActionRecord.getResourceAction();
4846
String content = resourceActionRecord.getResourceContent();
49-
String myAgency = WeDPRCommonConfig.getAgency();
50-
51-
logger.info(
52-
"ignore self agency sync message, id: {}, action: {}, content: {}",
53-
resourceActionRecord.getResourceID(),
54-
action,
55-
resourceActionRecord);
56-
57-
if (agency.equals(myAgency)) {
47+
if (agency.equalsIgnoreCase(WeDPRCommonConfig.getAgency())) {
5848
logger.info(
5949
"ignore self agency sync message, id: {}, action: {}, content: {}",
6050
resourceActionRecord.getResourceID(),
@@ -76,7 +66,7 @@ public void call(ResourceSyncer.CommitArgs args) throws WeDPRException {
7666
publishActionHandler.handle(content, syncer);
7767
} catch (Exception e) {
7868
logger.error(
79-
"handle dataset sync message exception, id: {}, action: {}, content: {}, e: {}",
69+
"handle service publish sync message exception, id: {}, action: {}, content: {}, e: ",
8070
resourceActionRecord.getResourceID(),
8171
action,
8272
resourceActionRecord,

wedpr-components/service-publish/src/main/java/com/webank/wedpr/components/publish/sync/handler/SyncPublishActionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void handle(String content, PublishSyncerImpl syncer) throws WeDPRExcepti
1919
PublishedServiceInfo publishedServiceInfo = PublishedServiceInfo.deserialize(content);
2020
syncer.syncPublishService(PublishSyncAction.SYNC, publishedServiceInfo);
2121
} catch (Exception e) {
22-
logger.error("sync publish service failed: " + content);
22+
logger.error("sync publish service failed, content: {}, error: ", content, e);
2323
throw new WeDPRException(e);
2424
}
2525
}

0 commit comments

Comments
 (0)