python怎么读的datax源码阅读⼀:python⽂件
⼀、前⾯主要是怎么使⽤datax和datax的插件编写,后⾯主要说明源码阅读部分,python相关⽂件
⼆、datax关键代码(python datax.py test.json)
1、datax.py⽂件
printCopyright()
parser = getOptionParser(sys.argv[1:])
options, args = parser.parse_args(sys.argv[1:])
ader is not None and options.writer is not None:
ader,options.writer)
if len(args) == 0:
parser.print_help()
startCommand = buildStartCommand(options, args)
child_process = subprocess.Popen(startCommand, shell=True)
上⾯代码关键部分是函数buildStartCommand(options, args)拼出来的java命令,然后启动⼀个新的⼦进程去执⾏java命令
def buildStartCommand(options, args):
commandMap = {}
tempJVMCommand = DEFAULT_JVM
if options.jvmParameters:
tempJVMCommand = tempJVMCommand + " " + options.jvmParameters
Debug:
tempJVMCommand = tempJVMCommand + " " + REMOTE_DEBUG_CONFIG
print 'local ip: ', getLocalIp()
if options.loglevel:
tempJVMCommand = tempJVMCommand + " " + ("-Dloglevel=%s" % (options.loglevel))
de:
commandMap["mode"] = de
# jobResource 可能是 URL,也可能是本地⽂件路径(相对,绝对)
jobResource = args[0]
if not isUrl(jobResource):
jobResource = os.path.abspath(jobResource)
if jobResource.lower().startswith("file://"):
jobResource = jobResource[len("file://"):]
jobParams = ("-Dlog.file.name=%s") % (jobResource[-20:].replace('/', '_').replace('.', '_'))
if options.params:
jobParams = jobParams + " " + options.params
if options.jobid:
commandMap["jobid"] = options.jobid
commandMap["jvm"] = tempJVMCommand
commandMap["params"] = jobParams
commandMap["job"] = jobResource
return Template(ENGINE_COMMAND).substitute(**commandMap)
java命令是通过模板ENGINE_COMMAND和commandMap拼接⽽成,其中ENGINE_COMMAND是主要的java脚本命令
ENGINE_COMMAND = "java -server ${jvm} %s -classpath %s  ${params} com.Engine -mode ${mode} -jobid ${jobid} -job ${job}" % (DE
commandMap中包含jvm参数、任务动态参数和job⽂件信息(json配置⽂件),根据这个python⽂件,⽤户可以⾃⾏修改jvm相关参
数,如
DEFAULT_JVM = "-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%s/log" % (DATAX_HOME)
2、上述python⽂件执⾏完毕之后会启动java命令,主函数是com.Engine,⾄此python⽂件主要流程完毕

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。