forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pinpoint-apm#84 Add web support for handling Agent lifecycle and events
- Loading branch information
Showing
27 changed files
with
1,471 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
web/src/main/java/com/navercorp/pinpoint/web/dao/AgentEventDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2015 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.dao; | ||
|
||
import java.util.List; | ||
|
||
import com.navercorp.pinpoint.common.bo.AgentEventBo; | ||
import com.navercorp.pinpoint.common.util.AgentEventType; | ||
import com.navercorp.pinpoint.web.vo.Range; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public interface AgentEventDao { | ||
|
||
public AgentEventBo getAgentEvent(String agentId, long eventTimestamp, AgentEventType eventType); | ||
|
||
public List<AgentEventBo> getAgentEvents(String agentId, Range range); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
web/src/main/java/com/navercorp/pinpoint/web/dao/AgentLifeCycleDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2015 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.dao; | ||
|
||
import com.navercorp.pinpoint.common.bo.AgentLifeCycleBo; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public interface AgentLifeCycleDao { | ||
|
||
AgentLifeCycleBo getAgentLifeCycle(String agentId, long timestamp); | ||
|
||
} |
129 changes: 129 additions & 0 deletions
129
web/src/main/java/com/navercorp/pinpoint/web/dao/hbase/HbaseAgentEventDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright 2015 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.dao.hbase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.hadoop.hbase.client.Result; | ||
import org.apache.hadoop.hbase.client.ResultScanner; | ||
import org.apache.hadoop.hbase.client.Scan; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.data.hadoop.hbase.ResultsExtractor; | ||
import org.springframework.data.hadoop.hbase.RowMapper; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.navercorp.pinpoint.common.bo.AgentEventBo; | ||
import com.navercorp.pinpoint.common.hbase.HBaseTables; | ||
import com.navercorp.pinpoint.common.hbase.HbaseOperations2; | ||
import com.navercorp.pinpoint.common.util.AgentEventType; | ||
import com.navercorp.pinpoint.common.util.BytesUtils; | ||
import com.navercorp.pinpoint.common.util.RowKeyUtils; | ||
import com.navercorp.pinpoint.common.util.TimeUtils; | ||
import com.navercorp.pinpoint.web.dao.AgentEventDao; | ||
import com.navercorp.pinpoint.web.vo.Range; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
@Repository | ||
public class HbaseAgentEventDao implements AgentEventDao { | ||
|
||
private static final int SCANNER_CACHE_SIZE = 20; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Autowired | ||
private HbaseOperations2 hbaseOperations2; | ||
|
||
@Autowired | ||
@Qualifier("agentEventMapper") | ||
private RowMapper<List<AgentEventBo>> agentEventMapper; | ||
|
||
@Override | ||
public List<AgentEventBo> getAgentEvents(String agentId, Range range) { | ||
if (agentId == null) { | ||
throw new NullPointerException("agentId must not be null"); | ||
} | ||
if (range == null) { | ||
throw new NullPointerException("range must not be null"); | ||
} | ||
|
||
Scan scan = new Scan(); | ||
scan.setMaxVersions(1); | ||
scan.setCaching(SCANNER_CACHE_SIZE); | ||
|
||
scan.setStartRow(createRowKey(agentId, range.getTo())); | ||
scan.setStopRow(createRowKey(agentId, range.getFrom())); | ||
scan.addFamily(HBaseTables.AGENT_EVENT_CF_EVENTS); | ||
|
||
List<AgentEventBo> agentEvents = this.hbaseOperations2.find(HBaseTables.AGENT_EVENT, scan, | ||
new AgentEventResultsExtractor()); | ||
logger.debug("agentEvents found. {}", agentEvents); | ||
return agentEvents; | ||
} | ||
|
||
@Override | ||
public AgentEventBo getAgentEvent(String agentId, long eventTimestamp, AgentEventType eventType) { | ||
if (agentId == null) { | ||
throw new NullPointerException("agentId must not be null"); | ||
} | ||
if (eventTimestamp < 0) { | ||
throw new IllegalArgumentException("eventTimestamp must not be less than 0"); | ||
} | ||
if (eventType == null) { | ||
throw new NullPointerException("eventType must not be null"); | ||
} | ||
|
||
final byte[] rowKey = createRowKey(agentId, eventTimestamp); | ||
byte[] qualifier = Bytes.toBytes(eventType.getCode()); | ||
List<AgentEventBo> events = this.hbaseOperations2.get(HBaseTables.AGENT_EVENT, rowKey, | ||
HBaseTables.AGENT_EVENT_CF_EVENTS, qualifier, this.agentEventMapper); | ||
if (events == null || events.isEmpty()) { | ||
return null; | ||
} | ||
return events.get(0); | ||
} | ||
|
||
private byte[] createRowKey(String agentId, long timestamp) { | ||
byte[] agentIdKey = BytesUtils.toBytes(agentId); | ||
long reverseTimestamp = TimeUtils.reverseTimeMillis(timestamp); | ||
return RowKeyUtils.concatFixedByteAndLong(agentIdKey, HBaseTables.AGENT_NAME_MAX_LEN, reverseTimestamp); | ||
} | ||
|
||
private class AgentEventResultsExtractor implements ResultsExtractor<List<AgentEventBo>> { | ||
|
||
@Override | ||
public List<AgentEventBo> extractData(ResultScanner results) throws Exception { | ||
List<AgentEventBo> agentEvents = new ArrayList<AgentEventBo>(); | ||
int rowNum = 0; | ||
for (Result result : results) { | ||
List<AgentEventBo> intermediateEvents = agentEventMapper.mapRow(result, rowNum++); | ||
if (!intermediateEvents.isEmpty()) { | ||
agentEvents.addAll(intermediateEvents); | ||
} | ||
} | ||
return agentEvents; | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.