use of com.qlangtech.tis.trigger.jst.ILogListener in project plugins by qlangtech.
the class DefaultWatchPodLog method sendMsg.
/**
* 向监听者发送消息
*
* @param event
* @return 是否所有的监听者都死了?
*/
private boolean sendMsg(TargetResName indexName, ExecuteState event) throws IOException {
event.setServiceName(indexName.getName());
// event.setLogType(LogType.INCR_DEPLOY_STATUS_CHANGE);
boolean allConnectionDie = true;
synchronized (this) {
Iterator<ILogListener> lit = this.listeners.iterator();
ILogListener l = null;
while (lit.hasNext()) {
l = lit.next();
if (l.isClosed()) {
lit.remove();
continue;
} else {
allConnectionDie = false;
}
loopQueue.write(event);
l.sendMsg2Client(event);
}
}
return allConnectionDie;
}
use of com.qlangtech.tis.trigger.jst.ILogListener in project tis by qlangtech.
the class TestIncrStatusServer method testServer.
public void testServer() throws Exception {
int taskid = 123;
String appname = "baisuitest";
AtomicBoolean clientClosed = new AtomicBoolean(false);
RegisterMonitorEventHook eventHook = new RegisterMonitorEventHook() {
boolean hasStartSession = false;
boolean hasCloseSession = false;
int send2ClientCount = 0;
int readFromFileTailerCount = 0;
@Override
public void send2ClientFromFileTailer(File logFile, PExecuteState s) {
readFromFileTailerCount++;
}
@Override
void startSession() {
hasStartSession = true;
}
@Override
void send2Client(PExecuteState s, LoggingEvent e) {
send2ClientCount++;
}
@Override
void closeSession() {
hasCloseSession = true;
}
public void validateExpect() {
assertTrue(this.hasStartSession);
assertTrue(this.hasCloseSession);
assertTrue("send2ClientCount shall big than 0", send2ClientCount > 0);
assertTrue("read from file buffer", readFromFileTailerCount > 0);
}
};
FullBuildStatCollectorServer.registerMonitorEventHook = eventHook;
// 启动rpc服务端
Runnable writeLog = () -> {
MDC.put(IParamContext.KEY_TASK_ID, String.valueOf(taskid));
MDC.put("app", appname);
String logMsg = "test_log_msg";
Logger log = LoggerFactory.getLogger(TestIncrStatusServer.class);
while (true) {
// 需要会向RealtimeLoggerCollectorAppender 该appender中写入
log.info(logMsg);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
};
Thread tt = new Thread(writeLog);
tt.setDaemon(true);
tt.start();
StatusRpcClient.AssembleSvcCompsite svc = getRpcClient();
try {
CountDownLatch countdown = new CountDownLatch(1);
int[] receiveCount = new int[1];
StreamObserver<PMonotorTarget> observer = svc.registerMonitorEvent(new ILogListener() {
@Override
public void sendMsg2Client(Object biz) throws IOException {
}
@Override
public void read(Object event) {
PExecuteState stat = (PExecuteState) event;
System.out.println(stat.getTaskId() + " " + stat.getMsg());
if (receiveCount[0]++ > 5) {
try {
// 收到服务端 5次消息之后,模拟webSocket session 关闭
clientClosed.set(true);
// throw new RuntimeException("dddddddddddddd");
} finally {
countdown.countDown();
}
}
}
@Override
public boolean isClosed() {
return clientClosed.get();
}
});
PMonotorTarget.Builder mt = PMonotorTarget.newBuilder();
mt.setCollection("dummy");
mt.setTaskid(taskid);
mt.setLogtype(LogCollectorClient.convert(LogType.FULL.typeKind));
PMonotorTarget mtarget = mt.build();
observer.onNext(mtarget);
String targetToken = FullBuildStatCollectorServer.addListener(LogCollectorClient.convert(mtarget), new RealtimeLoggerCollectorAppender.LoggerCollectorAppenderListener() {
@Override
public void process(RealtimeLoggerCollectorAppender.LoggingEventMeta mtarget, LoggingEvent e) {
System.out.println("server side kk:" + e.getMessage());
}
@Override
public void readLogTailer(RealtimeLoggerCollectorAppender.LoggingEventMeta meta, File logFile) {
}
@Override
public boolean isClosed() {
return clientClosed.get();
}
});
assertTrue("countdown shall be execute", countdown.await(20, TimeUnit.SECONDS));
// 需要再写几个日志
Thread.sleep(2000l);
RealtimeLoggerCollectorAppender.LogTypeListeners logListeners = RealtimeLoggerCollectorAppender.appenderListener.getLogTypeListeners(targetToken);
assertNotNull("logListeners can not be null", logListeners);
assertEquals(1, logListeners.getListenerSize());
eventHook.validateExpect();
System.out.println("rpc test over");
} finally {
svc.close();
}
}
use of com.qlangtech.tis.trigger.jst.ILogListener in project plugins by qlangtech.
the class TestDefaultIncrK8sConfig method testlistPodsAndWatchLog.
// public void testDefaultIncrK8sConfig() throws Exception {
// DefaultIncrK8sConfig incrK8sCfg = new DefaultIncrK8sConfig();
// incrK8sCfg.namespace = "tis";
// incrK8sCfg.k8sName = "minikube";
// incrK8sCfg.imagePath = "registry.cn-hangzhou.aliyuncs.com/tis/tis-incr:latest";
//
// incrK8sCfg.getIncrSync().removeInstance("search4totalpay");
// }
public void testlistPodsAndWatchLog() throws Exception {
IRCController incrSync = getIncrSync();
String podName = "podname";
assertNotNull(incrSync);
final AtomicInteger msgReceiveCount = new AtomicInteger();
incrSync.listPodAndWatchLog(new TargetResName(totalpay), podName, new ILogListener() {
@Override
public void sendMsg2Client(Object biz) throws IOException {
System.out.println("flushCount:" + msgReceiveCount.incrementAndGet());
}
@Override
public void read(Object event) {
}
@Override
public boolean isClosed() {
return false;
}
});
Thread.sleep(5000);
assertTrue(msgReceiveCount.get() > 0);
}
Aggregations