List of usage examples for java.lang.reflect UndeclaredThrowableException getCause
public synchronized Throwable getCause()
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
private Response renewDelegationToken(DelegationToken tokenData, HttpServletRequest hsr, UserGroupInformation callerUGI)/* www . j a v a 2 s . c o m*/ 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(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
@DELETE @Path("/delegation-token") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response cancelDelegationToken(@Context HttpServletRequest hsr) throws AuthorizationException, IOException, InterruptedException, Exception { init();/*w ww . jav a 2s .c o m*/ 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(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
/** * Function to submit a Reservation to the RM. * * @param resContext provides information to construct the * ReservationSubmissionRequest * @param hsr the servlet request/*from w w w .j a v a2 s . c o m*/ * @return Response containing the status code * @throws AuthorizationException * @throws IOException * @throws InterruptedException */ @POST @Path("/reservation/submit") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response submitReservation(ReservationSubmissionRequestInfo resContext, @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(); } final ReservationSubmissionRequest reservation = createReservationSubmissionRequest(resContext); try { callerUGI.doAs(new PrivilegedExceptionAction<ReservationSubmissionResponse>() { @Override public ReservationSubmissionResponse run() throws IOException, YarnException { return rm.getClientRMService().submitReservation(reservation); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { throw new BadRequestException(ue.getCause().getMessage()); } LOG.info("Submit reservation request failed", ue); throw ue; } return Response.status(Status.ACCEPTED).build(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
/** * Function to update a Reservation to the RM. * * @param resContext provides information to construct the * ReservationUpdateRequest// www .ja va2 s. com * @param hsr the servlet request * @return Response containing the status code * @throws AuthorizationException * @throws IOException * @throws InterruptedException */ @POST @Path("/reservation/update") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response updateReservation(ReservationUpdateRequestInfo resContext, @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(); } final ReservationUpdateRequest reservation = createReservationUpdateRequest(resContext); ReservationUpdateResponseInfo resRespInfo; try { resRespInfo = callerUGI.doAs(new PrivilegedExceptionAction<ReservationUpdateResponseInfo>() { @Override public ReservationUpdateResponseInfo run() throws IOException, YarnException { rm.getClientRMService().updateReservation(reservation); return new ReservationUpdateResponseInfo(); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { throw new BadRequestException(ue.getCause().getMessage()); } LOG.info("Update reservation request failed", ue); throw ue; } return Response.status(Status.OK).entity(resRespInfo).build(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
/** * Function to delete a Reservation to the RM. * * @param resContext provides information to construct * the ReservationDeleteRequest * @param hsr the servlet request/*w w w .j av a2 s .com*/ * @return Response containing the status code * @throws AuthorizationException when the user group information cannot be * retrieved. * @throws IOException when a {@link ReservationDeleteRequest} cannot be * created from the {@link ReservationDeleteRequestInfo}. This * exception is also thrown on * {@code ClientRMService.deleteReservation} invokation failure. * @throws InterruptedException if doAs action throws an InterruptedException. */ @POST @Path("/reservation/delete") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response deleteReservation(ReservationDeleteRequestInfo resContext, @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(); } final ReservationDeleteRequest reservation = createReservationDeleteRequest(resContext); ReservationDeleteResponseInfo resRespInfo; try { resRespInfo = callerUGI.doAs(new PrivilegedExceptionAction<ReservationDeleteResponseInfo>() { @Override public ReservationDeleteResponseInfo run() throws IOException, YarnException { rm.getClientRMService().deleteReservation(reservation); return new ReservationDeleteResponseInfo(); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { throw new BadRequestException(ue.getCause().getMessage()); } LOG.info("Update reservation request failed", ue); throw ue; } return Response.status(Status.OK).entity(resRespInfo).build(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
/** * Function to retrieve a list of all the reservations. *//*from ww w . j a va 2s . co m*/ @GET @Path("/reservation/list") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response listReservation(@QueryParam("queue") @DefaultValue("default") String queue, @QueryParam("reservation-id") @DefaultValue("") String reservationId, @QueryParam("start-time") @DefaultValue("0") long startTime, @QueryParam("end-time") @DefaultValue("-1") long endTime, @QueryParam("include-resource-allocations") @DefaultValue("false") boolean includeResourceAllocations, @Context HttpServletRequest hsr) throws Exception { init(); final ReservationListRequest request = ReservationListRequest.newInstance(queue, reservationId, startTime, endTime, includeResourceAllocations); 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(); } ReservationListResponse resRespInfo; try { resRespInfo = callerUGI.doAs(new PrivilegedExceptionAction<ReservationListResponse>() { @Override public ReservationListResponse run() throws IOException, YarnException { return rm.getClientRMService().listReservations(request); } }); } catch (UndeclaredThrowableException ue) { if (ue.getCause() instanceof YarnException) { throw new BadRequestException(ue.getCause().getMessage()); } LOG.info("List reservation request failed", ue); throw ue; } ReservationListInfo resResponse = new ReservationListInfo(resRespInfo, includeResourceAllocations); return Response.status(Status.OK).entity(resResponse).build(); }
From source file:org.apache.hawq.pxf.service.servlet.SecurityServletFilter.java
/** * If user impersonation is configured, examines the request for the presense of the expected security headers * and create a proxy user to execute further request chain. Responds with an HTTP error if the header is missing * or the chain processing throws an exception. * * @param request http request//ww w . j av a 2 s .c om * @param response http response * @param chain filter chain */ @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { if (SecureLogin.isUserImpersonationEnabled()) { // retrieve user header and make sure header is present and is not empty final String gpdbUser = getHeaderValue(request, USER_HEADER, true); final String transactionId = getHeaderValue(request, TRANSACTION_ID_HEADER, true); final Integer segmentId = getHeaderValueInt(request, SEGMENT_ID_HEADER, true); final boolean lastCallForSegment = getHeaderValueBoolean(request, LAST_FRAGMENT_HEADER, false); SessionId session = new SessionId(segmentId, transactionId, gpdbUser); // TODO refresh Kerberos token when security is enabled // prepare privileged action to run on behalf of proxy user PrivilegedExceptionAction<Boolean> action = new PrivilegedExceptionAction<Boolean>() { @Override public Boolean run() throws IOException, ServletException { if (LOG.isDebugEnabled()) { LOG.debug("Performing request chain call for proxy user = " + gpdbUser); } chain.doFilter(request, response); return true; } }; if (LOG.isDebugEnabled()) { LOG.debug("Retrieving proxy user for session: " + session); } try { // Retrieve proxy user UGI from the UGI of the logged in user // and execute the servlet chain as that user proxyUGICache.getUserGroupInformation(session).doAs(action); } catch (UndeclaredThrowableException ute) { // unwrap the real exception thrown by the action throw new ServletException(ute.getCause()); } catch (InterruptedException ie) { throw new ServletException(ie); } finally { // Optimization to cleanup the cache if it is the last fragment if (LOG.isDebugEnabled()) { LOG.debug("Releasing proxy user for session: " + session + (lastCallForSegment ? " Last fragment call." : "")); } try { proxyUGICache.release(session, lastCallForSegment); } catch (Throwable t) { LOG.error("Error releasing UGICache for session: " + session, t); } } } else { // no user impersonation is configured chain.doFilter(request, response); } }
From source file:org.apache.hive.service.cli.thrift.RetryingThriftCLIServiceClient.java
protected InvocationResult invokeInternal(Method method, Object[] args) throws Throwable { InvocationResult result;//from w w w.j ava 2s . c o m try { Object methodResult = method.invoke(base, args); result = new InvocationResult(true, methodResult, null); } catch (UndeclaredThrowableException e) { throw e.getCause(); } catch (InvocationTargetException e) { if (e.getCause() instanceof HiveSQLException) { HiveSQLException hiveExc = (HiveSQLException) e.getCause(); Throwable cause = hiveExc.getCause(); if ((cause instanceof TApplicationException) || (cause instanceof TProtocolException) || (cause instanceof TTransportException)) { result = new InvocationResult(false, null, hiveExc); } else { throw hiveExc; } } else { throw e.getCause(); } } return result; }
From source file:org.apache.nifi.dbcp.hive.Hive3ConnectionPool.java
@Override public Connection getConnection() throws ProcessException { try {//www . j av a 2 s . c o m if (ugi != null) { try { return ugi.doAs((PrivilegedExceptionAction<Connection>) () -> dataSource.getConnection()); } catch (UndeclaredThrowableException e) { Throwable cause = e.getCause(); if (cause instanceof SQLException) { throw (SQLException) cause; } else { throw e; } } } else { getLogger().info("Simple Authentication"); return dataSource.getConnection(); } } catch (SQLException | IOException | InterruptedException e) { getLogger().error("Error getting Hive connection", e); throw new ProcessException(e); } }
From source file:org.apache.nifi.dbcp.hive.Hive_1_1ConnectionPool.java
@Override public Connection getConnection() throws ProcessException { try {// w ww . j ava 2s .c o m if (ugi != null) { synchronized (this) { /* * Make sure that only one thread can request that the UGI relogin at a time. This * explicit relogin attempt is necessary due to the Hive client/thrift not implicitly handling * the acquisition of a new TGT after the current one has expired. * https://issues.apache.org/jira/browse/NIFI-5134 */ ugi.checkTGTAndReloginFromKeytab(); } try { return ugi.doAs((PrivilegedExceptionAction<Connection>) () -> dataSource.getConnection()); } catch (UndeclaredThrowableException e) { Throwable cause = e.getCause(); if (cause instanceof SQLException) { throw (SQLException) cause; } else { throw e; } } } else { getLogger().info("Simple Authentication"); return dataSource.getConnection(); } } catch (SQLException | IOException | InterruptedException e) { getLogger().error("Error getting Hive connection", e); throw new ProcessException(e); } }