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

add config modification record feature

上级 0ffbce74
package com.dianping.cat.system.page.config;
import java.util.Date;
import org.unidal.lookup.annotation.Inject;
import com.dianping.cat.Cat;
import com.dianping.cat.home.dal.report.ConfigModification;
import com.dianping.cat.home.dal.report.ConfigModificationDao;
import com.dianping.cat.report.page.JsonBuilder;
public class ConfigModificationService {
@Inject
ConfigModificationDao m_configModificationDao;
public void store(String userName, String accountName, Payload payload) {
ConfigModification modification = m_configModificationDao.createLocal();
modification.setUserName(userName);
modification.setAccountName(accountName);
modification.setActionName(payload.getAction().getName());
modification.setDate(new Date());
modification.setArgument(new JsonBuilder().toJson(payload));
try {
m_configModificationDao.insert(modification);
} catch (Exception ex) {
Cat.logError(ex);
}
}
}
package com.dianping.cat.system.page.config;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -13,6 +14,7 @@ import java.util.Map.Entry;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import org.codehaus.plexus.util.StringUtils;
import org.hsqldb.lib.StringUtil;
......@@ -129,6 +131,9 @@ public class Handler implements PageHandler<Context> {
@Inject
private RouterConfigManager m_routerConfigManager;
@Inject
private ConfigModificationService m_modificationService;
private void deleteAggregationRule(Payload payload) {
m_aggreationConfigManager.deleteAggregationRule(payload.getPattern());
}
......@@ -230,6 +235,8 @@ public class Handler implements PageHandler<Context> {
Model model = new Model(ctx);
Payload payload = ctx.getPayload();
storeModifyInfo(ctx, payload);
model.setPage(SystemPage.CONFIG);
Action action = payload.getAction();
......@@ -630,6 +637,31 @@ public class Handler implements PageHandler<Context> {
return project;
}
private void storeModifyInfo(Context ctx, Payload payload) {
Cookie cookie = ctx.getCookie("ct");
if (cookie != null) {
String cookieValue = cookie.getValue();
try {
String[] values = cookieValue.split("\\|");
String userName = values[0];
String account = values[1];
if (userName.startsWith("\"")) {
userName = userName.substring(1, userName.length() - 1);
}
userName = URLDecoder.decode(userName, "UTF-8");
m_modificationService.store(userName, account, payload);
} catch (Exception ex) {
Cat.logError("store cookie fail:" + cookieValue, new RuntimeException());
}
} else {
Cat.logError("cannot get cookie info", new RuntimeException());
}
}
private void updateAggregationRule(Payload payload) {
AggregationRule proto = payload.getRule();
m_aggreationConfigManager.insertAggregationRule(proto);
......
......@@ -166,6 +166,46 @@
</query>
</query-defs>
</entity>
<entity name="config-modification" table="config_modification" alias="cm">
<member name="id" field="id" value-type="int" length="10" nullable="false" key="true" auto-increment="true" />
<member name="user-name" field="user_name" value-type="String" length="64" nullable="false" />
<member name="account-name" field="account_name" value-type="String" length="64" nullable="false" />
<member name="action-name" field="action_name" value-type="String" length="64" nullable="false" />
<member name="argument" field="argument" value-type="String" length="2147483647" />
<member name="date" field="date" value-type="Date" nullable="false" />
<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" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
<updatesets>
<updateset name="FULL" all="true" />
</updatesets>
<query-defs>
<query name="find-by-PK" type="SELECT">
<param name="key-id" />
<statement><![CDATA[SELECT <FIELDS/>
FROM <TABLE/>
WHERE <FIELD name='id'/> = ${key-id}]]></statement>
</query>
<query name="insert" type="INSERT">
<statement><![CDATA[INSERT INTO <TABLE/>(<FIELDS/>)
VALUES(<VALUES/>)]]></statement>
</query>
<query name="update-by-PK" type="UPDATE">
<param name="key-id" />
<statement><![CDATA[UPDATE <TABLE/>
SET <FIELDS/>
WHERE <FIELD name='id'/> = ${key-id}]]></statement>
</query>
<query name="delete-by-PK" type="DELETE">
<param name="key-id" />
<statement><![CDATA[DELETE FROM <TABLE/>
WHERE <FIELD name='id'/> = ${key-id}]]></statement>
</query>
</query-defs>
</entity>
<entity name="daily-report-content" table="daily_report_content" alias="drc">
<member name="report-id" field="report_id" value-type="int" length="10" nullable="false" key="true" />
<member name="content" field="content" value-type="byte[]" length="2147483647" nullable="false" />
......
......@@ -267,4 +267,7 @@
</query>
</query-defs>
</entity>
<entity name="config-modification" table="config_modification" alias="cm">
<member name="creation-date" insert-expr="NOW()" />
</entity>
</entities>
\ No newline at end of file
......@@ -2016,6 +2016,16 @@
<data-source-name>cat</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>config-modification</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>config-modification</logical-table-name>
<physical-table-name>config_modification</physical-table-name>
<data-source-name>cat</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>daily-report-content</role-hint>
......@@ -2112,6 +2122,15 @@
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.home.dal.report.ConfigModificationDao</role>
<implementation>com.dianping.cat.home.dal.report.ConfigModificationDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.home.dal.report.DailyReportContentDao</role>
<implementation>com.dianping.cat.home.dal.report.DailyReportContentDao</implementation>
......@@ -4668,6 +4687,9 @@
<requirement>
<role>com.dianping.cat.system.config.RouterConfigManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.system.page.config.ConfigModificationService</role>
</requirement>
</requirements>
</component>
<component>
......@@ -4775,6 +4797,24 @@
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.system.page.config.ConfigModificationService</role>
<implementation>com.dianping.cat.system.page.config.ConfigModificationService</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.home.dal.report.ConfigModificationDao</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.home.dal.report.ConfigModificationDao</role>
<implementation>com.dianping.cat.home.dal.report.ConfigModificationDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.system.page.plugin.Handler</role>
<implementation>com.dianping.cat.system.page.plugin.Handler</implementation>
......
......@@ -18,7 +18,8 @@
<table name="weekly_report_content"/>
<table name="alert"/>
<table name="alert_summary"/>
<table name="overload_table"/>
<table name="overload"/>
<table name="config_modification"/>
</group>
<group name="alarm" package="com.dianping.cat.home.dal.alarm">
<table name="mailRecord"/>
......
......@@ -179,7 +179,7 @@
loginInfo.innerHTML ='<a href="/cat/s/login?op=logout">'+name +'&nbsp;登出</a>';
}else{
var loginInfo=document.getElementById('loginInfo');
loginInfo.innerHTML ='<a href="#loginModal" data-toggle="modal">登</a>';
loginInfo.innerHTML ='<a href="#loginModal" data-toggle="modal">登</a>';
}
});
</script>
......
......@@ -385,3 +385,14 @@ CREATE TABLE `overload` (
PRIMARY KEY (`id`),
UNIQUE KEY `reported` (`report_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1242 DEFAULT CHARSET=utf8 COMMENT='过大容量表';
CREATE TABLE `config_modification` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增长ID',
`user_name` varchar(64) NOT NULL COMMENT '用户名',
`account_name` varchar(64) NOT NULL COMMENT '账户名',
`action_name` varchar(64) NOT NULL COMMENT 'action名',
`argument` longtext COMMENT '参数内容',
`date` datetime NOT NULL COMMENT '修改时间',
`creation_date` datetime NOT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1242 DEFAULT CHARSET=utf8 COMMENT='配置修改记录表';
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册