use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class OrderlyTraceContextInterceptor method doBefore.
@Override
public void doBefore(Advice advice) throws Throwable {
try {
MessageQueue messageQueue = getMessageQueue(advice.getTarget());
String consumeGroup = getConsumeGroup(advice.getTarget());
ConsumeMessageContext consumeMessageContext = new ConsumeMessageContext();
consumeMessageContext.setConsumerGroup(consumeGroup);
consumeMessageContext.setMq(messageQueue);
consumeMessageContext.setSuccess(false);
OrderlyTraceContexts.set(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);
}
}
}
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();
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class PulsarTraceConsumerInterceptor method doBefore.
@Override
public void doBefore(Advice advice) {
Object[] args = advice.getParameterArray();
Object target = advice.getTarget();
try {
if (!(target instanceof org.apache.pulsar.client.impl.ConsumerBase)) {
return;
}
if (args == null || args.length != 1) {
return;
}
Object messageObj = args[0];
if (!(messageObj instanceof Message)) {
return;
}
Message<?> message = (Message<?>) messageObj;
MQTraceContext mqTraceContext = new MQTraceContext();
mqTraceContext.setMqType(MQType.PULSAR);
mqTraceContext.setGroup(message.getProducerName() + ":" + message.getTopicName());
MQTraceBean traceBean = new MQTraceBean();
Map<String, String> properties = message.getProperties();
if (properties != null) {
Map<String, String> rpcContext = new HashMap<String, String>();
for (String key : Pradar.getInvokeContextTransformKeys()) {
String value = ObjectUtils.toString(properties.get(key));
if (value != null) {
rpcContext.put(key, value);
}
}
traceBean.setContext(rpcContext);
}
traceBean.setTopic(message.getTopicName());
traceBean.setKeys(message.getKey());
traceBean.setBodyLength(message.getData().length);
// topic是否PT_开头
boolean isClusterTest = message.getTopicName() != null && (Pradar.isClusterTestPrefix(message.getTopicName()));
// 消息的properties是否包含Pradar.PRADAR_CLUSTER_TEST_KEY
if (properties != null) {
isClusterTest = isClusterTest || StringUtils.equalsIgnoreCase(Boolean.TRUE.toString(), ObjectUtils.toString(properties.get(PradarService.PRADAR_CLUSTER_TEST_KEY)));
}
if (isClusterTest) {
traceBean.setClusterTest(Boolean.TRUE.toString());
}
ArrayList<MQTraceBean> traceBeans = new ArrayList<MQTraceBean>(1);
traceBeans.add(traceBean);
mqTraceContext.setTraceBeans(traceBeans);
MQConsumeMessageTraceLog.consumeMessageBefore(mqTraceContext);
threadLocal.set(mqTraceContext);
} 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);
}
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class ZookeeperRegister method init.
@Override
public void init(RegisterOptions registerOptions) {
if (registerOptions == null) {
throw new NullPointerException("RegisterOptions is null");
}
this.basePath = registerOptions.getRegisterBasePath();
this.appName = registerOptions.getAppName();
this.md5 = registerOptions.getMd5();
this.simulatorConfig = registerOptions.getSimulatorConfig();
if (LOGGER.isInfoEnabled()) {
LOGGER.info("[pradar-register] prepare to init register zookeeper node. {}", Pradar.AGENT_ID_CONTAIN_USER_INFO);
}
String registerBasePath = null;
if (StringUtils.endsWith(basePath, "/")) {
registerBasePath = this.basePath + appName;
} else {
registerBasePath = this.basePath + '/' + appName;
}
try {
ZkClientSpec zkClientSpec = new ZkClientSpec();
zkClientSpec.setZkServers(registerOptions.getZkServers());
zkClientSpec.setConnectionTimeoutMillis(registerOptions.getConnectionTimeoutMillis());
zkClientSpec.setSessionTimeoutMillis(registerOptions.getSessionTimeoutMillis());
zkClientSpec.setThreadName("heartbeat");
this.zkClient = NetflixCuratorZkClientFactory.getInstance().create(zkClientSpec);
} catch (PradarException e) {
LOGGER.error("[pradar-register] ZookeeperRegister init error.", e);
throw e;
} catch (Throwable e) {
LOGGER.error("[pradar-register] ZookeeperRegister init error.", e);
throw new PradarException(e);
}
String client = Pradar.AGENT_ID_CONTAIN_USER_INFO;
try {
this.zkClient.ensureDirectoryExists(registerBasePath);
} catch (Throwable e) {
LOGGER.error("[register] ensureDirectoryExists err:{}", registerBasePath, e);
}
this.heartbeatPath = registerBasePath + '/' + client;
try {
if (this.zkClient.exists(this.heartbeatPath)) {
this.zkClient.deleteQuietly(this.heartbeatPath);
}
} catch (Throwable e) {
}
cleanExpiredNodes(registerBasePath);
this.heartbeatNode = this.zkClient.createHeartbeatNode(this.heartbeatPath);
PradarSwitcher.registerListener(new PradarSwitcher.PradarSwitcherListener() {
@Override
public void onListen(Event event) {
if (event instanceof PradarSwitchEvent || event instanceof ErrorEvent) {
refresh();
}
}
});
if (LOGGER.isInfoEnabled()) {
LOGGER.info("[pradar-register] init register zookeeper node successful. {}", Pradar.AGENT_ID_CONTAIN_USER_INFO);
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class NetflixCuratorZkClientFactory method create.
public ZkClient create(final ZkClientSpec spec) throws Exception {
if (StringUtils.isBlank(spec.getZkServers())) {
throw new PradarException("zookeeper servers is empty.");
}
String path = ZooKeeper.class.getProtectionDomain().getCodeSource().getLocation().toString();
if (logger.isInfoEnabled()) {
logger.info("Load ZooKeeper from {}", path);
}
CuratorFramework client = CuratorFrameworkFactory.builder().connectString(spec.getZkServers()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).connectionTimeoutMs(spec.getConnectionTimeoutMillis()).sessionTimeoutMs(spec.getSessionTimeoutMillis()).threadFactory(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, spec.getThreadName());
t.setDaemon(true);
t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
logger.error("Thread {} caught a unknow exception with UncaughtExceptionHandler", t.getName(), e);
}
});
return t;
}
}).build();
client.start();
if (logger.isInfoEnabled()) {
logger.info("ZkClient started: {}", spec.getZkServers());
}
NetflixCuratorZkClient theClient = new NetflixCuratorZkClient(client, spec.getZkServers());
return theClient;
}
Aggregations