Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
3584d240
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,发现更多精彩内容 >>
提交
3584d240
编写于
4月 08, 2012
作者:
Y
You Yong
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
ssh://192.168.8.22:58422/cat
上级
0ec8ca40
ee800329
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
190 addition
and
125 deletion
+190
-125
cat-core/src/main/resources/META-INF/dal/model/server-codegen.xml
.../src/main/resources/META-INF/dal/model/server-codegen.xml
+1
-0
cat-home/src/main/java/com/dianping/cat/report/build/ServiceComponentConfigurator.java
...anping/cat/report/build/ServiceComponentConfigurator.java
+9
-20
cat-home/src/main/java/com/dianping/cat/report/page/model/event/HistoricalEventService.java
...g/cat/report/page/model/event/HistoricalEventService.java
+27
-2
cat-home/src/main/java/com/dianping/cat/report/page/model/logview/HistoricalLogViewService.java
...t/report/page/model/logview/HistoricalLogViewService.java
+4
-11
cat-home/src/main/java/com/dianping/cat/report/page/model/problem/HistoricalProblemService.java
...t/report/page/model/problem/HistoricalProblemService.java
+27
-2
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/BaseCompositeModelService.java
...rt/page/model/spi/internal/BaseCompositeModelService.java
+15
-8
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/BaseHistoricalModelService.java
...t/page/model/spi/internal/BaseHistoricalModelService.java
+29
-1
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/BaseLocalModelService.java
...report/page/model/spi/internal/BaseLocalModelService.java
+20
-6
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/ModelServiceWithCalSupport.java
...t/page/model/spi/internal/ModelServiceWithCalSupport.java
+2
-1
cat-home/src/main/java/com/dianping/cat/report/page/model/transaction/HistoricalTransactionService.java
.../page/model/transaction/HistoricalTransactionService.java
+27
-2
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+9
-39
cat-home/src/test/java/com/dianping/cat/report/page/model/event/EventModelServiceTest.java
...ng/cat/report/page/model/event/EventModelServiceTest.java
+9
-15
cat-home/src/test/java/com/dianping/cat/report/page/model/transaction/TransactionModelServiceTest.java
...t/page/model/transaction/TransactionModelServiceTest.java
+11
-18
未找到文件。
cat-core/src/main/resources/META-INF/dal/model/server-codegen.xml
浏览文件 @
3584d240
<?xml version="1.0" encoding="UTF-8"?>
<model>
<entity
name=
"config"
root=
"true"
>
<attribute
name=
"local-mode"
value-type=
"boolean"
/>
<entity-ref
name=
"storage"
/>
<entity-ref
name=
"consumer"
/>
<entity-ref
name=
"console"
/>
...
...
cat-home/src/main/java/com/dianping/cat/report/build/ServiceComponentConfigurator.java
浏览文件 @
3584d240
...
...
@@ -3,8 +3,8 @@ package com.dianping.cat.report.build;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.dianping.cat.configuration.ServerConfigManager
;
import
com.dianping.cat.hadoop.dal.LogviewDao
;
import
com.dianping.cat.hadoop.dal.ReportDao
;
import
com.dianping.cat.hadoop.hdfs.InputChannelManager
;
import
com.dianping.cat.message.spi.MessageCodec
;
import
com.dianping.cat.message.spi.MessageConsumer
;
...
...
@@ -31,40 +31,31 @@ class ServiceComponentConfigurator extends AbstractResourceConfigurator {
@Override
public
List
<
Component
>
defineComponents
()
{
List
<
Component
>
all
=
new
ArrayList
<
Component
>();
String
defaultDomain
=
property
(
"default-domain"
,
"Cat"
);
all
.
add
(
C
(
ModelService
.
class
,
"transaction-local"
,
LocalTransactionService
.
class
)
//
.
req
(
MessageConsumer
.
class
,
"realtime"
)
//
.
config
(
E
(
"defaultDomain"
).
value
(
defaultDomain
)));
.
req
(
MessageConsumer
.
class
,
"realtime"
));
all
.
add
(
C
(
ModelService
.
class
,
"transaction-historical"
,
HistoricalTransactionService
.
class
)
//
.
req
(
BucketManager
.
class
));
.
req
(
BucketManager
.
class
,
ReportDao
.
class
));
all
.
add
(
C
(
ModelService
.
class
,
"transaction"
,
CompositeTransactionService
.
class
)
//
.
req
(
ServerConfigManager
.
class
)
//
.
req
(
ModelService
.
class
,
new
String
[]
{
"transaction-local"
,
"transaction-historical"
},
"m_services"
));
all
.
add
(
C
(
ModelService
.
class
,
"event-local"
,
LocalEventService
.
class
)
//
.
req
(
MessageConsumer
.
class
,
"realtime"
)
//
.
config
(
E
(
"defaultDomain"
).
value
(
defaultDomain
)));
.
req
(
MessageConsumer
.
class
,
"realtime"
));
all
.
add
(
C
(
ModelService
.
class
,
"event-historical"
,
HistoricalEventService
.
class
)
//
.
req
(
BucketManager
.
class
));
.
req
(
BucketManager
.
class
,
ReportDao
.
class
));
all
.
add
(
C
(
ModelService
.
class
,
"event"
,
CompositeEventService
.
class
)
//
.
req
(
ServerConfigManager
.
class
)
//
.
req
(
ModelService
.
class
,
new
String
[]
{
"event-local"
,
"event-historical"
},
"m_services"
));
all
.
add
(
C
(
ModelService
.
class
,
"problem-local"
,
LocalProblemService
.
class
)
//
.
req
(
MessageConsumer
.
class
,
"realtime"
)
//
.
config
(
E
(
"defaultDomain"
).
value
(
defaultDomain
)));
.
req
(
MessageConsumer
.
class
,
"realtime"
));
all
.
add
(
C
(
ModelService
.
class
,
"problem-historical"
,
HistoricalProblemService
.
class
)
//
.
req
(
BucketManager
.
class
));
.
req
(
BucketManager
.
class
,
ReportDao
.
class
));
all
.
add
(
C
(
ModelService
.
class
,
"problem"
,
CompositeProblemService
.
class
)
//
.
req
(
ServerConfigManager
.
class
)
//
.
req
(
ModelService
.
class
,
new
String
[]
{
"problem-local"
,
"problem-historical"
},
"m_services"
));
all
.
add
(
C
(
ModelService
.
class
,
"ip-local"
,
LocalIpService
.
class
)
//
.
req
(
MessageConsumer
.
class
,
"realtime"
)
//
.
config
(
E
(
"defaultDomain"
).
value
(
defaultDomain
)));
.
req
(
MessageConsumer
.
class
,
"realtime"
));
all
.
add
(
C
(
ModelService
.
class
,
"ip"
,
CompositeIpService
.
class
)
//
.
req
(
ServerConfigManager
.
class
)
//
.
req
(
ModelService
.
class
,
new
String
[]
{
"ip-local"
},
"m_services"
));
all
.
add
(
C
(
ModelService
.
class
,
"logview-local"
,
LocalLogViewService
.
class
)
//
...
...
@@ -72,11 +63,9 @@ class ServiceComponentConfigurator extends AbstractResourceConfigurator {
.
req
(
BucketManager
.
class
)
//
.
req
(
MessageCodec
.
class
,
"html"
));
all
.
add
(
C
(
ModelService
.
class
,
"logview-historical"
,
HistoricalLogViewService
.
class
)
//
.
req
(
BucketManager
.
class
)
//
.
req
(
LogviewDao
.
class
,
InputChannelManager
.
class
)
//
.
req
(
BucketManager
.
class
,
LogviewDao
.
class
,
InputChannelManager
.
class
)
//
.
req
(
MessageCodec
.
class
,
"html"
));
all
.
add
(
C
(
ModelService
.
class
,
"logview"
,
CompositeLogViewService
.
class
)
//
.
req
(
ServerConfigManager
.
class
)
//
.
req
(
ModelService
.
class
,
new
String
[]
{
"logview-local"
,
"logview-historical"
},
"m_services"
));
return
all
;
...
...
cat-home/src/main/java/com/dianping/cat/report/page/model/event/HistoricalEventService.java
浏览文件 @
3584d240
...
...
@@ -10,12 +10,17 @@ import com.dianping.cat.hadoop.dal.ReportDao;
import
com.dianping.cat.hadoop.dal.ReportEntity
;
import
com.dianping.cat.report.page.model.spi.ModelRequest
;
import
com.dianping.cat.report.page.model.spi.internal.BaseHistoricalModelService
;
import
com.dianping.cat.storage.Bucket
;
import
com.dianping.cat.storage.BucketManager
;
import
com.site.lookup.annotation.Inject
;
public
class
HistoricalEventService
extends
BaseHistoricalModelService
<
EventReport
>
{
@Inject
private
ReportDao
m_reportDao
;
@Inject
private
BucketManager
m_bucketManager
;
public
HistoricalEventService
()
{
super
(
"event"
);
}
...
...
@@ -24,13 +29,33 @@ public class HistoricalEventService extends BaseHistoricalModelService<EventRepo
protected
EventReport
buildModel
(
ModelRequest
request
)
throws
Exception
{
String
domain
=
request
.
getDomain
();
long
date
=
Long
.
parseLong
(
request
.
getProperty
(
"date"
));
List
<
Report
>
reports
=
m_reportDao
.
findAllByPeriodDomainTypeName
(
new
Date
(
date
),
domain
,
1
,
getName
(),
EventReport
report
=
getLocalReport
(
date
,
domain
);
// try remote report
if
(
report
==
null
&&
!
isLocalMode
())
{
report
=
getRemoteReport
(
date
,
domain
);
}
return
report
;
}
private
EventReport
getLocalReport
(
long
timestamp
,
String
domain
)
throws
Exception
{
Bucket
<
String
>
bucket
=
m_bucketManager
.
getReportBucket
(
timestamp
,
"event"
);
String
xml
=
bucket
.
findById
(
domain
);
DefaultXmlParser
parser
=
new
DefaultXmlParser
();
return
parser
.
parse
(
xml
);
}
private
EventReport
getRemoteReport
(
long
timestamp
,
String
domain
)
throws
Exception
{
List
<
Report
>
reports
=
m_reportDao
.
findAllByPeriodDomainTypeName
(
new
Date
(
timestamp
),
domain
,
1
,
getName
(),
ReportEntity
.
READSET_FULL
);
DefaultXmlParser
parser
=
new
DefaultXmlParser
();
EventReportMerger
merger
=
null
;
for
(
Report
report
:
reports
)
{
String
xml
=
report
.
getContent
();
EventReport
model
=
new
DefaultXmlParser
()
.
parse
(
xml
);
EventReport
model
=
parser
.
parse
(
xml
);
if
(
merger
==
null
)
{
merger
=
new
EventReportMerger
(
model
);
...
...
cat-home/src/main/java/com/dianping/cat/report/page/model/logview/HistoricalLogViewService.java
浏览文件 @
3584d240
...
...
@@ -23,21 +23,18 @@ import com.dianping.cat.storage.BucketManager;
import
com.site.lookup.annotation.Inject
;
public
class
HistoricalLogViewService
extends
BaseHistoricalModelService
<
String
>
implements
LogEnabled
{
@Inject
private
LogviewDao
m_logviewDao
;
@Inject
(
value
=
"html"
)
private
MessageCodec
m_codec
;
@Inject
private
BucketManager
m_bucketManager
;
@Inject
private
LogviewDao
m_logviewDao
;
@Inject
private
InputChannelManager
m_inputChannelManager
;
@Inject
private
boolean
m_localOnly
;
private
Logger
m_logger
;
public
HistoricalLogViewService
()
{
...
...
@@ -51,7 +48,7 @@ public class HistoricalLogViewService extends BaseHistoricalModelService<String>
MessageTree
tree
=
getLocalLogview
(
messageId
,
direction
,
tagThread
);
// try remote logview
if
(
tree
==
null
&&
!
m_localOnly
)
{
if
(
tree
==
null
&&
!
isLocalMode
()
)
{
tree
=
getRemoteLogview
(
messageId
,
direction
,
tagThread
);
}
...
...
@@ -134,8 +131,4 @@ public class HistoricalLogViewService extends BaseHistoricalModelService<String>
}
}
}
public
void
setLocalOnly
(
boolean
localOnly
)
{
m_localOnly
=
localOnly
;
}
}
cat-home/src/main/java/com/dianping/cat/report/page/model/problem/HistoricalProblemService.java
浏览文件 @
3584d240
...
...
@@ -11,12 +11,17 @@ import com.dianping.cat.hadoop.dal.ReportDao;
import
com.dianping.cat.hadoop.dal.ReportEntity
;
import
com.dianping.cat.report.page.model.spi.ModelRequest
;
import
com.dianping.cat.report.page.model.spi.internal.BaseHistoricalModelService
;
import
com.dianping.cat.storage.Bucket
;
import
com.dianping.cat.storage.BucketManager
;
import
com.site.lookup.annotation.Inject
;
public
class
HistoricalProblemService
extends
BaseHistoricalModelService
<
ProblemReport
>
{
@Inject
private
ReportDao
m_reportDao
;
@Inject
private
BucketManager
m_bucketManager
;
public
HistoricalProblemService
()
{
super
(
"problem"
);
}
...
...
@@ -25,13 +30,33 @@ public class HistoricalProblemService extends BaseHistoricalModelService<Problem
protected
ProblemReport
buildModel
(
ModelRequest
request
)
throws
Exception
{
String
domain
=
request
.
getDomain
();
long
date
=
Long
.
parseLong
(
request
.
getProperty
(
"date"
));
List
<
Report
>
reports
=
m_reportDao
.
findAllByPeriodDomainTypeName
(
new
Date
(
date
),
domain
,
1
,
getName
(),
ProblemReport
report
=
getLocalReport
(
date
,
domain
);
// try remote report
if
(
report
==
null
&&
!
isLocalMode
())
{
report
=
getRemoteReport
(
date
,
domain
);
}
return
report
;
}
private
ProblemReport
getLocalReport
(
long
timestamp
,
String
domain
)
throws
Exception
{
Bucket
<
String
>
bucket
=
m_bucketManager
.
getReportBucket
(
timestamp
,
"problem"
);
String
xml
=
bucket
.
findById
(
domain
);
DefaultXmlParser
parser
=
new
DefaultXmlParser
();
return
parser
.
parse
(
xml
);
}
private
ProblemReport
getRemoteReport
(
long
timestamp
,
String
domain
)
throws
Exception
{
List
<
Report
>
reports
=
m_reportDao
.
findAllByPeriodDomainTypeName
(
new
Date
(
timestamp
),
domain
,
1
,
getName
(),
ReportEntity
.
READSET_FULL
);
DefaultXmlParser
parser
=
new
DefaultXmlParser
();
DefaultMerger
merger
=
null
;
for
(
Report
report
:
reports
)
{
String
xml
=
report
.
getContent
();
ProblemReport
model
=
new
DefaultXmlParser
()
.
parse
(
xml
);
ProblemReport
model
=
parser
.
parse
(
xml
);
if
(
merger
==
null
)
{
merger
=
new
DefaultMerger
(
model
);
...
...
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/BaseCompositeModelService.java
浏览文件 @
3584d240
...
...
@@ -14,6 +14,7 @@ import com.dianping.cat.Cat;
import
com.dianping.cat.configuration.NetworkInterfaceManager
;
import
com.dianping.cat.configuration.ServerConfigManager
;
import
com.dianping.cat.configuration.server.entity.ConsoleConfig
;
import
com.dianping.cat.configuration.server.entity.ServerConfig
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.page.model.spi.ModelRequest
;
...
...
@@ -27,9 +28,6 @@ public abstract class BaseCompositeModelService<T> extends ModelServiceWithCalSu
@Inject
private
List
<
ModelService
<
T
>>
m_services
;
@Inject
private
ServerConfigManager
m_configManager
;
private
ExecutorService
m_threadPool
;
private
String
m_name
;
...
...
@@ -52,11 +50,20 @@ public abstract class BaseCompositeModelService<T> extends ModelServiceWithCalSu
m_threadPool
=
Executors
.
newFixedThreadPool
(
10
);
m_allServices
.
addAll
(
m_services
);
ConsoleConfig
console
=
m_configManager
.
getServerConfig
().
getConsole
();
String
remoteServers
=
console
.
getRemoteServers
();
ServerConfigManager
manager
=
lookup
(
ServerConfigManager
.
class
);
ServerConfig
serverConfig
=
manager
.
getServerConfig
();
try
{
if
(
serverConfig
!=
null
)
{
ConsoleConfig
console
=
serverConfig
.
getConsole
();
String
remoteServers
=
console
.
getRemoteServers
();
if
(
remoteServers
!=
null
&&
remoteServers
.
length
()
>
0
)
{
setRemoteServers
(
remoteServers
);
if
(
remoteServers
!=
null
&&
remoteServers
.
length
()
>
0
)
{
setRemoteServers
(
remoteServers
);
}
}
}
finally
{
release
(
manager
);
}
}
...
...
@@ -78,7 +85,7 @@ public abstract class BaseCompositeModelService<T> extends ModelServiceWithCalSu
// save current transaction so that child thread can access it
if
(
service
instanceof
ModelServiceWithCalSupport
)
{
((
ModelServiceWithCalSupport
)
service
).
setParentTransaction
(
t
);
((
ModelServiceWithCalSupport
)
service
).
setParentTransaction
(
t
);
}
m_threadPool
.
submit
(
new
Runnable
()
{
...
...
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/BaseHistoricalModelService.java
浏览文件 @
3584d240
package
com.dianping.cat.report.page.model.spi.internal
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.configuration.ServerConfigManager
;
import
com.dianping.cat.configuration.server.entity.ServerConfig
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.report.page.model.spi.ModelRequest
;
import
com.dianping.cat.report.page.model.spi.ModelResponse
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
public
abstract
class
BaseHistoricalModelService
<
T
>
extends
ModelServiceWithCalSupport
implements
ModelService
<
T
>
{
public
abstract
class
BaseHistoricalModelService
<
T
>
extends
ModelServiceWithCalSupport
implements
ModelService
<
T
>,
Initializable
{
private
String
m_name
;
private
boolean
m_localMode
;
public
BaseHistoricalModelService
(
String
name
)
{
m_name
=
name
;
}
...
...
@@ -20,6 +28,22 @@ public abstract class BaseHistoricalModelService<T> extends ModelServiceWithCalS
return
m_name
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
ServerConfigManager
manager
=
lookup
(
ServerConfigManager
.
class
);
ServerConfig
serverConfig
=
manager
.
getServerConfig
();
try
{
if
(
serverConfig
!=
null
)
{
m_localMode
=
serverConfig
.
isLocalMode
();
}
else
{
m_localMode
=
true
;
}
}
finally
{
release
(
manager
);
}
}
@Override
public
ModelResponse
<
T
>
invoke
(
ModelRequest
request
)
{
ModelResponse
<
T
>
response
=
new
ModelResponse
<
T
>();
...
...
@@ -46,6 +70,10 @@ public abstract class BaseHistoricalModelService<T> extends ModelServiceWithCalS
return
request
.
getPeriod
().
isHistorical
();
}
protected
boolean
isLocalMode
()
{
return
m_localMode
;
}
@Override
public
String
toString
()
{
StringBuilder
sb
=
new
StringBuilder
(
64
);
...
...
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/BaseLocalModelService.java
浏览文件 @
3584d240
package
com.dianping.cat.report.page.model.spi.internal
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.configuration.ServerConfigManager
;
import
com.dianping.cat.configuration.server.entity.ServerConfig
;
import
com.dianping.cat.consumer.RealtimeConsumer
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
...
...
@@ -13,11 +18,10 @@ import com.dianping.cat.report.page.model.spi.ModelResponse;
import
com.dianping.cat.report.page.model.spi.ModelService
;
import
com.site.lookup.annotation.Inject
;
public
class
BaseLocalModelService
<
T
>
extends
ModelServiceWithCalSupport
implements
ModelService
<
T
>
{
public
abstract
class
BaseLocalModelService
<
T
>
extends
ModelServiceWithCalSupport
implements
ModelService
<
T
>,
Initializable
{
@Inject
(
type
=
MessageConsumer
.
class
,
value
=
"realtime"
)
private
RealtimeConsumer
m_consumer
;
@Inject
private
String
m_defaultDomain
;
private
String
m_name
;
...
...
@@ -83,10 +87,6 @@ public class BaseLocalModelService<T> extends ModelServiceWithCalSupport impleme
return
!
period
.
isHistorical
();
}
public
void
setDefaultDomain
(
String
defaultDomain
)
{
m_defaultDomain
=
defaultDomain
;
}
@Override
public
String
toString
()
{
StringBuilder
sb
=
new
StringBuilder
(
64
);
...
...
@@ -97,4 +97,18 @@ public class BaseLocalModelService<T> extends ModelServiceWithCalSupport impleme
return
sb
.
toString
();
}
@Override
public
void
initialize
()
throws
InitializationException
{
ServerConfigManager
manager
=
lookup
(
ServerConfigManager
.
class
);
ServerConfig
config
=
manager
.
getServerConfig
();
try
{
if
(
config
!=
null
)
{
m_defaultDomain
=
config
.
getConsole
().
getDefaultDomain
();
}
}
finally
{
release
(
manager
);
}
}
}
cat-home/src/main/java/com/dianping/cat/report/page/model/spi/internal/ModelServiceWithCalSupport.java
浏览文件 @
3584d240
...
...
@@ -7,8 +7,9 @@ import com.dianping.cat.Cat;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Transaction
;
import
com.dianping.cat.message.internal.DefaultMessageProducer
;
import
com.site.lookup.ContainerHolder
;
public
abstract
class
ModelServiceWithCalSupport
{
public
abstract
class
ModelServiceWithCalSupport
extends
ContainerHolder
{
private
Transaction
m_current
;
protected
void
setParentTransaction
(
Transaction
current
)
{
...
...
cat-home/src/main/java/com/dianping/cat/report/page/model/transaction/HistoricalTransactionService.java
浏览文件 @
3584d240
...
...
@@ -10,12 +10,17 @@ import com.dianping.cat.hadoop.dal.ReportDao;
import
com.dianping.cat.hadoop.dal.ReportEntity
;
import
com.dianping.cat.report.page.model.spi.ModelRequest
;
import
com.dianping.cat.report.page.model.spi.internal.BaseHistoricalModelService
;
import
com.dianping.cat.storage.Bucket
;
import
com.dianping.cat.storage.BucketManager
;
import
com.site.lookup.annotation.Inject
;
public
class
HistoricalTransactionService
extends
BaseHistoricalModelService
<
TransactionReport
>
{
@Inject
private
ReportDao
m_reportDao
;
@Inject
private
BucketManager
m_bucketManager
;
public
HistoricalTransactionService
()
{
super
(
"transaction"
);
}
...
...
@@ -24,13 +29,33 @@ public class HistoricalTransactionService extends BaseHistoricalModelService<Tra
protected
TransactionReport
buildModel
(
ModelRequest
request
)
throws
Exception
{
String
domain
=
request
.
getDomain
();
long
date
=
Long
.
parseLong
(
request
.
getProperty
(
"date"
));
List
<
Report
>
reports
=
m_reportDao
.
findAllByPeriodDomainTypeName
(
new
Date
(
date
),
domain
,
1
,
getName
(),
TransactionReport
report
=
getLocalReport
(
date
,
domain
);
// try remote report
if
(
report
==
null
&&
!
isLocalMode
())
{
report
=
getRemoteReport
(
date
,
domain
);
}
return
report
;
}
private
TransactionReport
getLocalReport
(
long
timestamp
,
String
domain
)
throws
Exception
{
Bucket
<
String
>
bucket
=
m_bucketManager
.
getReportBucket
(
timestamp
,
"transaction"
);
String
xml
=
bucket
.
findById
(
domain
);
DefaultXmlParser
parser
=
new
DefaultXmlParser
();
return
parser
.
parse
(
xml
);
}
private
TransactionReport
getRemoteReport
(
long
timestamp
,
String
domain
)
throws
Exception
{
List
<
Report
>
reports
=
m_reportDao
.
findAllByPeriodDomainTypeName
(
new
Date
(
timestamp
),
domain
,
1
,
getName
(),
ReportEntity
.
READSET_FULL
);
DefaultXmlParser
parser
=
new
DefaultXmlParser
();
TransactionReportMerger
merger
=
null
;
for
(
Report
report
:
reports
)
{
String
xml
=
report
.
getContent
();
TransactionReport
model
=
new
DefaultXmlParser
()
.
parse
(
xml
);
TransactionReport
model
=
parser
.
parse
(
xml
);
if
(
merger
==
null
)
{
merger
=
new
TransactionReportMerger
(
model
);
...
...
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
3584d240
...
...
@@ -30,9 +30,6 @@
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hint>
transaction-local
</role-hint>
<implementation>
com.dianping.cat.report.page.model.transaction.LocalTransactionService
</implementation>
<configuration>
<defaultDomain>
Cat
</defaultDomain>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessageConsumer
</role>
...
...
@@ -48,6 +45,9 @@
<requirement>
<role>
com.dianping.cat.storage.BucketManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.hadoop.dal.ReportDao
</role>
</requirement>
</requirements>
</component>
<component>
...
...
@@ -55,9 +55,6 @@
<role-hint>
transaction
</role-hint>
<implementation>
com.dianping.cat.report.page.model.transaction.CompositeTransactionService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.configuration.ServerConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hints>
...
...
@@ -72,9 +69,6 @@
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hint>
event-local
</role-hint>
<implementation>
com.dianping.cat.report.page.model.event.LocalEventService
</implementation>
<configuration>
<defaultDomain>
Cat
</defaultDomain>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessageConsumer
</role>
...
...
@@ -90,6 +84,9 @@
<requirement>
<role>
com.dianping.cat.storage.BucketManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.hadoop.dal.ReportDao
</role>
</requirement>
</requirements>
</component>
<component>
...
...
@@ -97,9 +94,6 @@
<role-hint>
event
</role-hint>
<implementation>
com.dianping.cat.report.page.model.event.CompositeEventService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.configuration.ServerConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hints>
...
...
@@ -114,9 +108,6 @@
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hint>
problem-local
</role-hint>
<implementation>
com.dianping.cat.report.page.model.problem.LocalProblemService
</implementation>
<configuration>
<defaultDomain>
Cat
</defaultDomain>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessageConsumer
</role>
...
...
@@ -132,6 +123,9 @@
<requirement>
<role>
com.dianping.cat.storage.BucketManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.hadoop.dal.ReportDao
</role>
</requirement>
</requirements>
</component>
<component>
...
...
@@ -139,9 +133,6 @@
<role-hint>
problem
</role-hint>
<implementation>
com.dianping.cat.report.page.model.problem.CompositeProblemService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.configuration.ServerConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hints>
...
...
@@ -156,9 +147,6 @@
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hint>
ip-local
</role-hint>
<implementation>
com.dianping.cat.report.page.model.ip.LocalIpService
</implementation>
<configuration>
<defaultDomain>
Cat
</defaultDomain>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.message.spi.MessageConsumer
</role>
...
...
@@ -171,9 +159,6 @@
<role-hint>
ip
</role-hint>
<implementation>
com.dianping.cat.report.page.model.ip.CompositeIpService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.configuration.ServerConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hints>
...
...
@@ -226,9 +211,6 @@
<role-hint>
logview
</role-hint>
<implementation>
com.dianping.cat.report.page.model.logview.CompositeLogViewService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.configuration.ServerConfigManager
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.report.page.model.spi.ModelService
</role>
<role-hints>
...
...
@@ -438,9 +420,6 @@
<role-hint>
realtime
</role-hint>
<field-name>
m_consumer
</field-name>
</requirement>
<requirement>
<role>
java.lang.String
</role>
</requirement>
</requirements>
</component>
<component>
...
...
@@ -452,9 +431,6 @@
<role-hint>
realtime
</role-hint>
<field-name>
m_consumer
</field-name>
</requirement>
<requirement>
<role>
java.lang.String
</role>
</requirement>
</requirements>
</component>
<component>
...
...
@@ -466,9 +442,6 @@
<role-hint>
realtime
</role-hint>
<field-name>
m_consumer
</field-name>
</requirement>
<requirement>
<role>
java.lang.String
</role>
</requirement>
</requirements>
</component>
<component>
...
...
@@ -487,9 +460,6 @@
<role-hint>
realtime
</role-hint>
<field-name>
m_consumer
</field-name>
</requirement>
<requirement>
<role>
java.lang.String
</role>
</requirement>
</requirements>
</component>
<component>
...
...
cat-home/src/test/java/com/dianping/cat/report/page/model/event/EventModelServiceTest.java
浏览文件 @
3584d240
...
...
@@ -2,10 +2,12 @@ package com.dianping.cat.report.page.model.event;
import
junit.framework.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.JUnit4
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.report.page.model.spi.ModelRequest
;
import
com.dianping.cat.report.page.model.spi.ModelResponse
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
...
...
@@ -13,14 +15,19 @@ import com.site.lookup.ComponentTestCase;
@RunWith
(
JUnit4
.
class
)
public
class
EventModelServiceTest
extends
ComponentTestCase
{
@Before
public
void
before
()
throws
Exception
{
if
(!
Cat
.
isInitialized
())
{
Cat
.
initialize
(
null
);
}
}
@Test
public
void
testLookup
()
throws
Exception
{
ModelService
<?>
local
=
lookup
(
ModelService
.
class
,
"event-local"
);
ModelService
<?>
localhost
=
lookup
(
ModelService
.
class
,
"event-localhost"
);
ModelService
<?>
composite
=
lookup
(
ModelService
.
class
,
"event"
);
Assert
.
assertEquals
(
LocalEventService
.
class
,
local
.
getClass
());
Assert
.
assertEquals
(
RemoteEventService
.
class
,
localhost
.
getClass
());
Assert
.
assertEquals
(
CompositeEventService
.
class
,
composite
.
getClass
());
}
...
...
@@ -31,17 +38,4 @@ public class EventModelServiceTest extends ComponentTestCase {
Assert
.
assertEquals
(
"null"
,
String
.
valueOf
(
response
.
getModel
()));
}
@Test
public
void
testRemote
()
throws
Exception
{
RemoteEventService
remote
=
(
RemoteEventService
)
lookup
(
ModelService
.
class
,
"event-localhost"
);
ModelRequest
request
=
ModelRequest
.
from
(
"Cat"
,
"CURRENT"
);
Assert
.
assertEquals
(
"http://localhost:2281/cat/r/e/service?domain=Cat&period=CURRENT"
,
remote
.
buildUrl
(
request
)
.
toString
());
ModelResponse
<?>
response
=
remote
.
invoke
(
request
);
Assert
.
assertEquals
(
"null"
,
String
.
valueOf
(
response
.
getModel
()));
}
}
cat-home/src/test/java/com/dianping/cat/report/page/model/transaction/TransactionModelServiceTest.java
浏览文件 @
3584d240
...
...
@@ -2,10 +2,12 @@ package com.dianping.cat.report.page.model.transaction;
import
junit.framework.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.JUnit4
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.report.page.model.spi.ModelRequest
;
import
com.dianping.cat.report.page.model.spi.ModelResponse
;
import
com.dianping.cat.report.page.model.spi.ModelService
;
...
...
@@ -13,36 +15,27 @@ import com.site.lookup.ComponentTestCase;
@RunWith
(
JUnit4
.
class
)
public
class
TransactionModelServiceTest
extends
ComponentTestCase
{
@Before
public
void
before
()
throws
Exception
{
if
(!
Cat
.
isInitialized
())
{
Cat
.
initialize
(
null
);
}
}
@Test
public
void
testLookup
()
throws
Exception
{
ModelService
<?>
local
=
lookup
(
ModelService
.
class
,
"transaction-local"
);
ModelService
<?>
localhost
=
lookup
(
ModelService
.
class
,
"transaction-localhost"
);
ModelService
<?>
composite
=
lookup
(
ModelService
.
class
,
"transaction"
);
Assert
.
assertEquals
(
LocalTransactionService
.
class
,
local
.
getClass
());
Assert
.
assertEquals
(
RemoteTransactionService
.
class
,
localhost
.
getClass
());
Assert
.
assertEquals
(
CompositeTransactionService
.
class
,
composite
.
getClass
());
}
@Test
public
void
testLocal
()
throws
Exception
{
LocalTransactionService
local
=
(
LocalTransactionService
)
lookup
(
ModelService
.
class
,
"transaction-local"
);
LocalTransactionService
local
=
(
LocalTransactionService
)
lookup
(
ModelService
.
class
,
"transaction-local"
);
ModelResponse
<?>
response
=
local
.
invoke
(
ModelRequest
.
from
(
"Cat"
,
"CURRENT"
));
Assert
.
assertEquals
(
"null"
,
String
.
valueOf
(
response
.
getModel
()));
// TODO try to mock up a real consumer for test
}
@Test
public
void
testRemote
()
throws
Exception
{
RemoteTransactionService
remote
=
(
RemoteTransactionService
)
lookup
(
ModelService
.
class
,
"transaction-localhost"
);
ModelRequest
request
=
ModelRequest
.
from
(
"Cat"
,
"CURRENT"
);
Assert
.
assertEquals
(
"http://localhost:2281/cat/r/t/service?domain=Cat&period=CURRENT"
,
remote
.
buildUrl
(
request
).
toString
());
ModelResponse
<?>
response
=
remote
.
invoke
(
request
);
Assert
.
assertEquals
(
"null"
,
String
.
valueOf
(
response
.
getModel
()));
// TODO start a test server, and do real stuff
Assert
.
assertEquals
(
"null"
,
String
.
valueOf
(
response
.
getModel
()));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录