Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
f5208064
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f5208064
编写于
6月 05, 2013
作者:
A
ainilife
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change test id from int to string
上级
4faf486b
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
325 addition
and
329 deletion
+325
-329
abtest-sample/src/main/java/com/dianping/abtest/sample/ABTestSampleServlet.java
.../java/com/dianping/abtest/sample/ABTestSampleServlet.java
+4
-4
cat-core/src/main/java/com/dianping/cat/abtest/ABTestId.java
cat-core/src/main/java/com/dianping/cat/abtest/ABTestId.java
+4
-1
cat-core/src/main/java/com/dianping/cat/abtest/repository/ABTestEntityRepository.java
...ianping/cat/abtest/repository/ABTestEntityRepository.java
+1
-1
cat-core/src/main/java/com/dianping/cat/abtest/repository/HttpABTestEntityRepository.java
...ing/cat/abtest/repository/HttpABTestEntityRepository.java
+16
-9
cat-core/src/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
...c/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
+69
-75
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContextManager.java
.../cat/abtest/spi/internal/DefaultABTestContextManager.java
+9
-9
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManager.java
...g/cat/abtest/spi/internal/DefaultABTestEntityManager.java
+6
-6
cat-core/src/main/java/com/dianping/cat/build/ABTestComponentConfigurator.java
...a/com/dianping/cat/build/ABTestComponentConfigurator.java
+2
-1
cat-core/src/main/resources/META-INF/plexus/components.xml
cat-core/src/main/resources/META-INF/plexus/components.xml
+3
-0
cat-core/src/test/java/com/dianping/cat/abtest/sample/SampleTest.java
.../test/java/com/dianping/cat/abtest/sample/SampleTest.java
+5
-5
cat-core/src/test/java/com/dianping/cat/abtest/spi/internal/ABTestEntityManagerTest.java
...ping/cat/abtest/spi/internal/ABTestEntityManagerTest.java
+5
-7
cat-home/src/main/java/com/dianping/cat/build/CatDatabaseConfigurator.java
.../java/com/dianping/cat/build/CatDatabaseConfigurator.java
+1
-1
cat-home/src/main/java/com/dianping/cat/system/page/abtest/Handler.java
...ain/java/com/dianping/cat/system/page/abtest/Handler.java
+168
-177
cat-home/src/main/java/com/dianping/cat/system/page/abtest/Model.java
.../main/java/com/dianping/cat/system/page/abtest/Model.java
+26
-27
cat-home/src/main/java/com/dianping/cat/system/page/abtest/Payload.java
...ain/java/com/dianping/cat/system/page/abtest/Payload.java
+6
-6
未找到文件。
abtest-sample/src/main/java/com/dianping/abtest/sample/ABTestSampleServlet.java
浏览文件 @
f5208064
...
...
@@ -31,16 +31,16 @@ public class ABTestSampleServlet extends HttpServlet {
}
public
static
enum
MyABTestId
implements
ABTestId
{
CASE1
(
11
);
CASE1
(
"demo1"
);
private
int
m_id
;
private
String
m_id
;
private
MyABTestId
(
int
id
)
{
private
MyABTestId
(
String
id
)
{
m_id
=
id
;
}
@Override
public
int
getValue
()
{
public
String
getValue
()
{
return
m_id
;
}
}
...
...
cat-core/src/main/java/com/dianping/cat/abtest/ABTestId.java
浏览文件 @
f5208064
package
com.dianping.cat.abtest
;
public
interface
ABTestId
{
public
int
getValue
();
/**
* @return unique abtest name
*/
public
String
getValue
();
}
cat-core/src/main/java/com/dianping/cat/abtest/repository/ABTestEntityRepository.java
浏览文件 @
f5208064
...
...
@@ -5,5 +5,5 @@ import java.util.Map;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
public
interface
ABTestEntityRepository
{
public
Map
<
Integer
,
ABTestEntity
>
getEntities
();
public
Map
<
String
,
ABTestEntity
>
getEntities
();
}
cat-core/src/main/java/com/dianping/cat/abtest/repository/HttpABTestEntityRepository.java
浏览文件 @
f5208064
...
...
@@ -32,15 +32,18 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
@Inject
private
ClientConfigManager
m_configManager
;
@Inject
private
int
m_refreshTime
=
60
;
//seconds
private
String
m_domain
;
private
Map
<
Integer
,
ABTestEntity
>
m_entities
=
new
HashMap
<
Integer
,
ABTestEntity
>();
private
Map
<
String
,
ABTestEntity
>
m_entities
=
new
HashMap
<
String
,
ABTestEntity
>();
private
Map
<
String
,
ABTestGroupStrategy
>
m_strategies
=
new
HashMap
<
String
,
ABTestGroupStrategy
>();
private
String
m_domain
;
@Override
public
Map
<
Integer
,
ABTestEntity
>
getEntities
()
{
public
Map
<
String
,
ABTestEntity
>
getEntities
()
{
return
m_entities
;
}
...
...
@@ -54,6 +57,10 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
m_domain
=
m_configManager
.
getFirstDomain
().
getId
();
}
public
void
setRefreshTime
(
int
refreshTime
)
{
m_refreshTime
=
refreshTime
;
}
private
void
refresh
()
{
String
clientIp
=
NetworkInterfaceManager
.
INSTANCE
.
getLocalHostAddress
();
...
...
@@ -103,7 +110,7 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
Cat
.
logError
(
e
);
}
LockSupport
.
parkUntil
(
start
+
6
*
1000L
);
// every minute
LockSupport
.
parkUntil
(
start
+
m_refreshTime
*
1000L
);
// every minute
}
}
...
...
@@ -114,14 +121,14 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
class
ABTestVisitor
extends
BaseVisitor
{
private
String
m_domain
;
private
Map
<
Integer
,
ABTestEntity
>
m_entities
;
private
Map
<
String
,
ABTestEntity
>
m_entities
;
public
ABTestVisitor
(
String
domain
)
{
m_domain
=
domain
;
m_entities
=
new
HashMap
<
Integer
,
ABTestEntity
>();
m_entities
=
new
HashMap
<
String
,
ABTestEntity
>();
}
public
Map
<
Integer
,
ABTestEntity
>
getEntities
()
{
public
Map
<
String
,
ABTestEntity
>
getEntities
()
{
return
m_entities
;
}
...
...
@@ -158,7 +165,7 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
}
}
m_entities
.
put
(
entity
.
get
Id
(),
entity
);
m_entities
.
put
(
entity
.
get
Name
(),
entity
);
}
}
}
...
...
cat-core/src/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
浏览文件 @
f5208064
...
...
@@ -7,44 +7,100 @@ import com.dianping.cat.abtest.model.entity.Run;
public
class
ABTestEntity
{
private
int
m_id
;
private
String
m_name
;
private
String
m_groupStrategyName
;
private
Run
m_run
;
private
ABTestGroupStrategy
m_groupStrategy
;
private
String
m_groupStrategyName
;
public
ABTestEntity
()
{
m_run
=
new
Run
();
m_run
.
setDisabled
(
true
);
}
public
ABTestEntity
(
Case
_case
,
Run
run
)
{
m_id
=
_case
.
getId
();
m_name
=
_case
.
getName
();
m_groupStrategyName
=
_case
.
getGroupStrategy
();
m_run
=
run
;
}
public
String
getGroupStrategyName
()
{
return
m_groupStrategyName
!=
null
?
m_groupStrategyName
:
null
;
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
ABTestEntity
other
=
(
ABTestEntity
)
obj
;
if
(
m_groupStrategy
==
null
)
{
if
(
other
.
m_groupStrategy
!=
null
)
return
false
;
}
else
if
(!
m_groupStrategy
.
equals
(
other
.
m_groupStrategy
))
return
false
;
if
(
m_groupStrategyName
==
null
)
{
if
(
other
.
m_groupStrategyName
!=
null
)
return
false
;
}
else
if
(!
m_groupStrategyName
.
equals
(
other
.
m_groupStrategyName
))
return
false
;
if
(
m_name
==
null
)
{
if
(
other
.
m_name
!=
null
)
return
false
;
}
else
if
(!
m_name
.
equals
(
other
.
m_name
))
return
false
;
if
(
m_run
==
null
)
{
if
(
other
.
m_run
!=
null
)
return
false
;
}
else
if
(!
m_run
.
equals
(
other
.
m_run
))
return
false
;
return
true
;
}
public
Date
getEndDate
()
{
return
m_run
.
getEndDate
();
}
public
ABTestGroupStrategy
getGroupStrategy
()
{
return
m_groupStrategy
;
}
public
String
getGroupStrategyConfiguration
()
{
return
m_run
.
getGroupStrategyConfiguration
()
!=
null
?
m_run
.
getGroupStrategyConfiguration
()
:
null
;
}
public
Date
getEndDate
()
{
return
m_run
.
getEndDate
();
public
String
getGroupStrategyName
()
{
return
m_groupStrategyName
!=
null
?
m_groupStrategyName
:
null
;
}
public
String
getName
()
{
return
m_name
;
}
public
Run
getRun
()
{
return
m_run
;
}
public
Date
getStartDate
()
{
return
m_run
.
getStartDate
();
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
m_groupStrategy
==
null
)
?
0
:
m_groupStrategy
.
hashCode
());
result
=
prime
*
result
+
((
m_groupStrategyName
==
null
)
?
0
:
m_groupStrategyName
.
hashCode
());
result
=
prime
*
result
+
((
m_name
==
null
)
?
0
:
m_name
.
hashCode
());
result
=
prime
*
result
+
((
m_run
==
null
)
?
0
:
m_run
.
hashCode
());
return
result
;
}
public
boolean
isDisabled
()
{
return
m_run
.
isDisabled
();
}
public
boolean
isEligible
(
Date
date
)
{
if
(
m_run
.
getDisabled
()
!=
null
&&
m_run
.
getDisabled
())
{
return
false
;
...
...
@@ -67,83 +123,21 @@ public class ABTestEntity {
return
true
;
}
public
boolean
isDisabled
()
{
return
m_run
.
isDisabled
();
}
public
void
setDisabled
(
boolean
disabled
)
{
m_run
.
setDisabled
(
disabled
);
}
public
ABTestGroupStrategy
getGroupStrategy
()
{
return
m_groupStrategy
;
}
public
void
setGroupStrategy
(
ABTestGroupStrategy
groupStrategy
)
{
m_groupStrategy
=
groupStrategy
;
}
public
void
setId
(
int
id
){
m_id
=
id
;
}
public
int
getId
()
{
return
m_id
;
}
public
String
getName
()
{
return
m_name
;
}
public
Run
getRun
()
{
return
m_run
;
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
m_groupStrategyName
==
null
)
?
0
:
m_groupStrategyName
.
hashCode
());
result
=
prime
*
result
+
m_id
;
result
=
prime
*
result
+
((
m_name
==
null
)
?
0
:
m_name
.
hashCode
());
result
=
prime
*
result
+
((
m_run
==
null
)
?
0
:
m_run
.
hashCode
());
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
ABTestEntity
other
=
(
ABTestEntity
)
obj
;
if
(
m_groupStrategyName
==
null
)
{
if
(
other
.
m_groupStrategyName
!=
null
)
return
false
;
}
else
if
(!
m_groupStrategyName
.
equals
(
other
.
m_groupStrategyName
))
return
false
;
if
(
m_id
!=
other
.
m_id
)
return
false
;
if
(
m_name
==
null
)
{
if
(
other
.
m_name
!=
null
)
return
false
;
}
else
if
(!
m_name
.
equals
(
other
.
m_name
))
return
false
;
if
(
m_run
==
null
)
{
if
(
other
.
m_run
!=
null
)
return
false
;
}
else
if
(!
m_run
.
equals
(
other
.
m_run
))
return
false
;
return
true
;
public
void
setName
(
String
name
)
{
m_name
=
name
;
}
@Override
public
String
toString
()
{
return
"ABTestEntity [m_
id="
+
m_id
+
", m_name="
+
m_name
+
", m_groupStrategyName="
+
m_groupStrategyName
+
", m_
run="
+
m_run
+
"]"
;
return
"ABTestEntity [m_
name="
+
m_name
+
", m_groupStrategyName="
+
m_groupStrategyName
+
", m_run="
+
m_run
+
", m_
groupStrategy="
+
m_groupStrategy
+
"]"
;
}
}
\ No newline at end of file
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContextManager.java
浏览文件 @
f5208064
...
...
@@ -30,8 +30,8 @@ public class DefaultABTestContextManager extends ContainerHolder implements ABTe
@Override
public
ABTestContext
getContext
(
ABTestId
testId
)
{
Entry
entry
=
m_threadLocal
.
get
();
Map
<
Integer
,
DefaultABTestContext
>
map
=
entry
.
getContextMap
();
int
id
=
testId
.
getValue
();
Map
<
String
,
DefaultABTestContext
>
map
=
entry
.
getContextMap
();
String
id
=
testId
.
getValue
();
DefaultABTestContext
ctx
=
map
.
get
(
id
);
if
(
ctx
==
null
)
{
...
...
@@ -64,18 +64,18 @@ public class DefaultABTestContextManager extends ContainerHolder implements ABTe
ctxList
=
new
ArrayList
<
ABTestContext
>(
4
);
List
<
ABTestEntity
>
entities
=
m_entityManager
.
getEntityList
();
Map
<
Integer
,
DefaultABTestContext
>
ctxMap
=
m_threadLocal
.
get
().
getContextMap
();
Map
<
String
,
DefaultABTestContext
>
ctxMap
=
m_threadLocal
.
get
().
getContextMap
();
Date
now
=
new
Date
();
for
(
ABTestEntity
entity
:
entities
)
{
Entry
entry
=
m_threadLocal
.
get
();
int
id
=
entity
.
getId
();
DefaultABTestContext
ctx
=
ctxMap
.
get
(
id
);
String
name
=
entity
.
getName
();
DefaultABTestContext
ctx
=
ctxMap
.
get
(
name
);
if
(
ctx
==
null
)
{
ctx
=
createContext
(
entity
,
entry
.
getHttpServletRequest
());
ctxMap
.
put
(
id
,
ctx
);
ctxMap
.
put
(
name
,
ctx
);
}
ctx
.
initialize
(
now
);
...
...
@@ -100,20 +100,20 @@ public class DefaultABTestContextManager extends ContainerHolder implements ABTe
entry
.
setHttpServletRequest
(
req
);
Map
<
Integer
,
DefaultABTestContext
>
map
=
entry
.
getContextMap
();
Map
<
String
,
DefaultABTestContext
>
map
=
entry
.
getContextMap
();
for
(
DefaultABTestContext
ctx
:
map
.
values
())
{
ctx
.
setup
(
req
);
}
}
static
class
Entry
{
private
Map
<
Integer
,
DefaultABTestContext
>
m_map
=
new
HashMap
<
Integer
,
DefaultABTestContext
>(
4
);
private
Map
<
String
,
DefaultABTestContext
>
m_map
=
new
HashMap
<
String
,
DefaultABTestContext
>(
4
);
private
List
<
ABTestContext
>
m_list
;
private
HttpServletRequest
m_req
;
public
Map
<
Integer
,
DefaultABTestContext
>
getContextMap
()
{
public
Map
<
String
,
DefaultABTestContext
>
getContextMap
()
{
return
m_map
;
}
...
...
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManager.java
浏览文件 @
f5208064
...
...
@@ -20,19 +20,19 @@ public class DefaultABTestEntityManager extends ContainerHolder implements ABTes
private
ABTestEntityRepository
m_repository
;
@Override
public
ABTestEntity
getEntity
(
ABTestId
id
)
{
ABTestEntity
entity
=
m_repository
.
getEntities
().
get
(
id
.
getValue
());
public
ABTestEntity
getEntity
(
ABTestId
name
)
{
ABTestEntity
entity
=
m_repository
.
getEntities
().
get
(
name
.
getValue
());
if
(
entity
==
null
)
{
entity
=
new
ABTestEntity
();
entity
.
set
Id
(
id
.
getValue
());
entity
.
set
Name
(
name
.
getValue
());
entity
.
setDisabled
(
true
);
m_repository
.
getEntities
().
put
(
id
.
getValue
(),
entity
);
m_repository
.
getEntities
().
put
(
name
.
getValue
(),
entity
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"
id "
).
append
(
id
.
getValue
()).
append
(
" doesn't exsit"
);
Cat
.
getProducer
().
logEvent
(
"ABTest
.IDMiss"
,
"id
-miss"
,
sb
.
toString
(),
""
);
sb
.
append
(
"
name "
).
append
(
name
.
getValue
()).
append
(
" doesn't exsit"
);
Cat
.
getProducer
().
logEvent
(
"ABTest
"
,
"abtest
-miss"
,
sb
.
toString
(),
""
);
}
return
entity
;
...
...
cat-core/src/main/java/com/dianping/cat/build/ABTestComponentConfigurator.java
浏览文件 @
f5208064
...
...
@@ -23,7 +23,8 @@ class ABTestComponentConfigurator extends AbstractResourceConfigurator {
.
req
(
ABTestEntityManager
.
class
));
all
.
add
(
C
(
ABTestEntityRepository
.
class
,
HttpABTestEntityRepository
.
class
)
//
.
req
(
ClientConfigManager
.
class
));
.
req
(
ClientConfigManager
.
class
)
.
config
(
E
(
"refreshTime"
).
value
(
"6"
)));
all
.
add
(
C
(
ABTestEntityManager
.
class
,
DefaultABTestEntityManager
.
class
)
//
.
req
(
ABTestEntityRepository
.
class
));
...
...
cat-core/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
f5208064
...
...
@@ -314,6 +314,9 @@
<component>
<role>
com.dianping.cat.abtest.repository.ABTestEntityRepository
</role>
<implementation>
com.dianping.cat.abtest.repository.HttpABTestEntityRepository
</implementation>
<configuration>
<refreshTime>
6
</refreshTime>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.configuration.ClientConfigManager
</role>
...
...
cat-core/src/test/java/com/dianping/cat/abtest/sample/SampleTest.java
浏览文件 @
f5208064
...
...
@@ -26,18 +26,18 @@ public class SampleTest {
}
public
static
enum
MyABTestId
implements
ABTestId
{
CASE1
(
1001
),
CASE1
(
"1001"
),
CASE2
(
1002
);
CASE2
(
"1002"
);
private
int
m_id
;
private
String
m_id
;
private
MyABTestId
(
int
id
)
{
private
MyABTestId
(
String
id
)
{
m_id
=
id
;
}
@Override
public
int
getValue
()
{
public
String
getValue
()
{
return
m_id
;
}
}
...
...
cat-core/src/test/java/com/dianping/cat/abtest/spi/internal/ABTestEntityManagerTest.java
浏览文件 @
f5208064
...
...
@@ -16,19 +16,19 @@ public class ABTestEntityManagerTest extends ComponentTestCase {
@Test
public
void
testGetEntity
()
throws
Exception
{
checkEntity
(
-
1
,
null
,
null
,
null
,
null
,
false
,
false
);
checkEntity
(
1001
,
"Mock1"
,
"roundrobin"
,
"This is the configuration"
,
"2012-01-01 00:00:00"
,
false
,
false
);
checkEntity
(
1001
,
"Mock1"
,
"roundrobin"
,
"This is the configuration"
,
"2013-04-10 18:00:00"
,
true
,
false
);
checkEntity
(
"-1"
,
null
,
null
,
null
,
null
,
false
,
false
);
checkEntity
(
"1001"
,
"Mock1"
,
"roundrobin"
,
"This is the configuration"
,
"2012-01-01 00:00:00"
,
false
,
false
);
checkEntity
(
"1001"
,
"Mock1"
,
"roundrobin"
,
"This is the configuration"
,
"2013-04-10 18:00:00"
,
true
,
false
);
}
private
void
checkEntity
(
final
int
id
,
String
expectedEntityName
,
String
expectedGroupStrategy
,
private
void
checkEntity
(
final
String
name
,
String
expectedEntityName
,
String
expectedGroupStrategy
,
String
expectedGroupStrategyConfiguration
,
String
expectedDateStr
,
boolean
expectedEligible
,
boolean
expectedDisabled
)
throws
Exception
{
ABTestEntityManager
manager
=
lookup
(
ABTestEntityManager
.
class
);
ABTestEntity
entity
=
null
;
for
(
ABTestEntity
e
:
manager
.
getEntityList
())
{
if
(
e
.
get
Id
()
==
id
)
{
if
(
e
.
get
Name
()
==
name
)
{
entity
=
e
;
break
;
}
...
...
@@ -40,8 +40,6 @@ public class ABTestEntityManagerTest extends ComponentTestCase {
Assert
.
assertNotNull
(
entity
);
Assert
.
assertEquals
(
id
<
0
?
0
:
id
,
entity
.
getId
());
if
(
expectedGroupStrategy
!=
null
)
{
Assert
.
assertEquals
(
expectedGroupStrategy
,
entity
.
getGroupStrategyName
());
}
...
...
cat-home/src/main/java/com/dianping/cat/build/CatDatabaseConfigurator.java
浏览文件 @
f5208064
...
...
@@ -11,7 +11,7 @@ final class CatDatabaseConfigurator extends AbstractJdbcResourceConfigurator {
public
List
<
Component
>
defineComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
all
.
add
(
defineJdbcDataSourceComponent
(
"cat"
,
"com.mysql.jdbc.Driver"
,
"jdbc:mysql://1
92.168.7.43:3306/cat"
,
"binlog"
,
"binlog
"
,
"<![CDATA[useUnicode=true&autoReconnect=true]]>"
));
all
.
add
(
defineJdbcDataSourceComponent
(
"cat"
,
"com.mysql.jdbc.Driver"
,
"jdbc:mysql://1
27.0.0.1:3306/cat"
,
"root"
,
"
"
,
"<![CDATA[useUnicode=true&autoReconnect=true]]>"
));
defineSimpleTableProviderComponents
(
all
,
"cat"
,
com
.
dianping
.
cat
.
home
.
dal
.
report
.
_INDEX
.
getEntityClasses
());
defineDaoComponents
(
all
,
com
.
dianping
.
cat
.
home
.
dal
.
report
.
_INDEX
.
getDaoClasses
());
...
...
cat-home/src/main/java/com/dianping/cat/system/page/abtest/Handler.java
浏览文件 @
f5208064
...
...
@@ -43,13 +43,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
public
static
final
String
CHARSET
=
"UTF-8"
;
private
final
int
m_pageSize
=
5
;
private
Logger
m_logger
;
@Inject
private
JspViewer
m_jspViewer
;
@Inject
private
AbtestDao
m_abtestDao
;
...
...
@@ -57,33 +50,74 @@ public class Handler implements PageHandler<Context>, LogEnabled {
private
AbtestRunDao
m_abtestRunDao
;
@Inject
private
ProjectDao
m_project
Dao
;
private
GroupStrategyDao
m_groupStrategy
Dao
;
@Inject
private
GroupStrategyDao
m_groupStrategyDao
;
private
ProjectDao
m_projectDao
;
@Inject
private
JspViewer
m_jspViewer
;
private
Logger
m_logger
;
private
final
int
m_pageSize
=
10
;
@Override
@PayloadMeta
(
Payload
.
class
)
@InboundActionMeta
(
name
=
"abtest"
)
public
void
handleInbound
(
Context
ctx
)
throws
ServletException
,
IOException
{
if
(
ctx
.
getException
()
!=
null
)
{
return
;
}
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
Payload
payload
=
ctx
.
getPayload
();
Action
action
=
payload
.
getAction
();
private
AbtestModel
fetchAbtestModel
()
{
try
{
AbtestModel
abtestModel
=
new
AbtestModel
();
if
(
ctx
.
getHttpServletRequest
().
getMethod
().
equalsIgnoreCase
(
"post"
))
{
if
(
action
==
Action
.
CREATE
)
{
handleCreateAction
(
ctx
,
payload
);
}
else
if
(
action
==
Action
.
DETAIL
)
{
handleUpdateAction
(
ctx
,
payload
);
List
<
AbtestRun
>
abtestRuns
=
m_abtestRunDao
.
findAll
(
AbtestRunEntity
.
READSET_FULL
);
if
(
abtestRuns
!=
null
)
{
Date
now
=
new
Date
();
for
(
AbtestRun
abtestRun
:
abtestRuns
)
{
AbtestStatus
status
=
AbtestStatus
.
calculateStatus
(
abtestRun
,
now
);
if
(
status
==
AbtestStatus
.
READY
||
status
==
AbtestStatus
.
RUNNING
)
{
// fetch Case and GroupStrategy
int
caseId
=
abtestRun
.
getCaseId
();
Abtest
entity
=
m_abtestDao
.
findByPK
(
caseId
,
AbtestEntity
.
READSET_FULL
);
int
gid
=
entity
.
getGroupStrategy
();
GroupStrategy
groupStrategy
=
m_groupStrategyDao
.
findByPK
(
gid
,
GroupStrategyEntity
.
READSET_FULL
);
Case
_case
=
transform
(
abtestRun
,
entity
,
groupStrategy
);
abtestModel
.
addCase
(
_case
);
}
}
}
return
abtestModel
;
}
catch
(
DalException
e
)
{
m_logger
.
error
(
"Error when find all AbtestRun"
,
e
);
Cat
.
logError
(
e
);
}
return
null
;
}
if
(
action
==
Action
.
VIEW
)
{
handleStatusChangeAction
(
ctx
);
private
List
<
GroupStrategy
>
getAllGroupStrategys
()
{
try
{
return
m_groupStrategyDao
.
findAllByStatus
(
1
,
GroupStrategyEntity
.
READSET_FULL
);
}
catch
(
DalException
e
)
{
m_logger
.
error
(
e
.
getMessage
(),
e
);
Cat
.
logError
(
e
);
}
return
null
;
}
private
Map
<
String
,
List
<
Project
>>
getAllProjects
()
{
List
<
Project
>
projects
=
new
ArrayList
<
Project
>();
try
{
projects
=
m_projectDao
.
findAll
(
ProjectEntity
.
READSET_FULL
);
}
catch
(
Exception
e
)
{
m_logger
.
error
(
e
.
getMessage
(),
e
);
Cat
.
logError
(
e
);
}
// Collections.sort(projects, new ProjectCompartor());
return
transform
(
projects
);
}
private
void
handleCreateAction
(
Context
ctx
,
Payload
payload
)
{
...
...
@@ -111,7 +145,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
run
.
setCaseId
(
abtest
.
getId
());
m_abtestRunDao
.
insert
(
run
);
}
catch
(
DalException
e
)
{
m_logger
.
error
(
"Error when saving abtest"
,
e
);
Cat
.
logError
(
e
);
...
...
@@ -119,29 +152,59 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
}
private
void
handleUpdateAction
(
Context
ctx
,
Payload
payload
)
{
try
{
AbtestRun
run
=
new
AbtestRun
();
@Override
@PayloadMeta
(
Payload
.
class
)
@InboundActionMeta
(
name
=
"abtest"
)
public
void
handleInbound
(
Context
ctx
)
throws
ServletException
,
IOException
{
if
(
ctx
.
getException
()
!=
null
)
{
return
;
}
run
.
setId
(
payload
.
getId
());
run
.
setKeyId
(
payload
.
getId
());
run
.
setCreator
(
payload
.
getOwner
());
run
.
setStartDate
(
payload
.
getStartDate
());
run
.
setEndDate
(
payload
.
getEndDate
());
run
.
setDomains
(
StringUtils
.
join
(
payload
.
getDomains
(),
','
));
run
.
setStrategyConfiguration
(
payload
.
getStrategyConfig
());
Date
now
=
new
Date
();
run
.
setModifiedDate
(
now
);
Payload
payload
=
ctx
.
getPayload
();
Action
action
=
payload
.
getAction
();
// only update run info, do not update abtest meta-info
m_abtestRunDao
.
updateByPK
(
run
,
AbtestRunEntity
.
UPDATESET_ALLOWED_MODIFYPART
);
if
(
ctx
.
getHttpServletRequest
().
getMethod
().
equalsIgnoreCase
(
"post"
))
{
if
(
action
==
Action
.
CREATE
)
{
handleCreateAction
(
ctx
,
payload
);
}
else
if
(
action
==
Action
.
DETAIL
)
{
handleUpdateAction
(
ctx
,
payload
);
}
}
}
catch
(
DalException
e
)
{
m_logger
.
error
(
"Error when updating abtest"
,
e
);
Cat
.
logError
(
e
);
ctx
.
setException
(
e
);
if
(
action
==
Action
.
VIEW
)
{
handleStatusChangeAction
(
ctx
);
}
}
@Override
@OutboundActionMeta
(
name
=
"abtest"
)
public
void
handleOutbound
(
Context
ctx
)
throws
ServletException
,
IOException
{
Model
model
=
new
Model
(
ctx
);
Payload
payload
=
ctx
.
getPayload
();
Action
action
=
payload
.
getAction
();
switch
(
action
)
{
case
VIEW:
renderListModel
(
model
,
payload
);
break
;
case
CREATE:
renderCreateModel
(
model
);
break
;
case
DETAIL:
renderDetailModel
(
ctx
,
model
,
payload
);
break
;
case
REPORT:
renderReportModel
(
ctx
,
model
,
payload
);
break
;
case
MODEL:
renderModel
(
model
);
break
;
}
model
.
setAction
(
action
);
model
.
setPage
(
SystemPage
.
ABTEST
);
m_jspViewer
.
view
(
ctx
,
model
);
}
private
void
handleStatusChangeAction
(
Context
ctx
)
{
Payload
payload
=
ctx
.
getPayload
();
...
...
@@ -154,27 +217,26 @@ public class Handler implements PageHandler<Context>, LogEnabled {
int
runID
=
Integer
.
parseInt
(
id
);
AbtestRun
run
=
m_abtestRunDao
.
findByPK
(
runID
,
AbtestRunEntity
.
READSET_FULL
);
if
(
payload
.
getDisableAbtest
()
==
-
1
)
{
// suspend
if
(
payload
.
getDisableAbtest
()
==
-
1
)
{
// suspend abtest
if
(!
run
.
isDisabled
())
{
run
.
setDisabled
(
true
);
m_abtestRunDao
.
updateByPK
(
run
,
AbtestRunEntity
.
UPDATESET_STATUS
);
}
else
{
error
.
addArgument
(
id
,
"Abtest "
+
id
+
" has been already suspended!"
);
error
.
addArgument
(
id
,
String
.
format
(
"Abtest %d has been already suspended!"
,
id
)
);
}
}
else
if
(
payload
.
getDisableAbtest
()
==
1
)
{
// resume
}
else
if
(
payload
.
getDisableAbtest
()
==
1
)
{
// resume abtest
if
(
run
.
isDisabled
())
{
run
.
setDisabled
(
false
);
m_abtestRunDao
.
updateByPK
(
run
,
AbtestRunEntity
.
UPDATESET_STATUS
);
}
else
{
error
.
addArgument
(
id
,
"Abtest "
+
id
+
" has been already active!"
);
error
.
addArgument
(
id
,
String
.
format
(
"Abtest %d has been already active!"
,
id
)
);
}
}
}
catch
(
NumberFormatException
e
)
{
}
catch
(
Throwable
e
)
{
// do nothing
Cat
.
logError
(
e
);
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
}
...
...
@@ -187,97 +249,27 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
}
@Override
@OutboundActionMeta
(
name
=
"abtest"
)
public
void
handleOutbound
(
Context
ctx
)
throws
ServletException
,
IOException
{
Model
model
=
new
Model
(
ctx
);
Payload
payload
=
ctx
.
getPayload
();
Action
action
=
payload
.
getAction
();
switch
(
action
)
{
case
VIEW:
renderListModel
(
model
,
payload
);
break
;
case
CREATE:
renderCreateModel
(
model
);
break
;
case
DETAIL:
renderDetailModel
(
ctx
,
model
,
payload
);
break
;
case
REPORT:
renderReportModel
(
ctx
,
model
,
payload
);
break
;
case
MODEL:
renderModel
(
model
);
break
;
}
model
.
setAction
(
action
);
model
.
setPage
(
SystemPage
.
ABTEST
);
m_jspViewer
.
view
(
ctx
,
model
);
}
private
void
renderModel
(
Model
model
)
{
model
.
setAbtestModel
(
fetchAbtestModel
().
toString
());
}
private
AbtestModel
fetchAbtestModel
()
{
private
void
handleUpdateAction
(
Context
ctx
,
Payload
payload
)
{
try
{
AbtestModel
abtestModel
=
new
AbtestModel
();
List
<
AbtestRun
>
abtestRuns
=
m_abtestRunDao
.
findAll
(
AbtestRunEntity
.
READSET_FULL
);
if
(
abtestRuns
!=
null
)
{
Date
now
=
new
Date
();
for
(
AbtestRun
abtestRun
:
abtestRuns
)
{
AbtestStatus
status
=
AbtestStatus
.
calculateStatus
(
abtestRun
,
now
);
if
(
status
==
AbtestStatus
.
READY
||
status
==
AbtestStatus
.
RUNNING
)
{
// fetch Case and GroupStrategy
int
caseId
=
abtestRun
.
getCaseId
();
Abtest
entity
=
m_abtestDao
.
findByPK
(
caseId
,
AbtestEntity
.
READSET_FULL
);
int
gid
=
entity
.
getGroupStrategy
();
GroupStrategy
groupStrategy
=
m_groupStrategyDao
.
findByPK
(
gid
,
GroupStrategyEntity
.
READSET_FULL
);
Case
_case
=
transform
(
abtestRun
,
entity
,
groupStrategy
);
abtestModel
.
addCase
(
_case
);
AbtestRun
run
=
new
AbtestRun
();
}
}
}
run
.
setId
(
payload
.
getId
());
run
.
setKeyId
(
payload
.
getId
());
run
.
setCreator
(
payload
.
getOwner
());
run
.
setStartDate
(
payload
.
getStartDate
());
run
.
setEndDate
(
payload
.
getEndDate
());
run
.
setDomains
(
StringUtils
.
join
(
payload
.
getDomains
(),
','
));
run
.
setStrategyConfiguration
(
payload
.
getStrategyConfig
());
Date
now
=
new
Date
();
run
.
setModifiedDate
(
now
);
return
abtestModel
;
// only update run info, do not update abtest meta-info
m_abtestRunDao
.
updateByPK
(
run
,
AbtestRunEntity
.
UPDATESET_ALLOWED_MODIFYPART
);
}
catch
(
DalException
e
)
{
m_logger
.
error
(
"Error when
find all AbtestRun
"
,
e
);
m_logger
.
error
(
"Error when
updating abtest
"
,
e
);
Cat
.
logError
(
e
);
ctx
.
setException
(
e
);
}
return
null
;
}
private
Case
transform
(
AbtestRun
abtestRun
,
Abtest
entity
,
GroupStrategy
groupStrategy
)
throws
DalException
{
Case
_case
=
new
Case
(
entity
.
getId
());
_case
.
setCreatedDate
(
entity
.
getCreationDate
());
_case
.
setDescription
(
entity
.
getDescription
());
_case
.
setGroupStrategy
(
groupStrategy
.
getName
());
_case
.
setName
(
entity
.
getName
());
_case
.
setOwner
(
entity
.
getOwner
());
_case
.
setLastModifiedDate
(
entity
.
getModifiedDate
());
for
(
String
domain
:
StringUtils
.
split
(
entity
.
getDomains
(),
','
))
{
_case
.
addDomain
(
domain
);
}
Run
run
=
new
Run
(
abtestRun
.
getId
());
for
(
String
domain
:
StringUtils
.
split
(
abtestRun
.
getDomains
(),
','
))
{
run
.
addDomain
(
domain
);
}
run
.
setCreator
(
abtestRun
.
getCreator
());
run
.
setDisabled
(
false
);
run
.
setEndDate
(
abtestRun
.
getEndDate
());
run
.
setGroupStrategyConfiguration
(
abtestRun
.
getStrategyConfiguration
());
run
.
setStartDate
(
abtestRun
.
getStartDate
());
_case
.
addRun
(
run
);
return
_case
;
}
private
void
renderCreateModel
(
Model
model
)
{
...
...
@@ -293,21 +285,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
renderReportModel
(
ctx
,
model
,
payload
);
}
private
void
renderReportModel
(
Context
ctx
,
Model
model
,
Payload
payload
)
{
try
{
int
runId
=
payload
.
getId
();
AbtestRun
run
=
m_abtestRunDao
.
findByPK
(
runId
,
AbtestRunEntity
.
READSET_FULL
);
Abtest
abtest
=
m_abtestDao
.
findByPK
(
run
.
getCaseId
(),
AbtestEntity
.
READSET_FULL
);
AbtestDaoModel
abtestModel
=
new
AbtestDaoModel
(
abtest
,
run
);
model
.
setAbtest
(
abtestModel
);
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
m_logger
.
error
(
"Error when fetching abtest"
,
e
);
ctx
.
setException
(
e
);
}
}
private
void
renderListModel
(
Model
model
,
Payload
payload
)
{
List
<
ABTestReport
>
reports
=
new
ArrayList
<
ABTestReport
>();
AbtestStatus
status
=
AbtestStatus
.
getByName
(
payload
.
getStatus
(),
null
);
...
...
@@ -318,14 +295,11 @@ public class Handler implements PageHandler<Context>, LogEnabled {
int
createdCount
=
0
,
readyCount
=
0
,
runningCount
=
0
,
terminatedCount
=
0
,
suspendedCount
=
0
;
List
<
AbtestRun
>
runs
=
new
ArrayList
<
AbtestRun
>();
try
{
runs
=
m_abtestRunDao
.
findAll
(
AbtestRunEntity
.
READSET_FULL
);
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
for
(
AbtestRun
run
:
runs
)
{
try
{
for
(
AbtestRun
run
:
runs
)
{
Abtest
abtest
=
m_abtestDao
.
findByPK
(
run
.
getCaseId
(),
AbtestEntity
.
READSET_FULL
);
ABTestReport
report
=
new
ABTestReport
(
abtest
,
run
,
now
);
...
...
@@ -333,7 +307,6 @@ public class Handler implements PageHandler<Context>, LogEnabled {
if
(
status
!=
null
&&
report
.
getStatus
()
==
status
)
{
filterReports
.
add
(
report
);
}
switch
(
report
.
getStatus
())
{
case
CREATED:
createdCount
++;
...
...
@@ -351,9 +324,9 @@ public class Handler implements PageHandler<Context>, LogEnabled {
suspendedCount
++;
break
;
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
e
);
}
}
catch
(
Throwable
e
)
{
Cat
.
logError
(
e
);
}
model
.
setCreatedCount
(
createdCount
);
...
...
@@ -392,27 +365,50 @@ public class Handler implements PageHandler<Context>, LogEnabled {
model
.
setReports
(
reports
);
}
private
List
<
GroupStrategy
>
getAllGroupStrategys
()
{
private
void
renderModel
(
Model
model
)
{
model
.
setAbtestModel
(
fetchAbtestModel
().
toString
());
}
private
void
renderReportModel
(
Context
ctx
,
Model
model
,
Payload
payload
)
{
try
{
return
m_groupStrategyDao
.
findAllByStatus
(
1
,
GroupStrategyEntity
.
READSET_FULL
);
int
runId
=
payload
.
getId
();
AbtestRun
run
=
m_abtestRunDao
.
findByPK
(
runId
,
AbtestRunEntity
.
READSET_FULL
);
Abtest
abtest
=
m_abtestDao
.
findByPK
(
run
.
getCaseId
(),
AbtestEntity
.
READSET_FULL
);
AbtestDaoModel
abtestModel
=
new
AbtestDaoModel
(
abtest
,
run
);
model
.
setAbtest
(
abtestModel
);
}
catch
(
DalException
e
)
{
m_logger
.
error
(
e
.
getMessage
(),
e
);
Cat
.
logError
(
e
);
m_logger
.
error
(
"Error when fetching abtest"
,
e
);
ctx
.
setException
(
e
);
}
return
null
;
}
private
Map
<
String
,
List
<
Project
>>
getAllProjects
()
{
List
<
Project
>
projects
=
new
ArrayList
<
Project
>();
private
Case
transform
(
AbtestRun
abtestRun
,
Abtest
entity
,
GroupStrategy
groupStrategy
)
throws
DalException
{
Case
_case
=
new
Case
(
entity
.
getId
());
_case
.
setCreatedDate
(
entity
.
getCreationDate
());
_case
.
setDescription
(
entity
.
getDescription
());
_case
.
setGroupStrategy
(
groupStrategy
.
getName
());
_case
.
setName
(
entity
.
getName
());
_case
.
setOwner
(
entity
.
getOwner
());
_case
.
setLastModifiedDate
(
entity
.
getModifiedDate
());
for
(
String
domain
:
StringUtils
.
split
(
entity
.
getDomains
(),
','
))
{
_case
.
addDomain
(
domain
);
}
try
{
projects
=
m_projectDao
.
findAll
(
ProjectEntity
.
READSET_FULL
);
}
catch
(
Exception
e
)
{
m_logger
.
error
(
e
.
getMessage
(),
e
);
Cat
.
logError
(
e
);
Run
run
=
new
Run
(
abtestRun
.
getId
());
for
(
String
domain
:
StringUtils
.
split
(
abtestRun
.
getDomains
(),
','
))
{
run
.
addDomain
(
domain
);
}
// Collections.sort(projects, new ProjectCompartor());
return
transform
(
projects
);
run
.
setCreator
(
abtestRun
.
getCreator
());
run
.
setDisabled
(
false
);
run
.
setEndDate
(
abtestRun
.
getEndDate
());
run
.
setGroupStrategyConfiguration
(
abtestRun
.
getStrategyConfiguration
());
run
.
setStartDate
(
abtestRun
.
getStartDate
());
_case
.
addRun
(
run
);
return
_case
;
}
private
Map
<
String
,
List
<
Project
>>
transform
(
List
<
Project
>
projects
)
{
...
...
@@ -430,9 +426,4 @@ public class Handler implements PageHandler<Context>, LogEnabled {
}
return
re
;
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
}
cat-home/src/main/java/com/dianping/cat/system/page/abtest/Model.java
浏览文件 @
f5208064
...
...
@@ -41,7 +41,7 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
private
AbtestDaoModel
m_abtest
;
private
String
m_abtestModel
;
public
Model
(
Context
ctx
)
{
super
(
ctx
);
}
...
...
@@ -156,12 +156,12 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
}
public
String
getAbtestModel
()
{
return
m_abtestModel
;
}
return
m_abtestModel
;
}
public
void
setAbtestModel
(
String
abtestModel
)
{
m_abtestModel
=
abtestModel
;
}
m_abtestModel
=
abtestModel
;
}
public
static
class
AbtestDaoModel
{
...
...
@@ -192,45 +192,44 @@ public class Model extends ViewModel<SystemPage, Action, Context> {
}
public
String
getDescription
()
{
return
m_abtest
.
getDescription
();
}
return
m_abtest
.
getDescription
();
}
public
int
getGroupStrategy
()
{
return
m_abtest
.
getGroupStrategy
();
}
return
m_abtest
.
getGroupStrategy
();
}
public
String
getName
()
{
return
m_abtest
.
getName
();
}
return
m_abtest
.
getName
();
}
public
String
getOwner
()
{
return
m_abtest
.
getOwner
();
}
return
m_abtest
.
getOwner
();
}
public
int
getCaseId
()
{
return
m_run
.
getCaseId
();
}
return
m_run
.
getCaseId
();
}
public
String
getDomains
()
{
return
m_run
.
getDomains
();
}
return
m_run
.
getDomains
();
}
public
Date
getEndDate
()
{
return
m_run
.
getEndDate
();
}
return
m_run
.
getEndDate
();
}
public
int
getId
()
{
return
m_run
.
getId
();
}
return
m_run
.
getId
();
}
public
Date
getStartDate
()
{
return
m_run
.
getStartDate
();
}
return
m_run
.
getStartDate
();
}
public
String
getStrategyConfiguration
()
{
return
m_run
.
getStrategyConfiguration
();
}
return
m_run
.
getStrategyConfiguration
();
}
}
}
cat-home/src/main/java/com/dianping/cat/system/page/abtest/Payload.java
浏览文件 @
f5208064
...
...
@@ -49,12 +49,6 @@ public class Payload implements ActionPayload<SystemPage, Action> {
@FieldMeta
(
"strategyConfig"
)
private
String
m_strategyConfig
;
private
String
m_startDateStr
;
private
String
m_endDateStr
;
private
SimpleDateFormat
m_sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm"
);
@FieldMeta
(
"enable"
)
private
boolean
m_enableAbtest
;
...
...
@@ -67,6 +61,12 @@ public class Payload implements ActionPayload<SystemPage, Action> {
@FieldMeta
(
"id"
)
private
int
id
;
private
String
m_startDateStr
;
private
String
m_endDateStr
;
private
SimpleDateFormat
m_sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm"
);
public
void
setAction
(
String
action
)
{
if
(
action
.
equalsIgnoreCase
(
Action
.
REPORT
.
getName
()))
{
m_action
=
Action
.
getByName
(
action
,
Action
.
REPORT
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录