@Test public void testGetIndividualExceptions() throws Exception{ PowerMockito.mockStatic(ESUtils.class); PowerMockito.when(ESUtils.getEsUrl()).thenReturn(""); try { PowerMockito.when(ESUtils.getDataFromES(anyString(), anyString(), anyString(), anyMap(), anyMap(), any(HashMultimap.class), anyList(), anyLong(), anyLong())).thenReturn(new ArrayList()); } catch (Exception e) { } exManager.getIndividualExceptions("ec2"); }
@Override public Map<String, IssueException> getIndividualExceptions(String resourceType) throws Exception { String indexName = "*_" + resourceType; String type = "issue_" + resourceType + "_exception"; Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("exceptionEndDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), indexName, type, mustFilter, null, null, null, 0, 20); Map<String, IssueException> individualExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.INDIVIDUAL)) .collect(Collectors.toMap(IssueException::getIssueId, obj -> obj, (oldval, newval) -> { logger.error( "duplicate exceptions are found in the system, please fix the source, ignoring for now --> " + oldval); return newval; })); if (null != individualExceptions) { logger.info("got " + individualExceptions.size() + " individual exceptions"); } return individualExceptions; }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, IssueException> getIndividualExceptions(String resourceType) throws Exception { String indexName = "*_" + resourceType; String type = "issue_" + resourceType + "_exception"; Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("exceptionEndDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), indexName, type, mustFilter, null, null, null, 0, 20); Map<String, IssueException> individualExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.INDIVIDUAL)) .collect(Collectors.toMap(IssueException::getIssueId, obj -> obj, (oldval, newval) -> { logger.error( "duplicate exceptions are found in the system, please fix the source, ignoring for now --> " + oldval); return newval; })); if (null != individualExceptions) { logger.info("got " + individualExceptions.size() + " individual exceptions"); } return individualExceptions; } }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, IssueException> getIndividualExceptions(String resourceType) throws Exception { String indexName = "*_" + resourceType; String type = "issue_" + resourceType + "_exception"; Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("exceptionEndDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), indexName, type, mustFilter, null, null, null, 0, 20); Map<String, IssueException> individualExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.INDIVIDUAL)) .collect(Collectors.toMap(IssueException::getIssueId, obj -> obj, (oldval, newval) -> { logger.error( "duplicate exceptions are found in the system, please fix the source, ignoring for now --> " + oldval); return newval; })); if (null != individualExceptions) { logger.info("got " + individualExceptions.size() + " individual exceptions"); } return individualExceptions; }  }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, IssueException> getIndividualExceptions(String resourceType) throws Exception { String indexName = "*_" + resourceType; String type = "issue_" + resourceType + "_exception"; Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("exceptionEndDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), indexName, type, mustFilter, null, null, null, 0, 20); Map<String, IssueException> individualExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.INDIVIDUAL)) .collect(Collectors.toMap(IssueException::getIssueId, obj -> obj, (oldval, newval) -> { logger.error( "duplicate exceptions are found in the system, please fix the source, ignoring for now --> " + oldval); return newval; })); if (null != individualExceptions) { logger.info("got " + individualExceptions.size() + " individual exceptions"); } return individualExceptions; }  @Override Map<String, IssueException> getIndividualExceptions(String resourceType); @Override Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType); }
ExceptionManagerImpl implements ExceptionManager { @Override public Map<String, IssueException> getIndividualExceptions(String resourceType) throws Exception { String indexName = "*_" + resourceType; String type = "issue_" + resourceType + "_exception"; Map<String, Object> mustFilter = new HashMap<>(); Map<String, Object> rangeMap = new HashMap<String, Object>(); rangeMap.put("gte", "now"); Map<String, Object> dateRangeMap = new HashMap<String, Object>(); dateRangeMap.put("exceptionEndDate", rangeMap); mustFilter.put("range", dateRangeMap); List<Map<String, String>> exceptions = ESUtils.getDataFromES(ESUtils.getEsUrl(), indexName, type, mustFilter, null, null, null, 0, 20); Map<String, IssueException> individualExceptions = exceptions.stream() .map(obj -> new IssueException(obj, ExceptionType.INDIVIDUAL)) .collect(Collectors.toMap(IssueException::getIssueId, obj -> obj, (oldval, newval) -> { logger.error( "duplicate exceptions are found in the system, please fix the source, ignoring for now --> " + oldval); return newval; })); if (null != individualExceptions) { logger.info("got " + individualExceptions.size() + " individual exceptions"); } return individualExceptions; }  @Override Map<String, IssueException> getIndividualExceptions(String resourceType); @Override Map<String, List<IssueException>> getStickyExceptions(String ruleId, String resourceType);  }