Github user mxm commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2425#discussion_r86340045
  
    --- Diff: 
flink-yarn/src/main/java/org/apache/flink/yarn/cli/FlinkYarnSessionCli.java ---
    @@ -788,75 +719,125 @@ private void logAndSysout(String message) {
                }
        }
     
    -   public static File getYarnPropertiesLocation(Configuration conf) {
    -           String defaultPropertiesFileLocation = 
System.getProperty("java.io.tmpdir");
    -           String currentUser = System.getProperty("user.name");
    -           String propertiesFileLocation =
    -                   
conf.getString(ConfigConstants.YARN_PROPERTIES_FILE_LOCATION, 
defaultPropertiesFileLocation);
    -
    -           return new File(propertiesFileLocation, YARN_PROPERTIES_FILE + 
currentUser);
    +   public static File getYarnPropertiesLocation() {
    +           String path = System.getProperty("user.home") + File.separator 
+ YARN_APP_INI;
    +           File stateFile;
    +           try {
    +                   stateFile = new File(path);
    +                   if(!stateFile.exists()) {
    +                           stateFile.createNewFile();
    +                   }
    +           } catch(IOException e) {
    +                   throw new RuntimeException(e);
    +           }
    +           return stateFile;
        }
     
    -   public static void persistAppState(String appId, String cookie) {
    -           if(appId == null || cookie == null) {
    -                   return;
    +   public static void persistAppState(YarnAppState appState) {
    +
    +           final String appId = appState.getApplicationId();
    +           final String parallelism = appState.getParallelism();
    +           final String dynaProps = appState.getDynamicProperties();
    +           final String cookie = appState.getCookie();
    +
    +           if(appId == null) {
    +                   throw new RuntimeException("Missing application ID from 
Yarn application state");
                }
    -           String path = System.getProperty("user.home") + File.separator 
+ fileName;
    -           LOG.debug("Going to persist cookie for the appID: {} in {} ", 
appId, path);
    +
    +           String path = getYarnPropertiesLocation().getAbsolutePath();
    +
    +           LOG.debug("Going to persist Yarn application state: {} in {}", 
appState,path);
    +
                try {
    -                   File f = new File(path);
    -                   if(!f.exists()) {
    -                           f.createNewFile();
    -                   }
                        HierarchicalINIConfiguration config = new 
HierarchicalINIConfiguration(path);
    +
                        SubnodeConfiguration subNode = config.getSection(appId);
    -                   if (subNode.containsKey(cookieKey)) {
    -                           String errorMessage = "Secure Cookie is already 
found in "+ path + " for the appID: "+ appId;
    -                           LOG.error(errorMessage);
    -                           throw new RuntimeException(errorMessage);
    +                   if(!subNode.isEmpty()) {
    +                           throw new RuntimeException("Application with ID 
" + appId + "already exists");
                        }
    -                   subNode.addProperty(cookieKey, cookie);
    +
    +                   subNode.addProperty(YARN_PROPERTIES_PARALLELISM, 
parallelism);
    +                   
subNode.addProperty(YARN_PROPERTIES_DYNAMIC_PROPERTIES_STRING, dynaProps);
    +                   subNode.addProperty(YARN_PROPERTIES_SECURE_COOKIE, 
cookie);
    +
    +                   //update latest entry section with the most recent APP 
Id
    +                   config.clearTree(YARN_LATEST_ENTRY_SECTION_NAME);
    +                   SubnodeConfiguration activeAppSection = 
config.getSection(YARN_LATEST_ENTRY_SECTION_NAME);
    +                   activeAppSection.addProperty(YARN_APPLICATION_ID_KEY, 
appId);
    +
                        config.save();
    -                   LOG.debug("Persisted cookie for the appID: {}", appId);
    +                   LOG.debug("Persisted Yarn App state: {}", appState);
                } catch(Exception e) {
    -                   LOG.error("Exception occurred while persisting app 
state for app id: {}", appId, e);
                        throw new RuntimeException(e);
                }
        }
     
    -   public static String getAppSecureCookie(String appId) {
    +   public static YarnAppState retrieveMostRecentYarnApp() {
    +           String path = getYarnPropertiesLocation().getAbsolutePath();
    +           LOG.debug("Going to fetch app state from {}", path);
    +           try {
    +                   HierarchicalINIConfiguration config = new 
HierarchicalINIConfiguration(path);
    +                   SubnodeConfiguration subNode = 
config.getSection(YARN_LATEST_ENTRY_SECTION_NAME);
    +                   String appId = 
subNode.getString(YARN_APPLICATION_ID_KEY, null);
    +                   if(null != appId) {
    +                           return retrieveYarnAppState(appId);
    +                   }
    +           } catch(Exception e) {
    +                   throw new RuntimeException(e);
    +           }
    +           return null;
    +   }
    +
    +   public static YarnAppState retrieveYarnAppState(String appId) {
    --- End diff --
    
    You could pass the config here which would avoid re-creating it in this 
method.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to