Search in sources :

Example 1 with JudgeResult

use of com.dtstack.taier.pluginapi.pojo.JudgeResult in project Taier by DTStack.

the class JobSubmitDealer method submitJob.

private void submitJob(JobClient jobClient) {
    JobResult jobResult = null;
    try {
        // 判断资源
        JudgeResult judgeResult = workerOperator.judgeSlots(jobClient);
        if (JudgeResult.JudgeType.OK == judgeResult.getResult()) {
            LOGGER.info("jobId:{} taskType:{} submit to engine start.", jobClient.getJobId(), jobClient.getTaskType());
            jobClient.doStatusCallBack(TaskStatus.COMPUTING.getStatus());
            // 提交任务
            jobResult = workerOperator.submitJob(jobClient);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("jobId:{} taskType:{} submit jobResult:{}.", jobClient.getJobId(), jobClient.getTaskType(), jobResult);
            }
            jobClient.setEngineTaskId(jobResult.getData(JobResult.EXT_ID_KEY));
            jobClient.setApplicationId(jobResult.getData(JobResult.JOB_ID_KEY));
            addToTaskListener(jobClient, jobResult);
            LOGGER.info("jobId:{} taskType:{} submit to engine end.", jobClient.getJobId(), jobClient.getTaskType());
        } else if (JudgeResult.JudgeType.LIMIT_ERROR == judgeResult.getResult()) {
            LOGGER.info("jobId:{} taskType:{} submitJob happens system limitError:{}", jobClient.getJobId(), jobClient.getTaskType(), judgeResult.getReason());
            jobClient.setEngineTaskId(null);
            jobResult = JobResult.createErrorResult(false, judgeResult.getReason());
            addToTaskListener(jobClient, jobResult);
        } else if (JudgeResult.JudgeType.EXCEPTION == judgeResult.getResult()) {
            LOGGER.info("jobId:{} taskType:{} judgeSlots result is exception {}", jobClient.getJobId(), jobClient.getTaskType(), judgeResult.getReason());
            handlerFailedWithRetry(jobClient, true, new Exception(judgeResult.getReason()));
        } else {
            LOGGER.info("jobId:{} taskType:{} judgeSlots result is false.", jobClient.getJobId(), jobClient.getTaskType());
            handlerNoResource(jobClient, judgeResult);
        }
    } catch (WorkerAccessException e) {
        LOGGER.info(" jobId:{} taskType:{} worker not find.", jobClient.getJobId(), jobClient.getTaskType());
        handlerNoResource(jobClient, workerNotFindResult);
    } catch (ClientAccessException | ClientArgumentException e) {
        handlerFailedWithRetry(jobClient, false, e);
    } catch (Throwable e) {
        handlerFailedWithRetry(jobClient, true, e);
    }
}
Also used : ClientArgumentException(com.dtstack.taier.pluginapi.exception.ClientArgumentException) JobResult(com.dtstack.taier.pluginapi.pojo.JobResult) JudgeResult(com.dtstack.taier.pluginapi.pojo.JudgeResult) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException) WorkerAccessException(com.dtstack.taier.common.exception.WorkerAccessException) ClientArgumentException(com.dtstack.taier.pluginapi.exception.ClientArgumentException) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) WorkerAccessException(com.dtstack.taier.common.exception.WorkerAccessException)

Example 2 with JudgeResult

use of com.dtstack.taier.pluginapi.pojo.JudgeResult in project Taier by DTStack.

the class AbstractRdbsClientTest method testJudgeSlots.

@Test
public void testJudgeSlots() throws Exception {
    JobClient jobClient = new JobClient();
    JudgeResult result = testRdbsClient.judgeSlots(jobClient);
    Assert.assertEquals(JudgeResult.JudgeType.NOT_OK, result.getResult());
    EngineResourceInfo info = PowerMockito.mock(EngineResourceInfo.class);
    when(info.judgeSlots(any(JobClient.class))).thenReturn(JudgeResult.ok());
    MemberModifier.field(TestRdbsClient.class, "resourceInfo").set(testRdbsClient, info);
    JudgeResult judgeResult = testRdbsClient.judgeSlots(jobClient);
    Assert.assertEquals(JudgeResult.JudgeType.OK, judgeResult.getResult());
}
Also used : EngineResourceInfo(com.dtstack.taier.base.resource.EngineResourceInfo) JudgeResult(com.dtstack.taier.pluginapi.pojo.JudgeResult) JobClient(com.dtstack.taier.pluginapi.JobClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with JudgeResult

use of com.dtstack.taier.pluginapi.pojo.JudgeResult in project Taier by DTStack.

the class RdbsResourceInfoTest method testJudgeSlots.

@Test
public void testJudgeSlots() throws Exception {
    RdbsExeQueue rdbsExeQueue = PowerMockito.mock(RdbsExeQueue.class);
    when(rdbsExeQueue.checkCanSubmit()).thenReturn(true);
    MemberModifier.field(RdbsResourceInfo.class, "rdbsExeQueue").set(rdbsResourceInfo, rdbsExeQueue);
    JobClient jobClient = new JobClient();
    JudgeResult judgeResult = rdbsResourceInfo.judgeSlots(jobClient);
    Assert.assertTrue(judgeResult.available());
}
Also used : RdbsExeQueue(com.dtstack.taier.rdbs.common.executor.RdbsExeQueue) JudgeResult(com.dtstack.taier.pluginapi.pojo.JudgeResult) JobClient(com.dtstack.taier.pluginapi.JobClient) Test(org.junit.Test)

Example 4 with JudgeResult

use of com.dtstack.taier.pluginapi.pojo.JudgeResult in project Taier by DTStack.

the class AbstractYarnResourceInfo method getYarnSlots.

public JudgeResult getYarnSlots(YarnClient yarnClient, String queueName, int yarnAccepterTaskNumber) {
    try {
        EnumSet<YarnApplicationState> enumSet = EnumSet.noneOf(YarnApplicationState.class);
        enumSet.add(YarnApplicationState.ACCEPTED);
        List<ApplicationReport> acceptedApps = yarnClient.getApplications(enumSet).stream().filter(report -> report.getQueue().endsWith(queueName)).collect(Collectors.toList());
        if (acceptedApps.size() > yarnAccepterTaskNumber) {
            logger.info("queueName:{} acceptedApps:{} >= yarnAccepterTaskNumber:{}", queueName, acceptedApps.size(), yarnAccepterTaskNumber);
            return JudgeResult.notOk("queueName:" + queueName + " acceptedApps:" + acceptedApps.size() + " >= yarnAccepterTaskNumber:" + yarnAccepterTaskNumber);
        }
        List<NodeReport> nodeReports = yarnClient.getNodeReports(NodeState.RUNNING);
        if (!elasticCapacity) {
            getQueueRemainCapacity(1, queueName, yarnClient.getRootQueueInfos());
        }
        for (NodeReport report : nodeReports) {
            Resource capability = report.getCapability();
            Resource used = report.getUsed();
            int totalMem = capability.getMemory();
            int totalCores = capability.getVirtualCores();
            int usedMem = used.getMemory();
            int usedCores = used.getVirtualCores();
            int freeCores = totalCores - usedCores;
            int freeMem = totalMem - usedMem;
            if (freeCores > containerCoreMax) {
                containerCoreMax = freeCores;
            }
            if (freeMem > containerMemoryMax) {
                containerMemoryMax = freeMem;
            }
            this.addNodeResource(new NodeResourceDetail(report.getNodeId().toString(), totalCores, usedCores, freeCores, totalMem, usedMem, freeMem));
        }
        calc();
        return JudgeResult.ok();
    } catch (IOException | YarnException e) {
        throw new RuntimeException(e);
    }
}
Also used : Logger(org.slf4j.Logger) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) NodeState(org.apache.hadoop.yarn.api.records.NodeState) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) Lists(com.google.common.collect.Lists) CollectionUtils(org.apache.commons.collections.CollectionUtils) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) JudgeResult(com.dtstack.taier.pluginapi.pojo.JudgeResult) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) Resource(org.apache.hadoop.yarn.api.records.Resource) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) NodeReport(org.apache.hadoop.yarn.api.records.NodeReport) QueueInfo(org.apache.hadoop.yarn.api.records.QueueInfo) EnumSet(java.util.EnumSet) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) Resource(org.apache.hadoop.yarn.api.records.Resource) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) NodeReport(org.apache.hadoop.yarn.api.records.NodeReport)

Example 5 with JudgeResult

use of com.dtstack.taier.pluginapi.pojo.JudgeResult in project Taier by DTStack.

the class SparkYarnResourceInfo method judgeSlots.

@Override
public JudgeResult judgeSlots(JobClient jobClient) {
    JudgeResult jr = getYarnSlots(yarnClient, queueName, yarnAccepterTaskNumber);
    if (!jr.available()) {
        return jr;
    }
    Properties properties = jobClient.getConfProperties();
    int driverCores = DEFAULT_CORES;
    if (properties != null && properties.containsKey(DRIVER_CORE_KEY)) {
        driverCores = MathUtil.getIntegerVal(properties.get(DRIVER_CORE_KEY));
    }
    int driverMem = DEFAULT_MEM;
    if (properties != null && properties.containsKey(DRIVER_MEM_KEY)) {
        String setMemStr = properties.getProperty(DRIVER_MEM_KEY);
        driverMem = UnitConvertUtil.convert2Mb(setMemStr);
    }
    int driverMemOverhead = DEFAULT_MEM_OVERHEAD;
    if (properties != null && properties.containsKey(DRIVER_MEM_OVERHEAD_KEY)) {
        String setMemStr = properties.getProperty(DRIVER_MEM_OVERHEAD_KEY);
        driverMemOverhead = UnitConvertUtil.convert2Mb(setMemStr);
    }
    driverMem += driverMemOverhead;
    int executorNum = DEFAULT_INSTANCES;
    if (properties != null && properties.containsKey(EXECUTOR_INSTANCES_KEY)) {
        executorNum = MathUtil.getIntegerVal(properties.get(EXECUTOR_INSTANCES_KEY));
    }
    int executorCores = DEFAULT_CORES;
    if (properties != null && properties.containsKey(EXECUTOR_CORES_KEY)) {
        executorCores = MathUtil.getIntegerVal(properties.get(EXECUTOR_CORES_KEY));
    }
    int executorMem = DEFAULT_MEM;
    if (properties != null && properties.containsKey(EXECUTOR_MEM_KEY)) {
        String setMemStr = properties.getProperty(EXECUTOR_MEM_KEY);
        executorMem = UnitConvertUtil.convert2Mb(setMemStr);
    }
    int executorMemOverhead = DEFAULT_MEM_OVERHEAD;
    if (properties != null && properties.containsKey(EXECUTOR_MEM_OVERHEAD_KEY)) {
        String setMemStr = properties.getProperty(EXECUTOR_MEM_OVERHEAD_KEY);
        executorMemOverhead = UnitConvertUtil.convert2Mb(setMemStr);
    }
    executorMem += executorMemOverhead;
    List<InstanceInfo> instanceInfos = Lists.newArrayList(InstanceInfo.newRecord(1, driverCores, driverMem), InstanceInfo.newRecord(executorNum, executorCores, executorMem));
    return judgeYarnResource(instanceInfos);
}
Also used : JudgeResult(com.dtstack.taier.pluginapi.pojo.JudgeResult) Properties(java.util.Properties)

Aggregations

JudgeResult (com.dtstack.taier.pluginapi.pojo.JudgeResult)9 JobClient (com.dtstack.taier.pluginapi.JobClient)2 IOException (java.io.IOException)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 Test (org.junit.Test)2 EngineResourceInfo (com.dtstack.taier.base.resource.EngineResourceInfo)1 ClientAccessException (com.dtstack.taier.common.exception.ClientAccessException)1 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)1 WorkerAccessException (com.dtstack.taier.common.exception.WorkerAccessException)1 ClusterMode (com.dtstack.taier.flink.base.enums.ClusterMode)1 FlinkPerJobResourceInfo (com.dtstack.taier.flink.resource.FlinkPerJobResourceInfo)1 ClientArgumentException (com.dtstack.taier.pluginapi.exception.ClientArgumentException)1 PluginDefineException (com.dtstack.taier.pluginapi.exception.PluginDefineException)1 JobResult (com.dtstack.taier.pluginapi.pojo.JobResult)1 RdbsExeQueue (com.dtstack.taier.rdbs.common.executor.RdbsExeQueue)1 Lists (com.google.common.collect.Lists)1 MalformedURLException (java.net.MalformedURLException)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Properties (java.util.Properties)1