def _executeInternal(self): from common import SystemStatusManager SystemStatusManager.setKafkaComponentStatus(MediationStatusProducer.name, MediationStatusProducer.instance().status, AppConfig.getCurrentTime()) SystemStatusManager.setKafkaComponentStatus(MediationDataConsumer.name, MediationDataConsumer.instance().status, AppConfig.getCurrentTime())
def run(self): try: while True: job = self.queue.get_nowait() FlowAnalyzer(job).run(AppConfig.getCurrentTime()) except Exception as e: pass
def _setStatusMetadata(self, flowStatus, flow): ticTime = flowStatus["ticTime"] if not flow["options"]["enabled"]: return {"status": status.DISABLED} granDelta = datetime.timedelta( minutes=flow["options"]["granularity"] + 3 ) # set as N_A after it has not been analyzed for more than 3 minutes than it should have if ticTime + 2 * granDelta < AppConfig.getCurrentTime(): return {"status": status.NA} return flowStatus
def shouldSchedule(self, flow): granularity = flow["options"]["granularity"] lastExecution = self.lastExecutions[flow["gName"]] if lastExecution["status"] == status.NA: return True lastTicTime = lastExecution["ticTime"] if lastTicTime < AppConfig.getCurrentTime() - datetime.timedelta(minutes=2 * granularity): return True else: return False
def sendEmail(self, component, body): emailConfig = IntegrationConfig.getEmailConfig() if emailConfig is None: return if not self.canSendEmail(component): return msg = MIMEText(body + "\ntime:" + util.dateToTimeString(AppConfig.getCurrentTime()) + "\ncomponent:" + component) msg['Subject'] = 'Mediation monitoring: ' + component msg['From'] = emailConfig["from"] msg['To'] = emailConfig["to"] s = smtplib.SMTP(emailConfig["smtpHostname"]) s.login(emailConfig["login"], emailConfig["password"]) s.send_message(msg) self.lastComponentEmailTime[component] = AppConfig.getCurrentTime() s.quit()
def execute(self): try: logging.debug(" Running " + self.name + " on thread " + str(threading.get_ident())) self._executeInternal() from common import SystemStatusManager SystemStatusManager.saveExecutorSuccessfulExecution( self.name, AppConfig.getCurrentTime()) except Exception as e: logging.exception("Executing failed.") return
def logStatusChangeEvent(flow, message, ticTime, newStatus): currentTime = AppConfig.getCurrentTime() obj = { "flowName": flow["name"], "lobName": flow["lobName"], "country": flow["country"], "time": currentTime, "message": message, "newStatus": newStatus, "ticTime": ticTime } logging.debug("flow: " + flow["gName"] + " message:" + message) mongo.events().insert_one(obj)
def _analyzeFlow(self, flow, lastExecution): analyzer = FlowAnalyzer(flow) analyzer.run(AppConfig.getCurrentTime()) previousStatus = lastExecution["status"] newStatus = analyzer.status self.statusManager.saveStatus(flow, previousStatus, newStatus, analyzer.difference, analyzer.ticTime)
def __init__(self): super().__init__(DiscoverFlowsExecutor.name, DiscoverFlowsExecutor.interval) self.toDate = AppConfig.getCurrentTime() self.fromDate = self.toDate - datetime.timedelta(days=7)
def canSendEmail(self, component): lastTime = self.lastComponentEmailTime.get(component, None) if lastTime is None: return True return AppConfig.getCurrentTime() - lastTime > MIN_DELAY
def _statusIsExpired(time, maxSeconds=60 * 5): return AppConfig.getCurrentTime() - time > datetime.timedelta(seconds=maxSeconds)
def _executeInternal(self): clusterStatus = self.analyzer.run() self.checkStatusChange(StatusManager.getClusterStatus(), clusterStatus) StatusManager.saveClusterStatus(clusterStatus, AppConfig.getCurrentTime())
def currentTime(): return jsonify( {"currentTime": util.dateToTimeString(AppConfig.getCurrentTime())})