use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.
the class RMAppManager method updateApplicationTimeout.
// transaction method.
public void updateApplicationTimeout(RMApp app, Map<ApplicationTimeoutType, String> newTimeoutInISO8601Format) throws YarnException {
ApplicationId applicationId = app.getApplicationId();
synchronized (applicationId) {
if (app.isAppInCompletedStates()) {
return;
}
Map<ApplicationTimeoutType, Long> newExpireTime = RMServerUtils.validateISO8601AndConvertToLocalTimeEpoch(newTimeoutInISO8601Format);
SettableFuture<Object> future = SettableFuture.create();
Map<ApplicationTimeoutType, Long> currentExpireTimeouts = app.getApplicationTimeouts();
currentExpireTimeouts.putAll(newExpireTime);
ApplicationStateData appState = ApplicationStateData.newInstance(app.getSubmitTime(), app.getStartTime(), app.getApplicationSubmissionContext(), app.getUser(), app.getCallerContext());
appState.setApplicationTimeouts(currentExpireTimeouts);
// update to state store. Though it synchronous call, update via future to
// know any exception has been set. It is required because in non-HA mode,
// state-store errors are skipped.
this.rmContext.getStateStore().updateApplicationStateSynchronously(appState, false, future);
Futures.get(future, YarnException.class);
// update in-memory
((RMAppImpl) app).updateApplicationTimeout(newExpireTime);
}
}
use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.
the class RMServerUtils method validateISO8601AndConvertToLocalTimeEpoch.
/**
* Validate ISO8601 format with epoch time.
* @param timeoutsInISO8601 format
* @return expire time in local epoch
* @throws YarnException if given application timeout value is lesser than
* current time.
*/
public static Map<ApplicationTimeoutType, Long> validateISO8601AndConvertToLocalTimeEpoch(Map<ApplicationTimeoutType, String> timeoutsInISO8601) throws YarnException {
long currentTimeMillis = clock.getTime();
Map<ApplicationTimeoutType, Long> newApplicationTimeout = new HashMap<ApplicationTimeoutType, Long>();
if (timeoutsInISO8601 != null) {
for (Map.Entry<ApplicationTimeoutType, String> timeout : timeoutsInISO8601.entrySet()) {
long expireTime = 0L;
try {
expireTime = Times.parseISO8601ToLocalTimeInMillis(timeout.getValue());
} catch (ParseException ex) {
String message = "Expire time is not in ISO8601 format. ISO8601 supported " + "format is yyyy-MM-dd'T'HH:mm:ss.SSSZ. Configured " + "timeout value is " + timeout.getValue();
throw new YarnException(message, ex);
}
if (expireTime < currentTimeMillis) {
String message = "Expire time is less than current time, current-time=" + Times.formatISO8601(currentTimeMillis) + " expire-time=" + Times.formatISO8601(expireTime);
throw new YarnException(message);
}
newApplicationTimeout.put(timeout.getKey(), expireTime);
}
}
return newApplicationTimeout;
}
use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.
the class RMWebServices method getAppTimeouts.
@GET
@Path("/apps/{appid}/timeouts")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppTimeoutsInfo getAppTimeouts(@Context HttpServletRequest hsr, @PathParam("appid") String appId) throws AuthorizationException {
init();
RMApp app = validateAppTimeoutRequest(hsr, appId);
AppTimeoutsInfo timeouts = new AppTimeoutsInfo();
Map<ApplicationTimeoutType, Long> applicationTimeouts = app.getApplicationTimeouts();
if (applicationTimeouts.isEmpty()) {
// If application is not set timeout, lifetime should be sent as default
// with expiryTime=UNLIMITED and remainingTime=-1
timeouts.add(constructAppTimeoutDao(ApplicationTimeoutType.LIFETIME, null));
} else {
for (Entry<ApplicationTimeoutType, Long> timeout : app.getApplicationTimeouts().entrySet()) {
AppTimeoutInfo timeoutInfo = constructAppTimeoutDao(timeout.getKey(), timeout.getValue());
timeouts.add(timeoutInfo);
}
}
return timeouts;
}
use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.
the class ApplicationReportPBImpl method addApplicationTimeouts.
private void addApplicationTimeouts() {
maybeInitBuilder();
builder.clearAppTimeouts();
if (applicationTimeouts == null) {
return;
}
Iterable<? extends AppTimeoutsMapProto> values = new Iterable<AppTimeoutsMapProto>() {
@Override
public Iterator<AppTimeoutsMapProto> iterator() {
return new Iterator<AppTimeoutsMapProto>() {
private Iterator<ApplicationTimeoutType> iterator = applicationTimeouts.keySet().iterator();
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public AppTimeoutsMapProto next() {
ApplicationTimeoutType key = iterator.next();
return AppTimeoutsMapProto.newBuilder().setApplicationTimeout(convertToProtoFormat(applicationTimeouts.get(key))).setApplicationTimeoutType(ProtoUtils.convertToProtoFormat(key)).build();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
this.builder.addAllAppTimeouts(values);
}
use of org.apache.hadoop.yarn.api.records.ApplicationTimeoutType in project hadoop by apache.
the class ApplicationSubmissionContextPBImpl method initApplicationTimeout.
private void initApplicationTimeout() {
if (this.applicationTimeouts != null) {
return;
}
ApplicationSubmissionContextProtoOrBuilder p = viaProto ? proto : builder;
List<ApplicationTimeoutMapProto> lists = p.getApplicationTimeoutsList();
this.applicationTimeouts = new HashMap<ApplicationTimeoutType, Long>(lists.size());
for (ApplicationTimeoutMapProto timeoutProto : lists) {
this.applicationTimeouts.put(ProtoUtils.convertFromProtoFormat(timeoutProto.getApplicationTimeoutType()), timeoutProto.getTimeout());
}
}
Aggregations