Search in sources :

Example 1 with APILogInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO in project carbon-apimgt by wso2.

the class ApiLoggingConfigsApiServiceImpl method apiLoggingConfigsGet.

public Response apiLoggingConfigsGet(MessageContext messageContext) {
    ErrorDTO errorObject = new ErrorDTO();
    Response.Status status = Response.Status.NOT_IMPLEMENTED;
    errorObject.setCode(200);
    errorObject.setMessage(status.toString());
    List<APILoggingConfigDTO> loggingAPIDTOList = new ArrayList<>();
    try {
        List<APILogInfoDTO> apiLoggerList = LoggingMgtDAO.getInstance().retrieveAllAPILoggerList();
        for (APILogInfoDTO apiLogInfo : apiLoggerList) {
            APILoggingConfigDTO apiLoggingConfigDTO = new APILoggingConfigDTO();
            apiLoggingConfigDTO.setContext(apiLogInfo.getContext());
            apiLoggingConfigDTO.setLogLevel(apiLogInfo.getLogLevel());
            loggingAPIDTOList.add(apiLoggingConfigDTO);
        }
    } catch (APIManagementException e) {
        log.error("Error while retrieving api logger list");
    }
    APILoggingConfigListDTO apiLoggingConfigListDTO = new APILoggingConfigListDTO();
    apiLoggingConfigListDTO.apis(loggingAPIDTOList);
    return Response.ok().entity(apiLoggingConfigListDTO).build();
}
Also used : Response(javax.ws.rs.core.Response) APILoggingConfigDTO(org.wso2.carbon.apimgt.internal.service.dto.APILoggingConfigDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.internal.service.dto.ErrorDTO) ArrayList(java.util.ArrayList) APILoggingConfigListDTO(org.wso2.carbon.apimgt.internal.service.dto.APILoggingConfigListDTO) APILogInfoDTO(org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO)

Example 2 with APILogInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO in project carbon-apimgt by wso2.

the class TenantLogsApiServiceImpl method tenantLogsTenantIdApisApiIdGet.

public Response tenantLogsTenantIdApisApiIdGet(String tenantId, String apiId, MessageContext messageContext) throws APIManagementException {
    APILoggingImpl apiLoggingImpl = new APILoggingImpl();
    List<APILogInfoDTO> apiLogInfoDTOList = apiLoggingImpl.getAPILoggerListByApiId(tenantId, apiId);
    LoggingApiOutputListDTO loggingApiOutputListDT = DevopsAPIUtils.getLoggingAPIList(apiLogInfoDTOList);
    return Response.ok().entity(loggingApiOutputListDT).build();
}
Also used : APILogInfoDTO(org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO) LoggingApiOutputListDTO(org.wso2.carbon.apimgt.rest.api.devops.dto.LoggingApiOutputListDTO) APILoggingImpl(org.wso2.carbon.apimgt.devops.impl.logging.APILoggingImpl)

Example 3 with APILogInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO in project carbon-apimgt by wso2.

the class DevopsAPIUtils method getLoggingAPIList.

public static LoggingApiOutputListDTO getLoggingAPIList(List<APILogInfoDTO> apiLogInfoDTOList) {
    LoggingApiOutputListDTO loggingApiOutputListDTO = new LoggingApiOutputListDTO();
    List<LoggingApiOutputDTO> loggingApiOutputDTOList = new ArrayList<>();
    for (APILogInfoDTO apiLogInfoDTO : apiLogInfoDTOList) {
        LoggingApiOutputDTO loggingApiOutputDTO = new LoggingApiOutputDTO();
        loggingApiOutputDTO.setContext(apiLogInfoDTO.getContext());
        loggingApiOutputDTO.setLogLevel(apiLogInfoDTO.getLogLevel());
        loggingApiOutputDTO.setApiId(apiLogInfoDTO.getApiId());
        loggingApiOutputDTOList.add(loggingApiOutputDTO);
    }
    loggingApiOutputListDTO.apis(loggingApiOutputDTOList);
    return loggingApiOutputListDTO;
}
Also used : ArrayList(java.util.ArrayList) APILogInfoDTO(org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO) LoggingApiOutputDTO(org.wso2.carbon.apimgt.rest.api.devops.dto.LoggingApiOutputDTO) LoggingApiOutputListDTO(org.wso2.carbon.apimgt.rest.api.devops.dto.LoggingApiOutputListDTO)

Example 4 with APILogInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO in project carbon-apimgt by wso2.

the class LoggingMgtDAO method retrieveAPILoggerList.

public List<APILogInfoDTO> retrieveAPILoggerList(String organization, String logLevel) throws APIManagementException {
    List<APILogInfoDTO> apiLogInfoDTOList = new ArrayList<>();
    String query;
    if (logLevel == null) {
        query = SQLConstants.RETRIEVE_PER_API_LOGGING_ALL_SQL;
    } else {
        switch(logLevel.toUpperCase()) {
            case APIConstants.LOG_LEVEL_OFF:
                query = SQLConstants.RETRIEVE_PER_API_LOGGING_OFF_SQL;
                break;
            case APIConstants.LOG_LEVEL_BASIC:
                query = SQLConstants.RETRIEVE_PER_API_LOGGING_BASIC_SQL;
                break;
            case APIConstants.LOG_LEVEL_STANDARD:
                query = SQLConstants.RETRIEVE_PER_API_LOGGING_STANDARD_SQL;
                break;
            case APIConstants.LOG_LEVEL_FULL:
                query = SQLConstants.RETRIEVE_PER_API_LOGGING_FULL_SQL;
                break;
            default:
                throw new APIManagementException("Invalid log level", ExceptionCodes.from(ExceptionCodes.LOGGING_API_INCORRECT_LOG_LEVEL));
        }
    }
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        preparedStatement.setString(1, organization);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                String retrievedLogLevel = APIConstants.LOG_LEVEL_OFF;
                if (resultSet.getString(APIConstants.LOG_LEVEL) != null) {
                    retrievedLogLevel = resultSet.getString(APIConstants.LOG_LEVEL);
                }
                APILogInfoDTO apiLogInfoDTO = new APILogInfoDTO(resultSet.getString(API_UUID), resultSet.getString(CONTEXT), retrievedLogLevel);
                apiLogInfoDTOList.add(apiLogInfoDTO);
            }
        }
    } catch (SQLException e) {
        handleException("Failed to retrieve API logging for organization" + organization, e);
    }
    return apiLogInfoDTOList;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) APILogInfoDTO(org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO) PreparedStatement(java.sql.PreparedStatement)

Example 5 with APILogInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO in project carbon-apimgt by wso2.

the class LoggingMgtDAO method retrieveAllAPILoggerList.

public List<APILogInfoDTO> retrieveAllAPILoggerList() throws APIManagementException {
    List<APILogInfoDTO> apiLogInfoDTOList = new ArrayList<>();
    String query = SQLConstants.RETRIEVE_ALL_PER_API_LOGGING_SQL;
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(query)) {
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                String logLevel = APIConstants.LOG_LEVEL_OFF;
                if (resultSet.getString(APIConstants.LOG_LEVEL) != null) {
                    logLevel = resultSet.getString(APIConstants.LOG_LEVEL);
                }
                APILogInfoDTO apiLogInfoDTO = new APILogInfoDTO(resultSet.getString(API_UUID), resultSet.getString(CONTEXT), logLevel);
                apiLogInfoDTOList.add(apiLogInfoDTO);
            }
        }
    } catch (SQLException e) {
        handleException("Failed to retrieve organization", e);
    }
    return apiLogInfoDTOList;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) APILogInfoDTO(org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO) PreparedStatement(java.sql.PreparedStatement)

Aggregations

APILogInfoDTO (org.wso2.carbon.apimgt.impl.dto.APILogInfoDTO)7 ArrayList (java.util.ArrayList)5 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 LoggingApiOutputListDTO (org.wso2.carbon.apimgt.rest.api.devops.dto.LoggingApiOutputListDTO)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APILoggingImpl (org.wso2.carbon.apimgt.devops.impl.logging.APILoggingImpl)2 Response (javax.ws.rs.core.Response)1 APILoggingConfigDTO (org.wso2.carbon.apimgt.internal.service.dto.APILoggingConfigDTO)1 APILoggingConfigListDTO (org.wso2.carbon.apimgt.internal.service.dto.APILoggingConfigListDTO)1 ErrorDTO (org.wso2.carbon.apimgt.internal.service.dto.ErrorDTO)1 LoggingApiOutputDTO (org.wso2.carbon.apimgt.rest.api.devops.dto.LoggingApiOutputDTO)1