private void initializeErrorCollection() { try { errorCollection = new ErrorCollectionFactory().createErrorCollection(); } catch (ClassNotFoundException e) { throw new RuntimeException("Could not create error collection.", e); } }
@Override public JAXBContext getContext(Class<?> type) { JAXBContext jaxbContext = jaxbContextCache.get(type); if (jaxbContext == null) { log.debug("JAXB instance to be created for {}", type); try { if (type.equals(LensAPIResult.class)) { ErrorCollection errorCollection = new ErrorCollectionFactory().createErrorCollection(); Set<Class> classesToBeBound = Sets.newHashSet(errorCollection.getErrorPayloadClasses()); log.debug("classesToBeBound:{}", classesToBeBound); classesToBeBound.add(type); Class[] classesToBeBoundArray = classesToBeBound.toArray(new Class[classesToBeBound.size()]); jaxbContext = new LensJAXBContext(classesToBeBoundArray); } else { jaxbContext = new LensJAXBContext(type); } jaxbContextCache.put(type, jaxbContext); } catch (JAXBException | ClassNotFoundException e) { log.error("JAXBContext not initialized for " + type, e); } } return jaxbContext; } }
@Override public JAXBContext getContext(Class<?> type) { JAXBContext jaxbContext = jaxbContextCache.get(type); if (jaxbContext == null) { log.debug("JAXB instance to be created for {}", type); try { if (type.equals(LensAPIResult.class)) { ErrorCollection errorCollection = new ErrorCollectionFactory().createErrorCollection(); Set<Class> classesToBeBound = Sets.newHashSet(errorCollection.getErrorPayloadClasses()); log.debug("classesToBeBound:{}", classesToBeBound); classesToBeBound.add(type); Class[] classesToBeBoundArray = classesToBeBound.toArray(new Class[classesToBeBound.size()]); jaxbContext = new LensJAXBContext(classesToBeBoundArray); } else { jaxbContext = new LensJAXBContext(type); } jaxbContextCache.put(type, jaxbContext); } catch (JAXBException | ClassNotFoundException e) { log.error("JAXBContext not initialized for " + type, e); } } return jaxbContext; } }
static PruneCauses.BriefAndDetailedError extractPruneCause(LensException e) throws ClassNotFoundException { try { ErrorCollection errorCollection = new ErrorCollectionFactory().createErrorCollection(); final LensError lensError = errorCollection.getLensError(e.getErrorCode()); return new ObjectMapper().readValue( e.getFormattedErrorMsg(lensError).substring(e.getFormattedErrorMsg(lensError) .indexOf("{"), e.getFormattedErrorMsg(lensError).length()), new TypeReference<PruneCauses.BriefAndDetailedError>() {}); } catch (IOException e1) { throw new RuntimeException("!!!"); } }
protected String getLensExceptionErrorMessageInRewrite(String query, Configuration conf) throws LensException, ParseException, ClassNotFoundException { try { String hql = rewrite(query, conf); Assert.fail("Should have thrown exception. But rewrote the query : " + hql); // unreachable return null; } catch (LensException e) { ErrorCollection errorCollection = new ErrorCollectionFactory().createErrorCollection(); final LensError lensError = errorCollection.getLensError(e.getErrorCode()); log.error("Lens exception in Rewrite.", e); return e.getFormattedErrorMsg(lensError); } }
@Test public void testColumnErrors() throws Exception { LensException e; e = getLensExceptionInRewrite("select msr11 + msr2 from basecube" + " where " + TWO_DAYS_RANGE, conf); e.buildLensErrorResponse(new ErrorCollectionFactory().createErrorCollection(), null, "testid"); assertEquals(e.getErrorCode(), LensCubeErrorCode.NO_FACT_HAS_COLUMN.getLensErrorInfo().getErrorCode()); assertTrue(e.getMessage().contains("msr11"), e.getMessage()); assertTrue(e.getMessage().contains("msr2"), e.getMessage()); // no fact has the all the dimensions queried e = getLensExceptionInRewrite("select dim1, test_time_dim, msr3, msr13 from basecube where " + TWO_DAYS_RANGE, conf); assertEquals(e.getErrorCode(), LensCubeErrorCode.NO_JOIN_CANDIDATE_AVAILABLE.getLensErrorInfo().getErrorCode()); assertTrue(e.getMessage().contains("[msr3, msr13]")); }