All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.vespa.hosted.provision.provisioning.NodeResourceComparator Maven / Gradle / Ivy

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.provisioning;

import com.yahoo.config.provision.NodeResources;

import java.util.Comparator;

/**
 * Resource comparator
 *
 * @author bratseth
 */
public class NodeResourceComparator {

    private static final MemoryDiskCpu memoryDiskCpuComparator = new MemoryDiskCpu();

    /** Returns the default ordering */
    public static Comparator defaultOrder() { return memoryDiskCpuOrder(); }

    /** Returns a comparator comparing by memory, disk, vcpu */
    public static Comparator memoryDiskCpuOrder() { return memoryDiskCpuComparator; }

    private static class MemoryDiskCpu implements Comparator {

        @Override
        public int compare(NodeResources a, NodeResources b) {
            if (a.memoryGiB() > b.memoryGiB()) return 1;
            if (a.memoryGiB() < b.memoryGiB()) return -1;
            if (a.diskGb() > b.diskGb()) return 1;
            if (a.diskGb() < b.diskGb()) return -1;
            if (a.vcpu() > b.vcpu()) return 1;
            if (a.vcpu() < b.vcpu()) return -1;

            int storageTypeComparison = NodeResources.StorageType.compare(a.storageType(), b.storageType());
            if (storageTypeComparison != 0) return storageTypeComparison;

            return compare(a.diskSpeed(), b.diskSpeed());
        }

        private int compare(NodeResources.DiskSpeed a, NodeResources.DiskSpeed b) {
            if (a == b) return 0;
            if (a == NodeResources.DiskSpeed.slow) return -1;
            if (b == NodeResources.DiskSpeed.slow) return 1;
            return 0;
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy