csdn夏令营week2

一 本周任务

1. 提交topology(以源代码中的example为例)

  • 从github上pull源代码
  • 添加依赖的jar
  • 利用mvn命令编译 
  • 提交topology

2. 解读源代码

  • 建立nimbus
    • 首先我们从程序的入口即bin/jstorm出发,注意到有以下函数
    • def nimbus():
          """Syntax: [jstorm nimbus]
      
          Launches the nimbus daemon. This command should be run under 
          supervision with a tool like daemontools or monit. 
      
          See Setting up a Storm cluster for more information.
          (https://github.com/alibaba/jstorm/wiki/JStorm-Chinese-Documentation)
          """
          cppaths = [JSTORM_CONF_DIR]
          nimbus_classpath = confvalue("nimbus.classpath", cppaths)
          childopts = confvalue("nimbus.childopts", cppaths) + (" -Dlogfile.name=nimbus.log -Dlog4j.configuration=File:%s/conf/jstorm.log4j.properties "  %JSTORM_DIR)
          #childopts = confvalue("nimbus.childopts", cppaths) + (" -Dlogfile.name=nimbus.log -Dlogback.configurationFile=%s/conf/cluster.xml "  %JSTORM_DIR)
          exec_storm_class(
              "com.alibaba.jstorm.daemon.nimbus.NimbusServer", 
              jvmtype="-server", 
              extrajars=(cppaths+[nimbus_classpath]), 
              childopts=childopts)
    • 该段程序分为两部分,第一部分获取配置,第二部分传入配置及参数执行(exec_storm_class)
    • 最后实际执行的是java -server xxxxx com.alibaba.jstorm.daemon.nimbus.NimbusServer,中间的xxxx是一些jvm的配置和jstorm的配置
    • 于是我们转到 com.alibaba.jstorm.daemon.nimbus.NimbusServer所指的代码段中
    • 	public static void main(String[] args) throws Exception {
      		// read configuration files
      		@SuppressWarnings("rawtypes")
      		Map config = Utils.readStormConfig();
      		
      		JStormServerUtils.startTaobaoJvmMonitor();
      		
      		NimbusServer instance = new NimbusServer();
      
      		INimbus iNimbus = new DefaultInimbus();
      
      		instance.launchServer(config, iNimbus);
      
      	}
    • main函数中实例化了一个NumbusServer的对象,并且在最后执行了launchServer的方法
    • 	private void launchServer(final Map conf, INimbus inimbus)  {
      		LOG.info("Begin to start nimbus with conf " + conf);
      
      		try {
      			// 1. check whether mode is distributed or not
      			StormConfig.validate_distributed_mode(conf);
      			
      			createPid(conf);
      	
      			initShutdownHook();
      	
      			inimbus.prepare(conf, StormConfig.masterInimbus(conf));
      	
      			data = createNimbusData(conf, inimbus);
      	
      			initFollowerThread(conf);
      			
      			int port = ConfigExtension.getNimbusDeamonHttpserverPort(conf);
      			hs = new Httpserver(port);
      			hs.start();
      			
      			initContainerHBThread(conf);
      			
      			while (!data.isLeader())
      				Utils.sleep(5000);
      			
      			init(conf);
      		}catch (Throwable e) {
      			LOG.error("Fail to run nimbus ", e);
      		}finally {
      			cleanup();
      		}
      		
      		LOG.info("Quit nimbus");
      	}
    • 在该部分,程序执行了initShutdownHook方法以清理无用的线程,其后为nimbus建立数据区,然后建立并初始化了另一个线程Follower thread。接着读取端口进一步配置Nimbus,直到运行结束后清理,并向LOG文件写入信息。
  • 建立supervisor
  • 提交topology‘

二 心得感悟

  • 编译example的源码时需要加额外的依赖
  • 读源代码一般从程序的入口切入,同时需要从宏观上把握
  • log文件很有用

三 下周任务

  • 深入理解源代码
  • 在合适的地方加入监测模块(先实现框架)
  • 然后增加进程结束反馈机制
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值