Search in sources :

Example 6 with ClusterInfoNotConfigException

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) Gson(com.google.gson.Gson) JobSubmitResult(com.webank.wedatasphere.qualitis.bean.JobSubmitResult) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException) JobKillException(com.webank.wedatasphere.qualitis.exception.JobKillException) TaskNotExistException(com.webank.wedatasphere.qualitis.exception.TaskNotExistException) JobSubmitException(com.webank.wedatasphere.qualitis.exception.JobSubmitException) LogPartialException(com.webank.wedatasphere.qualitis.exception.LogPartialException) JobSubmitException(com.webank.wedatasphere.qualitis.exception.JobSubmitException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClusterInfoNotConfigException (com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)6 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)4 Task (com.webank.wedatasphere.qualitis.entity.Task)4 LogPartialException (com.webank.wedatasphere.qualitis.exception.LogPartialException)4 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)4 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)4 JobSubmitResult (com.webank.wedatasphere.qualitis.bean.JobSubmitResult)3 JobKillException (com.webank.wedatasphere.qualitis.exception.JobKillException)3 JobSubmitException (com.webank.wedatasphere.qualitis.exception.JobSubmitException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Gson (com.google.gson.Gson)2 DataQualityTask (com.webank.wedatasphere.qualitis.bean.DataQualityTask)2 JobKillResult (com.webank.wedatasphere.qualitis.bean.JobKillResult)2 LogResult (com.webank.wedatasphere.qualitis.bean.LogResult)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 DataQualityJob (com.webank.wedatasphere.qualitis.bean.DataQualityJob)1 RuleTaskDetail (com.webank.wedatasphere.qualitis.bean.RuleTaskDetail)1 TaskRule (com.webank.wedatasphere.qualitis.bean.TaskRule)1