@@ -48,6 +48,10 @@ public void setBlacklistedHosts(Set<String> hosts) {
48
48
blackListedHosts = hosts ;
49
49
}
50
50
51
+ public Set <String > getBlacklistedHosts () {
52
+ return blackListedHosts ;
53
+ }
54
+
51
55
public void blacklistHost (String host ) {
52
56
// this is so it plays well with setting blackListedHosts to an immutable list
53
57
if (blackListedHosts ==null ) blackListedHosts = new HashSet <String >();
@@ -147,9 +151,9 @@ public Map<String, List<ExecutorDetails>> getNeedsSchedulingComponentToExecutors
147
151
* @param cluster
148
152
* @return
149
153
*/
150
- public List <Integer > getUsedPorts (SupervisorDetails supervisor ) {
154
+ public Set <Integer > getUsedPorts (SupervisorDetails supervisor ) {
151
155
Map <String , SchedulerAssignment > assignments = this .getAssignments ();
152
- List <Integer > usedPorts = new ArrayList <Integer >();
156
+ Set <Integer > usedPorts = new HashSet <Integer >();
153
157
154
158
for (SchedulerAssignment assignment : assignments .values ()) {
155
159
for (WorkerSlot slot : assignment .getExecutorToSlot ().values ()) {
@@ -168,15 +172,20 @@ public List<Integer> getUsedPorts(SupervisorDetails supervisor) {
168
172
* @param cluster
169
173
* @return
170
174
*/
171
- public List <Integer > getAvailablePorts (SupervisorDetails supervisor ) {
172
- List <Integer > usedPorts = this .getUsedPorts (supervisor );
175
+ public Set <Integer > getAvailablePorts (SupervisorDetails supervisor ) {
176
+ Set <Integer > usedPorts = this .getUsedPorts (supervisor );
173
177
174
- List <Integer > ret = new ArrayList < Integer > ();
175
- ret .addAll (supervisor . allPorts );
178
+ Set <Integer > ret = new HashSet ();
179
+ ret .addAll (getAssignablePorts ( supervisor ) );
176
180
ret .removeAll (usedPorts );
177
181
178
182
return ret ;
179
183
}
184
+
185
+ public Set <Integer > getAssignablePorts (SupervisorDetails supervisor ) {
186
+ if (isBlackListed (supervisor .id )) return new HashSet ();
187
+ return supervisor .allPorts ;
188
+ }
180
189
181
190
/**
182
191
* Return all the available slots on this supervisor.
@@ -185,8 +194,7 @@ public List<Integer> getAvailablePorts(SupervisorDetails supervisor) {
185
194
* @return
186
195
*/
187
196
public List <WorkerSlot > getAvailableSlots (SupervisorDetails supervisor ) {
188
- if (isBlackListed (supervisor .id )) return new ArrayList ();
189
- List <Integer > ports = this .getAvailablePorts (supervisor );
197
+ Set <Integer > ports = this .getAvailablePorts (supervisor );
190
198
List <WorkerSlot > slots = new ArrayList <WorkerSlot >(ports .size ());
191
199
192
200
for (Integer port : ports ) {
@@ -196,6 +204,17 @@ public List<WorkerSlot> getAvailableSlots(SupervisorDetails supervisor) {
196
204
return slots ;
197
205
}
198
206
207
+ public List <WorkerSlot > getAssignableSlots (SupervisorDetails supervisor ) {
208
+ Set <Integer > ports = this .getAssignablePorts (supervisor );
209
+ List <WorkerSlot > slots = new ArrayList <WorkerSlot >(ports .size ());
210
+
211
+ for (Integer port : ports ) {
212
+ slots .add (new WorkerSlot (supervisor .getId (), port ));
213
+ }
214
+
215
+ return slots ;
216
+ }
217
+
199
218
/**
200
219
* get the unassigned executors of the topology.
201
220
*/
@@ -271,6 +290,15 @@ public List<WorkerSlot> getAvailableSlots() {
271
290
272
291
return slots ;
273
292
}
293
+
294
+ public List <WorkerSlot > getAssignableSlots () {
295
+ List <WorkerSlot > slots = new ArrayList <WorkerSlot >();
296
+ for (SupervisorDetails supervisor : this .supervisors .values ()) {
297
+ slots .addAll (this .getAssignableSlots (supervisor ));
298
+ }
299
+
300
+ return slots ;
301
+ }
274
302
275
303
/**
276
304
* Free the specified slot.
0 commit comments