mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 08:16:15 +10:00
Merge pull request #664 from emeroad/#662_refactoring_extract_ApplicationFacory
#662 refactoring ApplicaitonClass Creation logic
This commit is contained in:
@@ -17,11 +17,11 @@
|
||||
package com.navercorp.pinpoint.web.controller;
|
||||
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.web.applicationmap.ApplicationMap;
|
||||
import com.navercorp.pinpoint.web.applicationmap.MapWrap;
|
||||
import com.navercorp.pinpoint.web.applicationmap.histogram.Histogram;
|
||||
import com.navercorp.pinpoint.web.applicationmap.histogram.NodeHistogram;
|
||||
import com.navercorp.pinpoint.web.service.ApplicationFactory;
|
||||
import com.navercorp.pinpoint.web.service.MapService;
|
||||
import com.navercorp.pinpoint.web.util.Limiter;
|
||||
import com.navercorp.pinpoint.web.util.TimeUtils;
|
||||
@@ -35,11 +35,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -64,11 +64,14 @@ public class MapController {
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
private static final String DEFAULT_SEARCH_DEPTH = "8";
|
||||
private static final int DEFAULT_MAX_SEARCH_DEPTH = 8;
|
||||
|
||||
/**
|
||||
* Server map data query within from ~ to timeframe
|
||||
* Server map data query within from ~ to timeframe
|
||||
*
|
||||
* @param applicationName
|
||||
* @param serviceTypeCode
|
||||
@@ -85,12 +88,21 @@ public class MapController {
|
||||
@RequestParam("to") long to,
|
||||
@RequestParam(value = "callerRange", defaultValue = DEFAULT_SEARCH_DEPTH) int callerRange,
|
||||
@RequestParam(value = "calleeRange", defaultValue = DEFAULT_SEARCH_DEPTH) int calleeRange) {
|
||||
ServiceType serviceType = registry.findServiceType(serviceTypeCode);
|
||||
return getServerMapData(applicationName, serviceType.getName(), from, to, callerRange, calleeRange);
|
||||
final Range range = new Range(from, to);
|
||||
this.dateLimit.limit(range);
|
||||
|
||||
SearchOption searchOption = new SearchOption(callerRange, calleeRange);
|
||||
assertSearchOption(searchOption);
|
||||
|
||||
Application application = applicationFactory.createApplication(applicationName, serviceTypeCode);
|
||||
|
||||
return selectApplicationMap(application, range, searchOption);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Server map data query within from ~ to timeframe
|
||||
* Server map data query within from ~ to timeframe
|
||||
*
|
||||
* @param applicationName
|
||||
* @param serviceTypeName
|
||||
@@ -108,16 +120,28 @@ public class MapController {
|
||||
@RequestParam(value = "callerRange", defaultValue = DEFAULT_SEARCH_DEPTH) int callerRange,
|
||||
@RequestParam(value = "calleeRange", defaultValue = DEFAULT_SEARCH_DEPTH) int calleeRange) {
|
||||
final Range range = new Range(from, to);
|
||||
this.dateLimit.limit(from, to);
|
||||
this.dateLimit.limit(range);
|
||||
|
||||
SearchOption searchOption = new SearchOption(callerRange, calleeRange);
|
||||
assertSearchOption(searchOption);
|
||||
|
||||
logger.info("getServerMap() applicationName:{} range:{} searchOption:{}", applicationName, TimeUnit.MILLISECONDS.toMinutes(range.getRange()), searchOption);
|
||||
Application application = applicationFactory.createApplicationByTypeName(applicationName, serviceTypeName);
|
||||
|
||||
return selectApplicationMap(application, range, searchOption);
|
||||
}
|
||||
|
||||
ServiceType serviceType = registry.findServiceTypeByName(serviceTypeName);
|
||||
Application application = new Application(applicationName, serviceType);
|
||||
private MapWrap selectApplicationMap(Application application, Range range, SearchOption searchOption) {
|
||||
if (application == null) {
|
||||
throw new NullPointerException("application must not be null");
|
||||
}
|
||||
if (range == null) {
|
||||
throw new NullPointerException("range must not be null");
|
||||
}
|
||||
if (searchOption == null) {
|
||||
throw new NullPointerException("searchOption must not be null");
|
||||
}
|
||||
|
||||
logger.info("getServerMap() application:{} range:{} searchOption:{}", application, range, searchOption);
|
||||
|
||||
ApplicationMap map = mapService.selectApplicationMap(application, range, searchOption);
|
||||
|
||||
@@ -142,7 +166,7 @@ public class MapController {
|
||||
}
|
||||
|
||||
/**
|
||||
* Server map data query for the last "Period" timeframe
|
||||
* Server map data query for the last "Period" timeframe
|
||||
*
|
||||
* @param applicationName
|
||||
* @param serviceTypeCode
|
||||
@@ -160,11 +184,20 @@ public class MapController {
|
||||
|
||||
long to = TimeUtils.getDelayLastTime();
|
||||
long from = to - period;
|
||||
return getServerMapData(applicationName, serviceTypeCode, from, to, callerRange, calleeRange);
|
||||
|
||||
final Range range = new Range(from, to);
|
||||
this.dateLimit.limit(range);
|
||||
|
||||
SearchOption searchOption = new SearchOption(callerRange, calleeRange);
|
||||
assertSearchOption(searchOption);
|
||||
|
||||
Application application = applicationFactory.createApplication(applicationName, serviceTypeCode);
|
||||
|
||||
return selectApplicationMap(application, range, searchOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Server map data query for the last "Period" timeframe
|
||||
* Server map data query for the last "Period" timeframe
|
||||
*
|
||||
* @param applicationName
|
||||
* @param serviceTypeName
|
||||
@@ -182,14 +215,21 @@ public class MapController {
|
||||
|
||||
long to = TimeUtils.getDelayLastTime();
|
||||
long from = to - period;
|
||||
return getServerMapData(applicationName, serviceTypeName, from, to, callerRange, calleeRange);
|
||||
|
||||
final Range range = new Range(from, to);
|
||||
this.dateLimit.limit(range);
|
||||
|
||||
SearchOption searchOption = new SearchOption(callerRange, calleeRange);
|
||||
assertSearchOption(searchOption);
|
||||
|
||||
Application application = applicationFactory.createApplicationByTypeName(applicationName, serviceTypeName);
|
||||
return selectApplicationMap(application, range, searchOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible deprecation expected when UI change push forward to pick a map first from UI
|
||||
* Unfiltered server map request data query
|
||||
*
|
||||
* @param model
|
||||
* @param from
|
||||
* @param to
|
||||
* @param sourceApplicationName
|
||||
@@ -200,23 +240,22 @@ public class MapController {
|
||||
*/
|
||||
@Deprecated
|
||||
@RequestMapping(value = "/linkStatistics", method = RequestMethod.GET, params={"sourceServiceType", "targetServiceType"})
|
||||
public String getLinkStatistics(Model model,
|
||||
@RequestParam("from") long from,
|
||||
public ModelAndView getLinkStatistics(@RequestParam("from") long from,
|
||||
@RequestParam("to") long to,
|
||||
@RequestParam("sourceApplicationName") String sourceApplicationName,
|
||||
@RequestParam("sourceServiceType") short sourceServiceType,
|
||||
@RequestParam("targetApplicationName") String targetApplicationName,
|
||||
@RequestParam("targetServiceType") short targetServiceType) {
|
||||
String sourceServiceTypeName = registry.findServiceType(sourceServiceType).getName();
|
||||
String targetServiceTypeName = registry.findServiceType(targetServiceType).getName();
|
||||
return getLinkStatistics(model, from, to, sourceApplicationName, sourceServiceTypeName, targetApplicationName, targetServiceTypeName);
|
||||
final Application sourceApplication = this.applicationFactory.createApplication(sourceApplicationName, sourceServiceType);
|
||||
final Application destinationApplication = this.applicationFactory.createApplication(targetApplicationName, targetServiceType);
|
||||
final Range range = new Range(from, to);
|
||||
return getLinkStatistics(sourceApplication, destinationApplication, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible deprecation expected when UI change push forward to pick a map first from UI
|
||||
* Unfiltered server map request data query
|
||||
*
|
||||
* @param model
|
||||
* @param from
|
||||
* @param to
|
||||
* @param sourceApplicationName
|
||||
@@ -227,46 +266,49 @@ public class MapController {
|
||||
*/
|
||||
@Deprecated
|
||||
@RequestMapping(value = "/linkStatistics", method = RequestMethod.GET, params={"sourceServiceTypeName", "targetServiceTypeName"})
|
||||
public String getLinkStatistics(Model model,
|
||||
@RequestParam("from") long from,
|
||||
public ModelAndView getLinkStatistics(@RequestParam("from") long from,
|
||||
@RequestParam("to") long to,
|
||||
@RequestParam("sourceApplicationName") String sourceApplicationName,
|
||||
@RequestParam("sourceServiceTypeName") String sourceServiceTypeName,
|
||||
@RequestParam("targetApplicationName") String targetApplicationName,
|
||||
@RequestParam("targetServiceTypeName") String targetServiceTypeName) {
|
||||
|
||||
final Application sourceApplication = new Application(sourceApplicationName, registry.findServiceTypeByName(sourceServiceTypeName));
|
||||
final Application destinationApplication = new Application(targetApplicationName, registry.findServiceTypeByName(targetServiceTypeName));
|
||||
final Range range = new Range(from, to);
|
||||
|
||||
NodeHistogram nodeHistogram = mapService.linkStatistics(sourceApplication, destinationApplication, range);
|
||||
|
||||
model.addAttribute("range", range);
|
||||
|
||||
model.addAttribute("sourceApplication", sourceApplication);
|
||||
|
||||
model.addAttribute("targetApplication", destinationApplication);
|
||||
|
||||
Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
|
||||
model.addAttribute("linkStatistics", applicationHistogram);
|
||||
|
||||
|
||||
List<ResponseTimeViewModel> applicationTimeSeriesHistogram = nodeHistogram.getApplicationTimeHistogram();
|
||||
String applicationTimeSeriesHistogramJson = null;
|
||||
try {
|
||||
applicationTimeSeriesHistogramJson = MAPPER.writeValueAsString(applicationTimeSeriesHistogram);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
model.addAttribute("timeSeriesHistogram", applicationTimeSeriesHistogramJson);
|
||||
|
||||
// looks like we need to specify "from, to" to the result. but data got passed thru as it is.
|
||||
model.addAttribute("resultFrom", from);
|
||||
model.addAttribute("resultTo", to);
|
||||
|
||||
|
||||
return "linkStatistics";
|
||||
final Application sourceApplication = this.applicationFactory.createApplicationByTypeName(sourceApplicationName, sourceServiceTypeName);
|
||||
final Application destinationApplication = this.applicationFactory.createApplicationByTypeName(targetApplicationName, targetServiceTypeName);
|
||||
final Range range = new Range(from, to);
|
||||
return getLinkStatistics(sourceApplication, destinationApplication, range);
|
||||
}
|
||||
|
||||
private ModelAndView getLinkStatistics(Application sourceApplication, Application destinationApplication, Range range) {
|
||||
|
||||
NodeHistogram nodeHistogram = mapService.linkStatistics(sourceApplication, destinationApplication, range);
|
||||
|
||||
final ModelAndView mav = new ModelAndView("linkStatistics");
|
||||
mav.addObject("range", range);
|
||||
|
||||
mav.addObject("sourceApplication", sourceApplication);
|
||||
|
||||
mav.addObject("targetApplication", destinationApplication);
|
||||
|
||||
Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
|
||||
mav.addObject("linkStatistics", applicationHistogram);
|
||||
|
||||
|
||||
List<ResponseTimeViewModel> applicationTimeSeriesHistogram = nodeHistogram.getApplicationTimeHistogram();
|
||||
String applicationTimeSeriesHistogramJson = null;
|
||||
try {
|
||||
applicationTimeSeriesHistogramJson = MAPPER.writeValueAsString(applicationTimeSeriesHistogram);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
mav.addObject("timeSeriesHistogram", applicationTimeSeriesHistogramJson);
|
||||
|
||||
// looks like we need to specify "from, to" to the result. but data got passed thru as it is.
|
||||
mav.addObject("resultFrom", range.getFrom());
|
||||
mav.addObject("resultTo", range.getTo());
|
||||
|
||||
return mav;
|
||||
}
|
||||
@Deprecated
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.navercorp.pinpoint.web.service.ApplicationFactory;
|
||||
import org.apache.hadoop.hbase.Cell;
|
||||
import org.apache.hadoop.hbase.CellUtil;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
@@ -40,7 +41,7 @@ import com.navercorp.pinpoint.web.vo.Application;
|
||||
public class ApplicationNameMapper implements RowMapper<List<Application>> {
|
||||
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
@Override
|
||||
public List<Application> mapRow(Result result, int rowNum) throws Exception {
|
||||
@@ -55,10 +56,11 @@ public class ApplicationNameMapper implements RowMapper<List<Application>> {
|
||||
short serviceTypeCode = Bytes.toShort(CellUtil.cloneValue(cell));
|
||||
uniqueTypeCodes.add(serviceTypeCode);
|
||||
}
|
||||
List<Application> applications = new ArrayList<Application>();
|
||||
List<Application> applicationList = new ArrayList<Application>();
|
||||
for (short serviceTypeCode : uniqueTypeCodes) {
|
||||
applications.add(new Application(applicationName, registry.findServiceType(serviceTypeCode)));
|
||||
final Application application = applicationFactory.createApplication(applicationName, serviceTypeCode);
|
||||
applicationList.add(application);
|
||||
}
|
||||
return applications;
|
||||
return applicationList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Arrays;
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
|
||||
import com.navercorp.pinpoint.web.service.ApplicationFactory;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.slf4j.Logger;
|
||||
@@ -43,7 +44,7 @@ public class HostApplicationMapper implements RowMapper<Application> {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
@Override
|
||||
public Application mapRow(Result result, int rowNum) throws Exception {
|
||||
@@ -58,7 +59,6 @@ public class HostApplicationMapper implements RowMapper<Application> {
|
||||
|
||||
String applicationName = Bytes.toString(value, 0, HBaseTables.APPLICATION_NAME_MAX_LEN - 1).trim();
|
||||
short serviceTypeCode = Bytes.toShort(value, HBaseTables.APPLICATION_NAME_MAX_LEN);
|
||||
ServiceType serviceType = registry.findServiceType(serviceTypeCode);
|
||||
return new Application(applicationName, serviceType);
|
||||
return this.applicationFactory.createApplication(applicationName, serviceTypeCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ package com.navercorp.pinpoint.web.mapper;
|
||||
|
||||
import com.navercorp.pinpoint.common.buffer.Buffer;
|
||||
import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer;
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.web.service.ApplicationFactory;
|
||||
import com.navercorp.pinpoint.web.service.map.AcceptApplication;
|
||||
import com.navercorp.pinpoint.web.vo.Application;
|
||||
|
||||
@@ -47,7 +46,7 @@ public class HostApplicationMapperVer2 implements RowMapper<List<AcceptApplicati
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
@Override
|
||||
public List<AcceptApplication> mapRow(Result result, int rowNum) throws Exception {
|
||||
@@ -81,8 +80,7 @@ public class HostApplicationMapperVer2 implements RowMapper<List<AcceptApplicati
|
||||
String bindApplicationName = reader.readPrefixedString();
|
||||
short bindServiceTypeCode = reader.readShort();
|
||||
|
||||
ServiceType bindServiceType = registry.findServiceType(bindServiceTypeCode);
|
||||
Application bindApplication = new Application(bindApplicationName, bindServiceType);
|
||||
final Application bindApplication = applicationFactory.createApplication(bindApplicationName, bindServiceTypeCode);
|
||||
return new AcceptApplication(host, bindApplication);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.ApplicationMapStatisticsUtils;
|
||||
import com.navercorp.pinpoint.common.util.TimeUtils;
|
||||
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap;
|
||||
import com.navercorp.pinpoint.web.service.ApplicationFactory;
|
||||
import com.navercorp.pinpoint.web.vo.Application;
|
||||
|
||||
import org.apache.hadoop.hbase.Cell;
|
||||
@@ -50,6 +51,9 @@ public class MapStatisticsCalleeMapper implements RowMapper<LinkDataMap> {
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
public MapStatisticsCalleeMapper() {
|
||||
this(SkipLinkFilter.FILTER);
|
||||
}
|
||||
@@ -114,17 +118,14 @@ public class MapStatisticsCalleeMapper implements RowMapper<LinkDataMap> {
|
||||
} else {
|
||||
callerApplicationName = ApplicationMapStatisticsUtils.getDestApplicationNameFromColumnName(qualifier);
|
||||
}
|
||||
return createApplication(callerApplicationName, callerServiceType);
|
||||
return this.applicationFactory.createApplication(callerApplicationName, callerServiceType);
|
||||
}
|
||||
|
||||
private Application readCalleeApplication(Buffer row) {
|
||||
String calleeApplicationName = row.read2PrefixedString();
|
||||
short calleeServiceType = row.readShort();
|
||||
return createApplication(calleeApplicationName, calleeServiceType);
|
||||
|
||||
return this.applicationFactory.createApplication(calleeApplicationName, calleeServiceType);
|
||||
}
|
||||
|
||||
private Application createApplication(String applicationName, short serviceTypeCode) {
|
||||
ServiceType serviceType = registry.findServiceType(serviceTypeCode);
|
||||
return new Application(applicationName, serviceType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ import com.navercorp.pinpoint.common.buffer.FixedBuffer;
|
||||
import com.navercorp.pinpoint.common.buffer.OffsetFixedBuffer;
|
||||
import com.navercorp.pinpoint.common.hbase.HBaseTables;
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.common.util.ApplicationMapStatisticsUtils;
|
||||
import com.navercorp.pinpoint.common.util.TimeUtils;
|
||||
import com.navercorp.pinpoint.web.applicationmap.rawdata.LinkDataMap;
|
||||
import com.navercorp.pinpoint.web.service.ApplicationFactory;
|
||||
import com.navercorp.pinpoint.web.vo.Application;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -56,6 +56,9 @@ public class MapStatisticsCallerMapper implements RowMapper<LinkDataMap> {
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
public MapStatisticsCallerMapper() {
|
||||
this(SkipLinkFilter.FILTER);
|
||||
}
|
||||
@@ -148,24 +151,20 @@ public class MapStatisticsCallerMapper implements RowMapper<LinkDataMap> {
|
||||
private Application readCalleeApplication(byte[] qualifier) {
|
||||
String calleeApplicationName = ApplicationMapStatisticsUtils.getDestApplicationNameFromColumnName(qualifier);
|
||||
short calleeServiceType = ApplicationMapStatisticsUtils.getDestServiceTypeFromColumnName(qualifier);
|
||||
return createApplication(calleeApplicationName, calleeServiceType);
|
||||
return applicationFactory.createApplication(calleeApplicationName, calleeServiceType);
|
||||
}
|
||||
|
||||
|
||||
private Application readCalleeApplication(Buffer buffer) {
|
||||
short calleeServiceType = buffer.readShort();
|
||||
String calleeApplicationName = buffer.readPrefixedString();
|
||||
return createApplication(calleeApplicationName, calleeServiceType);
|
||||
return applicationFactory.createApplication(calleeApplicationName, calleeServiceType);
|
||||
}
|
||||
|
||||
private Application readCallerApplication(Buffer row) {
|
||||
String callerApplicationName = row.read2PrefixedString();
|
||||
short callerServiceType = row.readShort();
|
||||
return createApplication(callerApplicationName, callerServiceType);
|
||||
return this.applicationFactory.createApplication(callerApplicationName, callerServiceType);
|
||||
}
|
||||
|
||||
private Application createApplication(String applicationName, short serviceTypeCode) {
|
||||
ServiceType serviceType = registry.findServiceType(serviceTypeCode);
|
||||
return new Application(applicationName, serviceType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.web.service;
|
||||
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.web.vo.Application;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
public interface ApplicationFactory {
|
||||
|
||||
Application createApplication(String applicationName, short serviceTypeCode);
|
||||
|
||||
Application createApplication(String applicationName, ServiceType serviceType);
|
||||
|
||||
Application createApplicationByTypeName(String applicationName, String serviceTypeName);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2014 NAVER Corp.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.navercorp.pinpoint.web.service;
|
||||
|
||||
import com.navercorp.pinpoint.common.service.ServiceTypeRegistryService;
|
||||
import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.web.vo.Application;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author emeroad
|
||||
*/
|
||||
@Component
|
||||
public class DefaultApplicationFactory implements ApplicationFactory {
|
||||
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
|
||||
@Override
|
||||
public Application createApplication(String applicationName, short serviceTypeCode) {
|
||||
if (applicationName == null) {
|
||||
throw new NullPointerException("applicationName must not be null");
|
||||
}
|
||||
|
||||
final ServiceType serviceType = registry.findServiceType(serviceTypeCode);
|
||||
return new Application(applicationName, serviceType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Application createApplication(String applicationName, ServiceType serviceType) {
|
||||
return new Application(applicationName, serviceType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Application createApplicationByTypeName(String applicationName, String serviceTypeName) {
|
||||
if (applicationName == null) {
|
||||
throw new NullPointerException("applicationName must not be null");
|
||||
}
|
||||
if (serviceTypeName == null) {
|
||||
throw new NullPointerException("serviceTypeName must not be null");
|
||||
}
|
||||
|
||||
final ServiceType serviceType = registry.findServiceTypeByName(serviceTypeName);
|
||||
return new Application(applicationName, serviceType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,20 +38,20 @@ public class DotExtractor {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final Range range;
|
||||
private final ServiceTypeRegistryService registry;
|
||||
private final ApplicationFactory applicationFactory;
|
||||
|
||||
private Map<Application, List<Dot>> dotMap = new HashMap<Application, List<Dot>>();
|
||||
|
||||
|
||||
public DotExtractor(Range range, ServiceTypeRegistryService registry) {
|
||||
public DotExtractor(Range range, ApplicationFactory applicationFactory) {
|
||||
if (range == null) {
|
||||
throw new NullPointerException("range must not be null");
|
||||
}
|
||||
if (registry == null) {
|
||||
throw new NullPointerException("registry must not be null");
|
||||
if (applicationFactory == null) {
|
||||
throw new NullPointerException("applicationFactory must not be null");
|
||||
}
|
||||
this.range = range;
|
||||
this.registry = registry;
|
||||
this.applicationFactory = applicationFactory;
|
||||
}
|
||||
|
||||
public void addDot(SpanBo span) {
|
||||
@@ -59,7 +59,7 @@ public class DotExtractor {
|
||||
throw new NullPointerException("span must not be null");
|
||||
}
|
||||
|
||||
Application spanApplication = new Application(span.getApplicationId(), registry.findServiceType(span.getApplicationServiceType()));
|
||||
Application spanApplication = this.applicationFactory.createApplication(span.getApplicationId(), span.getApplicationServiceType());
|
||||
final List<Dot> dotList = getDotList(spanApplication);
|
||||
|
||||
final TransactionId transactionId = new TransactionId(span.getTraceAgentId(), span.getTraceAgentStartTime(), span.getTraceTransactionSequence());
|
||||
@@ -87,18 +87,4 @@ public class DotExtractor {
|
||||
}
|
||||
return applicationScatterScanResult;
|
||||
}
|
||||
|
||||
public static class Key {
|
||||
private String applicationId;
|
||||
private short serviceType;
|
||||
|
||||
public Key(String applicationId, short serviceType) {
|
||||
if (applicationId == null) {
|
||||
throw new NullPointerException("applicationId must not be null");
|
||||
}
|
||||
this.applicationId = applicationId;
|
||||
this.serviceType = serviceType;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ public class FilteredMapServiceImpl implements FilteredMapService {
|
||||
@Autowired
|
||||
private ServiceTypeRegistryService registry;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
private static final Object V = new Object();
|
||||
|
||||
@Override
|
||||
@@ -234,7 +237,7 @@ public class FilteredMapServiceImpl implements FilteredMapService {
|
||||
|
||||
final LinkDataDuplexMap linkDataDuplexMap = new LinkDataDuplexMap();
|
||||
|
||||
final DotExtractor dotExtractor = new DotExtractor(scanRange, registry);
|
||||
final DotExtractor dotExtractor = new DotExtractor(scanRange, applicationFactory);
|
||||
final ResponseHistogramBuilder mapHistogramSummary = new ResponseHistogramBuilder(range);
|
||||
/**
|
||||
* Convert to statistical data
|
||||
@@ -244,7 +247,7 @@ public class FilteredMapServiceImpl implements FilteredMapService {
|
||||
|
||||
for (SpanBo span : transaction) {
|
||||
final Application parentApplication = createParentApplication(span, transactionSpanMap);
|
||||
final Application spanApplication = new Application(span.getApplicationId(), registry.findServiceType(span.getApplicationServiceType()));
|
||||
final Application spanApplication = this.applicationFactory.createApplication(span.getApplicationId(), span.getApplicationServiceType());
|
||||
|
||||
// records the Span's response time statistics
|
||||
recordSpanResponseTime(spanApplication, span, mapHistogramSummary, span.getCollectorAcceptTime());
|
||||
@@ -323,7 +326,7 @@ public class FilteredMapServiceImpl implements FilteredMapService {
|
||||
if (CollectionUtils.isEmpty(spanEventBoList)) {
|
||||
return;
|
||||
}
|
||||
final Application srcApplication = new Application(span.getApplicationId(), registry.findServiceType(span.getApplicationServiceType()));
|
||||
final Application srcApplication = applicationFactory.createApplication(span.getApplicationId(), span.getApplicationServiceType());
|
||||
|
||||
LinkDataMap sourceLinkDataMap = linkDataDuplexMap.getSourceLinkDataMap();
|
||||
for (SpanEventBo spanEvent : spanEventBoList) {
|
||||
@@ -343,11 +346,11 @@ public class FilteredMapServiceImpl implements FilteredMapService {
|
||||
}
|
||||
|
||||
String dest = spanEvent.getDestinationId();
|
||||
if(dest == null) {
|
||||
if (dest == null) {
|
||||
dest = "Unknown";
|
||||
}
|
||||
|
||||
final Application destApplication = new Application(dest, destServiceType);
|
||||
final Application destApplication = this.applicationFactory.createApplication(dest, destServiceType);
|
||||
|
||||
final short slotTime = getHistogramSlotTime(spanEvent, destServiceType);
|
||||
|
||||
@@ -367,12 +370,11 @@ public class FilteredMapServiceImpl implements FilteredMapService {
|
||||
if (span.isRoot() || parentSpan == null) {
|
||||
String applicationName = span.getApplicationId();
|
||||
ServiceType serviceType = ServiceType.USER;
|
||||
return new Application(applicationName, serviceType);
|
||||
return this.applicationFactory.createApplication(applicationName, serviceType);
|
||||
} else {
|
||||
String parentApplicationName = parentSpan.getApplicationId();
|
||||
|
||||
ServiceType serviceType = registry.findServiceType(parentSpan.getApplicationServiceType());
|
||||
return new Application(parentApplicationName, serviceType);
|
||||
short parentServiceType = parentSpan.getApplicationServiceType();
|
||||
return this.applicationFactory.createApplication(parentApplicationName, parentServiceType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ public class MapServiceImpl implements MapService {
|
||||
@Autowired
|
||||
private HostApplicationMapDao hostApplicationMapDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationFactory applicationFactory;
|
||||
|
||||
@Autowired(required=false)
|
||||
private MatcherGroup matcherGroup;
|
||||
|
||||
@@ -116,7 +119,7 @@ public class MapServiceImpl implements MapService {
|
||||
for (TimeHistogram timeHistogram : histogram.getTimeHistogram()) {
|
||||
Application toApplication = linkData.getToApplication();
|
||||
if (toApplication.getServiceType().isRpcClient()) {
|
||||
toApplication = new Application(toApplication.getName(), ServiceType.UNKNOWN);
|
||||
toApplication = this.applicationFactory.createApplication(toApplication.getName(), ServiceType.UNKNOWN);
|
||||
}
|
||||
responseHistogramSummary.addLinkHistogram(toApplication, histogram.getId(), timeHistogram);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user