def remove_app(self, appname): """Remove app from scheduler.""" if appname not in self.cell.apps: return app = self.cell.apps[appname] if app.server: self.backend.delete(z.path.placement(app.server, appname)) if self.events_dir: appevents.post(self.events_dir, traceevents.DeletedTraceEvent(instanceid=appname)) # If finished does not exist, it means app is terminated by # explicit request, not because it finished on the node. if not self.backend.exists(z.path.finished(appname)): self.backend.put( z.path.finished(appname), { 'state': 'terminated', 'when': time.time(), 'host': app.server, 'data': None }, ) super(Master, self).remove_app(appname)
def process_scheduled(self, scheduled): """Callback invoked when on scheduling changes.""" current = set(self.cell.apps.keys()) target = set(scheduled) for appname in current - target: app = self.cell.apps[appname] if app.server: self.backend.delete(z.path.placement(app.server, appname)) if self.events_dir: appevents.post( self.events_dir, traceevents.DeletedTraceEvent(instanceid=appname)) # If finished does not exist, it means app is terminated by # explicit request, not because it finished on the node. if not self.backend.exists(z.path.finished(appname)): self.backend.put( z.path.finished(appname), { 'state': 'terminated', 'when': time.time(), 'host': app.server, 'data': None }, ) self.cell.remove_app(appname) for appname in target - current: self.load_app(appname)
def test_deleted(self): """Deleted event operations. """ event = events.DeletedTraceEvent(timestamp=1, source='tests', instanceid='proid.foo#123', payload={'foo': 'bar'}) self.assertEqual( event.to_dict(), { 'event_type': 'deleted', 'timestamp': 1, 'source': 'tests', 'instanceid': 'proid.foo#123', 'payload': { 'foo': 'bar' }, }) self.assertEqual(event.to_data(), ( 1, 'tests', 'proid.foo#123', 'deleted', '', { 'foo': 'bar' }, )) self.assertEqual( event, events.DeletedTraceEvent.from_data(timestamp=1, source='tests', instanceid='proid.foo#123', event_type='deleted', event_data='not used', payload={'foo': 'bar'}))
def test_deleted(self, stdout_mock): """Test printing Deleted event. """ event = events.DeletedTraceEvent(timestamp=1, source='tests', instanceid='proid.foo#123', payload={'foo': 'bar'}) self.trace_printer.process(event) self.assertEqual( stdout_mock.getvalue(), 'Thu, 01 Jan 1970 00:00:01+0000 - ' 'proid.foo#123 deleted\n')