public List convertParameter()

in client/migrationx/migrationx-transformer/src/main/java/com/aliyun/dataworks/migrationx/transformer/dataworks/converter/dolphinscheduler/v2/nodes/parameters/PythonParameterConverter.java [64:152]


    public List<DwNode> convertParameter() throws IOException {
        DwNode dwNode = newDwNode(taskDefinition);
        String shellType = getConverterType();
        String type = properties.getProperty(Constants.CONVERTER_TARGET_PYTHON_NODE_TYPE_AS, shellType);
        dwNode.setType(type);
        String usingCmd = properties.getProperty(Constants.CONVERTER_PYTHON_CODE_BLOCK, "false");
        if (Boolean.parseBoolean(usingCmd)) {
            //python -c 'some python code block'
            String cmd = "python -c \"" + parameter.getRawScript() + "\"";
            cmd = replaceCode(cmd, dwNode);
            dwNode.setCode(cmd);
        } else if (CodeProgramType.ODPS_PYTHON.equals(CodeProgramType.of(type))
                || CodeProgramType.PYODPS.equals(CodeProgramType.of(type))
                || CodeProgramType.PYODPS3.equals(CodeProgramType.of(type))) {
            String code = parameter.getRawScript();
            code = replaceCode(code, dwNode);
            dwNode.setCode(code);
        } else {
            DwResource pyRes = new DwResource();
            pyRes.setName(Joiner.on("_").join(processMeta.getName(), taskDefinition.getName()) + ".py");
            pyRes.setWorkflowRef(dwWorkflow);
            dwWorkflow.getResources().add(pyRes);

            String engineType = properties.getProperty(Constants.CONVERTER_TARGET_ENGINE_TYPE, "");
            if (StringUtils.equalsIgnoreCase(CalcEngineType.EMR.name(), engineType)) {
                pyRes.setType(CodeProgramType.EMR_FILE.name());
                pyRes.setExtend(ResourceType.PYTHON.name());
                dwNode.setCode(EmrCodeUtils.toEmrCode(dwNode));
                List<String> paths = new ArrayList<>();
                DataWorksTransformerConfig config = DataWorksTransformerConfig.getConfig();
                if (config != null) {
                    paths.add(CalcEngineType.EMR.getDisplayName(config.getLocale()));
                    paths.add(LabelType.RESOURCE.getDisplayName(config.getLocale()));
                } else {
                    paths.add(CalcEngineType.EMR.getDisplayName(Locale.SIMPLIFIED_CHINESE));
                    paths.add(LabelType.RESOURCE.getDisplayName(Locale.SIMPLIFIED_CHINESE));
                }

                pyRes.setFolder(Joiner.on(File.separator).join(paths));
            } else if (StringUtils.equalsIgnoreCase(CalcEngineType.HADOOP_CDH.name(), engineType)) {
                pyRes.setExtend(ResourceType.PYTHON.name());
                pyRes.setType(CodeProgramType.CDH_FILE.name());
                List<String> paths = new ArrayList<>();
                DataWorksTransformerConfig config = DataWorksTransformerConfig.getConfig();
                if (config != null) {
                    paths.add(CalcEngineType.HADOOP_CDH.getDisplayName(config.getLocale()));
                    paths.add(LabelType.RESOURCE.getDisplayName(config.getLocale()));
                } else {
                    paths.add(CalcEngineType.HADOOP_CDH.getDisplayName(Locale.SIMPLIFIED_CHINESE));
                    paths.add(LabelType.RESOURCE.getDisplayName(Locale.SIMPLIFIED_CHINESE));
                }
                pyRes.setFolder(Joiner.on(File.separator).join(paths));
            } else {
                pyRes.setExtend(ResourceType.PYTHON.name());
                pyRes.setType(CodeProgramType.ODPS_PYTHON.name());
                List<String> paths = new ArrayList<>();
                DataWorksTransformerConfig config = DataWorksTransformerConfig.getConfig();
                if (config != null) {
                    paths.add(CalcEngineType.ODPS.getDisplayName(config.getLocale()));
                    paths.add(LabelType.RESOURCE.getDisplayName(config.getLocale()));
                } else {
                    paths.add(CalcEngineType.ODPS.getDisplayName(Locale.SIMPLIFIED_CHINESE));
                    paths.add(LabelType.RESOURCE.getDisplayName(Locale.SIMPLIFIED_CHINESE));
                }
                pyRes.setFolder(Joiner.on(File.separator).join(paths));
            }
            File tmpFIle = new File(FileUtils.getTempDirectory(), pyRes.getName());
            FileUtils.writeStringToFile(tmpFIle, parameter.getRawScript(), StandardCharsets.UTF_8);
            pyRes.setLocalPath(tmpFIle.getAbsolutePath());

            Map<String, String> resourceMap = handleResourcesReference();
            List<String> resources = new ArrayList<>();
            if (resourceMap != null) {
                resources.addAll(resourceMap.values());
            }
            resources.add(pyRes.getName());
            String code = Joiner.on("\n").join(
                    DataStudioCodeUtils.addResourceReference(CodeProgramType.of(dwNode.getType()), "", resources),
                    "python ./" + pyRes.getName()
            );
            code = replaceCode(code, dwNode);
            code = replaceResourceFullName(resourceMap, code);
            dwNode.setCode(code);
            if (type.equals(CodeProgramType.EMR_SHELL.name())) {
                dwNode.setCode(EmrCodeUtils.toEmrCode(dwNode));
            }
        }
        return Arrays.asList(dwNode);
    }