forked from AcademySoftwareFoundation/OpenCue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostManagerService.java
More file actions
445 lines (369 loc) · 14.9 KB
/
Copy pathHostManagerService.java
File metadata and controls
445 lines (369 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/*
* Copyright Contributors to the OpenCue Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.imageworks.spcue.service;
import java.sql.Timestamp;
import java.util.List;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.imageworks.spcue.AllocationEntity;
import com.imageworks.spcue.AllocationInterface;
import com.imageworks.spcue.DispatchHost;
import com.imageworks.spcue.EntityModificationError;
import com.imageworks.spcue.FrameInterface;
import com.imageworks.spcue.HostEntity;
import com.imageworks.spcue.HostInterface;
import com.imageworks.spcue.LocalHostAssignment;
import com.imageworks.spcue.ProcInterface;
import com.imageworks.spcue.ShowInterface;
import com.imageworks.spcue.Source;
import com.imageworks.spcue.StrandedCoreStats;
import com.imageworks.spcue.VirtualProc;
import com.imageworks.spcue.dao.AllocationDao;
import com.imageworks.spcue.dao.FacilityDao;
import com.imageworks.spcue.dao.HostDao;
import com.imageworks.spcue.dao.ProcDao;
import com.imageworks.spcue.dao.ShowDao;
import com.imageworks.spcue.dao.SubscriptionDao;
import com.imageworks.spcue.dao.criteria.FrameSearchInterface;
import com.imageworks.spcue.dao.criteria.ProcSearchInterface;
import com.imageworks.spcue.grpc.host.HardwareState;
import com.imageworks.spcue.grpc.host.HostTagType;
import com.imageworks.spcue.grpc.host.LockState;
import com.imageworks.spcue.grpc.report.HostReport;
import com.imageworks.spcue.grpc.report.RenderHost;
import com.imageworks.spcue.rqd.RqdClient;
import com.imageworks.spcue.rqd.RqdClientException;
@Transactional
public class HostManagerService implements HostManager {
private static final Logger logger = LogManager.getLogger(HostManagerService.class);
private HostDao hostDao;
private RqdClient rqdClient;
private ProcDao procDao;
private ShowDao showDao;
private FacilityDao facilityDao;
private SubscriptionDao subscriptionDao;
private AllocationDao allocationDao;
public HostManagerService() {}
@Override
public void setHostLock(HostInterface host, LockState lock, Source source) {
hostDao.updateHostLock(host, lock, source);
rqdClient.setHostLock(host, lock);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public boolean isLocked(HostInterface host) {
return hostDao.isHostLocked(host);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public boolean isHostUp(HostInterface host) {
return hostDao.isHostUp(host);
}
@Override
public void setHostState(HostInterface host, HardwareState state) {
hostDao.updateHostState(host, state);
}
@Override
public void setHostFreeTempDir(HostInterface host, Long freeTempDir) {
hostDao.updateHostFreeTempDir(host, freeTempDir);
}
public void rebootWhenIdle(HostInterface host) {
try {
hostDao.updateHostState(host, HardwareState.REBOOT_WHEN_IDLE);
rqdClient.rebootWhenIdle(host);
} catch (RqdClientException e) {
logger.info("failed to contact host: " + host.getName() + " for reboot");
}
}
public void rebootNow(HostInterface host) {
try {
hostDao.updateHostState(host, HardwareState.REBOOTING);
rqdClient.rebootNow(host);
} catch (RqdClientException e) {
logger.info("failed to contact host: " + host.getName() + " for reboot");
hostDao.updateHostState(host, HardwareState.DOWN);
}
}
@Override
public void setHostStatistics(HostInterface host, long totalMemory, long freeMemory,
long totalSwap, long freeSwap, long totalMcp, long freeMcp, long totalGpuMemory,
long freeGpuMemory, int load, Timestamp bootTime, String os) {
hostDao.updateHostStats(host, totalMemory, freeMemory, totalSwap, freeSwap, totalMcp,
freeMcp, totalGpuMemory, freeGpuMemory, load, bootTime, os);
}
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public HostInterface findHost(String name) {
return hostDao.findHost(name);
}
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public HostInterface getHost(String id) {
return hostDao.getHost(id);
}
@Transactional(propagation = Propagation.REQUIRED)
public DispatchHost createHost(HostReport report) {
return createHost(report.getHost());
}
@Transactional(propagation = Propagation.REQUIRED)
public DispatchHost createHost(RenderHost rhost) {
// Find suitable allocation with facility and tags.
AllocationEntity alloc = null;
if (rhost.getTagsCount() > 0) {
String facility = rhost.getFacility();
for (String tag : rhost.getTagsList()) {
try {
alloc = allocationDao.findAllocationEntity(facility, tag);
logger.info("set " + rhost.getName() + " to the given allocation "
+ alloc.getName());
break;
} catch (EmptyResultDataAccessException e) {
// Allocation doesn't exist. ignore.
}
}
}
if (alloc == null) {
alloc = getDefaultAllocationDetail();
logger.info("set " + rhost.getName() + " to the default allocation " + alloc.getName());
}
return createHost(rhost, alloc);
}
@Transactional(propagation = Propagation.REQUIRED)
public DispatchHost createHost(RenderHost rhost, AllocationEntity alloc) {
hostDao.insertRenderHost(rhost, alloc, false);
DispatchHost host = hostDao.findDispatchHost(rhost.getName());
hostDao.tagHost(host, alloc.tag, HostTagType.ALLOC);
hostDao.tagHost(host, host.name, HostTagType.HOSTNAME);
if (rhost.getTagsCount() > 0) {
for (String tag : rhost.getTagsList()) {
hostDao.tagHost(host, tag, HostTagType.HARDWARE);
}
}
// RQD tags (version, platform) are tagged as HARDWARE type since they represent
// technical characteristics of the host, not manual user assignments
hostDao.recalcuateTags(host.id);
return host;
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public DispatchHost findDispatchHost(String name) {
return hostDao.findDispatchHost(name);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public HostEntity findHostDetail(String name) {
return hostDao.findHostDetail(name);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public DispatchHost getDispatchHost(String id) {
return hostDao.getDispatchHost(id);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public HostEntity getHostDetail(HostInterface host) {
return hostDao.getHostDetail(host);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public HostEntity getHostDetail(String id) {
return hostDao.getHostDetail(id);
}
@Transactional(propagation = Propagation.SUPPORTS)
public AllocationEntity getDefaultAllocationDetail() {
return allocationDao.getDefaultAllocationEntity();
}
public void addTags(HostInterface host, String[] tags) {
for (String tag : tags) {
if (tag == null) {
continue;
}
if (tag.length() == 0) {
continue;
}
hostDao.tagHost(host, tag, HostTagType.MANUAL);
}
hostDao.recalcuateTags(host.getHostId());
}
public void removeTags(HostInterface host, String[] tags) {
for (String tag : tags) {
hostDao.removeTag(host, tag);
}
hostDao.recalcuateTags(host.getHostId());
}
public void renameTag(HostInterface host, String oldTag, String newTag) {
hostDao.renameTag(host, oldTag, newTag);
hostDao.recalcuateTags(host.getHostId());
}
public void setAllocation(HostInterface host, AllocationInterface alloc) {
if (procDao.findVirtualProcs(host).size() > 0) {
throw new EntityModificationError(
"You cannot move hosts with " + "running procs between allocations.");
}
hostDao.lockForUpdate(host);
hostDao.updateHostSetAllocation(host, alloc);
hostDao.recalcuateTags(host.getHostId());
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public int getStrandedCoreUnits(HostInterface h) {
return hostDao.getStrandedCoreUnits(h);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<StrandedCoreStats> getStrandedCoreStats() {
return hostDao.getStrandedCoreStats();
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public int getStrandedGpuUnits(HostInterface h) {
return hostDao.getStrandedGpus(h);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public boolean verifyRunningProc(String procId, String frameId) {
return procDao.verifyRunningProc(procId, frameId);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<VirtualProc> findVirtualProcs(FrameSearchInterface request) {
return procDao.findVirtualProcs(request);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public VirtualProc findVirtualProc(FrameInterface frame) {
return procDao.findVirtualProc(frame);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<VirtualProc> findVirtualProcs(HardwareState state) {
return procDao.findVirtualProcs(state);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<VirtualProc> findVirtualProcs(LocalHostAssignment l) {
return procDao.findVirtualProcs(l);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<VirtualProc> findVirtualProcs(ProcSearchInterface r) {
return procDao.findVirtualProcs(r);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<VirtualProc> findVirtualProcs(HostInterface host) {
return procDao.findVirtualProcs(host);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public List<VirtualProc> findBookedVirtualProcs(ProcSearchInterface r) {
return procDao.findBookedVirtualProcs(r);
}
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void unbookVirtualProcs(List<VirtualProc> procs) {
for (VirtualProc proc : procs) {
unbookProc(proc);
}
}
@Transactional(propagation = Propagation.REQUIRED)
public void unbookProc(ProcInterface proc) {
procDao.unbookProc(proc);
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void setHostResources(DispatchHost host, HostReport report) {
hostDao.updateHostResources(host, report);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public VirtualProc getVirtualProc(String id) {
return procDao.getVirtualProc(id);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public boolean isOprhan(ProcInterface proc) {
return procDao.isOrphan(proc);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public boolean isPreferShow(HostInterface host) {
return hostDao.isPreferShow(host);
}
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public ShowInterface getPreferredShow(HostInterface host) {
return showDao.getShowDetail(host);
}
public void deleteHost(HostInterface host) {
hostDao.deleteHost(host);
}
public AllocationDao getAllocationDao() {
return allocationDao;
}
public void setAllocationDao(AllocationDao allocationDao) {
this.allocationDao = allocationDao;
}
public HostDao getHostDao() {
return hostDao;
}
public void setHostDao(HostDao hostDao) {
this.hostDao = hostDao;
}
public ProcDao getProcDao() {
return procDao;
}
public void setProcDao(ProcDao procDao) {
this.procDao = procDao;
}
public RqdClient getRqdClient() {
return rqdClient;
}
public void setRqdClient(RqdClient rqdClient) {
this.rqdClient = rqdClient;
}
public FacilityDao getFacilityDao() {
return facilityDao;
}
public void setFacilityDao(FacilityDao facilityDao) {
this.facilityDao = facilityDao;
}
public ShowDao getShowDao() {
return showDao;
}
public void setShowDao(ShowDao showDao) {
this.showDao = showDao;
}
public SubscriptionDao getSubscriptionDao() {
return subscriptionDao;
}
public void setSubscriptionDao(SubscriptionDao subscriptionDao) {
this.subscriptionDao = subscriptionDao;
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
public boolean reconcileIdleResources(HostInterface host) {
return hostDao.reconcileIdleResources(host);
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void updateHostTags(DispatchHost host, RenderHost rhost) {
// Remove existing hardware tags and re-add current tags from report
hostDao.removeTagsByType(host, HostTagType.HARDWARE);
if (rhost.getTagsCount() > 0) {
for (String tag : rhost.getTagsList()) {
// Remove tag by name, regardless of type.
// It avoids duplicates if the host was first registered with
// an older version of Cuebot where those tags were of MANUAL type.
hostDao.removeTag(host, tag);
hostDao.tagHost(host, tag, HostTagType.HARDWARE);
}
}
hostDao.recalcuateTags(host.getHostId());
logger.info("Updated hardware tags for host {} with tags: {}", host.getName(),
rhost.getTagsList());
}
}