minor, enable job page search by job name
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/61825893 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/61825893 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/61825893 Branch: refs/heads/master Commit: 6182589362b0675db28fa494a0664efd4942e6c3 Parents: 1c3329a Author: Roger Shi <[email protected]> Authored: Fri Jun 16 17:28:27 2017 +0800 Committer: Hongbin Ma <[email protected]> Committed: Fri Jun 16 18:08:41 2017 +0800 ---------------------------------------------------------------------- .../kylin/rest/controller/JobController.java | 9 ++- .../kylin/rest/controller2/JobControllerV2.java | 6 +- .../apache/kylin/rest/service/CubeService.java | 8 +-- .../apache/kylin/rest/service/JobService.java | 60 +++++++++++++++----- 4 files changed, 58 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/61825893/server-base/src/main/java/org/apache/kylin/rest/controller/JobController.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller/JobController.java b/server-base/src/main/java/org/apache/kylin/rest/controller/JobController.java index 7c9c40d..749c872 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/controller/JobController.java +++ b/server-base/src/main/java/org/apache/kylin/rest/controller/JobController.java @@ -72,7 +72,8 @@ public class JobController extends BasicController { JobTimeFilterEnum timeFilter = JobTimeFilterEnum.getByCode(jobRequest.getTimeFilter()); try { - jobInstanceList = jobService.searchJobs(jobRequest.getCubeName(), jobRequest.getProjectName(), statusList, jobRequest.getLimit(), jobRequest.getOffset(), timeFilter); + jobInstanceList = jobService.searchJobs(jobRequest.getCubeName(), jobRequest.getProjectName(), statusList, + jobRequest.getLimit(), jobRequest.getOffset(), timeFilter); } catch (Exception e) { logger.error(e.getLocalizedMessage(), e); throw new InternalErrorException(e); @@ -106,7 +107,8 @@ public class JobController extends BasicController { * @return * @throws IOException */ - @RequestMapping(value = "/{jobId}/steps/{stepId}/output", method = { RequestMethod.GET }, produces = { "application/json" }) + @RequestMapping(value = "/{jobId}/steps/{stepId}/output", method = { RequestMethod.GET }, produces = { + "application/json" }) @ResponseBody public Map<String, String> getStepOutput(@PathVariable String jobId, @PathVariable String stepId) { Map<String, String> result = new HashMap<String, String>(); @@ -180,7 +182,8 @@ public class JobController extends BasicController { * @return * @throws IOException */ - @RequestMapping(value = "/{jobId}/steps/{stepId}/rollback", method = { RequestMethod.PUT }, produces = { "application/json" }) + @RequestMapping(value = "/{jobId}/steps/{stepId}/rollback", method = { RequestMethod.PUT }, produces = { + "application/json" }) @ResponseBody public JobInstance rollback(@PathVariable String jobId, @PathVariable String stepId) { try { http://git-wip-us.apache.org/repos/asf/kylin/blob/61825893/server-base/src/main/java/org/apache/kylin/rest/controller2/JobControllerV2.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/JobControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/JobControllerV2.java index 5554852..f9db6d8 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/controller2/JobControllerV2.java +++ b/server-base/src/main/java/org/apache/kylin/rest/controller2/JobControllerV2.java @@ -107,8 +107,8 @@ public class JobControllerV2 extends BasicController { @RequestMapping(value = "", method = { RequestMethod.GET }, produces = { "application/vnd.apache.kylin-v2+json" }) @ResponseBody public EnvelopeResponse listV2(@RequestParam(value = "status", required = false) Integer[] status, // - @RequestParam(value = "timeFilter", required = true) Integer timeFilter, // - @RequestParam(value = "cubeName", required = false) String cubeName, // + @RequestParam(value = "timeFilter") Integer timeFilter, // + @RequestParam(value = "jobName", required = false) String jobName, // @RequestParam(value = "projectName", required = false) String projectName, // @RequestParam(value = "pageOffset", required = false, defaultValue = "0") Integer pageOffset, // @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize, // @@ -124,7 +124,7 @@ public class JobControllerV2 extends BasicController { } } - List<JobInstance> jobInstanceList = jobService.searchJobs(cubeName, projectName, statusList, + List<JobInstance> jobInstanceList = jobService.searchJobsByJobName(jobName, projectName, statusList, JobTimeFilterEnum.getByCode(timeFilter)); if (sortby.equals("last_modify")) { http://git-wip-us.apache.org/repos/asf/kylin/blob/61825893/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java index 74d8578..7f09612 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java @@ -234,7 +234,7 @@ public class CubeService extends BasicService { throws IOException { Message msg = MsgPicker.getMsg(); - final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, + final List<CubingJob> cubingJobs = jobService.listJobsByRealizationName(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING)); if (!cubingJobs.isEmpty()) { throw new BadRequestException(String.format(msg.getDISCARD_JOB_FIRST(), cube.getName())); @@ -266,7 +266,7 @@ public class CubeService extends BasicService { public void deleteCube(CubeInstance cube) throws IOException { Message msg = MsgPicker.getMsg(); - final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, + final List<CubingJob> cubingJobs = jobService.listJobsByRealizationName(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING, ExecutableState.ERROR)); if (!cubingJobs.isEmpty()) { throw new BadRequestException(String.format(msg.getDISCARD_JOB_FIRST(), cube.getName())); @@ -361,7 +361,7 @@ public class CubeService extends BasicService { throw new BadRequestException(String.format(msg.getNO_READY_SEGMENT(), cubeName)); } - final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, + final List<CubingJob> cubingJobs = jobService.listJobsByRealizationName(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING)); if (!cubingJobs.isEmpty()) { throw new BadRequestException(msg.getENABLE_WITH_RUNNING_JOB()); @@ -482,7 +482,7 @@ public class CubeService extends BasicService { } protected void releaseAllJobs(CubeInstance cube) { - final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null); + final List<CubingJob> cubingJobs = jobService.listJobsByRealizationName(cube.getName(), null); for (CubingJob cubingJob : cubingJobs) { final ExecutableState status = cubingJob.getStatus(); if (status != ExecutableState.SUCCEED && status != ExecutableState.DISCARDED) { http://git-wip-us.apache.org/repos/asf/kylin/blob/61825893/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java b/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java index 3db7fb6..7eb1292 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java @@ -28,7 +28,10 @@ import java.util.Map; import java.util.Set; import java.util.TimeZone; +import javax.annotation.Nullable; + import org.apache.commons.lang3.StringUtils; +import org.apache.directory.api.util.Strings; import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.util.ClassUtil; import org.apache.kylin.cube.CubeInstance; @@ -368,7 +371,7 @@ public class JobService extends BasicService implements InitializingBean { final JobTimeFilterEnum timeFilter) { Integer limit = (null == limitValue) ? 30 : limitValue; Integer offset = (null == offsetValue) ? 0 : offsetValue; - List<JobInstance> jobs = searchJobs(cubeNameSubstring, projectName, statusList, timeFilter); + List<JobInstance> jobs = searchJobsByCubeName(cubeNameSubstring, projectName, statusList, timeFilter); Collections.sort(jobs); if (jobs.size() <= offset) { @@ -382,20 +385,31 @@ public class JobService extends BasicService implements InitializingBean { return jobs.subList(offset, offset + limit); } - public List<JobInstance> searchJobs(final String cubeNameSubstring, final String projectName, + public List<JobInstance> searchJobsByCubeName(final String cubeNameSubstring, final String projectName, + final List<JobStatusEnum> statusList, final JobTimeFilterEnum timeFilter) { + return innerSearchCubingJobs(cubeNameSubstring, null, projectName, statusList, timeFilter); + } + + public List<JobInstance> searchJobsByJobName(final String jobName, final String projectName, final List<JobStatusEnum> statusList, final JobTimeFilterEnum timeFilter) { + return innerSearchCubingJobs(null, jobName, projectName, statusList, timeFilter); + } + + public List<JobInstance> innerSearchCubingJobs(final String cubeName, final String jobName, + final String projectName, final List<JobStatusEnum> statusList, final JobTimeFilterEnum timeFilter) { + // prepare time range Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); long timeStartInMillis = getTimeStartInMillis(calendar, timeFilter); - long timeEndInMillis = Long.MAX_VALUE; Set<ExecutableState> states = convertStatusEnumToStates(statusList); final Map<String, Output> allOutputs = getExecutableManager().getAllOutputs(timeStartInMillis, timeEndInMillis); + return Lists .newArrayList( FluentIterable - .from(searchCubingJobs(cubeNameSubstring, projectName, states, timeStartInMillis, - timeEndInMillis, allOutputs, false)) + .from(innerSearchCubingJobs(cubeName, jobName, states, timeStartInMillis, + timeEndInMillis, allOutputs, false, projectName)) .transform(new Function<CubingJob, JobInstance>() { @Override public JobInstance apply(CubingJob cubingJob) { @@ -404,9 +418,9 @@ public class JobService extends BasicService implements InitializingBean { })); } - public List<CubingJob> searchCubingJobs(final String cubeName, final String projectName, + public List<CubingJob> innerSearchCubingJobs(final String cubeName, final String jobName, final Set<ExecutableState> statusList, long timeStartInMillis, long timeEndInMillis, - final Map<String, Output> allOutputs, final boolean cubeNameExactMatch) { + final Map<String, Output> allOutputs, final boolean nameExactMatch, final String projectName) { List<CubingJob> results = Lists.newArrayList(FluentIterable.from( getExecutableManager().getAllAbstractExecutables(timeStartInMillis, timeEndInMillis, CubingJob.class)) .filter(new Predicate<AbstractExecutable>() { @@ -419,8 +433,8 @@ public class JobService extends BasicService implements InitializingBean { String executableCubeName = CubingExecutableUtil.getCubeName(executable.getParams()); if (executableCubeName == null) return true; - if (cubeNameExactMatch) - return executableCubeName.equalsIgnoreCase(cubeName); + if (nameExactMatch) + return executableCubeName.toLowerCase().equals(cubeName); else return executableCubeName.toLowerCase().contains(cubeName.toLowerCase()); } else { @@ -453,19 +467,35 @@ public class JobService extends BasicService implements InitializingBean { throw e; } } + }, new Predicate<CubingJob>() { + @Override + public boolean apply(@Nullable CubingJob cubeJob) { + if (cubeJob == null) { + return false; + } + + if (Strings.isEmpty(jobName)) { + return true; + } + + if (nameExactMatch) { + return cubeJob.getName().toLowerCase().equals(jobName); + } else { + return cubeJob.getName().toLowerCase().contains(jobName); + } + } }))); return results; } - public List<CubingJob> listAllCubingJobs(final String cubeName, final String projectName, + public List<CubingJob> listJobsByRealizationName(final String realizationName, final String projectName, final Set<ExecutableState> statusList) { - return searchCubingJobs(cubeName, projectName, statusList, 0L, Long.MAX_VALUE, - getExecutableManager().getAllOutputs(), true); + return innerSearchCubingJobs(realizationName, null, statusList, 0L, Long.MAX_VALUE, + getExecutableManager().getAllOutputs(), true, projectName); } - public List<CubingJob> listAllCubingJobs(final String cubeName, final String projectName) { - return searchCubingJobs(cubeName, projectName, EnumSet.allOf(ExecutableState.class), 0L, Long.MAX_VALUE, - getExecutableManager().getAllOutputs(), true); + public List<CubingJob> listJobsByRealizationName(final String realizationName, final String projectName) { + return listJobsByRealizationName(realizationName, projectName, EnumSet.allOf(ExecutableState.class)); } }
