~landscape/landscape-client/trunk

« back to all changes in this revision

Viewing changes to landscape/broker/store.py

  • Committer: Thomas Hervé
  • Date: 2011-08-19 16:29:47 UTC
  • mfrom: (359.1.7 fake-package-reporter)
  • Revision ID: thomas@canonical.com-20110819162947-apn3cvdxrsbq12wv
Merge fake-package-reporter [r=free.ekanayaka,fwierbicki] [f=821570]

Write 2 package reporters for load testing: one saving the messages in sqlite,
and the other using that store to fake package reporting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    api = SERVER_API
44
44
 
45
45
    def __init__(self, persist, directory, directory_size=1000,
46
 
                 monitor_interval=60*60, get_time=time.time):
47
 
        """
48
 
        """
 
46
                 monitor_interval=60 * 60, get_time=time.time):
49
47
        self._get_time = get_time
50
48
        self._directory = directory
51
49
        self._directory_size = directory_size
82
80
    def get_sequence(self):
83
81
        """Get the current sequence.
84
82
 
85
 
        @return: The sequence number of the message that the server expects us to
86
 
           send on the next exchange.
 
83
        @return: The sequence number of the message that the server expects us
 
84
            to send on the next exchange.
87
85
        """
88
86
        return self._persist.get("sequence", 0)
89
87
 
98
96
    def get_server_sequence(self):
99
97
        """Get the current server sequence.
100
98
 
101
 
        @return: the sequence number of the message that we will ask the server to
102
 
            send to us on the next exchange.
 
99
        @return: the sequence number of the message that we will ask the server
 
100
            to send to us on the next exchange.
103
101
        """
104
102
        return self._persist.get("server_sequence", 0)
105
103
 
161
159
 
162
160
    def delete_old_messages(self):
163
161
        """Delete messages which are unlikely to be needed in the future."""
164
 
        for fn in itertools.islice(self._walk_messages(exclude=HELD+BROKEN),
 
162
        for fn in itertools.islice(self._walk_messages(exclude=HELD + BROKEN),
165
163
                                   self.get_pending_offset()):
166
164
            os.unlink(fn)
167
165
            containing_dir = os.path.split(fn)[0]
256
254
    def _walk_pending_messages(self):
257
255
        """Walk the files which are definitely pending."""
258
256
        pending_offset = self.get_pending_offset()
259
 
        for i, filename in enumerate(self._walk_messages(exclude=HELD+BROKEN)):
 
257
        for i, filename in enumerate(self._walk_messages(exclude=HELD +
 
258
                                                                 BROKEN)):
260
259
            if i >= pending_offset:
261
260
                yield filename
262
261
 
308
307
                    if accepted:
309
308
                        new_filename = self._get_next_message_filename()
310
309
                        os.rename(old_filename, new_filename)
311
 
                        self._set_flags(new_filename, set(flags)-set(HELD))
 
310
                        self._set_flags(new_filename, set(flags) - set(HELD))
312
311
                else:
313
312
                    if not accepted and offset >= pending_offset:
314
 
                        self._set_flags(old_filename, set(flags)|set(HELD))
 
313
                        self._set_flags(old_filename, set(flags) | set(HELD))
315
314
                    offset += 1
316
315
 
317
316
    def _get_flags(self, path):
324
323
        dirname, basename = os.path.split(path)
325
324
        new_path = os.path.join(dirname, basename.split("_")[0])
326
325
        if flags:
327
 
            new_path += "_"+"".join(sorted(set(flags)))
 
326
            new_path += "_" + "".join(sorted(set(flags)))
328
327
        os.rename(path, new_path)
329
328
        return new_path
330
329
 
331
330
    def _add_flags(self, path, flags):
332
 
        self._set_flags(path, self._get_flags(path)+flags)
 
331
        self._set_flags(path, self._get_flags(path) + flags)
333
332
 
334
333
 
335
334
def get_default_message_store(*args, **kwargs):
336
 
    """Get a L{MessageStore} object with all Landscape message schemas added."""
 
335
    """
 
336
    Get a L{MessageStore} object with all Landscape message schemas added.
 
337
    """
337
338
    from landscape. message_schemas import message_schemas
338
339
    store = MessageStore(*args, **kwargs)
339
340
    for schema in message_schemas.values():