Implement information viewing and control of storm

Source: Internet
Author: User

There is a need for the company recently. It is necessary to get the execution information of storm cluster and topology related submission and control on the backend application server in real time, and after several days analysis of Storm UI and Cmd source code, it is concluded that these functions can be realized through its thrift interface call. First download a thrift library for encoding and installation. About thrift can see this place.

After installation, copy the Storm.thrift from the storm source code to the Thrift folder.

Input:

Hrift-gen CPP Storm.thrift

Will get a gen-cpp folder, which is the C + + implementation of Thrift script first.

Let's look at the Storm.thrift file interface first:

Service Nimbus {//topology upload interface 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 package Upload interface 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);  Gets the configuration information for the Nimbus string getnimbusconf ();  Get storm cluster execution information clustersummary getclusterinfo ();  Gets the execution status information of the topology Topologyinfo Gettopologyinfo (1:string ID); Gets the Topology object information string gettopologyconf (1:string ID);  Stormtopology gettopology (1:string ID); Stormtopology getusertopology (1:string ID);}
Once the C + + file is generated, we are able to invoke its interface because the Thrift C + + framework is implemented using the Boost library and must be installed with boost library dependencies. The implementation of the code such as the following:

 #define HAVE_NETDB_H//macros using the network module must open # 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)); Tframedtransportboost::shared_ptr<tprotocol> Tprotocol (New Tbinaryprotocol (Ttransport)) must be used here; try{//Create a Nimbus client object Nimbusclient clients (Tprotocol);//Open channel Ttransport->open (); Clustersummary summ;std::string conf;//RPC call to storm. Direct access to information, synchronized.    

client.getnimbusconf (conf); Client.getclusterinfo (Summ);//Close channel ttransport->close (); }catch (texception &tx) {printf ("InvalidOperation:%s\n", Tx.what ()); }}

The above code can be directly obtained Nimbus configuration and cluster information. Other interfaces and so on. It is noteworthy that the operator < functions in the Storm_types.h file generated by Storm.thrift to C + + are not implemented. So you must manually join the implementation. Otherwise the compilation will be problematic.

Not only C + + can achieve storm control, PHP and other languages can also be implemented, as long as the thrift support is OK. Interested to be able to achieve a try.













Implement information viewing and control of storm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.