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

服务发布相关代码 #35

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ wedpr-components/user/src/main/resources/
wedpr-adm/src/main/resources/
wedpr-admin/src/main/resources/
logs/
bin/
3 changes: 2 additions & 1 deletion db/wedpr_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ create table if not exists wedpr_service_auth_table(
`apply_time` DATETIME DEFAULT CURRENT_TIMESTAMP comment "申请时间",
`last_update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment "更新时间",
primary key (`id`),
index service_id_index(`service_id`(128)),
index service_id_index(`service_id`(64)),
index access_key_id_index(`access_key_id`(128))
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=DYNAMIC;

Expand All @@ -393,6 +393,7 @@ create table if not exists wedpr_service_invoke_table(
`service_id` varchar(64) not null comment "调用的服务ID",
`invoke_user` varchar(1024) not null comment "调用者",
`invoke_agency` varchar(1024) not null comment "调用方所属机构",
`invoke_status` varchar(64) comment "调用的服务状态",
`invoke_time` DATETIME DEFAULT CURRENT_TIMESTAMP comment "调用时间",
`last_update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment "更新时间",
primary key (`invoke_id`),
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ project(":wedpr-admin").projectDir=file("wedpr-admin")
include "wedpr-components-report"
project(":wedpr-components-report").projectDir=file("wedpr-components/report")


include ":wedpr-components-service-publish"
project(":wedpr-components-service-publish").projectDir=file("wedpr-components/service-publish")
1 change: 1 addition & 0 deletions wedpr-adm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
compile project(":wedpr-components-token-auth")
compile project(":wedpr-components-initializer")
compile project(":wedpr-components-project")
compile project(":wedpr-components-service-publish")
compile project(":wedpr-components-scheduler")
compile project(":wedpr-components-user")
compile project(":wedpr-components-dataset")
Expand Down
2 changes: 1 addition & 1 deletion wedpr-adm/conf/wedpr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ wedpr.crypto.symmetric.iv=123456

wedpr.mybatis.mapperLocations=classpath*:mapper/*Mapper.xml
# Note: the basePackage can't set to com.webank.wedpr simply for the mybatis will scan the Service
wedpr.mybatis.BasePackage=com.webank.wedpr.components.meta.resource.follower.dao,com.webank.wedpr.components.meta.sys.config.dao,com.webank.wedpr.components.project.dao,com.webank.wedpr.components.meta.setting.template.dao,com.webank.wedpr.components.sync.dao,com.webank.wedpr.components.authorization.dao,com.webank.wedpr.components.dataset.mapper,com.webank.wedpr.components.user.mapper,com.webank.wedpr.components.meta.agency.dao,com.webank.wedpr.components.report.mapper,com.webank.wedpr.components.api.credential.dao,com.webank.wedpr.components.integration.jupyter.dao
wedpr.mybatis.BasePackage=com.webank.wedpr.components.meta.resource.follower.dao,com.webank.wedpr.components.meta.sys.config.dao,com.webank.wedpr.components.project.dao,com.webank.wedpr.components.meta.setting.template.dao,com.webank.wedpr.components.sync.dao,com.webank.wedpr.components.authorization.dao,com.webank.wedpr.components.dataset.mapper,com.webank.wedpr.components.user.mapper,com.webank.wedpr.components.meta.agency.dao,com.webank.wedpr.components.integration.jupyter.dao,com.webank.wedpr.components.publish.mapper
# wedpr.mybatis.typeAliasesPackage=

### the blockchain configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import com.webank.wedpr.components.api.credential.dao.ApiCredentialDO;
import com.webank.wedpr.core.utils.PageRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString
public class CredentialRequest extends PageRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import com.webank.wedpr.components.integration.jupyter.dao.JupyterInfoDO;
import com.webank.wedpr.core.utils.PageRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString
public class JupyterRequest extends PageRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import lombok.EqualsAndHashCode;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString
@EqualsAndHashCode(callSuper = false)
public class ApiCredentialDO extends TimeRange {
private String id = WeDPRUuidGenerator.generateID();
private String accessKeyID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import com.webank.wedpr.components.uuid.generator.WeDPRUuidGenerator;
import com.webank.wedpr.core.utils.TimeRange;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@EqualsAndHashCode(callSuper = true)
@Data
@ToString
public class JupyterInfoDO extends TimeRange {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
/** Created by caryliao on 2024/7/15 20:26 */
public class GenerateCodeMain {
public static void main(String[] args) {
String moduleName = "admin";
String tableName = "wedpr_dataset";
String moduleName = "";
String tableName = "";
String prefixName = "";

// 代码生成器
Expand All @@ -23,10 +23,10 @@ public static void main(String[] args) {
// 数据源配置
com.baomidou.mybatisplus.generator.config.DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl(
"jdbc:mysql://127.0.0.1:3306/wedpr?characterEncoding=utf8&useSSL=false&serverTimezone=UTC");
"jdbc:mysql://xxxxxxxxxx:3306/xxxxxxx?characterEncoding=utf8&useSSL=false&serverTimezone=UTC");
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
dsc.setUsername("");
dsc.setPassword("");
dsc.setUsername("xxx");
dsc.setPassword("xxxxxx");
mpg.setDataSource(dsc);

// 全局配置
Expand Down
12 changes: 12 additions & 0 deletions wedpr-components/service-publish/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Apply the java-library plugin to add support for Java Library
plugins {
id 'java'
id 'com.github.sherter.google-java-format'
}
dependencies{
compile project(":wedpr-components-dataset")
compile project(":wedpr-core-utils")
compile project(":wedpr-core-protocol")
compile project(":wedpr-components-uuid")
compile project(":wedpr-components-mybatis")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.webank.wedpr.components.publish.config;

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;
import com.webank.wedpr.components.sync.ResourceSyncer;
import com.webank.wedpr.components.sync.core.ResourceActionRecorderBuilder;
import com.webank.wedpr.core.config.WeDPRCommonConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author zachma
* @date 2024/8/31
*/
@Configuration
public class PublishSyncConfig {
private static final Logger logger = LoggerFactory.getLogger(PublishSyncConfig.class);

@Autowired
@Qualifier("resourceSyncer")
private ResourceSyncer resourceSyncer;

@Autowired
@Qualifier("publishSyncerCommitHandler")
PublishSyncerCommitHandler publishSyncerCommitHandler;

@Bean(name = "publishSyncer")
public PublishSyncerApi newPublishSyncer() {

PublishSyncer publishSyncer = new PublishSyncer();
String agency = WeDPRCommonConfig.getAgency();
logger.info(" => create publish syncer, agency: {}", agency);

String resourceType = ResourceSyncer.ResourceType.Publish.getType();
ResourceActionRecorderBuilder resourceBuilder =
new ResourceActionRecorderBuilder(agency, resourceType);
publishSyncer.setResourceSyncer(resourceSyncer);
publishSyncer.setResourceBuilder(resourceBuilder);
resourceSyncer.registerCommitHandler(resourceType, publishSyncerCommitHandler);
return publishSyncer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.webank.wedpr.components.publish.controller;

import com.webank.wedpr.components.publish.entity.request.PublishCreateRequest;
import com.webank.wedpr.components.publish.entity.request.PublishSearchRequest;
import com.webank.wedpr.components.publish.service.WedprPublishedServiceService;
import com.webank.wedpr.components.token.auth.TokenUtils;
import com.webank.wedpr.core.utils.Constant;
import com.webank.wedpr.core.utils.WeDPRResponse;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 前端控制器
*
* @author caryliao
* @since 2024-08-31
*/
@RestController
@RequestMapping(
path = Constant.WEDPR_API_PREFIX + "/publish",
produces = {"application/json"})
@Slf4j
public class WedprPublishedServiceController {
private static final Logger logger =
LoggerFactory.getLogger(WedprPublishedServiceController.class);

@Autowired private WedprPublishedServiceService wedprPublishService;

@PostMapping("/create")
public WeDPRResponse createPublish(
@RequestBody PublishCreateRequest publishCreate, HttpServletRequest request) {
try {
return wedprPublishService.createPublishService(
TokenUtils.getLoginUser(request).getUsername(), publishCreate);
} catch (Exception e) {
logger.warn("发布服务失败 error: ", e);
return new WeDPRResponse(Constant.WEDPR_FAILED, "发布服务失败 error: " + e.getMessage());
}
}

@PostMapping("/update")
public WeDPRResponse updatePublish(
@RequestBody PublishCreateRequest publishRequest, HttpServletRequest request) {
try {
return wedprPublishService.updatePublishService(
TokenUtils.getLoginUser(request).getUsername(), publishRequest);
} catch (Exception e) {
logger.warn("更新已发布的服务 error: ", e);
return new WeDPRResponse(Constant.WEDPR_FAILED, "撤回已发布的服务失败: " + e.getMessage());
}
}

@GetMapping("/list")
public WeDPRResponse listPublish(PublishSearchRequest request) {
try {
return wedprPublishService.listPublishService(request);
} catch (Exception e) {
logger.warn("列出所有的已发布的服务 exception, error: ", e);
return new WeDPRResponse(
Constant.WEDPR_FAILED, "listPublish failed for " + e.getMessage());
}
}

@DeleteMapping("/revoke/{serviceId}")
public WeDPRResponse revokePublish(@PathVariable String serviceId, HttpServletRequest request) {
try {
return wedprPublishService.revokePublishService(
TokenUtils.getLoginUser(request).getUsername(), serviceId);
} catch (Exception e) {
logger.warn("撤回已发布的服务 error: ", e);
return new WeDPRResponse(Constant.WEDPR_FAILED, "撤回已发布的服务失败: " + e.getMessage());
}
}

@GetMapping("/search/{serviceId}")
public WeDPRResponse searchPublish(@PathVariable String serviceId) {
try {
return wedprPublishService.searchPublishService(serviceId);
} catch (Exception e) {
logger.warn("searchPublish exception, error: ", e);
return new WeDPRResponse(
Constant.WEDPR_FAILED, "createProject failed for " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.webank.wedpr.components.publish.controller;

import com.webank.wedpr.components.publish.entity.request.NodeInvokeRequest;
import com.webank.wedpr.components.publish.entity.request.PublishInvokeSearchRequest;
import com.webank.wedpr.components.publish.service.WedprServiceInvokeTableService;
import com.webank.wedpr.core.utils.Constant;
import com.webank.wedpr.core.utils.WeDPRResponse;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 前端控制器
*
* @author caryliao
* @since 2024-08-31
*/
@RestController
@RequestMapping(
path = Constant.WEDPR_API_PREFIX + "/publish/invoke",
produces = {"application/json"})
@Slf4j
public class WedprServiceInvokeTableController {
private static final Logger logger =
LoggerFactory.getLogger(WedprServiceInvokeTableController.class);

@Autowired private WedprServiceInvokeTableService wedprPublishInvokeService;

@GetMapping("/search/{serviceId}")
public WeDPRResponse searchPublishRecord(
@PathVariable String serviceId, PublishInvokeSearchRequest publishInvokeRequest) {
try {
return wedprPublishInvokeService.seachPublishInvokeService(
serviceId, publishInvokeRequest);
} catch (Exception e) {
logger.warn("发起方搜索申报记录 exception, error: ", e);
return new WeDPRResponse(
Constant.WEDPR_FAILED, "searchPublishRecord failed for " + e.getMessage());
}
}

@PostMapping("/upload")
public WeDPRResponse invokePublishRecord(NodeInvokeRequest nodeInvokeRequest) {
try {
return wedprPublishInvokeService.invokePublishRecordService(nodeInvokeRequest);
} catch (Exception e) {
logger.warn("任务结果申报失败 exception, error: ", e);
return new WeDPRResponse(Constant.WEDPR_FAILED, "任务结果申报失败 for " + e.getMessage());
}
}
}
Loading
Loading