11/*
2- * Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
2+ * Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package com .iexec .core .worker ;
1818
19+ import com .iexec .commons .poco .tee .TeeUtils ;
1920import lombok .AllArgsConstructor ;
2021import lombok .Builder ;
2122import lombok .Data ;
23+ import lombok .extern .slf4j .Slf4j ;
2224import org .springframework .data .annotation .Id ;
2325import org .springframework .data .mongodb .core .index .Indexed ;
2426import org .springframework .data .mongodb .core .mapping .Document ;
2527
2628import java .util .Date ;
2729import java .util .List ;
2830
31+ @ Slf4j
2932@ Document
3033@ Data
3134@ Builder
3235@ AllArgsConstructor
3336public class Worker {
34-
3537 @ Id
3638 private String id ;
3739 private String name ;
@@ -44,8 +46,10 @@ public class Worker {
4446 private int cpuNb ;
4547 private int maxNbTasks ;
4648 private int memorySize ;
47- private boolean teeEnabled ;
4849 private boolean gpuEnabled ;
50+ // TODO remove or rename to sgxEnabled in the future
51+ private boolean teeEnabled ;
52+ private boolean tdxEnabled ;
4953 @ Builder .Default
5054 private List <String > participatingChainTaskIds = List .of ();
5155 @ Builder .Default
@@ -60,12 +64,36 @@ void addChainTaskId(String chainTaskId) {
6064 computingChainTaskIds .add (chainTaskId );
6165 }
6266
63- void removeChainTaskId (String chainTaskId ) {
64- participatingChainTaskIds .remove (chainTaskId );
65- computingChainTaskIds .remove (chainTaskId );
67+ /**
68+ * Returns excluded tags depending on worker configuration
69+ *
70+ * @return The list of excluded tags
71+ */
72+ public List <String > getExcludedTags () {
73+ if (!teeEnabled && !tdxEnabled ) {
74+ return List .of (TeeUtils .TEE_TDX_ONLY_TAG , TeeUtils .TEE_SCONE_ONLY_TAG , TeeUtils .TEE_GRAMINE_ONLY_TAG );
75+ } else if (!teeEnabled ) {
76+ return List .of (TeeUtils .TEE_SCONE_ONLY_TAG , TeeUtils .TEE_GRAMINE_ONLY_TAG );
77+ } else if (!tdxEnabled ) {
78+ return List .of (TeeUtils .TEE_TDX_ONLY_TAG );
79+ } else {
80+ // /!\ teeEnabled and tdxEnabled are both true in this branch
81+ log .warn ("Worker seems to support both SGX and TDX, this should not happen [wallet:{}]" , walletAddress );
82+ return List .of ();
83+ }
6684 }
6785
68- void removeComputedChainTaskId (String chainTaskId ) {
69- computingChainTaskIds .remove (chainTaskId );
86+ /**
87+ * Returns whether the worker can accept more work or not.
88+ *
89+ * @return {@literal true} when the worker is at max capacity, {@literal false} otherwise
90+ */
91+ public boolean hasNoRemainingComputingSlot () {
92+ final boolean areAllComputingSlotsInUse = computingChainTaskIds .size () >= maxNbTasks ;
93+ if (areAllComputingSlotsInUse ) {
94+ log .debug ("Worker is computing at max capacity [walletAddress:{}, runningReplicateNb:{}, workerMaxNbTasks:{}]" ,
95+ walletAddress , computingChainTaskIds .size (), maxNbTasks );
96+ }
97+ return areAllComputingSlotsInUse ;
7098 }
7199}
0 commit comments