牛客网-华为-2020届校园招聘上机考试-软件类机考-3

题目描述: Apache Hadoop YARN是一种新的Hadoop资源管理器,主要部件为resource manager和node manager。resource manager使用有限状态机维护有状态对象的生命周期。 RmAppAttempt是resource manager中用于维护一个 Application运行尝试的生命周期的数据结构,当某个事件发生时RmAppAttempt会根据当前状态进行状态迁移,同时触发一个其余行为。RmAppAttempt相关状态和事件简述以下:node

  1. RmApp发送start事件建立RmAppAttempt,初始化后,状态迁移为submitted。
  2. RmAppAttempt在submitted状态下收到资源调度器(ResourceScheduler)发来的app_accepted事件,状态迁移为scheduled。
  3. RmAppAttempt在scheduled状态下收到RmContainer发来的container_allocated事件,状态迁移为allocated。
  4. RmAppAttempt在scheduled状态下收到ApplicationMasterLauncher发来的launched事件,状态迁移为running。
  5. RmAppAttempt在running状态下收到ResourceScheduler发来的finished事件,状态迁移为finished。
  6. 在RmAppAttempt运行过程当中(不含finished状态),当收到来自客户端的杀死应用程序的命令,RmApp向RmAppAttempt发送kill事件,RmAppAttempt收到后,状态迁移到killed状态。

请编写一段程序模拟实现RmAppAttempt状态机,接受一段连续事件输入,输出每一个事件处理后yarn中对应RmAppAttempt对象的状态。数据结构

输入描述: 模拟RmAppAttempt状态机,接收一段连续事件输入 输入接口:(事件间用空格分隔) 事件源|RmAppAttempt对象|事件 事件源:RmApp、ResourceScheduler、ApplicationMasterLauncher、RmContainer 事件:start、app_accepted、container_allocated、launched、finished、killapp

输出描述: 输出接口:(输出结果用分毫;分隔) RmAppAttempt对象|状态 状态:submitted、scheduled、allocated、running、finished、killed 无效输入经过状态机过滤,不须要任何输出oop

示例1 输入: mApp|RmAppAttempt_001|start RmApp|RmAppAttempt_002|start RmApp|RmAppAttempt_001|kill 输出: RmAppAttempt_001|submitted;RmAppAttempt_002|submitted;RmAppAttempt_001|killed; <br><br>对象

----------------2019.03.20------------------- 上机考试的时候,由于只剩下20min左右时间作这道题,来不及写完,只写了一部分代码。待以后完善了再来更新。接口

相关文章
相关标签/搜索