bool CWsLoggingServiceEx::onGetTransactionSeed(IEspContext& context, IEspGetTransactionSeedRequest& req, IEspGetTransactionSeedResponse& resp) { bool bRet = false; try { if (!context.validateFeatureAccess(WSLOGGING_ACCESS, SecAccess_Write, false)) throw MakeStringException(EspLoggingErrors::WSLoggingAccessDenied, "Failed to get transaction seed. Permission denied."); LOGServiceType serviceType = LGSTGetTransactionSeed; for (unsigned int x = 0; x < loggingAgentThreads.size(); x++) { IUpdateLogThread* loggingThread = loggingAgentThreads[x]; if (!loggingThread->hasService(serviceType)) continue; IEspLogAgent* loggingAgent = loggingThread->getLogAgent(); bRet = loggingAgent->getTransactionSeed(req, resp); break; } } catch (IException* e) { StringBuffer errorStr; e->errorMessage(errorStr); errorStr.insert(0, "Failed to get Transaction Seed: "); ERRLOG("%s", errorStr.str()); resp.setStatusCode(-1); resp.setStatusMessage(errorStr.str()); e->Release(); } return bRet; }
bool CLoggingManager::getTransactionID(StringAttrMapping* transFields, StringBuffer& transactionID, StringBuffer& status) { if (!initialized) throw MakeStringException(-1,"LoggingManager not initialized"); try { for (unsigned int x = 0; x < loggingAgentThreads.size(); x++) { IUpdateLogThread* loggingThread = loggingAgentThreads[x]; if (!loggingThread->hasService(LGSTGetTransactionID)) continue; IEspLogAgent* loggingAgent = loggingThread->getLogAgent(); loggingAgent->getTransactionID(transFields, transactionID); if (!transactionID.isEmpty()) ESPLOG(LogMax, "Got TransactionID '%s'", transactionID.str()); return true; } } catch (IException* e) { e->errorMessage(status); e->Release(); } return false; }
//Called when Logging manager is created. Create logging agents based on settings bool CLoggingManager::init(IPropertyTree* cfg, const char* service) { if (!cfg) { ERRLOG(EspLoggingErrors::ConfigurationFileEntryError, "Logging Manager setting not found for %s", service); return false; } Owned<IPTreeIterator> loggingAgentSettings = cfg->getElements("LogAgent"); ForEach(*loggingAgentSettings) { IPropertyTree& loggingAgentTree = loggingAgentSettings->query(); const char* agentName = loggingAgentTree.queryProp("@name"); const char* agentType = loggingAgentTree.queryProp("@type"); const char* agentPlugin = loggingAgentTree.queryProp("@plugin"); if (!agentName || !*agentName || !agentPlugin || !*agentPlugin) continue; IEspLogAgent* loggingAgent = loadLoggingAgent(agentName, agentPlugin, service, cfg); if (!loggingAgent) { ERRLOG(-1, "Failed to create logging agent for %s", agentName); continue; } loggingAgent->init(agentName, agentType, &loggingAgentTree, service); IUpdateLogThread* logThread = createUpdateLogThread(&loggingAgentTree, service, agentName, loggingAgent); if(!logThread) throw MakeStringException(-1, "Failed to create update log thread for %s", agentName); loggingAgentThreads.push_back(logThread); } initialized = true; return !loggingAgentThreads.empty(); }
bool CLoggingManager::getTransactionSeed(IEspGetTransactionSeedRequest& req, IEspGetTransactionSeedResponse& resp) { if (!initialized) throw MakeStringException(-1,"LoggingManager not initialized"); bool bRet = false; try { for (unsigned int x = 0; x < loggingAgentThreads.size(); x++) { IUpdateLogThread* loggingThread = loggingAgentThreads[x]; if (!loggingThread->hasService(LGSTGetTransactionSeed)) continue; IEspLogAgent* loggingAgent = loggingThread->getLogAgent(); bRet = loggingAgent->getTransactionSeed(req, resp); if (bRet) break; } } catch (IException* e) { StringBuffer errorStr; e->errorMessage(errorStr); ERRLOG("Failed to get Transaction Seed: %s",errorStr.str()); resp.setStatusCode(-1); resp.setStatusMessage(errorStr.str()); e->Release(); } return bRet; }
bool CWsLoggingServiceEx::init(const char* service, const char* type, IPropertyTree* cfg, const char* process) { VStringBuffer xpath("Software/EspProcess[@name=\"%s\"]/EspService[@name=\"%s\"]", process, service); Owned<IPropertyTree> pServiceNode = cfg->getPropTree(xpath.str()); if (!pServiceNode) throw MakeStringException(-1, "No settings found for service %s", service); Owned<IPropertyTreeIterator> logAgents = pServiceNode->getElements("LogAgent"); if (!logAgents) throw MakeStringException(-1, "No logAgent is defined for service %s", service); ForEach(*logAgents) { IPropertyTree& ptree = logAgents->query(); const char* agentName = ptree.queryProp("@name"); const char* agentType = ptree.queryProp("@type"); const char* agentPlugin = ptree.queryProp("@plugin"); if (!agentName || !*agentName || !agentPlugin || !*agentPlugin) continue; IEspLogAgent* logAgent = loadLoggingAgent(agentName, agentPlugin); if (!logAgent) { ERRLOG(-1, "Failed to create logging agent for %s", agentName); continue; } logAgent->init(agentName, agentType, &ptree, process); IUpdateLogThread* logThread = createUpdateLogThread(&ptree, service, agentName, logAgent); if(!logThread) throw MakeStringException(-1, "Failed to create update log thread for %s", agentName); loggingAgentThreads.push_back(logThread); } return true; }