1
1
package com .flowci .core .agent .manager ;
2
2
3
+ import com .fasterxml .jackson .core .JacksonException ;
3
4
import com .fasterxml .jackson .databind .ObjectMapper ;
4
5
import com .flowci .core .agent .domain .*;
5
6
import com .flowci .core .agent .event .*;
6
7
import com .flowci .core .common .domain .StatusCode ;
7
8
import com .flowci .core .common .domain .http .ResponseMessage ;
8
9
import com .flowci .core .common .manager .SpringEventManager ;
9
- import lombok .extern .log4j . Log4j2 ;
10
+ import lombok .extern .slf4j . Slf4j ;
10
11
import org .springframework .beans .factory .annotation .Autowired ;
11
12
import org .springframework .stereotype .Component ;
12
13
import org .springframework .web .socket .BinaryMessage ;
23
24
/**
24
25
* Handle event from agent via websocket
25
26
*/
26
- @ Log4j2
27
+ @ Slf4j
27
28
@ Component
28
29
public class AgentEventManager extends BinaryWebSocketHandler {
29
30
@@ -128,8 +129,8 @@ private <T> void writeMessage(WebSocketSession session, ResponseMessage<T> msg)
128
129
try {
129
130
byte [] bytes = objectMapper .writeValueAsBytes (msg );
130
131
writeMessage (session , bytes );
131
- } catch (IOException e ) {
132
- log .warn (e );
132
+ } catch (JacksonException e ) {
133
+ log .warn ("Unable to convert agent response message" , e );
133
134
}
134
135
}
135
136
@@ -138,7 +139,7 @@ private void writeMessage(WebSocketSession session, byte[] body) {
138
139
try {
139
140
session .sendMessage (new BinaryMessage (body ));
140
141
} catch (IOException e ) {
141
- log .warn (e );
142
+ log .warn ("Unable to send message" , e );
142
143
}
143
144
}
144
145
}
@@ -159,26 +160,22 @@ private void onConnected(WebSocketSession session, String token, byte[] body) {
159
160
writeMessage (token , new ResponseMessage <>(StatusCode .OK , agent .getConfig ()));
160
161
log .debug ("Agent {} is connected with status {}" , token , init .getStatus ());
161
162
} catch (Exception e ) {
162
- log .warn (e );
163
+ log .warn ("Agent connected error" , e );
163
164
writeMessage (session , new ResponseMessage <Void >(StatusCode .FATAL , e .getMessage (), null ));
164
165
}
165
166
}
166
167
167
168
private void onCmdOut (String token , byte [] body ) {
168
- try {
169
- log .debug ("Agent {} got cmd back: {}" , token , new String (body ));
170
- eventManager .publish (new OnCmdOutEvent (this , body ));
171
- } catch (Exception e ) {
172
- log .warn (e );
173
- }
169
+ log .debug ("Agent {} got cmd back: {}" , token , new String (body ));
170
+ eventManager .publish (new OnCmdOutEvent (this , body ));
174
171
}
175
172
176
173
private void onShellLog (byte [] body ) {
177
174
try {
178
175
ShellLog item = objectMapper .readValue (body , ShellLog .class );
179
176
eventManager .publish (new OnShellLogEvent (this , item .getJobId (), item .getStepId (), item .getLog ()));
180
177
} catch (IOException e ) {
181
- log .warn (e );
178
+ log .warn ("Unable to convert to ShellLog" , e );
182
179
}
183
180
}
184
181
@@ -187,7 +184,7 @@ private void onTtyLog(byte[] body) {
187
184
TtyCmd .Log item = objectMapper .readValue (body , TtyCmd .Log .class );
188
185
eventManager .publish (new OnTTYLogEvent (this , item .getId (), item .getLog ()));
189
186
} catch (IOException e ) {
190
- log .warn (e );
187
+ log .warn ("Unable to convert to TtyCmd.Log" , e );
191
188
}
192
189
}
193
190
@@ -197,7 +194,7 @@ private void onProfile(String token, byte[] body) {
197
194
profile .setId (token );
198
195
eventManager .publish (new OnAgentProfileEvent (this , profile ));
199
196
} catch (IOException e ) {
200
- log .warn (e );
197
+ log .warn ("Unable to convert to AgentProfile" , e );
201
198
}
202
199
}
203
200
0 commit comments