Flume是一个分布式的日志收集系统,提供了很好的配置管理。今天分析一下页面提交配置的详细过程。
1,前台部分,首先,在flumeconfig.jsp页面中,提供了配置管理的表单,详细如下,
<h2>Configure a single node</h2> <form method=post action="command.jsp"> <table> <tr> <td>Configure node:</td> <td> <select name="nodeChoice"> <option value="">Choose from list</option> <% for (String s : FlumeMaster.getInstance().getKnownNodes()) { %> <option value="<%= s %>"><%= s %></option> <% } %> </select> </td> </tr> <tr> <td> or specify another node: </td> <td> <input type="text" name="node" size=128 /> </td> </tr> <tr> <td>Source: </td> <td><input type="text" name="source" size=128/> </td> </tr> <tr> <td>Sink:</td> <td><input type="text" name="sink" size=128/> </td> </tr> <tr> <td> <input type="submit"/> </td> </tr> </form> </table>
当填好表单,并提交表单,该页面会跳转到command.jsp中进行处理,command.jsp详细如下:
<jsp:useBean id="cmd" class="com.cloudera.flume.master.ConfigCommand" scope="request"/> <jsp:setProperty name="cmd" property="*"/> <html> <link rel="stylesheet" type="text/css" href="/flume.css"> <meta HTTP-EQUIV="REFRESH" content="5;url=flumeconfig.jsp"/> <body> <h2>Command received</h2> You entered<br> Node: <%= cmd.getNode() %> <br> Source: <%= cmd.getSource() %> <br> Sink: <%= cmd.getSink() %> <br> <p>Please wait for a few seconds, and we'll redirect you back to <a href="flumemaster.jsp">the Master overview</a>. </body> </html> <% FlumeMaster.getInstance().submit(cmd.toCommand()); %>
从command.jsp代码中,可以看出flumeconfig.jsp提交过来的表单值赋给了ConfigCommand对象cmd。然后,调用FlumeMaster对象提交该命令。其中,cmd.toCommand()代码如下:
public Command toCommand() { return new Command("config", node != null ? node : nodeChoice, source, sink); }
config是该命令的名称,后面是该命令的参数。将ConfigCommand对象转换成Command对象。在Flume的命令管理中,会将各种各样的不同的命令转换成Command对象,然后CommandManager对象管理这些Command,类似于Command是所有其他具体Command的超集,例如ConfigCommand,LoadConfigCommand等。
2,后台部分
后台部分从 FlumeMaster.getInstance().submit(cmd.toCommand());代码开始,从下面代码可以看出FlumeMaster将会调用CmmandManager对象来提交从前台提交过来的命令,并处理命令。
public long submit(Command cmd) { return cmdman.submit(cmd); //cmdman其实是CommandManager对象 }从以上分析可以看出,Flume的提交配置非常简单,清晰。下节将会讲解CommandManager。