JStorm之Topology提交服務端

來源:互聯網
上載者:User

標籤:storm   jstorm   雲端運算   即時計算   hadoop   

  topology提交前會先判斷叢集中是否存在同名作業,如果存在在提交失敗,如果沒有則會增加叢集提交次數SubmittedCount,每次提交成功,該變數都會加1,然後會為該作業分配一個id,建置規則如下:
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>
因此我們從作業id中就可以判斷叢集作業成功提交次數、提交時間、還有作業名稱了,如果我們沒有指定acker數量,對topology本身的校正比較細緻:
1、組件id是否合法
2、是否存在同名id
3、woker數量是否合法,小於0或null
4、ack數量校正同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 topologyname in client codetry {//校正叢集中是否存在同名作業checkTopologyActive(data, topologyname, false);} catch (AlreadyAliveException e) {LOG.info(topologyname + " is already exist ");throw e;} catch (Throwable e) {LOG.info("Failed to check whether topology is alive or not", e);throw new TException(e);}//成功提交次數加1int counter = data.getSubmittedCount().incrementAndGet();String topologyId = Common.TopologyNameToId(topologyname, counter);try {//調整相關配置,增加一些預設配置項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);// 校正ID、欄位合法性,worker和acker數量合法性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 bolt or spout in ZK// 為每個組件建立相應znode,並存放相應資料,資料如下:/****{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的目錄結構如下://[zk: localhost:2181(CONNECTED) 20] ls /jstorm/tasks/test-3-1421404402//   [3, 2, 1, 6, 5, 4]setupZkTaskInfo(conf, topologyId, stormClusterState);// make assignments for a topologyLOG.info("Submit for " + topologyname + " with conf "+ serializedConf);//這裡開始任務分發,任務分發由TopologyAssign完成,這步僅僅是建立一個事件對象放入隊列中,然後返回//真正的任務分發由其他線程來操作,所以這裡返回比較快,除非隊列是滿的// ServiceHandler中makeAssignment(topologyname, topologyId, options.get_initial_status());} catch (FailedAssignTopologyException e) {//異常處理代碼就不貼了,見諒}}
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));        //這裡放入事件隊列中立即返回,所以提交是很快的TopologyAssign.push(assignEvent);boolean isSuccess = assignEvent.waitFinish();if (isSuccess == true) {LOG.info("Finish submit for " + topologyName);} else {throw new FailedAssignTopologyException(assignEvent.getErrorMsg());}}


JStorm之Topology提交服務端

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.