org.apache.kylin.job.execution.AbstractExecutable Java Examples

The following examples show how to use org.apache.kylin.job.execution.AbstractExecutable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Coordinator.java    From kylin with Apache License 2.0 6 votes vote down vote up
private boolean isInOptimize(CubeInstance cube) {
    Segments<CubeSegment> readyPendingSegments = cube.getSegments(SegmentStatusEnum.READY_PENDING);
    if (readyPendingSegments.size() > 0) {
        logger.info("The cube {} has READY_PENDING segments {}. It's not allowed for building", cube.getName(),
                readyPendingSegments);
        return true;
    }
    Segments<CubeSegment> newSegments = cube.getSegments(SegmentStatusEnum.NEW);
    for (CubeSegment newSegment : newSegments) {
        String jobId = newSegment.getLastBuildJobID();
        if (jobId == null) {
            continue;
        }
        AbstractExecutable job = getExecutableManager().getJob(jobId);
        if (job != null && job instanceof CubingJob) {
            CubingJob cubingJob = (CubingJob) job;
            if (CubingJob.CubingJobTypeEnum.OPTIMIZE.toString().equals(cubingJob.getJobType())) {
                logger.info(
                        "The cube {} is in optimization. It's not allowed to build new segments during optimization.",
                        cube.getName());
                return true;
            }
        }
    }
    return false;
}
 
Example #2
Source File: JdbcHiveMRInputTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenSqoopCmd_WithLookupShardBy() throws IOException {
    ISource source = SourceManager.getSource(new JdbcSourceAware());
    IMRInput input = source.adaptToBuildEngine(IMRInput.class);
    Assert.assertNotNull(input);

    CubeManager cubeManager = CubeManager.getInstance(getTestConfig());
    CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("ut_jdbc_shard");
    CubeSegment seg = cubeManager.appendSegment(cubeManager.getCube(cubeDesc.getName()),
            new SegmentRange.TSRange(System.currentTimeMillis() - 100L, System.currentTimeMillis() + 100L));
    CubeJoinedFlatTableDesc flatDesc = new CubeJoinedFlatTableDesc(seg);
    JdbcHiveMRInput.JdbcMRBatchCubingInputSide inputSide = (JdbcHiveMRInput.JdbcMRBatchCubingInputSide) input
            .getBatchCubingInputSide(flatDesc);

    AbstractExecutable executable = new MockInputSide(flatDesc, inputSide).createSqoopToFlatHiveStep("/tmp",
            cubeDesc.getName());
    Assert.assertNotNull(executable);

    String cmd = executable.getParam("cmd");
    Assert.assertTrue(cmd.contains("org.h2.Driver"));
    Assert.assertTrue(cmd.contains(
            "--boundary-query \"SELECT MIN(\\\"TEST_CATEGORY_GROUPINGS\\\".\\\"META_CATEG_NAME\\\"), MAX(\\\"TEST_CATEGORY_GROUPINGS\\\".\\\"META_CATEG_NAME\\\")" + System.lineSeparator()
                    + "FROM \\\"DEFAULT\\\".\\\"TEST_CATEGORY_GROUPINGS\\\" AS \\\"TEST_CATEGORY_GROUPINGS\\\"\""));

    source.close();
}
 
Example #3
Source File: AbstractJobBuilder.java    From Kylin with Apache License 2.0 6 votes vote down vote up
protected AbstractExecutable createIntermediateHiveTableStep(IJoinedFlatTableDesc intermediateTableDesc, String jobId) {

        final String dropTableHql = JoinedFlatTable.generateDropTableStatement(intermediateTableDesc, jobId);
        final String createTableHql = JoinedFlatTable.generateCreateTableStatement(intermediateTableDesc, getJobWorkingDir(jobId), jobId);
        String insertDataHqls;
        try {
            insertDataHqls = JoinedFlatTable.generateInsertDataStatement(intermediateTableDesc, jobId, this.engineConfig);
        } catch (IOException e1) {
            e1.printStackTrace();
            throw new RuntimeException("Failed to generate insert data SQL for intermediate table.");
        }

        ShellExecutable step = new ShellExecutable();
        StringBuffer buf = new StringBuffer();
        buf.append("hive -e \"");
        buf.append(dropTableHql + "\n");
        buf.append(createTableHql + "\n");
        buf.append(insertDataHqls + "\n");
        buf.append("\"");

        step.setCmd(buf.toString());
        step.setName(ExecutableConstants.STEP_NAME_CREATE_FLAT_HIVE_TABLE);

        return step;
    }
 
Example #4
Source File: JobInstanceExtractor.java    From kylin with Apache License 2.0 6 votes vote down vote up
private List<JobInstance> listJobInstances(String project, String cube, long startTime, long endTime) {
    final List<JobInstance> result = Lists.newArrayList();
    final List<AbstractExecutable> executables = executableManager.getAllExecutables(startTime, endTime);
    final Map<String, Output> allOutputs = executableManager.getAllOutputs();
    for (AbstractExecutable executable : executables) {
        if (executable instanceof CubingJob) {
            String cubeName = CubingExecutableUtil.getCubeName(executable.getParams());
            boolean shouldExtract = false;
            if (cube == null || cube.equalsIgnoreCase(cubeName)) {
                if (project == null) {
                    shouldExtract = true;
                } else {
                    ProjectInstance projectInstance = projectManager.getProject(project);
                    if (projectInstance != null && projectInstance.containsRealization(RealizationType.CUBE, cubeName)) {
                        shouldExtract = true;
                    }
                }
            }

            if (shouldExtract) {
                result.add(parseToJobInstance((CubingJob) executable, allOutputs));
            }
        }
    }
    return result;
}
 
Example #5
Source File: BuildCubeWithEngine.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public void before() throws Exception {
    deployEnv();

    final KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    jobService = ExecutableManager.getInstance(kylinConfig);
    scheduler = DefaultScheduler.createInstance();
    scheduler.init(new JobEngineConfig(kylinConfig), new ZookeeperJobLock());
    if (!scheduler.hasStarted()) {
        throw new RuntimeException("scheduler has not been started");
    }
    cubeManager = CubeManager.getInstance(kylinConfig);
    for (String jobId : jobService.getAllJobIds()) {
        AbstractExecutable executable = jobService.getJob(jobId);
        if (executable instanceof CubingJob || executable instanceof CheckpointExecutable) {
            jobService.deleteJob(jobId);
        }
    }

    cubeDescManager = CubeDescManager.getInstance(kylinConfig);

    // update enginType
    updateCubeEngineType(Lists.newArrayList("ci_inner_join_cube", "ci_left_join_cube"));
}
 
Example #6
Source File: HBaseMRSteps.java    From kylin with Apache License 2.0 6 votes vote down vote up
public AbstractExecutable createConvertCuboidToHfileStep(String jobId) {
    String cuboidRootPath = getCuboidRootPath(jobId);
    String inputPath = cuboidRootPath + (cuboidRootPath.endsWith("/") ? "" : "/") + "*";

    MapReduceExecutable createHFilesStep = new MapReduceExecutable();
    createHFilesStep.setName(ExecutableConstants.STEP_NAME_CONVERT_CUBOID_TO_HFILE);
    StringBuilder cmd = new StringBuilder();

    appendMapReduceParameters(cmd);
    appendExecCmdParameters(cmd, BatchConstants.ARG_CUBE_NAME, seg.getRealization().getName());
    appendExecCmdParameters(cmd, BatchConstants.ARG_PARTITION, getRowkeyDistributionOutputPath(jobId) + "/part-r-00000_hfile");
    appendExecCmdParameters(cmd, BatchConstants.ARG_INPUT, inputPath);
    appendExecCmdParameters(cmd, BatchConstants.ARG_OUTPUT, getHFilePath(jobId));
    appendExecCmdParameters(cmd, BatchConstants.ARG_HTABLE_NAME, seg.getStorageLocationIdentifier());
    appendExecCmdParameters(cmd, BatchConstants.ARG_JOB_NAME, "Kylin_HFile_Generator_" + seg.getRealization().getName() + "_Step");

    createHFilesStep.setMapReduceParams(cmd.toString());
    createHFilesStep.setMapReduceJobClass(CubeHFileJob.class);
    createHFilesStep.setCounterSaveAs(",," + CubingJob.CUBE_SIZE_BYTES);

    return createHFilesStep;
}
 
Example #7
Source File: JobService.java    From Kylin with Apache License 2.0 6 votes vote down vote up
private JobInstance.JobStep parseToJobStep(AbstractExecutable task, int i) {
    JobInstance.JobStep result = new JobInstance.JobStep();
    result.setId(task.getId());
    result.setName(task.getName());
    result.setSequenceID(i);
    result.setStatus(parseToJobStepStatus(task.getStatus()));
    final Output output = getExecutableManager().getOutput(task.getId());
    for (Map.Entry<String, String> entry : output.getExtra().entrySet()) {
        if (entry.getKey() != null && entry.getValue() != null) {
            result.putInfo(entry.getKey(), entry.getValue());
        }
    }
    result.setExecStartTime(task.getStartTime());
    result.setExecEndTime(task.getEndTime());
    if (task instanceof ShellExecutable) {
        result.setExecCmd(((ShellExecutable) task).getCmd());
    }
    if (task instanceof MapReduceExecutable) {
        result.setExecCmd(((MapReduceExecutable) task).getMapReduceParams());
        result.setExecWaitTime(((MapReduceExecutable) task).getMapReduceWaitTime() / 1000);
    }
    if (task instanceof HadoopShellExecutable) {
        result.setExecCmd(((HadoopShellExecutable) task).getJobParams());
    }
    return result;
}
 
Example #8
Source File: ExecutableManager.java    From Kylin with Apache License 2.0 6 votes vote down vote up
public void resumeJob(String jobId) {
    AbstractExecutable job = getJob(jobId);
    if (job == null) {
        return;
    }
    updateJobOutput(jobId, ExecutableState.READY, null, null);
    if (job instanceof DefaultChainedExecutable) {
        List<AbstractExecutable> tasks = ((DefaultChainedExecutable) job).getTasks();
        for (AbstractExecutable task : tasks) {
            if (task.getStatus() == ExecutableState.ERROR) {
                updateJobOutput(task.getId(), ExecutableState.READY, null, null);
                break;
            }
        }
    }
}
 
Example #9
Source File: HBaseMRSteps.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public AbstractExecutable createConvertCuboidToHfileStep(String jobId) {
    String cuboidRootPath = getCuboidRootPath(jobId);
    String inputPath = cuboidRootPath + (cuboidRootPath.endsWith("/") ? "" : "/") + "*";

    MapReduceExecutable createHFilesStep = new MapReduceExecutable();
    createHFilesStep.setName(ExecutableConstants.STEP_NAME_CONVERT_CUBOID_TO_HFILE);
    StringBuilder cmd = new StringBuilder();

    appendMapReduceParameters(cmd);
    appendExecCmdParameters(cmd, BatchConstants.ARG_CUBE_NAME, seg.getRealization().getName());
    appendExecCmdParameters(cmd, BatchConstants.ARG_PARTITION, getRowkeyDistributionOutputPath(jobId) + "/part-r-00000_hfile");
    appendExecCmdParameters(cmd, BatchConstants.ARG_INPUT, inputPath);
    appendExecCmdParameters(cmd, BatchConstants.ARG_OUTPUT, getHFilePath(jobId));
    appendExecCmdParameters(cmd, BatchConstants.ARG_HTABLE_NAME, seg.getStorageLocationIdentifier());
    appendExecCmdParameters(cmd, BatchConstants.ARG_JOB_NAME, "Kylin_HFile_Generator_" + seg.getRealization().getName() + "_Step");

    createHFilesStep.setMapReduceParams(cmd.toString());
    createHFilesStep.setMapReduceJobClass(CubeHFileJob.class);
    createHFilesStep.setCounterSaveAs(",," + CubingJob.CUBE_SIZE_BYTES);

    return createHFilesStep;
}
 
Example #10
Source File: BuildJobSubmitter.java    From kylin with Apache License 2.0 6 votes vote down vote up
private boolean isInOptimize(CubeInstance cube) {
    Segments<CubeSegment> readyPendingSegments = cube.getSegments(SegmentStatusEnum.READY_PENDING);
    if (readyPendingSegments.size() > 0) {
        logger.info("The cube {} has READY_PENDING segments {}. It's not allowed for building",
            cube.getName(), readyPendingSegments);
        return true;
    }
    Segments<CubeSegment> newSegments = cube.getSegments(SegmentStatusEnum.NEW);
    for (CubeSegment newSegment : newSegments) {
        String jobId = newSegment.getLastBuildJobID();
        if (jobId == null) {
            continue;
        }
        AbstractExecutable job = coordinator.getExecutableManager().getJob(jobId);
        if (job != null && job instanceof CubingJob) {
            CubingJob cubingJob = (CubingJob) job;
            if (CubingJob.CubingJobTypeEnum.OPTIMIZE.toString().equals(cubingJob.getJobType())) {
                logger.info("The cube {} is in optimization. It's not allowed to build new segments during optimization.", cube.getName());
                return true;
            }
        }
    }
    return false;
}
 
Example #11
Source File: BuildCubeWithEngine.java    From kylin with Apache License 2.0 6 votes vote down vote up
public void before() throws Exception {
    deployEnv();

    final KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    jobService = ExecutableManager.getInstance(kylinConfig);
    scheduler = DefaultScheduler.createInstance();
    scheduler.init(new JobEngineConfig(kylinConfig), new ZookeeperJobLock());
    if (!scheduler.hasStarted()) {
        throw new RuntimeException("scheduler has not been started");
    }
    cubeManager = CubeManager.getInstance(kylinConfig);
    for (String jobId : jobService.getAllJobIds()) {
        AbstractExecutable executable = jobService.getJob(jobId);
        if (executable instanceof CubingJob || executable instanceof CheckpointExecutable) {
            jobService.deleteJob(jobId);
        }
    }

    cubeDescManager = CubeDescManager.getInstance(kylinConfig);

    // update enginType
    updateCubeEngineType(Lists.newArrayList("ci_inner_join_cube", "ci_left_join_cube"));
}
 
Example #12
Source File: DistributedScheduler.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void resumeAllRunningJobs() {
    for (final String id : executableManager.getAllJobIds()) {
        final Output output = executableManager.getOutput(id);
        AbstractExecutable executable = executableManager.getJob(id);
        if (output.getState() == ExecutableState.RUNNING && executable instanceof DefaultChainedExecutable) {
            try {
                if (!jobLock.isLocked(getLockPath(executable.getId()))) {
                    executableManager.resumeRunningJobForce(executable.getId());
                    fetcherPool.schedule(fetcher, 0, TimeUnit.SECONDS);
                }
            } catch (Exception e) {
                logger.error("resume the job " + id + " fail in server: " + serverName, e);
            }
        }
    }
}
 
Example #13
Source File: JdbcHiveMRInputTest.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenSqoopCmd_Partition() throws IOException {
    ISource source = SourceManager.getSource(new JdbcSourceAware());
    IMRInput input = source.adaptToBuildEngine(IMRInput.class);
    Assert.assertNotNull(input);

    CubeManager cubeManager = CubeManager.getInstance(getTestConfig());
    CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("ci_inner_join_cube");
    CubeSegment seg = cubeManager.appendSegment(cubeManager.getCube(cubeDesc.getName()),
            new SegmentRange.TSRange(System.currentTimeMillis() - 100L, System.currentTimeMillis() + 100L));
    CubeJoinedFlatTableDesc flatDesc = new CubeJoinedFlatTableDesc(seg);
    JdbcHiveMRInput.JdbcMRBatchCubingInputSide inputSide = (JdbcHiveMRInput.JdbcMRBatchCubingInputSide) input
            .getBatchCubingInputSide(flatDesc);

    AbstractExecutable executable = new MockInputSide(flatDesc, inputSide).createSqoopToFlatHiveStep("/tmp",
            cubeDesc.getName());
    Assert.assertNotNull(executable);

    String cmd = executable.getParam("cmd");
    Assert.assertTrue(cmd.contains("org.h2.Driver"));
    Assert.assertTrue(cmd.contains(
            "--boundary-query \"SELECT MIN(\\\"TEST_KYLIN_FACT\\\".\\\"LEAF_CATEG_ID\\\"), MAX(\\\"TEST_KYLIN_FACT\\\".\\\"LEAF_CATEG_ID\\\")" + System.lineSeparator()
                    + "FROM \\\"DEFAULT\\\".\\\"TEST_KYLIN_FACT\\\" AS \\\"TEST_KYLIN_FACT\\\""));
    source.close();
}
 
Example #14
Source File: KafkaInputBase.java    From kylin with Apache License 2.0 5 votes vote down vote up
protected static AbstractExecutable createFlatTable(final String hiveTableDatabase,
                                                    final String baseLocation, final String cubeName,
                                                    final StreamCubeFactTableDesc streamFactDesc, final List<String> intermediateTables,
                                                    final List<String> intermediatePaths) {
    final IJoinedFlatTableDesc flatDesc = streamFactDesc.getFlatTableDesc();

    final String hiveInitStatements = JoinedFlatTable.generateHiveInitStatements(hiveTableDatabase);

    final String dropFactTableHql = JoinedFlatTable.generateDropTableStatement(streamFactDesc);
    // the table inputformat is sequence file
    final String createFactTableHql = JoinedFlatTable.generateCreateTableStatement(streamFactDesc, baseLocation,
            JoinedFlatTable.SEQUENCEFILE);

    final String dropTableHql = JoinedFlatTable.generateDropTableStatement(flatDesc);
    final String createTableHql = JoinedFlatTable.generateCreateTableStatement(flatDesc, baseLocation);
    String insertDataHqls = JoinedFlatTable.generateInsertDataStatement(flatDesc);
    insertDataHqls = insertDataHqls.replace(
            quoteTableIdentity(flatDesc.getDataModel().getRootFactTable(), null) + " ",
            quoteTableIdentity(hiveTableDatabase, streamFactDesc.getTableName(), null) + " ");

    CreateFlatHiveTableStep step = new CreateFlatHiveTableStep();
    CubingExecutableUtil.setCubeName(cubeName, step.getParams());
    step.setInitStatement(hiveInitStatements);
    step.setCreateTableStatement(
            dropFactTableHql + createFactTableHql + dropTableHql + createTableHql + insertDataHqls);
    step.setName(ExecutableConstants.STEP_NAME_CREATE_FLAT_HIVE_TABLE);

    intermediateTables.add(flatDesc.getTableName());
    intermediateTables.add(streamFactDesc.getTableName());
    intermediatePaths.add(baseLocation + "/" + flatDesc.getTableName());
    intermediatePaths.add(baseLocation + "/" + streamFactDesc.getTableName());
    return step;
}
 
Example #15
Source File: KafkaInputBase.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
protected static AbstractExecutable createGCStep(List<String> intermediateTables, List<String> intermediatePaths) {
    GarbageCollectionStep step = new GarbageCollectionStep();
    step.setName(ExecutableConstants.STEP_NAME_HIVE_CLEANUP);
    step.setIntermediateTables(intermediateTables);
    step.setExternalDataPaths(intermediatePaths);

    return step;
}
 
Example #16
Source File: FetcherRunner.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
protected void addToJobPool(AbstractExecutable executable, int priority) {
    String jobDesc = executable.toString();
    logger.info(jobDesc + " prepare to schedule and its priority is " + priority);
    try {
        context.addRunningJob(executable);
        jobExecutor.execute(executable);
        logger.info(jobDesc + " scheduled");
    } catch (Exception ex) {
        context.removeRunningJob(executable);
        logger.warn(jobDesc + " fail to schedule", ex);
    }
}
 
Example #17
Source File: BaseSchedulerTest.java    From Kylin with Apache License 2.0 5 votes vote down vote up
protected void waitForJobStatus(String jobId, ExecutableState state, long interval) {
    while (true) {
        AbstractExecutable job = jobService.getJob(jobId);
        if (job.getStatus() == state) {
            break;
        } else {
            try {
                Thread.sleep(interval);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example #18
Source File: JobService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void afterPropertiesSet() throws Exception {

    String timeZone = getConfig().getTimeZone();
    TimeZone tzone = TimeZone.getTimeZone(timeZone);
    TimeZone.setDefault(tzone);

    final KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();

    // In case of that kylin.server.cluster-name is not set,
    // this method have to be called first to avoid the influence of the change of kylin.metadata.url
    String clusterName = kylinConfig.getClusterName();
    logger.info("starting to initialize an instance in cluster {}", clusterName);

    final Scheduler<AbstractExecutable> scheduler = (Scheduler<AbstractExecutable>) SchedulerFactory
            .scheduler(kylinConfig.getSchedulerType());

    scheduler.init(new JobEngineConfig(kylinConfig), new ZookeeperJobLock());

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                scheduler.shutdown();
            } catch (SchedulerException e) {
                logger.error("error occurred to shutdown scheduler", e);
            }
        }
    }));
}
 
Example #19
Source File: ITDistributedSchedulerTakeOverTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSchedulerTakeOver() throws Exception {
    if (!lock(jobLock1, jobId2)) {
        throw new JobException("fail to get the lock");
    }

    DefaultChainedExecutable job = new DefaultChainedExecutable();
    job.setId(jobId2);
    AbstractExecutable task1 = new SucceedTestExecutable();
    AbstractExecutable task2 = new SucceedTestExecutable();
    AbstractExecutable task3 = new SucceedTestExecutable();
    job.addTask(task1);
    job.addTask(task2);
    job.addTask(task3);
    execMgr.addJob(job);

    waitForJobStatus(job.getId(), ExecutableState.RUNNING, 500);

    scheduler1.shutdown();
    scheduler1 = null;

    waitForJobFinish(job.getId());

    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task1.getId()).getState());
    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task2.getId()).getState());
    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task3.getId()).getState());
    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(job.getId()).getState());
}
 
Example #20
Source File: ExecutableManager.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public void discardJob(String jobId) {
    AbstractExecutable job = getJob(jobId);
    if (job instanceof DefaultChainedExecutable) {
        List<AbstractExecutable> tasks = ((DefaultChainedExecutable) job).getTasks();
        for (AbstractExecutable task : tasks) {
            if (!task.getStatus().isFinalState()) {
                updateJobOutput(task.getId(), ExecutableState.DISCARDED, null, null);
            }
        }
    }
    updateJobOutput(jobId, ExecutableState.DISCARDED, null, null);
}
 
Example #21
Source File: BaseSchedulerTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
protected void waitForJobFinish(String jobId, int maxWaitTime) {
    int error = 0;
    long start = System.currentTimeMillis();
    final int errorLimit = 3;
    while (error < errorLimit && (System.currentTimeMillis() - start < maxWaitTime)) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        try {
            AbstractExecutable job = execMgr.getJob(jobId);
            ExecutableState status = job.getStatus();
            if (status == ExecutableState.SUCCEED || status == ExecutableState.ERROR
                    || status == ExecutableState.STOPPED || status == ExecutableState.DISCARDED) {
                break;
            }
        } catch (Exception ex) {
            logger.error("", ex);
            error++;
        }
    }

    if (error >= errorLimit) {
        throw new RuntimeException("too many exceptions");
    }

    if (System.currentTimeMillis() - start >= maxWaitTime) {
        throw new RuntimeException("too long wait time");
    }
}
 
Example #22
Source File: AclEvaluate.java    From kylin with Apache License 2.0 5 votes vote down vote up
private ProjectInstance getProjectByJob(JobInstance job) {
    AbstractExecutable executable = ExecutableManager.getInstance(KylinConfig.getInstanceFromEnv())
            .getJob(job.getUuid());
    String projectName = null;
    if (executable instanceof CubingJob) {
        projectName = ((CubingJob) executable).getProjectName();
    } else if (executable instanceof CheckpointExecutable) {
        projectName = ((CheckpointExecutable) executable).getProjectName();
    } else {
        return null;
    }
    return getProjectInstance(projectName);
}
 
Example #23
Source File: ExecutableManager.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public AbstractExecutable getJob(String uuid) {
    try {
        return parseTo(executableDao.getJob(uuid));
    } catch (PersistentException e) {
        logger.error("fail to get job:" + uuid, e);
        throw new RuntimeException(e);
    }
}
 
Example #24
Source File: DistributedScheduler.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void releaseJobLock(AbstractExecutable executable) {
    if (executable instanceof DefaultChainedExecutable) {
        ExecutableState state = executable.getStatus();

        if (state != ExecutableState.READY && state != ExecutableState.RUNNING) {
            if (jobWithLocks.contains(executable.getId())) {
                logger.info(
                        executable.toString() + " will release the lock for the job: " + executable.getId());
                jobLock.unlock(getLockPath(executable.getId()));
                jobWithLocks.remove(executable.getId());
            }
        }
    }
}
 
Example #25
Source File: StorageCleanupJob.java    From kylin with Apache License 2.0 5 votes vote down vote up
private boolean isTableInUse(String segUuid, List<String> workingJobList) {
    for (String jobId : workingJobList) {
        AbstractExecutable abstractExecutable = executableManager.getJob(jobId);
        String segmentId = abstractExecutable.getParam("segmentId");

        if (null == segmentId)
            continue;

        return segUuid.equals(segmentId);
    }
    return false;
}
 
Example #26
Source File: CubingJobBuilder.java    From Kylin with Apache License 2.0 5 votes vote down vote up
public CubingJob mergeJob(CubeSegment seg) {
    checkPreconditions(seg);
    
    CubingJob result = initialJob(seg, "MERGE");
    final String jobId = result.getId();
    final String mergedCuboidPath = getJobWorkingDir(jobId) + "/" + seg.getCubeInstance().getName() + "/cuboid/";
    
    List<CubeSegment> mergingSegments = seg.getCubeInstance().getMergingSegments(seg);
    Preconditions.checkState(mergingSegments.size() > 1, "there should be more than 2 segments to merge");
    List<String> mergingSegmentIds = Lists.newArrayList();
    List<String> mergingCuboidPaths = Lists.newArrayList();
    for (CubeSegment merging : mergingSegments) {
        mergingSegmentIds.add(merging.getUuid());
        mergingCuboidPaths.add(getPathToMerge(merging));
    }

    // merge cuboid
    addMergeSteps(seg, mergingSegmentIds, mergingCuboidPaths, mergedCuboidPath, result);
    
    // convert htable
    AbstractExecutable convertCuboidToHfileStep = addHTableSteps(seg, mergedCuboidPath, result);

    // update cube info
    result.addTask(createUpdateCubeInfoAfterMergeStep(seg, mergingSegmentIds, convertCuboidToHfileStep.getId(), jobId));

    return result;
}
 
Example #27
Source File: CubingJobBuilder.java    From Kylin with Apache License 2.0 5 votes vote down vote up
AbstractExecutable addHTableSteps(CubeSegment seg, String cuboidRootPath, CubingJob result) {
    final String jobId = result.getId();
    final String cuboidPath = cuboidRootPath + "*";
    
    result.addTask(createRangeRowkeyDistributionStep(seg, cuboidPath));
    // create htable step
    result.addTask(createCreateHTableStep(seg));
    // generate hfiles step
    final MapReduceExecutable convertCuboidToHfileStep = createConvertCuboidToHfileStep(seg, cuboidPath, jobId);
    result.addTask(convertCuboidToHfileStep);
    // bulk load step
    result.addTask(createBulkLoadStep(seg, jobId));
    
    return convertCuboidToHfileStep;
}
 
Example #28
Source File: JobService.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void setRelatedIdList(CheckpointExecutable checkpointExecutable, List<String> segmentIdList,
        List<String> jobIdList) {
    for (AbstractExecutable taskForCheck : checkpointExecutable.getSubTasksForCheck()) {
        jobIdList.add(taskForCheck.getId());
        if (taskForCheck instanceof CubingJob) {
            segmentIdList.addAll(Lists
                    .newArrayList(StringUtils.split(CubingExecutableUtil.getSegmentId(taskForCheck.getParams()))));
        } else if (taskForCheck instanceof CheckpointExecutable) {
            setRelatedIdList((CheckpointExecutable) taskForCheck, segmentIdList, jobIdList);
        }
    }
}
 
Example #29
Source File: DefaultScheduler.java    From Kylin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean stop(AbstractExecutable executable) throws SchedulerException {
    if (hasStarted) {
        return true;
    } else {
        //TODO should try to stop this executable
        return true;
    }
}
 
Example #30
Source File: ITDistributedSchedulerBaseTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSchedulerLock() throws Exception {
    if (!lock(jobLock1, jobId1)) {
        throw new JobException("fail to get the lock");
    }
    DefaultChainedExecutable job = new DefaultChainedExecutable();
    job.setId(jobId1);
    AbstractExecutable task1 = new SucceedTestExecutable();
    AbstractExecutable task2 = new SucceedTestExecutable();
    AbstractExecutable task3 = new SucceedTestExecutable();
    job.addTask(task1);
    job.addTask(task2);
    job.addTask(task3);
    execMgr.addJob(job);

    Assert.assertEquals(serverName1, getServerName(jobId1));

    waitForJobFinish(job.getId());

    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task1.getId()).getState());
    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task2.getId()).getState());
    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(task3.getId()).getState());
    Assert.assertEquals(ExecutableState.SUCCEED, execMgr.getOutput(job.getId()).getState());
    
    Thread.sleep(5000);

    Assert.assertEquals(null, getServerName(jobId1));
}