diff --git a/ChaosMetadataService/CMakeLists.txt b/ChaosMetadataService/CMakeLists.txt index a2a4500e313849b370e7018009c683c1245452c2..fdad4d2aa0a56c4b3f9da6d9b3d686d80e6d18cd 100644 --- a/ChaosMetadataService/CMakeLists.txt +++ b/ChaosMetadataService/CMakeLists.txt @@ -246,7 +246,7 @@ SET(api_src api/ApiManagement.cpp SET(api_src ${api_src} api/logging/LoggingApiGroup.cpp api/logging/SubmitEntry.cpp api/logging/SubmitEntryBase.cpp - + api/logging/DeleteLog.cpp api/logging/SearchLogEntry.cpp api/logging/GetLogForSourceUID.cpp api/logging/GetLogDomainForSourceUID.cpp) diff --git a/ChaosMetadataService/ChaosMetadataService.cpp b/ChaosMetadataService/ChaosMetadataService.cpp index ee84ad2908bbeaf71c22949eec3d7f5f9cafa2b8..3c30cdec03328f0da5099e766275df8471e47051 100644 --- a/ChaosMetadataService/ChaosMetadataService.cpp +++ b/ChaosMetadataService/ChaosMetadataService.cpp @@ -465,7 +465,7 @@ int ChaosMetadataService::removeStorageData(const std::string& control_unit_foun } log(CHAOS_FORMAT("Remove log for cu %1%", % control_unit_found)); - if ((err = DriverPoolManager::getInstance()->getPersistenceDataAccess<persistence::data_access::LoggingDataAccess>()->eraseLogBeforTS(control_unit_found, + if ((err = DriverPoolManager::getInstance()->getPersistenceDataAccess<persistence::data_access::LoggingDataAccess>()->eraseLogBeforTS(control_unit_found,"", remove_until_ts))) { log(CHAOS_FORMAT("Error erasing logging for control unit %1% with error %2%", % control_unit_found % err)); } diff --git a/ChaosMetadataService/api/logging/DeleteLog.cpp b/ChaosMetadataService/api/logging/DeleteLog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0867788a02a840ba6ddd18c1418d9b79833dc7fe --- /dev/null +++ b/ChaosMetadataService/api/logging/DeleteLog.cpp @@ -0,0 +1,72 @@ +/* + * Copyright 2023 INFN + * + * Andrea Michelotti + * Licensed under the EUPL, Version 1.2 or – as soon they + * will be approved by the European Commission - subsequent + * versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the + * Licence. + * You may obtain a copy of the Licence at: + * + * https://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in + * writing, software distributed under the Licence is + * distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the Licence for the specific language governing + * permissions and limitations under the Licence. + */ + +#include "DeleteLog.h" + +#include <chaos/common/network/NetworkBroker.h> + +using namespace chaos::metadata_service::api::logging; + +#define L_SE_INFO INFO_LOG(DeleteLog) +#define L_SE_DBG DBG_LOG(DeleteLog) +#define L_SE_ERR ERR_LOG(DeleteLog) + +using namespace chaos::common::data; +using namespace chaos::common::network; +using namespace chaos::common::event::channel; +using namespace chaos::metadata_service::api::logging; +using namespace chaos::metadata_service::persistence::data_access; + +CHAOS_MDS_DEFINE_API_CLASS_CD(DeleteLog, "deleteLog") + + + +CDWUniquePtr DeleteLog::execute(CDWUniquePtr api_data) { + int err = 0; + GET_DATA_ACCESS(LoggingDataAccess, l_da, -4); + + //check for mandatory attributes + CHECK_CDW_THROW_AND_LOG(api_data, L_SE_ERR, -1, "No parameter found"); + CHECK_KEY_THROW_AND_LOG(api_data, MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER, L_SE_ERR, -2, "The log timestamp key is mandatory:"+api_data->getJSONString()); + CHAOS_LASSERT_EXCEPTION(api_data->isStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER), L_SE_ERR, -3, "The log timestamp key needs to be a string value"); + CHECK_KEY_THROW_AND_LOG(api_data, MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_TIMESTAMP, L_SE_ERR, -4, "The log timestamp key is mandatory:"+api_data->getJSONString()); + CHAOS_LASSERT_EXCEPTION(api_data->isInt64Value(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_TIMESTAMP), L_SE_ERR, -5, "The log timestamp key needs to be an int64 value"); + CHECK_KEY_THROW_AND_LOG(api_data, MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_DOMAIN, L_SE_ERR, -6, "The log domain key is mandatory:"+api_data->getJSONString()); + CHAOS_LASSERT_EXCEPTION(api_data->isStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_DOMAIN), L_SE_ERR, -7, "The log domain needs to be a string"); + + + //crete entry + LogEntry new_log_entry; + new_log_entry.source_identifier = api_data->getStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER); + new_log_entry.ts = api_data->getUInt64Value(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_TIMESTAMP); + new_log_entry.domain = api_data->getStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_DOMAIN); + //compelte log antry with log channel custom key + + //insert the log entry + if((err = l_da->eraseLogBeforTS(new_log_entry.source_identifier,new_log_entry.domain,new_log_entry.ts))){ + LOG_AND_TROW(L_SE_ERR, -9, "Error erasing log :"+api_data->getJSONString()); + } + + + return NULL; +} + diff --git a/ChaosMetadataService/api/logging/DeleteLog.h b/ChaosMetadataService/api/logging/DeleteLog.h new file mode 100644 index 0000000000000000000000000000000000000000..55fe14a992cbafb8668ea72b47cc38bd959852af --- /dev/null +++ b/ChaosMetadataService/api/logging/DeleteLog.h @@ -0,0 +1,43 @@ +/* + * Copyright 2023 INFN + * + * Andrea Michelotti + * Licensed under the EUPL, Version 1.2 or – as soon they + * will be approved by the European Commission - subsequent + * versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the + * Licence. + * You may obtain a copy of the Licence at: + * + * https://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in + * writing, software distributed under the Licence is + * distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the Licence for the specific language governing + * permissions and limitations under the Licence. + */ + +#ifndef __CHAOSFramework__DeleteLog_h +#define __CHAOSFramework__DeleteLog_h + +#include "../AbstractApi.h" + +#include <chaos/common/event/event.h> + +namespace chaos { + namespace metadata_service { + namespace api { + namespace logging { + + + CHAOS_MDS_DEFINE_API_CLASS(DeleteLog) + + } + } + } +} + +#endif /* __CHAOSFramework__DeleteLog_h */ diff --git a/ChaosMetadataService/api/logging/LoggingApiGroup.cpp b/ChaosMetadataService/api/logging/LoggingApiGroup.cpp index b44cf32ce8269d7689a4814629c76f1b8126f20e..1882f19ad712cd7e39b116bbde4cf84baa1c9676 100644 --- a/ChaosMetadataService/api/logging/LoggingApiGroup.cpp +++ b/ChaosMetadataService/api/logging/LoggingApiGroup.cpp @@ -24,6 +24,7 @@ #include "SearchLogEntry.h" #include "GetLogForSourceUID.h" #include "GetLogDomainForSourceUID.h" +#include "DeleteLog.h" using namespace chaos::metadata_service::api::logging; @@ -36,6 +37,8 @@ AbstractApiGroup(MetadataServerLoggingDefinitionKeyRPC::ACTION_NODE_LOGGING_RPC_ addApi<SearchLogEntry>(); addApi<GetLogForSourceUID>(); addApi<GetLogDomainForSourceUID>(); + addApi<DeleteLog>(); + } LoggingApiGroup::~LoggingApiGroup() {} diff --git a/ChaosMetadataService/persistence/data_access/LoggingDataAccess.h b/ChaosMetadataService/persistence/data_access/LoggingDataAccess.h index 288323f315aac9407f25d38e16ecd1b47f2974a1..e13255528a1b3d43ee62c87206c5ab0e70a120d9 100644 --- a/ChaosMetadataService/persistence/data_access/LoggingDataAccess.h +++ b/ChaosMetadataService/persistence/data_access/LoggingDataAccess.h @@ -135,8 +135,8 @@ namespace chaos { const LogSourceList& source_uids) = 0; //! remove all log for belog to the source id - virtual int eraseLogBeforTS(const std::string& source_uid, - uint64_t unit_ts) = 0; + virtual int eraseLogBeforTS(const std::string& source_uid="",const std::string& type_id="", + uint64_t unit_ts=0) = 0; }; } } diff --git a/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.cpp b/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.cpp index ef1d36ab14542242ecd2241eae18b4d57d341be4..2ae33a096bf4814d47bbe6d710999c7a6b32a30e 100644 --- a/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.cpp +++ b/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.cpp @@ -372,12 +372,27 @@ int MongoDBLoggingDataAccess::getLogDomainsForSource(LogDomainList& entry_list, return err; } -int MongoDBLoggingDataAccess::eraseLogBeforTS(const std::string& source_uid, +int MongoDBLoggingDataAccess::eraseLogBeforTS(const std::string& source_uid,const std::string& log_type, uint64_t unit_ts) { int err = 0; try { - mongo::BSONObj query = BSON(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER << source_uid << - MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_TIMESTAMP << BSON( "$lte" << mongo::Date_t(unit_ts))); + mongo::BSONObjBuilder builder; + mongo::BSONArrayBuilder bson_find_token_or; + + if(source_uid.size()){ + std::string token_for_mongo = source_uid+".*"; + builder<<MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER << BSON("$regex" << token_for_mongo<<"$options"<<"i"); + // builder<<MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER<<source_uid; + } + + if(log_type.size()){ + builder<<MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_DOMAIN<<log_type; + + } + if(unit_ts>0){ + builder<<MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_TIMESTAMP << BSON( "$lte" << mongo::Date_t(unit_ts)); + } + mongo::BSONObj query = builder.obj(); DEBUG_CODE(MDBLDA_DBG<<log_message("eraseLog", "erase", diff --git a/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.h b/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.h index 825307407c395056189299bd699d326fc2555252..7c895df649737d071704e1f275c6e6d156cdea51 100644 --- a/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.h +++ b/ChaosMetadataService/persistence/mongodb/MongoDBLoggingDataAccess.h @@ -77,8 +77,9 @@ namespace chaos { const data_access::LogSourceList& source_uids); //!inherited method - int eraseLogBeforTS(const std::string& source_uid, - uint64_t unit_ts); + int eraseLogBeforTS(const std::string& source_uid="",const std::string& log_type="", + uint64_t unit_ts=0); + }; } } diff --git a/chaos_metadata_service_client/CMakeLists.txt b/chaos_metadata_service_client/CMakeLists.txt index 690a9034ceda3e87a82528bf302a54cf764b4cc0..28a3ee024493beb290a390412c49a2cde4b7e94d 100644 --- a/chaos_metadata_service_client/CMakeLists.txt +++ b/chaos_metadata_service_client/CMakeLists.txt @@ -38,6 +38,7 @@ SET(mcl_src ${mcl_src} event/alert/AlertEventHandler.cpp event/alert/AlertAgentCheckProcessHandler.cpp) SET(mcl_src ${mcl_src} api_proxy/logging/SearchLogEntry.cpp + api_proxy/logging/DeleteLog.cpp api_proxy/logging/GetLogForSourceUID.cpp api_proxy/logging/GetLogDomainForSourceUID.cpp) diff --git a/chaos_metadata_service_client/api_proxy/logging/DeleteLog.cpp b/chaos_metadata_service_client/api_proxy/logging/DeleteLog.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b857c799eb7e23b83946290aaf5f6cb626c5e7b1 --- /dev/null +++ b/chaos_metadata_service_client/api_proxy/logging/DeleteLog.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2012, 2017 INFN + * + * Licensed under the EUPL, Version 1.2 or – as soon they + * will be approved by the European Commission - subsequent + * versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the + * Licence. + * You may obtain a copy of the Licence at: + * + * https://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in + * writing, software distributed under the Licence is + * distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the Licence for the specific language governing + * permissions and limitations under the Licence. + */ + +#include <chaos_metadata_service_client/api_proxy/logging/DeleteLog.h> +#include <chaos/common/message/MultiAddressMessageRequestFuture.h> +using namespace chaos; +using namespace chaos::common::data; +using namespace chaos::metadata_service_client::api_proxy; +using namespace chaos::metadata_service_client::api_proxy::logging; + +API_PROXY_CD_DEFINITION(DeleteLog, + MetadataServerLoggingDefinitionKeyRPC::ACTION_NODE_LOGGING_RPC_DOMAIN, + "deleteLog") + +ApiProxyResult DeleteLog::execute(const std::string& search_string, + const std::string& domain_list, + const uint64_t start_ts) { + CDWUniquePtr pack(new CDataWrapper()); + pack->addStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER, search_string); + pack->addStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_DOMAIN, domain_list); + pack->addInt64Value(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_TIMESTAMP, start_ts); + + + return callApi(pack); +} + diff --git a/chaos_metadata_service_client/api_proxy/logging/DeleteLog.h b/chaos_metadata_service_client/api_proxy/logging/DeleteLog.h new file mode 100644 index 0000000000000000000000000000000000000000..1b1f07c5cfd1a1779f28002b80ac541e6ede05ea --- /dev/null +++ b/chaos_metadata_service_client/api_proxy/logging/DeleteLog.h @@ -0,0 +1,63 @@ +/* + * Copyright 2012, 2017 INFN + * + * Licensed under the EUPL, Version 1.2 or – as soon they + * will be approved by the European Commission - subsequent + * versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the + * Licence. + * You may obtain a copy of the Licence at: + * + * https://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in + * writing, software distributed under the Licence is + * distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. + * See the Licence for the specific language governing + * permissions and limitations under the Licence. + */ + +#ifndef __CHAOSFramework__DeleteLog_h +#define __CHAOSFramework__DeleteLog_h + + +#include <chaos_metadata_service_client/api_proxy/ApiProxy.h> +#include <chaos_metadata_service_client/api_proxy/logging/logging_types.h> +#include <chaos_metadata_service_client/api_proxy/logging/GetLogForSourceUID.h> + +#include <chaos/common/chaos_types.h> + +namespace chaos { + namespace metadata_service_client { + namespace api_proxy { + namespace logging { + + + //! get log entries for a source + class DeleteLog: + public chaos::metadata_service_client::api_proxy::ApiProxy { + API_PROXY_CLASS(DeleteLog) + protected: + API_PROXY_CD_DECLARATION(DeleteLog) + public: + + //! Perform an advanced search specifind also the range of ts + /*! + \param search_string is the string that is search with a 'like' procedure in all fields + \param domain is the lis tof domain to wich need to belog the result entry + \param start_ts if > 0 is used has start timestamp + \param end_ts if > 0 is used as end timestamp + \param last_sequence_id is the id of the last returned entries in the past query + \param page_length is the length of the returned element + */ + ApiProxyResult execute(const std::string& uid,const std::string& dom, + const uint64_t start_ts); + }; + } + } + } +} + +#endif /* __CHAOSFramework__DeleteLog_h */ diff --git a/chaos_metadata_service_client/api_proxy/logging/logging.h b/chaos_metadata_service_client/api_proxy/logging/logging.h index e94f976fc63ce409164aa727847db1a63b8f380f..a3edff0a36db82e93e76b0111fd28f47fb33be96 100644 --- a/chaos_metadata_service_client/api_proxy/logging/logging.h +++ b/chaos_metadata_service_client/api_proxy/logging/logging.h @@ -25,5 +25,6 @@ #include <chaos_metadata_service_client/api_proxy/logging/SearchLogEntry.h> #include <chaos_metadata_service_client/api_proxy/logging/GetLogForSourceUID.h> #include <chaos_metadata_service_client/api_proxy/logging/GetLogDomainForSourceUID.h> +#include <chaos_metadata_service_client/api_proxy/logging/DeleteLog.h> #endif /* __CHAOSFramework__DB96A43_83ED_4C1F_8BA5_9B41D053D5CA_logging_h */ diff --git a/chaos_service_common/ChaosManager.cpp b/chaos_service_common/ChaosManager.cpp index bf154321b75e2a10e1ec683df87501e10e3065b0..ed3dd8d46997007384755988e935421ffbc91a5a 100644 --- a/chaos_service_common/ChaosManager.cpp +++ b/chaos_service_common/ChaosManager.cpp @@ -62,6 +62,8 @@ #include <ChaosMetadataService/api/service/SetVariable.h> #include <ChaosMetadataService/api/logging/SearchLogEntry.h> +#include <ChaosMetadataService/api/logging/DeleteLog.h> + #include <chaos_service_common/DriverPoolManager.h> using namespace chaos::common::cache_system; @@ -814,6 +816,21 @@ chaos::common::data::CDWUniquePtr ChaosManager::searchLogEntry(const std::string return res; } +chaos::common::data::CDWUniquePtr ChaosManager::deleteLog(const std::string& uid,const std::string& domains,uint64_t to){ + CDWUniquePtr res; + if (persistence_driver) { + DeleteLog node; + CALC_EXEC_START; + ChaosUniquePtr<chaos::common::data::CDataWrapper> pack(new CDataWrapper()); + pack->addStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_SOURCE_IDENTIFIER, uid); + pack->addInt64Value(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_TIMESTAMP, to); + pack->addStringValue(MetadataServerLoggingDefinitionKeyRPC::PARAM_NODE_LOGGING_LOG_DOMAIN, domains); + res = node.execute(MOVE(pack)); + CALC_EXEC_END + } + return res; +} + chaos::common::data::CDWUniquePtr ChaosManager::initDeinit(const std::string& uid, bool ini) { CDWUniquePtr res; if (persistence_driver) { diff --git a/chaos_service_common/ChaosManager.h b/chaos_service_common/ChaosManager.h index 6195f7e6ecfb2851711046e6ec15affedddad0ef..14b68f42dbc7a44ffdb24fcdb661a77c643d87ae 100644 --- a/chaos_service_common/ChaosManager.h +++ b/chaos_service_common/ChaosManager.h @@ -102,6 +102,8 @@ chaos::common::data::CDWUniquePtr startStop(const std::string& uid,bool start); chaos::common::data::CDWUniquePtr initDeinit(const std::string& uid,bool ini); chaos::common::data::CDWUniquePtr loadUnloadControlUnit(const std::string& uid,bool ini); chaos::common::data::CDWUniquePtr searchLogEntry(const std::string& uid,const std::vector<std::string>& domains,uint64_t start,uint64_t end,uint64_t seq,uint32_t page,int sort=-1); +chaos::common::data::CDWUniquePtr deleteLog(const std::string& uid,const std::string& domains,uint64_t to); + chaos::common::data::CDWUniquePtr searchScript(const std::string& uid,uint64_t start,uint32_t page); chaos::common::data::CDWUniquePtr saveScript(const chaos::common::data::CDataWrapper& value);