def __loadAdminData(self): self.debug("Loading admin data from '%s'", self._adminPath) loader = inifile.IniFile() adminData = dataprops.AdminData() loader.loadFromFile(adminData, self._adminPath) self._adminData = adminData basePath = os.path.dirname(self._adminPath) relDir = self._adminData.customersDir absPath = fileutils.makeAbsolute(relDir, basePath) absDir = fileutils.ensureAbsDirPath(absPath) self._customersDir = absDir fileutils.ensureDirExists(self._customersDir, "customers configuration") self.debug("Loading customers data from directory '%s'", absDir) self._customersData.clear() files = os.listdir(absDir) for f in files: if f.startswith(".") or not f.endswith('.ini'): self.log("Ignoring customer data file '%s'", f) continue self.log("Loading customer data file '%s'", f) data = dataprops.CustomerData() try: loader.loadFromFile(data, absDir + f) except Exception, e: log.notifyException(self, e, "Fail to load customer data " "from file '%s'", absDir + f) continue identifier = f.rsplit(os.path.extsep, 1)[0] self._customersData[identifier] = data
def __safeMove(self, sourceDir, destDir, file): try: shutil.move(sourceDir + file, destDir + file) except Exception, e: log.notifyException(self, e, "Fail to move file '%s' from '%s' to '%s'", file, sourceDir, destDir)
def __deleteFile(self, file): try: os.remove(file) except Exception, e: log.notifyException(self._source, e, "Fail to delete file '%s'", file) raise e
def __moveFile(self, sourceFile, destFile): try: shutil.move(sourceFile, destFile) except Exception, e: log.notifyException(self._source, e, "Fail to move file from '%s' to '%s'", sourceFile, destFile) raise e
def _doExtractProperties(self, workerCtx, state): conf = state.get("config") assert conf != None, "Component state without config dict" props = conf.get("properties") assert props != None, "Component state without porperty dict" try: return self.properties_factory.createFromComponentDict(workerCtx, props) except Exception, e: log.notifyException(self, e, "Exception during component '%s' " "properties creation", self.label) return None
def _componentStateAppend(self, state, key, value): try: if key == 'messages': if value.id in self._messageIds: return self._messageIds[value.id] = None self._onComponentMessage(value) except Exception, e: log.notifyException(self, e, "Exception when appening value '%s' " "to component '%s' state list '%s'", value, self.label, key)
def _transcoderPreparedCallback(self, transcoder, pipeline): try: #FIXME: Don't reference the global context context = self._context for transTarget in transcoder.getProducers(): targetCtx = transTarget.getContext() info = transTarget.getPipelineInfo() targetCtx.reporter.updatePipelineInfo(info) self._fireSyncReport() except Exception, e: log.notifyException(context, e, "Exception during " "transcoder initialization reporting")
def __cbJobTerminated(self, result): try: report = self._report self.__syncReport(report) self.__terminate(report, self._status) # Acknowledge return the transcoding status return self._status except Exception, e: log.notifyException(self, e, "Unexpected exception", cleanTraceback=True) self.__unexpectedError() # Reraise for the do_acknowledge call to return the failure raise e
def __cbJobDone(self, report): try: assert report == self._report, ("Job creates it's own report " + "instance. It's Baaaaad.") # FIXME: Very ugly, should not ask the job for this self._reportDefaultPath = self._job.getDoneReportPath() self.__syncReport(report) self.__deleteTempReport() self._fireStatusChanged(TranscoderStatusEnum.done) self.__finalize(report, True) except Exception, e: log.notifyException(self, e, "Unexpected exception", cleanTraceback=True) self.__unexpectedError()
def _transcoderPlayingCallback(self, transcoder, pipeline): try: #FIXME: Don't reference the global context context = self._context targetsBins = {} for transTarget in transcoder.getProducers(): targetCtx = transTarget.getContext() bins = transTarget.getBins() if len(bins) > 0: targetsBins[targetCtx.key] = bins context.reporter.crawlPipeline(pipeline, targetsBins) self._fireSyncReport() except Exception, e: log.notifyException(context, e, "Exception during pipeline reporting")
def __loadActivityData(self): basePath = os.path.dirname(self._adminPath) relDir = self._adminData.activitiesDir absPath = fileutils.makeAbsolute(relDir, basePath) absDir = fileutils.ensureAbsDirPath(absPath) self._activeActivitiesDir = absDir self._failedActivitiesDir = fileutils.ensureAbsDirPath(absDir + "failed") self._doneActivitiesDir = fileutils.ensureAbsDirPath(absDir + "done") self._invalidActivitiesDir = fileutils.ensureAbsDirPath(absDir + "invalid") fileutils.ensureDirExists(self._activeActivitiesDir, "activities data base") fileutils.ensureDirExists(self._failedActivitiesDir, "failed activities") fileutils.ensureDirExists(self._doneActivitiesDir, "done activities") fileutils.ensureDirExists(self._invalidActivitiesDir, "invalid activities") self.debug("Loading activities data from directory '%s'", absDir) loader = inifile.IniFile() self._activitiesData.clear() files = os.listdir(absDir) for f in files: if not f.endswith('.ini'): self.log("Ignoring activity data file '%s'", f) continue if f.startswith("transcoding-"): data = dataprops.TranscodingActivityData() elif f.startswith("notification-"): data = dataprops.NotificationActivityData() else: self.log("Ignoring activity data file '%s'", f) continue self.log("Loading activity data file '%s'", f) try: loader.loadFromFile(data, absDir + f) except Exception, e: log.notifyException(self, e, "Fail to load activity data " "from file '%s'", absDir + f) self.__safeMove(absDir, self._invalidActivitiesDir, f) continue if data.state == ActivityStateEnum.done: self.__safeMove(absDir, self._doneActivitiesDir, f) elif data.state == ActivityStateEnum.failed: self.__safeMove(absDir, self._failedActivitiesDir, f) else: self._activitiesData[f] = (absDir + f, data)
def _componentStateSet(self, state, key, value): self.log("Component '%s' state '%s' set to '%s'", self.label, key, value) try: if key == 'mood': if self.isActive(): self.__componentMoodChanged(value) elif key == 'workerName': self.__componentActiveWorkerChanged(value) elif key == 'workerRequested': self.__componentRequestedWorkerChanged(value) elif key == 'pid': self._pid = value except Exception, e: log.notifyException(self, e, "Exception when setting component '%s' " "state key '%s' to '%s'", self.label, key, value)
def __ebJobFailed(self, failure): try: report = self._report if not failure.check(FlumotionError): m = messages.Error(T_(failure.getErrorMessage()), debug=log.getFailureMessage(failure)) self.addMessage(m) # FIXME: Very ugly, should not ask the job for this self._reportDefaultPath = self._job.getFailedReportPath() self.__syncReport(report) self.__deleteTempReport() self._fireStatusChanged(TranscoderStatusEnum.failed) self.__finalize(report, False) except Exception, e: log.notifyException(self, e, "Unexpected exception", cleanTraceback=True) self.__unexpectedError()
def __ebAcknowledgeError(self, failure): try: self.warning("Transcoding acknowledge Error: %s", log.getFailureMessage(failure)) self._fireStatusChanged(TranscoderStatusEnum.failed) self.setMood(moods.sad) # FIXME: Very ugly, should not ask the job for this newReportPath = self._job.getFailedReportPath() if newReportPath != self._reportDefaultPath: self._reportDefaultPath = newReportPath self._fireTranscodingReport(self._reportDefaultPath) self.__syncReport(self._report) self.__terminate(self._report, self._status) return failure except Exception, e: log.notifyException(self, e, "Unexpected exception", cleanTraceback=True) self.__unexpectedError() # Reraise for the do_acknowledge call to return the failure raise e
def _store(self): # WARNING: This function is not generic, it's specific for activities # PyChecker doesn't like dynamic attributes __pychecker__ = "no-classattr" identifier = self._identifier or self.__newIdentifier() data = self._data or self._template['class']() newPath = self.__getPath(identifier, self.state) newTmpPath = newPath + ".tmp" for attr, value in self._fields.items(): if isinstance(value, list): l = getattr(data, attr) del l[:] for v in value: l.append(utils.deepCopy(v)) elif isinstance(value, dict): d = getattr(data, attr) d.clear() for k, v in value.items(): d[k] = utils.deepCopy(v) else: setattr(data, attr, utils.deepCopy(value)) try: fileutils.ensureDirExists(os.path.dirname(newTmpPath), "activities") saver = inifile.IniFile() # The activities can contains sensitive information (passwords) # so we don't want it to be readable by others oldmask = os.umask(0137) try: saver.saveToFile(data, newTmpPath) finally: os.umask(oldmask) except Exception, e: log.notifyException(self._source, e, "File to save activity data file '%s'", newPath) raise e