YARN-5769. Integrate update app lifetime using feature implemented in YARN-5611. Contributed by Jian He

This commit is contained in:
Gour Saha 2016-11-30 23:24:45 -08:00 committed by Jian He
parent bd0e9f91b6
commit 6143aa135b
3 changed files with 53 additions and 8 deletions

View File

@ -77,6 +77,7 @@ import org.apache.slider.common.params.ActionFreezeArgs;
import org.apache.slider.common.params.ActionListArgs;
import org.apache.slider.common.params.ActionRegistryArgs;
import org.apache.slider.common.params.ActionThawArgs;
import org.apache.slider.common.params.ActionUpdateArgs;
import org.apache.slider.common.params.ComponentArgsDelegate;
import org.apache.slider.common.tools.SliderUtils;
import org.apache.slider.common.tools.SliderVersionInfo;
@ -1398,14 +1399,34 @@ public class ApplicationApiService implements ApplicationApi {
}
// If new lifetime value specified then update it
if (updateAppData.getLifetime() != null) {
// TODO: Once YARN-3813 and YARN-4205 are available
if (updateAppData.getLifetime() != null
&& updateAppData.getLifetime() > 0) {
try {
updateAppLifetime(appName, updateAppData.getLifetime());
} catch (Exception e) {
logger.error("Failed to update application (" + appName + ") lifetime ("
+ updateAppData.getLifetime() + ")", e);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}
// If nothing happens consider it a no-op
return Response.status(Status.NO_CONTENT).build();
}
private Void updateAppLifetime(String appName, long lifetime)
throws InterruptedException, YarnException, IOException {
return invokeSliderClientRunnable(new SliderClientContextRunnable<Void>() {
@Override public Void run(SliderClient sliderClient)
throws YarnException, IOException, InterruptedException {
ActionUpdateArgs args = new ActionUpdateArgs();
args.lifetime = lifetime;
sliderClient.actionUpdate(appName, args);
return null;
}
});
}
// create default component and initialize with app level global values
private List<Component> getDefaultComponentAsList(Application app) {
List<Component> comps = getDefaultComponentAsList();

View File

@ -52,6 +52,7 @@ import org.apache.hadoop.security.alias.CredentialProvider;
import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.util.Shell;
import org.apache.hadoop.yarn.api.ApplicationConstants;
import org.apache.hadoop.yarn.api.protocolrecords.UpdateApplicationTimeoutsRequest;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.api.records.ApplicationReport;
import org.apache.hadoop.yarn.api.records.ApplicationTimeoutType;
@ -65,6 +66,7 @@ import org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException;
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.apache.hadoop.yarn.util.ConverterUtils;
import org.apache.hadoop.yarn.util.Times;
import org.apache.slider.api.ClusterDescription;
import org.apache.slider.api.ClusterNode;
import org.apache.slider.api.SliderApplicationApi;
@ -177,14 +179,12 @@ import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.Console;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.io.PrintWriter;
@ -1602,8 +1602,33 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe
public int actionUpdate(String clustername,
AbstractClusterBuildingActionArgs buildInfo) throws
YarnException, IOException {
buildInstanceDefinition(clustername, buildInfo, true, true);
return EXIT_SUCCESS;
if (buildInfo.lifetime > 0) {
updateLifetime(clustername, buildInfo.lifetime);
} else {
buildInstanceDefinition(clustername, buildInfo, true, true);
}
return EXIT_SUCCESS;
}
public void updateLifetime(String appName, long lifetime)
throws YarnException, IOException {
ApplicationReport report = findInstance(appName);
if (report == null) {
throw new YarnException("Application not found for " + appName);
}
ApplicationId appId = report.getApplicationId();
log.info("Updating lifetime of an application: appName = " + appName
+ ", appId = " + appId+ ", lifetime = " + lifetime);
Map<ApplicationTimeoutType, String> map = new HashMap<>();
String newTimeout =
Times.formatISO8601(System.currentTimeMillis() + lifetime * 1000);
map.put(ApplicationTimeoutType.LIFETIME, newTimeout);
UpdateApplicationTimeoutsRequest request =
UpdateApplicationTimeoutsRequest.newInstance(appId, map);
yarnClient.updateApplicationTimeouts(request);
log.info("Successfully updated lifetime for an application: appName = "
+ appName + ", appId = " + appId
+ ". New expiry time in ISO8601 format is " + newTimeout);
}
/**

View File

@ -103,8 +103,7 @@ public abstract class AbstractClusterBuildingActionArgs extends
public String queue;
@Parameter(names = {ARG_LIFETIME},
description = "Life time of the application since application started at"
+ " running state")
description = "Lifetime of the application from the time of request")
public long lifetime;
@ParametersDelegate