Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python2.7 / dist-packages / landscape / broker / | server ip : 172.67.156.115 your ip : 172.70.131.160 H O M E |
Filename | /usr/lib/python2.7/dist-packages/landscape/broker/service.py |
Size | 3.84 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 20-Feb-2014 23:01 |
Last accessed | 06-Jul-2025 20:10 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
"""Deployment code for the monitor."""
import os
from landscape.lib.fetch import fetch_async
from landscape.service import LandscapeService, run_landscape_service
from landscape.amp import ComponentPublisher
from landscape.broker.registration import RegistrationHandler, Identity
from landscape.broker.config import BrokerConfiguration
from landscape.broker.transport import HTTPTransport
from landscape.broker.exchange import MessageExchange
from landscape.broker.exchangestore import ExchangeStore
from landscape.broker.ping import Pinger
from landscape.broker.store import get_default_message_store
from landscape.broker.server import BrokerServer
class BrokerService(LandscapeService):
"""The core C{Service} of the Landscape Broker C{Application}.
The Landscape broker service handles all the communication between the
client and server. When started it creates and runs all necessary
components to exchange messages with the Landscape server.
@cvar service_name: C{broker}
@ivar persist_filename: Path to broker-specific persistent data.
@ivar persist: A L{Persist} object saving and loading data from
C{self.persist_filename}.
@ivar message_store: A L{MessageStore} used by the C{exchanger} to
queue outgoing messages.
@ivar transport: An L{HTTPTransport} used by the C{exchanger} to deliver
messages.
@ivar identity: The L{Identity} of the Landscape client the broker runs on.
@ivar exchanger: The L{MessageExchange} exchanges messages with the server.
@ivar pinger: The L{Pinger} checks if the server has new messages for us.
@ivar registration: The L{RegistrationHandler} performs the initial
registration.
@param config: A L{BrokerConfiguration}.
"""
transport_factory = HTTPTransport
pinger_factory = Pinger
service_name = BrokerServer.name
def __init__(self, config):
self.persist_filename = os.path.join(
config.data_path, "%s.bpickle" % (self.service_name,))
super(BrokerService, self).__init__(config)
self.transport = self.transport_factory(
self.reactor, config.url, config.ssl_public_key)
self.message_store = get_default_message_store(
self.persist, config.message_store_path)
self.identity = Identity(self.config, self.persist)
exchange_store = ExchangeStore(self.config.exchange_store_path)
self.exchanger = MessageExchange(
self.reactor, self.message_store, self.transport, self.identity,
exchange_store, config)
self.pinger = self.pinger_factory(
self.reactor, self.identity, self.exchanger, config)
self.registration = RegistrationHandler(
config, self.identity, self.reactor, self.exchanger, self.pinger,
self.message_store, fetch_async)
self.broker = BrokerServer(self.config, self.reactor, self.exchanger,
self.registration, self.message_store,
self.pinger)
self.publisher = ComponentPublisher(self.broker, self.reactor,
self.config)
def startService(self):
"""Start the broker.
Create a L{BrokerServer} listening on C{broker_socket_path} for clients
connecting with the L{BrokerServerConnector}, and start the
L{MessageExchange} and L{Pinger} services.
"""
super(BrokerService, self).startService()
self.publisher.start()
self.exchanger.start()
self.pinger.start()
def stopService(self):
"""Stop the broker."""
self.publisher.stop()
self.exchanger.stop()
self.pinger.stop()
super(BrokerService, self).stopService()
def run(args):
"""Run the application, given some command line arguments."""
run_landscape_service(BrokerConfiguration, BrokerService, args)
import os
from landscape.lib.fetch import fetch_async
from landscape.service import LandscapeService, run_landscape_service
from landscape.amp import ComponentPublisher
from landscape.broker.registration import RegistrationHandler, Identity
from landscape.broker.config import BrokerConfiguration
from landscape.broker.transport import HTTPTransport
from landscape.broker.exchange import MessageExchange
from landscape.broker.exchangestore import ExchangeStore
from landscape.broker.ping import Pinger
from landscape.broker.store import get_default_message_store
from landscape.broker.server import BrokerServer
class BrokerService(LandscapeService):
"""The core C{Service} of the Landscape Broker C{Application}.
The Landscape broker service handles all the communication between the
client and server. When started it creates and runs all necessary
components to exchange messages with the Landscape server.
@cvar service_name: C{broker}
@ivar persist_filename: Path to broker-specific persistent data.
@ivar persist: A L{Persist} object saving and loading data from
C{self.persist_filename}.
@ivar message_store: A L{MessageStore} used by the C{exchanger} to
queue outgoing messages.
@ivar transport: An L{HTTPTransport} used by the C{exchanger} to deliver
messages.
@ivar identity: The L{Identity} of the Landscape client the broker runs on.
@ivar exchanger: The L{MessageExchange} exchanges messages with the server.
@ivar pinger: The L{Pinger} checks if the server has new messages for us.
@ivar registration: The L{RegistrationHandler} performs the initial
registration.
@param config: A L{BrokerConfiguration}.
"""
transport_factory = HTTPTransport
pinger_factory = Pinger
service_name = BrokerServer.name
def __init__(self, config):
self.persist_filename = os.path.join(
config.data_path, "%s.bpickle" % (self.service_name,))
super(BrokerService, self).__init__(config)
self.transport = self.transport_factory(
self.reactor, config.url, config.ssl_public_key)
self.message_store = get_default_message_store(
self.persist, config.message_store_path)
self.identity = Identity(self.config, self.persist)
exchange_store = ExchangeStore(self.config.exchange_store_path)
self.exchanger = MessageExchange(
self.reactor, self.message_store, self.transport, self.identity,
exchange_store, config)
self.pinger = self.pinger_factory(
self.reactor, self.identity, self.exchanger, config)
self.registration = RegistrationHandler(
config, self.identity, self.reactor, self.exchanger, self.pinger,
self.message_store, fetch_async)
self.broker = BrokerServer(self.config, self.reactor, self.exchanger,
self.registration, self.message_store,
self.pinger)
self.publisher = ComponentPublisher(self.broker, self.reactor,
self.config)
def startService(self):
"""Start the broker.
Create a L{BrokerServer} listening on C{broker_socket_path} for clients
connecting with the L{BrokerServerConnector}, and start the
L{MessageExchange} and L{Pinger} services.
"""
super(BrokerService, self).startService()
self.publisher.start()
self.exchanger.start()
self.pinger.start()
def stopService(self):
"""Stop the broker."""
self.publisher.stop()
self.exchanger.stop()
self.pinger.stop()
super(BrokerService, self).stopService()
def run(args):
"""Run the application, given some command line arguments."""
run_landscape_service(BrokerConfiguration, BrokerService, args)