YARN-6115. Few additional paths in Slider client still uses get all Applications without tags/states filter. Contributed by Gour Saha

This commit is contained in:
Billie Rinaldi 2017-01-25 14:20:58 -08:00 committed by Jian He
parent a5e20f0fc1
commit 7edc154e0e
2 changed files with 73 additions and 21 deletions

View File

@ -142,7 +142,6 @@ import org.apache.slider.core.launch.ClasspathConstructor;
import org.apache.slider.core.launch.CredentialUtils;
import org.apache.slider.core.launch.JavaCommandLineBuilder;
import org.apache.slider.core.launch.LaunchedApplication;
import org.apache.slider.core.launch.RunningApplication;
import org.apache.slider.core.launch.SerializedApplicationReport;
import org.apache.slider.core.main.RunService;
import org.apache.slider.core.persist.AppDefinitionPersister;
@ -1535,7 +1534,9 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
public void updateLifetime(String appName, long lifetime)
throws YarnException, IOException {
ApplicationReport report = findInstance(appName);
EnumSet<YarnApplicationState> appStates = EnumSet.range(
YarnApplicationState.NEW, YarnApplicationState.RUNNING);
ApplicationReport report = findInstance(appName, appStates);
if (report == null) {
throw new YarnException("Application not found for " + appName);
}
@ -2672,15 +2673,17 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
}
/**
* List Slider instances belonging to a specific user. This will include
* failed and killed instances; there may be duplicates
* List Slider instances belonging to a specific user with a specific app
* name and within a set of app states.
* @param user user: "" means all users, null means "default"
* @param appName name of the application set as a tag
* @param appStates a set of states the applications should be in
* @return a possibly empty list of Slider AMs
*/
public List<ApplicationReport> listSliderInstances(String user)
public List<ApplicationReport> listSliderInstances(String user,
String appName, EnumSet<YarnApplicationState> appStates)
throws YarnException, IOException {
return yarnAppListClient.listInstances(user);
return yarnAppListClient.listInstances(user, appName, appStates);
}
/**
@ -2806,7 +2809,9 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
}
// and those the RM knows about
List<ApplicationReport> instances = listSliderInstances(null);
EnumSet<YarnApplicationState> appStates = EnumSet.range(min, max);
List<ApplicationReport> instances = listSliderInstances(null, clustername,
appStates);
sortApplicationsByMostRecent(instances);
Map<String, ApplicationReport> reportMap =
buildApplicationReportMap(instances, min, max);
@ -3053,7 +3058,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
}
/**
* Find an instance of an application belonging to the current user
* Find an instance of an application belonging to the current user.
* @param appname application name
* @return the app report or null if none is found
* @throws YarnException YARN issues
@ -3061,14 +3066,22 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
*/
public ApplicationReport findInstance(String appname)
throws YarnException, IOException {
return yarnAppListClient.findInstance(appname);
return findInstance(appname, null);
}
private RunningApplication findApplication(String appname)
/**
* Find an instance of an application belonging to the current user and in
* specific app states.
* @param appname application name
* @param appStates app states in which the application should be in
* @return the app report or null if none is found
* @throws YarnException YARN issues
* @throws IOException IO problems
*/
public ApplicationReport findInstance(String appname,
EnumSet<YarnApplicationState> appStates)
throws YarnException, IOException {
ApplicationReport applicationReport = findInstance(appname);
return applicationReport != null ?
new RunningApplication(yarnClient, applicationReport): null;
return yarnAppListClient.findInstance(appname, appStates);
}
/**

View File

@ -32,6 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -77,7 +78,7 @@ public class YarnAppListClient {
/**
* Find an instance of a application belong to the current user
* Find an instance of a application belong to the current user.
* @param appname application name
* @return the app report or null if none is found
* @throws YarnException YARN issues
@ -86,7 +87,22 @@ public class YarnAppListClient {
public ApplicationReport findInstance(String appname) throws
YarnException,
IOException {
List<ApplicationReport> instances = listInstances(null, appname);
return findInstance(appname, null);
}
/**
* Find an instance of a application belong to the current user in specific
* app states.
* @param appname application name
* @param appStates list of states in which application should be in
* @return the app report or null if none is found
* @throws YarnException YARN issues
* @throws IOException IO problems
*/
public ApplicationReport findInstance(String appname,
EnumSet<YarnApplicationState> appStates)
throws YarnException, IOException {
List<ApplicationReport> instances = listInstances(null, appname, appStates);
return yarnClient.findClusterInInstanceList(instances, appname);
}
@ -111,21 +127,44 @@ public class YarnAppListClient {
}
/**
* List all instances belonging to a specific user and a specific appname.
* List all instances belonging to a specific user with a specific app name.
*
* @param user
* user if not the default. null means default, "" means all users,
* otherwise it is the name of a user
* @param appname
* @param appName
* application name set as an application tag
* @return a possibly empty list of AMs
* @throws YarnException
* @throws IOException
*/
public List<ApplicationReport> listInstances(String user, String appname)
public List<ApplicationReport> listInstances(String user, String appName)
throws YarnException, IOException {
return listInstances(user, appName, null);
}
/**
* List all instances belonging to a specific user, with a specific app name
* and in specific app states.
*
* @param user
* user if not the default. null means default, "" means all users,
* otherwise it is the name of a user
* @param appName
* application name set as an application tag
* @param appStates
* a set of application states within which the app should be in
* @return a possibly empty list of AMs
* @throws YarnException
* @throws IOException
*/
public List<ApplicationReport> listInstances(String user, String appName,
EnumSet<YarnApplicationState> appStates)
throws YarnException, IOException {
log.debug("listInstances called with user: {}, appName: {}, appStates: {}",
user, appName, appStates);
String listUser = user == null ? username : user;
return yarnClient.listDeployedInstances(listUser, null, appname);
return yarnClient.listDeployedInstances(listUser, appStates, appName);
}
/**