def perspective_workerCallRemote(self, workerName, methodName, *args, **kwargs): """ Call a remote method on the worker. This is used so that admin clients can call methods from the interface to the worker. @param workerName: the worker to call @type workerName: str @param methodName: Name of the method to call. Gets proxied to L{flumotion.worker.medium.WorkerMedium} 's remote_(methodName) @type methodName: str """ self.debug('AdminAvatar.workerCallRemote(%r, %r)' % ( workerName, methodName)) workerAvatar = self.vishnu.workerHeaven.getAvatar(workerName) # XXX: Maybe we need to a prefix, so we can limit what an admin # interface can call on a worker try: return workerAvatar.mindCallRemote(methodName, *args, **kwargs) except Exception, e: self.warning("exception on remote call: %s" % log.getExceptionMessage(e)) return failure.Failure(errors.RemoteMethodError(methodName, log.getExceptionMessage(e)))
def manager_connected(self, model): try: psd = model.callRemote('getPlanetState') yield psd planet = psd.result self.planet = planet #get running flows and components flows = planet.get('flows') if flows: flow = flows[0] for f in flows: if f.get('name') == 'default': self.default_flow = flow = f break self._components = flow.get('components') flow.addListener(self, append=self.flow_state_append, remove=self.flow_state_remove) for c in self._components: self.new_component(c) 'Get atmosphere components' atmosphere = planet.get('atmosphere') if atmosphere: self._components += atmosphere.get('components') self.planet.addListener(self, append=self.planet_state_append, remove=self.planet_state_remove) self.stomp_client.restart_statuses() except Exception, e: print log.getExceptionMessage(e)
def run(self): while self._running: sessions = self.plug._sessions.keys() for session in sessions: try: session.doServe() except Exception, e: log.warning("Error during async file serving: %s", log.getExceptionMessage(e)) try: session.doCopy() except Exception, e: log.warning("Error during file copy: %s", log.getExceptionMessage(e))
def _stopRecordingFull(self, handle, location, lastTstamp, delayedStop): sink = self.get_element('fdsink') if sink.get_state() == gst.STATE_NULL: sink.set_state(gst.STATE_READY) if handle: handle.flush() sink.emit('remove', handle.fileno()) self._recordingStopped(handle, location) handle = None if not delayedStop: self.uiState.set('filename', None) self.uiState.set('recording', False) try: size = formatting.formatStorage(os.stat(location).st_size) except EnvironmentError, e: self.debug("Failed to stat %s: %s", location, log.getExceptionMessage(e)) # catch File not found, permission denied, disk problems size = "unknown" # Limit number of entries on filelist, remove the oldest entry fl = self.uiState.get('filelist', otherwise=[]) if FILELIST_SIZE == len(fl): self.uiState.remove('filelist', fl[0]) self.uiState.append('filelist', (lastTstamp, location, size)) if not delayedStop and self._symlinkToLastRecording: self._updateSymlink(location, self._symlinkToLastRecording)
def scheduleRecordings(self, icalFile): self.uiState.set('has-schedule', True) self.debug('Parsing iCalendar file %s' % icalFile) from flumotion.component.base import scheduler try: self.icalScheduler = scheduler.ICalScheduler(icalFile) self.icalScheduler.subscribe(self.eventInstanceStarted, self.eventInstanceEnded) # FIXME: this should be handled through the subscription # handlers; for that, we should subscribe before the calendar # gets added cal = self.icalScheduler.getCalendar() eventInstances = cal.getActiveEventInstances() if eventInstances: instance = eventInstances[0] content = instance.event.content self.info('Event %s is in progress, start recording' % content) self._startFilenameTemplate = content self._startTime = instance.start self._recordAtStart = True else: self.info('No events in progress') self._recordAtStart = False self._updateNextPoints() except (ValueError, IndexError, KeyError), e: m = messages.Warning(T_( N_("Error parsing ical file %s, so not scheduling any" " events." % icalFile)), debug=log.getExceptionMessage(e), mid="error-parsing-ical") self.addMessage(m)
def _startCopying(self): self.log("Start copy session") # First ensure there is not already a temporary file self._removeTempFile() # Reserve cache space, may trigger a cache cleanup if not self._allocCacheSpace(): # No free space, proxying source file directly self._cancelSession() return self.plug.stats.onCopyStarted() # Then open a transient temporary files try: fd, transientPath = tempfile.mkstemp(".tmp", LOG_CATEGORY) self.log("Created transient file '%s'", transientPath) self._wTempFile = os.fdopen(fd, "wb") self.log("Opened temporary file for writing [fd %d]", self._wTempFile.fileno()) self._rTempFile = file(transientPath, "rb") self.log("Opened temporary file for reading [fd %d]", self._rTempFile.fileno()) except IOError, e: self.warning("Failed to open temporary file: %s", log.getExceptionMessage(e)) self._cancelSession() return
def writeConnection(): i = self.connectionInfo if not (i.authenticator.username and i.authenticator.password): self.log('not caching connection information') return s = ''.join([ '<connection>', '<host>%s</host>' % i.host, '<manager>%s</manager>' % self.planet.get('name'), '<port>%d</port>' % i.port, '<use_insecure>%d</use_insecure>' % ((not i.use_ssl) and 1 or 0), '<user>%s</user>' % i.authenticator.username, '<passwd>%s</passwd>' % i.authenticator.password, '</connection>' ]) import os from flumotion.common import python md5sum = python.md5(s).hexdigest() f = os.path.join(configure.registrydir, '%s.connection' % md5sum) try: h = open(f, 'w') h.write(s) h.close() except Exception, e: self.info('failed to write connection cache file %s: %s', f, log.getExceptionMessage(e))
def do_element_check(pipeline_str, element_name, check_proc, state=None, set_state_deferred=False): """ Parse the given pipeline and set it to the given state. When the bin reaches that state, perform the given check function on the element with the given name. @param pipeline_str: description of the pipeline used to test @param element_name: name of the element being checked @param check_proc: a function to call with the GstElement as argument. @param state: an unused keyword parameter that will be removed when support for GStreamer 0.8 is dropped. @param set_state_deferred: a flag to say whether the set_state is run in a deferToThread @type set_state_deferred: bool @returns: a deferred that will fire with the result of check_proc, or fail. @rtype: L{twisted.internet.defer.Deferred} """ def run_check(pipeline, resolution): element = pipeline.get_by_name(element_name) try: retval = check_proc(element) resolution.callback(retval) except check.CheckProcError, e: log.debug('check', 'CheckProcError when running %r: %r', check_proc, e.data) resolution.errback(errors.RemoteRunError(e.data)) except Exception, e: log.debug('check', 'Unhandled exception while running %r: %r', check_proc, e) resolution.errback(errors.RemoteRunError( log.getExceptionMessage(e)))
def haveWtree(wtree): self.wtree = wtree self.debug('render: calling haveWidgetTree') try: self.haveWidgetTree() except Exception, e: return error(log.getExceptionMessage(e))
def _closeSourceFile(self, sourceFile): self.log("Closing source file [fd %d]", sourceFile.fileno()) try: sourceFile.close() except Exception, e: self.warning("Failed to close source file: %s", log.getExceptionMessage(e))
def _onCopyFinished(self): if self._sourceFile is None: return # Called when the copy thread really stopped to read/write self.debug("Finished caching '%s' [fd %d]", self.sourcePath, self._sourceFile.fileno()) self.plug.stats.onCopyFinished(self.size) # Set the copy as finished to prevent the temporary file # to be deleted when closed self._copied = None # Closing source and write files self._closeSourceFile() self._closeWriteTempFile() # Setting the modification time on the temporary file try: mtime = self.mtime atime = int(time.time()) self.log("Setting temporary file modification time to %d", mtime) # FIXME: Should use futimes, but it's not wrapped by python os.utime(self.tempPath, (atime, mtime)) except OSError, e: if e.errno == errno.ENOENT: # The file may have been deleted by another process self._releaseCacheSpace() else: self.warning("Failed to update modification time of temporary " "file: %s", log.getExceptionMessage(e)) self._cancelSession()
def _onCopyFinished(self): if self._sourceFile is None: return # Called when the copy thread really stopped to read/write self.debug("Finished caching '%s' [fd %d]", self.sourcePath, self._sourceFile.fileno()) self.plug.stats.onCopyFinished(self.size) # Set the copy as finished to prevent the temporary file # to be deleted when closed self._copied = None # Closing source and write files self._closeSourceFile() self._closeWriteTempFile() # Setting the modification time on the temporary file try: mtime = self.mtime atime = int(time.time()) self.log("Setting temporary file modification time to %d", mtime) # FIXME: Should use futimes, but it's not wrapped by python os.utime(self.tempPath, (atime, mtime)) except OSError, e: if e.errno == errno.ENOENT: # The file may have been deleted by another process self._releaseCacheSpace() else: self.warning( "Failed to update modification time of temporary " "file: %s", log.getExceptionMessage(e)) self._cancelSession()
def scheduleRecordings(self, icalFile): self.uiState.set('has-schedule', True) self.debug('Parsing iCalendar file %s' % icalFile) from flumotion.component.base import scheduler try: self.icalScheduler = scheduler.ICalScheduler(icalFile) self.icalScheduler.subscribe(self.eventInstanceStarted, self.eventInstanceEnded) # FIXME: this should be handled through the subscription # handlers; for that, we should subscribe before the calendar # gets added cal = self.icalScheduler.getCalendar() eventInstances = cal.getActiveEventInstances() if eventInstances: instance = eventInstances[0] content = instance.event.content self.info('Event %s is in progress, start recording' % content) self._startFilenameTemplate = content self._startTimeTuple = instance.start.utctimetuple() self._recordAtStart = True else: self.info('No events in progress') self._recordAtStart = False self._updateNextPoints() except (ValueError, IndexError, KeyError), e: m = messages.Warning(T_(N_( "Error parsing ical file %s, so not scheduling any" " events." % icalFile)), debug=log.getExceptionMessage(e), mid="error-parsing-ical") self.addMessage(m)
def parseTextNode(self, node, type=str): """Parse a text-containing XML node. The node is expected to contain only text children. Recognized node types are L{xml.dom.Node.TEXT_NODE} and L{xml.dom.Node.CDATA_SECTION_NODE}. @param node: the node to parse @type node: L{xml.dom.Node} @param type: a function to call on the resulting text @type type: function of type unicode -> object @returns: The result of calling type on the unicode text. By default, type is L{str}. """ ret = [] for child in node.childNodes: if (child.nodeType == Node.TEXT_NODE or child.nodeType == Node.CDATA_SECTION_NODE): ret.append(child.data) elif child.nodeType == Node.COMMENT_NODE: continue else: raise self.parserError('unexpected non-text content of ' '%r: %r' % (node, child)) try: return type(''.join(ret)) except Exception, e: raise self.parserError('failed to parse %s as %s: %s', node, type, log.getExceptionMessage(e))
def __init__(self, name, parent, type, label, propertyList, plugList, worker, eatersList, isClockMaster, project, version, virtualFeeds=None): self.name = name self.parent = parent self.type = type self.label = label self.worker = worker self.defs = registry.getRegistry().getComponent(self.type) try: self.config = self._buildConfig(propertyList, plugList, eatersList, isClockMaster, project, version, virtualFeeds) except errors.ConfigError, e: # reuse the original exception? e.args = ("While parsing component %s: %s" % (name, log.getExceptionMessage(e)), ) raise
def writeConnection(): i = self.connectionInfo if not (i.authenticator.username and i.authenticator.password): self.log('not caching connection information') return s = ''.join(['<connection>', '<host>%s</host>' % i.host, '<manager>%s</manager>' % self.planet.get('name'), '<port>%d</port>' % i.port, '<use_insecure>%d</use_insecure>' % ((not i.use_ssl) and 1 or 0), '<user>%s</user>' % i.authenticator.username, '<passwd>%s</passwd>' % i.authenticator.password, '</connection>']) import os import md5 md5sum = md5.new(s).hexdigest() f = os.path.join(configure.registrydir, '%s.connection' % md5sum) try: h = open(f, 'w') h.write(s) h.close() except Exception, e: self.info('failed to write connection cache file %s: %s', f, log.getExceptionMessage(e))
def read(self): try: tree = minidom.parse(self._filename) node = tree.getElementsByTagName('gtk-admin-state')[0] for elem in node.childNodes: self._values[elem.nodeName] = elem.firstChild.data except (IOError, IndexError, ExpatError), e: log.warning('Cannot read gtl-admin-state %s', log.getExceptionMessage(e))
def _getRRDPaths(self): """Create the RRD file using the CACTI standard configuration if it doesn't exist""" paths = [] rrds = ( (self._clientsPath, 'clients', 'GAUGE'), (self._bytesPath, 'bytes', 'DERIVE'), ) for path, name, counterType in rrds: if not os.path.exists(path): try: DAY = 60 * 60 * 24 count = [ 8 * DAY // self._stepSize, 56 * DAY // (self._stepSize * 6), 250 * DAY // (self._stepSize * 24), 3000 * DAY // (self._stepSize * 288), ] rrdtool.create(path, '-s %d' % self._stepSize, 'DS:%s:%s:600:0:U' % (name, counterType), 'RRA:AVERAGE:0.5:1:%d' % count[0], 'RRA:AVERAGE:0.5:6:%d' % count[1], 'RRA:AVERAGE:0.5:24:%d' % count[2], 'RRA:AVERAGE:0.5:288:%d' % count[3], 'RRA:MAX:0.5:1:%d' % count[0], 'RRA:MAX:0.5:6:%d' % count[1], 'RRA:MAX:0.5:24:%d' % count[2], 'RRA:MAX:0.5:288:%d' % count[3]) paths.append(path) self.info("Created RRD file: '%s'", path) except Exception, e: self.warning("Error creating RRD file '%s': %s", path, log.getExceptionMessage(e)) m = messages.Warning(T_(N_( "Could not create RRD file '%s'.\n"), path), debug=log.getExceptionMessage(e), mid='rrd-create-error-%s' % path) self._component.addMessage(m) else: paths.append(path) self.info("Using existing RRD file: '%s'", path)
def _pollDisk(self): # Figure out the remaining disk space where the disker is saving # files to self._pollDiskDC = None s = None try: s = os.statvfs(self.directory) except Exception, e: self.debug('failed to figure out disk space: %s', log.getExceptionMessage(e))
def perspective_componentCallRemote(self, componentState, methodName, *args, **kwargs): """ Call a method on the given component on behalf of an admin client. @param componentState: state of the component to call the method on @type componentState: L{planet.ManagerComponentState} @param methodName: name of the method to call. Gets proxied to L{flumotion.component.component.""" \ """BaseComponentMedium}'s remote_(methodName) @type methodName: str @rtype: L{twisted.internet.defer.Deferred} """ assert isinstance(componentState, planet.ManagerComponentState), \ "%r is not a componentState" % componentState if methodName == "start": self.warning('forwarding "start" to perspective_componentStart') return self.perspective_componentStart(componentState) m = self.vishnu.getComponentMapper(componentState) if not m: self.warning('Component not mapped. Maybe deleted.') raise errors.UnknownComponentError(componentState) avatar = m.avatar if not avatar: self.warning('No avatar for %s, cannot call remote' % componentState.get('name')) raise errors.SleepingComponentError(componentState) # XXX: Maybe we need to have a prefix, so we can limit what an # admin interface can call on a component try: return avatar.mindCallRemote(methodName, *args, **kwargs) except Exception, e: msg = "exception on remote call %s: %s" % (methodName, log.getExceptionMessage(e)) self.warning(msg) raise errors.RemoteMethodError(methodName, log.getExceptionMessage(e))
def _closeSourceFile(self): if self._sourceFile is not None: self.log("Closing source file [fd %d]", self._sourceFile.fileno()) try: try: self._sourceFile.close() finally: self._sourceFile = None except IOError, e: self.warning("Failed to close source file: %s", log.getExceptionMessage(e))
def expireKeycards(self, keycardIds): """ Expire client's connections associated with the keycard Ids. """ expired = 0 for keycardId in keycardIds: try: self.expireKeycard(keycardId) expired += 1 except KeyError, e: self.warn("Failed to expire keycard %r: %s", keycardId, log.getExceptionMessage(e))
def _closeReadTempFile(self): if self._rTempFile is not None: self.log("Closing temporary file for reading [fd %d]", self._rTempFile.fileno()) try: try: self._rTempFile.close() finally: self._rTempFile = None except IOError, e: self.warning("Failed to close temporary file for reading: %s", log.getExceptionMessage(e))
class IcalBouncerAlgorithm(base.BouncerAlgorithm): logCategory = 'icalbouncer' events = [] maxKeyCardDuration = timedelta(days=1) def get_namespace(self): return 'icalbouncer' def start(self, component): self.props = self.args['properties'] self.iCalScheduler = None self.subscriptionToken = None self.check_properties(component) self.setup(component) def check_properties(self, component): def missingModule(moduleName): m = messages.Error(T_(N_( "To use the iCalendar bouncer you need to have " "the '%s' module installed.\n"), moduleName), mid='error-python-%s' % moduleName) documentation.messageAddPythonInstall(m, moduleName) component.addMessage(m) if not eventcalendar.HAS_ICALENDAR: missingModule('icalendar') if not eventcalendar.HAS_DATEUTIL: missingModule('dateutil') def setup(self, component): self._icsfile = self.props['file'] try: handle = open(self._icsfile, 'r') except IOError, e: m = messages.Error(T_(N_( "Failed to open iCalendar file '%s'. " "Check permissions on that file."), self._icsfile), mid='error-icalbouncer-file') component.addMessage(m) raise errors.ComponentSetupHandledError() try: self.iCalScheduler = scheduler.ICalScheduler(handle) except (ValueError, IndexError, KeyError), e: m = messages.Error(T_(N_( "Error parsing ical file '%s'."), self._icsfile), debug=log.getExceptionMessage(e), mid="error-icalbouncer-file") component.addMessage(m) raise errors.ComponentSetupHandledError()
def changeFilename(self, filenameTemplate=None, timeTuple=None): """ @param filenameTemplate: strftime format string to decide filename @param timeTuple: a valid time tuple to pass to strftime, defaulting to time.localtime(). """ mime = self.getMime() ext = mimeTypeToExtention(mime) self.stopRecording() sink = self.get_element('fdsink') if sink.get_state() == gst.STATE_NULL: sink.set_state(gst.STATE_READY) filename = "" if not filenameTemplate: filenameTemplate = self._defaultFilenameTemplate filename = "%s.%s" % (format.strftime(filenameTemplate, timeTuple or time.localtime()), ext) self.location = os.path.join(self.directory, filename) # only overwrite existing files if it was last changed before the # start of this event; ie. if it is a recording of a previous event location = self.location i = 1 while os.path.exists(location): mtimeTuple = time.gmtime(os.stat(location).st_mtime) if mtimeTuple <= timeTuple: self.info( "Existing recording %s from previous event, overwriting", location) break self.info( "Existing recording %s from current event, changing name", location) location = self.location + '.' + str(i) i += 1 self.location = location self.info("Changing filename to %s", self.location) try: self.file = open(self.location, 'wb') except IOError, e: self.warning("Failed to open output file %s: %s", self.location, log.getExceptionMessage(e)) m = messages.Error(T_(N_( "Failed to open output file '%s' for writing. " "Check permissions on the file."), self.location)) self.addMessage(m) return
def _notifyListeners(self, index, *args): # notify our local listeners; compute set of procs first, so as # to allow the listeners set to change during the calls self._ensureListeners() for proc in [tup[index] for tup in self._listeners.values()]: if proc: try: proc(self, *args) except Exception, e: # These are all programming errors log.warning("stateremotecache", 'Exception in StateCache handler: %s', log.getExceptionMessage(e))
def save(self): try: f = open(self._filename, 'w') doc = minidom.Document() root = doc.createElement('gtk-admin-state') doc.appendChild(root) for key, value in self._values.iteritems(): self._append(doc, root, key, value) doc.writexml(f) f.close() except IOError, e: log.warning('Cannot find gtk-admin-state: %s', log.getExceptionMessage(e))
def _sendFileDescriptor(self, fd, message): try: # FIXME: pay attention to the return value of # sendFileDescriptor; is the same as the return value of # sendmsg(2) self.mind.broker.transport.sendFileDescriptor(fd, message) return True except OSError, e: # OSError is what is thrown by the C code doing this # when there are issues self.warning("Error %s sending file descriptors", log.getExceptionMessage(e)) return False
def process(self): # First check that we have a valid request. if self.clientproto != SERVER_PROTOCOL: e = ErrorResource(BAD_REQUEST) self.render(e) return # process the request and render the resource or give a failure first = "%s %s %s" % (self.method, self.path, SERVER_PROTOCOL) self.debug('incoming request: %s' % first) lines = [] for key, value in self.received_headers.items(): lines.append("%s: %s" % (key, value)) self.debug('incoming headers:\n%s\n' % "\n".join(lines)) #self.debug('user-agent: %s' % self.received_headers.get('user-agent', # '[Unknown]')) #self.debug('clientid: %s' % self.received_headers.get('clientid', # '[Unknown]')) # don't store site locally; we can't be sure every request has gone # through our customized handlers site = self.channel.site ip = self.getClientIP() site.logRequest(ip, first, lines) if not self._processPath(): return try: if self.path == "*": resrc = site.resource else: resrc = site.getResourceFor(self) self.debug("RTSPRequest.process(): got resource %r" % resrc) try: self.render(resrc) except server.UnsupportedMethod: e = ErrorResource(OPTION_NOT_SUPPORTED) self.setHeader('Allow', ",".join(resrc.allowedMethods)) self.render(e) except RTSPError, e: er = ErrorResource(e.args[0]) self.render(er) except Exception, e: self.warning('failed to process %s: %s' % (lines and lines[0] or "[No headers]", flog.getExceptionMessage(e))) self.processingFailed(failure.Failure())
def _updateSymlink(self, src, dest): if not dest.startswith('/'): dest = os.path.join(self.directory, dest) # this should read: # "updating symbolic link /tmp/current to point to /tmp/video-XXX.data" # hence the order of parameters should be dest, src self.debug("updating symbolic link %s to point to %s", dest, src) try: try: os.symlink(src, dest) except OSError, e: if e.errno == errno.EEXIST and os.path.islink(dest): os.unlink(dest) os.symlink(src, dest) else: raise except Exception, e: self.info("Failed to update link %s: %s", dest, log.getExceptionMessage(e)) m = messages.Warning(T_(N_("Failed to update symbolic link " "'%s'. Check your permissions."), dest), debug=log.getExceptionMessage(e)) self.addMessage(m)
def event(self, event, *args, **kwargs): """Fire an event. This method is intended for use by object implementations. """ for s in self.subscribers.values(): if s[event]: # Exceptions raised by subscribers need to be catched to # continue polling for changes try: s[event](*args, **kwargs) except Exception, e: self.warning("A callback for event %s raised an error: %s" % (event, log.getExceptionMessage(e)))
def _removeTempFile(self): try: os.remove(self.tempPath) self.log("Deleted temporary file '%s'", self.tempPath) # Inform the plug that cache space has been released self._releaseCacheSpace() except OSError, e: if e.errno == errno.ENOENT: if self._wTempFile is not None: # Already deleted but inform the plug anyway self._releaseCacheSpace() else: self.warning("Error deleting temporary file: %s", log.getExceptionMessage(e))
def manager_connected(self, model): try: psd = model.callRemote('getPlanetState') yield psd planet = psd.result self.planet = planet flows = planet.get('flows') if flows: flow = flows[0] for f in flows: if f.get('name') == 'default': self.default_flow = flow = f break self._components = flow.get('components') flow.addListener(self, append=self.flow_state_append, remove=self.flow_state_remove) for c in self._components: self.new_component(c) self.planet.addListener(self, append=self.planet_state_append, remove=self.planet_state_remove) self.stomp_client.restart_statuses() except Exception, e: print log.getExceptionMessage(e)
def emit(self, signalName, *args): self.__ensureSignals() if signalName not in self.__signals__: raise ValueError('Emitting unknown signal %s' % signalName) connections = self.__signalConnections for name, proc, pargs, pkwargs in connections.values(): if name == signalName: try: proc(self, *(args + pargs), **pkwargs) except Exception, e: log.warning("signalmixin", "Exception calling " "signal handler %r: %s", proc, log.getExceptionMessage(e))
def getFileData(self): """ @returns: a dict, {filename => DATA} DATA can be anything. In the default implementation it is a pair of (mtime, size). """ ret = {} for f in self.getFilesToStat(): try: stat = os.stat(f) ret[f] = (stat.st_mtime, stat.st_size) except OSError, e: self.debug('could not read file %s: %s', f, log.getExceptionMessage(e))
def perspective_upstreamList(self, avatarId): """ List a component and its upstream components along with types and worker hosts. @param avatarId: the component avatar id @type avatarId: str """ def get_eaters_ids(eaters_dic): avatars = [] for flow in eaters_dic.keys(): comps = eaters_dic[flow] for c in comps: (name, what) = c[0].split(':') avatars.append('/%s/%s' % (flow, name)) return avatars def create_response(components, workers): comps = [] for c in components: workerName = c.get('workerName') host = "unknown" for w in workers: if workerName == w.get('name'): host = w.get('host') break comps.append((c.get('name'), c.get('type'), host)) return comps component = util.findComponent(self.vishnu.state, avatarId) if not component: self.warning('No component with avatar id %s' % avatarId) raise errors.UnknownComponentError(avatarId) eaters = component.get('config').get('eater', {}) eaters_id = get_eaters_ids(eaters) comps = [component] while len(eaters_id) > 0: eaters = {} for i in eaters_id: try: compState = util.findComponent(self.vishnu.state, i) comps.append(compState) eaters.update(compState.get('config').get('eater', {})) except Exception, e: self.debug(log.getExceptionMessage(e)) emsg = "Error retrieving component '%s'" % i raise errors.UnknownComponentError(emsg) eaters_id = get_eaters_ids(eaters)
def ensureRRDFiles(self, sources): for source in sources: rrdfile = sourceGetFileName(source) if not os.path.exists(rrdfile): try: self.info('Creating RRD file %s', rrdfile) rrdtool.create(rrdfile, "-s", str(sourceGetSampleFrequency(source)), sourceGetDS(source), *sourceGetRRAList(source)) except rrdtool.error, e: self.warning('Could not create RRD file %s', rrdfile) self.debug('Failure reason: %s', log.getExceptionMessage(e))
def onErrorCloseConnection(failure): try: host = mind.broker.transport.getHost() remote = '%s:%d' % (host.host, host.port) except: remote = '(unknown)' self.warning('failed login -- closing connection to %s', remote) self.debug('failure: %s', log.getFailureMessage(failure)) try: mind.broker.transport.loseConnection() except Exception, e: self.info('loseConnection failed: %s', log.getExceptionMessage(e))