惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
GbyAI
GbyAI
P
Proofpoint News Feed
B
Blog
MyScale Blog
MyScale Blog
V
V2EX
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
量子位
Jina AI
Jina AI
博客园 - 叶小钗
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
罗磊的独立博客
L
LangChain Blog
I
InfoQ
云风的 BLOG
云风的 BLOG
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
人人都是产品经理
人人都是产品经理
小众软件
小众软件
V
Visual Studio Blog
月光博客
月光博客
The Cloudflare Blog
雷峰网
雷峰网

博客园 - mengfanrong

防止WordPress利用xmlrpc.php进行暴力破解以及DDoS 汇编语言学习笔记(5)——[bx]和loop 机房收费系统——项目开发计划书 jquery实现返回基部案例效果 【LeetCode】Power of Two bash可改动的环境变量 博主-橄榄山软件创始人-其人其事 构造函数模式自己定义js对象 UVA1626 - Brackets sequence(区间DP--括号匹配+递归打印) CentOS安装NodeJS及Express开发框架 C# 中堆与栈的浅记 RabbitMQ学习笔记 【数据库摘要】10_Sql_Create_Index win10 + VS2010 + OpenCV2.4.10重编译OpenCV开发环境搭建 再看《阿甘正传》 Swift开发iOS项目实战视频教程(二)---图片与动画 360面试小结 System.ServiceModel.CommunicationException: 接收HTTP 响应时错误发生 jQuery上传文件
用C/C++实现对STORM的执行信息查看和控制
mengfanrong · 2016-04-23 · via 博客园 - mengfanrong

近期公司有个需求。须要在后端应用server上实时获取STORM集群的执行信息和topology相关的提交和控制,经过几天对STORM UI和CMD源代码的分析,得出能够通过其thrift接口调用实现这些功能。先下载一个thrift库进行编码和安装。关于thrift能够參见这个地方

安装完毕后,从STORM源代码中将storm.thrift复制到thrift文件夹下。

输入:

hrift -gen cpp storm.thrift

会得到一个gen-cpp文件夹,里面就是thrift先关脚本的C++实现。

我们先看storm.thrift文件接口:

service Nimbus 
{
  //TOPOLOGY上传接口
  void submitTopology(1: string name, 2: string uploadedJarLocation, 3: string jsonConf, 4: StormTopology topology);
  void submitTopologyWithOpts(1: string name, 2: string uploadedJarLocation, 3: string jsonConf, 4: StormTopology topology, 5: SubmitOptions options);
  void killTopology(1: string name);
  void killTopologyWithOpts(1: string name, 2: KillOptions options) throws (1: NotAliveException e);
  void activate(1: string name) ;
  void deactivate(1: string name);
  void rebalance(1: string name, 2: RebalanceOptions options);
 
  //TOPOLOGY JAR包上传接口
  string beginFileUpload();
  void uploadChunk(1: string location, 2: binary chunk);
  void finishFileUpload(1: string location);
  string beginFileDownload(1: string file);
  binary downloadChunk(1: string id);

  //获取NIMBUS的配置信息
  string getNimbusConf();
  //获取STORM集群执行信息
  ClusterSummary getClusterInfo();
  //获取TOPOLOGY的执行状态信息
  TopologyInfo getTopologyInfo(1: string id);
  //获取TOPOLOGY对象信息
  string getTopologyConf(1: string id);
  StormTopology getTopology(1: string id);
  StormTopology getUserTopology(1: string id);
}

生成C++文件后,我们就能够对其接口进行调用,因为thrift c++框架是使用boost库实现的,必须安装boost库依赖。实现的代码例如以下:

#define HAVE_NETDB_H  //使用网络模块的宏必须打开
#include "Nimbus.h"
#include "storm_types.h"

#include <string>
#include <iostream>
#include <set>

#include <transport/TSocket.h>  
#include <transport/TBufferTransports.h>  
#include <protocol/TBinaryProtocol.h> 
int test_storm_thrift()
{
	boost::shared_ptr<TSocket> tsocket(new TSocket("storm-nimbus-server", 6627));
	boost::shared_ptr<TTransport> ttransport(new TFramedTransport(tsocket, 1024 * 512)); //此处必须使用TFramedTransport
	boost::shared_ptr<TProtocol> tprotocol(new TBinaryProtocol(ttransport));
 try{
	//创建一个nimbus客户端对象
	NimbusClient client(tprotocol);
	//打开通道
    ttransport->open();

	ClusterSummary summ;
	std::string conf;
	//对STORM的RPC调用。直接获取信息,同步进行的。

client.getNimbusConf(conf); client.getClusterInfo(summ); //关闭通道 ttransport->close(); }catch(TException &tx){ printf("InvalidOperation: %s\n", tx.what()); } }

以上代码就能够直接获取nimbus的配置和集群信息。其它接口以此类推。值得注意的是storm.thrift to C++生成的storm_types.h文件中当中operator < 函数都未实现。所以必须手动进行加入实现。否则编译会有问题。

不只C++能够实现STORM的控制,PHP和其它的语言也能够实现,只要thrift支持就OK。有兴趣能够实现一下试试看。