fix(pool): migrate legacy coordinator state before worker heartbeats
This commit is contained in:
parent
c40c3fdb61
commit
828a9f2f3f
1 changed files with 5 additions and 2 deletions
|
|
@ -20,6 +20,9 @@ def read_state():
|
|||
def write_state(value):
|
||||
STATE.parent.mkdir(parents=True, exist_ok=True); tmp=STATE.with_suffix('.tmp'); tmp.write_text(json.dumps(value,ensure_ascii=False,indent=2)+'\n'); tmp.replace(STATE)
|
||||
|
||||
def normalized_state():
|
||||
value=read_state(); value.setdefault('workers',{}); value.setdefault('leases',{}); value.setdefault('registered_workers',len(value['workers'])); return value
|
||||
|
||||
def authorized(handler):
|
||||
try:
|
||||
subject=handler.connection.getpeercert().get('subject',())
|
||||
|
|
@ -39,13 +42,13 @@ class Handler(BaseHTTPRequestHandler):
|
|||
try: payload=json.loads(self.rfile.read(int(self.headers.get('Content-Length','0')) or 0) or b'{}')
|
||||
except Exception: self.send_json(400,{'error':'JSON_INVALID'}); return
|
||||
with LOCK:
|
||||
state=read_state()
|
||||
state=normalized_state()
|
||||
if self.path=='/v1/worker/heartbeat':
|
||||
node=payload.get('node_id');
|
||||
if not node or node=='JD-FD-PRIMARY': self.send_json(403,{'error':'MOTHER_NODE_FORBIDDEN'}); return
|
||||
peer=next((value for group in self.connection.getpeercert().get('subject',()) for key,value in group if key=='commonName'),None)
|
||||
if node != peer: self.send_json(403,{'error':'WORKER_CERT_ID_MISMATCH'}); return
|
||||
state['workers'][node]={**payload,'last_seen':payload.get('observed_at'),'authority_granted':False}; write_state(state); self.send_json(200,{'outcome':'HEARTBEAT_ACCEPTED','node_id':node,'authority_granted':False}); return
|
||||
state['workers'][node]={**payload,'last_seen':payload.get('observed_at'),'authority_granted':False}; state['registered_workers']=len(state['workers']); write_state(state); self.send_json(200,{'outcome':'HEARTBEAT_ACCEPTED','node_id':node,'authority_granted':False}); return
|
||||
if self.path=='/v1/lease/request':
|
||||
self.send_json(200,{'outcome':'LEASE_QUEUED','state':'PENDING_DETERMINISTIC_SELECTION','authority_granted':False}); return
|
||||
self.send_json(404,{'error':'NOT_FOUND'})
|
||||
|
|
|
|||
Loading…
Reference in a new issue