use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by pinpoint-apm.
the class AgentServiceImpl method openStream.
@Override
public ClientStreamChannel openStream(AgentInfo agentInfo, byte[] payload, ClientStreamChannelEventHandler streamChannelEventHandler) throws TException, StreamException {
assertClusterEnabled();
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
if (CollectionUtils.nullSafeSize(socketList) == 1) {
PinpointSocket socket = socketList.get(0);
return socket.openStream(serializeRequest(transferObject), streamChannelEventHandler);
} else if (CollectionUtils.isEmpty(socketList)) {
throw new StreamException(StreamCode.CONNECTION_NOT_FOUND);
} else {
throw new StreamException(StreamCode.CONNECTION_DUPLICATED);
}
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by pinpoint-apm.
the class AgentServiceImpl method invoke.
@Override
public PinpointRouteResponse invoke(AgentInfo agentInfo, byte[] payload, long timeout) throws TException {
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
Future<ResponseMessage> future = null;
if (CollectionUtils.nullSafeSize(socketList) == 1) {
PinpointSocket socket = socketList.get(0);
future = socket.request(serializeRequest(transferObject));
}
PinpointRouteResponse response = getResponse(future, timeout);
return response;
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by pinpoint-apm.
the class AgentServiceImpl method invoke.
@Override
public Map<AgentInfo, PinpointRouteResponse> invoke(List<AgentInfo> agentInfoList, byte[] payload, long timeout) throws TException {
Map<AgentInfo, Future<ResponseMessage>> futureMap = new HashMap<>();
for (AgentInfo agentInfo : agentInfoList) {
TCommandTransfer transferObject = createCommandTransferObject(agentInfo, payload);
List<PinpointSocket> socketList = clusterManager.getSocket(agentInfo);
if (CollectionUtils.nullSafeSize(socketList) == 1) {
PinpointSocket socket = socketList.get(0);
Future<ResponseMessage> future = socket.request(serializeRequest(transferObject));
futureMap.put(agentInfo, future);
} else {
futureMap.put(agentInfo, null);
}
}
long startTime = System.currentTimeMillis();
Map<AgentInfo, PinpointRouteResponse> result = new HashMap<>();
for (Map.Entry<AgentInfo, Future<ResponseMessage>> futureEntry : futureMap.entrySet()) {
AgentInfo agentInfo = futureEntry.getKey();
Future<ResponseMessage> future = futureEntry.getValue();
PinpointRouteResponse response = getResponse(future, getTimeoutMillis(startTime, timeout));
result.put(agentInfo, response);
}
return result;
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.
the class ClusterPointRouter method handleStreamRouteCreate.
private StreamCode handleStreamRouteCreate(TCommandTransfer request, StreamCreatePacket packet, ServerStreamChannelContext streamChannelContext) {
byte[] payload = ((TCommandTransfer) request).getPayload();
TBase<?, ?> command = deserialize(payload);
if (command == null) {
return StreamCode.TYPE_UNKNOWN;
}
TCommandTransferResponse response = streamRouteHandler.onRoute(new StreamEvent((TCommandTransfer) request, streamChannelContext, command));
TRouteResult routeResult = response.getRouteResult();
if (routeResult != TRouteResult.OK) {
logger.warn("handleStreamRouteCreate failed. command:{}, routeResult:{}", command, routeResult);
return convertToStreamCode(routeResult);
}
return StreamCode.OK;
}
use of com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer in project pinpoint by naver.
the class AgentEventHandlerTest method handler_should_handle_serialization_of_request_events.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_handle_serialization_of_request_events() throws Exception {
// given
final AgentEventType expectedEventType = AgentEventType.USER_THREAD_DUMP;
final TCommandThreadDumpResponse expectedThreadDumpResponse = new TCommandThreadDumpResponse();
final byte[] expectedThreadDumpResponseBody = new byte[0];
final TCommandTransfer tCommandTransfer = new TCommandTransfer();
tCommandTransfer.setAgentId(TEST_AGENT_ID);
tCommandTransfer.setStartTime(TEST_START_TIMESTAMP);
final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse();
tCommandTransferResponse.setRouteResult(TRouteResult.OK);
tCommandTransferResponse.setPayload(expectedThreadDumpResponseBody);
final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse);
ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
HeaderTBaseDeserializer deserializer = mock(HeaderTBaseDeserializer.class);
when(this.deserializerFactory.createDeserializer()).thenReturn(deserializer);
when(deserializer.deserialize(expectedThreadDumpResponseBody)).thenReturn((TBase) expectedThreadDumpResponse);
// when
this.agentEventHandler.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
// then
verify(this.agentEventDao, atLeast(1)).insert(argCaptor.capture());
AgentEventBo actualAgentEventBo = argCaptor.getValue();
assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
assertEquals(expectedEventType, actualAgentEventBo.getEventType());
assertArrayEquals(expectedThreadDumpResponseBody, actualAgentEventBo.getEventBody());
}
Aggregations