Search in sources :

Example 1 with ResourceInfo

use of org.apache.dolphinscheduler.common.process.ResourceInfo in project dolphinscheduler by apache.

the class FlinkParametersTest method getResourceFilesList.

@Test
public void getResourceFilesList() {
    FlinkParameters flinkParameters = new FlinkParameters();
    Assert.assertTrue(CollectionUtils.isEmpty(flinkParameters.getResourceFilesList()));
    ResourceInfo mainResource = new ResourceInfo();
    mainResource.setRes("testFlinkMain-1.0.0-SNAPSHOT.jar");
    flinkParameters.setMainJar(mainResource);
    List<ResourceInfo> resourceInfos = new LinkedList<>();
    ResourceInfo resourceInfo1 = new ResourceInfo();
    resourceInfo1.setRes("testFlinkParameters1.jar");
    resourceInfos.add(resourceInfo1);
    flinkParameters.setResourceList(resourceInfos);
    List<ResourceInfo> resourceFilesList = flinkParameters.getResourceFilesList();
    Assert.assertNotNull(resourceFilesList);
    Assert.assertEquals(2, resourceFilesList.size());
    ResourceInfo resourceInfo2 = new ResourceInfo();
    resourceInfo2.setRes("testFlinkParameters2.jar");
    resourceInfos.add(resourceInfo2);
    flinkParameters.setResourceList(resourceInfos);
    resourceFilesList = flinkParameters.getResourceFilesList();
    Assert.assertNotNull(resourceFilesList);
    Assert.assertEquals(3, resourceFilesList.size());
}
Also used : ResourceInfo(org.apache.dolphinscheduler.common.process.ResourceInfo) FlinkParameters(org.apache.dolphinscheduler.common.task.flink.FlinkParameters) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with ResourceInfo

use of org.apache.dolphinscheduler.common.process.ResourceInfo in project dolphinscheduler by apache.

the class TaskPriorityQueueConsumer method getResourceFullNames.

/**
 * get resource map key is full name and value is tenantCode
 */
protected Map<String, String> getResourceFullNames(TaskNode taskNode) {
    Map<String, String> resourceMap = new HashMap<>();
    AbstractParameters baseParam = TaskParametersUtils.getParameters(taskNode.getType(), taskNode.getParams());
    if (baseParam != null) {
        List<ResourceInfo> projectResourceFiles = baseParam.getResourceFilesList();
        if (CollectionUtils.isNotEmpty(projectResourceFiles)) {
            // filter the resources that the resource id equals 0
            Set<ResourceInfo> oldVersionResources = projectResourceFiles.stream().filter(t -> t.getId() == 0).collect(Collectors.toSet());
            if (CollectionUtils.isNotEmpty(oldVersionResources)) {
                oldVersionResources.forEach((t) -> resourceMap.put(t.getRes(), processService.queryTenantCodeByResName(t.getRes(), ResourceType.FILE)));
            }
            // get the resource id in order to get the resource names in batch
            Stream<Integer> resourceIdStream = projectResourceFiles.stream().map(resourceInfo -> resourceInfo.getId());
            Set<Integer> resourceIdsSet = resourceIdStream.filter(resId -> resId != 0).collect(Collectors.toSet());
            if (CollectionUtils.isNotEmpty(resourceIdsSet)) {
                Integer[] resourceIds = resourceIdsSet.toArray(new Integer[resourceIdsSet.size()]);
                List<Resource> resources = processService.listResourceByIds(resourceIds);
                resources.forEach((t) -> resourceMap.put(t.getFullName(), processService.queryTenantCodeByResName(t.getFullName(), ResourceType.FILE)));
            }
        }
    }
    return resourceMap;
}
Also used : ResourceInfo(org.apache.dolphinscheduler.common.process.ResourceInfo) java.util(java.util) ExecutorDispatcher(org.apache.dolphinscheduler.server.master.dispatch.ExecutorDispatcher) ExecuteException(org.apache.dolphinscheduler.server.master.dispatch.exceptions.ExecuteException) LoggerFactory(org.slf4j.LoggerFactory) TaskExecutionContextBuilder(org.apache.dolphinscheduler.server.builder.TaskExecutionContextBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) TaskPriorityQueue(org.apache.dolphinscheduler.service.queue.TaskPriorityQueue) MasterConfig(org.apache.dolphinscheduler.server.master.config.MasterConfig) SqoopParameters(org.apache.dolphinscheduler.common.task.sqoop.SqoopParameters) AbstractParameters(org.apache.dolphinscheduler.common.task.AbstractParameters) Constants(org.apache.dolphinscheduler.common.Constants) org.apache.dolphinscheduler.server.entity(org.apache.dolphinscheduler.server.entity) Stopper(org.apache.dolphinscheduler.common.thread.Stopper) org.apache.dolphinscheduler.common.utils(org.apache.dolphinscheduler.common.utils) ProcedureParameters(org.apache.dolphinscheduler.common.task.procedure.ProcedureParameters) Logger(org.slf4j.Logger) SourceMysqlParameter(org.apache.dolphinscheduler.common.task.sqoop.sources.SourceMysqlParameter) ProcessService(org.apache.dolphinscheduler.service.process.ProcessService) org.apache.dolphinscheduler.common.enums(org.apache.dolphinscheduler.common.enums) ExecutionContext(org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) DataxParameters(org.apache.dolphinscheduler.common.task.datax.DataxParameters) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) TargetMysqlParameter(org.apache.dolphinscheduler.common.task.sqoop.targets.TargetMysqlParameter) PostConstruct(javax.annotation.PostConstruct) JSONObject(com.alibaba.fastjson.JSONObject) ExecutorType(org.apache.dolphinscheduler.server.master.dispatch.enums.ExecutorType) SqlParameters(org.apache.dolphinscheduler.common.task.sql.SqlParameters) org.apache.dolphinscheduler.dao.entity(org.apache.dolphinscheduler.dao.entity) TaskNode(org.apache.dolphinscheduler.common.model.TaskNode) ResourceInfo(org.apache.dolphinscheduler.common.process.ResourceInfo) AbstractParameters(org.apache.dolphinscheduler.common.task.AbstractParameters)

Example 3 with ResourceInfo

use of org.apache.dolphinscheduler.common.process.ResourceInfo in project dolphinscheduler by apache.

the class FlinkArgsUtilsTest method setUp.

@Before
public void setUp() throws Exception {
    ResourceInfo main = new ResourceInfo();
    main.setRes("testflink-1.0.0-SNAPSHOT.jar");
    mainJar = main;
}
Also used : ResourceInfo(org.apache.dolphinscheduler.common.process.ResourceInfo) Before(org.junit.Before)

Example 4 with ResourceInfo

use of org.apache.dolphinscheduler.common.process.ResourceInfo in project dolphinscheduler by apache.

the class UpgradeDao method updateProcessDefinitionJsonResourceList.

/**
 * updateProcessDefinitionJsonResourceList
 */
protected void updateProcessDefinitionJsonResourceList() {
    ResourceDao resourceDao = new ResourceDao();
    ProcessDefinitionDao processDefinitionDao = new ProcessDefinitionDao();
    Map<Integer, String> replaceProcessDefinitionMap = new HashMap<>();
    try {
        Map<String, Integer> resourcesMap = resourceDao.listAllResources(dataSource.getConnection());
        Map<Integer, String> processDefinitionJsonMap = processDefinitionDao.queryAllProcessDefinition(dataSource.getConnection());
        for (Map.Entry<Integer, String> entry : processDefinitionJsonMap.entrySet()) {
            JSONObject jsonObject = JSONObject.parseObject(entry.getValue());
            JSONArray tasks = JSONArray.parseArray(jsonObject.getString("tasks"));
            for (int i = 0; i < tasks.size(); i++) {
                JSONObject task = tasks.getJSONObject(i);
                JSONObject param = (JSONObject) task.get("params");
                if (param != null) {
                    List<ResourceInfo> resourceList = JSONUtils.toList(param.getString("resourceList"), ResourceInfo.class);
                    ResourceInfo mainJar = JSONUtils.parseObject(param.getString("mainJar"), ResourceInfo.class);
                    if (mainJar != null && mainJar.getId() == 0) {
                        String fullName = mainJar.getRes().startsWith("/") ? mainJar.getRes() : String.format("/%s", mainJar.getRes());
                        if (resourcesMap.containsKey(fullName)) {
                            mainJar.setId(resourcesMap.get(fullName));
                            param.put("mainJar", JSONUtils.parseObject(JSONObject.toJSONString(mainJar)));
                        }
                    }
                    if (CollectionUtils.isNotEmpty(resourceList)) {
                        List<ResourceInfo> newResourceList = resourceList.stream().map(resInfo -> {
                            String fullName = resInfo.getRes().startsWith("/") ? resInfo.getRes() : String.format("/%s", resInfo.getRes());
                            if (resInfo.getId() == 0 && resourcesMap.containsKey(fullName)) {
                                resInfo.setId(resourcesMap.get(fullName));
                            }
                            return resInfo;
                        }).collect(Collectors.toList());
                        param.put("resourceList", JSONArray.parse(JSONObject.toJSONString(newResourceList)));
                    }
                }
                task.put("params", param);
            }
            jsonObject.remove(jsonObject.getString("tasks"));
            jsonObject.put("tasks", tasks);
            replaceProcessDefinitionMap.put(entry.getKey(), jsonObject.toJSONString());
        }
        if (replaceProcessDefinitionMap.size() > 0) {
            processDefinitionDao.updateProcessDefinitionJson(dataSource.getConnection(), replaceProcessDefinitionMap);
        }
    } catch (Exception e) {
        logger.error("update process definition json resource list error", e);
    }
}
Also used : AbstractBaseDao(org.apache.dolphinscheduler.dao.AbstractBaseDao) ResourceInfo(org.apache.dolphinscheduler.common.process.ResourceInfo) org.apache.dolphinscheduler.common.utils(org.apache.dolphinscheduler.common.utils) Logger(org.slf4j.Logger) Connection(java.sql.Connection) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) MessageFormat(java.text.MessageFormat) JSONArray(com.alibaba.fastjson.JSONArray) SQLException(java.sql.SQLException) List(java.util.List) java.io(java.io) DbType(org.apache.dolphinscheduler.common.enums.DbType) ResultSet(java.sql.ResultSet) Map(java.util.Map) DataSource(javax.sql.DataSource) JSONObject(com.alibaba.fastjson.JSONObject) ConnectionFactory(org.apache.dolphinscheduler.dao.datasource.ConnectionFactory) ResourceInfo(org.apache.dolphinscheduler.common.process.ResourceInfo) HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray) SQLException(java.sql.SQLException) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ResourceInfo

use of org.apache.dolphinscheduler.common.process.ResourceInfo in project dolphinscheduler by apache.

the class SparkArgsUtils method buildArgs.

/**
 * build args
 *
 * @param param param
 * @return argument list
 */
public static List<String> buildArgs(SparkParameters param) {
    List<String> args = new ArrayList<>();
    String deployMode = "cluster";
    args.add(Constants.MASTER);
    if (StringUtils.isNotEmpty(param.getDeployMode())) {
        deployMode = param.getDeployMode();
    }
    if (!"local".equals(deployMode)) {
        args.add("yarn");
        args.add(Constants.DEPLOY_MODE);
    }
    args.add(param.getDeployMode());
    ProgramType type = param.getProgramType();
    String mainClass = param.getMainClass();
    if (type != null && type != ProgramType.PYTHON && StringUtils.isNotEmpty(mainClass)) {
        args.add(Constants.MAIN_CLASS);
        args.add(mainClass);
    }
    int driverCores = param.getDriverCores();
    if (driverCores != 0) {
        args.add(Constants.DRIVER_CORES);
        args.add(String.format("%d", driverCores));
    }
    String driverMemory = param.getDriverMemory();
    if (StringUtils.isNotEmpty(driverMemory)) {
        args.add(Constants.DRIVER_MEMORY);
        args.add(driverMemory);
    }
    int numExecutors = param.getNumExecutors();
    if (numExecutors != 0) {
        args.add(Constants.NUM_EXECUTORS);
        args.add(String.format("%d", numExecutors));
    }
    int executorCores = param.getExecutorCores();
    if (executorCores != 0) {
        args.add(Constants.EXECUTOR_CORES);
        args.add(String.format("%d", executorCores));
    }
    String executorMemory = param.getExecutorMemory();
    if (StringUtils.isNotEmpty(executorMemory)) {
        args.add(Constants.EXECUTOR_MEMORY);
        args.add(executorMemory);
    }
    // --files --conf --libjar ...
    String others = param.getOthers();
    String queue = param.getQueue();
    if (StringUtils.isNotEmpty(others)) {
        if (!others.contains(Constants.SPARK_QUEUE) && StringUtils.isNotEmpty(queue)) {
            args.add(Constants.SPARK_QUEUE);
            args.add(queue);
        }
        args.add(others);
    } else if (StringUtils.isNotEmpty(queue)) {
        args.add(Constants.SPARK_QUEUE);
        args.add(queue);
    }
    ResourceInfo mainJar = param.getMainJar();
    if (mainJar != null) {
        args.add(mainJar.getRes());
    }
    String mainArgs = param.getMainArgs();
    if (StringUtils.isNotEmpty(mainArgs)) {
        args.add(mainArgs);
    }
    return args;
}
Also used : ResourceInfo(org.apache.dolphinscheduler.common.process.ResourceInfo) ArrayList(java.util.ArrayList) ProgramType(org.apache.dolphinscheduler.common.enums.ProgramType)

Aggregations

ResourceInfo (org.apache.dolphinscheduler.common.process.ResourceInfo)11 JSONObject (com.alibaba.fastjson.JSONObject)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 ProgramType (org.apache.dolphinscheduler.common.enums.ProgramType)2 DataxParameters (org.apache.dolphinscheduler.common.task.datax.DataxParameters)2 FlinkParameters (org.apache.dolphinscheduler.common.task.flink.FlinkParameters)2 ProcedureParameters (org.apache.dolphinscheduler.common.task.procedure.ProcedureParameters)2 SqlParameters (org.apache.dolphinscheduler.common.task.sql.SqlParameters)2 org.apache.dolphinscheduler.common.utils (org.apache.dolphinscheduler.common.utils)2 Resource (org.apache.dolphinscheduler.dao.entity.Resource)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 JSONArray (com.alibaba.fastjson.JSONArray)1 java.io (java.io)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 MessageFormat (java.text.MessageFormat)1