List of usage examples for java.lang.reflect UndeclaredThrowableException getCause
public synchronized Throwable getCause()
From source file:org.apache.hadoop.hive.metastore.RetryingHMSHandler.java
public Result invokeInternal(final Object proxy, final Method method, final Object[] args) throws Throwable { boolean gotNewConnectUrl = false; boolean reloadConf = HiveConf.getBoolVar(origConf, HiveConf.ConfVars.HMSHANDLERFORCERELOADCONF); long retryInterval = HiveConf.getTimeVar(origConf, HiveConf.ConfVars.HMSHANDLERINTERVAL, TimeUnit.MILLISECONDS); int retryLimit = HiveConf.getIntVar(origConf, HiveConf.ConfVars.HMSHANDLERATTEMPTS); long timeout = HiveConf.getTimeVar(origConf, HiveConf.ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); Deadline.registerIfNot(timeout);//from w w w .j av a 2 s . c om if (reloadConf) { MetaStoreInit.updateConnectionURL(origConf, getActiveConf(), null, metaStoreInitData); } int retryCount = 0; Throwable caughtException = null; while (true) { try { if (reloadConf || gotNewConnectUrl) { baseHandler.setConf(getActiveConf()); } Object object = null; boolean isStarted = Deadline.startTimer(method.getName()); try { object = method.invoke(baseHandler, args); } finally { if (isStarted) { Deadline.stopTimer(); } } return new Result(object, retryCount); } catch (UndeclaredThrowableException e) { if (e.getCause() != null) { if (e.getCause() instanceof javax.jdo.JDOException) { // Due to reflection, the jdo exception is wrapped in // invocationTargetException caughtException = e.getCause(); } else if (e.getCause() instanceof MetaException && e.getCause().getCause() != null && e.getCause().getCause() instanceof javax.jdo.JDOException) { // The JDOException may be wrapped further in a MetaException caughtException = e.getCause().getCause(); } else { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } } else { LOG.error(ExceptionUtils.getStackTrace(e)); throw e; } } catch (InvocationTargetException e) { if (e.getCause() instanceof javax.jdo.JDOException) { // Due to reflection, the jdo exception is wrapped in // invocationTargetException caughtException = e.getCause(); } else if (e.getCause() instanceof NoSuchObjectException || e.getTargetException().getCause() instanceof NoSuchObjectException) { String methodName = method.getName(); if (!methodName.startsWith("get_database") && !methodName.startsWith("get_table") && !methodName.startsWith("get_partition") && !methodName.startsWith("get_function")) { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); } throw e.getCause(); } else if (e.getCause() instanceof MetaException && e.getCause().getCause() != null) { if (e.getCause().getCause() instanceof javax.jdo.JDOException || e.getCause().getCause() instanceof NucleusException) { // The JDOException or the Nucleus Exception may be wrapped further in a MetaException caughtException = e.getCause().getCause(); } else if (e.getCause().getCause() instanceof DeadlineException) { // The Deadline Exception needs no retry and be thrown immediately. Deadline.clear(); LOG.error("Error happens in method " + method.getName() + ": " + ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } else { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } } else { LOG.error(ExceptionUtils.getStackTrace(e.getCause())); throw e.getCause(); } } if (retryCount >= retryLimit) { LOG.error("HMSHandler Fatal error: " + ExceptionUtils.getStackTrace(caughtException)); MetaException me = new MetaException(caughtException.getMessage()); me.initCause(caughtException); throw me; } assert (retryInterval >= 0); retryCount++; LOG.error(String.format("Retrying HMSHandler after %d ms (attempt %d of %d)", retryInterval, retryCount, retryLimit) + " with error: " + ExceptionUtils.getStackTrace(caughtException)); Thread.sleep(retryInterval); // If we have a connection error, the JDO connection URL hook might // provide us with a new URL to access the datastore. String lastUrl = MetaStoreInit.getConnectionURL(getActiveConf()); gotNewConnectUrl = MetaStoreInit.updateConnectionURL(origConf, getActiveConf(), lastUrl, metaStoreInitData); } }
From source file:org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.java
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object ret = null;//from w w w.j a v a 2 s.co m int retriesMade = 0; TException caughtException = null; while (true) { try { reloginExpiringKeytabUser(); if (retriesMade > 0 || hasConnectionLifeTimeReached(method)) { base.reconnect(); lastConnectionTime = System.currentTimeMillis(); } if (metaCallTimeMap == null) { ret = method.invoke(base, args); } else { // need to capture the timing long startTime = System.currentTimeMillis(); ret = method.invoke(base, args); long timeTaken = System.currentTimeMillis() - startTime; addMethodTime(method, timeTaken); } break; } catch (UndeclaredThrowableException e) { throw e.getCause(); } catch (InvocationTargetException e) { if ((e.getCause() instanceof TApplicationException) || (e.getCause() instanceof TProtocolException) || (e.getCause() instanceof TTransportException)) { caughtException = (TException) e.getCause(); } else if ((e.getCause() instanceof MetaException) && e.getCause().getMessage() .matches("(?s).*(JDO[a-zA-Z]*|TApplication|TProtocol|TTransport)Exception.*")) { caughtException = (MetaException) e.getCause(); } else { throw e.getCause(); } } catch (MetaException e) { if (e.getMessage().matches("(?s).*(IO|TTransport)Exception.*")) { caughtException = e; } else { throw e; } } if (retriesMade >= retryLimit) { throw caughtException; } retriesMade++; LOG.warn("MetaStoreClient lost connection. Attempting to reconnect.", caughtException); Thread.sleep(retryDelaySeconds * 1000); } return ret; }
From source file:org.apache.hadoop.yarn.applications.amonly.ApplicationMaster.java
@VisibleForTesting void startTimelineClient(final Configuration conf) throws YarnException, IOException, InterruptedException { try {/*from w w w . j a v a 2s . com*/ appSubmitterUgi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) { // Creating the Timeline Client timelineClient = TimelineClient.createTimelineClient(); timelineClient.init(conf); timelineClient.start(); } else { timelineClient = null; LOG.warn("Timeline service is not enabled"); } return null; } }); } catch (UndeclaredThrowableException e) { throw new YarnException(e.getCause()); } }
From source file:org.apache.hadoop.yarn.client.api.impl.TimelineWriter.java
private ClientResponse doPosting(final Object obj, final String path) throws IOException, YarnException { ClientResponse resp;/*from w ww. j a v a 2s.co m*/ try { resp = authUgi.doAs(new PrivilegedExceptionAction<ClientResponse>() { @Override public ClientResponse run() throws Exception { return doPostingObject(obj, path); } }); } catch (UndeclaredThrowableException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } else { throw new IOException(cause); } } catch (InterruptedException ie) { throw (IOException) new InterruptedIOException().initCause(ie); } if (resp == null || resp.getClientResponseStatus() != ClientResponse.Status.OK) { String msg = "Failed to get the response from the timeline server."; LOG.error(msg); if (resp != null) { msg += " HTTP error code: " + resp.getStatus(); if (LOG.isDebugEnabled()) { String output = resp.getEntity(String.class); LOG.debug("HTTP error code: " + resp.getStatus() + " Server response : \n" + output); } } throw new YarnException(msg); } return resp; }
From source file:org.apache.hadoop.yarn.server.resourcemanager.MockAM.java
public RegisterApplicationMasterResponse registerAppAttempt(boolean wait) throws Exception { if (wait) {/*from w w w .j av a 2 s .c o m*/ waitForState(RMAppAttemptState.LAUNCHED); } responseId = 0; final RegisterApplicationMasterRequest req = Records.newRecord(RegisterApplicationMasterRequest.class); req.setHost("test"); req.setRpcPort(1); req.setTrackingUrl(""); UserGroupInformation ugi = UserGroupInformation.createRemoteUser(attemptId.toString()); Token<AMRMTokenIdentifier> token = context.getRMApps().get(attemptId.getApplicationId()) .getRMAppAttempt(attemptId).getAMRMToken(); ugi.addTokenIdentifier(token.decodeIdentifier()); try { return ugi.doAs(new PrivilegedExceptionAction<RegisterApplicationMasterResponse>() { @Override public RegisterApplicationMasterResponse run() throws Exception { return amRMProtocol.registerApplicationMaster(req); } }); } catch (UndeclaredThrowableException e) { throw (Exception) e.getCause(); } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.MockAM.java
public AllocateResponse allocate(List<ResourceRequest> resourceRequest, List<ContainerId> releases) throws Exception { final AllocateRequest req = AllocateRequest.newInstance(++responseId, 0F, resourceRequest, releases, null); UserGroupInformation ugi = UserGroupInformation.createRemoteUser(attemptId.toString()); Token<AMRMTokenIdentifier> token = context.getRMApps().get(attemptId.getApplicationId()) .getRMAppAttempt(attemptId).getAMRMToken(); ugi.addTokenIdentifier(token.decodeIdentifier()); try {//w ww . ja va 2 s .co m return ugi.doAs(new PrivilegedExceptionAction<AllocateResponse>() { @Override public AllocateResponse run() throws Exception { return amRMProtocol.allocate(req); } }); } catch (UndeclaredThrowableException e) { throw (Exception) e.getCause(); } }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
protected Response killApp(RMApp app, UserGroupInformation callerUGI, HttpServletRequest hsr, final String diagnostic) throws IOException, InterruptedException { if (app == null) { throw new IllegalArgumentException("app cannot be null"); }//from www . j a v a2 s .c o m String userName = callerUGI.getUserName(); final ApplicationId appid = app.getApplicationId(); KillApplicationResponse resp = null; try { resp = callerUGI.doAs(new PrivilegedExceptionAction<KillApplicationResponse>() { @Override public KillApplicationResponse run() throws IOException, YarnException { KillApplicationRequest req = KillApplicationRequest.newInstance(appid); if (diagnostic != null) { req.setDiagnostics(diagnostic); } return rm.getClientRMService().forceKillApplication(req); } }); } catch (UndeclaredThrowableException ue) { // if the root cause is a permissions issue // bubble that up to the user if (ue.getCause() instanceof YarnException) { YarnException ye = (YarnException) ue.getCause(); if (ye.getCause() instanceof AccessControlException) { String appId = app.getApplicationId().toString(); String msg = "Unauthorized attempt to kill appid " + appId + " by remote user " + userName; return Response.status(Status.FORBIDDEN).entity(msg).build(); } else { throw ue; } } else { throw ue; } } AppState ret = new AppState(); ret.setState(app.getState().toString()); if (resp.getIsKillCompleted()) { RMAuditLogger.logSuccess(userName, AuditConstants.KILL_APP_REQUEST, "RMWebService", app.getApplicationId()); } else { return Response.status(Status.ACCEPTED).entity(ret).header(HttpHeaders.LOCATION, hsr.getRequestURL()) .build(); } return Response.status(Status.OK).entity(ret).build(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
private Response modifyApplicationPriority(final RMApp app, UserGroupInformation callerUGI, final int appPriority) throws IOException, InterruptedException { String userName = callerUGI.getUserName(); try {// w w w .j a va2 s . c om callerUGI.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws IOException, YarnException { Priority priority = Priority.newInstance(appPriority); UpdateApplicationPriorityRequest request = UpdateApplicationPriorityRequest .newInstance(app.getApplicationId(), priority); rm.getClientRMService().updateApplicationPriority(request); return null; } }); } catch (UndeclaredThrowableException ue) { // if the root cause is a permissions issue // bubble that up to the user if (ue.getCause() instanceof YarnException) { YarnException ye = (YarnException) ue.getCause(); if (ye.getCause() instanceof AccessControlException) { String appId = app.getApplicationId().toString(); String msg = "Unauthorized attempt to change priority of appid " + appId + " by remote user " + userName; return Response.status(Status.FORBIDDEN).entity(msg).build(); } else if (ye.getMessage().startsWith("Application in") && ye.getMessage().endsWith("state cannot be update priority.")) { return Response.status(Status.BAD_REQUEST).entity(ye.getMessage()).build(); } else { throw ue; } } else { throw ue; } } AppPriority ret = new AppPriority(app.getApplicationSubmissionContext().getPriority().getPriority()); return Response.status(Status.OK).entity(ret).build(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
protected Response moveApp(RMApp app, UserGroupInformation callerUGI, String targetQueue) throws IOException, InterruptedException { if (app == null) { throw new IllegalArgumentException("app cannot be null"); }/*from w w w.j a va 2s . c o m*/ String userName = callerUGI.getUserName(); final ApplicationId appid = app.getApplicationId(); final String reqTargetQueue = targetQueue; try { callerUGI.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws IOException, YarnException { MoveApplicationAcrossQueuesRequest req = MoveApplicationAcrossQueuesRequest.newInstance(appid, reqTargetQueue); rm.getClientRMService().moveApplicationAcrossQueues(req); return null; } }); } catch (UndeclaredThrowableException ue) { // if the root cause is a permissions issue // bubble that up to the user if (ue.getCause() instanceof YarnException) { YarnException ye = (YarnException) ue.getCause(); if (ye.getCause() instanceof AccessControlException) { String appId = app.getApplicationId().toString(); String msg = "Unauthorized attempt to move appid " + appId + " by remote user " + userName; return Response.status(Status.FORBIDDEN).entity(msg).build(); } else if (ye.getMessage().startsWith("App in") && ye.getMessage().endsWith("state cannot be moved.")) { return Response.status(Status.BAD_REQUEST).entity(ye.getMessage()).build(); } else { throw ue; } } else { throw ue; } } AppQueue ret = new AppQueue(); ret.setQueue(app.getQueue()); return Response.status(Status.OK).entity(ret).build(); }
From source file:org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices.java
/** * Function to submit an app to the RM//from w w w.ja va 2 s . com * * @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(); }