Jstorm Topology Submission Service side

Source: Internet
Author: User

topology before the submission will determine whether there is a job with the same name in the cluster, if there is a commit failure, if not, it will increase the number of cluster commits submittedcount, each commit succeeds, the variable will add 1, and then the job will be assigned an ID, the following rule is generated:
public static string Topologynametoid (string topologyname, int counter) {    return topologyname + "-" + Counter + "-" + Timeutils.current_time_secs ();} <span style= "font-family: ' Courier New '; Background-color:rgb (255, 255, 255); " > </span>
Therefore, we can judge the success of the cluster job from the job ID, the time of submission, and the job name, if we do not specify the number of Acker, the verification of the topology itself is more detailed:
1. Is the component ID legal
2. If there is an ID with the same name
3, Woker number is legal, less than 0 or null
4. Ack quantity Check same as worker
public void Submittopologywithopts (String topologyname,string uploadedjarlocation, String jsonconf,stormtopology Topology, Submitoptions options) throws Alreadyaliveexception, Invalidtopologyexception,topologyassignexception, texception {log.info ("Receive" + Topologyname + ", uploadedjarlocation:" + uploadedjarlocation);//@@@ Move Validate Topol Ogyname in client Codetry {//verifies if there is a job with the same name checktopologyactive (data, Topologyname, false) in the cluster;} catch ( Alreadyaliveexception e) {log.info (Topologyname + "is already exist"); throw e;} catch (Throwable e) {log.info ("Failed to check whether topology was alive or not", e); throw new Texception (e);} Number of successful commits plus 1int counter = Data.getsubmittedcount (). Incrementandget (); String Topologyid = common.topologynametoid (topologyname, counter); try {//adjust related configuration, add some default configuration items Map<object, object> serializedconf = (Map<object, object>) Jstormutils.from_json (jsonconf); if (serializedconf = = null) {LOG.warn (" Failed to serialized Configuration "); throw new InvalidtopologyexCeption ("Failed to Serilaze Topology Configuration");} Serializedconf.put (config.topology_id, Topologyid); Serializedconf.put (Config.topology_name, topologyname); Map<object, object> stormconf;stormconf = nimbusutils.normalizeconf (conf, serializedconf,topology); Map<object, object> totalstormconf = new Hashmap<object, object> (conf); Totalstormconf.putall (stormConf); Stormtopology normalizedtopology = Nimbusutils.normalizetopology (stormconf, topology, false);//check ID, field legitimacy, Worker and Acker quantity legality Common.validate_basic (Normalizedtopology, Totalstormconf,topologyid);//don ' t need generate real Topology, so skip common.system_topology//common.system_topology (totalstormconf, topology); Stormclusterstate stormclusterstate = Data.getstormclusterstate ();//Create/local-dir/nimbus/topologyid/xxxx files/ /Copy jar To/local-dir/nimbus/topologyid/stormjar.jarsetupstormcode (conf, Topologyid, Uploadedjarlocation, stormconf,normalizedtopology);//Generate taskinfo for every bolts or spout in zk//create corresponding Znode for each component and hold the corresponding data as follows:/****{1=taskinfo[componentid=__acker,componenttype=bolt], 2=taskinfo[componentid= Step1bolt,componenttype=bolt], 3=taskinfo[componentid=step1bolt,componenttype=bolt], 4=TaskInfo[componentId= Step1bolt,componenttype=bolt], 5=taskinfo[componentid=step1bolt,componenttype=bolt], 6=TaskInfo[componentId= Step1bolt,componenttype=bolt], 7=taskinfo[componentid=step1bolt,componenttype=bolt], 8=TaskInfo[componentId= Spout,componenttype=spout], 9=TASKINFO[COMPONENTID=SPOUT,COMPONENTTYPE=SPOUT]}**///ZK's directory structure is as follows://[zk:localhost : 2181 (CONNECTED) ls/jstorm/tasks/test-3-1421404402//[3, 2, 1, 6, 5, 4]setupzktaskinfo (conf, Topologyid, Stormclust erstate)//Make assignments for a topologylog.info (' Submit for ' + Topologyname + ' with conf ' + serializedconf);//Start task here Distribution, task distribution is done by topologyassign, this step is simply to create an event object into the queue, and then return//Real task distribution is handled by other threads, so it returns faster here, unless the queue is full// Servicehandler makeassignment (Topologyname, Topologyid, Options.get_initial_status ());} catch (Failedassigntopologyexception E{//exception handling code is not affixed, forgive}} 
private void Makeassignment (String topologyname, String Topologyid, Topologyinitialstatus status) throws failedassigntopologyexception {topologyassignevent assignevent = new Topologyassignevent (); Assignevent.settopologyid (Topologyid); Assignevent.setscratch (false); Assignevent.settopologyname (TopologyName); Assignevent.setoldstatus (Thrift.topologyinitialstatustostormstatus (status));        This is put back immediately in the event queue, so the commit is fast Topologyassign.push (Assignevent), Boolean issuccess = Assignevent.waitfinish (); if ( Issuccess = = True) {Log.info ("Finish submit for" + Topologyname);} else {throw new Failedassigntopologyexception (Assignevent.geterrormsg ());}}


Jstorm Topology Submission Service side

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.