diff --git a/pom.xml b/pom.xml
index f3876c4..a64bdd2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,7 +60,7 @@
io.github.oneteme.traceapi
traceapi-core
- 0.0.15-SNAPSHOT
+ 0.0.16-SNAPSHOT
io.github.oneteme
diff --git a/src/main/java/org/usf/trace/api/server/ApiController.java b/src/main/java/org/usf/trace/api/server/ApiController.java
index 7ad8dc7..eb439a7 100644
--- a/src/main/java/org/usf/trace/api/server/ApiController.java
+++ b/src/main/java/org/usf/trace/api/server/ApiController.java
@@ -4,9 +4,7 @@
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.ResponseEntity.accepted;
import static org.usf.trace.api.server.Utils.requireSingle;
-import static org.usf.traceapi.core.RemoteTraceSender.INCOMING_ENDPOINT;
-import static org.usf.traceapi.core.RemoteTraceSender.MAIN_ENDPOINT;
-import static org.usf.traceapi.core.RemoteTraceSender.TRACE_ENDPOINT;
+import static org.usf.traceapi.core.Session.nextId;
import java.time.Instant;
import java.util.List;
@@ -22,46 +20,52 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
+import org.usf.traceapi.core.ApiRequest;
+import org.usf.traceapi.core.ApiSession;
import org.usf.traceapi.core.ApplicationInfo;
-import org.usf.traceapi.core.IncomingRequest;
-import org.usf.traceapi.core.MainRequest;
-import org.usf.traceapi.core.OutcomingRequest;
+import org.usf.traceapi.core.MainSession;
import org.usf.traceapi.core.Session;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+@Slf4j
@CrossOrigin
@RestController
-@RequestMapping(value = TRACE_ENDPOINT, produces = APPLICATION_JSON_VALUE)
+@RequestMapping(value = "trace", produces = APPLICATION_JSON_VALUE)
@RequiredArgsConstructor
-public class ApiController {
+public class ApiController {
private final RequestDao dao;
private final SessionQueueService queueService;
- @PutMapping(INCOMING_ENDPOINT)
- public ResponseEntity saveRequest(@RequestBody IncomingRequest req) {
- return appendRequest(req);
+ @PutMapping("session")
+ public ResponseEntity saveSession(HttpServletRequest hsr,@RequestBody Session[] sessions) {
+ for(Session s : sessions) {
+ if(isNull(s.getId())) {
+ if(s instanceof MainSession) {
+ s.setId(nextId()); // safe id set for web collectors
+ updateRemoteAddress(hsr,(MainSession) s);
+ }
+ else if(s instanceof ApiSession) {
+ log.warn("ApiSesstion id is null : {}", s);
+ }
+ }
+ }
+ queueService.add(sessions);
+ return accepted().build();
}
-
- @PutMapping(MAIN_ENDPOINT)
- public ResponseEntity saveRequest(HttpServletRequest hsr, @RequestBody MainRequest req) {
+ public void updateRemoteAddress(HttpServletRequest hsr, @RequestBody MainSession req) {
if(isNull(req.getApplication())) { //set IP address for WABAPP trace
req.setApplication(new ApplicationInfo(null, null, hsr.getRemoteAddr(), null, null, null));
}
else if(isNull(req.getApplication().getAddress())) {
req.setApplication(req.getApplication().withAddress(hsr.getRemoteAddr()));
}
- return appendRequest(req);
- }
-
- private ResponseEntity appendRequest(Session session){
- queueService.add(session);
- return accepted().build();
}
- @GetMapping(INCOMING_ENDPOINT)
- public List getIncomingRequestByCriteria(
+ @GetMapping("incoming/request")
+ public List getIncomingRequestByCriteria(
@RequestParam(defaultValue = "true", name = "lazy") boolean lazy,
@RequestParam(required = false, name = "id") String[] id,
@RequestParam(required = false, name = "name") String[] name,
@@ -75,12 +79,12 @@ public List getIncomingRequestByCriteria(
}
@GetMapping("incoming/request/{id}")
- public IncomingRequest getIncomingRequestById(@PathVariable String id) { // without tree
+ public ApiSession getIncomingRequestById(@PathVariable String id) { // without tree
return requireSingle(dao.getIncomingRequestById(true, id));
}
- @GetMapping(MAIN_ENDPOINT)
- public List getMainRequestByCriteria(
+ @GetMapping("main/request")
+ public List getMainRequestByCriteria(
@RequestParam(defaultValue = "true", name = "lazy") boolean lazy,
@RequestParam(required = false, name = "id") String[] id,
@RequestParam(required = false, name = "env") String[] env,
@@ -93,17 +97,17 @@ public List getMainRequestByCriteria(
}
@GetMapping("main/request/{id}")
- public MainRequest getMainRequestById(@PathVariable String id) { // without tree
+ public MainSession getMainRequestById(@PathVariable String id) { // without tree
return requireSingle(dao.getMainRequestById(true, id));
}
@GetMapping("incoming/request/{id}/out")
- public OutcomingRequest getOutcomingRequestById(@PathVariable String id) {
+ public ApiRequest getOutcomingRequestById(@PathVariable String id) {
return dao.getOutcomingRequestById(id);
}
@GetMapping("incoming/request/{id}/tree") //LATER
- public IncomingRequest getIncomingRequestTreeById(@PathVariable String id) {
+ public ApiSession getIncomingRequestTreeById(@PathVariable String id) {
return requireSingle(dao.getIncomingRequestById(true, id)); //change query
}
diff --git a/src/main/java/org/usf/trace/api/server/CacheController.java b/src/main/java/org/usf/trace/api/server/CacheController.java
index 1326c29..02f6670 100644
--- a/src/main/java/org/usf/trace/api/server/CacheController.java
+++ b/src/main/java/org/usf/trace/api/server/CacheController.java
@@ -3,10 +3,13 @@
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import java.util.Collection;
+import java.util.Set;
import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.usf.traceapi.core.Session;
@@ -25,4 +28,9 @@ public Collection getCache(){
return queue.waitList();
}
+ @DeleteMapping
+ public Collection deleteSessions(@RequestParam("id") Set ids){
+ return queue.deleteSessions(ids);
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/org/usf/trace/api/server/Exchange.java b/src/main/java/org/usf/trace/api/server/Exchange.java
index 2059ee0..99ea5f7 100644
--- a/src/main/java/org/usf/trace/api/server/Exchange.java
+++ b/src/main/java/org/usf/trace/api/server/Exchange.java
@@ -1,8 +1,8 @@
package org.usf.trace.api.server;
import lombok.Setter;
-import org.usf.traceapi.core.IncomingRequest;
-import org.usf.traceapi.core.OutcomingRequest;
+import org.usf.traceapi.core.ApiSession;
+import org.usf.traceapi.core.ApiRequest;
import lombok.Getter;
@@ -13,12 +13,8 @@
*/
@Getter
@Setter
-public final class Exchange extends OutcomingRequest {
+public final class Exchange extends ApiRequest {
- private IncomingRequest remoteTrace;
-
- public Exchange(String id) {
- super(id);
- }
+ private ApiSession remoteTrace;
}
diff --git a/src/main/java/org/usf/trace/api/server/RequestDao.java b/src/main/java/org/usf/trace/api/server/RequestDao.java
index 3ef32c7..8b2aeb2 100644
--- a/src/main/java/org/usf/trace/api/server/RequestDao.java
+++ b/src/main/java/org/usf/trace/api/server/RequestDao.java
@@ -21,6 +21,7 @@
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
+import java.util.function.Supplier;
import java.util.stream.Stream;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -43,13 +44,14 @@ public class RequestDao {
@Transactional(rollbackFor = Exception.class)
public void saveSessions(List sessions) {
- filterAndSave(sessions, IncomingRequest.class, this::addIncomingRequest);
- filterAndSave(sessions, MainRequest.class, this::addMainRequest);
+ filterAndSave(sessions, ApiSession.class, this::addIncomingRequest);
+ filterAndSave(sessions, MainSession.class, this::addMainRequest);
filterSubAndSave(sessions, Session::getRequests, (s, r) -> new OutcomingRequestWrapper(r, s.getId()), this::addOutcomingRequest);
filterSubAndSave(sessions, Session::getQueries, (s, q) -> new OutcomingQueryWrapper(q, s.getId()), this::addOutcomingQueries);
+ filterSubAndSave(sessions, Session::getStages, (s, st) -> new OutcomingStagesWrapper(st, s.getId()), this::addOutcomingStages);
}
- private void addMainRequest(List reqList) {
+ private void addMainRequest(List reqList) {
template.batchUpdate("INSERT INTO E_MAIN_REQ(ID_MAIN_REQ,VA_NAME,VA_USR,DH_DBT,DH_FIN,LNCH,LOC,VA_THRED,VA_APP_NME,VA_VRS,VA_ADRS,VA_ENV,VA_OS,VA_RE,VA_ERR_CLS,VA_ERR_MSG)"
+ " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", reqList, reqList.size(), (ps, o) -> {
var app = nullableApplication(o.getApplication());
@@ -73,7 +75,7 @@ private void addMainRequest(List reqList) {
});
}
- private void addIncomingRequest(List reqList) {
+ private void addIncomingRequest(List reqList) {
template.batchUpdate("INSERT INTO E_IN_REQ(ID_IN_REQ,VA_MTH,VA_PRTCL,VA_HST,CD_PRT,VA_PTH,VA_QRY,VA_CNT_TYP,VA_AUTH,CD_STT,VA_I_SZE,VA_O_SZE,DH_DBT,DH_FIN,VA_THRED,VA_ERR_CLS,VA_ERR_MSG,VA_API_NME,VA_USR,VA_APP_NME,VA_VRS,VA_ADRS,VA_ENV,VA_OS,VA_RE)"
+ " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", reqList, reqList.size(), (ps, o) -> {
var app = nullableApplication(o.getApplication());
@@ -131,6 +133,22 @@ private void addOutcomingRequest(List reqList) {
});
}
+ public void addOutcomingStages(List stagesList){
+ template.batchUpdate("INSERT INTO E_OUT_STG(VA_NAME,LOC,DH_DBT,DH_FIN,VA_USR,VA_THRED,VA_ERR_CLS,VA_ERR_MSG,CD_IN_REQ)"
+ + " VALUES(?,?,?,?,?,?,?,?,?)", stagesList,stagesList.size(),(ps,o)-> {
+ var exp = nullableException(o.getException());
+ ps.setString(1,o.getName());
+ ps.setString(2,o.getLocation());
+ ps.setTimestamp(3,fromNullableInstant(o.getStart()));
+ ps.setTimestamp(4,fromNullableInstant(o.getEnd()));
+ ps.setString(5,o.getUser());
+ ps.setString(6,o.getThreadName());
+ ps.setString(7,exp.getClassname());
+ ps.setString(8,exp.getMessage());
+ ps.setString(9,o.getParentId());
+ });
+ }
+
private void addOutcomingQueries(List qryList) {
var maxId = template.queryForObject("SELECT COALESCE(MAX(ID_OUT_QRY), 0) FROM E_OUT_QRY", Long.class);
var inc = new AtomicLong(maxId);
@@ -167,12 +185,13 @@ private void addDatabaseActions(List queries) {
}
@Deprecated // reuse RequestDao::outcomingRequests using criteria
- public OutcomingRequest getOutcomingRequestById(String id) {
+ public ApiRequest getOutcomingRequestById(String id) {
return template.query("SELECT ID_OUT_REQ,VA_PRTCL,VA_HST,CD_PRT,VA_PTH,VA_QRY,VA_MTH,CD_STT,VA_I_SZE,VA_O_SZE,DH_DBT,DH_FIN,VA_THRED,CD_IN_REQ FROM E_OUT_REQ"
+ " WHERE ID_OUT_REQ = ? ", new Object[]{id}, newArray(1, VARCHAR), rs -> {
if (rs.next()) {
- OutcomingRequest out = new OutcomingRequest(rs.getString("ID_OUT_REQ"));
+ ApiRequest out = new ApiRequest();
+ out.setId(rs.getString("ID_OUT_REQ"));
out.setProtocol(rs.getString("VA_PRTCL"));
out.setHost(rs.getString("VA_HST"));
out.setPort(rs.getInt("CD_PRT"));
@@ -191,7 +210,7 @@ public OutcomingRequest getOutcomingRequestById(String id) {
});
}
- public List getMainRequestByCriteria(boolean lazy, FilterCriteria fc) {
+ public List getMainRequestByCriteria(boolean lazy, FilterCriteria fc) {
var query = "SELECT ID_MAIN_REQ,VA_NAME,VA_USR,DH_DBT,DH_FIN,LNCH,LOC,VA_THRED,VA_APP_NME,VA_VRS,VA_ADRS,VA_ENV,VA_OS,VA_RE,VA_ERR_CLS,VA_ERR_MSG FROM E_MAIN_REQ";
Collection argTypes = new ArrayList<>();
@@ -199,8 +218,9 @@ public List getMainRequestByCriteria(boolean lazy, FilterCriteria f
query += fc.toSql(ID_IN_REQ, ID_MAIN_REQ, VA_APP_NME, VA_ENV, CD_PRT, LNCH, DH_DBT, DH_FIN, args, argTypes);
- List res = template.query(query, args.toArray(), argTypes.stream().mapToInt(i -> i).toArray(), (rs, i) -> {
- MainRequest main = new MainRequest(rs.getString("ID_MAIN_REQ"));
+ List res = template.query(query, args.toArray(), argTypes.stream().mapToInt(i -> i).toArray(), (rs, i) -> {
+ MainSession main = new MainSession();
+ main.setId(rs.getString("ID_MAIN_REQ")); // add value of nullable
main.setName(rs.getString("VA_NAME"));
main.setUser(rs.getString("VA_USR"));
main.setStart(fromNullableTimestamp(rs.getTimestamp("DH_DBT")));
@@ -223,14 +243,15 @@ public List getMainRequestByCriteria(boolean lazy, FilterCriteria f
return main;
});
if (lazy && !res.isEmpty()) {
- var reqMap = res.stream().collect(toMap(MainRequest::getId, identity()));
- outcomingRequests(reqMap.keySet(),OutcomingRequest::new).forEach(r -> reqMap.get(r.getParentId()).getRequests().add(r.getRequest()));
+ var reqMap = res.stream().collect(toMap(MainSession::getId, identity()));
+ outcomingRequests(reqMap.keySet(),ApiRequest::new).forEach(r -> reqMap.get(r.getParentId()).getRequests().add(r.getRequest()));
+ outcomingStages(reqMap.keySet(),RunnableStage::new).forEach(r -> reqMap.get(r.getParentId()).getStages().add(r.getStage()));
outcomingQueries(reqMap.keySet()).forEach(q -> reqMap.get(q.getParentId()).getQueries().add(q.getQuery()));
}
return res;
}
- public List getMainRequestById(boolean lazy, String... idArr) {
+ public List getMainRequestById(boolean lazy, String... idArr) {
var query = "SELECT ID_MAIN_REQ,VA_NAME,VA_USR,DH_DBT,DH_FIN,LNCH,LOC,VA_THRED,VA_APP_NME,VA_VRS,VA_ADRS,VA_ENV,VA_OS,VA_RE,VA_ERR_CLS,VA_ERR_MSG FROM E_MAIN_REQ";
int[] argTypes = null;
if (!isEmpty(idArr)) {
@@ -238,8 +259,9 @@ public List getMainRequestById(boolean lazy, String... idArr) {
argTypes = newArray(idArr.length, VARCHAR);
}
query += " order by DH_DBT desc";
- List res = template.query(query, idArr, argTypes, (rs, i) -> {
- MainRequest main = new MainRequest(rs.getString("ID_MAIN_REQ"));
+ List res = template.query(query, idArr, argTypes, (rs, i) -> {
+ MainSession main = new MainSession();
+ main.setId(rs.getString("ID_MAIN_REQ"));
main.setName(rs.getString("VA_NAME"));
main.setUser(rs.getString("VA_USR"));
main.setStart(fromNullableTimestamp(rs.getTimestamp("DH_DBT")));
@@ -262,22 +284,24 @@ public List getMainRequestById(boolean lazy, String... idArr) {
return main;
});
if (lazy && !res.isEmpty()) {
- var reqMap = res.stream().collect(toMap(MainRequest::getId, identity()));
- outcomingRequests(reqMap.keySet(),OutcomingRequest::new).forEach(r -> reqMap.get(r.getParentId()).getRequests().add(r.getRequest()));
+ var reqMap = res.stream().collect(toMap(MainSession::getId, identity()));
+ outcomingRequests(reqMap.keySet(),ApiRequest::new).forEach(r -> reqMap.get(r.getParentId()).getRequests().add(r.getRequest()));
+ outcomingStages(reqMap.keySet(),RunnableStage::new).forEach(r -> reqMap.get(r.getParentId()).getStages().add(r.getStage()));
outcomingQueries(reqMap.keySet()).forEach(q -> reqMap.get(q.getParentId()).getQueries().add(q.getQuery()));
}
return res;
}
- public List getIncomingRequestByCriteria(boolean lazy, FilterCriteria fs) {
+ public List getIncomingRequestByCriteria(boolean lazy, FilterCriteria fs) {
var query = "SELECT ID_IN_REQ,VA_MTH,VA_PRTCL,VA_HST,CD_PRT,VA_PTH,VA_QRY,VA_CNT_TYP,VA_AUTH,CD_STT,VA_I_SZE,VA_O_SZE,DH_DBT,DH_FIN,VA_THRED,VA_ERR_CLS,VA_ERR_MSG,VA_API_NME,VA_USR,VA_APP_NME,VA_VRS,VA_ADRS,VA_ENV,VA_OS,VA_RE FROM E_IN_REQ ";
Collection argTypes = new ArrayList<>();
Collection