Search in sources :

Example 31 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ZkWithIpCacheSupport method renew.

/**
 * 注意这里,不完全保证一定能拿到最新的
 */
private void renew(Supplier supplier, String connectionLocalIp) {
    try {
        if (lock.acquire(10, TimeUnit.MILLISECONDS)) {
            try {
                List<ConsumerApiResult> newList = supplier.get();
                if (newList == null) {
                    throw new PradarException("supplier invoke but not data return!");
                }
                CACHE = group(newList);
                putInZK(newList);
            } finally {
                lock.release();
            }
        } else {
            // 如果没获取到锁,锁一定是被其它节点获取,这里等到能获取到锁的时候,一定是zk上的数据已经更新了
            lock.acquire();
            try {
                List<ConsumerApiResult> newList = getFromZK(connectionLocalIp);
                if (newList == null) {
                    throw new PradarException("get lock but zk not update! this should never happened!");
                }
                CACHE = group(newList);
            } finally {
                lock.release();
            }
        }
    } catch (Exception e) {
        throw new PradarException(e);
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) ConsumerApiResult(com.pamirs.attach.plugin.rabbitmq.consumer.admin.support.ConsumerApiResult) ZipException(java.util.zip.ZipException) KeeperException(org.apache.zookeeper.KeeperException) PradarException(com.pamirs.pradar.exception.PradarException)

Example 32 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class SendMessageHookImpl method sendMessageBefore.

@Override
public void sendMessageBefore(SendMessageContext context) {
    try {
        if (context == null || context.getMessage() == null) {
            return;
        }
        Message message = context.getMessage();
        if (message == null) {
            return;
        }
        ClusterTestUtils.validateClusterTest();
        MQTraceBean traceBean = new MQTraceBean();
        traceBean.setTopic(message.getTopic());
        traceBean.setOriginMsgId(MessageAccessor.getOriginMessageId(message));
        traceBean.setTags(message.getTags());
        traceBean.setKeys(message.getKeys());
        traceBean.setBuyerId(message.getBuyerId());
        traceBean.setTransferFlag(MessageAccessor.getTransferFlag(message));
        traceBean.setCorrectionFlag(MessageAccessor.getCorrectionFlag(message));
        traceBean.setBodyLength(message.getBody().length);
        traceBean.setBornHost(context.getBornHost());
        String brokerAddr = context.getBrokerAddr();
        int port = -1;
        int indexOfColon = -1;
        if (brokerAddr != null && (indexOfColon = brokerAddr.indexOf(':')) != -1) {
            try {
                port = Integer.parseInt(brokerAddr.substring(indexOfColon + 1));
            } catch (NumberFormatException e) {
            }
            brokerAddr = brokerAddr.substring(0, indexOfColon);
        }
        final List<String> nameServerAddressList = context.getProducer().getmQClientFactory().getMQClientAPIImpl().getNameServerAddressList();
        Collections.sort(nameServerAddressList);
        traceBean.setStoreHost(StringUtils.join(nameServerAddressList, ","));
        traceBean.setBrokerName(context.getMq().getBrokerName());
        // 上游AppName,记录当前应用的AppName
        traceBean.setProps(context.getProps());
        ArrayList<MQTraceBean> traceBeans = new ArrayList<MQTraceBean>(1);
        traceBeans.add(traceBean);
        MQTraceContext mqTraceContext = new MQTraceContext();
        context.setMqTraceContext(mqTraceContext);
        mqTraceContext.setMqType(MQType.ROCKETMQ);
        mqTraceContext.setGroup(context.getProducerGroup());
        mqTraceContext.setAsync(CommunicationMode.ASYNC == context.getCommunicationMode());
        mqTraceContext.setTraceBeans(traceBeans);
        Map<String, String> rpcContext = new HashMap<String, String>();
        for (String key : Pradar.getInvokeContextTransformKeys()) {
            String value = message.getProperty(key);
            if (value != null) {
                rpcContext.put(key, value);
            }
        }
        traceBean.setContext(rpcContext);
        traceBean.setClusterTest(message.getUserProperty(PradarService.PRADAR_CLUSTER_TEST_KEY));
        MQSendMessageTraceLog.sendMessageBefore(mqTraceContext);
        for (Map.Entry<String, String> entry : traceBean.getContext().entrySet()) {
            putUserProperty(message, entry.getKey(), entry.getValue());
        }
        putUserProperty(message, RocketmqConstants.NAME_SERVER_ADDRESS, traceBean.getStoreHost());
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : Message(org.apache.rocketmq.common.message.Message) PradarException(com.pamirs.pradar.exception.PradarException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MQTraceBean(com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceBean) MQTraceContext(com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceContext) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class OrderlyTraceBeforeInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeMessageContext consumeMessageContext = OrderlyTraceContexts.get();
        if (consumeMessageContext == null) {
            return;
        }
        List<MessageExt> messageExts = (List<MessageExt>) advice.getReturnObj();
        if (messageExts == null || messageExts.isEmpty()) {
            return;
        }
        consumeMessageContext.setMsgList(messageExts);
        PushConsumeMessageHookImpl.getInstance().consumeMessageBefore(consumeMessageContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : ConsumeMessageContext(org.apache.rocketmq.client.hook.ConsumeMessageContext) MessageExt(org.apache.rocketmq.common.message.MessageExt) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) List(java.util.List)

Example 34 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class OrderlyTraceBeforeInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeMessageContext consumeMessageContext = OrderlyTraceContexts.get();
        if (consumeMessageContext == null) {
            return;
        }
        List<MessageExt> messageExts = (List<MessageExt>) advice.getReturnObj();
        if (messageExts == null || messageExts.isEmpty()) {
            return;
        }
        consumeMessageContext.setMsgList(messageExts);
        PushConsumeMessageHookImpl.getInstance().consumeMessageBefore(consumeMessageContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    }
}
Also used : ConsumeMessageContext(com.alibaba.rocketmq.client.hook.ConsumeMessageContext) MessageExt(com.alibaba.rocketmq.common.message.MessageExt) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError) List(java.util.List)

Example 35 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class OrderlyTraceContextInterceptor method doAfter.

@Override
public void doAfter(Advice advice) throws Throwable {
    try {
        ConsumeMessageContext consumeMessageContext = OrderlyTraceContexts.get();
        if (consumeMessageContext == null || consumeMessageContext.getMsgList() == null) {
            return;
        }
        consumeMessageContext.setSuccess(true);
        consumeMessageContext.setStatus("SUCCESS");
        // 兜底,以免after没有执行(consumeMessageContext.getMsgList() != null 说明before 已经执行了)
        PushConsumeMessageHookImpl.getInstance().consumeMessageAfter(consumeMessageContext);
    } catch (PradarException e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (PressureMeasureError e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw e;
        }
    } catch (Throwable e) {
        LOGGER.error("", e);
        if (Pradar.isClusterTest()) {
            throw new PressureMeasureError(e);
        }
    } finally {
        OrderlyTraceContexts.remove();
    }
}
Also used : ConsumeMessageContext(com.alibaba.rocketmq.client.hook.ConsumeMessageContext) PradarException(com.pamirs.pradar.exception.PradarException) PressureMeasureError(com.pamirs.pradar.exception.PressureMeasureError)

Aggregations

PradarException (com.pamirs.pradar.exception.PradarException)46 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)34 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)6 MQTraceContext (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext)6 ZipException (java.util.zip.ZipException)6 ConsumeMessageContext (org.apache.rocketmq.client.hook.ConsumeMessageContext)6 KeeperException (org.apache.zookeeper.KeeperException)6 MQTraceContext (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceContext)5 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)4 MQTraceBean (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceBean)4 MQTraceBean (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceBean)4 InetSocketAddress (java.net.InetSocketAddress)4 MessageExt (org.apache.rocketmq.common.message.MessageExt)4 MQTraceContext (com.pamirs.attach.plugin.pulsar.common.MQTraceContext)3 ConcurrentWeakHashMap (com.shulie.instrument.simulator.message.ConcurrentWeakHashMap)3 List (java.util.List)3 Map (java.util.Map)3 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)3