Search in sources :

Example 1 with TargetClusterPoint

use of com.navercorp.pinpoint.collector.cluster.TargetClusterPoint in project pinpoint by naver.

the class ClusterManager method getConnectedAgentList.

@Override
public List<String> getConnectedAgentList() {
    List<String> result = new ArrayList<>();
    List clusterPointList = clusterPointLocator.getClusterPointList();
    for (Object clusterPoint : clusterPointList) {
        if (clusterPoint instanceof TargetClusterPoint) {
            TargetClusterPoint agentClusterPoint = (TargetClusterPoint) clusterPoint;
            result.add(createAgentKey(agentClusterPoint));
        }
    }
    return result;
}
Also used : TargetClusterPoint(com.navercorp.pinpoint.collector.cluster.TargetClusterPoint) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with TargetClusterPoint

use of com.navercorp.pinpoint.collector.cluster.TargetClusterPoint in project pinpoint by naver.

the class DefaultRouteHandler method onRoute0.

private TCommandTransferResponse onRoute0(RequestEvent event) {
    TBase<?, ?> requestObject = event.getRequestObject();
    if (requestObject == null) {
        return createResponse(TRouteResult.EMPTY_REQUEST);
    }
    TargetClusterPoint clusterPoint = findClusterPoint(event.getDeliveryCommand());
    if (clusterPoint == null) {
        return createResponse(TRouteResult.NOT_FOUND);
    }
    if (!clusterPoint.isSupportCommand(requestObject)) {
        return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
    }
    Future<ResponseMessage> future = clusterPoint.request(event.getDeliveryCommand().getPayload());
    boolean isCompleted = future.await();
    if (!isCompleted) {
        return createResponse(TRouteResult.TIMEOUT);
    }
    ResponseMessage responseMessage = future.getResult();
    if (responseMessage == null) {
        return createResponse(TRouteResult.EMPTY_RESPONSE);
    }
    byte[] responsePayload = responseMessage.getMessage();
    if (responsePayload == null || responsePayload.length == 0) {
        return createResponse(TRouteResult.EMPTY_RESPONSE, new byte[0]);
    }
    return createResponse(TRouteResult.OK, responsePayload);
}
Also used : TargetClusterPoint(com.navercorp.pinpoint.collector.cluster.TargetClusterPoint) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage)

Example 3 with TargetClusterPoint

use of com.navercorp.pinpoint.collector.cluster.TargetClusterPoint in project pinpoint by naver.

the class StreamRouteHandler method onRoute0.

private TCommandTransferResponse onRoute0(StreamEvent event) {
    TBase<?, ?> requestObject = event.getRequestObject();
    if (requestObject == null) {
        return createResponse(TRouteResult.EMPTY_REQUEST);
    }
    TargetClusterPoint clusterPoint = findClusterPoint(event.getDeliveryCommand());
    if (clusterPoint == null) {
        return createResponse(TRouteResult.NOT_FOUND);
    }
    if (!clusterPoint.isSupportCommand(requestObject)) {
        return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
    }
    try {
        if (clusterPoint instanceof PinpointServerClusterPoint) {
            StreamRouteManager routeManager = new StreamRouteManager(event);
            ServerStreamChannelContext consumerContext = event.getStreamChannelContext();
            consumerContext.setAttributeIfAbsent(ATTACHMENT_KEY, routeManager);
            ClientStreamChannelContext producerContext = createStreamChannel((PinpointServerClusterPoint) clusterPoint, event.getDeliveryCommand().getPayload(), routeManager);
            if (producerContext.getCreateFailPacket() == null) {
                routeManager.setProducer(producerContext.getStreamChannel());
                producerContext.getStreamChannel().addStateChangeEventHandler(routeManager);
                return createResponse(TRouteResult.OK);
            }
        } else {
            return createResponse(TRouteResult.NOT_SUPPORTED_SERVICE);
        }
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Create StreamChannel({}) failed. Error:{}", clusterPoint, e.getMessage(), e);
        }
    }
    return createResponse(TRouteResult.UNKNOWN);
}
Also used : TargetClusterPoint(com.navercorp.pinpoint.collector.cluster.TargetClusterPoint) ClientStreamChannelContext(com.navercorp.pinpoint.rpc.stream.ClientStreamChannelContext) ServerStreamChannelContext(com.navercorp.pinpoint.rpc.stream.ServerStreamChannelContext) PinpointServerClusterPoint(com.navercorp.pinpoint.collector.cluster.PinpointServerClusterPoint)

Example 4 with TargetClusterPoint

use of com.navercorp.pinpoint.collector.cluster.TargetClusterPoint in project pinpoint by naver.

the class AbstractRouteHandler method findClusterPoint.

protected TargetClusterPoint findClusterPoint(TCommandTransfer deliveryCommand) {
    String applicationName = deliveryCommand.getApplicationName();
    String agentId = deliveryCommand.getAgentId();
    long startTimeStamp = deliveryCommand.getStartTime();
    List<TargetClusterPoint> result = new ArrayList<>();
    for (TargetClusterPoint targetClusterPoint : targetClusterPointLocator.getClusterPointList()) {
        if (!targetClusterPoint.getApplicationName().equals(applicationName)) {
            continue;
        }
        if (!targetClusterPoint.getAgentId().equals(agentId)) {
            continue;
        }
        if (!(targetClusterPoint.getStartTimeStamp() == startTimeStamp)) {
            continue;
        }
        result.add(targetClusterPoint);
    }
    if (result.size() == 1) {
        return result.get(0);
    }
    if (result.size() > 1) {
        logger.warn("Ambiguous ClusterPoint {}, {}, {} (Valid Agent list={}).", applicationName, agentId, startTimeStamp, result);
        return null;
    }
    return null;
}
Also used : TargetClusterPoint(com.navercorp.pinpoint.collector.cluster.TargetClusterPoint) ArrayList(java.util.ArrayList)

Aggregations

TargetClusterPoint (com.navercorp.pinpoint.collector.cluster.TargetClusterPoint)4 ArrayList (java.util.ArrayList)2 PinpointServerClusterPoint (com.navercorp.pinpoint.collector.cluster.PinpointServerClusterPoint)1 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)1 ClientStreamChannelContext (com.navercorp.pinpoint.rpc.stream.ClientStreamChannelContext)1 ServerStreamChannelContext (com.navercorp.pinpoint.rpc.stream.ServerStreamChannelContext)1 List (java.util.List)1