2323import org .apache .flink .configuration .ConfigConstants ;
2424import org .apache .flink .configuration .Configuration ;
2525import org .apache .flink .core .fs .FileSystem ;
26- import org .apache .flink .runtime . security . SecurityConfiguration ;
27- import org .apache .flink .runtime . security . SecurityUtils ;
26+ import org .apache .flink .util . FileUtils ;
27+ import org .apache .flink .util . function . FunctionUtils ;
2828import org .apache .flink .yarn .YarnClientYarnClusterInformationRetriever ;
2929import org .apache .flink .yarn .YarnClusterDescriptor ;
3030import org .apache .hadoop .yarn .client .api .YarnClient ;
3131import org .apache .hadoop .yarn .conf .YarnConfiguration ;
3232
3333import java .io .File ;
34+ import java .io .IOException ;
3435import java .util .Iterator ;
3536import java .util .Map ;
3637
4142 * @author maqi
4243 */
4344public class YarnClusterClientFactory extends AbstractClusterClientFactory {
45+ private static final String XML_FILE_EXTENSION = "xml" ;
4446 @ Override
4547 public ClusterDescriptor createClusterDescriptor (String yarnConfDir , Configuration flinkConfig ) {
4648
@@ -70,27 +72,12 @@ public ClusterDescriptor createClusterDescriptor(String yarnConfDir, Configurati
7072 }
7173 }
7274
73- private YarnConfiguration getYarnConf (String yarnConfDir ) {
75+ private YarnConfiguration getYarnConf (String yarnConfDir ) throws IOException {
7476 YarnConfiguration yarnConf = new YarnConfiguration ();
75- try {
76- File dir = new File (yarnConfDir );
77- if (dir .exists () && dir .isDirectory ()) {
78- File [] xmlFileList = new File (yarnConfDir ).listFiles ((dir1 , name ) -> {
79- if (name .endsWith (".xml" )) {
80- return true ;
81- }
82- return false ;
83- });
84- if (xmlFileList != null ) {
85- for (File xmlFile : xmlFileList ) {
86- yarnConf .addResource (xmlFile .toURI ().toURL ());
87- }
88- }
89- }
90-
91- } catch (Exception e ) {
92- throw new RuntimeException (e );
93- }
77+ FileUtils .listFilesInDirectory (new File (yarnConfDir ).toPath (), this ::isXmlFile )
78+ .stream ()
79+ .map (FunctionUtils .uncheckedFunction (FileUtils ::toURL ))
80+ .forEach (yarnConf ::addResource );
9481
9582 haYarnConf (yarnConf );
9683 return yarnConf ;
@@ -101,8 +88,7 @@ private YarnConfiguration getYarnConf(String yarnConfDir) {
10188 */
10289 private org .apache .hadoop .conf .Configuration haYarnConf (org .apache .hadoop .conf .Configuration yarnConf ) {
10390 Iterator <Map .Entry <String , String >> iterator = yarnConf .iterator ();
104- while (iterator .hasNext ()) {
105- Map .Entry <String , String > entry = iterator .next ();
91+ iterator .forEachRemaining ((Map .Entry <String , String > entry ) -> {
10692 String key = entry .getKey ();
10793 String value = entry .getValue ();
10894 if (key .startsWith ("yarn.resourcemanager.hostname." )) {
@@ -112,7 +98,12 @@ private org.apache.hadoop.conf.Configuration haYarnConf(org.apache.hadoop.conf.C
11298 yarnConf .set (addressKey , value + ":" + YarnConfiguration .DEFAULT_RM_PORT );
11399 }
114100 }
115- }
101+ });
102+
116103 return yarnConf ;
117104 }
105+
106+ private boolean isXmlFile (java .nio .file .Path file ) {
107+ return XML_FILE_EXTENSION .equals (org .apache .flink .shaded .guava18 .com .google .common .io .Files .getFileExtension (file .toString ()));
108+ }
118109}
0 commit comments