org.apache.hadoop.yarn.webapp.BadRequestException Java Examples
The following examples show how to use
org.apache.hadoop.yarn.webapp.BadRequestException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HsWebServices.java From big-c with Apache License 2.0 | 6 votes |
@GET @Path("/mapreduce/jobs/{jobid}/tasks") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TasksInfo getJobTasks(@Context HttpServletRequest hsr, @PathParam("jobid") String jid, @QueryParam("type") String type) { init(); Job job = AMWebServices.getJobFromJobIdString(jid, ctx); checkAccess(job, hsr); TasksInfo allTasks = new TasksInfo(); for (Task task : job.getTasks().values()) { TaskType ttype = null; if (type != null && !type.isEmpty()) { try { ttype = MRApps.taskType(type); } catch (YarnRuntimeException e) { throw new BadRequestException("tasktype must be either m or r"); } } if (ttype != null && task.getType() != ttype) { continue; } allTasks.add(new TaskInfo(task)); } return allTasks; }
Example #2
Source File: NMWebServices.java From hadoop with Apache License 2.0 | 6 votes |
@GET @Path("/containers/{containerid}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public ContainerInfo getNodeContainer(@PathParam("containerid") String id) { ContainerId containerId = null; init(); try { containerId = ConverterUtils.toContainerId(id); } catch (Exception e) { throw new BadRequestException("invalid container id, " + id); } Container container = nmContext.getContainers().get(containerId); if (container == null) { throw new NotFoundException("container with id, " + id + ", not found"); } return new ContainerInfo(this.nmContext, container, uriInfo.getBaseUri() .toString(), webapp.name()); }
Example #3
Source File: AMWebServices.java From big-c with Apache License 2.0 | 6 votes |
@GET @Path("/jobs/{jobid}/tasks") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TasksInfo getJobTasks(@Context HttpServletRequest hsr, @PathParam("jobid") String jid, @QueryParam("type") String type) { init(); Job job = getJobFromJobIdString(jid, appCtx); checkAccess(job, hsr); TasksInfo allTasks = new TasksInfo(); for (Task task : job.getTasks().values()) { TaskType ttype = null; if (type != null && !type.isEmpty()) { try { ttype = MRApps.taskType(type); } catch (YarnRuntimeException e) { throw new BadRequestException("tasktype must be either m or r"); } } if (ttype != null && task.getType() != ttype) { continue; } allTasks.add(new TaskInfo(task)); } return allTasks; }
Example #4
Source File: AHSWebServices.java From big-c with Apache License 2.0 | 6 votes |
private static void validateStates(String stateQuery, Set<String> statesQuery) { // stateQuery is deprecated. if (stateQuery != null && !stateQuery.isEmpty()) { statesQuery.add(stateQuery); } Set<String> appStates = parseQueries(statesQuery, true); for (String appState : appStates) { switch (YarnApplicationState.valueOf( StringUtils.toUpperCase(appState))) { case FINISHED: case FAILED: case KILLED: continue; default: throw new BadRequestException("Invalid application-state " + appState + " specified. It should be a final state"); } } }
Example #5
Source File: AHSWebServices.java From hadoop with Apache License 2.0 | 6 votes |
private static void validateStates(String stateQuery, Set<String> statesQuery) { // stateQuery is deprecated. if (stateQuery != null && !stateQuery.isEmpty()) { statesQuery.add(stateQuery); } Set<String> appStates = parseQueries(statesQuery, true); for (String appState : appStates) { switch (YarnApplicationState.valueOf( StringUtils.toUpperCase(appState))) { case FINISHED: case FAILED: case KILLED: continue; default: throw new BadRequestException("Invalid application-state " + appState + " specified. It should be a final state"); } } }
Example #6
Source File: NMWebServices.java From big-c with Apache License 2.0 | 6 votes |
@GET @Path("/containers/{containerid}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public ContainerInfo getNodeContainer(@PathParam("containerid") String id) { ContainerId containerId = null; init(); try { containerId = ConverterUtils.toContainerId(id); } catch (Exception e) { throw new BadRequestException("invalid container id, " + id); } Container container = nmContext.getContainers().get(containerId); if (container == null) { throw new NotFoundException("container with id, " + id + ", not found"); } return new ContainerInfo(this.nmContext, container, uriInfo.getBaseUri() .toString(), webapp.name()); }
Example #7
Source File: AMWebServices.java From hadoop with Apache License 2.0 | 6 votes |
@GET @Path("/jobs/{jobid}/tasks") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TasksInfo getJobTasks(@Context HttpServletRequest hsr, @PathParam("jobid") String jid, @QueryParam("type") String type) { init(); Job job = getJobFromJobIdString(jid, appCtx); checkAccess(job, hsr); TasksInfo allTasks = new TasksInfo(); for (Task task : job.getTasks().values()) { TaskType ttype = null; if (type != null && !type.isEmpty()) { try { ttype = MRApps.taskType(type); } catch (YarnRuntimeException e) { throw new BadRequestException("tasktype must be either m or r"); } } if (ttype != null && task.getType() != ttype) { continue; } allTasks.add(new TaskInfo(task)); } return allTasks; }
Example #8
Source File: HsWebServices.java From hadoop with Apache License 2.0 | 6 votes |
@GET @Path("/mapreduce/jobs/{jobid}/tasks") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public TasksInfo getJobTasks(@Context HttpServletRequest hsr, @PathParam("jobid") String jid, @QueryParam("type") String type) { init(); Job job = AMWebServices.getJobFromJobIdString(jid, ctx); checkAccess(job, hsr); TasksInfo allTasks = new TasksInfo(); for (Task task : job.getTasks().values()) { TaskType ttype = null; if (type != null && !type.isEmpty()) { try { ttype = MRApps.taskType(type); } catch (YarnRuntimeException e) { throw new BadRequestException("tasktype must be either m or r"); } } if (ttype != null && task.getType() != ttype) { continue; } allTasks.add(new TaskInfo(task)); } return allTasks; }
Example #9
Source File: WebServices.java From big-c with Apache License 2.0 | 5 votes |
protected static Set<String> parseQueries(Set<String> queries, boolean isState) { Set<String> params = new HashSet<String>(); if (!queries.isEmpty()) { for (String query : queries) { if (query != null && !query.trim().isEmpty()) { String[] paramStrs = query.split(","); for (String paramStr : paramStrs) { if (paramStr != null && !paramStr.trim().isEmpty()) { if (isState) { try { // enum string is in the uppercase YarnApplicationState.valueOf( StringUtils.toUpperCase(paramStr.trim())); } catch (RuntimeException e) { YarnApplicationState[] stateArray = YarnApplicationState.values(); String allAppStates = Arrays.toString(stateArray); throw new BadRequestException("Invalid application-state " + paramStr.trim() + " specified. It should be one of " + allAppStates); } } params.add(StringUtils.toLowerCase(paramStr.trim())); } } } } } return params; }
Example #10
Source File: TimelineWebServices.java From big-c with Apache License 2.0 | 5 votes |
/** * Return a list of domains of the given owner. */ @GET @Path("/domain") @Produces({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */}) public TimelineDomains getDomains( @Context HttpServletRequest req, @Context HttpServletResponse res, @QueryParam("owner") String owner) { init(res); owner = parseStr(owner); UserGroupInformation callerUGI = getUser(req); if (owner == null || owner.length() == 0) { if (callerUGI == null) { throw new BadRequestException("Domain owner is not specified."); } else { // By default it's going to list the caller's domains owner = callerUGI.getShortUserName(); } } try { return timelineDataManager.getDomains(owner, callerUGI); } catch (Exception e) { LOG.error("Error getting domains", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } }
Example #11
Source File: TimelineWebServices.java From big-c with Apache License 2.0 | 5 votes |
/** * Return a single domain of the given domain Id. */ @GET @Path("/domain/{domainId}") @Produces({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */}) public TimelineDomain getDomain( @Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("domainId") String domainId) { init(res); domainId = parseStr(domainId); if (domainId == null || domainId.length() == 0) { throw new BadRequestException("Domain ID is not specified."); } TimelineDomain domain = null; try { domain = timelineDataManager.getDomain( parseStr(domainId), getUser(req)); } catch (Exception e) { LOG.error("Error getting domain", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } if (domain == null) { throw new NotFoundException("Timeline domain [" + domainId + "] is not found"); } return domain; }
Example #12
Source File: RMWebServices.java From big-c with Apache License 2.0 | 5 votes |
private Token<RMDelegationTokenIdentifier> extractToken(String encodedToken) { Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(); try { token.decodeFromUrlString(encodedToken); } catch (Exception ie) { String msg = "Could not decode encoded token"; throw new BadRequestException(msg); } return token; }
Example #13
Source File: RMWebServices.java From big-c with Apache License 2.0 | 5 votes |
private Token<RMDelegationTokenIdentifier> extractToken( HttpServletRequest request) { String encodedToken = request.getHeader(DELEGATION_TOKEN_HEADER); if (encodedToken == null) { String msg = "Header '" + DELEGATION_TOKEN_HEADER + "' containing encoded token not found"; throw new BadRequestException(msg); } return extractToken(encodedToken); }
Example #14
Source File: RMWebServices.java From big-c with Apache License 2.0 | 5 votes |
/** * Create the actual ApplicationSubmissionContext to be submitted to the RM * from the information provided by the user. * * @param newApp * the information provided by the user * @return returns the constructed ApplicationSubmissionContext * @throws IOException */ protected ApplicationSubmissionContext createAppSubmissionContext( ApplicationSubmissionContextInfo newApp) throws IOException { // create local resources and app submission context ApplicationId appid; String error = "Could not parse application id " + newApp.getApplicationId(); try { appid = ConverterUtils.toApplicationId(recordFactory, newApp.getApplicationId()); } catch (Exception e) { throw new BadRequestException(error); } ApplicationSubmissionContext appContext = ApplicationSubmissionContext.newInstance(appid, newApp.getApplicationName(), newApp.getQueue(), Priority.newInstance(newApp.getPriority()), createContainerLaunchContext(newApp), newApp.getUnmanagedAM(), newApp.getCancelTokensWhenComplete(), newApp.getMaxAppAttempts(), createAppSubmissionContextResource(newApp), newApp.getApplicationType(), newApp.getKeepContainersAcrossApplicationAttempts(), newApp.getAppNodeLabelExpression(), newApp.getAMContainerNodeLabelExpression()); appContext.setApplicationTags(newApp.getApplicationTags()); return appContext; }
Example #15
Source File: RMWebServices.java From big-c with Apache License 2.0 | 5 votes |
private static Set<String> parseQueries( Set<String> queries, boolean isState) { Set<String> params = new HashSet<String>(); if (!queries.isEmpty()) { for (String query : queries) { if (query != null && !query.trim().isEmpty()) { String[] paramStrs = query.split(","); for (String paramStr : paramStrs) { if (paramStr != null && !paramStr.trim().isEmpty()) { if (isState) { try { // enum string is in the uppercase YarnApplicationState.valueOf( StringUtils.toUpperCase(paramStr.trim())); } catch (RuntimeException e) { YarnApplicationState[] stateArray = YarnApplicationState.values(); String allAppStates = Arrays.toString(stateArray); throw new BadRequestException( "Invalid application-state " + paramStr.trim() + " specified. It should be one of " + allAppStates); } } params.add( StringUtils.toLowerCase(paramStr.trim())); } } } } } return params; }
Example #16
Source File: NMWebServices.java From big-c with Apache License 2.0 | 5 votes |
@GET @Path("/apps") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AppsInfo getNodeApps(@QueryParam("state") String stateQuery, @QueryParam("user") String userQuery) { init(); AppsInfo allApps = new AppsInfo(); for (Entry<ApplicationId, Application> entry : this.nmContext .getApplications().entrySet()) { AppInfo appInfo = new AppInfo(entry.getValue()); if (stateQuery != null && !stateQuery.isEmpty()) { ApplicationState.valueOf(stateQuery); if (!appInfo.getState().equalsIgnoreCase(stateQuery)) { continue; } } if (userQuery != null) { if (userQuery.isEmpty()) { String msg = "Error: You must specify a non-empty string for the user"; throw new BadRequestException(msg); } if (!appInfo.getUser().toString().equals(userQuery)) { continue; } } allApps.add(appInfo); } return allApps; }
Example #17
Source File: WebServices.java From hadoop with Apache License 2.0 | 5 votes |
protected static Set<String> parseQueries(Set<String> queries, boolean isState) { Set<String> params = new HashSet<String>(); if (!queries.isEmpty()) { for (String query : queries) { if (query != null && !query.trim().isEmpty()) { String[] paramStrs = query.split(","); for (String paramStr : paramStrs) { if (paramStr != null && !paramStr.trim().isEmpty()) { if (isState) { try { // enum string is in the uppercase YarnApplicationState.valueOf( StringUtils.toUpperCase(paramStr.trim())); } catch (RuntimeException e) { YarnApplicationState[] stateArray = YarnApplicationState.values(); String allAppStates = Arrays.toString(stateArray); throw new BadRequestException("Invalid application-state " + paramStr.trim() + " specified. It should be one of " + allAppStates); } } params.add(StringUtils.toLowerCase(paramStr.trim())); } } } } } return params; }
Example #18
Source File: TimelineWebServices.java From hadoop with Apache License 2.0 | 5 votes |
/** * Return a list of domains of the given owner. */ @GET @Path("/domain") @Produces({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */}) public TimelineDomains getDomains( @Context HttpServletRequest req, @Context HttpServletResponse res, @QueryParam("owner") String owner) { init(res); owner = parseStr(owner); UserGroupInformation callerUGI = getUser(req); if (owner == null || owner.length() == 0) { if (callerUGI == null) { throw new BadRequestException("Domain owner is not specified."); } else { // By default it's going to list the caller's domains owner = callerUGI.getShortUserName(); } } try { return timelineDataManager.getDomains(owner, callerUGI); } catch (Exception e) { LOG.error("Error getting domains", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } }
Example #19
Source File: TimelineWebServices.java From hadoop with Apache License 2.0 | 5 votes |
/** * Return a single domain of the given domain Id. */ @GET @Path("/domain/{domainId}") @Produces({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */}) public TimelineDomain getDomain( @Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("domainId") String domainId) { init(res); domainId = parseStr(domainId); if (domainId == null || domainId.length() == 0) { throw new BadRequestException("Domain ID is not specified."); } TimelineDomain domain = null; try { domain = timelineDataManager.getDomain( parseStr(domainId), getUser(req)); } catch (Exception e) { LOG.error("Error getting domain", e); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } if (domain == null) { throw new NotFoundException("Timeline domain [" + domainId + "] is not found"); } return domain; }
Example #20
Source File: RMWebServices.java From hadoop with Apache License 2.0 | 5 votes |
private Token<RMDelegationTokenIdentifier> extractToken(String encodedToken) { Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(); try { token.decodeFromUrlString(encodedToken); } catch (Exception ie) { String msg = "Could not decode encoded token"; throw new BadRequestException(msg); } return token; }
Example #21
Source File: RMWebServices.java From hadoop with Apache License 2.0 | 5 votes |
private Token<RMDelegationTokenIdentifier> extractToken( HttpServletRequest request) { String encodedToken = request.getHeader(DELEGATION_TOKEN_HEADER); if (encodedToken == null) { String msg = "Header '" + DELEGATION_TOKEN_HEADER + "' containing encoded token not found"; throw new BadRequestException(msg); } return extractToken(encodedToken); }
Example #22
Source File: RMWebServices.java From hadoop with Apache License 2.0 | 5 votes |
/** * Create the actual ApplicationSubmissionContext to be submitted to the RM * from the information provided by the user. * * @param newApp * the information provided by the user * @return returns the constructed ApplicationSubmissionContext * @throws IOException */ protected ApplicationSubmissionContext createAppSubmissionContext( ApplicationSubmissionContextInfo newApp) throws IOException { // create local resources and app submission context ApplicationId appid; String error = "Could not parse application id " + newApp.getApplicationId(); try { appid = ConverterUtils.toApplicationId(recordFactory, newApp.getApplicationId()); } catch (Exception e) { throw new BadRequestException(error); } ApplicationSubmissionContext appContext = ApplicationSubmissionContext.newInstance(appid, newApp.getApplicationName(), newApp.getQueue(), Priority.newInstance(newApp.getPriority()), createContainerLaunchContext(newApp), newApp.getUnmanagedAM(), newApp.getCancelTokensWhenComplete(), newApp.getMaxAppAttempts(), createAppSubmissionContextResource(newApp), newApp.getApplicationType(), newApp.getKeepContainersAcrossApplicationAttempts(), newApp.getAppNodeLabelExpression(), newApp.getAMContainerNodeLabelExpression()); appContext.setApplicationTags(newApp.getApplicationTags()); return appContext; }
Example #23
Source File: RMWebServices.java From hadoop with Apache License 2.0 | 5 votes |
private static Set<String> parseQueries( Set<String> queries, boolean isState) { Set<String> params = new HashSet<String>(); if (!queries.isEmpty()) { for (String query : queries) { if (query != null && !query.trim().isEmpty()) { String[] paramStrs = query.split(","); for (String paramStr : paramStrs) { if (paramStr != null && !paramStr.trim().isEmpty()) { if (isState) { try { // enum string is in the uppercase YarnApplicationState.valueOf( StringUtils.toUpperCase(paramStr.trim())); } catch (RuntimeException e) { YarnApplicationState[] stateArray = YarnApplicationState.values(); String allAppStates = Arrays.toString(stateArray); throw new BadRequestException( "Invalid application-state " + paramStr.trim() + " specified. It should be one of " + allAppStates); } } params.add( StringUtils.toLowerCase(paramStr.trim())); } } } } } return params; }
Example #24
Source File: NMWebServices.java From hadoop with Apache License 2.0 | 5 votes |
@GET @Path("/apps") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public AppsInfo getNodeApps(@QueryParam("state") String stateQuery, @QueryParam("user") String userQuery) { init(); AppsInfo allApps = new AppsInfo(); for (Entry<ApplicationId, Application> entry : this.nmContext .getApplications().entrySet()) { AppInfo appInfo = new AppInfo(entry.getValue()); if (stateQuery != null && !stateQuery.isEmpty()) { ApplicationState.valueOf(stateQuery); if (!appInfo.getState().equalsIgnoreCase(stateQuery)) { continue; } } if (userQuery != null) { if (userQuery.isEmpty()) { String msg = "Error: You must specify a non-empty string for the user"; throw new BadRequestException(msg); } if (!appInfo.getUser().toString().equals(userQuery)) { continue; } } allApps.add(appInfo); } return allApps; }
Example #25
Source File: RMWebServices.java From big-c with Apache License 2.0 | 4 votes |
/** * Function to submit an app to the RM * * @param newApp * structure containing information to construct the * ApplicationSubmissionContext * @param hsr * the servlet request * @return Response containing the status code * @throws AuthorizationException * @throws IOException * @throws InterruptedException */ @POST @Path("/apps") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response submitApplication(ApplicationSubmissionContextInfo newApp, @Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException { init(); UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); if (callerUGI == null) { throw new AuthorizationException("Unable to obtain user name, " + "user not authenticated"); } if (UserGroupInformation.isSecurityEnabled() && isStaticUser(callerUGI)) { String msg = "The default static user cannot carry out this operation."; return Response.status(Status.FORBIDDEN).entity(msg).build(); } ApplicationSubmissionContext appContext = createAppSubmissionContext(newApp); final SubmitApplicationRequest req = SubmitApplicationRequest.newInstance(appContext); try { callerUGI .doAs(new PrivilegedExceptionAction<SubmitApplicationResponse>() { @Override public SubmitApplicationResponse run() throws IOException, YarnException { return rm.getClientRMService().submitApplication(req); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { throw new BadRequestException(ue.getCause().getMessage()); } LOG.info("Submit app request failed", ue); throw ue; } String url = hsr.getRequestURL() + "/" + newApp.getApplicationId(); return Response.status(Status.ACCEPTED).header(HttpHeaders.LOCATION, url) .build(); }
Example #26
Source File: RMWebServices.java From big-c with Apache License 2.0 | 4 votes |
private Response renewDelegationToken(DelegationToken tokenData, HttpServletRequest hsr, UserGroupInformation callerUGI) throws AuthorizationException, IOException, InterruptedException, Exception { Token<RMDelegationTokenIdentifier> token = extractToken(tokenData.getToken()); org.apache.hadoop.yarn.api.records.Token dToken = BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind() .toString(), token.getPassword(), token.getService().toString()); final RenewDelegationTokenRequest req = RenewDelegationTokenRequest.newInstance(dToken); RenewDelegationTokenResponse resp; try { resp = callerUGI .doAs(new PrivilegedExceptionAction<RenewDelegationTokenResponse>() { @Override public RenewDelegationTokenResponse run() throws IOException, YarnException { return rm.getClientRMService().renewDelegationToken(req); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { if (ue.getCause().getCause() instanceof InvalidToken) { throw new BadRequestException(ue.getCause().getCause().getMessage()); } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) { return Response.status(Status.FORBIDDEN) .entity(ue.getCause().getCause().getMessage()).build(); } LOG.info("Renew delegation token request failed", ue); throw ue; } LOG.info("Renew delegation token request failed", ue); throw ue; } catch (Exception e) { LOG.info("Renew delegation token request failed", e); throw e; } long renewTime = resp.getNextExpirationTime(); DelegationToken respToken = new DelegationToken(); respToken.setNextExpirationTime(renewTime); return Response.status(Status.OK).entity(respToken).build(); }
Example #27
Source File: RMWebServices.java From big-c with Apache License 2.0 | 4 votes |
@DELETE @Path("/delegation-token") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response cancelDelegationToken(@Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException, Exception { init(); UserGroupInformation callerUGI; try { callerUGI = createKerberosUserGroupInformation(hsr); } catch (YarnException ye) { return Response.status(Status.FORBIDDEN).entity(ye.getMessage()).build(); } Token<RMDelegationTokenIdentifier> token = extractToken(hsr); org.apache.hadoop.yarn.api.records.Token dToken = BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind() .toString(), token.getPassword(), token.getService().toString()); final CancelDelegationTokenRequest req = CancelDelegationTokenRequest.newInstance(dToken); try { callerUGI .doAs(new PrivilegedExceptionAction<CancelDelegationTokenResponse>() { @Override public CancelDelegationTokenResponse run() throws IOException, YarnException { return rm.getClientRMService().cancelDelegationToken(req); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { if (ue.getCause().getCause() instanceof InvalidToken) { throw new BadRequestException(ue.getCause().getCause().getMessage()); } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) { return Response.status(Status.FORBIDDEN) .entity(ue.getCause().getCause().getMessage()).build(); } LOG.info("Renew delegation token request failed", ue); throw ue; } LOG.info("Renew delegation token request failed", ue); throw ue; } catch (Exception e) { LOG.info("Renew delegation token request failed", e); throw e; } return Response.status(Status.OK).build(); }
Example #28
Source File: RMWebServices.java From hadoop with Apache License 2.0 | 4 votes |
@DELETE @Path("/delegation-token") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response cancelDelegationToken(@Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException, Exception { init(); UserGroupInformation callerUGI; try { callerUGI = createKerberosUserGroupInformation(hsr); } catch (YarnException ye) { return Response.status(Status.FORBIDDEN).entity(ye.getMessage()).build(); } Token<RMDelegationTokenIdentifier> token = extractToken(hsr); org.apache.hadoop.yarn.api.records.Token dToken = BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind() .toString(), token.getPassword(), token.getService().toString()); final CancelDelegationTokenRequest req = CancelDelegationTokenRequest.newInstance(dToken); try { callerUGI .doAs(new PrivilegedExceptionAction<CancelDelegationTokenResponse>() { @Override public CancelDelegationTokenResponse run() throws IOException, YarnException { return rm.getClientRMService().cancelDelegationToken(req); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { if (ue.getCause().getCause() instanceof InvalidToken) { throw new BadRequestException(ue.getCause().getCause().getMessage()); } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) { return Response.status(Status.FORBIDDEN) .entity(ue.getCause().getCause().getMessage()).build(); } LOG.info("Renew delegation token request failed", ue); throw ue; } LOG.info("Renew delegation token request failed", ue); throw ue; } catch (Exception e) { LOG.info("Renew delegation token request failed", e); throw e; } return Response.status(Status.OK).build(); }
Example #29
Source File: RMWebServices.java From hadoop with Apache License 2.0 | 4 votes |
private Response renewDelegationToken(DelegationToken tokenData, HttpServletRequest hsr, UserGroupInformation callerUGI) throws AuthorizationException, IOException, InterruptedException, Exception { Token<RMDelegationTokenIdentifier> token = extractToken(tokenData.getToken()); org.apache.hadoop.yarn.api.records.Token dToken = BuilderUtils.newDelegationToken(token.getIdentifier(), token.getKind() .toString(), token.getPassword(), token.getService().toString()); final RenewDelegationTokenRequest req = RenewDelegationTokenRequest.newInstance(dToken); RenewDelegationTokenResponse resp; try { resp = callerUGI .doAs(new PrivilegedExceptionAction<RenewDelegationTokenResponse>() { @Override public RenewDelegationTokenResponse run() throws IOException, YarnException { return rm.getClientRMService().renewDelegationToken(req); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { if (ue.getCause().getCause() instanceof InvalidToken) { throw new BadRequestException(ue.getCause().getCause().getMessage()); } else if (ue.getCause().getCause() instanceof org.apache.hadoop.security.AccessControlException) { return Response.status(Status.FORBIDDEN) .entity(ue.getCause().getCause().getMessage()).build(); } LOG.info("Renew delegation token request failed", ue); throw ue; } LOG.info("Renew delegation token request failed", ue); throw ue; } catch (Exception e) { LOG.info("Renew delegation token request failed", e); throw e; } long renewTime = resp.getNextExpirationTime(); DelegationToken respToken = new DelegationToken(); respToken.setNextExpirationTime(renewTime); return Response.status(Status.OK).entity(respToken).build(); }
Example #30
Source File: RMWebServices.java From hadoop with Apache License 2.0 | 4 votes |
/** * Function to submit an app to the RM * * @param newApp * structure containing information to construct the * ApplicationSubmissionContext * @param hsr * the servlet request * @return Response containing the status code * @throws AuthorizationException * @throws IOException * @throws InterruptedException */ @POST @Path("/apps") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response submitApplication(ApplicationSubmissionContextInfo newApp, @Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException { init(); UserGroupInformation callerUGI = getCallerUserGroupInformation(hsr, true); if (callerUGI == null) { throw new AuthorizationException("Unable to obtain user name, " + "user not authenticated"); } if (UserGroupInformation.isSecurityEnabled() && isStaticUser(callerUGI)) { String msg = "The default static user cannot carry out this operation."; return Response.status(Status.FORBIDDEN).entity(msg).build(); } ApplicationSubmissionContext appContext = createAppSubmissionContext(newApp); final SubmitApplicationRequest req = SubmitApplicationRequest.newInstance(appContext); try { callerUGI .doAs(new PrivilegedExceptionAction<SubmitApplicationResponse>() { @Override public SubmitApplicationResponse run() throws IOException, YarnException { return rm.getClientRMService().submitApplication(req); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { throw new BadRequestException(ue.getCause().getMessage()); } LOG.info("Submit app request failed", ue); throw ue; } String url = hsr.getRequestURL() + "/" + newApp.getApplicationId(); return Response.status(Status.ACCEPTED).header(HttpHeaders.LOCATION, url) .build(); }