class YarnWorkerResourceSpecFactory extends WorkerResourceSpecFactory {

	@VisibleForTesting
	static CPUResource getDefaultCpus(final Configuration configuration) {
		int fallback = configuration.getInteger(YarnConfigOptions.VCORES);
		double cpuCoresDouble = TaskExecutorProcessUtils.getCpuCoresWithFallback(configuration, fallback).getValue().doubleValue();
		@SuppressWarnings("NumericCastThatLosesPrecision")
		long cpuCoresLong = Math.max((long) Math.ceil(cpuCoresDouble), 1L);
		//noinspection FloatingPointEquality
		if (cpuCoresLong != cpuCoresDouble) {
			LOG.info(
				"The amount of cpu cores must be a positive integer on Yarn. Rounding {} up to the closest positive integer {}.",
				cpuCoresDouble,
				cpuCoresLong);
		}
		if (cpuCoresLong > Integer.MAX_VALUE) {
			throw new IllegalConfigurationException(String.format(
				"The amount of cpu cores %d cannot exceed Integer.MAX_VALUE: %d",
				cpuCoresLong,
				Integer.MAX_VALUE));
		}
		//noinspection NumericCastThatLosesPrecision
		return new CPUResource(cpuCoresLong);
	}

	private  YarnWorkerResourceSpecFactory();

}