[Notes] [Git][BuildGrid/buildgrid][finn/74-operation-cancelation] Removed state machine from BotsInterface.



Title: GitLab

finn pushed to branch finn/74-operation-cancelation at BuildGrid / buildgrid

Commits:

2 changed files:

Changes:

  • buildgrid/server/bots/instance.py
    ... ... @@ -80,9 +80,11 @@ class BotsInterface:
    80 80
             self.logger.debug("Updating bot session name={}".format(name))
    
    81 81
             self._check_bot_ids(bot_session.bot_id, name)
    
    82 82
     
    
    83
    -        leases = filter(None, [self.check_states(lease) for lease in bot_session.leases])
    
    83
    +        leases = filter(None, [self._check_lease_state(lease) for lease in bot_session.leases])
    
    84
    +
    
    85
    +        for lease in bot_session.leases:
    
    86
    +            lease.Clear()
    
    84 87
     
    
    85
    -        del bot_session.leases[:]
    
    86 88
             bot_session.leases.extend(leases)
    
    87 89
     
    
    88 90
             # TODO: Send worker capabilities to the scheduler!
    
    ... ... @@ -94,55 +96,18 @@ class BotsInterface:
    94 96
             self._bot_sessions[name] = bot_session
    
    95 97
             return bot_session
    
    96 98
     
    
    97
    -    def check_states(self, client_lease):
    
    98
    -        """ Edge detector for states
    
    99
    -        """
    
    100
    -        # TODO: Handle cancelled states
    
    101
    -        try:
    
    102
    -            server_lease = self._scheduler.get_job_lease(client_lease.id)
    
    103
    -        except KeyError:
    
    104
    -            raise InvalidArgumentError("Lease not found on server: [{}]".format(client_lease))
    
    105
    -
    
    106
    -        server_state = LeaseState(server_lease.state)
    
    107
    -        client_state = LeaseState(client_lease.state)
    
    108
    -
    
    109
    -        if server_state == LeaseState.PENDING:
    
    110
    -
    
    111
    -            if client_state == LeaseState.ACTIVE:
    
    112
    -                self._scheduler.update_job_lease_state(client_lease.id,
    
    113
    -                                                       LeaseState.ACTIVE)
    
    114
    -            elif client_state == LeaseState.COMPLETED:
    
    115
    -                # TODO: Lease was rejected
    
    116
    -                raise NotImplementedError("'Not Accepted' is unsupported")
    
    117
    -            else:
    
    118
    -                raise OutOfSyncError("Server lease: [{}]. Client lease: [{}]".format(server_lease, client_lease))
    
    99
    +    def _check_lease_state(self, lease):
    
    119 100
     
    
    120
    -        elif server_state == LeaseState.ACTIVE:
    
    101
    +        self._scheduler.update_job_lease(lease)
    
    121 102
     
    
    122
    -            if client_state == LeaseState.ACTIVE:
    
    123
    -                pass
    
    103
    +        lease_state = LeaseState(lease.state)
    
    104
    +        if lease_state == LeaseState.COMPLETED:
    
    105
    +            return None
    
    124 106
     
    
    125
    -            elif client_state == LeaseState.COMPLETED:
    
    126
    -                self._scheduler.update_job_lease_state(client_lease.id,
    
    127
    -                                                       LeaseState.COMPLETED,
    
    128
    -                                                       lease_status=client_lease.status,
    
    129
    -                                                       lease_result=client_lease.result)
    
    130
    -                return None
    
    131
    -
    
    132
    -            else:
    
    133
    -                raise OutOfSyncError("Server lease: [{}]. Client lease: [{}]".format(server_lease, client_lease))
    
    134
    -
    
    135
    -        elif server_state == LeaseState.COMPLETED:
    
    136
    -            raise OutOfSyncError("Server lease: [{}]. Client lease: [{}]".format(server_lease, client_lease))
    
    137
    -
    
    138
    -        elif server_state == LeaseState.CANCELLED:
    
    139
    -            raise NotImplementedError("Cancelled states not supported yet")
    
    140
    -
    
    141
    -        else:
    
    142
    -            # Sould never get here
    
    143
    -            raise OutOfSyncError("State now allowed: {}".format(server_state))
    
    107
    +        elif lease_state == LeaseState.CANCELLED:
    
    108
    +            return None
    
    144 109
     
    
    145
    -        return client_lease
    
    110
    +        return lease
    
    146 111
     
    
    147 112
         def _check_bot_ids(self, bot_id, name=None):
    
    148 113
             """ Checks the ID and the name of the bot.
    

  • buildgrid/server/scheduler.py
    ... ... @@ -99,7 +99,7 @@ class Scheduler:
    99 99
     
    
    100 100
             return None
    
    101 101
     
    
    102
    -    def update_job_lease_state(self, job_name, lease_state, lease_status=None, lease_result=None):
    
    102
    +    def update_job_lease(self, lease):
    
    103 103
             """Requests a state transition for a job's current :class:Lease.
    
    104 104
     
    
    105 105
             Args:
    
    ... ... @@ -110,14 +110,21 @@ class Scheduler:
    110 110
                 lease_result (google.protobuf.Any): the lease execution result, only
    
    111 111
                     required if `lease_state` is `COMPLETED`.
    
    112 112
             """
    
    113
    -        job = self.jobs[job_name]
    
    114 113
     
    
    115
    -        if lease_state != LeaseState.COMPLETED:
    
    116
    -            job.update_lease_state(lease_state)
    
    114
    +        job = self.jobs[lease.id]
    
    115
    +        lease_state = LeaseState(lease.state)
    
    117 116
     
    
    118
    -        else:
    
    119
    -            job.update_lease_state(lease_state,
    
    120
    -                                   status=lease_status, result=lease_result)
    
    117
    +        if lease_state == LeaseState.PENDING:
    
    118
    +            job.update_lease_state(LeaseState.PENDING)
    
    119
    +            job.update_operation_stage(OperationStage.QUEUED)
    
    120
    +
    
    121
    +        elif lease_state == LeaseState.ACTIVE:
    
    122
    +            job.update_lease_state(LeaseState.ACTIVE)
    
    123
    +            job.update_operation_stage(OperationStage.EXECUTING)
    
    124
    +
    
    125
    +        elif lease_state == LeaseState.COMPLETED:
    
    126
    +            job.update_lease_state(LeaseState.COMPLETED,
    
    127
    +                                   status=lease.status, result=lease.result)
    
    121 128
     
    
    122 129
                 if self._action_cache is not None and not job.do_not_cache:
    
    123 130
                     self._action_cache.update_action_result(job.action_digest, job.action_result)
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]