提交 af17959a 编写于 作者: L leon.li

fix seval bugs

上级 a45a39ed
......@@ -2,6 +2,7 @@ package com.dianping.cat.report.page.alteration;
public enum Action implements org.unidal.web.mvc.Action {
INSERT("insert"),
VIEW("view");
private String m_name;
......
package com.dianping.cat.report.page.alteration;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.ServletException;
import com.dianping.cat.Cat;
import com.dianping.cat.home.dal.report.Alteration;
import com.dianping.cat.home.dal.report.AlterationDao;
import com.dianping.cat.home.dal.report.AlterationEntity;
import com.dianping.cat.report.ReportPage;
import org.unidal.dal.jdbc.DalException;
import org.unidal.lookup.annotation.Inject;
import org.unidal.web.mvc.PageHandler;
import org.unidal.web.mvc.annotation.InboundActionMeta;
import org.unidal.web.mvc.annotation.OutboundActionMeta;
import org.unidal.web.mvc.annotation.PayloadMeta;
import com.dianping.cat.Cat;
import com.dianping.cat.home.dal.report.Alteration;
import com.dianping.cat.home.dal.report.AlterationDao;
import com.dianping.cat.home.dal.report.AlterationEntity;
import com.dianping.cat.report.ReportPage;
public class Handler implements PageHandler<Context> {
@Inject
private JspViewer m_jspViewer;
@Inject
private AlterationDao m_alterationDao;
private SimpleDateFormat m_sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
@PayloadMeta(Payload.class)
......@@ -38,66 +41,183 @@ public class Handler implements PageHandler<Context> {
@Override
@OutboundActionMeta(name = "alteration")
public void handleOutbound(Context ctx) throws ServletException, IOException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Model model = new Model(ctx);
Payload payload = ctx.getPayload();
Action action = payload.getAction();
String type = payload.getType();
String domain = payload.getDomain();
String hostname = payload.getHostname();
switch(action){
case INSERT:
switch (action) {
case INSERT:
String title = payload.getTitle();
String ip = payload.getIp();
String user = payload.getUser();
String content = payload.getContent();
String url = payload.getUrl();
String date = payload.getDate();
Alteration alt = new Alteration();
Date date = payload.getAlterationDate();
Alteration alt = new Alteration();
alt.setType(type);
alt.setDomain(domain);
alt.setTitle(title);
alt.setIp(ip);
alt.setUser(user);
alt.setContent(content);
alt.setUrl(url);
alt.setUrl(url);
alt.setHostname(hostname);
alt.setDate(date);
try {
alt.setDate(m_sdf.parse(date));
m_alterationDao.insert(alt);
model.setStatus("{\"status\":200}");
} catch (Exception e) {
Cat.logError(e);
model.setStatus("{\"status\":500}");
model.setStatus("{\"status\":500}");
}
break;
case VIEW:
String startTime = payload.getStartTime();
String endTime = payload.getEndTime();
long granularity = payload.getGranularity();
List<Alteration> alts;
Date startTime = payload.getStartTime();
Date endTime = payload.getEndTime();
List<AltBarrel> barrels = new ArrayList<AltBarrel>();
try {
m_alterationDao.findByDtdh(m_sdf.parse(startTime), m_sdf.parse(endTime), type, domain, hostname, AlterationEntity.READSET_FULL);
model.setViewDataSuccess(true);
alts = m_alterationDao
.findByDtdh(startTime, endTime, type, domain, hostname, AlterationEntity.READSET_FULL);
} catch (Exception e) {
Cat.logError(e);
model.setViewDataSuccess(false);
break;
}
System.out.println(alts.size());
/*
long startMill = startTime.getTime();
long endMill = endTime.getTime() - granularity;
List<Alteration> tmpAlts = new ArrayList<Alteration>();
int tmp = 0,
length = alts.size();
while (startMill <= endMill) {
endMill -= granularity;
for (int i = tmp; i < alts.size() && alts.get(i).getDate().getTime() > endMill; i++) {
tmp++;
tmpAlts.add(alts.get(i));
}
if (tmp >= length)
break;
if (tmpAlts.size() > 0)
barrels.add(new AltBarrel(sdf.format(new Date(endMill)), sdf.format(new Date(endMill + granularity)),
tmpAlts));
}
int l = barrels.size();
if (l > 10) {
barrels = barrels.subList(0, 10);
}
model.setBarrels(barrels);
*/
long startMill = startTime.getTime();
long endMill = endTime.getTime();
Map<Long, List<Alteration>> alterations = new TreeMap<Long, List<Alteration>>();
for (Alteration alt_genBarrel : alts) {
long barTime = alt_genBarrel.getDate().getTime();
long key;
List<Alteration> tmpAlts_genBarrel;
if(endMill == barTime){
key = barTime - granularity;
}
if((endMill-barTime)/granularity == 0){
key = barTime;
}
else{
key = endMill - ((endMill-barTime)/granularity+1)*granularity;
}
if(alterations.get(key)==null){
alterations.put(key, new ArrayList<Alteration>());
}
tmpAlts_genBarrel = alterations.get(key);
tmpAlts_genBarrel.add(alt_genBarrel);
}
Iterator it=alterations.entrySet().iterator();
while (it.hasNext()) {
Map.Entry ent = (Map.Entry) it.next();
long key = (Long) ent.getKey();
List<Alteration> value = (List<Alteration>) ent.getValue();
barrels.add(new AltBarrel(sdf.format(new Date(key - granularity)), sdf.format(new Date(key)),
value));
}
int l = barrels.size();
System.out.println(l);
if (l > 10) {
barrels = barrels.subList(0, 10);
}
model.setBarrels(barrels);
break;
}
if(action!=null)
model.setAction(action);
else
model.setAction(Action.VIEW);
model.setAction(action);
model.setPage(ReportPage.ALTERATION);
if (!ctx.isProcessStopped()) {
m_jspViewer.view(ctx, model);
m_jspViewer.view(ctx, model);
}
}
public class AltBarrel {
private List<Alteration> alterations;
private String startTime;
private String endTime;
public AltBarrel(String startTime, String endTime, List<Alteration> tmpAlts) {
this.startTime = startTime;
this.endTime = endTime;
this.alterations = tmpAlts;
}
public List<Alteration> getAlterations() {
// TODO
int length = alterations.size();
if (length > 10) {
return alterations.subList(0, 10);
}
return alterations;
}
public void setAlterations(List<Alteration> alterations) {
this.alterations = alterations;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
}
}
......@@ -2,6 +2,7 @@ package com.dianping.cat.report.page.alteration;
public enum JspFile {
INSERT("/jsp/report/alteration/alter_insertResult.jsp"),
VIEW("/jsp/report/alteration/alter_view.jsp"),
;
......
package com.dianping.cat.report.page.alteration;
import com.dianping.cat.report.ReportPage;
import org.unidal.web.mvc.ViewModel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.dianping.cat.Constants;
import com.dianping.cat.report.page.AbstractReportModel;
import com.dianping.cat.report.page.alteration.Handler.AltBarrel;
public class Model extends AbstractReportModel<Action, Context> {
public class Model extends ViewModel<ReportPage, Action, Context> {
private String m_status;
private boolean m_isViewDataSuccess;
public boolean isViewDataSuccess() {
return m_isViewDataSuccess;
}
public void setViewDataSuccess(boolean isViewDataSuccess) {
this.m_isViewDataSuccess = isViewDataSuccess;
}
private List<AltBarrel> m_barrels;
public String getStatus() {
return m_status;
}
public void setStatus(String status) {
this.m_status = status;
m_status = status;
}
public List<AltBarrel> getBarrels() {
return m_barrels;
}
public void setBarrels(List<AltBarrel> barrels) {
m_barrels = barrels;
}
public Model(Context ctx) {
......@@ -32,4 +39,14 @@ public class Model extends ViewModel<ReportPage, Action, Context> {
public Action getDefaultAction() {
return Action.VIEW;
}
@Override
public Collection<String> getDomains() {
return new ArrayList<String>();
}
@Override
public String getDomain() {
return Constants.CAT;
}
}
package com.dianping.cat.report.page.alteration;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.dianping.cat.helper.TimeUtil;
import com.dianping.cat.report.ReportPage;
import com.dianping.cat.report.page.AbstractReportPayload;
import org.unidal.web.mvc.ActionContext;
import org.unidal.web.mvc.ActionPayload;
import org.unidal.web.mvc.payload.annotation.FieldMeta;
public class Payload implements ActionPayload<ReportPage, Action> {
public class Payload extends AbstractReportPayload<Action> {
private ReportPage m_page;
@FieldMeta("frequency")
private int m_frequency = 10;
@FieldMeta("refresh")
private boolean m_refresh = false;
@FieldMeta("fullScreen")
private boolean fullScreen = false;
@FieldMeta("op")
private Action m_action;
......@@ -22,9 +38,9 @@ public class Payload implements ActionPayload<ReportPage, Action> {
@FieldMeta("ip")
private String m_ip;
@FieldMeta("date")
private String m_date;
@FieldMeta("alterationDate")
private String m_alterationDate;
@FieldMeta("user")
private String m_user;
......@@ -34,134 +50,197 @@ public class Payload implements ActionPayload<ReportPage, Action> {
@FieldMeta("url")
private String m_url;
@FieldMeta("startTime")
private String m_startTime;
@FieldMeta("endTime")
private String m_endTime;
@FieldMeta("granularity")
private long m_granularity;
@FieldMeta("hostname")
private String m_hostname;
public String getStartTime() {
return m_startTime;
}
private SimpleDateFormat m_sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public String getType() {
return m_type;
public Payload() {
super(ReportPage.ALTERATION);
}
public void setType(String type) {
this.m_type = type;
@Override
public Action getAction() {
if (m_action == null) {
return Action.VIEW;
}else{
return m_action;
}
}
public String getTitle() {
return m_title;
public Date getAlterationDate() {
try {
return m_sdf.parse(m_alterationDate);
} catch (ParseException e) {
return new Date();
}
}
public void setTitle(String title) {
this.m_title = title;
public String getContent() {
return m_content;
}
public String getDomain() {
return m_domain;
if ("".equals(m_domain)) {
return null;
} else {
return m_domain;
}
}
public void setDomain(String domain) {
this.m_domain = domain;
public Date getEndTime() {
if (m_endTime == null || m_endTime.length() == 0) {
return new Date();
} else {
try {
return m_sdf.parse(m_endTime);
} catch (ParseException e) {
return new Date();
}
}
}
public int getFrequency() {
return m_frequency;
}
public long getGranularity() {
return m_granularity;
}
public String getHostname() {
if("".equals(m_hostname)){
return null;
}else{
return m_hostname;
}
}
public String getIp() {
return m_ip;
}
public void setIp(String ip) {
this.m_ip = ip;
public ReportPage getPage() {
return m_page;
}
public String getDate() {
return m_date;
public Date getStartTime() {
if (m_startTime == null || m_startTime.length() == 0) {
return new Date(System.currentTimeMillis() - TimeUtil.ONE_HOUR);
} else {
try {
return m_sdf.parse(m_startTime);
} catch (ParseException e) {
return new Date();
}
}
}
public void setDate(String date) {
this.m_date = date;
public String getTitle() {
return m_title;
}
public String getType() {
return m_type;
}
public String getUrl() {
return m_url;
}
public String getUser() {
return m_user;
}
public void setUser(String user) {
this.m_user = user;
public boolean isFullScreen() {
return fullScreen;
}
public String getContent() {
return m_content;
public boolean isRefresh() {
return m_refresh;
}
public void setContent(String content) {
this.m_content = content;
public void setAction(String action) {
m_action = Action.getByName(action, Action.VIEW);
}
public String getUrl() {
return m_url;
public void setAlterationDate(String alterationDate) {
m_alterationDate = alterationDate;
}
public void setUrl(String url) {
this.m_url = url;
}
public void setStartTime(String m_startTime) {
this.m_startTime = m_startTime;
public void setContent(String content) {
m_content = content;
}
public String getEndTime() {
return m_endTime;
public void setDomain(String domain) {
m_domain = domain;
}
public void setEndTime(String m_endTime) {
this.m_endTime = m_endTime;
public void setEndTime(String endTime) {
m_endTime = endTime;
}
public long getGranularity() {
return m_granularity;
public void setFrequency(int frequency) {
m_frequency = frequency;
}
public void setGranularity(long m_granularity) {
this.m_granularity = m_granularity;
public void setFullScreen(boolean fullScreen) {
this.fullScreen = fullScreen;
}
public String getHostname() {
return m_hostname;
public void setGranularity(long granularity) {
m_granularity = granularity;
}
public void setHostname(String hostname) {
this.m_hostname = hostname;
m_hostname = hostname;
}
public void setIp(String ip) {
m_ip = ip;
}
public void setAction(String action) {
m_action = Action.getByName(action, Action.VIEW);
public void setPage(ReportPage page) {
m_page = page;
}
@Override
public Action getAction() {
return m_action;
public void setPage(String page) {
m_page = ReportPage.getByName(page, ReportPage.ALTERATION);
}
@Override
public ReportPage getPage() {
return m_page;
public void setRefresh(boolean refresh) {
m_refresh = refresh;
}
@Override
public void setPage(String page) {
m_page = ReportPage.getByName(page, ReportPage.ALTERATION);
public void setStartTime(String startTime) {
m_startTime = startTime;
}
public void setTitle(String title) {
m_title = title;
}
public void setType(String type) {
m_type = type;
}
public void setUrl(String url) {
m_url = url;
}
public void setUser(String user) {
m_user = user;
}
@Override
......
......@@ -5,15 +5,16 @@
<member name="type" field="type" value-type="String" length="64" nullable="false" />
<member name="title" field="title" value-type="String" length="128" nullable="false" />
<member name="domain" field="domain" value-type="String" length="128" nullable="false" />
<member name="ip" field="ip" value-type="String" length="128" nullable="false" />
<member name="hostname" field="hostname" value-type="String" length="128" nullable="false" />
<member name="ip" field="ip" value-type="String" length="128" />
<member name="date" field="date" value-type="Date" nullable="false" />
<member name="user" field="user" value-type="String" length="45" nullable="false" />
<member name="content" field="content" value-type="String" length="65535" />
<member name="content" field="content" value-type="String" length="65535" nullable="false" />
<member name="url" field="url" value-type="String" length="200" />
<member name="creation-date" field="creation_date" value-type="Date" nullable="false" />
<var name="key-id" value-type="int" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="ind_dom_ip" members="date ASC, domain ASC, ip ASC" />
<index name="ind_date_domain_host" members="date ASC, domain ASC, hostname ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
......
......@@ -4,9 +4,9 @@
<member name="creation-date" insert-expr="NOW()" />
<var name="start-time" value-type="Date" />
<var name="end-time" value-type="Date" />
<var name="type" value-type="String" />
<var name="domain" value-type="String" />
<var name="hostname" value-type="String" />
<param name="type" />
<param name="domain" />
<param name="hostname" />
<query-defs>
<query name="find-by-dtdh" type="SELECT" multiple="true">
<param name="start-time" />
......@@ -27,7 +27,8 @@
</IF>
<IF type='NOT_NULL' field='hostname'>
AND <FIELD name='hostname'/> = ${hostname}
</IF>
</IF>
ORDER BY <FIELD name='date'/> DESC
]]></statement>
</query>
</query-defs>
......
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html; charset=utf-8"%>
<div class="text-left text-info"></div>时间粒度 <select class="input-small" id="granularity">
<option value="1000">1 sec</option>
<option value="5000">5 sec</option>
<option value="60000">1 min</option>
<option value="300000">5 min</option>
<option value="3600000">1 hour</option>
<option value="86400000">1 day</option>
</select>
开始
<input type="text" name="startTime" id="startTime" value="<fmt:formatDate value="${payload.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>" style="height:auto" class="input-medium" placeholder="格式如:2014-02-02 00:00:00">
结束
<input type="text" name="endTime" id="endTime" value="<fmt:formatDate value="${payload.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>" style="height:auto" class="input-medium" placeholder="格式如:2014-02-02 00:00:00">
应用名
<input type="text" name="domain" id="domain" value="${payload.domain}" style="height:auto" class="input-small">
机器名
<input type="text" name="hostname" id="hostname" value="${payload.hostname}" style="height:auto" class="input-small">
<input class="btn btn-primary btn-small" value="查询"
onclick="queryNew()" type="submit">
<c:if test="${!payload.fullScreen}">
<a id="fullScreen" class='btn btn-small btn-primary' href="?fullScreen=true&refresh=${payload.refresh}&frequency=${payload.frequency}&startTime=<fmt:formatDate value="${payload.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&endTime=<fmt:formatDate value="${payload.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&granularity=${payload.granularity}">全屏</a>
</c:if>
<c:if test="${payload.fullScreen}">
<a id="fullScreen" class='btn btn-small btn-primary' href="?fullScreen=false&refresh=${payload.refresh}&frequency=${payload.frequency}&startTime=<fmt:formatDate value="${payload.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&endTime=<fmt:formatDate value="${payload.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&granularity=${payload.granularity}">全屏</a>
</c:if>
<a id="refresh10" class='btn btn-small btn-primary' href="?fullScreen=${payload.fullScreen}&refresh=true&frequency=10&startTime=<fmt:formatDate value="${payload.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&endTime=<fmt:formatDate value="${payload.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&granularity=${payload.granularity}">10秒定时刷新</a>
<a id="refresh20" class='btn btn-small btn-primary' href="?fullScreen=${payload.fullScreen}&refresh=true&frequency=20&startTime=<fmt:formatDate value="${payload.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&endTime=<fmt:formatDate value="${payload.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&granularity=${payload.granularity}">20秒定时刷新</a>
<a id="refresh30" class='btn btn-small btn-primary' href="?fullScreen=${payload.fullScreen}&refresh=true&frequency=30&startTime=<fmt:formatDate value="${payload.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&endTime=<fmt:formatDate value="${payload.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>&granularity=${payload.granularity}">30秒定时刷新</a>
</div>
<script>
function queryNew(){
var granularity=$("#granularity").val();
var startTime=$("#startTime").val();
var endTime=$("#endTime").val();
var domain=$("#domain").val();
var hostname=$("#hostname").val();
window.location.href="?op=view&domain="+domain+"&granularity="+granularity+"&startTime="+startTime+"&endTime="+endTime+"&hostname="+hostname;
}
</script>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page session="false" language="java" pageEncoding="UTF-8" %>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="a" uri="/WEB-INF/app.tld"%>
<%@ taglib prefix="w" uri="http://www.unidal.org/web/core"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="res" uri="http://www.unidal.org/webres"%>
<jsp:useBean id="ctx" type="com.dianping.cat.report.page.alteration.Context" scope="request"/>
<jsp:useBean id="payload" type="com.dianping.cat.report.page.alteration.Payload" scope="request"/>
<jsp:useBean id="model" type="com.dianping.cat.report.page.alteration.Model" scope="request"/>
View of alteration page under report
\ No newline at end of file
<c:set var="barrels" value="${model.barrels}" />
<a:report title="Alteration Report"
navUrlPrefix="">
<jsp:body>
<res:useJs value="${res.js.local['highcharts.js']}" target="head-js"/>
<res:useJs value="${res.js.local['baseGraph.js']}" target="head-js"/>
<table class="machines">
<tr>
<th>
<%@ include file="alter_query.jsp" %>
</th>
</tr>
</table>
<table class="problem table table-striped table-bordered table-condensed table-hover" style="width:100%">
<tr class="text-success">
<th width="15%">时间</th>
<th width="85%">详细信息</th>
</tr>
<c:forEach var="barrel" items="${model.barrels}" varStatus="typeIndex">
<tr style="width:85%">
<td>
${barrel.startTime}</br>${barrel.endTime}
</td>
<td>
<table class="table table-striped table-bordered table-condensed table-hover">
<tr class="text-success">
<th width="15%">标题</th>
<th width="5%">类型</th>
<th width="5%">应用</th>
<th width="8%">主机名</th>
<th width="15%">变更时间</th>
<th width="5%">变更用户</th>
<th width="5%">详情</th>
</tr>
<c:forEach var="item" items="${barrel.alterations}" varStatus="index">
<tr>
<td class="text-info">
<i tips="" data-trigger="hover" class="icon-question-sign" data-toggle="popover" data-placement="top" data-content="${item.content}"></i>
${item.title}
</td>
<td class="alertation${item.type}">
${item.type}
</td>
<td >
${item.domain}
</td>
<td >
${item.hostname}
</td>
<td >
${item.date}
</td>
<td >
${item.user}
</td>
<td >
<c:if test=" ${empty item.url}">
<a href="${item.url}">link</a>
</c:if>
</td>
</tr>
</c:forEach>
</table>
</td>
</tr>
</c:forEach>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('i[tips]').popover();
$(".header").hide();
<c:if test="${payload.fullScreen}">
$('#fullScreen').addClass('btn-danger');
$('.navbar').hide();
$('.footer').hide();
</c:if>
<c:if test="${!payload.fullScreen}">
$('#fullScreen').removeClass('btn-danger');
$('.navbar').show();
$('.footer').show();
</c:if>
/*
$('#fullScreen').click(function(){
if($('#fullScreen').hasClass('btn-danger')){
$('#fullScreen').removeClass('btn-danger');
$('#fullScreen').val('full');
$('.navbar').show();
$('.footer').show();
}else{
$('#fullScreen').addClass('btn-danger');
$('#fullScreen').val('exit');
$('.navbar').hide();
$('.footer').hide();
}
});*/
var refresh = ${payload.refresh};
var frequency = ${payload.frequency};
if(refresh){
$('#refresh${payload.frequency}').addClass('btn-danger');
setInterval(function(){
location.reload();
},frequency*1000);
};
var value = ${payload.granularity};
$("#granularity").val(value);
});
</script>
<res:useJs value="${res.js.local.problem_js}" target="buttom-js" />
<res:useJs value="${res.js.local.problemHistory_js}" target="bottom-js" />
</jsp:body>
</a:report>
\ No newline at end of file
......@@ -32,7 +32,8 @@ public class TestServer extends JettyServer {
@Override
protected int getServerPort() {
return 2281;
//return 2281;
return 8080;
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册