public static Configuration loadConfiguration(
            String workingDirectory, Configuration dynamicParameters, Map<String, String> env) {
        final Configuration configuration =
                GlobalConfiguration.loadConfiguration(workingDirectory, dynamicParameters);

        final String keytabPrincipal = env.get(YarnConfigKeys.KEYTAB_PRINCIPAL);

        final String hostname = env.get(ApplicationConstants.Environment.NM_HOST.key());
        Preconditions.checkState(
                hostname != null,
                "ApplicationMaster hostname variable %s not set",
                ApplicationConstants.Environment.NM_HOST.key());

        configuration.set(JobManagerOptions.ADDRESS, hostname);
        configuration.set(RestOptions.ADDRESS, hostname);
        configuration.set(RestOptions.BIND_ADDRESS, hostname);

        // if a web monitor shall be started, set the port to random binding
        if (configuration.get(WebOptions.PORT, 0) >= 0) {
            configuration.set(WebOptions.PORT, 0);
        }

        if (!configuration.contains(RestOptions.BIND_PORT)) {
            // set the REST port to 0 to select it randomly
            configuration.set(RestOptions.BIND_PORT, "0");
        }

        // if the user has set the deprecated YARN-specific config keys, we add the
        // corresponding generic config keys instead. that way, later code needs not
        // deal with deprecated config keys

        BootstrapTools.substituteDeprecatedConfigPrefix(
                configuration,
                ConfigConstants.YARN_APPLICATION_MASTER_ENV_PREFIX,
                ResourceManagerOptions.CONTAINERIZED_MASTER_ENV_PREFIX);

        BootstrapTools.substituteDeprecatedConfigPrefix(
                configuration,
                ConfigConstants.YARN_TASK_MANAGER_ENV_PREFIX,
                ResourceManagerOptions.CONTAINERIZED_TASK_MANAGER_ENV_PREFIX);

        final String keytabPath =
                Utils.resolveKeytabPath(
                        workingDirectory, env.get(YarnConfigKeys.LOCAL_KEYTAB_PATH));

        if (keytabPath != null && keytabPrincipal != null) {
            configuration.set(SecurityOptions.KERBEROS_LOGIN_KEYTAB, keytabPath);
            configuration.set(SecurityOptions.KERBEROS_LOGIN_PRINCIPAL, keytabPrincipal);
        }

        final String localDirs = env.get(ApplicationConstants.Environment.LOCAL_DIRS.key());
        BootstrapTools.updateTmpDirectoriesInConfiguration(configuration, localDirs);

        return configuration;
    }
@Test
    void testDynamicParameterOverloading() throws IOException {
        final Configuration initialConfiguration = new Configuration();
        initialConfiguration.set(JobManagerOptions.JVM_METASPACE, MemorySize.ofMebiBytes(1));

        Configuration dynamicParameters = new Configuration();
        dynamicParameters.set(JobManagerOptions.JVM_METASPACE, MemorySize.MAX_VALUE);
        Configuration overloadedConfiguration =
                loadConfiguration(initialConfiguration, dynamicParameters);

        assertThat(overloadedConfiguration.get(JobManagerOptions.JVM_METASPACE))
                .isEqualTo(MemorySize.MAX_VALUE);
    }