3232from .models import (
3333 ComputeServiceID ,
3434 ComputeServiceRegistration ,
35+ ComputeManagerRegistration ,
3536 ComputeManagerID ,
3637 ComputeManagerStatus ,
3738 NetworkMark ,
@@ -1358,45 +1359,91 @@ def compute_service_can_claim(
13581359
13591360 ## compute manager
13601361
1361- def get_compute_manager_compute_services (
1362+ def get_compute_manager_compute_service_ids (
13621363 self , compute_manager_id : ComputeManagerID
13631364 ):
1364- raise NotImplementedError
1365+
1366+ manager_id , uuid = compute_manager_id .manager_id , compute_manager_id .uuid
1367+
1368+ query = """
1369+ MATCH (:ComputeManagerRegistration {manager_id: $manager_id, uuid: $uuid})-[:MANAGES]->(csr:ComputeServiceRegistration)
1370+ RETURN csr.identifier as id
1371+ """
1372+
1373+ results = self .execute_query (query , manager_id = manager_id , uuid = uuid )
1374+
1375+ ids = []
1376+ for record in results .records :
1377+ ids .append (ComputeServiceID (record ["id" ]))
1378+
1379+ return ids
13651380
13661381 def deregister_computemanager (
13671382 self , compute_manager_id : ComputeManagerID , force = False
13681383 ):
1369- name , uuid = compute_manager_id .name , compute_manager_id .uuid
1384+ manager_id , uuid = compute_manager_id .manager_id , compute_manager_id .uuid
13701385
13711386 full_delete_query = """
1372- MATCH (csm:ComputeServiceManager {name : $name , uuid: $uuid})
1387+ MATCH (csm:ComputeServiceManager {manager_id : $manager_id , uuid: $uuid})
13731388 DELETE csm
13741389 RETURN
13751390 """
13761391
13771392 if force :
1378- self .execute_query (full_delete_query , name = name , uuid = uuid )
1393+ self .execute_query (full_delete_query , manager_id = manager_id , uuid = uuid )
13791394 return compute_manager_id
13801395
13811396 query = """
1382- MATCH (csm: ComputeServiceManager {name : $name , uuid: $uuid})-[rel:MANAGES]->(ComputeServiceRegistration)
1397+ MATCH (csm: ComputeServiceManager {manager_id : $manager_id , uuid: $uuid})-[rel:MANAGES]->(ComputeServiceRegistration)
13831398 DELETE rel
13841399 RETURN csm.status AS status
13851400 """
13861401
1387- results = self .execute_query (query , name = name , uuid = uuid )
1402+ results = self .execute_query (query , manager_id = manager_id , uuid = uuid )
13881403
13891404 if (
13901405 ComputeManagerStatus (results .records [0 ]["status" ])
13911406 != ComputeManagerStatus .ERRORED
13921407 ):
1393- self .execute_query (full_delete_query , name = name , uuid = uuid )
1408+ self .execute_query (full_delete_query , manager_id = manager_id , uuid = uuid )
13941409
1395- def register_computemanager (self , compute_manager_id : ComputeManagerID ):
1396- raise NotImplementedError
1410+ def register_computemanager (
1411+ self , compute_manager_registration : ComputeManagerRegistration
1412+ ):
1413+ node = Node (
1414+ "ComputeManagerRegistration" , ** compute_manager_registration .to_dict ()
1415+ )
1416+
1417+ with self .transaction () as tx :
1418+ create_subgraph (tx , Subgraph () | node )
1419+
1420+ identifier = (
1421+ compute_manager_registration .manager_id
1422+ + "-"
1423+ + compute_manager_registration .uuid
1424+ )
1425+ return identifier
13971426
13981427 def expire_computemanager_registrations (self , expire_time : datetime ):
1399- raise NotImplementedError
1428+ query = """
1429+ MATCH (cmr:ComputeManagerRegistration)
1430+ WHERE cmr.last_status_update < localdatetime($expire_time)
1431+
1432+ DETACH DELETE cmr
1433+
1434+ RETURN cmr.manager_id as id, cmr.uuid as uuid
1435+ """
1436+
1437+ results = self .execute_query (query , expire_time = expire_time .isoformat ())
1438+
1439+ identities = set ()
1440+ for record in results :
1441+ compute_manager_id = ComputeManagerID (
1442+ record ["manager_id" ] + "-" + record ["uuid" ]
1443+ )
1444+ identities .add (compute_manager_id )
1445+
1446+ return identities
14001447
14011448 def get_computemanager_instruction (
14021449 self ,
@@ -1405,15 +1452,15 @@ def get_computemanager_instruction(
14051452 max_failures : int ,
14061453 ) -> ComputeManagerInstruction :
14071454
1408- name , uuid = compute_manager_id .name , compute_manager_id .uuid
1455+ manager_id , uuid = compute_manager_id .manager_id , compute_manager_id .uuid
14091456
14101457 query = """
1411- MATCH (csm: ComputeServiceManager {name : $name , uuid: $uuid})
1458+ MATCH (csm: ComputeServiceManager {manager_id : $manager_id , uuid: $uuid})
14121459 OPTIONAL MATCH (csm)-[rel:MANAGES]->(csr: ComputeServiceRegistration)
14131460 RETURN csm, csr.identifier as csr_id
14141461 """
14151462
1416- results = self .execute_query (query , name = name , uuid = uuid )
1463+ results = self .execute_query (query , manager_id = manager_id , uuid = uuid )
14171464
14181465 # no compute manager was found the given name and UUID
14191466 if len (results .records ) == 0 :
@@ -1441,17 +1488,17 @@ def update_compute_manager_status(
14411488 ):
14421489 status = ComputeManagerStatus (status )
14431490
1444- name , uuid = compute_manager_id .name , compute_manager_id .uuid
1491+ manager_id , uuid = compute_manager_id .manager_id , compute_manager_id .uuid
14451492
14461493 query = """
1447- MATCH (csm: ComputeServiceManager {name : $name , uuid: $uuid})
1494+ MATCH (csm: ComputeServiceManager {manager_id : $manager_id , uuid: $uuid})
14481495 SET csm.status = $status
14491496 SET csm.detail = $detail
14501497 RETURN csm
14511498 """
14521499
14531500 results = self .execute_query (
1454- query , status = str (status ), uuid = uuid , name = name , detail = detail
1501+ query , status = str (status ), uuid = uuid , manager_id = manager_id , detail = detail
14551502 )
14561503
14571504 if len (results .records ) == 0 :
0 commit comments