Azkaban源码阅读
2017-12-28 14:56
246 查看
准备工作
源码地址:https://github.com/azkaban/azkaban.git目录结构:
![](https://i.imgur.com/dNsZ4p8.png)
Azkaban分为8个大模块:
az-core:基础模块.
azkaban-common:公共模块.
azkaban-db:提供访问数据库模块.
azkaban-exec-server:具体执行任务的模块.
azkaban-web-server:提供web界面展示和接收http请求的模块.
azkaban-hadoop-security-plugin:Hadoop模块.
azkaban-solo-server:web和exec运行在同一个 JVM。
azkaban-spi:
下图为依赖关系:
![](https://i.imgur.com/LCUFMAk.jpg)
导入源码
导入idea后结果,如下:![](https://i.imgur.com/TYuslLp.png)
利用gradle构建
此方法比较简单,在idea里面新建一个azkaban的 Gradle工程就可以了。
![](https://i.imgur.com/kJ45mRu.png)
建好之后,把源码的azkaban目录下所有文件复制到新建的工程文件夹azkaban下面,如图:
![](https://i.imgur.com/tRSNmEX.png)
完成后,返回到idea,过一会就自动构建完成,Build Project也是OK的!
利用Maven构建
此过程比较复杂,适合对Maven熟悉的玩家使用,结果如下:
![](https://i.imgur.com/iq4LjU2.png)
1、新建一个azkaban maven工程。
2、按照上述的依赖关系,得一个个子模块依次创建。选中idea的azkaban project,新建一个artifactId为az-core的子模块。
3、然后选中az-core,新建一个module,artifactId输入azkaban-db。
4、选中azkaban-db,新建一个artifactId名为azkaban-common的子模块。
5、后面依次选中子模块创建其下面的子模块。对于有2个父模块的,直接选择只有1个公共的父模块(azkaban-common)或者超父模块(azkaban)。
6、azkaban-solo-server的父模块是azkaban-web-server和azkaban-exec-server。
7、如果上述模块依赖建立错误或者不知道怎么操作,可以根据下面的pom.xml文件来设置依赖关系。
下面是每个pom.xml对应的内容。
azkaban工程的总pom.xml内容:
<groupId>com.gavin</groupId> <artifactId>azkaban</artifactId> <packaging>pom</packaging> <version>1.0</version> <modules> <module>az-core</module> <module>azkaban-spi</module> </modules> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>
为了方便快捷,直接加入下面的依赖:
<dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>3.8.0</version> </dependency> <dependency> <groupId>org.awaitility</groupId> <artifactId>awaitility</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.2</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-dbcp2</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>commons-dbutils</groupId> <artifactId>commons-dbutils</artifactId> <version>1.5</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.1</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>21.0</version> </dependency> <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>4.1.0</version> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.4.193</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-annotations</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-auth</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-hdfs</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-common</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-core</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-exec</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-metastore</artifactId> <version>1.1.0</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.3</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.5</version> </dependency> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.5</version> </dependency> <dependency> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty</artifactId> <version>6.1.26</version> </dependency> <dependency> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-util</artifactId> <version>6.1.26</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-jexl</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>net.sf.jopt-simple</groupId> <artifactId>jopt-simple</artifactId> <version>4.3</version> </dependency> <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <version>3.0.2</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-log4j-appender</artifactId> <version>0.10.0.0</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.5</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <dependency> <groupId>io.dropwizard.metrics</groupId> <artifactId>metrics-core</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>io.dropwizard.metrics</groupId> <artifactId>metrics-jvm</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>2.10.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.36</version> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.1</version> </dependency> <dependency> <groupId>com.linkedin.pegasus</groupId> <artifactId>generator</artifactId> <version>1.15.7</version> </dependency> <dependency> <groupId>com.linkedin.pegasus</groupId> <artifactId>restli-server</artifactId> <version>1.15.7</version> </dependency> <dependency> <groupId>com.linkedin.pegasus</groupId> <artifactId>restli-tools</artifactId> <version>1.15.7</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.18</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.18</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.18</version> </dependency> <dependency> <groupId>org.yaml</groupId> <artifactId>snakeyaml</artifactId> <version>1.18</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-tools</artifactId> <version>2.0</version> </dependency>
az-core模块下面的pom.xml内容:
<parent> <artifactId>azkaban</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>az-core</artifactId> <packaging>pom</packaging> <modules> <module>../azkaban-db</module> </modules>
azkaban-db模块下面的pom.xml:
<parent> <artifactId>az-core</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../az-core/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>azkaban-db</artifactId> <packaging>pom</packaging> <modules> <module>../azkaban-common</module> </modules>
azkaban-spi的pom.xml
<parent> <artifactId>azkaban</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>azkaban-spi</artifactId> <packaging>pom</packaging> <modules> <module>../azkaban-common</module> </modules>
azkaban-common模块的pom.xml
<parent> <artifactId>azkaban</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>azkaban-common</artifactId> <packaging>pom</packaging> <modules> <module>../azkaban-web-server</module> <module>../azkaban-hadoop-security-plugin</module> </modules>
azkaban-exec-server模块的pom.xml
<parent> <artifactId>azkaban-hadoop-security-plugin</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../azkaban-hadoop-security-plugin/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>azkaban-exec-server</artifactId> <packaging>pom</packaging> <modules> <module>../azkaban-solo-server</module> </modules>
azkaban-web-server模块的pom.xml
<parent> <artifactId>azkaban-common</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../azkaban-common/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>azkaban-web-server</artifactId> <packaging>pom</packaging> <modules> <module>../azkaban-solo-server</module> </modules>
azkaban-hadoop-security-plugin模块的pom.xml
<parent> <artifactId>azkaban-common</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../azkaban-common/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <packaging>pom</packaging> <artifactId>azkaban-hadoop-security-plugin</artifactId> <modules> <module>../azkaban-exec-server</module> </modules>
azkaban-solo-server模块的pom.xml
<parent> <artifactId>azkaban-common</artifactId> <groupId>com.gavin</groupId> <version>1.0</version> <relativePath>../azkaban-common/pom.xml</relativePath> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>azkaban-solo-server</artifactId> <packaging>pom</packaging>
设置完成后,再在Project Structure里面的Modules里面添加模块依赖。模块依赖+Maven依赖都OK,Build 和Run Project是没问题的。(所有的test模块都可以去掉。选择Project Structure里面的某个Module,切换到Sources页签,取消Tests文件夹的标记即可)
azkaban-common模块
该模块是公共模块,供其它模块调用。包含在启动前数据库信息的检查。是否缺失表,是否需要执行更新等脚本。
azkaban-spi模块
azkaban元数据存储接口及其Exception类。azkaban-az-core模块
定义一些常量(属性名,默认值等)的类Constants。一些通用工具。配置文件定义,读取,JSON的读取,及cron表达式的解析。
azkaban-db模块
提供数据库访问的一些方法。数据库的初始化,检查是否需要升级等。
初始化SQL脚本。
azkaban-hadoop-security-plugin模块
提供hadoop访问相关的模块,支持集群
kerberos验证。
需要在配置文件里面设置hadoop相关的一些参数。如:
hadoop.home,
hadoop.conf.dir或者,设置
HADOOP_HOME,
HADOOP_CONF_DIR等参数。
azkaban-web-server模块
azkaban的web-server单独模块入口main:
azkaban.webapp.AzkabanWebServer.
此入口main方法主要逻辑代码:
所有的输出和错误信息都输出到log4j里.
StdOutErrRedirect.redirectOutAndErrToLog();
加载conf目录下的azkaban.properties 和 azkaban.private.properties 两个文件,获取用户配置的系统参数
Props azkabanSettings = AzkabanServer.loadProps(args);
构建Azkaban的web服务,Jetty提供的Server服务对象.
webServer.prepareAndStartServer();,
getTriggerManager().start();,
azkaban.webapp.WebServerProvider.get(){...final Server server = new Server();...}
是否采用ssl,由配置参数jetty.use.ssl的值确定,如果为true,则访问的时候需要用https,否则默认为http服务。程序里面默认jetty.use.ssl=true。(如果此配置属性不存在)
final boolean useSsl = this.props.getBoolean("jetty.use.ssl", true);
构建Context。位于configureRoutes()方法:
final Context root = new Context(this.server, "/", Context.SESSIONS);
configureRoutes()方法主要用于获取静态资源信息。
启动服务。
this.server.start();
最后还定义了一个ShutdownHook,用于在进程挂掉的时候打印当时的进程资源利用情况。
Runtime.getRuntime().addShutdownHook(new Thread(){...})
azkaban-exec-server模块
azkaban的executor-server单独模块入口main:
azkaban.execapp.AzkabanExecutorServer。
此入口main方法主要逻辑:
初始化加载过程和web-server一样,所有的输出和错误信息都输出到log4j里
StdOutErrRedirect.redirectOutAndErrToLog();
加载conf目录下的配置文件信息。
final Props props = AzkabanServer.loadProps(args);
然后启动
azkabanExecutorServer.start();
最后也定义了一个ShutdownHook,用于在进程挂掉的时候打印当时的进程资源利用情况。
Runtime.getRuntime().addShutdownHook(new Thread(){...})
azkaban-solo-server模块
入口main:azkaban.soloserver.AzkabanSingleServer.
此入口main方法主要逻辑:
加载默认配置。
if(args.length== 0){args = prepareDefaultConf();}
根据配置,检查数据库信息,是否需要,创建,更新等。
AzkabanDatabaseUpdater.runDatabaseUpdater(props, scriptDir, updateDB);
启动web和exec server。
AzkabanExecutorServer.launch(this.executor);
此模块比较简单,就AzkabanSingleServer一个类,大致过程就这样。
权限定义在Permission.Type枚举中
<azkaban-users> <user username="admin" password="admin" roles="admin" groups="admin" /> <user username="read" password="read" roles="read" /> <user username="exec" password="exec" groups="g_e" roles="read,execute,"/> <user username="manager" password="manager" groups="g_rw" /> <group name="admin" roles="admin"/> <group name="g_r" roles="read"/> <group name="g_rw" roles="read,write"/> <group name="g_e" roles="execute"/> <role name="admin" permissions="ADMIN"/> <role name="metrics" permissions="METRICS"/> <role name="read" permissions="READ"/> <role name="write" permissions="WRITE"/> <role name="execute" permissions="EXECUTE"/> <role name="schdl" permissions="SCHEDULE"/> <role name="ctpjs" permissions="CREATEPROJECTS"/> <role name="upldpjs" permissions="UPLOADPROJECTS"/> </azkaban-users>
相关文章推荐
- 从源码安装Mysql/Percona 5.5
- 作为资深产品经理,我是如何选择一本书的?
- java.util.concurrent 学习(一)
- 浅析Ruby的源代码布局及其编程风格
- asp.net 抓取网页源码三种实现方法
- JS小游戏之仙剑翻牌源码详解
- JS小游戏之宇宙战机源码详解
- 深入浅析knockout源码分析之订阅
- jQuery源码解读之extend()与工具方法、实例方法详解
- jQuery源码分析之jQuery中的循环技巧详解
- 本人自用的global.js库源码分享
- java中原码、反码与补码的问题分析
- Java写入写出Excel操作源码分享
- 在Java8与Java7中HashMap源码实现的对比
- ASP.NET使用HttpWebRequest读取远程网页源代码
- 阅读EnumSet抽象类源码
- PHP网页游戏学习之Xnova(ogame)源码解读(六)
- C#获取网页HTML源码实例
- PHP网页游戏学习之Xnova(ogame)源码解读(八)