use of com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException in project Qualitis by WeBankFinTech.
the class LinkisJobSubmitter method submitJob.
@Override
public JobSubmitResult submitJob(String code, String engineName, String user, String remoteAddress, String clusterName, Long taskId, String csId, String nodeName, String startupParam) throws JobSubmitException, ClusterInfoNotConfigException {
String url = getPath(remoteAddress).path(linkisConfig.getSubmitJob()).toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", user);
headers.add("Token-Code", getToken(clusterName));
Gson gson = new Gson();
Map<String, Object> map = new HashMap<>(4);
Map<String, Map> configuration = new HashMap<>(2);
map.put("requestApplicationName", linkisConfig.getAppName());
map.put("executeApplicationName", engineName);
map.put("executionCode", code);
map.put("runType", "scala");
Map<String, String> runtime = new HashMap<>(2);
runtime.put("contextID", csId);
runtime.put("nodeName", nodeName);
configuration.put("runtime", runtime);
Map<String, Object> startup;
if (StringUtils.isNotBlank(startupParam)) {
String[] startupParams = startupParam.split(SpecCharEnum.DIVIDER.getValue());
startup = new HashMap<>(startupParams.length);
for (String param : startupParams) {
if (StringUtils.isBlank(param)) {
continue;
}
String[] params = param.split("=");
String key = params[0];
String value = params[1];
Matcher matcher = NUBBER_PATTERN.matcher(value);
if (matcher.matches()) {
startup.put(key, Integer.parseInt(value));
} else {
startup.put(key, value);
}
}
configuration.put("startup", startup);
}
Map<String, Map> params = new HashMap<>(1);
params.put("configuration", configuration);
map.put("params", params);
HttpEntity<Object> entity = new HttpEntity<>(gson.toJson(map), headers);
LOGGER.info("Start to submit job to linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.POST, entity);
Map<String, Object> response = null;
try {
response = restTemplate.postForObject(url, entity, Map.class);
} catch (Exception e) {
LOGGER.error(e.getMessage());
return null;
}
LOGGER.info("Succeed to submit job to linkis. response: {}", response);
if (!checkResponse(response)) {
String message = (String) response.get("message");
throw new JobSubmitException("Error! Can not submit job, exception: " + message);
}
Long jobId = ((Integer) ((Map<String, Object>) response.get("data")).get("taskID")).longValue();
String execId = (String) ((Map<String, Object>) response.get("data")).get("execID");
String status = "";
return new JobSubmitResult(taskId, status, clusterName, remoteAddress, jobId, execId);
}
Aggregations