Esempio n. 1
0
    def worker_heartbeat(self, heartbeat_data):
        """
        Name
        ----
        `worker_heartbeat` (`heartbeat_data`)

        Description
        -----------
        Pushes the heartbeat of dispatcher worker node.

        Arguments
        ---------
        `heartbeat_data`: string
            Heartbeat data extracted from dispatcher worker node.

        Return value
        ------------
        This function returns an XML-RPC boolean output, provided the user is
        authenticated with an username and token.
        """
        worker = Worker()
        if not self.user:
            raise xmlrpclib.Fault(
                401, "Authentication with user and token required for this "
                "API.")
        if not worker.can_update(self.user):
            raise xmlrpclib.Fault(403, "Permission denied.")

        worker.update_heartbeat(heartbeat_data)
        return True
Esempio n. 2
0
    def worker_heartbeat(self, heartbeat_data):
        """
        Name
        ----
        `worker_heartbeat` (`heartbeat_data`)

        Description
        -----------
        Pushes the heartbeat of dispatcher worker node.

        Arguments
        ---------
        `heartbeat_data`: string
            Heartbeat data extracted from dispatcher worker node.

        Return value
        ------------
        This function returns an XML-RPC boolean output, provided the user is
        authenticated with an username and token.
        """
        worker = Worker()
        if not self.user:
            raise xmlrpclib.Fault(
                401, "Authentication with user and token required for this "
                "API.")
        if not worker.can_update(self.user):
            raise xmlrpclib.Fault(403, "Permission denied.")

        worker.update_heartbeat(heartbeat_data)
        return True
Esempio n. 3
0
def _get_scheduler_rpc():
    """Returns the scheduler xmlrpc AuthicatingServerProxy object.
    """
    username = '******'  # We assume this user exists always.
    user = User.objects.get(username=username)
    rpc2_url = Worker.get_rpc2_url()

    try:
        token = AuthToken.objects.filter(user=user)[0]
    except IndexError:
        token = AuthToken.objects.create(user=user)
        token.save()

    parsed_server = urlparse.urlparse(rpc2_url)
    server = '{0}://{1}:{2}@{3}'.format(parsed_server.scheme, username,
                                        token.secret, parsed_server.hostname)
    if parsed_server.port:
        server += ':' + str(parsed_server.port)
    server += parsed_server.path

    auth_backend = MemoryAuthBackend([(username, rpc2_url, token.secret)])
    server = AuthenticatingServerProxy(server, auth_backend=auth_backend)
    server = server.scheduler

    return server
Esempio n. 4
0
def _get_scheduler_rpc():
    """Returns the scheduler xmlrpc AuthicatingServerProxy object.
    """
    username = '******'  # We assume this user exists always.
    user = User.objects.get(username=username)
    rpc2_url = Worker.get_rpc2_url()

    try:
        token = AuthToken.objects.filter(user=user)[0]
    except IndexError:
        token = AuthToken.objects.create(user=user)
        token.save()

    parsed_server = urlparse.urlparse(rpc2_url)
    server = '{0}://{1}:{2}@{3}'.format(parsed_server.scheme, username,
                                        token.secret, parsed_server.hostname)
    if parsed_server.port:
        server += ':' + str(parsed_server.port)
    server += parsed_server.path

    auth_backend = MemoryAuthBackend([(username, rpc2_url, token.secret)])
    server = AuthenticatingServerProxy(server, auth_backend=auth_backend)
    server = server.scheduler

    return server
Esempio n. 5
0
 def record_master_scheduler_tick(self):
     """Records the master's last scheduler tick timestamp.
     """
     try:
         worker = Worker.localhost()
         if worker.on_master():
             worker.record_last_master_scheduler_tick()
     except Exception as err:
         self.logger.error("Unable to record last master scheduler tick.")
         self.logger.error("Details: %s", err)
Esempio n. 6
0
 def record_master_scheduler_tick(self):
     """Records the master's last scheduler tick timestamp.
     """
     try:
         worker = Worker.localhost()
         if worker.on_master():
             worker.record_last_master_scheduler_tick()
     except Exception as err:
         self.logger.error("Unable to record last master scheduler tick.")
         self.logger.error("Details: %s", err)
Esempio n. 7
0
    def put_heartbeat_data(self, restart=False):
        """Puts heartbeat data via the xmlrpc api.

        If the scheduler daemon was restarted identified by RESTART, populate
        the complete worker data, else populate minimal worker data, if it is
        too long since the last heartbeat data was updated.
        """
        try:
            localhost = Worker.localhost()
            if localhost.too_long_since_last_heartbeat():
                self.populate_minimal_worker_data()
            elif restart:
                self.populate_complete_worker_data()
            else:
                return
        except ValueError:
            self.logger.debug("Worker %s unavailable" % utils.get_fqdn())
            self.populate_complete_worker_data()

        MAX_RETRIES = 3
        data = simplejson.dumps(self.worker)

        for retry in range(MAX_RETRIES):
            try:
                server = _get_scheduler_rpc()
                server.worker_heartbeat(data)
                self.logger.debug("Heartbeat updated")
                return
            except (CommandError, URLError, IOError) as err:
                self.logger.debug("Error message: %s" % str(err))
            except xmlrpclib.Fault as err:
                time.sleep(1)
                self.logger.debug("Retrying heartbeat update (%d) ..." % retry)
            except xmlrpclib.ProtocolError as err:
                self.logger.error("Protocol error occured")
                self.logger.error("URL: %s" % err.url)
                self.logger.error("HTTP/HTTPS headers: %s" % err.headers)
                self.logger.error("Error code: %d" % err.errcode)
                self.logger.error("Error message: %s" % err.errmsg)
                raise err
        self.logger.error("Unable to update the Heartbeat, trying later")
Esempio n. 8
0
    def put_heartbeat_data(self, restart=False):
        """Puts heartbeat data via the xmlrpc api.

        If the scheduler daemon was restarted identified by RESTART, populate
        the complete worker data, else populate minimal worker data, if it is
        too long since the last heartbeat data was updated.
        """
        try:
            localhost = Worker.localhost()
            if restart:
                self.populate_complete_worker_data()
            elif localhost.too_long_since_last_heartbeat():
                self.populate_minimal_worker_data()
            else:
                return
        except ValueError:
            self.logger.debug("Worker %s unavailable", utils.get_fqdn())
            self.populate_complete_worker_data()

        MAX_RETRIES = 3
        data = simplejson.dumps(self.worker)

        for retry in range(MAX_RETRIES):
            try:
                server = _get_scheduler_rpc()
                server.worker_heartbeat(data)
                self.logger.debug("Heartbeat updated")
                return
            except (CommandError, URLError, IOError) as err:
                self.logger.debug("Error message: %s", str(err))
            except xmlrpclib.Fault as err:
                time.sleep(1)
                self.logger.debug("Retrying heartbeat update (%d) ...", retry)
            except xmlrpclib.ProtocolError as err:
                self.logger.error("Protocol error occured")
                self.logger.error("URL: %s", err.url)
                self.logger.error("HTTP/HTTPS headers: %s", err.headers)
                self.logger.error("Error code: %d", err.errcode)
                self.logger.error("Error message: %s", err.errmsg)
                raise err
        self.logger.error("Unable to update the Heartbeat, trying later")