You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/04 02:25:32 UTC
[shardingsphere-elasticjob-lite] branch master updated: Refactor
EventTraceHistoryController (#930)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-lite.git
The following commit(s) were added to refs/heads/master by this push:
new 8635f3e Refactor EventTraceHistoryController (#930)
8635f3e is described below
commit 8635f3e8c4fda73fbea0058fba73fc2e6d4e8a34
Author: Long Chen <54...@qq.com>
AuthorDate: Sat Jul 4 10:25:22 2020 +0800
Refactor EventTraceHistoryController (#930)
* Refactor EventTraceHistoryController
* Fix checkstyle
* Fix checkstyle
* Add licenses info
---
.../controller/EventTraceHistoryController.java | 89 ++-----
.../dao/search/JobExecutionLogRepository.java | 1 +
.../dao/search/JobStatusTraceLogRepository.java | 1 +
.../lite/console/dao/search/RDBJobEventSearch.java | 215 ----------------
.../{dao/search => domain}/JobExecutionLog.java | 2 +-
.../{dao/search => domain}/JobStatusTraceLog.java | 2 +-
.../lite/console/dto/request/BasePageRequest.java | 62 +++++
.../dto/request/FindJobExecutionEventsRequest.java | 79 ++++++
.../request/FindJobStatusTraceEventsRequest.java | 81 ++++++
.../console/dto/response/BasePageResponse.java | 64 +++++
.../console/service/EventTraceHistoryService.java | 46 ++++
.../service/impl/EventTraceHistoryServiceImpl.java | 131 ++++++++++
.../src/main/resources/application.properties | 1 +
.../console/dao/search/RDBJobEventSearchTest.java | 276 ++++++++++-----------
.../search/RDBJobEventSearchTestConfiguration.java | 22 +-
15 files changed, 632 insertions(+), 440 deletions(-)
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceHistoryController.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceHistoryController.java
index 2f96691..c328b54 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceHistoryController.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/controller/EventTraceHistoryController.java
@@ -17,59 +17,39 @@
package org.apache.shardingsphere.elasticjob.lite.console.controller;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch;
-import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch.Condition;
-import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch.Result;
-import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceDataSourceConfigurationService;
+import javax.ws.rs.core.MediaType;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobExecutionEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobStatusTraceEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.response.BasePageResponse;
+import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceHistoryService;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.MultiValueMap;
+import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
-import javax.ws.rs.core.MediaType;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* Event trace history RESTful API.
*/
@RestController
@RequestMapping("/event-trace")
public final class EventTraceHistoryController {
-
- private EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService;
-
- private final RDBJobEventSearch rdbJobEventSearch;
-
+
@Autowired
- public EventTraceHistoryController(final EventTraceDataSourceConfigurationService eventTraceDataSourceConfigurationService,
- final RDBJobEventSearch rdbJobEventSearch) {
- this.eventTraceDataSourceConfigurationService = eventTraceDataSourceConfigurationService;
- this.rdbJobEventSearch = rdbJobEventSearch;
- }
-
+ private EventTraceHistoryService eventTraceHistoryService;
+
/**
* Find job execution events.
*
* @param requestParams query criteria
* @return job execution event trace result
- * @throws ParseException parse exception
*/
- @GetMapping(value = "/execution", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
- public Result<JobExecutionEvent> findJobExecutionEvents(@RequestParam final MultiValueMap<String, String> requestParams) throws ParseException {
- if (!eventTraceDataSourceConfigurationService.loadActivated().isPresent()) {
- return new Result<>(0L, new ArrayList<JobExecutionEvent>());
- }
- return rdbJobEventSearch.findJobExecutionEvents(buildCondition(requestParams, new String[]{"jobName", "ip", "isSuccess"}));
+ @GetMapping(value = "/execution", produces = MediaType.APPLICATION_JSON)
+ public BasePageResponse<JobExecutionEvent> findJobExecutionEvents(final FindJobExecutionEventsRequest requestParams) {
+ Page<JobExecutionEvent> jobExecutionEvents = eventTraceHistoryService.findJobExecutionEvents(requestParams);
+ return BasePageResponse.of(jobExecutionEvents);
}
/**
@@ -77,47 +57,10 @@ public final class EventTraceHistoryController {
*
* @param requestParams query criteria
* @return job status trace result
- * @throws ParseException parse exception
*/
@GetMapping(value = "/status", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
- public Result<JobStatusTraceEvent> findJobStatusTraceEvents(@RequestParam final MultiValueMap<String, String> requestParams) throws ParseException {
- if (!eventTraceDataSourceConfigurationService.loadActivated().isPresent()) {
- return new Result<>(0L, new ArrayList<JobStatusTraceEvent>());
- }
- return rdbJobEventSearch.findJobStatusTraceEvents(buildCondition(requestParams, new String[]{"jobName", "source", "executionType", "state"}));
- }
-
- private Condition buildCondition(final MultiValueMap<String, String> requestParams, final String[] params) throws ParseException {
- int perPage = 10;
- int page = 1;
- if (!Strings.isNullOrEmpty(requestParams.getFirst("per_page"))) {
- perPage = Integer.parseInt(requestParams.getFirst("per_page"));
- }
- if (!Strings.isNullOrEmpty(requestParams.getFirst("page"))) {
- page = Integer.parseInt(requestParams.getFirst("page"));
- }
- String sort = requestParams.getFirst("sort");
- String order = requestParams.getFirst("order");
- Date startTime = null;
- Date endTime = null;
- Map<String, Object> fields = getQueryParameters(requestParams, params);
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- if (!Strings.isNullOrEmpty(requestParams.getFirst("startTime"))) {
- startTime = simpleDateFormat.parse(requestParams.getFirst("startTime"));
- }
- if (!Strings.isNullOrEmpty(requestParams.getFirst("endTime"))) {
- endTime = simpleDateFormat.parse(requestParams.getFirst("endTime"));
- }
- return new Condition(perPage, page, sort, order, startTime, endTime, fields);
- }
-
- private Map<String, Object> getQueryParameters(final MultiValueMap<String, String> requestParams, final String[] params) {
- final Map<String, Object> result = new HashMap<>();
- for (String each : params) {
- if (!Strings.isNullOrEmpty(requestParams.getFirst(each))) {
- result.put(each, requestParams.getFirst(each));
- }
- }
- return result;
+ public BasePageResponse<JobStatusTraceEvent> findJobStatusTraceEvents(final FindJobStatusTraceEventsRequest requestParams) {
+ Page<JobStatusTraceEvent> jobStatusTraceEvents = eventTraceHistoryService.findJobStatusTraceEvents(requestParams);
+ return BasePageResponse.of(jobStatusTraceEvents);
}
}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobExecutionLogRepository.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobExecutionLogRepository.java
index 42db723..7e0d8f8 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobExecutionLogRepository.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobExecutionLogRepository.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.elasticjob.lite.console.dao.search;
+import org.apache.shardingsphere.elasticjob.lite.console.domain.JobExecutionLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobStatusTraceLogRepository.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobStatusTraceLogRepository.java
index 0523fd7..302c4d9 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobStatusTraceLogRepository.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobStatusTraceLogRepository.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.elasticjob.lite.console.dao.search;
+import org.apache.shardingsphere.elasticjob.lite.console.domain.JobStatusTraceLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearch.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearch.java
deleted file mode 100644
index c46082e..0000000
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearch.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.elasticjob.lite.console.dao.search;
-
-import com.google.common.base.Strings;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.elasticjob.lite.console.util.BeanUtils;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
-import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageImpl;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.jpa.convert.QueryByExamplePredicateBuilder;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.stereotype.Component;
-
-import javax.persistence.criteria.Predicate;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-/**
- * RDB job event search.
- */
-@Slf4j
-@Component
-public final class RDBJobEventSearch {
-
- private final JobExecutionLogRepository jobExecutionLogRepository;
-
- private final JobStatusTraceLogRepository jobStatusTraceLogRepository;
-
- @Autowired
- public RDBJobEventSearch(final JobExecutionLogRepository jobExecutionLogRepository,
- final JobStatusTraceLogRepository jobStatusTraceLogRepository) {
- this.jobExecutionLogRepository = jobExecutionLogRepository;
- this.jobStatusTraceLogRepository = jobStatusTraceLogRepository;
- }
-
- /**
- * Find job execution events.
- *
- * @param condition query condition
- * @return job execution events
- */
- public Result<JobExecutionEvent> findJobExecutionEvents(final Condition condition) {
- dealFields(condition.getFields());
- Page<JobExecutionEvent> jobExecutionEvents = getJobExecutionEvents(condition);
- return new Result<>(jobExecutionEvents.getTotalElements(), jobExecutionEvents.getContent());
- }
-
- private void dealFields(final Map<String, Object> fields) {
- if (Objects.isNull(fields)) {
- return;
- }
- Object isSuccessField = fields.get("isSuccess");
- if (!Objects.isNull(isSuccessField)) {
- fields.put("isSuccess", Objects.equals(isSuccessField, "1"));
- }
- }
-
- /**
- * Find job status trace events.
- *
- * @param condition query condition
- * @return job status trace events
- */
- public Result<JobStatusTraceEvent> findJobStatusTraceEvents(final Condition condition) {
- Page<JobStatusTraceEvent> jobStatusTraceEvents = getJobStatusTraceEvents(condition);
- return new Result<>(jobStatusTraceEvents.getTotalElements(), jobStatusTraceEvents.getContent());
- }
-
- private Page<JobExecutionEvent> getJobExecutionEvents(final Condition condition) {
- Specification<JobExecutionLog> specification =
- getSpecification(JobExecutionLog.class, condition, "startTime");
- Page<JobExecutionLog> page =
- jobExecutionLogRepository.findAll(specification, getPageable(condition, JobExecutionLog.class));
- return new PageImpl<>(
- page.get().map(JobExecutionLog::toJobExecutionEvent).collect(Collectors.toList()),
- page.getPageable(),
- page.getTotalElements()
- );
- }
-
- private <T> Pageable getPageable(final Condition condition, final Class<T> clazz) {
- int page = 0;
- int perPage = Condition.DEFAULT_PAGE_SIZE;
- if (condition.getPage() > 0 && condition.getPerPage() > 0) {
- page = condition.getPage() - 1;
- perPage = condition.getPerPage();
- }
- return PageRequest.of(page, perPage, getSort(condition, clazz));
- }
-
- private <T> Sort getSort(final Condition condition, final Class<T> clazz) {
- Sort sort = Sort.unsorted();
- boolean sortFieldIsPresent = Arrays.stream(clazz.getDeclaredFields())
- .map(Field::getName)
- .anyMatch(e -> e.equals(condition.getSort()));
- if (!sortFieldIsPresent) {
- return sort;
- }
- if (!Strings.isNullOrEmpty(condition.getSort())) {
- Sort.Direction order = Sort.Direction.ASC;
- try {
- order = Sort.Direction.valueOf(condition.getOrder());
- } catch (IllegalArgumentException ignored) {
- }
- sort = Sort.by(order, condition.getSort());
- }
- return sort;
- }
-
- private Page<JobStatusTraceEvent> getJobStatusTraceEvents(final Condition condition) {
- Specification<JobStatusTraceLog> specification =
- getSpecification(JobStatusTraceLog.class, condition, "creationTime");
- Page<JobStatusTraceLog> page =
- jobStatusTraceLogRepository.findAll(specification, getPageable(condition, JobStatusTraceLog.class));
- return new PageImpl<>(
- page.get().map(JobStatusTraceLog::toJobStatusTraceEvent).collect(Collectors.toList()),
- page.getPageable(),
- page.getTotalElements()
- );
- }
-
- private <T> Specification<T> getSpecification(final Class<T> clazz, final Condition condition, final String dateField) {
- Example<T> example = getExample(condition.getFields(), clazz);
- return getSpecWithExampleAndDate(
- example, condition.getStartTime(), condition.getEndTime(), dateField
- );
- }
-
- private <T> Specification<T> getSpecWithExampleAndDate(
- final Example<T> example, final Date from, final Date to, final String field
- ) {
- return (Specification<T>) (root, query, builder) -> {
- final List<Predicate> predicates = new ArrayList<>();
- if (from != null) {
- predicates.add(builder.greaterThan(root.get(field), from));
- }
- if (to != null) {
- predicates.add(builder.lessThan(root.get(field), to));
- }
- predicates.add(QueryByExamplePredicateBuilder.getPredicate(root, builder, example));
- return builder.and(predicates.toArray(new Predicate[0]));
- };
- }
-
- private <T> Example<T> getExample(final Map<String, Object> fields, final Class<T> clazz) {
- T bean = BeanUtils.toBean(fields, clazz);
- if (Objects.isNull(bean)) {
- bean = BeanUtils.newInstance(clazz);
- }
- return Example.of(bean);
- }
-
- /**
- * Query condition.
- */
- @RequiredArgsConstructor
- @Getter
- public static class Condition {
-
- private static final int DEFAULT_PAGE_SIZE = 10;
-
- private final int perPage;
-
- private final int page;
-
- private final String sort;
-
- private final String order;
-
- private final Date startTime;
-
- private final Date endTime;
-
- private final Map<String, Object> fields;
- }
-
- @RequiredArgsConstructor
- @Getter
- public static class Result<T> {
-
- private final Long total;
-
- private final List<T> rows;
- }
-}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobExecutionLog.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/domain/JobExecutionLog.java
similarity index 97%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobExecutionLog.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/domain/JobExecutionLog.java
index 5780d78..1c28686 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobExecutionLog.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/domain/JobExecutionLog.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.dao.search;
+package org.apache.shardingsphere.elasticjob.lite.console.domain;
import lombok.Data;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobStatusTraceLog.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/domain/JobStatusTraceLog.java
similarity index 97%
rename from elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobStatusTraceLog.java
rename to elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/domain/JobStatusTraceLog.java
index 79d522d..68003fd 100644
--- a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/JobStatusTraceLog.java
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/domain/JobStatusTraceLog.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.lite.console.dao.search;
+package org.apache.shardingsphere.elasticjob.lite.console.domain;
import lombok.Data;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/BasePageRequest.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/BasePageRequest.java
new file mode 100644
index 0000000..fd78e95
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/BasePageRequest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.console.dto.request;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * Pageable request base request.
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class BasePageRequest {
+
+ public static final int DEFAULT_PAGE_SIZE = 10;
+
+ // CHECKSTYLE:OFF
+ /**
+ * Page size of request.
+ */
+ @JsonProperty("per_page")
+ protected Integer pageSize = DEFAULT_PAGE_SIZE;
+
+ /**
+ * Page number of request.
+ */
+ @JsonProperty("page")
+ protected Integer pageNumber = 1;
+
+ /**
+ * The field name for sort by.
+ */
+ @JsonProperty("sort")
+ protected String sortBy;
+
+ /**
+ * Order type, asc or desc.
+ */
+ @JsonProperty("order")
+ protected String orderType;
+ // CHECKSTYLE:ON
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/FindJobExecutionEventsRequest.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/FindJobExecutionEventsRequest.java
new file mode 100644
index 0000000..02abc05
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/FindJobExecutionEventsRequest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.console.dto.request;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Date;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * Request object of uri '/event-trace/execution'.
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class FindJobExecutionEventsRequest extends BasePageRequest {
+
+ private String jobName;
+
+ private String ip;
+
+ private Boolean isSuccess;
+
+ @JsonProperty("startTime")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date start;
+
+ @JsonProperty("endTime")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date end;
+
+ /**
+ * Create new FindJobExecutionEventsRequest with pageSize and pageNumber.
+ * @param pageNumber page number
+ * @param pageSize page size
+ */
+ public FindJobExecutionEventsRequest(final Integer pageSize, final Integer pageNumber) {
+ this.pageSize = pageSize;
+ this.pageNumber = pageNumber;
+ }
+
+ /**
+ * Create new FindJobExecutionEventsRequest with properties.
+ * @param pageNumber page number
+ * @param pageSize page size
+ * @param sortBy the field name sort by
+ * @param orderType order type, asc or desc
+ * @param startTime start time
+ * @param endTime end time
+ */
+ public FindJobExecutionEventsRequest(final Integer pageSize, final Integer pageNumber, final String sortBy,
+ final String orderType, final Date startTime, final Date endTime) {
+ this.pageSize = pageSize;
+ this.pageNumber = pageNumber;
+ this.sortBy = sortBy;
+ this.orderType = orderType;
+ this.start = startTime;
+ this.end = endTime;
+ }
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/FindJobStatusTraceEventsRequest.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/FindJobStatusTraceEventsRequest.java
new file mode 100644
index 0000000..252c87c
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/request/FindJobStatusTraceEventsRequest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.console.dto.request;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Date;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * Request object of uri '/event-trace/status'.
+ */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+public class FindJobStatusTraceEventsRequest extends BasePageRequest {
+
+ private String jobName;
+
+ private String source;
+
+ private String executionType;
+
+ private String state;
+
+ @JsonProperty("startTime")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date start;
+
+ @JsonProperty("endTime")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ private Date end;
+
+ /**
+ * Create new FindJobStatusTraceEventsRequest with pageSize and pageNumber.
+ * @param pageNumber page number.
+ * @param pageSize page size.
+ */
+ public FindJobStatusTraceEventsRequest(final Integer pageSize, final Integer pageNumber) {
+ this.pageSize = pageSize;
+ this.pageNumber = pageNumber;
+ }
+
+ /**
+ * Create new FindJobStatusTraceEventsRequest with properties.
+ * @param pageNumber page number
+ * @param pageSize page size
+ * @param sortBy the field name sort by
+ * @param orderType order type, asc or desc
+ * @param startTime start time
+ * @param endTime end time
+ */
+ public FindJobStatusTraceEventsRequest(final Integer pageSize, final Integer pageNumber, final String sortBy,
+ final String orderType, final Date startTime, final Date endTime) {
+ this.pageSize = pageSize;
+ this.pageNumber = pageNumber;
+ this.sortBy = sortBy;
+ this.orderType = orderType;
+ this.start = startTime;
+ this.end = endTime;
+ }
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/response/BasePageResponse.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/response/BasePageResponse.java
new file mode 100644
index 0000000..bda2983
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/dto/response/BasePageResponse.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.console.dto.response;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import java.io.Serializable;
+import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import org.springframework.data.domain.Page;
+
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class BasePageResponse<T> implements Serializable {
+
+ /**
+ * Total count of rows.
+ */
+ private Long total;
+
+ /**
+ * Rows data.
+ */
+ private List<T> rows;
+
+ /**
+ * Create new BasePageResponse with total and data.
+ * @param total Total count of match data
+ * @param data Current page of data
+ * @param <T> Data type
+ * @return BasePageResponse
+ */
+ public static <T> BasePageResponse of(final Long total, final List<T> data) {
+ return new BasePageResponse(total, data);
+ }
+
+ /**
+ * Create new BasePageResponse with Page.
+ * @param page match data info.
+ * @param <T> Data type
+ * @return BasePageResponse
+ */
+ public static <T> BasePageResponse of(final Page<T> page) {
+ return new BasePageResponse(page.getTotalElements(), page.getContent());
+ }
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/EventTraceHistoryService.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/EventTraceHistoryService.java
new file mode 100644
index 0000000..cf3ab16
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/EventTraceHistoryService.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.console.service;
+
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobExecutionEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobStatusTraceEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
+import org.springframework.data.domain.Page;
+
+/**
+ * Event trace history service.
+ */
+public interface EventTraceHistoryService {
+
+ /**
+ * Find job execution events.
+ *
+ * @param findJobExecutionEventsRequest query params
+ * @return job execution events
+ */
+ Page<JobExecutionEvent> findJobExecutionEvents(FindJobExecutionEventsRequest findJobExecutionEventsRequest);
+
+ /**
+ * Find job status trace events.
+ *
+ * @param findJobStatusTraceEventsRequest query params
+ * @return job status trace events
+ */
+ Page<JobStatusTraceEvent> findJobStatusTraceEvents(FindJobStatusTraceEventsRequest findJobStatusTraceEventsRequest);
+}
diff --git a/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/EventTraceHistoryServiceImpl.java b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/EventTraceHistoryServiceImpl.java
new file mode 100644
index 0000000..93f8c07
--- /dev/null
+++ b/elastic-job-lite-console/src/main/java/org/apache/shardingsphere/elasticjob/lite/console/service/impl/EventTraceHistoryServiceImpl.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.lite.console.service.impl;
+
+import com.google.common.base.Strings;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.persistence.criteria.Predicate;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.lite.console.dao.search.JobExecutionLogRepository;
+import org.apache.shardingsphere.elasticjob.lite.console.dao.search.JobStatusTraceLogRepository;
+import org.apache.shardingsphere.elasticjob.lite.console.domain.JobExecutionLog;
+import org.apache.shardingsphere.elasticjob.lite.console.domain.JobStatusTraceLog;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.BasePageRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobExecutionEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobStatusTraceEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceHistoryService;
+import org.apache.shardingsphere.elasticjob.lite.console.util.BeanUtils;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
+import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.jpa.convert.QueryByExamplePredicateBuilder;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Component;
+
+/**
+ * Event trace history service implementation.
+ */
+@Slf4j
+@Component
+public final class EventTraceHistoryServiceImpl implements EventTraceHistoryService {
+
+ @Autowired
+ private JobExecutionLogRepository jobExecutionLogRepository;
+
+ @Autowired
+ private JobStatusTraceLogRepository jobStatusTraceLogRepository;
+
+ @Override
+ public Page<JobExecutionEvent> findJobExecutionEvents(final FindJobExecutionEventsRequest findJobExecutionEventsRequest) {
+ Example<JobExecutionLog> jobExecutionLogExample = getExample(findJobExecutionEventsRequest, JobExecutionLog.class);
+ Specification<JobExecutionLog> specification = getSpecWithExampleAndDate(jobExecutionLogExample, findJobExecutionEventsRequest.getStart(),
+ findJobExecutionEventsRequest.getEnd(), "startTime");
+
+ Page<JobExecutionLog> page = jobExecutionLogRepository.findAll(specification, getPageable(findJobExecutionEventsRequest, JobExecutionLog.class));
+ return new PageImpl<>(page.get().map(JobExecutionLog::toJobExecutionEvent).collect(Collectors.toList()), page.getPageable(), page.getTotalElements());
+ }
+
+ @Override
+ public Page<JobStatusTraceEvent> findJobStatusTraceEvents(final FindJobStatusTraceEventsRequest findJobStatusTraceEventsRequest) {
+ Example<JobStatusTraceLog> jobStatusTraceLogExample = getExample(findJobStatusTraceEventsRequest, JobStatusTraceLog.class);
+ Specification<JobStatusTraceLog> specification = getSpecWithExampleAndDate(jobStatusTraceLogExample, findJobStatusTraceEventsRequest.getStart(),
+ findJobStatusTraceEventsRequest.getEnd(), "creationTime");
+ Page<JobStatusTraceLog> page = jobStatusTraceLogRepository.findAll(specification, getPageable(findJobStatusTraceEventsRequest, JobStatusTraceLog.class));
+ return new PageImpl<>(page.get().map(JobStatusTraceLog::toJobStatusTraceEvent).collect(Collectors.toList()), page.getPageable(), page.getTotalElements());
+ }
+
+ private <T> Pageable getPageable(final BasePageRequest pageRequest, final Class<T> clazz) {
+ int page = 0;
+ int perPage = BasePageRequest.DEFAULT_PAGE_SIZE;
+ if (pageRequest.getPageNumber() > 0 && pageRequest.getPageSize() > 0) {
+ page = pageRequest.getPageNumber() - 1;
+ perPage = pageRequest.getPageSize();
+ }
+ return PageRequest.of(page, perPage, getSort(pageRequest, clazz));
+ }
+
+ private <T> Sort getSort(final BasePageRequest pageRequest, final Class<T> clazz) {
+ Sort sort = Sort.unsorted();
+ boolean sortFieldIsPresent = Arrays.stream(clazz.getDeclaredFields())
+ .map(Field::getName)
+ .anyMatch(e -> e.equals(pageRequest.getSortBy()));
+ if (!sortFieldIsPresent) {
+ return sort;
+ }
+ if (!Strings.isNullOrEmpty(pageRequest.getSortBy())) {
+ Sort.Direction order = Sort.Direction.ASC;
+ try {
+ order = Sort.Direction.valueOf(pageRequest.getOrderType());
+ } catch (IllegalArgumentException ignored) {
+ }
+ sort = Sort.by(order, pageRequest.getSortBy());
+ }
+ return sort;
+ }
+
+ private <T> Specification<T> getSpecWithExampleAndDate(final Example<T> example, final Date from, final Date to, final String field) {
+ return (Specification<T>) (root, query, builder) -> {
+ final List<Predicate> predicates = new ArrayList<>();
+ if (from != null) {
+ predicates.add(builder.greaterThan(root.get(field), from));
+ }
+ if (to != null) {
+ predicates.add(builder.lessThan(root.get(field), to));
+ }
+ predicates.add(QueryByExamplePredicateBuilder.getPredicate(root, builder, example));
+ return builder.and(predicates.toArray(new Predicate[0]));
+ };
+ }
+
+ private <T> Example<T> getExample(final Object source, final Class<T> clazz) {
+ T instance = BeanUtils.newInstance(clazz);
+ BeanUtils.copyProperties(source, instance);
+ return Example.of(instance);
+ }
+}
diff --git a/elastic-job-lite-console/src/main/resources/application.properties b/elastic-job-lite-console/src/main/resources/application.properties
index 24a2a54..b07f5e5 100644
--- a/elastic-job-lite-console/src/main/resources/application.properties
+++ b/elastic-job-lite-console/src/main/resources/application.properties
@@ -28,3 +28,4 @@ spring.datasource.default.url=jdbc:h2:mem:
spring.datasource.default.username=sa
spring.datasource.default.password=
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
+spring.jpa.show-sql=true
diff --git a/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTest.java b/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTest.java
index a30b212..e79eb37 100644
--- a/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTest.java
+++ b/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTest.java
@@ -17,8 +17,13 @@
package org.apache.shardingsphere.elasticjob.lite.console.dao.search;
-import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch.Condition;
-import org.apache.shardingsphere.elasticjob.lite.console.dao.search.RDBJobEventSearch.Result;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.Date;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobExecutionEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobStatusTraceEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceHistoryService;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
import org.junit.Test;
@@ -26,195 +31,186 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
+import org.springframework.data.domain.Page;
import org.springframework.test.context.junit4.SpringRunner;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
@RunWith(SpringRunner.class)
@SpringBootTest
@Import(RDBJobEventSearchTestConfiguration.class)
public final class RDBJobEventSearchTest {
-
+
@Autowired
- private RDBJobEventSearch repository;
-
+ private EventTraceHistoryService eventTraceHistoryService;
+
@Test
public void assertFindJobExecutionEventsWithPageSizeAndNumber() {
- Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- result = repository.findJobExecutionEvents(new Condition(50, 1, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(50));
- result = repository.findJobExecutionEvents(new Condition(100, 5, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(100));
- result = repository.findJobExecutionEvents(new Condition(100, 6, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(0));
+ Page<JobExecutionEvent> result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest());
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(50, 1));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(50));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(100, 5));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(100));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(100, 6));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(0));
}
-
+
@Test
public void assertFindJobExecutionEventsWithErrorPageSizeAndNumber() {
- Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(-1, -1, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ Page<JobExecutionEvent> result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(-1, -1, null, null, null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
-
+
@Test
public void assertFindJobExecutionEventsWithSort() {
- Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, "jobName", "ASC", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- assertThat(result.getRows().get(0).getJobName(), is("test_job_1"));
- result = repository.findJobExecutionEvents(new Condition(10, 1, "jobName", "DESC", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- assertThat(result.getRows().get(0).getJobName(), is("test_job_99"));
+ Page<JobExecutionEvent> result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, "jobName", "ASC", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ assertThat(result.getContent().get(0).getJobName(), is("test_job_1"));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, "jobName", "DESC", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ assertThat(result.getContent().get(0).getJobName(), is("test_job_99"));
}
-
+
@Test
public void assertFindJobExecutionEventsWithErrorSort() {
- Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, "jobName", "ERROR_SORT", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- assertThat(result.getRows().get(0).getJobName(), is("test_job_1"));
- result = repository.findJobExecutionEvents(new Condition(10, 1, "notExistField", "ASC", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ Page<JobExecutionEvent> result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, "jobName", "ERROR_SORT", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ assertThat(result.getContent().get(0).getJobName(), is("test_job_1"));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, "notExistField", "ASC", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
-
+
@Test
public void assertFindJobExecutionEventsWithTime() {
Date now = new Date();
Date tenMinutesBefore = new Date(now.getTime() - 10 * 60 * 1000);
- Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, tenMinutesBefore, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, now, null, null));
- assertThat(result.getTotal(), is(0L));
- assertThat(result.getRows().size(), is(0));
- result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, tenMinutesBefore, null));
- assertThat(result.getTotal(), is(0L));
- assertThat(result.getRows().size(), is(0));
- result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, now, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, tenMinutesBefore, now, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ Page<JobExecutionEvent> result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, null, null, tenMinutesBefore, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, null, null, now, null));
+ assertThat(result.getTotalElements(), is(0L));
+ assertThat(result.getContent().size(), is(0));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, null, null, null, tenMinutesBefore));
+ assertThat(result.getTotalElements(), is(0L));
+ assertThat(result.getContent().size(), is(0));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, null, null, null, now));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1, null, null, tenMinutesBefore, now));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
-
+
@Test
public void assertFindJobExecutionEventsWithFields() {
- Map<String, Object> fields = new HashMap<>();
- fields.put("isSuccess", "1");
- Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, null, fields));
- assertThat(result.getTotal(), is(250L));
- assertThat(result.getRows().size(), is(10));
- fields.put("isSuccess", null);
- fields.put("jobName", "test_job_1");
- result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, null, fields));
- assertThat(result.getTotal(), is(1L));
- assertThat(result.getRows().size(), is(1));
+ FindJobExecutionEventsRequest findJobExecutionEventsRequest = new FindJobExecutionEventsRequest(10, 1, null, null, null, null);
+ findJobExecutionEventsRequest.setIsSuccess(true);
+ Page<JobExecutionEvent> result = eventTraceHistoryService.findJobExecutionEvents(findJobExecutionEventsRequest);
+ assertThat(result.getTotalElements(), is(250L));
+ assertThat(result.getContent().size(), is(10));
+ findJobExecutionEventsRequest.setIsSuccess(null);
+ findJobExecutionEventsRequest.setJobName("test_job_1");
+ result = eventTraceHistoryService.findJobExecutionEvents(findJobExecutionEventsRequest);
+ assertThat(result.getTotalElements(), is(1L));
+ assertThat(result.getContent().size(), is(1));
}
-
+
@Test
public void assertFindJobExecutionEventsWithErrorFields() {
- Map<String, Object> fields = new HashMap<>();
- fields.put("notExistField", "some value");
- Result<JobExecutionEvent> result = repository.findJobExecutionEvents(new Condition(10, 1, null, null, null, null, fields));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ Page<JobExecutionEvent> result = eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
-
+
@Test
public void assertFindJobStatusTraceEventsWithPageSizeAndNumber() {
- Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- result = repository.findJobStatusTraceEvents(new Condition(50, 1, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(50));
- result = repository.findJobStatusTraceEvents(new Condition(100, 5, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(100));
- result = repository.findJobStatusTraceEvents(new Condition(100, 6, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(0));
+ Page<JobStatusTraceEvent> result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, null, null, null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(50, 1, null, null, null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(50));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(100, 5, null, null, null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(100));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(100, 6, null, null, null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(0));
}
-
+
@Test
public void assertFindJobStatusTraceEventsWithErrorPageSizeAndNumber() {
- Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(-1, -1, null, null, null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ Page<JobStatusTraceEvent> result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(-1, -1));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
-
+
@Test
public void assertFindJobStatusTraceEventsWithSort() {
- Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, "jobName", "ASC", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- assertThat(result.getRows().get(0).getJobName(), is("test_job_1"));
- result = repository.findJobStatusTraceEvents(new Condition(10, 1, "jobName", "DESC", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- assertThat(result.getRows().get(0).getJobName(), is("test_job_99"));
+ Page<JobStatusTraceEvent> result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, "jobName", "ASC", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ assertThat(result.getContent().get(0).getJobName(), is("test_job_1"));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, "jobName", "DESC", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ assertThat(result.getContent().get(0).getJobName(), is("test_job_99"));
}
-
+
@Test
public void assertFindJobStatusTraceEventsWithErrorSort() {
- Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, "jobName", "ERROR_SORT", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- assertThat(result.getRows().get(0).getJobName(), is("test_job_1"));
- result = repository.findJobStatusTraceEvents(new Condition(10, 1, "notExistField", "ASC", null, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ Page<JobStatusTraceEvent> result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, "jobName", "ERROR_SORT", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ assertThat(result.getContent().get(0).getJobName(), is("test_job_1"));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, "notExistField", "ASC", null, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
-
+
@Test
public void assertFindJobStatusTraceEventsWithTime() {
Date now = new Date();
Date tenMinutesBefore = new Date(now.getTime() - 10 * 60 * 1000);
- Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, tenMinutesBefore, null, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, now, null, null));
- assertThat(result.getTotal(), is(0L));
- assertThat(result.getRows().size(), is(0));
- result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, tenMinutesBefore, null));
- assertThat(result.getTotal(), is(0L));
- assertThat(result.getRows().size(), is(0));
- result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, now, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
- result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, tenMinutesBefore, now, null));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ Page<JobStatusTraceEvent> result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, null, null, tenMinutesBefore, null));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, null, null, now, null));
+ assertThat(result.getTotalElements(), is(0L));
+ assertThat(result.getContent().size(), is(0));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, null, null, null, tenMinutesBefore));
+ assertThat(result.getTotalElements(), is(0L));
+ assertThat(result.getContent().size(), is(0));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, null, null, null, now));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
+ result = eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1, null, null, tenMinutesBefore, now));
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
-
+
@Test
public void assertFindJobStatusTraceEventsWithFields() {
- Map<String, Object> fields = new HashMap<>();
- fields.put("jobName", "test_job_1");
- Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, null, fields));
- assertThat(result.getTotal(), is(1L));
- assertThat(result.getRows().size(), is(1));
+ FindJobStatusTraceEventsRequest findJobStatusTraceEventsRequest = new FindJobStatusTraceEventsRequest(10, 1);
+ findJobStatusTraceEventsRequest.setJobName("test_job_1");
+ Page<JobStatusTraceEvent> result = eventTraceHistoryService.findJobStatusTraceEvents(findJobStatusTraceEventsRequest);
+ assertThat(result.getTotalElements(), is(1L));
+ assertThat(result.getContent().size(), is(1));
}
-
+
@Test
public void assertFindJobStatusTraceEventsWithErrorFields() {
- Map<String, Object> fields = new HashMap<>();
- fields.put("notExistField", "some value");
- Result<JobStatusTraceEvent> result = repository.findJobStatusTraceEvents(new Condition(10, 1, null, null, null, null, fields));
- assertThat(result.getTotal(), is(500L));
- assertThat(result.getRows().size(), is(10));
+ FindJobStatusTraceEventsRequest findJobStatusTraceEventsRequest = new FindJobStatusTraceEventsRequest(10, 1);
+ Page<JobStatusTraceEvent> result = eventTraceHistoryService.findJobStatusTraceEvents(findJobStatusTraceEventsRequest);
+ assertThat(result.getTotalElements(), is(500L));
+ assertThat(result.getContent().size(), is(10));
}
}
diff --git a/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTestConfiguration.java b/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTestConfiguration.java
index c9dc0f2..2d23be1 100644
--- a/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTestConfiguration.java
+++ b/elastic-job-lite-console/src/test/java/org/apache/shardingsphere/elasticjob/lite/console/dao/search/RDBJobEventSearchTestConfiguration.java
@@ -17,6 +17,11 @@
package org.apache.shardingsphere.elasticjob.lite.console.dao.search;
+import java.sql.SQLException;
+import javax.sql.DataSource;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobExecutionEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.dto.request.FindJobStatusTraceEventsRequest;
+import org.apache.shardingsphere.elasticjob.lite.console.service.EventTraceHistoryService;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobExecutionEvent;
import org.apache.shardingsphere.elasticjob.lite.tracing.event.JobStatusTraceEvent;
import org.apache.shardingsphere.elasticjob.lite.tracing.rdb.storage.RDBJobEventStorage;
@@ -24,26 +29,23 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.TestConfiguration;
-import javax.sql.DataSource;
-import java.sql.SQLException;
-
@TestConfiguration
public class RDBJobEventSearchTestConfiguration implements InitializingBean {
-
+
@Autowired
- private RDBJobEventSearch repository;
-
+ private EventTraceHistoryService eventTraceHistoryService;
+
@Autowired
private DataSource dataSource;
-
+
@Override
public void afterPropertiesSet() throws Exception {
initStorage();
}
-
+
private void initStorage() throws SQLException {
- repository.findJobExecutionEvents(new RDBJobEventSearch.Condition(10, 1, null, null, null, null, null));
- repository.findJobStatusTraceEvents(new RDBJobEventSearch.Condition(10, 1, null, null, null, null, null));
+ eventTraceHistoryService.findJobExecutionEvents(new FindJobExecutionEventsRequest(10, 1));
+ eventTraceHistoryService.findJobStatusTraceEvents(new FindJobStatusTraceEventsRequest(10, 1));
RDBJobEventStorage storage = new RDBJobEventStorage(dataSource);
for (int i = 1; i <= 500L; i++) {
JobExecutionEvent startEvent = new JobExecutionEvent("localhost", "127.0.0.1", "fake_task_id", "test_job_" + i, JobExecutionEvent.ExecutionSource.NORMAL_TRIGGER, 0);