/** * Return query for all <code>HttpTimerData</code> objects. * * @param httpData * <code>HttpTimerData</code> object used to retrieve the platformId * @param fromDate * the fromDate or <code>null</code> if not applicable * @param toDate * the toDate or <code>null</code> if not applicable * @return Query for all <code>HttpTimerData</code> objects in the buffer. */ public E getFindAllHttpTimersQuery(HttpTimerData httpData, Date fromDate, Date toDate) { E query = getIndexQueryProvider().getIndexQuery(); query.setPlatformIdent(httpData.getPlatformIdent()); ArrayList<Class<?>> classesToSearch = new ArrayList<>(); classesToSearch.add(HttpTimerData.class); classesToSearch.add(AggregatedHttpTimerData.class); query.setObjectClasses(classesToSearch); if (null != fromDate) { query.setFromDate(new Timestamp(fromDate.getTime())); } if (null != toDate) { query.setToDate(new Timestamp(toDate.getTime())); } return query; }
Root<? extends HttpTimerData> root = criteria.from(HttpTimerData.class); Predicate platformId = builder.equal(root.get("platformIdent"), templates.iterator().next().getPlatformIdent()); Predicate timestamp = builder.between(root.<Timestamp> get("timeStamp"), new Timestamp(fromDate.getTime()), new Timestamp(toDate.getTime())); Predicate condition = null;
/** * Return query for all <code>HttpTimerData</code> objects that have a inspectIT tag header * value. * * @param httpData * <code>HttpTimerData</code> object used to retrieve the platformId * @param fromDate * the fromDate or <code>null</code> if not applicable * @param toDate * the toDate or <code>null</code> if not applicable * @return Query for all <code>HttpTimerData</code> objects in the buffer. */ public E getFindAllTaggedHttpTimersQuery(HttpTimerData httpData, Date fromDate, Date toDate) { E query = getIndexQueryProvider().getIndexQuery(); query.setPlatformIdent(httpData.getPlatformIdent()); ArrayList<Class<?>> classesToSearch = new ArrayList<>(); classesToSearch.add(HttpTimerData.class); classesToSearch.add(AggregatedHttpTimerData.class); query.setObjectClasses(classesToSearch); query.addIndexingRestriction(IndexQueryRestrictionFactory.isNotNull("httpInfo.inspectItTaggingHeaderValue")); if (null != fromDate) { query.setFromDate(new Timestamp(fromDate.getTime())); } if (null != toDate) { query.setToDate(new Timestamp(toDate.getTime())); } return query; } }
@Test public void noTag() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(URI); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(false); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(null); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Http.TAG_INSPECTIT_TAGGING_HEADER))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
@Test public void noUri() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(null); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(false); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(null); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), not(hasKey(Series.Http.TAG_URI))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
@Test public void noPlatform() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(null); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(URI); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(true); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(TAG); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), not(hasKey(Series.TAG_AGENT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(RandomUtils.nextDouble()); when(data.getHttpInfo()).thenReturn(httpInfo); when(httpInfo.getUri()).thenReturn(URI); when(httpInfo.hasInspectItTaggingHeader()).thenReturn(true); when(httpInfo.getInspectItTaggingHeaderValue()).thenReturn(TAG); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.Http.NAME)); assertThat(getTime(pointBuilder), is(time)); assertThat(getPrecision(pointBuilder), is(TimeUnit.MILLISECONDS)); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_ID, String.valueOf(PLATFORM_ID))); assertThat(getTags(pointBuilder), hasEntry(Series.TAG_AGENT_NAME, String.valueOf(AGENT_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.Http.TAG_URI, String.valueOf(URI))); assertThat(getTags(pointBuilder), hasEntry(Series.Http.TAG_INSPECTIT_TAGGING_HEADER, String.valueOf(TAG))); assertThat(getFields(pointBuilder), hasEntry(Series.Http.FIELD_DURATION, (Object) data.getDuration())); }
idDefinition.setPlatformId(templates.get(0).getPlatformIdent()); idDefinition.setSensorTypeId(templates.get(0).getSensorTypeIdent()); inputDefinition.setIdDefinition(idDefinition);
/** * {@inheritDoc} */ @Override public IAggregatedData<HttpTimerData> getClone(HttpTimerData httpData) { AggregatedHttpTimerData clone = new AggregatedHttpTimerData(); clone.setPlatformIdent(httpData.getPlatformIdent()); clone.setSensorTypeIdent(httpData.getSensorTypeIdent()); clone.setMethodIdent(httpData.getMethodIdent()); clone.setCharting(httpData.isCharting()); if (uriBased) { clone.getHttpInfo().setUri(httpData.getHttpInfo().getUri()); } else { // Aggregation based on Usecase. We reset the URI so that we can easily know // that use case aggregation is used. clone.getHttpInfo().setUri(HttpInfo.UNDEFINED); clone.getHttpInfo().setInspectItTaggingHeaderValue(httpData.getHttpInfo().getInspectItTaggingHeaderValue()); } clone.getHttpInfo().setRequestMethod(httpData.getHttpInfo().getRequestMethod()); return clone; }