Search in sources :

Example 6 with StringUtils.defaultIfEmpty

use of org.apache.commons.lang3.StringUtils.defaultIfEmpty in project graylog2-server by Graylog2.

the class OshiFsProbe method init.

private void init() {
    final OperatingSystem os = service.getOs();
    final FileSystem fileSystem = os.getFileSystem();
    final HardwareAbstractionLayer hardware = service.getHal();
    for (Path location : locations) {
        Path path = location.toAbsolutePath();
        oshiFileSystems.put(path, fileSystem.getFileStores().stream().filter(fs -> path.startsWith(fs.getMount())).max(Comparator.comparingInt(p -> Paths.get(p.getMount()).getNameCount())).map(fs -> {
            // First try search for the diskstore with the logical volume or volume name
            Optional<HWDiskStore> diskStore = hardware.getDiskStores().stream().filter(ds -> ds.getName().equals(StringUtils.defaultIfEmpty(fs.getLogicalVolume(), fs.getVolume()))).findFirst();
            if (diskStore.isPresent()) {
                return new Pair<>(fs, diskStore.get());
            }
            // Try to search for the diskstore with the partition of our mountpoint
            diskStore = hardware.getDiskStores().stream().filter(ds -> ds.getPartitions().stream().anyMatch(part -> path.startsWith(part.getMountPoint()))).max(Comparator.comparingInt(ds -> ds.getPartitions().stream().filter(part -> path.startsWith(part.getMountPoint())).mapToInt(part -> Paths.get(part.getMountPoint()).getNameCount()).max().orElse(0)));
            if (diskStore.isPresent()) {
                return new Pair<>(fs, diskStore.get());
            }
            return new Pair<>(fs, generateDummyDiskStore());
        }).orElse(new Pair<>(generateDummyFileStore(), generateDummyDiskStore())));
    }
}
Also used : OperatingSystem(oshi.software.os.OperatingSystem) HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) Path(java.nio.file.Path) Pair(oshi.util.tuples.Pair) java.util(java.util) ImmutableSet(com.google.common.collect.ImmutableSet) KafkaJournalConfiguration(org.graylog2.plugin.KafkaJournalConfiguration) AbstractOSFileStore(oshi.software.common.AbstractOSFileStore) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) AbstractHWDiskStore(oshi.hardware.common.AbstractHWDiskStore) OSFileStore(oshi.software.os.OSFileStore) OperatingSystem(oshi.software.os.OperatingSystem) Inject(javax.inject.Inject) FileSystem(oshi.software.os.FileSystem) Configuration(org.graylog2.Configuration) Paths(java.nio.file.Paths) HWDiskStore(oshi.hardware.HWDiskStore) HardwareAbstractionLayer(oshi.hardware.HardwareAbstractionLayer) HWPartition(oshi.hardware.HWPartition) Path(java.nio.file.Path) OshiService(org.graylog2.shared.system.stats.OshiService) FileSystem(oshi.software.os.FileSystem) AbstractHWDiskStore(oshi.hardware.common.AbstractHWDiskStore) HWDiskStore(oshi.hardware.HWDiskStore) Pair(oshi.util.tuples.Pair)

Aggregations

StringUtils (org.apache.commons.lang3.StringUtils)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 Function (java.util.function.Function)4 UserException (org.apache.drill.common.exceptions.UserException)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)4 TypeProtos (org.apache.drill.common.types.TypeProtos)4 Types (org.apache.drill.common.types.Types)4 OutOfMemoryException (org.apache.drill.exec.exception.OutOfMemoryException)4 ColumnNamesOptions (org.apache.drill.exec.metastore.ColumnNamesOptions)4 AnalyzeColumnUtils (org.apache.drill.exec.metastore.analyze.AnalyzeColumnUtils)4