~free.ekanayaka/landscape-client/karmic-proposed

« back to all changes in this revision

Viewing changes to landscape/broker/store.py

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Free Ekanayaka
  • Date: 2009-07-22 14:54:50 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090722145450-pvbp13gh8734c8ft
Tags: 1.3.2.2-0ubuntu0.9.10.1
[ Free Ekanayaka ]
* New upstream release:
  - Include the README file in landscape-client (LP: #396260)
  - Fix client capturing stderr from run_command when constructing
    hash-id-databases url (LP: #397480)
  - Use substvars to conditionally depend on update-motd or
    libpam-modules (LP: #393454)
  - Fix reporting wrong version to the server (LP: #391225)
  - The init script does not wait for the network to be available
    before checking for EC2 user data (LP: #383336)
  - When the broker is restarted by the watchdog, the state of the client
    is inconsistent (LP: #380633)
  - Package stays unknown forever in the client with hash-id-databases
    support (LP: #381356)
  - Standard error not captured when calling smart-update (LP: #387441)
  - Changer calls reporter without switching groups, just user (LP: #388092)
  - Run smart update in the package-reporter instead of having a cronjob (LP: #362355)
  - Package changer does not inherit proxy settings (LP: #381241)
  - The ./test script doesn't work in landscape-client (LP: #381613)
  - The source package should build on all supported releases (LP: #385098)
  - Strip smart update's output (LP: #387331)
  - The fetch() timeout isn't based on activity (#389224)
  - Client can use a UUID of "None" when fetching the hash-id-database (LP: #381291)
  - Registration should use the fqdn rather than just the hostname (LP: #385730)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import os
7
7
 
8
8
from landscape.lib import bpickle
 
9
from landscape.lib.persist import Persist
9
10
from landscape.lib.monitor import Monitor
10
11
from landscape import API
11
12
 
22
23
    that reason, let's review the terminology here.
23
24
 
24
25
    Assume we have 10 messages in the store, which we label by
25
 
    the following uppercase letters:
 
26
    the following uppercase letters::
26
27
 
27
28
        A, B, C, D, E, F, G, H, I, J
28
29
                 ^
41
42
 
42
43
    def __init__(self, persist, directory, directory_size=1000,
43
44
                 monitor_interval=60*60, get_time=time.time):
 
45
        """
 
46
        @param persist: a L{Persist} used to save state parameters like
 
47
            the accepted message types, sequence, server uuid etc.
 
48
        @param directory: base of the file system hierarchy
 
49
        """
44
50
        self._get_time = get_time
45
51
        self._directory = directory
46
52
        self._directory_size = directory_size
52
58
            os.makedirs(message_dir)
53
59
 
54
60
    def commit(self):
55
 
        """Save metadata to disk."""
 
61
        """Persist metadata to disk."""
56
62
        self._original_persist.save()
57
63
 
58
64
    def set_accepted_types(self, types):
67
73
        self._reprocess_holding()
68
74
 
69
75
    def get_accepted_types(self):
 
76
        """Get a list of all accepted message types."""
70
77
        return self._persist.get("accepted-types", ())
71
78
 
72
79
    def accepts(self, type):
 
80
        """Return bool indicating if C{type} is an accepted message type."""
73
81
        return type in self.get_accepted_types()
74
82
 
75
83
    def get_sequence(self):
76
 
        """
77
 
        Get the sequence number of the message that the server expects us to
78
 
        send on the next exchange.
 
84
        """Get the current sequence.
 
85
 
 
86
        @return: The sequence number of the message that the server expects us to
 
87
           send on the next exchange.
79
88
        """
80
89
        return self._persist.get("sequence", 0)
81
90
 
82
91
    def set_sequence(self, number):
83
 
        """
 
92
        """Set the current sequence.
 
93
 
84
94
        Set the sequence number of the message that the server expects us to
85
95
        send on the next exchange.
86
96
        """
87
97
        self._persist.set("sequence", number)
88
98
 
89
99
    def get_server_sequence(self):
90
 
        """
91
 
        Get the sequence number of the message that we will ask the server to
92
 
        send to us on the next exchange.
 
100
        """Get the current server sequence.
 
101
 
 
102
        @return: the sequence number of the message that we will ask the server to
 
103
            send to us on the next exchange.
93
104
        """
94
105
        return self._persist.get("server_sequence", 0)
95
106
 
96
107
    def set_server_sequence(self, number):
97
 
        """
 
108
        """Set the current server sequence.
 
109
 
98
110
        Set the sequence number of the message that we will ask the server to
99
111
        send to us on the next exchange.
100
112
        """
109
121
        self._persist.set("server_uuid", uuid)
110
122
 
111
123
    def get_pending_offset(self):
 
124
        """Get the current pending offset."""
112
125
        return self._persist.get("pending_offset", 0)
113
126
 
114
127
    def set_pending_offset(self, val):
115
 
        """
 
128
        """Set the current pending offset.
 
129
 
116
130
        Set the offset into the message pool to consider assigned to the
117
131
        current sequence number as returned by l{get_sequence}.
118
132
        """
119
133
        self._persist.set("pending_offset", val)
120
134
 
121
135
    def add_pending_offset(self, val):
 
136
        """Increment the current pending offset by C{val}."""
122
137
        self.set_pending_offset(self.get_pending_offset() + val)
123
138
 
124
139
    def count_pending_messages(self):
186
201
 
187
202
    def add(self, message):
188
203
        """Queue a message for delivery.
189
 
        
 
204
 
 
205
        @param message: a C{dict} with a C{type} key and other keys conforming
 
206
            to the L{Message} schema for that specifc message type.
190
207
        @return: message_id, which is an identifier for the added message.
191
208
        """
192
209
        assert "type" in message