Search in sources :

Example 6 with JobClient

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

the class HiveClient method main.

public static void main(String[] args) throws IOException {
    FileInputStream fileInputStream = null;
    InputStreamReader inputStreamReader = null;
    BufferedReader reader = null;
    try {
        System.setProperty("HADOOP_USER_NAME", "admin");
        // input params json file path
        String filePath = args[0];
        File paramsFile = new File(filePath);
        fileInputStream = new FileInputStream(paramsFile);
        inputStreamReader = new InputStreamReader(fileInputStream);
        reader = new BufferedReader(inputStreamReader);
        String request = reader.readLine();
        Map params = PublicUtil.jsonStrToObject(request, Map.class);
        ParamAction paramAction = PublicUtil.mapToObject(params, ParamAction.class);
        JobClient jobClient = new JobClient(paramAction);
        String pluginInfo = jobClient.getPluginInfo();
        Properties properties = PublicUtil.jsonStrToObject(pluginInfo, Properties.class);
        String md5plugin = MD5Util.getMd5String(pluginInfo);
        properties.setProperty("md5sum", md5plugin);
        HiveClient client = new HiveClient();
        client.init(properties);
        ClusterResource clusterResource = client.getClusterResource();
        LOG.info("submit success!");
        LOG.info(clusterResource.toString());
        System.exit(0);
    } catch (Exception e) {
        LOG.error("submit error!", e);
    } finally {
        if (reader != null) {
            reader.close();
            inputStreamReader.close();
            fileInputStream.close();
        }
    }
}
Also used : ParamAction(com.dtstack.taier.pluginapi.pojo.ParamAction) Properties(java.util.Properties) Map(java.util.Map) JobClient(com.dtstack.taier.pluginapi.JobClient) ClusterResource(com.dtstack.taier.pluginapi.pojo.ClusterResource)

Example 7 with JobClient

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

the class AbstractRdbsClientTest method testProcessSubmitJobWithType.

@Test
public void testProcessSubmitJobWithType() throws Exception {
    JobClient jobClient = new JobClient();
    jobClient.setJobType(EJobType.MR);
    AbstractRdbsClient abstractRdbsClient = PowerMockito.mock(AbstractRdbsClient.class, Mockito.CALLS_REAL_METHODS);
    Boolean isMr = true;
    try {
        JobResult jobResult = abstractRdbsClient.processSubmitJobWithType(jobClient);
        Assert.assertNotNull(jobResult);
    } catch (Exception e) {
        isMr = true;
    }
    Assert.assertTrue(isMr);
    jobClient.setJobType(EJobType.SQL);
    RdbsExeQueue rdbsExeQueue = PowerMockito.mock(RdbsExeQueue.class);
    when(rdbsExeQueue.submit(any(JobClient.class))).thenReturn("test");
    MemberModifier.field(AbstractRdbsClient.class, "exeQueue").set(abstractRdbsClient, rdbsExeQueue);
    JobResult jobResult = abstractRdbsClient.processSubmitJobWithType(jobClient);
    Assert.assertNotNull(jobResult);
}
Also used : JobResult(com.dtstack.taier.pluginapi.pojo.JobResult) RdbsExeQueue(com.dtstack.taier.rdbs.common.executor.RdbsExeQueue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JobClient(com.dtstack.taier.pluginapi.JobClient) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with JobClient

use of com.dtstack.taier.pluginapi.JobClient 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 9 with JobClient

use of com.dtstack.taier.pluginapi.JobClient 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 10 with JobClient

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

the class Launcher method main.

public static void main(String[] args) throws Exception {
    System.setProperty("HADOOP_USER_NAME", "admin");
    // job json path
    String jobJsonPath = USER_DIR + SP + "local-test/src/main/json/dtscript-agent.json";
    // create jobClient
    String content = getJobContent(jobJsonPath);
    Map params = PublicUtil.jsonStrToObject(content, Map.class);
    ParamAction paramAction = PublicUtil.mapToObject(params, ParamAction.class);
    JobClient jobClient = new JobClient(paramAction);
    // create jobIdentifier
    String jobId = "jobId";
    String appId = "appId";
    String taskId = "taskId";
    JobIdentifier jobIdentifier = JobIdentifier.createInstance(jobId, appId, taskId);
    // get pluginInfo
    String pluginInfo = jobClient.getPluginInfo();
    Properties properties = PublicUtil.jsonStrToObject(pluginInfo, Properties.class);
    String md5plugin = MD5Util.getMd5String(pluginInfo);
    properties.setProperty("md5sum", md5plugin);
    // create client
    String pluginParentPath = USER_DIR + SP + "pluginLibs";
    IClient client = ClientFactory.buildPluginClient(pluginInfo, pluginParentPath);
    // client init
    ClassLoaderCallBackMethod.callbackAndReset(new CallBack<String>() {

        @Override
        public String execute() throws Exception {
            client.init(properties);
            return null;
        }
    }, client.getClass().getClassLoader(), true);
    // test target method
    ClassLoaderCallBackMethod.callbackAndReset(new CallBack<Object>() {

        @Override
        public Object execute() throws Exception {
            JobResult jobResult = client.submitJob(jobClient);
            return jobResult;
        }
    }, client.getClass().getClassLoader(), true);
    LOG.info("Launcher Success!");
    System.exit(0);
}
Also used : JobResult(com.dtstack.taier.pluginapi.pojo.JobResult) IClient(com.dtstack.taier.pluginapi.client.IClient) JobIdentifier(com.dtstack.taier.pluginapi.JobIdentifier) Properties(java.util.Properties) JobClient(com.dtstack.taier.pluginapi.JobClient) ParamAction(com.dtstack.taier.pluginapi.pojo.ParamAction) Map(java.util.Map)

Aggregations

JobClient (com.dtstack.taier.pluginapi.JobClient)28 ParamAction (com.dtstack.taier.pluginapi.pojo.ParamAction)14 Test (org.junit.Test)6 PluginDefineException (com.dtstack.taier.pluginapi.exception.PluginDefineException)5 JobResult (com.dtstack.taier.pluginapi.pojo.JobResult)5 IOException (java.io.IOException)5 JarFileInfo (com.dtstack.taier.pluginapi.JarFileInfo)4 JobIdentifier (com.dtstack.taier.pluginapi.JobIdentifier)4 ClusterResource (com.dtstack.taier.pluginapi.pojo.ClusterResource)4 Properties (java.util.Properties)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 JSONObject (com.alibaba.fastjson.JSONObject)3 KerberosUtils (com.dtstack.taier.base.util.KerberosUtils)3 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 ScheduleEngineJobCache (com.dtstack.taier.dao.domain.ScheduleEngineJobCache)3 FlinkConfig (com.dtstack.taier.flink.FlinkConfig)3 EJobType (com.dtstack.taier.pluginapi.enums.EJobType)3 JudgeResult (com.dtstack.taier.pluginapi.pojo.JudgeResult)3 File (java.io.File)3