[강운덕] [WEB-122] ReverseRange 로직 공통화.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@3706 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2014-04-21 08:01:55 +00:00
parent baefee3210
commit 414c8edf52
6 changed files with 58 additions and 42 deletions
@@ -1,10 +1,9 @@
package com.nhn.pinpoint.web.dao.hbase;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import com.nhn.pinpoint.web.vo.Range;
import com.nhn.pinpoint.web.vo.RangeFactory;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
@@ -18,8 +17,6 @@ import com.nhn.pinpoint.web.dao.HostApplicationMapDao;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.common.hbase.HBaseTables;
import com.nhn.pinpoint.common.hbase.HbaseOperations2;
import com.nhn.pinpoint.common.util.TimeSlot;
import com.nhn.pinpoint.common.util.TimeUtils;
/**
*
@@ -40,6 +37,9 @@ public class HbaseHostApplicationMapDao implements HostApplicationMapDao {
@Qualifier("hostApplicationMapper")
private RowMapper<Application> hostApplicationMapper;
@Autowired
private RangeFactory rangeFactory;
@Override
public Application findApplicationName(String host, Range range) {
if (host == null) {
@@ -55,17 +55,15 @@ public class HbaseHostApplicationMapDao implements HostApplicationMapDao {
}
private Scan createScan(String host, Range range) {
long startTime = TimeUtils.reverseTimeMillis(TimeSlot.getStatisticsRowSlot(range.getFrom()));
long endTime = TimeUtils.reverseTimeMillis(TimeSlot.getStatisticsRowSlot(range.getTo()) + 1);
range = rangeFactory.createReverseStatisticsRange(range);
if (logger.isDebugEnabled()) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss,SSS");
logger.debug("scan startTime:{} endTime:{}", simpleDateFormat.format(new Date(startTime)), simpleDateFormat.format(new Date(endTime)));
logger.debug("scan time:{}", range.prettyToString());
}
// timestamp가 reverse되었기 때문에 start, end를 바꿔서 조회.
byte[] startKey = Bytes.toBytes(endTime);
byte[] endKey = Bytes.toBytes(startTime);
byte[] startKey = Bytes.toBytes(range.getFrom());
byte[] endKey = Bytes.toBytes(range.getTo());
Scan scan = new Scan();
scan.setCaching(this.scanCacheSize);
@@ -3,10 +3,10 @@ package com.nhn.pinpoint.web.dao.hbase;
import com.nhn.pinpoint.common.hbase.HBaseTables;
import com.nhn.pinpoint.common.hbase.HbaseOperations2;
import com.nhn.pinpoint.common.util.ApplicationMapStatisticsUtils;
import com.nhn.pinpoint.common.util.TimeSlot;
import com.nhn.pinpoint.web.dao.MapResponseDao;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.web.vo.Range;
import com.nhn.pinpoint.web.vo.RangeFactory;
import com.nhn.pinpoint.web.vo.ResponseTime;
import org.apache.hadoop.hbase.client.Scan;
@@ -16,8 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.hadoop.hbase.RowMapper;
import org.springframework.stereotype.Repository;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@@ -39,6 +37,9 @@ public class HbaseMapResponseTimeDao implements MapResponseDao {
@Autowired
private HbaseOperations2 hbaseOperations2;
@Autowired
private RangeFactory rangeFactory;
@Override
public List<ResponseTime> selectResponseTime(Application application, Range range) {
@@ -61,20 +62,17 @@ public class HbaseMapResponseTimeDao implements MapResponseDao {
}
private Scan createScan(Application application, Range range) {
long startTime = TimeSlot.getStatisticsRowSlot(range.getFrom()) - 1;
// hbase의 scanner를 사용하여 검색시 endTime은 검색 대상에 포함되지 않기 때문에, +1을 해줘야 된다.
// 단 key가 역으로 치환되어 있으므로 startTime에 -1을 해야함.
long endTime = TimeSlot.getStatisticsRowSlot(range.getTo());
range = rangeFactory.createReverseStatisticsRange(range);
if (logger.isDebugEnabled()) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss,SSS");
logger.debug("scan startTime:{} endTime:{}", simpleDateFormat.format(new Date(startTime)), simpleDateFormat.format(new Date(endTime)));
logger.debug("scan time:{} ", range.prettyToString());
}
// timestamp가 reverse되었기 때문에 start, end를 바꿔서 조회.
byte[] startKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), endTime);
byte[] endKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), startTime);
byte[] startKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), range.getFrom());
byte[] endKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), range.getTo());
final Scan scan = new Scan();
scan.setCaching(this.scanCacheSize);
@@ -1,7 +1,5 @@
package com.nhn.pinpoint.web.dao.hbase;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.*;
@@ -10,6 +8,7 @@ import com.nhn.pinpoint.web.dao.MapStatisticsCalleeDao;
import com.nhn.pinpoint.web.mapper.*;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.web.vo.Range;
import com.nhn.pinpoint.web.vo.RangeFactory;
import org.apache.hadoop.hbase.client.Scan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -21,7 +20,6 @@ import org.springframework.stereotype.Repository;
import com.nhn.pinpoint.common.hbase.HBaseTables;
import com.nhn.pinpoint.common.hbase.HbaseOperations2;
import com.nhn.pinpoint.common.util.ApplicationMapStatisticsUtils;
import com.nhn.pinpoint.common.util.TimeSlot;
/**
*
@@ -42,6 +40,9 @@ public class HbaseMapStatisticsCalleeDao implements MapStatisticsCalleeDao {
@Qualifier("mapStatisticsCalleeMapper")
private RowMapper<LinkDataMap> mapStatisticsCalleeMapper;
@Autowired
private RangeFactory rangeFactory;
@Override
public LinkDataMap selectCallee(Application calleeApplication, Range range) {
if (calleeApplication == null) {
@@ -100,18 +101,15 @@ public class HbaseMapStatisticsCalleeDao implements MapStatisticsCalleeDao {
}
private Scan createScan(Application application, Range range) {
long startTime = TimeSlot.getStatisticsRowSlot(range.getFrom()) - 1;
// hbase의 scanner를 사용하여 검색시 endTime은 검색 대상에 포함되지 않기 때문에, +1을 해줘야 된다.
long endTime = TimeSlot.getStatisticsRowSlot(range.getTo());
range = rangeFactory.createReverseStatisticsRange(range);
if (logger.isDebugEnabled()) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss,SSS");
logger.debug("scan startTime:{} endTime:{}", simpleDateFormat.format(new Date(startTime)), simpleDateFormat.format(new Date(endTime)));
logger.debug("scan time:{} ", range.prettyToString());
}
// timestamp가 reverse되었기 때문에 start, end를 바꿔서 조회.
byte[] startKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), endTime);
byte[] endKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), startTime);
byte[] startKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), range.getFrom());
byte[] endKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), range.getTo());
Scan scan = new Scan();
scan.setCaching(this.scanCacheSize);
@@ -1,7 +1,5 @@
package com.nhn.pinpoint.web.dao.hbase;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.*;
import com.nhn.pinpoint.web.applicationmap.rawdata.LinkDataMap;
@@ -9,6 +7,7 @@ import com.nhn.pinpoint.web.dao.MapStatisticsCallerDao;
import com.nhn.pinpoint.web.mapper.*;
import com.nhn.pinpoint.web.vo.Application;
import com.nhn.pinpoint.web.vo.Range;
import com.nhn.pinpoint.web.vo.RangeFactory;
import org.apache.hadoop.hbase.client.Scan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,7 +19,6 @@ import org.springframework.stereotype.Repository;
import com.nhn.pinpoint.common.hbase.HBaseTables;
import com.nhn.pinpoint.common.hbase.HbaseOperations2;
import com.nhn.pinpoint.common.util.ApplicationMapStatisticsUtils;
import com.nhn.pinpoint.common.util.TimeSlot;
/**
*
@@ -41,6 +39,9 @@ public class HbaseMapStatisticsCallerDao implements MapStatisticsCallerDao {
@Qualifier("mapStatisticsCallerMapper")
private RowMapper<LinkDataMap> mapStatisticsCallerMapper;
@Autowired
private RangeFactory rangeFactory;
@Override
public LinkDataMap selectCaller(Application callerApplication, Range range) {
Scan scan = createScan(callerApplication, range);
@@ -89,18 +90,15 @@ public class HbaseMapStatisticsCallerDao implements MapStatisticsCallerDao {
}
private Scan createScan(Application application, Range range) {
long startTime = TimeSlot.getStatisticsRowSlot(range.getFrom()) - 1;
// hbase의 scanner를 사용하여 검색시 endTime은 검색 대상에 포함되지 않기 때문에, +1을 해줘야 된다.
long endTime = TimeSlot.getStatisticsRowSlot(range.getTo());
range = rangeFactory.createReverseStatisticsRange(range);
if (logger.isDebugEnabled()) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss,SSS");
logger.debug("scan startTime:{} endTime:{}", simpleDateFormat.format(new Date(startTime)), simpleDateFormat.format(new Date(endTime)));
logger.debug("scan Time:{}", range.prettyToString());
}
// timestamp가 reverse되었기 때문에 start, end를 바꿔서 조회.
byte[] startKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), endTime);
byte[] endKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), startTime);
byte[] startKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), range.getFrom());
byte[] endKey = ApplicationMapStatisticsUtils.makeRowKey(application.getName(), application.getServiceTypeCode(), range.getTo());
Scan scan = new Scan();
scan.setCaching(this.scanCacheSize);
@@ -0,0 +1,22 @@
package com.nhn.pinpoint.web.vo;
import com.nhn.pinpoint.common.util.TimeSlot;
import com.nhn.pinpoint.common.util.TimeUtils;
/**
* @author emeroad
*/
public class RangeFactory {
public Range createReverseStatisticsRange(Range range) {
if (range == null) {
throw new NullPointerException("range must not be null");
}
// hbase의 scanner를 사용하여 검색시 endTime은 검색 대상에 포함되지 않기 때문에, +1을 해줘야 된다.
// 단 key가 역으로 치환되어 있으므로 startTime에 -1을 해야함.
final long startTime = TimeSlot.getStatisticsRowSlot(range.getFrom()) - 1;
final long endTime = TimeSlot.getStatisticsRowSlot(range.getTo());
return Range.createUncheckedRange(endTime, startTime);
}
}
@@ -39,5 +39,7 @@
</bean>
<bean id="jsonObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"></bean>
<bean id="rangeFactory" class="com.nhn.pinpoint.web.vo.RangeFactory"></bean>
</beans>