YARN-5970. Validate application update timeout request parameters. Contributed by Rohith Sharma K S.
This commit is contained in:
parent
48853c7319
commit
23bd68a4a4
|
@ -105,6 +105,9 @@ public class Times {
|
||||||
*/
|
*/
|
||||||
public static long parseISO8601ToLocalTimeInMillis(String isoString)
|
public static long parseISO8601ToLocalTimeInMillis(String isoString)
|
||||||
throws ParseException {
|
throws ParseException {
|
||||||
|
if (isoString == null) {
|
||||||
|
throw new ParseException("Invalid input.", -1);
|
||||||
|
}
|
||||||
return isoFormat.get().parse(isoString).getTime();
|
return isoFormat.get().parse(isoString).getTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,7 +507,8 @@ public class RMServerUtils {
|
||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
String message =
|
String message =
|
||||||
"Expire time is not in ISO8601 format. ISO8601 supported "
|
"Expire time is not in ISO8601 format. ISO8601 supported "
|
||||||
+ "format is yyyy-MM-dd'T'HH:mm:ss.SSSZ";
|
+ "format is yyyy-MM-dd'T'HH:mm:ss.SSSZ. Configured "
|
||||||
|
+ "timeout value is " + timeout.getValue();
|
||||||
throw new YarnException(message, ex);
|
throw new YarnException(message, ex);
|
||||||
}
|
}
|
||||||
if (expireTime < currentTimeMillis) {
|
if (expireTime < currentTimeMillis) {
|
||||||
|
|
|
@ -2396,7 +2396,7 @@ public class RMWebServices extends WebServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/apps/{appid}/timeout/{type}")
|
@Path("/apps/{appid}/timeouts/{type}")
|
||||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
public AppTimeoutInfo getAppTimeout(@Context HttpServletRequest hsr,
|
public AppTimeoutInfo getAppTimeout(@Context HttpServletRequest hsr,
|
||||||
@PathParam("appid") String appId, @PathParam("type") String type)
|
@PathParam("appid") String appId, @PathParam("type") String type)
|
||||||
|
@ -2530,10 +2530,10 @@ public class RMWebServices extends WebServices {
|
||||||
private Response updateApplicationTimeouts(final RMApp app,
|
private Response updateApplicationTimeouts(final RMApp app,
|
||||||
UserGroupInformation callerUGI, final AppTimeoutInfo appTimeout)
|
UserGroupInformation callerUGI, final AppTimeoutInfo appTimeout)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
|
if (appTimeout.getTimeoutType() == null
|
||||||
if (appTimeout.getTimeoutType() == null) {
|
|| appTimeout.getExpireTime() == null) {
|
||||||
return Response.status(Status.BAD_REQUEST).entity("Timeout type is null.")
|
return Response.status(Status.BAD_REQUEST)
|
||||||
.build();
|
.entity("Timeout type or ExpiryTime is null.").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
String userName = callerUGI.getUserName();
|
String userName = callerUGI.getUserName();
|
||||||
|
|
|
@ -1313,19 +1313,11 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
||||||
ApplicationTimeoutType.LIFETIME, "UNLIMITED", -1);
|
ApplicationTimeoutType.LIFETIME, "UNLIMITED", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppTimeoutInfo timeoutUpdate = new AppTimeoutInfo();
|
|
||||||
long timeOutFromNow = 60;
|
long timeOutFromNow = 60;
|
||||||
String expireTime = Times
|
String expireTime = Times
|
||||||
.formatISO8601(System.currentTimeMillis() + timeOutFromNow * 1000);
|
.formatISO8601(System.currentTimeMillis() + timeOutFromNow * 1000);
|
||||||
timeoutUpdate.setTimeoutType(ApplicationTimeoutType.LIFETIME);
|
Object entity = getAppTimeoutInfoEntity(ApplicationTimeoutType.LIFETIME,
|
||||||
timeoutUpdate.setExpiryTime(expireTime);
|
contentType, expireTime);
|
||||||
|
|
||||||
Object entity;
|
|
||||||
if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
|
|
||||||
entity = appTimeoutToJSON(timeoutUpdate);
|
|
||||||
} else {
|
|
||||||
entity = timeoutUpdate;
|
|
||||||
}
|
|
||||||
response = this
|
response = this
|
||||||
.constructWebResource("apps", app.getApplicationId().toString(),
|
.constructWebResource("apps", app.getApplicationId().toString(),
|
||||||
"timeout")
|
"timeout")
|
||||||
|
@ -1345,10 +1337,21 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
||||||
expireTime, timeOutFromNow);
|
expireTime, timeOutFromNow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// verify for negative cases
|
||||||
|
entity = getAppTimeoutInfoEntity(null,
|
||||||
|
contentType, null);
|
||||||
|
response = this
|
||||||
|
.constructWebResource("apps", app.getApplicationId().toString(),
|
||||||
|
"timeout")
|
||||||
|
.entity(entity, contentType).accept(mediaType)
|
||||||
|
.put(ClientResponse.class);
|
||||||
|
assertEquals(Status.BAD_REQUEST,
|
||||||
|
response.getClientResponseStatus());
|
||||||
|
|
||||||
// invoke get
|
// invoke get
|
||||||
response =
|
response =
|
||||||
this.constructWebResource("apps", app.getApplicationId().toString(),
|
this.constructWebResource("apps", app.getApplicationId().toString(),
|
||||||
"timeout", ApplicationTimeoutType.LIFETIME.toString())
|
"timeouts", ApplicationTimeoutType.LIFETIME.toString())
|
||||||
.accept(mediaType).get(ClientResponse.class);
|
.accept(mediaType).get(ClientResponse.class);
|
||||||
assertEquals(Status.OK, response.getClientResponseStatus());
|
assertEquals(Status.OK, response.getClientResponseStatus());
|
||||||
if (mediaType.contains(MediaType.APPLICATION_JSON)) {
|
if (mediaType.contains(MediaType.APPLICATION_JSON)) {
|
||||||
|
@ -1360,6 +1363,21 @@ public class TestRMWebServicesAppsModification extends JerseyTestBase {
|
||||||
rm.stop();
|
rm.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object getAppTimeoutInfoEntity(ApplicationTimeoutType type,
|
||||||
|
MediaType contentType, String expireTime) throws Exception {
|
||||||
|
AppTimeoutInfo timeoutUpdate = new AppTimeoutInfo();
|
||||||
|
timeoutUpdate.setTimeoutType(type);
|
||||||
|
timeoutUpdate.setExpiryTime(expireTime);
|
||||||
|
|
||||||
|
Object entity;
|
||||||
|
if (contentType.equals(MediaType.APPLICATION_JSON_TYPE)) {
|
||||||
|
entity = appTimeoutToJSON(timeoutUpdate);
|
||||||
|
} else {
|
||||||
|
entity = timeoutUpdate;
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
protected static void verifyAppTimeoutJson(ClientResponse response,
|
protected static void verifyAppTimeoutJson(ClientResponse response,
|
||||||
ApplicationTimeoutType type, String expireTime, long timeOutFromNow)
|
ApplicationTimeoutType type, String expireTime, long timeOutFromNow)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
Loading…
Reference in New Issue