Search in sources :

Example 1 with LogList

use of org.wso2.ei.dashboard.core.rest.model.LogList in project product-mi-tooling by wso2.

the class GroupsApi method getLogFilesByNodeIds.

@GET
@Path("/{group-id}/logs")
@Produces({ "application/json" })
@Operation(summary = "Get log files by node ids", description = "", tags = { "logFiles" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "List of log files of provided nodes", content = @Content(schema = @Schema(implementation = LogList.class))), @ApiResponse(responseCode = "200", description = "Unexpected error", content = @Content(schema = @Schema(implementation = Error.class))) })
public Response getLogFilesByNodeIds(@PathParam("group-id") @Parameter(description = "Group ID of the node") String groupId, @NotNull @QueryParam("nodes") @Parameter(description = "ID/IDs of the nodes") List<String> nodes) throws ManagementApiException {
    LogsDelegate logsDelegate = new LogsDelegate();
    LogList logList = logsDelegate.getLogsList(groupId, nodes);
    Response.ResponseBuilder responseBuilder = Response.ok().entity(logList);
    HttpUtils.setHeaders(responseBuilder);
    return responseBuilder.build();
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) LogList(org.wso2.ei.dashboard.core.rest.model.LogList) LogsDelegate(org.wso2.ei.dashboard.micro.integrator.delegates.LogsDelegate) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 2 with LogList

use of org.wso2.ei.dashboard.core.rest.model.LogList in project product-mi-tooling by wso2.

the class LogsDelegate method getLogsList.

public LogList getLogsList(String groupId, List<String> nodeList) throws ManagementApiException {
    log.debug("Fetching logs via management api.");
    LogList logList = new LogList();
    for (String nodeId : nodeList) {
        JsonArray logsArray = getLogsArray(groupId, nodeId);
        for (JsonElement jsonElement : logsArray) {
            JsonObject logObject = jsonElement.getAsJsonObject();
            String fileName = logObject.get("FileName").getAsString();
            String fileSize = logObject.get("Size").getAsString();
            AtomicBoolean isRecordExist = new AtomicBoolean(false);
            logList.stream().filter(o -> o.getName().equals(fileName)).forEach(o -> {
                LogDetail logDetail = new LogDetail();
                logDetail.setNodeId(nodeId);
                logDetail.setLogSize(fileSize);
                o.getNodes().add(logDetail);
                isRecordExist.set(true);
            });
            if (!isRecordExist.get()) {
                LogListInner logListInner = new LogListInner();
                logListInner.setName(fileName);
                List<LogDetail> logDetailList = new ArrayList<>();
                LogDetail logDetail = new LogDetail();
                logDetail.setNodeId(nodeId);
                logDetail.setLogSize(fileSize);
                logDetailList.add(logDetail);
                logListInner.setNodes(logDetailList);
                logList.add(logListInner);
            }
        }
    }
    return logList;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) ManagementApiUtils(org.wso2.ei.dashboard.core.commons.utils.ManagementApiUtils) LogDetail(org.wso2.ei.dashboard.core.rest.model.LogDetail) HttpEntity(org.apache.http.HttpEntity) HttpUtils(org.wso2.ei.dashboard.core.commons.utils.HttpUtils) ManagementApiException(org.wso2.ei.dashboard.core.exception.ManagementApiException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) LogList(org.wso2.ei.dashboard.core.rest.model.LogList) Utils(org.wso2.ei.dashboard.micro.integrator.commons.Utils) EntityUtils(org.apache.http.util.EntityUtils) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) DatabaseManagerFactory(org.wso2.ei.dashboard.core.db.manager.DatabaseManagerFactory) JsonArray(com.google.gson.JsonArray) List(java.util.List) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Log(org.apache.commons.logging.Log) LogListInner(org.wso2.ei.dashboard.core.rest.model.LogListInner) LogFactory(org.apache.commons.logging.LogFactory) DatabaseManager(org.wso2.ei.dashboard.core.db.manager.DatabaseManager) LogList(org.wso2.ei.dashboard.core.rest.model.LogList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogDetail(org.wso2.ei.dashboard.core.rest.model.LogDetail) LogListInner(org.wso2.ei.dashboard.core.rest.model.LogListInner) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Aggregations

LogList (org.wso2.ei.dashboard.core.rest.model.LogList)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Response (javax.ws.rs.core.Response)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 EntityUtils (org.apache.http.util.EntityUtils)1 HttpUtils (org.wso2.ei.dashboard.core.commons.utils.HttpUtils)1 ManagementApiUtils (org.wso2.ei.dashboard.core.commons.utils.ManagementApiUtils)1 DatabaseManager (org.wso2.ei.dashboard.core.db.manager.DatabaseManager)1