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();
}
}
}
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);
}
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());
}
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());
}
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);
}
Aggregations