public WebResponse beWebExecute(MasterContext context, WebRequest req) { // 判断job是否已经在运行中,或者在队列中 // 如果在,抛出异常,已经在执行中 // 如果不在,将该job放入等待队列 SocketLog.info("receive web debug request,rid=" + req.getRid() + ",debugId=" + req.getId()); String debugId = req.getId(); for (JobElement e : new ArrayList<JobElement>(context.getDebugQueue())) { if (e.getJobID().equals(debugId)) { WebResponse resp = WebResponse.newBuilder() .setRid(req.getRid()) .setOperate(WebOperate.ExecuteDebug) .setStatus(Status.ERROR) .setErrorText("已经在队列中,无法再次运行") .build(); return resp; } } DebugHistory debug = context.getDebugHistoryManager().findDebugHistory(debugId); context.getMaster().debug(debug); WebResponse resp = WebResponse.newBuilder() .setRid(req.getRid()) .setOperate(WebOperate.ExecuteDebug) .setStatus(Status.OK) .build(); SocketLog.info("send web debug response,rid=" + req.getRid() + ",debugId=" + debugId); return resp; }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { final Channel channel = ctx.getChannel(); SocketMessage sm = (SocketMessage) e.getMessage(); if (sm.getKind() == Kind.REQUEST) { final Request request = Request.newBuilder().mergeFrom(sm.getBody()).build(); if (request.getOperate() == Operate.HeartBeat) { beHeartBeat.beHeartBeat(context, channel, request); } } else if (sm.getKind() == Kind.WEB_REUQEST) { final WebRequest request = WebRequest.newBuilder().mergeFrom(sm.getBody()).build(); if (request.getOperate() == WebOperate.ExecuteJob) { completionService.submit( new Callable<ChannelResponse>() { public ChannelResponse call() throws Exception { return new ChannelResponse(channel, beWebExecute.beWebExecute(context, request)); } }); } else if (request.getOperate() == WebOperate.CancelJob) { completionService.submit( new Callable<ChannelResponse>() { public ChannelResponse call() throws Exception { return new ChannelResponse(channel, beWebCancel.beWebCancel(context, request)); } }); } else if (request.getOperate() == WebOperate.UpdateJob) { completionService.submit( new Callable<ChannelResponse>() { public ChannelResponse call() throws Exception { return new ChannelResponse(channel, beUpdate.beWebUpdate(context, request)); } }); } else if (request.getOperate() == WebOperate.ExecuteDebug) { completionService.submit( new Callable<ChannelResponse>() { public ChannelResponse call() throws Exception { return new ChannelResponse(channel, beDebug.beWebExecute(context, request)); } }); } } else if (sm.getKind() == Kind.RESPONSE) { for (ResponseListener lis : new ArrayList<ResponseListener>(listeners)) { lis.onResponse(Response.newBuilder().mergeFrom(sm.getBody()).build()); } } else if (sm.getKind() == Kind.WEB_RESPONSE) { for (ResponseListener lis : new ArrayList<ResponseListener>(listeners)) { lis.onWebResponse(WebResponse.newBuilder().mergeFrom(sm.getBody()).build()); } } super.messageReceived(ctx, e); }