@Override public LensError getLensError(final int errorCode) { LensError lensError = errors.get(errorCode); if (lensError == null) { if (log.isWarnEnabled()) { log.warn("Error Code {} not found in initialized error collection. This could be a case of a pluggable code " + "trying to send a random error code without initializing it in lens-errors.conf or " + "lens-additional-errors.conf. We will drop this random error code and send INTERNAL SERVER ERROR " + "instead of this.", errorCode); } lensError = errors.get(INTERNAL_SERVER_ERROR.getValue()); } return lensError; }
@Override public LensError getLensError(final int errorCode) { LensError lensError = errors.get(errorCode); if (lensError == null) { if (log.isWarnEnabled()) { log.warn("Error Code {} not found in initialized error collection. This could be a case of a pluggable code " + "trying to send a random error code without initializing it in lens-errors.conf or " + "lens-additional-errors.conf. We will drop this random error code and send INTERNAL SERVER ERROR " + "instead of this.", errorCode); } lensError = errors.get(INTERNAL_SERVER_ERROR.getValue()); } return lensError; }
public MissingParameterException(Collection<String> missingParameters) { super( new LensErrorInfo(MISSING_PARAMETERS.getValue(), 0, MISSING_PARAMETERS.toString()) , Joiner.on(",").join(missingParameters)); this.missingParameters = ImmutableList.copyOf(missingParameters); } }
public MissingParameterException(Collection<String> missingParameters) { super( new LensErrorInfo(MISSING_PARAMETERS.getValue(), 0, MISSING_PARAMETERS.toString()) , Joiner.on(",").join(missingParameters)); this.missingParameters = ImmutableList.copyOf(missingParameters); } }
public SavedQueryNotFound(long id) { super( new LensErrorInfo(RESOURCE_NOT_FOUND.getValue(), 0, RESOURCE_NOT_FOUND.toString()) , SavedQuery.class.getSimpleName() , String.valueOf(id)); this.id = id; } }
public ParameterValueException(String paramName, List<String> values, Throwable cause) { super( new LensErrorInfo(INVALID_PARAMETER_VALUE.getValue(), 0, INVALID_PARAMETER_VALUE.toString()) , values , paramName , cause.getMessage()); this.paramName = paramName; this.values = ImmutableList.copyOf(values); }
public ParameterValueException(String paramName, List<String> values, Throwable cause) { super( new LensErrorInfo(INVALID_PARAMETER_VALUE.getValue(), 0, INVALID_PARAMETER_VALUE.toString()) , values , paramName , cause.getMessage()); this.paramName = paramName; this.values = ImmutableList.copyOf(values); }
public SavedQueryNotFound(long id) { super( new LensErrorInfo(RESOURCE_NOT_FOUND.getValue(), 0, RESOURCE_NOT_FOUND.toString()) , SavedQuery.class.getSimpleName() , String.valueOf(id)); this.id = id; } }
public PrivilegeException(String resourceType, String resourceIdentifier, String privilege) { super( new LensErrorInfo(NOT_AUTHORIZED.getValue(), 0, NOT_AUTHORIZED.toString()) , privilege , resourceType , resourceIdentifier); this.resourceType = resourceType; this.resourceIdentifier = resourceIdentifier; this.privilege = privilege; } }
public PrivilegeException(String resourceType, String resourceIdentifier, String privilege) { super( new LensErrorInfo(NOT_AUTHORIZED.getValue(), 0, NOT_AUTHORIZED.toString()) , privilege , resourceType , resourceIdentifier); this.resourceType = resourceType; this.resourceIdentifier = resourceIdentifier; this.privilege = privilege; } }
@Override public Response toResponse(LensJAXBValidationException e) { ValidationEvent event = e.getEvent(); ValidationEventLocator vel = event.getLocator(); String msg = "XML Validation Exception: " + event.getMessage() + " at row: " + vel.getLineNumber() + " column: " + vel.getColumnNumber(); LensAPIResult lensAPIResult = LensAPIResult.composedOf(null, new MappedDiagnosticLogSegregationContext().getLogSegragationId(), LensErrorTO.composedOf(LensCommonErrorCode.INVALID_XML_ERROR.getValue(), msg, Arrays.toString(e.getStackTrace())), Response.Status.BAD_REQUEST); return Response.status(Response.Status.BAD_REQUEST).entity(lensAPIResult).build(); } }
private void assertXMLError(Response resp, MediaType mt) { assertEquals(resp.getStatus(), 400); if (mt.equals(MediaType.APPLICATION_XML_TYPE)) { LensAPIResult entity = resp.readEntity(LensAPIResult.class); assertTrue(entity.isErrorResult()); assertEquals(entity.getLensErrorTO().getCode(), LensCommonErrorCode.INVALID_XML_ERROR.getValue()); assertTrue(entity.getLensErrorTO().getMessage().contains("unexpected element")); } }
private SchedulerJobInfo checkAndGetSchedulerJobInfo(SchedulerJobHandle jobHandle) throws LensException { SchedulerJobInfo jobInfo = schedulerDAO.getSchedulerJobInfo(jobHandle); if (jobInfo == null) { throw new LensException( new LensErrorInfo(LensCommonErrorCode.RESOURCE_NOT_FOUND.getValue(), 0, "Job handle not found"), null, "job", jobHandle.getHandleIdString()); } return jobInfo; }
/** * Validates the saved query and throws LensException with. * BAD_SYNTAX code if wrong * * @param savedQuery Saved query object * @throws LensException if invalid */ private void validateSampleResolved(@NonNull SavedQuery savedQuery) throws LensException { final String sampleResolved = SavedQueryHelper.getSampleResolvedQuery(savedQuery); try { HQLParser.parseHQL(sampleResolved, new HiveConf()); } catch (Exception e) { throw new LensException( new LensErrorInfo(INVALID_XML_ERROR.getValue(), 0, INVALID_XML_ERROR.toString()) , e , "Encountered while resolving with sample values { " + sampleResolved + " }"); } }
@Test(dataProvider = "mediaTypeData") public void testErrorResponseWhenLensMultiCauseExceptionOccurs(MediaType mt) { LensSessionHandle sessionId = openSession(target(), "foo", "bar", mt); final String testQuery = "select * from non_existing_table"; Response response = estimate(target(), Optional.of(sessionId), Optional.of(testQuery), mt); final String expectedErrMsg1 = "Semantic Error : Error while compiling statement: " + "FAILED: SemanticException [Error 10001]: Line 1:31 Table not found 'non_existing_table'"; final String expectedErrMsg2 = "Semantic Error : user lacks privilege or object not found: NON_EXISTING_TABLE"; LensErrorTO expectedLensErrorTO1 = LensErrorTO.composedOf(INTERNAL_SERVER_ERROR.getValue(), expectedErrMsg1, MOCK_STACK_TRACE); LensErrorTO expectedLensErrorTO2 = LensErrorTO.composedOf(INTERNAL_SERVER_ERROR.getValue(), expectedErrMsg2, MOCK_STACK_TRACE); LensErrorTO responseLensErrorTO = response.readEntity(LensAPIResult.class).getLensErrorTO(); assertTrue(expectedLensErrorTO1.getMessage().equals(responseLensErrorTO.getMessage()) || expectedLensErrorTO2.getMessage().equals(responseLensErrorTO.getMessage()), "Message is " + responseLensErrorTO.getMessage()); closeSession(target(), sessionId, mt); }
/** * Test execute failure in with selected driver throwing Runtime exception. * * @throws InterruptedException the interrupted exception */ @Test(dataProvider = "mediaTypeData") public void testExplainRuntimeException(MediaType mt) throws InterruptedException { LensSessionHandle sessionId = openSession(target(), "foo", "bar", new LensConf(), mt); try { Response response = explain(target(), Optional.of(sessionId), Optional.of("select fail, execute_runtime " + " from non_exist"), mt); final String expectedErrMsg = "Internal server error:Runtime exception from query explain"; LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf( INTERNAL_SERVER_ERROR.getValue(), expectedErrMsg, MOCK_STACK_TRACE); ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(Response.Status.INTERNAL_SERVER_ERROR, expectedLensErrorTO); expectedData.verify(response); } finally { closeSessionFailFast(target(), sessionId, mt); } } /**