diff --git a/db/wedpr_ddl.sql b/db/wedpr_ddl.sql index 47fc4381..0598b92a 100644 --- a/db/wedpr_ddl.sql +++ b/db/wedpr_ddl.sql @@ -103,13 +103,15 @@ create table if not exists `wedpr_project_table`( `owner_agency` varchar(255) not null comment "项目所属机构", `project_type` varchar(255) not null comment "项目类型(Export/Wizard)", `label` varchar(1024) comment "项目标签", + `report_status` tinyint default 0 comment "上报状态", `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP comment "项目创建时间", `last_update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment "项目更新时间", primary key (`id`), unique index name_index(`name`(128)), index owner_index(`owner`(128), `owner_agency`(128)), index project_type_index(`project_type`(128)), - index label_index(`label`(128)) + index label_index(`label`(128)), + index report_status_index(`report_status`) )ENGINE=InnoDB default charset=utf8mb4 default collate=utf8mb4_bin ROW_FORMAT=DYNAMIC; -- the job table @@ -124,6 +126,7 @@ create table if not exists `wedpr_job_table`( `param` longtext comment "任务参数(json)", `status` varchar(255) comment "任务状态", `job_result` longtext comment "任务执行结果(json)", + `report_status` tinyint default 0 comment "上报状态", `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP comment "任务创建时间", `last_update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment "任务更新时间", primary key(`id`), @@ -131,7 +134,8 @@ create table if not exists `wedpr_job_table`( index owner_index(`owner`(128)), index owner_agency_index(`owner_agency`(128)), index project_index(`project_name`(128)), - index status_index(`status`(128)) + index status_index(`status`(128)), + index report_status_index(`report_status`) )ENGINE=InnoDB default charset=utf8mb4 default collate=utf8mb4_bin ROW_FORMAT=DYNAMIC; -- job dataset relationship table diff --git a/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/CredentialRequest.java b/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/CredentialRequest.java index bf866739..6d0b427a 100644 --- a/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/CredentialRequest.java +++ b/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/CredentialRequest.java @@ -23,6 +23,7 @@ @EqualsAndHashCode(callSuper = true) @Data @ToString +@EqualsAndHashCode(callSuper = false) public class CredentialRequest extends PageRequest { private ApiCredentialDO condition = new ApiCredentialDO(true); } diff --git a/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/JupyterRequest.java b/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/JupyterRequest.java index 2bb577f3..fdf08f31 100644 --- a/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/JupyterRequest.java +++ b/wedpr-adm/src/main/java/com/webank/wedpr/adm/controller/request/JupyterRequest.java @@ -23,6 +23,7 @@ @EqualsAndHashCode(callSuper = true) @Data @ToString +@EqualsAndHashCode(callSuper = false) public class JupyterRequest extends PageRequest { private JupyterInfoDO condition = new JupyterInfoDO(true); } diff --git a/wedpr-components/admin/build.gradle b/wedpr-components/admin/build.gradle index e44fea86..8ccba6cb 100644 --- a/wedpr-components/admin/build.gradle +++ b/wedpr-components/admin/build.gradle @@ -4,8 +4,9 @@ plugins { } dependencies { - compile project(":wedpr-components-token-auth") - compile project(":wedpr-components-mybatis") - compile project(":wedpr-components-dataset") - compile project(":wedpr-components-sync") + implementation project(":wedpr-components-token-auth") + implementation project(":wedpr-components-mybatis") + implementation project(":wedpr-components-dataset") + implementation project(":wedpr-components-sync") + implementation project(":wedpr-components-transport") } diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprJobTableController.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprJobTableController.java index 578af47e..558a046b 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprJobTableController.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprJobTableController.java @@ -7,7 +7,7 @@ * 前端控制器 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ @RestController @RequestMapping("/admin/wedprJobTable") diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprProjectTableController.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprProjectTableController.java index 030bf0cb..592b2847 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprProjectTableController.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/controller/WedprProjectTableController.java @@ -1,5 +1,17 @@ package com.webank.wedpr.components.admin.controller; +import com.webank.wedpr.components.admin.common.Utils; +import com.webank.wedpr.components.admin.request.GetWedprProjectListRequest; +import com.webank.wedpr.components.admin.response.ListProjectResponse; +import com.webank.wedpr.components.admin.service.WedprProjectTableService; +import com.webank.wedpr.components.token.auth.model.UserToken; +import com.webank.wedpr.core.utils.Constant; +import com.webank.wedpr.core.utils.WeDPRResponse; +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -7,8 +19,30 @@ * 前端控制器 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ @RestController -@RequestMapping("/admin/wedprProjectTable") -public class WedprProjectTableController {} +@RequestMapping( + path = Constant.WEDPR_API_PREFIX + "/admin", + produces = {"application/json"}) +@Slf4j +public class WedprProjectTableController { + @Autowired private WedprProjectTableService wedprProjectTableService; + + @GetMapping("/listProject") + public WeDPRResponse listProject( + @Valid GetWedprProjectListRequest getWedprProjectListRequest, + HttpServletRequest request) { + try { + // check user permission + UserToken userToken = Utils.checkPermission(request); + ListProjectResponse listProjectResponse = + wedprProjectTableService.listProject(getWedprProjectListRequest); + return new WeDPRResponse( + Constant.WEDPR_SUCCESS, Constant.WEDPR_SUCCESS_MSG, listProjectResponse); + } catch (Exception e) { + log.error("listProject error", e); + return new WeDPRResponse(Constant.WEDPR_FAILED, e.getMessage()); + } + } +} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprJobTable.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprJobTable.java index c7ecdb55..a793f6ed 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprJobTable.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprJobTable.java @@ -1,5 +1,6 @@ package com.webank.wedpr.components.admin.entity; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -8,7 +9,7 @@ /** * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ @TableName("wedpr_job_table") @ApiModel(value = "WedprJobTable对象", description = "") @@ -17,6 +18,7 @@ public class WedprJobTable implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "任务ID") + @TableId("id") private String id; @ApiModelProperty(value = "任务名称") @@ -46,6 +48,9 @@ public class WedprJobTable implements Serializable { @ApiModelProperty(value = "任务执行结果(json)") private String jobResult; + @ApiModelProperty(value = "上报状态") + private Integer reportStatus; + @ApiModelProperty(value = "任务创建时间") private LocalDateTime createTime; @@ -132,6 +137,14 @@ public void setJobResult(String jobResult) { this.jobResult = jobResult; } + public Integer getReportStatus() { + return reportStatus; + } + + public void setReportStatus(Integer reportStatus) { + this.reportStatus = reportStatus; + } + public LocalDateTime getCreateTime() { return createTime; } @@ -171,6 +184,8 @@ public String toString() { + status + ", jobResult=" + jobResult + + ", reportStatus=" + + reportStatus + ", createTime=" + createTime + ", lastUpdateTime=" diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprProjectTable.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprProjectTable.java index 4502f0aa..bfc6e4f4 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprProjectTable.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/entity/WedprProjectTable.java @@ -1,5 +1,7 @@ package com.webank.wedpr.components.admin.entity; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -8,7 +10,7 @@ /** * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ @TableName("wedpr_project_table") @ApiModel(value = "WedprProjectTable对象", description = "") @@ -17,12 +19,14 @@ public class WedprProjectTable implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "项目ID") + @TableId("id") private String id; @ApiModelProperty(value = "项目名称") private String name; @ApiModelProperty(value = "项目描述") + @TableField("`desc`") private String desc; @ApiModelProperty(value = "项目属主") @@ -37,6 +41,9 @@ public class WedprProjectTable implements Serializable { @ApiModelProperty(value = "项目标签") private String label; + @ApiModelProperty(value = "上报状态") + private Integer reportStatus; + @ApiModelProperty(value = "项目创建时间") private LocalDateTime createTime; @@ -99,6 +106,14 @@ public void setLabel(String label) { this.label = label; } + public Integer getReportStatus() { + return reportStatus; + } + + public void setReportStatus(Integer reportStatus) { + this.reportStatus = reportStatus; + } + public LocalDateTime getCreateTime() { return createTime; } @@ -132,6 +147,8 @@ public String toString() { + projectType + ", label=" + label + + ", reportStatus=" + + reportStatus + ", createTime=" + createTime + ", lastUpdateTime=" diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprJobTableMapper.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprJobTableMapper.java index 7890ae5b..fff7d163 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprJobTableMapper.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprJobTableMapper.java @@ -7,6 +7,6 @@ * Mapper 接口 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ public interface WedprJobTableMapper extends BaseMapper {} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprProjectTableMapper.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprProjectTableMapper.java index f1893e46..643a9311 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprProjectTableMapper.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/mapper/WedprProjectTableMapper.java @@ -7,6 +7,6 @@ * Mapper 接口 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ public interface WedprProjectTableMapper extends BaseMapper {} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/request/GetWedprProjectListRequest.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/request/GetWedprProjectListRequest.java new file mode 100644 index 00000000..4974e398 --- /dev/null +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/request/GetWedprProjectListRequest.java @@ -0,0 +1,19 @@ +package com.webank.wedpr.components.admin.request; + +import com.webank.wedpr.core.utils.Constant; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import lombok.Data; + +@Data +public class GetWedprProjectListRequest { + private String ownerAgencyName; + private String projectName; + private String startTime; + private String endTime; + private Integer pageNum = Constant.DEFAULT_PAGE_NUM; + + @Min(value = 5, message = "分页条数最小不能小于5") + @Max(value = 10000, message = "分页条数最大不能大于10000") + private Integer pageSize = Constant.DEFAULT_PAGE_SIZE; +} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/response/ListProjectResponse.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/response/ListProjectResponse.java new file mode 100644 index 00000000..9ac23f6b --- /dev/null +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/response/ListProjectResponse.java @@ -0,0 +1,12 @@ +package com.webank.wedpr.components.admin.response; + +import com.webank.wedpr.components.admin.entity.WedprProjectTable; +import java.util.List; +import lombok.Data; + +/** Created by caryliao on 2024/9/5 9:35 */ +@Data +public class ListProjectResponse { + private Long total; + private List projectList; +} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprJobTableService.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprJobTableService.java index 32a09dce..55aca11f 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprJobTableService.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprJobTableService.java @@ -7,6 +7,6 @@ * 服务类 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ public interface WedprJobTableService extends IService {} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprProjectTableService.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprProjectTableService.java index 6bb5b5bd..6fa00006 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprProjectTableService.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/WedprProjectTableService.java @@ -2,11 +2,16 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.webank.wedpr.components.admin.entity.WedprProjectTable; +import com.webank.wedpr.components.admin.request.GetWedprProjectListRequest; +import com.webank.wedpr.components.admin.response.ListProjectResponse; /** * 服务类 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ -public interface WedprProjectTableService extends IService {} +public interface WedprProjectTableService extends IService { + + ListProjectResponse listProject(GetWedprProjectListRequest getWedprProjectListRequest); +} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprJobTableServiceImpl.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprJobTableServiceImpl.java index 0df12450..86a3331b 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprJobTableServiceImpl.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprJobTableServiceImpl.java @@ -10,7 +10,7 @@ * 服务实现类 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ @Service public class WedprJobTableServiceImpl extends ServiceImpl diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprProjectTableServiceImpl.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprProjectTableServiceImpl.java index 176001c2..98f0cd8e 100644 --- a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprProjectTableServiceImpl.java +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/service/impl/WedprProjectTableServiceImpl.java @@ -1,18 +1,58 @@ package com.webank.wedpr.components.admin.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.webank.wedpr.components.admin.common.Utils; import com.webank.wedpr.components.admin.entity.WedprProjectTable; import com.webank.wedpr.components.admin.mapper.WedprProjectTableMapper; +import com.webank.wedpr.components.admin.request.GetWedprProjectListRequest; +import com.webank.wedpr.components.admin.response.ListProjectResponse; import com.webank.wedpr.components.admin.service.WedprProjectTableService; +import java.time.LocalDateTime; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; /** * 服务实现类 * * @author caryliao - * @since 2024-08-22 + * @since 2024-09-04 */ @Service public class WedprProjectTableServiceImpl extends ServiceImpl - implements WedprProjectTableService {} + implements WedprProjectTableService { + + @Override + public ListProjectResponse listProject(GetWedprProjectListRequest request) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + String ownerAgencyName = request.getOwnerAgencyName(); + String projectName = request.getProjectName(); + String startTimeStr = request.getStartTime(); + String endTimeStr = request.getEndTime(); + Integer pageNum = request.getPageNum(); + Integer pageSize = request.getPageSize(); + if (!StringUtils.isEmpty(ownerAgencyName)) { + lambdaQueryWrapper.like(WedprProjectTable::getOwnerAgency, ownerAgencyName); + } + if (!StringUtils.isEmpty(projectName)) { + lambdaQueryWrapper.like(WedprProjectTable::getName, projectName); + } + if (!StringUtils.isEmpty(startTimeStr)) { + LocalDateTime startTime = Utils.getLocalDateTime(startTimeStr); + lambdaQueryWrapper.ge(WedprProjectTable::getCreateTime, startTime); + } + if (!StringUtils.isEmpty(endTimeStr)) { + LocalDateTime endTime = Utils.getLocalDateTime(endTimeStr); + lambdaQueryWrapper.le(WedprProjectTable::getCreateTime, endTime); + } + lambdaQueryWrapper.orderByDesc(WedprProjectTable::getLastUpdateTime); + Page projectTablePage = new Page<>(pageNum, pageSize); + Page page = page(projectTablePage, lambdaQueryWrapper); + ListProjectResponse listProjectResponse = new ListProjectResponse(); + listProjectResponse.setTotal(page.getTotal()); + listProjectResponse.setProjectList(page.getRecords()); + return listProjectResponse; + } +} diff --git a/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/transport/TopicSubscriber.java b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/transport/TopicSubscriber.java new file mode 100644 index 00000000..01428e81 --- /dev/null +++ b/wedpr-components/admin/src/main/java/com/webank/wedpr/components/admin/transport/TopicSubscriber.java @@ -0,0 +1,60 @@ +package com.webank.wedpr.components.admin.transport; + +import com.webank.wedpr.components.admin.entity.WedprProjectTable; +import com.webank.wedpr.components.admin.service.WedprProjectTableService; +import com.webank.wedpr.components.transport.Transport; +import com.webank.wedpr.core.protocol.TransportTopicEnum; +import com.webank.wedpr.core.utils.ObjectMapperFactory; +import java.io.IOException; +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Service; + +/** Created by caryliao on 2024/9/4 15:03 */ +@Service +@Slf4j +public class TopicSubscriber implements CommandLineRunner { + private Transport transport; + + @Autowired private WedprProjectTableService wedprProjectTableService; + + @Override + public void run(String... args) throws Exception { + try { + subscribeProjectTopic(); + } catch (Exception e) { + log.warn("subscribe topic error", e); + } + } + + private void subscribeProjectTopic() { + transport.registerTopicHandler( + TransportTopicEnum.PROJECT_REPORT.name(), + (message) -> { + byte[] payload = message.getPayload(); + List wedprProjectTableList = null; + try { + wedprProjectTableList = + (List) + ObjectMapperFactory.getObjectMapper() + .readValue(payload, List.class); + } catch (IOException e) { + log.warn("parse message error", e); + } + for (WedprProjectTable wedprProjectTable : wedprProjectTableList) { + String id = wedprProjectTable.getId(); + WedprProjectTable queriedWedprProjectTable = + wedprProjectTableService.getById(id); + if (queriedWedprProjectTable == null) { + wedprProjectTableService.save(wedprProjectTable); + } else { + wedprProjectTableService.updateById(wedprProjectTable); + } + } + // TODO send response message + // transport.asyncSendMessage() + }); + } +} diff --git a/wedpr-components/admin/src/main/resources/mapper/WedprJobTableMapper.xml b/wedpr-components/admin/src/main/resources/mapper/WedprJobTableMapper.xml index 5dcfa2a5..596c0f18 100644 --- a/wedpr-components/admin/src/main/resources/mapper/WedprJobTableMapper.xml +++ b/wedpr-components/admin/src/main/resources/mapper/WedprJobTableMapper.xml @@ -14,6 +14,7 @@ + diff --git a/wedpr-components/admin/src/main/resources/mapper/WedprProjectTableMapper.xml b/wedpr-components/admin/src/main/resources/mapper/WedprProjectTableMapper.xml index 814d9666..153ac620 100644 --- a/wedpr-components/admin/src/main/resources/mapper/WedprProjectTableMapper.xml +++ b/wedpr-components/admin/src/main/resources/mapper/WedprProjectTableMapper.xml @@ -2,7 +2,6 @@ - @@ -11,6 +10,7 @@ + diff --git a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java index 7b316414..ba25f088 100644 --- a/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java +++ b/wedpr-components/env-integration/jupyter/src/main/java/com/webank/wedpr/components/integration/jupyter/dao/JupyterInfoDO.java @@ -26,6 +26,7 @@ @EqualsAndHashCode(callSuper = true) @Data @ToString +@EqualsAndHashCode(callSuper = false) public class JupyterInfoDO extends TimeRange { private String id = WeDPRUuidGenerator.generateID(); private String owner; diff --git a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectDO.java b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectDO.java index ef5ccaa7..0937ec9b 100644 --- a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectDO.java +++ b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectDO.java @@ -54,6 +54,16 @@ public static ProjectType deserialize(String type) { private String owner; private String ownerAgency; private String label = ""; + + public Integer getReportStatus() { + return reportStatus; + } + + public void setReportStatus(Integer reportStatus) { + this.reportStatus = reportStatus; + } + + private Integer reportStatus; private String type; private ProjectType projectType; @@ -188,9 +198,19 @@ public String toString() { + ", label='" + label + '\'' + + ", reportStatus=" + + reportStatus + ", type='" + type + '\'' + + ", projectType=" + + projectType + + ", createTime='" + + createTime + + '\'' + + ", lastUpdateTime='" + + lastUpdateTime + + '\'' + '}'; } } diff --git a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectMapper.java b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectMapper.java index 535e6cd1..52fd9755 100644 --- a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectMapper.java +++ b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/dao/ProjectMapper.java @@ -62,4 +62,8 @@ public List queryFollowerJobByCondition( @Param("condition") JobDO condition); public List queryJobsByDatasetID(@Param("datasetID") String datasetID); + + List queryProjectForAdmin(); + + ProjectDO queryProjectById(@Param("id") String id); } diff --git a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/ProjectService.java b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/ProjectService.java index 67e6d629..42ff7c2d 100644 --- a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/ProjectService.java +++ b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/ProjectService.java @@ -15,7 +15,9 @@ package com.webank.wedpr.components.project.service; +import com.webank.wedpr.components.project.dao.ProjectDO; import com.webank.wedpr.components.project.model.*; +import com.webank.wedpr.core.utils.WeDPRException; import com.webank.wedpr.core.utils.WeDPRResponse; import java.util.List; @@ -50,4 +52,8 @@ public abstract WeDPRResponse queryJobsByDatasetID( // job kill public abstract WeDPRResponse killJobs(String user, JobListRequest request); + + List queryProjectForReport() throws WeDPRException; + + ProjectDO queryProjectById(String id); } diff --git a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/impl/ProjectServiceImpl.java b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/impl/ProjectServiceImpl.java index f0636601..0072b918 100644 --- a/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/impl/ProjectServiceImpl.java +++ b/wedpr-components/meta/project/src/main/java/com/webank/wedpr/components/project/service/impl/ProjectServiceImpl.java @@ -31,10 +31,7 @@ import com.webank.wedpr.components.project.service.ProjectService; import com.webank.wedpr.core.config.WeDPRCommonConfig; import com.webank.wedpr.core.protocol.JobStatus; -import com.webank.wedpr.core.utils.Constant; -import com.webank.wedpr.core.utils.TimeRange; -import com.webank.wedpr.core.utils.WeDPRException; -import com.webank.wedpr.core.utils.WeDPRResponse; +import com.webank.wedpr.core.utils.*; import java.util.List; import org.apache.commons.lang3.tuple.Pair; import org.apache.ibatis.reflection.ArrayUtil; @@ -42,6 +39,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; @Service public class ProjectServiceImpl implements ProjectService { @@ -59,12 +57,15 @@ public WeDPRResponse createProject(String user, ProjectRequest projectDetail) { new WeDPRResponse(Constant.WEDPR_SUCCESS, Constant.WEDPR_SUCCESS_MSG); try { // set the user - projectDetail.getProject().setOwner(user); - projectDetail.getProject().setOwnerAgency(WeDPRCommonConfig.getAgency()); + ProjectDO project = projectDetail.getProject(); + project.setOwner(user); + if (StringUtils.isEmpty(project.getOwnerAgency())) { + project.setOwnerAgency(WeDPRCommonConfig.getAgency()); + } // check - projectDetail.getProject().checkCreate(); + project.checkCreate(); // check the existence - ProjectDO condition = new ProjectDO(projectDetail.getProject().getName()); + ProjectDO condition = new ProjectDO(project.getName()); condition.setId(null); List existedProjects = this.projectMapperWrapper @@ -73,15 +74,13 @@ public WeDPRResponse createProject(String user, ProjectRequest projectDetail) { if (existedProjects != null && !existedProjects.isEmpty()) { throw new WeDPRException( "createProject failed for the project " - + projectDetail.getProject().getName() + + project.getName() + " already exists, please try another project name!"); } - this.projectMapperWrapper - .getProjectMapper() - .insertProjectInfo(projectDetail.getProject()); + this.projectMapperWrapper.getProjectMapper().insertProjectInfo(project); // TODO: init the project resource logger.info("createProject success, detail: {}", projectDetail.toString()); - response.setData(projectDetail.getProject().getId()); + response.setData(project.getId()); } catch (Exception e) { logger.warn( "createProject failed, user: {}, detail: {}, error: ", @@ -480,6 +479,24 @@ public WeDPRResponse killJobs(String user, JobListRequest request) { user, WeDPRCommonConfig.getAgency(), request.getJobs(), JobStatus.WaitToKill); } + @Override + public List queryProjectForReport() throws WeDPRException { + PageRequest pageRequest = new PageRequest(); + pageRequest.setPageNum(Constant.DEFAULT_PAGE_NUM); + pageRequest.setPageSize(Constant.DEFAULT_REPORT_PAGE_SIZE); + try (PageHelperWrapper pageHelperWrapper = new PageHelperWrapper(pageRequest)) { + return this.projectMapperWrapper.getProjectMapper().queryProjectForAdmin(); + } catch (Exception e) { + logger.warn("queryProjectForAdmin exception, error: ", e); + throw new WeDPRException(e); + } + } + + @Override + public ProjectDO queryProjectById(String id) { + return this.projectMapperWrapper.getProjectMapper().queryProjectById(id); + } + @Override public Object queryJobOverview(String user, JobOverviewRequest jobOverviewRequest) throws Exception { diff --git a/wedpr-components/meta/project/src/main/resources/mapper/ProjectMapper.xml b/wedpr-components/meta/project/src/main/resources/mapper/ProjectMapper.xml index 7dd90a6c..e36b50b8 100644 --- a/wedpr-components/meta/project/src/main/resources/mapper/ProjectMapper.xml +++ b/wedpr-components/meta/project/src/main/resources/mapper/ProjectMapper.xml @@ -26,6 +26,7 @@ + @@ -117,6 +118,11 @@ order by `last_update_time` desc + + + + + diff --git a/wedpr-components/report/build.gradle b/wedpr-components/report/build.gradle index e58fbbbe..4fc1329e 100644 --- a/wedpr-components/report/build.gradle +++ b/wedpr-components/report/build.gradle @@ -4,6 +4,8 @@ plugins { } dependencies { - compile project(":wedpr-components-mybatis") + implementation project(":wedpr-components-mybatis") + implementation project(":wedpr-components-project") + implementation project(":wedpr-components-transport") implementation("org.springframework.boot:spring-boot-starter-quartz:${springBootVersion}") } diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/ReportQuartzJob.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/ReportQuartzJob.java deleted file mode 100644 index 713814e6..00000000 --- a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/ReportQuartzJob.java +++ /dev/null @@ -1,29 +0,0 @@ -/** Copyright (C) @2014-2022 Webank */ -package com.webank.wedpr.components.report; - -import java.time.LocalDateTime; -import lombok.extern.slf4j.Slf4j; -import org.quartz.DisallowConcurrentExecution; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.springframework.transaction.annotation.Transactional; - -@DisallowConcurrentExecution -@Slf4j -public class ReportQuartzJob implements Job { - - @Override - public void execute(JobExecutionContext context) { - log.info("ReportQuartzJob run at:{}", LocalDateTime.now()); - try { - doReport(); - } catch (Throwable e) { - log.warn("ReportQuartzJob run error", e); - } - } - - @Transactional(rollbackFor = Exception.class) - private void doReport() { - log.info("do report..."); - } -} diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/ApplicationListenerConfig.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/ApplicationListenerConfig.java similarity index 93% rename from wedpr-components/report/src/main/java/com/webank/wedpr/components/report/ApplicationListenerConfig.java rename to wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/ApplicationListenerConfig.java index c1b19ec9..eb1f9836 100644 --- a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/ApplicationListenerConfig.java +++ b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/ApplicationListenerConfig.java @@ -1,5 +1,5 @@ /** Copyright (C) @2014-2022 Webank */ -package com.webank.wedpr.components.report; +package com.webank.wedpr.components.report.config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzBindJobConfig.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzBindJobConfig.java similarity index 93% rename from wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzBindJobConfig.java rename to wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzBindJobConfig.java index 39e1a526..2d5dc599 100644 --- a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzBindJobConfig.java +++ b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzBindJobConfig.java @@ -1,6 +1,7 @@ /** Copyright (C) @2014-2022 Webank */ -package com.webank.wedpr.components.report; +package com.webank.wedpr.components.report.config; +import com.webank.wedpr.components.report.job.ReportQuartzJob; import lombok.extern.slf4j.Slf4j; import org.quartz.*; import org.springframework.beans.factory.annotation.Autowired; diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzConfig.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzConfig.java similarity index 97% rename from wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzConfig.java rename to wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzConfig.java index 0bb6a9c2..79bd1d46 100644 --- a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzConfig.java +++ b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzConfig.java @@ -1,5 +1,5 @@ /** Copyright (C) @2014-2022 Webank */ -package com.webank.wedpr.components.report; +package com.webank.wedpr.components.report.config; import java.io.IOException; import java.util.Properties; diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzJobFactory.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzJobFactory.java similarity index 93% rename from wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzJobFactory.java rename to wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzJobFactory.java index 0667b2b8..f0b04457 100644 --- a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/QuartzJobFactory.java +++ b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/config/QuartzJobFactory.java @@ -1,5 +1,5 @@ /** Copyright (C) @2014-2022 Webank */ -package com.webank.wedpr.components.report; +package com.webank.wedpr.components.report.config; import org.quartz.spi.TriggerFiredBundle; import org.springframework.beans.factory.annotation.Autowired; diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/handler/ProjectMessage.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/handler/ProjectMessage.java new file mode 100644 index 00000000..636a784d --- /dev/null +++ b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/handler/ProjectMessage.java @@ -0,0 +1,29 @@ +package com.webank.wedpr.components.report.handler; + +import com.webank.wedpr.components.transport.model.Message; +import lombok.Data; + +/** Created by caryliao on 2024/9/4 11:04 */ +@Data +public class ProjectMessage implements Message { + private String id; + private String name; + private String projectDesc; + private String owner; + private String ownerAgency; + private String label; + private Integer reportStatus; + private String projectType; + private String createTime; + private String lastUpdateTime; + + @Override + public MessageHeader getHeader() { + return null; + } + + @Override + public byte[] getPayload() { + return new byte[0]; + } +} diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/handler/ProjectReportMessageHandler.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/handler/ProjectReportMessageHandler.java new file mode 100644 index 00000000..a8a8bc98 --- /dev/null +++ b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/handler/ProjectReportMessageHandler.java @@ -0,0 +1,13 @@ +package com.webank.wedpr.components.report.handler; + +import com.webank.wedpr.components.transport.Transport; +import com.webank.wedpr.components.transport.model.Message; +import com.webank.wedpr.core.utils.WeDPRException; + +/** Created by caryliao on 2024/9/4 10:54 */ +public class ProjectReportMessageHandler implements Transport.MessageHandler { + @Override + public void call(Message msg) throws WeDPRException { + byte[] payload = msg.getPayload(); + } +} diff --git a/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/job/ReportQuartzJob.java b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/job/ReportQuartzJob.java new file mode 100644 index 00000000..1fe97ded --- /dev/null +++ b/wedpr-components/report/src/main/java/com/webank/wedpr/components/report/job/ReportQuartzJob.java @@ -0,0 +1,62 @@ +/** Copyright (C) @2014-2022 Webank */ +package com.webank.wedpr.components.report.job; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.webank.wedpr.components.project.dao.ProjectDO; +import com.webank.wedpr.components.project.service.ProjectService; +import com.webank.wedpr.components.report.handler.ProjectReportMessageHandler; +import com.webank.wedpr.components.transport.Transport; +import com.webank.wedpr.core.config.WeDPRCommonConfig; +import com.webank.wedpr.core.protocol.TransportTopicEnum; +import com.webank.wedpr.core.utils.ObjectMapperFactory; +import com.webank.wedpr.core.utils.WeDPRException; +import java.time.LocalDateTime; +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import org.quartz.DisallowConcurrentExecution; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +@DisallowConcurrentExecution +@Slf4j +public class ReportQuartzJob implements Job { + @Autowired private ProjectService projectService; + + private Transport transport; + + @Override + public void execute(JobExecutionContext context) { + log.info("ReportQuartzJob run at:{}", LocalDateTime.now()); + try { + doReport(); + } catch (Throwable e) { + log.warn("ReportQuartzJob run error", e); + } + } + + @Transactional(rollbackFor = Exception.class) + private void doReport() { + log.info("do report..."); + try { + String agency = WeDPRCommonConfig.getAgency(); + reportProjectInfo(agency); + } catch (Exception e) { + throw new RuntimeException("report error", e); + } + } + + private void reportProjectInfo(String agency) throws WeDPRException, JsonProcessingException { + ProjectReportMessageHandler projectReportMessageHandler = new ProjectReportMessageHandler(); + List projectDOList = projectService.queryProjectForReport(); + byte[] payload = ObjectMapperFactory.getObjectMapper().writeValueAsBytes(projectDOList); + transport.asyncSendMessageByAgency( + TransportTopicEnum.PROJECT_REPORT.name(), + agency, + payload, + 0, + WeDPRCommonConfig.getReportTimeout(), + projectReportMessageHandler); + } +} diff --git a/wedpr-core/protocol/src/main/java/com/webank/wedpr/core/protocol/TransportTopicEnum.java b/wedpr-core/protocol/src/main/java/com/webank/wedpr/core/protocol/TransportTopicEnum.java new file mode 100644 index 00000000..1166d7a2 --- /dev/null +++ b/wedpr-core/protocol/src/main/java/com/webank/wedpr/core/protocol/TransportTopicEnum.java @@ -0,0 +1,15 @@ +package com.webank.wedpr.core.protocol; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum TransportTopicEnum { + + /** project report */ + PROJECT_REPORT, + + /** job report */ + JOB_REPORT; +} diff --git a/wedpr-core/utils/src/main/java/com/webank/wedpr/core/config/WeDPRCommonConfig.java b/wedpr-core/utils/src/main/java/com/webank/wedpr/core/config/WeDPRCommonConfig.java index 55636aae..5c48e0ab 100644 --- a/wedpr-core/utils/src/main/java/com/webank/wedpr/core/config/WeDPRCommonConfig.java +++ b/wedpr-core/utils/src/main/java/com/webank/wedpr/core/config/WeDPRCommonConfig.java @@ -34,6 +34,8 @@ public class WeDPRCommonConfig { WeDPRConfig.apply("wedpr.auth.cache.size", 10000); private static final Integer AUTH_CACHE_EXPIRE_TIME = WeDPRConfig.apply("wedpr.auth.cache.expire.minutes", 30); + private static final Integer REPORT_TIMEOUT = + WeDPRConfig.apply("wedpr.report.timeout.seconds", 30); public static String getAgency() { return AGENCY; @@ -78,4 +80,8 @@ public static Integer getAuthCacheSize() { public static Integer getAuthCacheExpireTime() { return AUTH_CACHE_EXPIRE_TIME; } + + public static Integer getReportTimeout() { + return REPORT_TIMEOUT; + } } diff --git a/wedpr-core/utils/src/main/java/com/webank/wedpr/core/utils/Constant.java b/wedpr-core/utils/src/main/java/com/webank/wedpr/core/utils/Constant.java index 7a5dcda7..5390bf1e 100644 --- a/wedpr-core/utils/src/main/java/com/webank/wedpr/core/utils/Constant.java +++ b/wedpr-core/utils/src/main/java/com/webank/wedpr/core/utils/Constant.java @@ -50,6 +50,8 @@ public class Constant { /** @Fields DEFAULT_PAGE_SIZE:分页的每页记录数 */ public static final int DEFAULT_PAGE_SIZE = 5; + public static final int DEFAULT_REPORT_PAGE_SIZE = 1000; + public static final String SITE_END_LOGIN_URL = WEDPR_API_PREFIX + "/login"; public static final String ADMIN_END_LOGIN_URL = WEDPR_API_PREFIX + "/admin/login";