lvyanquan commented on code in PR #26502: URL: https://github.com/apache/flink/pull/26502#discussion_r2086718654
########## flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterDescriptor.java: ########## @@ -1568,151 +1568,78 @@ public static ApplicationSubmissionContextReflector getInstance() { @Nullable private final Method nodeLabelExpressionMethod; private ApplicationSubmissionContextReflector(Class<ApplicationSubmissionContext> clazz) { - Method applicationTagsMethod; - Method attemptFailuresValidityIntervalMethod; - Method keepContainersMethod; - Method nodeLabelExpressionMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - applicationTagsMethod = clazz.getMethod(APPLICATION_TAGS_METHOD_NAME, Set.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - applicationTagsMethod = null; - } - - this.applicationTagsMethod = applicationTagsMethod; - - try { - // this method is only supported by Hadoop 2.6.0 onwards - attemptFailuresValidityIntervalMethod = - clazz.getMethod(ATTEMPT_FAILURES_METHOD_NAME, long.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - attemptFailuresValidityIntervalMethod = null; - } - - this.attemptFailuresValidityIntervalMethod = attemptFailuresValidityIntervalMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - keepContainersMethod = clazz.getMethod(KEEP_CONTAINERS_METHOD_NAME, boolean.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - keepContainersMethod = null; - } - - this.keepContainersMethod = keepContainersMethod; + this.applicationTagsMethod = getMethod(clazz, APPLICATION_TAGS_METHOD_NAME, Set.class); + this.attemptFailuresValidityIntervalMethod = + getMethod(clazz, ATTEMPT_FAILURES_METHOD_NAME, long.class); + this.keepContainersMethod = + getMethod(clazz, KEEP_CONTAINERS_METHOD_NAME, boolean.class); + this.nodeLabelExpressionMethod = + getMethod(clazz, NODE_LABEL_EXPRESSION_NAME, String.class); + } + private Method getMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) { try { - nodeLabelExpressionMethod = - clazz.getMethod(NODE_LABEL_EXPRESSION_NAME, String.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - NODE_LABEL_EXPRESSION_NAME); + Method method = clazz.getMethod(methodName, paramTypes); + LOG.debug("{} supports method {}.", clazz.getCanonicalName(), methodName); + return method; } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - NODE_LABEL_EXPRESSION_NAME); - nodeLabelExpressionMethod = null; + LOG.debug("{} does not support method {}.", clazz.getCanonicalName(), methodName); + return null; Review Comment: // assign null because the Hadoop version apparently does not support this call. ########## flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterDescriptor.java: ########## @@ -1568,151 +1568,78 @@ public static ApplicationSubmissionContextReflector getInstance() { @Nullable private final Method nodeLabelExpressionMethod; private ApplicationSubmissionContextReflector(Class<ApplicationSubmissionContext> clazz) { - Method applicationTagsMethod; - Method attemptFailuresValidityIntervalMethod; - Method keepContainersMethod; - Method nodeLabelExpressionMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - applicationTagsMethod = clazz.getMethod(APPLICATION_TAGS_METHOD_NAME, Set.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - applicationTagsMethod = null; - } - - this.applicationTagsMethod = applicationTagsMethod; - - try { - // this method is only supported by Hadoop 2.6.0 onwards - attemptFailuresValidityIntervalMethod = - clazz.getMethod(ATTEMPT_FAILURES_METHOD_NAME, long.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - attemptFailuresValidityIntervalMethod = null; - } - - this.attemptFailuresValidityIntervalMethod = attemptFailuresValidityIntervalMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - keepContainersMethod = clazz.getMethod(KEEP_CONTAINERS_METHOD_NAME, boolean.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - keepContainersMethod = null; - } - - this.keepContainersMethod = keepContainersMethod; + this.applicationTagsMethod = getMethod(clazz, APPLICATION_TAGS_METHOD_NAME, Set.class); + this.attemptFailuresValidityIntervalMethod = + getMethod(clazz, ATTEMPT_FAILURES_METHOD_NAME, long.class); + this.keepContainersMethod = Review Comment: // this method is only supported by Hadoop 2.4.0 onwards ########## flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterDescriptor.java: ########## @@ -1568,151 +1568,78 @@ public static ApplicationSubmissionContextReflector getInstance() { @Nullable private final Method nodeLabelExpressionMethod; private ApplicationSubmissionContextReflector(Class<ApplicationSubmissionContext> clazz) { - Method applicationTagsMethod; - Method attemptFailuresValidityIntervalMethod; - Method keepContainersMethod; - Method nodeLabelExpressionMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - applicationTagsMethod = clazz.getMethod(APPLICATION_TAGS_METHOD_NAME, Set.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - applicationTagsMethod = null; - } - - this.applicationTagsMethod = applicationTagsMethod; - - try { - // this method is only supported by Hadoop 2.6.0 onwards - attemptFailuresValidityIntervalMethod = - clazz.getMethod(ATTEMPT_FAILURES_METHOD_NAME, long.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - attemptFailuresValidityIntervalMethod = null; - } - - this.attemptFailuresValidityIntervalMethod = attemptFailuresValidityIntervalMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - keepContainersMethod = clazz.getMethod(KEEP_CONTAINERS_METHOD_NAME, boolean.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - keepContainersMethod = null; - } - - this.keepContainersMethod = keepContainersMethod; + this.applicationTagsMethod = getMethod(clazz, APPLICATION_TAGS_METHOD_NAME, Set.class); Review Comment: Please add the previously existing comments: // this method is only supported by Hadoop 2.4.0 onwards ########## flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterDescriptor.java: ########## @@ -1568,151 +1568,78 @@ public static ApplicationSubmissionContextReflector getInstance() { @Nullable private final Method nodeLabelExpressionMethod; private ApplicationSubmissionContextReflector(Class<ApplicationSubmissionContext> clazz) { - Method applicationTagsMethod; - Method attemptFailuresValidityIntervalMethod; - Method keepContainersMethod; - Method nodeLabelExpressionMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - applicationTagsMethod = clazz.getMethod(APPLICATION_TAGS_METHOD_NAME, Set.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - APPLICATION_TAGS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - applicationTagsMethod = null; - } - - this.applicationTagsMethod = applicationTagsMethod; - - try { - // this method is only supported by Hadoop 2.6.0 onwards - attemptFailuresValidityIntervalMethod = - clazz.getMethod(ATTEMPT_FAILURES_METHOD_NAME, long.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - ATTEMPT_FAILURES_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - attemptFailuresValidityIntervalMethod = null; - } - - this.attemptFailuresValidityIntervalMethod = attemptFailuresValidityIntervalMethod; - - try { - // this method is only supported by Hadoop 2.4.0 onwards - keepContainersMethod = clazz.getMethod(KEEP_CONTAINERS_METHOD_NAME, boolean.class); - LOG.debug( - "{} supports method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - } catch (NoSuchMethodException e) { - LOG.debug( - "{} does not support method {}.", - clazz.getCanonicalName(), - KEEP_CONTAINERS_METHOD_NAME); - // assign null because the Hadoop version apparently does not support this call. - keepContainersMethod = null; - } - - this.keepContainersMethod = keepContainersMethod; + this.applicationTagsMethod = getMethod(clazz, APPLICATION_TAGS_METHOD_NAME, Set.class); + this.attemptFailuresValidityIntervalMethod = Review Comment: // this method is only supported by Hadoop 2.6.0 onwards -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org