class Utils {

	@VisibleForTesting
	static Resource getUnitResource(YarnConfiguration yarnConfig) {
		final int unitMemMB, unitVcore;

		final String yarnRmSchedulerClazzName = yarnConfig.get(YarnConfiguration.RM_SCHEDULER);
		if (Objects.equals(yarnRmSchedulerClazzName, YARN_RM_FAIR_SCHEDULER_CLAZZ) ||
				Objects.equals(yarnRmSchedulerClazzName, YARN_RM_SLS_FAIR_SCHEDULER_CLAZZ)) {
			String propMem = yarnConfig.get(YARN_RM_INCREMENT_ALLOCATION_MB_KEY);
			String propVcore = yarnConfig.get(YARN_RM_INCREMENT_ALLOCATION_VCORES_KEY);

			unitMemMB = propMem != null ?
					Integer.parseInt(propMem) :
					yarnConfig.getInt(YARN_RM_INCREMENT_ALLOCATION_MB_LEGACY_KEY, DEFAULT_YARN_RM_INCREMENT_ALLOCATION_MB);
			unitVcore = propVcore != null ?
					Integer.parseInt(propVcore) :
					yarnConfig.getInt(YARN_RM_INCREMENT_ALLOCATION_VCORES_LEGACY_KEY, DEFAULT_YARN_RM_INCREMENT_ALLOCATION_VCORES);
		} else {
			unitMemMB = yarnConfig.getInt(
					YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB,
					YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB);
			unitVcore = yarnConfig.getInt(
					YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES,
					YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES);
		}

		return Resource.newInstance(unitMemMB, unitVcore);
	}

	private  Utils();

}