diff --git a/src/examples/alert/AlertLoggerMock.hpp b/src/examples/alert/AlertLoggerMock.hpp index 48c3a903d..ffa885d08 100644 --- a/src/examples/alert/AlertLoggerMock.hpp +++ b/src/examples/alert/AlertLoggerMock.hpp @@ -34,7 +34,7 @@ class AlertLoggerMock : public terrama2::services::alert::core::AlertLogger void log(MessageType messageType, const std::string &description, RegisterId /*registerId*/) const override { - std::cout << "Message Type: " << messageType << " Message: " << description << std::endl; + std::cout << "Message Type: " << static_cast(messageType) << " Message: " << description << std::endl; } }; diff --git a/src/examples/core/ProcessLogger.cpp b/src/examples/core/ProcessLogger.cpp index a9306fd7d..c6b3e1b19 100644 --- a/src/examples/core/ProcessLogger.cpp +++ b/src/examples/core/ProcessLogger.cpp @@ -81,16 +81,16 @@ int main(int argc, char* argv[]) log.logValue("tag2", "value4", registerID); // Log errors - log.log(Logger::ERROR_MESSAGE, "Unit Test Error", registerID); - log.log(Logger::ERROR_MESSAGE, "Unit Test second Error", registerID); + log.log(Logger::MessageType::ERROR_MESSAGE, "Unit Test Error", registerID); + log.log(Logger::MessageType::ERROR_MESSAGE, "Unit Test second Error", registerID); // Log informations - log.log(Logger::INFO_MESSAGE, "Unit Test Info", registerID); - log.log(Logger::INFO_MESSAGE, "Unit Test seconde Info", registerID); + log.log(Logger::MessageType::INFO_MESSAGE, "Unit Test Info", registerID); + log.log(Logger::MessageType::INFO_MESSAGE, "Unit Test seconde Info", registerID); // Log the end of process with the timestamp of processed data std::shared_ptr< te::dt::TimeInstantTZ > data_dateTime = terrama2::core::TimeUtils::nowUTC(); - log.result(Logger::DONE, data_dateTime, registerID); + log.result(Logger::Status::DONE, data_dateTime, registerID); // Get the process ID consulting by register ID ProcessId process_id = log.processID(registerID); diff --git a/src/examples/view/ViewLoggerMock.hpp b/src/examples/view/ViewLoggerMock.hpp index 4db8517b2..9c15d56b0 100644 --- a/src/examples/view/ViewLoggerMock.hpp +++ b/src/examples/view/ViewLoggerMock.hpp @@ -31,7 +31,7 @@ class ViewLoggerMock : public terrama2::services::view::core::ViewLogger void log(MessageType messageType, const std::string &description, RegisterId) const override { - std::cout << "Message Type: " << messageType << " Message: " << description << std::endl; + std::cout << "Message Type: " << static_cast(messageType) << " Message: " << description << std::endl; } }; diff --git a/src/terrama2/core/utility/ProcessLogger.hpp b/src/terrama2/core/utility/ProcessLogger.hpp index 42c31057e..d0f25288a 100644 --- a/src/terrama2/core/utility/ProcessLogger.hpp +++ b/src/terrama2/core/utility/ProcessLogger.hpp @@ -58,7 +58,7 @@ namespace terrama2 \brief Possible status of manipulate data. */ - enum Status + enum class Status { ERROR = 1, /*!< Error during process */ START = 2, /*!< The process started */ @@ -75,7 +75,7 @@ namespace terrama2 \brief Possible status of logged messages. */ - enum MessageType + enum class MessageType { ERROR_MESSAGE = 1, INFO_MESSAGE = 2, diff --git a/src/terrama2/services/alert/core/AlertExecutor.cpp b/src/terrama2/services/alert/core/AlertExecutor.cpp index 5179974d2..c8aedd3f0 100644 --- a/src/terrama2/services/alert/core/AlertExecutor.cpp +++ b/src/terrama2/services/alert/core/AlertExecutor.cpp @@ -547,8 +547,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex auto dataMap = dataAccessor->getSeries(filter, remover); if(dataMap.empty()) { - logger->result(AlertLogger::DONE, nullptr, executionPackage.registerId); - logger->log(AlertLogger::WARNING_MESSAGE, QObject::tr("No data to available.").toStdString(), executionPackage.registerId); + logger->result(AlertLogger::Status::DONE, nullptr, executionPackage.registerId); + logger->log(AlertLogger::MessageType::WARNING_MESSAGE, QObject::tr("No data to available.").toStdString(), executionPackage.registerId); TERRAMA2_LOG_WARNING() << QObject::tr("No data to available."); emit alertFinished(alertId, executionPackage.executionDate, false); return; @@ -592,7 +592,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex if(datetimeColumnName.empty()) { QString errMsg = QObject::tr("Unable to identify timestamp column."); - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; return; } @@ -607,7 +607,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex if(dataSetType->getNumberOfForeignKeys() != 1) { QString errMsg = QObject::tr("Invalid number of identifier attribute."); - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; return; } @@ -617,8 +617,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex if(!idProperty) { QString errMsg = QObject::tr("Invalid identifier attribute."); - logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId); - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; return; } @@ -681,7 +681,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex if(alertDataSet->isEmpty()) { QString errMsg = QObject::tr("No alert data for %1 data series.").arg(dataset->dataSeriesId); - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; return; } @@ -721,8 +721,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex if(!alertGenerated) { QString errMsg = QObject::tr("No alert was generated."); - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); - logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId); TERRAMA2_LOG_WARNING() << errMsg.toStdString(); emit alertFinished(alertId, executionPackage.executionDate, false); return; @@ -733,7 +733,7 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex logger->setStartProcessingTime(processingStartTime, executionPackage.registerId); logger->setEndProcessingTime(processingEndTime, executionPackage.registerId); - logger->result(AlertLogger::DONE, executionPackage.executionDate, executionPackage.registerId); + logger->result(AlertLogger::Status::DONE, executionPackage.executionDate, executionPackage.registerId); TERRAMA2_LOG_INFO() << QObject::tr("Alert '%1' generated successfully").arg(alertPtr->name.c_str()); @@ -744,16 +744,16 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex } catch(const terrama2::Exception& e) { - logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId); - logger->log(AlertLogger::ERROR_MESSAGE, boost::get_error_info(e)->toStdString(), executionPackage.registerId); + logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, boost::get_error_info(e)->toStdString(), executionPackage.registerId); TERRAMA2_LOG_DEBUG() << boost::get_error_info(e)->toStdString(); emit alertFinished(alertId, executionPackage.executionDate, false); } catch(const boost::exception& e) { - logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId); - logger->log(AlertLogger::ERROR_MESSAGE, boost::diagnostic_information(e), executionPackage.registerId); + logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, boost::diagnostic_information(e), executionPackage.registerId); TERRAMA2_LOG_ERROR() << boost::diagnostic_information(e); emit alertFinished(alertId, executionPackage.executionDate, false); @@ -761,8 +761,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex catch(const std::exception& e) { QString errMsg(e.what()); - logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId); - logger->log(AlertLogger::ERROR_MESSAGE, e.what(), executionPackage.registerId); + logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, e.what(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; emit alertFinished(alertId, executionPackage.executionDate, false); @@ -770,8 +770,8 @@ void terrama2::services::alert::core::AlertExecutor::runAlert(terrama2::core::Ex catch(...) { QString errMsg = QObject::tr("Unknown exception"); - logger->result(AlertLogger::ERROR, nullptr, executionPackage.registerId); - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(AlertLogger::Status::ERROR, nullptr, executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; emit alertFinished(alertId, executionPackage.executionDate, false); @@ -869,7 +869,7 @@ te::core::URI terrama2::services::alert::core::AlertExecutor::makeDocument(Repor errMsg.append(msg); } - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; } @@ -888,7 +888,7 @@ void terrama2::services::alert::core::AlertExecutor::sendNotification(const std: if(serverMap.empty()) { QString errMsg("No message server configured"); - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; } else @@ -907,7 +907,7 @@ void terrama2::services::alert::core::AlertExecutor::sendNotification(const std: errMsg.append(msg); } - logger->log(AlertLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->log(AlertLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); TERRAMA2_LOG_ERROR() << errMsg; } } diff --git a/src/terrama2/services/alert/core/Service.cpp b/src/terrama2/services/alert/core/Service.cpp index 4f41797e1..fdbfdf813 100644 --- a/src/terrama2/services/alert/core/Service.cpp +++ b/src/terrama2/services/alert/core/Service.cpp @@ -106,7 +106,7 @@ void terrama2::services::alert::core::Service::addToQueue(AlertId alertId, std:: else { waitQueue_[alertId].push(executionPackage); - logger_->result(AlertLogger::ON_QUEUE, nullptr, executionPackage.registerId); + logger_->result(AlertLogger::Status::ON_QUEUE, nullptr, executionPackage.registerId); TERRAMA2_LOG_INFO() << tr("Alert %1 added to wait queue.").arg(alertId); } } diff --git a/src/terrama2/services/analysis/core/AnalysisExecutor.cpp b/src/terrama2/services/analysis/core/AnalysisExecutor.cpp index 5ba73fac2..f1c5f041b 100644 --- a/src/terrama2/services/analysis/core/AnalysisExecutor.cpp +++ b/src/terrama2/services/analysis/core/AnalysisExecutor.cpp @@ -102,7 +102,7 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag { for(const std::string& message : messages) { - logger->log(AnalysisLogger::WARNING_MESSAGE, message, logId); + logger->log(AnalysisLogger::MessageType::WARNING_MESSAGE, message, logId); } } @@ -155,7 +155,7 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag { for (const auto& warning: warnings) { - logger->log(AnalysisLogger::WARNING_MESSAGE, warning, logId); + logger->log(AnalysisLogger::MessageType::WARNING_MESSAGE, warning, logId); } } @@ -168,13 +168,13 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag for(const auto& error : errors) { errorStr += error + "\n"; - logger->log(AnalysisLogger::ERROR_MESSAGE, error, logId); + logger->log(AnalysisLogger::MessageType::ERROR_MESSAGE, error, logId); } QString errMsg = QObject::tr("Analysis %1 (%2) finished with the following error(s):\n%3").arg(analysis->id).arg(QString::fromStdString(startTime->toString()), QString::fromStdString(errorStr)); TERRAMA2_LOG_INFO() << errMsg; - logger->result(AnalysisLogger::ERROR, startTime, logId); + logger->result(AnalysisLogger::Status::ERROR, startTime, logId); emit analysisFinished(analysis->id, startTime, false); } @@ -188,7 +188,7 @@ void terrama2::services::analysis::core::AnalysisExecutor::runAnalysis(DataManag logger->setStartProcessingTime(processingStartTime, executionPackage.registerId); logger->setEndProcessingTime(processingEndTime, executionPackage.registerId); - logger->result(AnalysisLogger::DONE, startTime, logId); + logger->result(AnalysisLogger::Status::DONE, startTime, logId); QString errMsg = QObject::tr("Analysis %1 finished successfully: %2").arg(analysis->id).arg(startTime->toString().c_str()); TERRAMA2_LOG_INFO() << errMsg; diff --git a/src/terrama2/services/analysis/core/Service.cpp b/src/terrama2/services/analysis/core/Service.cpp index 307b5221b..0934666b5 100644 --- a/src/terrama2/services/analysis/core/Service.cpp +++ b/src/terrama2/services/analysis/core/Service.cpp @@ -216,7 +216,7 @@ void terrama2::services::analysis::core::Service::addToQueue(AnalysisId analysis else { waitQueue_[analysisId].push(executionPackage); - logger_->result(AnalysisLogger::ON_QUEUE, nullptr, executionPackage.registerId); + logger_->result(AnalysisLogger::Status::ON_QUEUE, nullptr, executionPackage.registerId); TERRAMA2_LOG_INFO() << tr("Analysis %1 added to wait queue.").arg(analysisId); } } diff --git a/src/terrama2/services/collector/core/Service.cpp b/src/terrama2/services/collector/core/Service.cpp index cff08ee24..516a9f8fa 100644 --- a/src/terrama2/services/collector/core/Service.cpp +++ b/src/terrama2/services/collector/core/Service.cpp @@ -100,18 +100,14 @@ void terrama2::services::collector::core::Service::addToQueue(CollectorId collec { processQueue_.push_back(executionPackage); processingQueue_.push_back(collectorId); - - //wake loop thread - mainLoopCondition_.notify_one(); } else { waitQueue_[collectorId].push(executionPackage); - logger_->result(CollectorLogger::ON_QUEUE, nullptr, executionPackage.registerId); + logger_->result(CollectorLogger::Status::ON_QUEUE, nullptr, executionPackage.registerId); TERRAMA2_LOG_INFO() << tr("Collector %1 added to wait queue.").arg(collectorId); } - mainLoopCondition_.notify_one(); } catch(const terrama2::core::LogException&) @@ -150,7 +146,6 @@ void terrama2::services::collector::core::Service::collect(terrama2::core::Execu auto inputDataSeries = dataManager->findDataSeries(collectorPtr->inputDataSeries); auto inputDataProvider = dataManager->findDataProvider(inputDataSeries->dataProviderId); - TERRAMA2_LOG_DEBUG() << tr("Starting collection for data series '%1'").arg(inputDataSeries->name.c_str()); // output data @@ -182,7 +177,12 @@ void terrama2::services::collector::core::Service::collect(terrama2::core::Execu auto dataAccessor = terrama2::core::DataAccessorFactory::getInstance().make(inputDataProvider, inputDataSeries); std::shared_ptr lastDateTime; + auto status = CollectorLogger::ProcessLogger::Status::START; + ///////////////////////////////// + // + // begin processing + // dataAccessor->getSeriesCallback(filter, remover, [&](const DataSetId& datasetId, const std::string& uri) { try { @@ -190,23 +190,24 @@ void terrama2::services::collector::core::Service::collect(terrama2::core::Execu if(dataMap.empty()) { QString errMsg = tr("No data to collect."); - logger->result(CollectorLogger::WARNING, nullptr, executionPackage.registerId); - logger->log(CollectorLogger::WARNING_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->log(CollectorLogger::MessageType::WARNING_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(CollectorLogger::Status::WARNING, nullptr, executionPackage.registerId); TERRAMA2_LOG_WARNING() << errMsg; - notifyWaitQueue(executionPackage.processId); - sendProcessFinishedSignal(executionPackage.processId, executionPackage.executionDate, false); + // yellow status to the user + status = CollectorLogger::ProcessLogger::Status::WARNING; return; } + auto thisFileLastDateTime = dataAccessor->lastDateTime(); ///////////////////////////////////////////////////////////////////////// // data intersection - for(auto& item : dataMap) + // intersection + if(collectorPtr->intersection) { - // intersection - if(collectorPtr->intersection) + for(auto& item : dataMap) { //FIXME: the datamanager is being used outside the lock item.second = processIntersection(dataManager, collectorPtr->intersection, item.second, executionPackage.executionDate); @@ -225,95 +226,101 @@ void terrama2::services::collector::core::Service::collect(terrama2::core::Execu // if any exception happens, don't update the data timestamp if(thisFileLastDateTime && (!lastDateTime || (*thisFileLastDateTime > *lastDateTime))) lastDateTime = thisFileLastDateTime; + + status = CollectorLogger::ProcessLogger::Status::DONE; } catch(const terrama2::core::LogException& e) { + status = CollectorLogger::ProcessLogger::Status::ERROR; std::string errMsg = boost::get_error_info(e)->toStdString(); - if(executionPackage.registerId != 0 ) - { - TERRAMA2_LOG_ERROR() << errMsg << std::endl; - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); - } + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with a log exception.").arg(QString::fromStdString(outputDataSeries->name)); + TERRAMA2_LOG_ERROR() << errMsg; } catch(const terrama2::core::NoDataException& e) { - TERRAMA2_LOG_INFO() << tr("Collection finished but there was no data available for collector %1.").arg(executionPackage.processId); - + status = CollectorLogger::ProcessLogger::Status::WARNING; std::string errMsg = boost::get_error_info(e)->toStdString(); + TERRAMA2_LOG_INFO() << tr("No data available for collector %1.").arg(QString::fromStdString(outputDataSeries->name)); + if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::WARNING_MESSAGE, errMsg, executionPackage.registerId); - logger->result(CollectorLogger::WARNING, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::WARNING_MESSAGE, errMsg, executionPackage.registerId); + logger->result(CollectorLogger::Status::WARNING, nullptr, executionPackage.registerId); } - - QJsonObject jsonAnswer; - jsonAnswer.insert(terrama2::core::ReturnTags::AUTOMATIC, false); - sendProcessFinishedSignal(executionPackage.processId, executionPackage.executionDate, true, jsonAnswer); - notifyWaitQueue(executionPackage.processId); - return; } catch(const terrama2::Exception& e) { + status = CollectorLogger::ProcessLogger::Status::ERROR; QString errMsg = *boost::get_error_info(e); - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(QString::fromStdString(outputDataSeries->name)); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } } catch(const boost::exception& e) { + status = CollectorLogger::ProcessLogger::Status::ERROR; std::string errMsg = boost::diagnostic_information(e); TERRAMA2_LOG_ERROR() << errMsg; - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(QString::fromStdString(outputDataSeries->name)); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, errMsg, executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, errMsg, executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } } catch(const std::exception& e) { + status = CollectorLogger::ProcessLogger::Status::ERROR; TERRAMA2_LOG_ERROR() << e.what(); - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(QString::fromStdString(outputDataSeries->name)); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, e.what(), executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, e.what(), executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } } catch(...) { QString errMsg = tr("Unknown error."); TERRAMA2_LOG_ERROR() << errMsg; - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(QString::fromStdString(outputDataSeries->name)); + status = CollectorLogger::ProcessLogger::Status::ERROR; if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } - } }); + // + // end processing + // + ///////////////////////////////// - TERRAMA2_LOG_INFO() << tr("Data from collector %1 collected successfully.").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished successfully.").arg(QString::fromStdString(outputDataSeries->name)); auto processingEndTime = terrama2::core::TimeUtils::nowUTC(); + // log processing time logger->setStartProcessingTime(processingStartTime, executionPackage.registerId); logger->setEndProcessingTime(processingEndTime, executionPackage.registerId); - if(lastDateTime) - logger->result(CollectorLogger::DONE, lastDateTime, executionPackage.registerId); - else - logger->result(CollectorLogger::WARNING, lastDateTime, executionPackage.registerId); + logger->result(status, lastDateTime, executionPackage.registerId); + + QJsonObject jsonAnswer; + // only execute linked automatic process if finished successfully + jsonAnswer.insert(terrama2::core::ReturnTags::AUTOMATIC, status == CollectorLogger::ProcessLogger::Status::DONE); - sendProcessFinishedSignal(executionPackage.processId, executionPackage.executionDate, true); + auto success = (status == CollectorLogger::ProcessLogger::Status::DONE || status == CollectorLogger::ProcessLogger::Status::WARNING); + // notify process finished + sendProcessFinishedSignal(executionPackage.processId, executionPackage.executionDate, success, jsonAnswer); notifyWaitQueue(executionPackage.processId); return; } @@ -323,74 +330,69 @@ void terrama2::services::collector::core::Service::collect(terrama2::core::Execu if(executionPackage.registerId != 0 ) { TERRAMA2_LOG_ERROR() << errMsg << std::endl; - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(executionPackage.processId); } } catch(const terrama2::core::NoDataException& e) { - TERRAMA2_LOG_INFO() << tr("Collection finished but there was no data available for collector %1.").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished but there was no data available.").arg(executionPackage.processId); std::string errMsg = boost::get_error_info(e)->toStdString(); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::WARNING_MESSAGE, errMsg, executionPackage.registerId); - logger->result(CollectorLogger::DONE, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::WARNING_MESSAGE, errMsg, executionPackage.registerId); + logger->result(CollectorLogger::Status::DONE, nullptr, executionPackage.registerId); } - - QJsonObject jsonAnswer; - jsonAnswer.insert(terrama2::core::ReturnTags::AUTOMATIC, false); - sendProcessFinishedSignal(executionPackage.processId, executionPackage.executionDate, true, jsonAnswer); - notifyWaitQueue(executionPackage.processId); - return; } catch(const terrama2::Exception& e) { QString errMsg = *boost::get_error_info(e); - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(executionPackage.processId); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } } catch(const boost::exception& e) { std::string errMsg = boost::diagnostic_information(e); TERRAMA2_LOG_ERROR() << errMsg; - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(executionPackage.processId); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, errMsg, executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, errMsg, executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } } catch(const std::exception& e) { TERRAMA2_LOG_ERROR() << e.what(); - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(executionPackage.processId); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, e.what(), executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, e.what(), executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } } catch(...) { QString errMsg = tr("Unknown error."); TERRAMA2_LOG_ERROR() << errMsg; - TERRAMA2_LOG_INFO() << tr("Collection for collector %1 finished with error(s).").arg(executionPackage.processId); + TERRAMA2_LOG_INFO() << tr("Collector %1 finished with error(s).").arg(executionPackage.processId); if(executionPackage.registerId != 0) { - logger->log(CollectorLogger::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); - logger->result(CollectorLogger::ERROR, nullptr, executionPackage.registerId); + logger->log(CollectorLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), executionPackage.registerId); + logger->result(CollectorLogger::Status::ERROR, nullptr, executionPackage.registerId); } } + // if arrived here, always error sendProcessFinishedSignal(executionPackage.processId, executionPackage.executionDate, false); notifyWaitQueue(executionPackage.processId); } diff --git a/src/terrama2/services/view/core/Service.cpp b/src/terrama2/services/view/core/Service.cpp index acbaa1efd..80e61aa48 100644 --- a/src/terrama2/services/view/core/Service.cpp +++ b/src/terrama2/services/view/core/Service.cpp @@ -114,7 +114,7 @@ void terrama2::services::view::core::Service::addToQueue(ViewId viewId, std::sha else { waitQueue_[viewId].push(executionPackage); - logger_->result(ViewLogger::ON_QUEUE, nullptr, executionPackage.registerId); + logger_->result(ViewLogger::Status::ON_QUEUE, nullptr, executionPackage.registerId); TERRAMA2_LOG_INFO() << tr("View %1 added to wait queue.").arg(viewId); } @@ -282,7 +282,7 @@ void terrama2::services::view::core::Service::viewJob(const terrama2::core::Exec logger->setStartProcessingTime(processingStartTime, executionPackage.registerId); logger->setEndProcessingTime(processingEndTime, executionPackage.registerId); - logger->result(ViewLogger::DONE, terrama2::core::TimeUtils::nowUTC(), logId); + logger->result(ViewLogger::Status::DONE, terrama2::core::TimeUtils::nowUTC(), logId); jsonAnswer = mapsServerAnswer; jsonAnswer.insert("class", QString("RegisteredViews")); @@ -325,7 +325,7 @@ void terrama2::services::view::core::Service::viewJob(const terrama2::core::Exec TERRAMA2_LOG_INFO() << QObject::tr("Build of view %1(%2) finished with error(s).").arg(QString::fromStdString(viewName)).arg(viewId); if(logId != 0) - logger->log(ViewLogger::ERROR_MESSAGE, errMsg, logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errMsg, logId); } catch(const boost::exception& e) { @@ -343,7 +343,7 @@ void terrama2::services::view::core::Service::viewJob(const terrama2::core::Exec TERRAMA2_LOG_INFO() << QObject::tr("Build of view %1(%2) finished with error(s).").arg(QString::fromStdString(viewName)).arg(viewId); if(logId != 0) - logger->log(ViewLogger::ERROR_MESSAGE, errMsg, logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errMsg, logId); } catch(const std::exception& e) { @@ -352,7 +352,7 @@ void terrama2::services::view::core::Service::viewJob(const terrama2::core::Exec TERRAMA2_LOG_INFO() << QObject::tr("Build of view %1(%2) finished with error(s).").arg(QString::fromStdString(viewName)).arg(viewId); if(logId != 0) - logger->log(ViewLogger::ERROR_MESSAGE, errMsg, logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errMsg, logId); } catch(...) { @@ -361,11 +361,11 @@ void terrama2::services::view::core::Service::viewJob(const terrama2::core::Exec TERRAMA2_LOG_INFO() << QObject::tr("Build of view %1(%2) finished with error(s).").arg(QString::fromStdString(viewName)).arg(viewId); if(logId != 0) - logger->log(ViewLogger::ERROR_MESSAGE, errMsg, logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errMsg, logId); } if(logId != 0) - logger->result(ViewLogger::ERROR, terrama2::core::TimeUtils::nowUTC(), logId); + logger->result(ViewLogger::Status::ERROR, terrama2::core::TimeUtils::nowUTC(), logId); sendProcessFinishedSignal(viewId, executionPackage.executionDate, false); notifyWaitQueue(viewId); diff --git a/src/terrama2/services/view/core/data-access/Geoserver.cpp b/src/terrama2/services/view/core/data-access/Geoserver.cpp index 724f9cd6a..ec7327f34 100644 --- a/src/terrama2/services/view/core/data-access/Geoserver.cpp +++ b/src/terrama2/services/view/core/data-access/Geoserver.cpp @@ -104,7 +104,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co if(inputDataSeries->id != viewPtr->dataSeriesID) { QString errorMsg = QString("This View is not from this Data Series."); - logger->log(ViewLogger::ERROR_MESSAGE, errorMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errorMsg.toStdString(), logId); TERRAMA2_LOG_ERROR() << QObject::tr(errorMsg.toStdString().c_str()); throw ViewGeoserverException() << ErrorDescription(errorMsg); } @@ -114,7 +114,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co if(dataProviderType != "POSTGIS" && dataProviderType != "FILE") { QString errorMsg = QString("Data provider not supported: %1.").arg(dataProviderType.c_str()); - logger->log(ViewLogger::ERROR_MESSAGE, errorMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errorMsg.toStdString(), logId); TERRAMA2_LOG_ERROR() << QObject::tr(errorMsg.toStdString().c_str()); throw ViewGeoserverException() << ErrorDescription(errorMsg); } @@ -123,14 +123,14 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co if(dataFormat != "OGR" && dataFormat != "POSTGIS" && dataFormat != "GDAL") { QString errorMsg = QString("Data format not supported in the maps server: %1.").arg(dataFormat.c_str()); - logger->log(ViewLogger::ERROR_MESSAGE, errorMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errorMsg.toStdString(), logId); TERRAMA2_LOG_ERROR() << QObject::tr(errorMsg.toStdString().c_str()); throw ViewGeoserverException() << ErrorDescription(errorMsg); } if(inputDataSeries->datasetList.empty()) { - logger->log(ViewLogger::WARNING_MESSAGE, "No data to register.", logId); + logger->log(ViewLogger::MessageType::WARNING_MESSAGE, "No data to register.", logId); TERRAMA2_LOG_WARNING() << QObject::tr("No data to register in maps server."); return jsonAnswer; } @@ -208,7 +208,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co if(fileInfoList.empty()) { QString errorMsg = QString("No data in data series %1.").arg(inputDataSeries->id); - logger->log(ViewLogger::WARNING_MESSAGE, errorMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::WARNING_MESSAGE, errorMsg.toStdString(), logId); TERRAMA2_LOG_WARNING() << QObject::tr(errorMsg.toStdString().c_str()); continue; } @@ -225,7 +225,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co if(!dataSetType) { QString errorMsg = QString("Unable to access data series %1.").arg(inputDataSeries->id); - logger->log(ViewLogger::ERROR_MESSAGE, errorMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errorMsg.toStdString(), logId); TERRAMA2_LOG_ERROR() << QObject::tr(errorMsg.toStdString().c_str()); break; } @@ -329,7 +329,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co const auto& id = dataset->format.find("monitored_object_id"); if(id == dataset->format.end()) { - logger->log(ViewLogger::ERROR_MESSAGE, "Data to join not informed.", logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, "Data to join not informed.", logId); TERRAMA2_LOG_ERROR() << QObject::tr("Cannot join data from a different DB source!"); continue; } @@ -344,7 +344,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co || monitoredObjectUrl.path().section("/", 1, 1) != url.path().section("/", 1, 1)) { QString errMsg = QObject::tr("Cannot join data from a different DB source."); - logger->log(ViewLogger::ERROR_MESSAGE, errMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), logId); TERRAMA2_LOG_ERROR() << errMsg; continue; } @@ -352,7 +352,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co if(monitoredObjectDataSeries->datasetList.empty()) { QString errMsg = QObject::tr("No dataset found in dataseries: %1.").arg(QString::fromStdString(monitoredObjectDataSeries->name)); - logger->log(ViewLogger::ERROR_MESSAGE, errMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), logId); TERRAMA2_LOG_ERROR() << errMsg; continue; } @@ -371,7 +371,7 @@ QJsonObject terrama2::services::view::core::GeoServer::generateLayersInternal(co else { QString errMsg = QObject::tr("Invalid type of dataseries: %1.").arg(QString::fromStdString(monitoredObjectDataSeries->name)); - logger->log(ViewLogger::ERROR_MESSAGE, errMsg.toStdString(), logId); + logger->log(ViewLogger::MessageType::ERROR_MESSAGE, errMsg.toStdString(), logId); TERRAMA2_LOG_ERROR() << errMsg; continue; } @@ -1453,7 +1453,7 @@ void terrama2::services::view::core::GeoServer::cleanup(const ViewPtr& viewPtr, warningMessage += "\n -" + fileURI; } - logger->log(terrama2::core::ProcessLogger::WARNING_MESSAGE, warningMessage, id); + logger->log(terrama2::core::ProcessLogger::MessageType::WARNING_MESSAGE, warningMessage, id); } } } // endif !directory.currentPath().toStdString().empty() diff --git a/src/unittest/core/TsProcessLogger.cpp b/src/unittest/core/TsProcessLogger.cpp index 612c1b18e..5958394a9 100644 --- a/src/unittest/core/TsProcessLogger.cpp +++ b/src/unittest/core/TsProcessLogger.cpp @@ -61,14 +61,14 @@ void TsProcessLogger::testProcessLogger() log.logValue("tag2", "value2", registerID); log.logValue("tag1", "value3", registerID); log.logValue("tag2", "value4", registerID); - log.log(TestLogger::ERROR_MESSAGE, "Unit Test Error", registerID); - log.log(TestLogger::ERROR_MESSAGE, "Unit Test second Error", registerID); - log.log(TestLogger::INFO_MESSAGE, "Unit Test Info", registerID); - log.log(TestLogger::INFO_MESSAGE, "Unit Test seconde Info", registerID); + log.log(TestLogger::MessageType::ERROR_MESSAGE, "Unit Test Error", registerID); + log.log(TestLogger::MessageType::ERROR_MESSAGE, "Unit Test second Error", registerID); + log.log(TestLogger::MessageType::INFO_MESSAGE, "Unit Test Info", registerID); + log.log(TestLogger::MessageType::INFO_MESSAGE, "Unit Test seconde Info", registerID); std::shared_ptr< te::dt::TimeInstantTZ > dataTime = terrama2::core::TimeUtils::nowUTC(); - log.result(terrama2::core::ProcessLogger::ERROR, dataTime, registerID); + log.result(terrama2::core::ProcessLogger::Status::ERROR, dataTime, registerID); } catch(const terrama2::Exception& e) {