in server/src/main/java/org/eclipse/jifa/server/service/impl/WorkerServiceImpl.java [163:216]
public FileLocation decideLocationForNewFile(UserEntity user, FileType type) {
FileLocationRuleEntity rule = null;
if (fileLocationRuleRepo.count() > 0) {
// find by user and file type
rule = fileLocationRuleRepo.findByUserAndFileType(user, type);
if (rule == null) {
// find by user
rule = fileLocationRuleRepo.findByUserAndFileType(user, null);
}
if (rule == null) {
// find by file type
rule = fileLocationRuleRepo.findByUserAndFileType(null, type);
}
if (rule == null) {
// default
rule = fileLocationRuleRepo.findByUserAndFileType(null, null);
}
}
Optional<StaticWorkerEntity> staticWorker;
if (rule == null) {
if (storageService.available()) {
return new FileLocation(true, null);
}
staticWorker = staticWorkerRepo.findFirstByOrderByAvailableSpaceDesc();
} else {
switch (rule.getRule()) {
case SHARED_STORAGE -> {
return new FileLocation(true, null);
}
case STATIC_WORKERS -> {
staticWorker = staticWorkerRepo.findFirstByOrderByAvailableSpaceDesc();
}
case LABELED_STATIC_WORKERS -> {
staticWorker = staticWorkerLabelRepo.findByLabel(rule.getLabel()).stream()
.sorted(Comparator.comparingLong(e -> e.getStaticWorker().getAvailableSpace()))
.reduce((f, s) -> s).map(StaticWorkerLabelEntity::getStaticWorker);
}
default -> throw new ShouldNotReachHereException();
}
}
if (staticWorker.isPresent()) {
return new FileLocation(false, staticWorker.get());
}
throw CE(NO_AVAILABLE_LOCATION);
}