Skip to content

Commit f852863

Browse files
committed
minor, add option to listAllCubingJobs precisely cont.
1 parent 242b331 commit f852863

File tree

4 files changed

+46
-83
lines changed

4 files changed

+46
-83
lines changed

server-base/src/main/java/org/apache/kylin/rest/controller/JobController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public List<JobInstance> list(JobListRequest jobRequest) {
7070
JobTimeFilterEnum timeFilter = JobTimeFilterEnum.getByCode(jobRequest.getTimeFilter());
7171

7272
try {
73-
jobInstanceList = jobService.listAllJobs(jobRequest.getCubeName(), jobRequest.getProjectName(), statusList, jobRequest.getLimit(), jobRequest.getOffset(), timeFilter);
73+
jobInstanceList = jobService.searchJobs(jobRequest.getCubeName(), jobRequest.getProjectName(), statusList, jobRequest.getLimit(), jobRequest.getOffset(), timeFilter);
7474
} catch (Exception e) {
7575
logger.error(e.getLocalizedMessage(), e);
7676
throw new InternalErrorException(e);

server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private boolean isCubeInProject(String projectName, CubeInstance target) {
218218
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')")
219219
public CubeDesc updateCubeAndDesc(CubeInstance cube, CubeDesc desc, String newProjectName, boolean forceUpdate) throws IOException, JobException {
220220

221-
final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING), true);
221+
final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING));
222222
if (!cubingJobs.isEmpty()) {
223223
throw new JobException("Cube schema shouldn't be changed with running job.");
224224
}
@@ -248,7 +248,7 @@ public CubeDesc updateCubeAndDesc(CubeInstance cube, CubeDesc desc, String newPr
248248

249249
@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')")
250250
public void deleteCube(CubeInstance cube) throws IOException, JobException {
251-
final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING, ExecutableState.ERROR), true);
251+
final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING, ExecutableState.ERROR));
252252
if (!cubingJobs.isEmpty()) {
253253
throw new JobException("The cube " + cube.getName() + " has running or failed job, please discard it and try again.");
254254
}
@@ -340,7 +340,7 @@ public CubeInstance enableCube(CubeInstance cube) throws IOException, JobExcepti
340340
throw new InternalErrorException("Cube " + cubeName + " doesn't contain any READY segment");
341341
}
342342

343-
final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING), true);
343+
final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING));
344344
if (!cubingJobs.isEmpty()) {
345345
throw new JobException("Enable is not allowed with a running job.");
346346
}

server-base/src/main/java/org/apache/kylin/rest/service/JobService.java

+40-78
Original file line numberDiff line numberDiff line change
@@ -138,74 +138,6 @@ public void run() {
138138
}));
139139
}
140140

141-
public List<JobInstance> listAllJobs(final String cubeName, final String projectName, final List<JobStatusEnum> statusList, final Integer limitValue, final Integer offsetValue, final JobTimeFilterEnum timeFilter) throws IOException, JobException {
142-
Integer limit = (null == limitValue) ? 30 : limitValue;
143-
Integer offset = (null == offsetValue) ? 0 : offsetValue;
144-
List<JobInstance> jobs = listAllJobs(cubeName, projectName, statusList, timeFilter);
145-
Collections.sort(jobs);
146-
147-
if (jobs.size() <= offset) {
148-
return Collections.emptyList();
149-
}
150-
151-
if ((jobs.size() - offset) < limit) {
152-
return jobs.subList(offset, jobs.size());
153-
}
154-
155-
return jobs.subList(offset, offset + limit);
156-
}
157-
158-
public List<JobInstance> listAllJobs(final String cubeName, final String projectName, final List<JobStatusEnum> statusList, final JobTimeFilterEnum timeFilter) {
159-
Calendar calendar = Calendar.getInstance();
160-
calendar.setTime(new Date());
161-
long timeStartInMillis = getTimeStartInMillis(calendar, timeFilter);
162-
return listCubeJobInstance(cubeName, projectName, statusList, timeStartInMillis, Long.MAX_VALUE);
163-
}
164-
165-
@Deprecated
166-
public List<JobInstance> listAllJobs(final String cubeName, final String projectName, final List<JobStatusEnum> statusList, final Integer limitValue, final Integer offsetValue) throws IOException, JobException {
167-
Integer limit = (null == limitValue) ? 30 : limitValue;
168-
Integer offset = (null == offsetValue) ? 0 : offsetValue;
169-
List<JobInstance> jobs = listAllJobs(cubeName, projectName, statusList);
170-
Collections.sort(jobs);
171-
172-
if (jobs.size() <= offset) {
173-
return Collections.emptyList();
174-
}
175-
176-
if ((jobs.size() - offset) < limit) {
177-
return jobs.subList(offset, jobs.size());
178-
}
179-
180-
return jobs.subList(offset, offset + limit);
181-
}
182-
183-
public List<JobInstance> listAllJobs(final String cubeName, final String projectName, final List<JobStatusEnum> statusList) {
184-
return listCubeJobInstance(cubeName, projectName, statusList);
185-
}
186-
187-
private List<JobInstance> listCubeJobInstance(final String cubeName, final String projectName, List<JobStatusEnum> statusList, final long timeStartInMillis, final long timeEndInMillis) {
188-
Set<ExecutableState> states = convertStatusEnumToStates(statusList);
189-
final Map<String, Output> allOutputs = getExecutableManager().getAllOutputs(timeStartInMillis, timeEndInMillis);
190-
return Lists.newArrayList(FluentIterable.from(listAllCubingJobs(cubeName, projectName, states, timeStartInMillis, timeEndInMillis, allOutputs, false)).transform(new Function<CubingJob, JobInstance>() {
191-
@Override
192-
public JobInstance apply(CubingJob cubingJob) {
193-
return parseToJobInstance(cubingJob, allOutputs);
194-
}
195-
}));
196-
}
197-
198-
private List<JobInstance> listCubeJobInstance(final String cubeName, final String projectName, List<JobStatusEnum> statusList) {
199-
Set<ExecutableState> states = convertStatusEnumToStates(statusList);
200-
final Map<String, Output> allOutputs = getExecutableManager().getAllOutputs();
201-
return Lists.newArrayList(FluentIterable.from(listAllCubingJobs(cubeName, projectName, states, allOutputs, false)).transform(new Function<CubingJob, JobInstance>() {
202-
@Override
203-
public JobInstance apply(CubingJob cubingJob) {
204-
return parseToJobInstance(cubingJob, allOutputs);
205-
}
206-
}));
207-
}
208-
209141
private Set<ExecutableState> convertStatusEnumToStates(List<JobStatusEnum> statusList) {
210142
Set<ExecutableState> states;
211143
if (statusList == null || statusList.isEmpty()) {
@@ -484,11 +416,44 @@ public JobInstance pauseJob(JobInstance job) throws IOException, JobException {
484416
return job;
485417
}
486418

487-
public List<CubingJob> listAllCubingJobs(final String cubeName, final String projectName, final Set<ExecutableState> statusList, final Map<String, Output> allOutputs, final boolean bEqual) {
488-
return listAllCubingJobs(cubeName, projectName, statusList, 0L, Long.MAX_VALUE, allOutputs, bEqual);
419+
/**
420+
* currently only support substring match
421+
* @return
422+
*/
423+
public List<JobInstance> searchJobs(final String cubeNameSubstring, final String projectName, final List<JobStatusEnum> statusList, final Integer limitValue, final Integer offsetValue, final JobTimeFilterEnum timeFilter) throws IOException, JobException {
424+
Integer limit = (null == limitValue) ? 30 : limitValue;
425+
Integer offset = (null == offsetValue) ? 0 : offsetValue;
426+
List<JobInstance> jobs = searchJobs(cubeNameSubstring, projectName, statusList, timeFilter);
427+
Collections.sort(jobs);
428+
429+
if (jobs.size() <= offset) {
430+
return Collections.emptyList();
431+
}
432+
433+
if ((jobs.size() - offset) < limit) {
434+
return jobs.subList(offset, jobs.size());
435+
}
436+
437+
return jobs.subList(offset, offset + limit);
438+
}
439+
440+
private List<JobInstance> searchJobs(final String cubeNameSubstring, final String projectName, final List<JobStatusEnum> statusList, final JobTimeFilterEnum timeFilter) {
441+
Calendar calendar = Calendar.getInstance();
442+
calendar.setTime(new Date());
443+
long timeStartInMillis = getTimeStartInMillis(calendar, timeFilter);
444+
445+
long timeEndInMillis = Long.MAX_VALUE;
446+
Set<ExecutableState> states = convertStatusEnumToStates(statusList);
447+
final Map<String, Output> allOutputs = getExecutableManager().getAllOutputs(timeStartInMillis, timeEndInMillis);
448+
return Lists.newArrayList(FluentIterable.from(searchCubingJobs(cubeNameSubstring, projectName, states, timeStartInMillis, timeEndInMillis, allOutputs, false)).transform(new Function<CubingJob, JobInstance>() {
449+
@Override
450+
public JobInstance apply(CubingJob cubingJob) {
451+
return parseToJobInstance(cubingJob, allOutputs);
452+
}
453+
}));
489454
}
490455

491-
public List<CubingJob> listAllCubingJobs(final String cubeName, final String projectName, final Set<ExecutableState> statusList, long timeStartInMillis, long timeEndInMillis, final Map<String, Output> allOutputs, final boolean bEqual) {
456+
public List<CubingJob> searchCubingJobs(final String cubeName, final String projectName, final Set<ExecutableState> statusList, long timeStartInMillis, long timeEndInMillis, final Map<String, Output> allOutputs, final boolean cubeNameExactMatch) {
492457
List<CubingJob> results = Lists.newArrayList(FluentIterable.from(getExecutableManager().getAllAbstractExecutables(timeStartInMillis, timeEndInMillis, CubingJob.class)).filter(new Predicate<AbstractExecutable>() {
493458
@Override
494459
public boolean apply(AbstractExecutable executable) {
@@ -499,7 +464,7 @@ public boolean apply(AbstractExecutable executable) {
499464
String executableCubeName = CubingExecutableUtil.getCubeName(executable.getParams());
500465
if (executableCubeName == null)
501466
return true;
502-
if (bEqual)
467+
if (cubeNameExactMatch)
503468
return executableCubeName.equalsIgnoreCase(cubeName);
504469
else
505470
return executableCubeName.contains(cubeName);
@@ -537,15 +502,12 @@ public boolean apply(CubingJob executable) {
537502
return results;
538503
}
539504

540-
public List<CubingJob> listAllCubingJobs(final String cubeName, final String projectName, final Set<ExecutableState> statusList, final boolean bEqual) {
541-
return listAllCubingJobs(cubeName, projectName, statusList, getExecutableManager().getAllOutputs(), bEqual);
542-
}
543-
544505
public List<CubingJob> listAllCubingJobs(final String cubeName, final String projectName, final Set<ExecutableState> statusList) {
545-
return listAllCubingJobs(cubeName, projectName, statusList, getExecutableManager().getAllOutputs(), false);
506+
return searchCubingJobs(cubeName, projectName, statusList, 0L, Long.MAX_VALUE, getExecutableManager().getAllOutputs(), true);
546507
}
547508

548509
public List<CubingJob> listAllCubingJobs(final String cubeName, final String projectName) {
549-
return listAllCubingJobs(cubeName, projectName, EnumSet.allOf(ExecutableState.class), getExecutableManager().getAllOutputs(), false);
510+
return searchCubingJobs(cubeName, projectName, EnumSet.allOf(ExecutableState.class), 0L, Long.MAX_VALUE, getExecutableManager().getAllOutputs(), true);
550511
}
512+
551513
}

server/src/test/java/org/apache/kylin/rest/service/JobServiceTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.IOException;
2222

23+
import org.apache.kylin.job.constant.JobTimeFilterEnum;
2324
import org.apache.kylin.job.exception.JobException;
2425
import org.apache.kylin.metadata.project.ProjectInstance;
2526
import org.junit.Assert;
@@ -44,6 +45,6 @@ public void testBasics() throws JobException, IOException {
4445
Assert.assertNotNull(jobService.getMetadataManager());
4546
Assert.assertNotNull(cacheService.getOLAPDataSource(ProjectInstance.DEFAULT_PROJECT_NAME));
4647
Assert.assertNull(jobService.getJobInstance("job_not_exist"));
47-
Assert.assertNotNull(jobService.listAllJobs(null, null, null));
48+
Assert.assertNotNull(jobService.searchJobs(null, null, null, 0, 0, JobTimeFilterEnum.ALL));
4849
}
4950
}

0 commit comments

Comments
 (0)