/** * {@inheritDoc} */ @Override public Object getKey(E element) { if (0 == element.getPlatformIdent()) { return null; } return element.getPlatformIdent(); }
/** * Returns the platform id for the object. * * @param firstElement * Object. * @return If object is instance of {@link DefaultData} method returns its platform id, * otherwise 0. */ private long getPlatformIdent(Object firstElement) { if (firstElement instanceof DefaultData) { return ((DefaultData) firstElement).getPlatformIdent(); } return 0; }
/** * {@inheritDoc} */ @Override protected boolean shouldBePassedToChainedProcessors(DefaultData defaultData) { return agentIds.contains(Long.valueOf(defaultData.getPlatformIdent())); }
/** * {@inheritDoc} */ @Override public List<DefaultData> findByExampleSinceIdIgnoreMethodId(DefaultData template) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<DefaultData> criteria = builder.createQuery(DefaultData.class); Root<? extends DefaultData> root = criteria.from(template.getClass()); criteria.select(root); Predicate id = builder.greaterThan(root.<Long> get("id"), template.getId()); Predicate platformId = builder.equal(root.get("platformIdent"), template.getPlatformIdent()); criteria.where(id, platformId); return entityManager.createQuery(criteria).getResultList(); }
/** * {@inheritDoc} */ @Override public List<DefaultData> findByExampleWithLastInterval(DefaultData template, long timeInterval) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<DefaultData> criteria = builder.createQuery(DefaultData.class); Root<? extends DefaultData> root = criteria.from(template.getClass()); criteria.select(root); Predicate platformId = builder.equal(root.get("platformIdent"), template.getPlatformIdent()); Predicate sensorTypeId = builder.equal(root.get("sensorTypeIdent"), template.getSensorTypeIdent()); Predicate timestamp = builder.greaterThan(root.<Timestamp> get("timeStamp"), new Timestamp(System.currentTimeMillis() - timeInterval)); if (template instanceof MethodSensorData) { MethodSensorData methodSensorData = (MethodSensorData) template; Predicate methodId = builder.equal(root.get("methodIdent"), methodSensorData.getMethodIdent()); criteria.where(platformId, sensorTypeId, timestamp, methodId); } else if (template instanceof JmxSensorValueData) { JmxSensorValueData jmxSensorValueData = (JmxSensorValueData) template; Predicate jmxSensorDefinitionDataId = builder.equal(root.get("jmxSensorDefinitionDataIdentId"), jmxSensorValueData.getJmxSensorDefinitionDataIdentId()); criteria.where(platformId, sensorTypeId, timestamp, jmxSensorDefinitionDataId); } else { criteria.where(platformId, sensorTypeId, timestamp); } return entityManager.createQuery(criteria).getResultList(); }
/** * Adds needed tags related to the data to the builder. When overriding sub-classes should call * super first. * * @param data * Data carrier * @param builder * Builder to add tags to. * @see Builder#tag(String, String) */ protected void addTags(E data, Builder builder) { PlatformIdent platformIdent = cachedDataService.getPlatformIdentForId(data.getPlatformIdent()); builder.tag(Series.TAG_AGENT_ID, String.valueOf(data.getPlatformIdent())); if (null != platformIdent) { builder.tag(Series.TAG_AGENT_NAME, platformIdent.getAgentName()); } }
/** * {@inheritDoc} */ @Override public List<DefaultData> findByExampleFromToDate(DefaultData template, Date fromDate, Date toDate) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<DefaultData> criteria = builder.createQuery(DefaultData.class); Root<? extends DefaultData> root = criteria.from(template.getClass()); criteria.select(root); Predicate platformId = builder.equal(root.get("platformIdent"), template.getPlatformIdent()); Predicate sensorTypeId = builder.equal(root.get("sensorTypeIdent"), template.getSensorTypeIdent()); Predicate timestamp = builder.between(root.<Timestamp> get("timeStamp"), new Timestamp(fromDate.getTime()), new Timestamp(toDate.getTime())); if (template instanceof MethodSensorData) { MethodSensorData methodSensorData = (MethodSensorData) template; Predicate methodId = builder.equal(root.get("methodIdent"), methodSensorData.getMethodIdent()); criteria.where(platformId, sensorTypeId, timestamp, methodId); } else if (template instanceof JmxSensorValueData) { JmxSensorValueData jmxSensorValueData = (JmxSensorValueData) template; Predicate jmxSensorDefinitionDataId = builder.equal(root.get("jmxSensorDefinitionDataIdentId"), jmxSensorValueData.getJmxSensorDefinitionDataIdentId()); criteria.where(platformId, sensorTypeId, timestamp, jmxSensorDefinitionDataId); } else { criteria.where(platformId, sensorTypeId, timestamp); } return entityManager.createQuery(criteria).getResultList(); }
/** * {@inheritDoc} */ @Override @MethodLog public void addDataObjects(final List<? extends DefaultData> dataObjects) { if (CollectionUtils.isNotEmpty(dataObjects)) { agentStatusDataProvider.registerDataSent(dataObjects.get(0).getPlatformIdent()); long time = 0; if (log.isDebugEnabled()) { time = System.nanoTime(); } defaultDataDao.saveAll(dataObjects); if (log.isDebugEnabled()) { log.debug("Data Objects count: " + dataObjects.size() + " Save duration: " + Converter.nanoToMilliseconds(System.nanoTime() - time)); } } }
/** * {@inheritDoc} */ @Override public List<DefaultData> findByExampleSinceId(DefaultData template) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<DefaultData> criteria = builder.createQuery(DefaultData.class); Root<? extends DefaultData> root = criteria.from(template.getClass()); criteria.select(root); Predicate id = builder.greaterThan(root.<Long> get("id"), template.getId()); Predicate platformId = builder.equal(root.get("platformIdent"), template.getPlatformIdent()); Predicate sensorTypeId = builder.equal(root.get("sensorTypeIdent"), template.getSensorTypeIdent()); if (template instanceof MethodSensorData) { MethodSensorData methodSensorData = (MethodSensorData) template; Predicate methodId = builder.equal(root.get("methodIdent"), methodSensorData.getMethodIdent()); criteria.where(id, platformId, sensorTypeId, methodId); } else if (template instanceof JmxSensorValueData) { JmxSensorValueData jmxSensorValueData = (JmxSensorValueData) template; Predicate jmxSensorDefinitionDataId = builder.equal(root.get("jmxSensorDefinitionDataIdentId"), jmxSensorValueData.getJmxSensorDefinitionDataIdentId()); criteria.where(id, platformId, sensorTypeId, jmxSensorDefinitionDataId); } else { criteria.where(id, platformId, sensorTypeId); } return entityManager.createQuery(criteria).getResultList(); }
/** * {@inheritDoc} */ @Override public DefaultData findByExampleLastData(DefaultData template) { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaQuery<DefaultData> criteria = builder.createQuery(DefaultData.class); Root<? extends DefaultData> root = criteria.from(template.getClass()); criteria.select(root); Predicate platformId = builder.equal(root.get("platformIdent"), template.getPlatformIdent()); if (template instanceof MethodSensorData) { MethodSensorData methodSensorData = (MethodSensorData) template; Predicate methodId = builder.equal(root.get("methodIdent"), methodSensorData.getMethodIdent()); criteria.where(platformId, methodId); } else if (template instanceof JmxSensorValueData) { JmxSensorValueData jmxSensorValueData = (JmxSensorValueData) template; Predicate jmxSensorDefinitionDataId = builder.equal(root.get("jmxSensorDefinitionDataIdentId"), jmxSensorValueData.getJmxSensorDefinitionDataIdentId()); criteria.where(platformId, jmxSensorDefinitionDataId); } else { criteria.where(platformId); } criteria.orderBy(builder.desc(root.get("id"))); List<DefaultData> results = entityManager.createQuery(criteria).setMaxResults(1).getResultList(); if (CollectionUtils.isNotEmpty(results)) { return results.get(0); } else { return null; } }
/** * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override protected void processData(DefaultData defaultData, Map<?, ?> kryoPreferences) { Long key = Long.valueOf(defaultData.getPlatformIdent()); AggregationPerformer<E> aggregationPerformer = aggregationPerformerMap.get(key); if (null == aggregationPerformer) { aggregationPerformer = aggregationPerformerMap.putIfAbsent(key, new AggregationPerformer<>(aggregator)); if (null == aggregationPerformer) { aggregationPerformer = aggregationPerformerMap.get(key); } } // deal with no saving of the invocation affiliation for cached views as well if (Boolean.FALSE.equals(kryoPreferences.get(KryoSerializationPreferences.WRITE_INVOCATION_AFFILIATION_DATA)) && (defaultData instanceof InvocationAwareData)) { InvocationAwareData invocationAwareData = (InvocationAwareData) defaultData; Map<Long, MutableInt> temp = invocationAwareData.getInvocationsParentsIdMap(); invocationAwareData.setInvocationsParentsIdMap(Collections.<Long, MutableInt> emptyMap()); aggregationPerformer.processElement((E) defaultData); invocationAwareData.setInvocationsParentsIdMap(temp); } else { aggregationPerformer.processElement((E) defaultData); } }
/** * {@inheritDoc} */ @Override public List<DefaultData> getDataObjectsSinceIdIgnoreMethodId(DefaultData template) { StorageIndexQuery query = storageIndexQueryProvider.createNewStorageIndexQuery(); query.setMinId(template.getId()); ArrayList<Class<?>> searchClasses = new ArrayList<>(); searchClasses.add(template.getClass()); query.setObjectClasses(searchClasses); query.setPlatformIdent(template.getPlatformIdent()); return super.executeQuery(query); }
/** * Records this object, by processing it against the all the recording * {@link AbstractDataProcessor}s that are defined in the {@link RecordingProperties} for this * {@link StorageWriter}. Processor define which data will be stored, when and in which format. * <p> * If the processors are not set, then the normal write will be executed. * * @param defaultData * Object to be processed. */ public void record(DefaultData defaultData) { if (isRecordingOn() && storageWriter.isWritingOn()) { Collection<AbstractDataProcessor> recordingDataProcessors = recordingProperties.getRecordingDataProcessors(); if (CollectionUtils.isNotEmpty(recordingDataProcessors)) { for (AbstractDataProcessor dataProcessor : recordingDataProcessors) { dataProcessor.process(defaultData); } } involvedAgentsSet.add(defaultData.getPlatformIdent()); } }
/** * {@inheritDoc} */ @Override public DefaultData getLastDataObject(DefaultData template) { StorageIndexQuery query = storageIndexQueryProvider.createNewStorageIndexQuery(); query.setMinId(template.getId()); ArrayList<Class<?>> searchClasses = new ArrayList<>(); searchClasses.add(template.getClass()); query.setObjectClasses(searchClasses); query.setPlatformIdent(template.getPlatformIdent()); query.setSensorTypeIdent(template.getSensorTypeIdent()); List<DefaultData> resultList = super.executeQuery(query); if (CollectionUtils.isNotEmpty(resultList)) { Iterator<DefaultData> it = resultList.iterator(); DefaultData lastObject = it.next(); while (it.hasNext()) { DefaultData next = it.next(); if (next.getTimeStamp().after(lastObject.getTimeStamp())) { lastObject = next; } } return lastObject; } else { return null; } }
/** * Test that the agent filtering is correct. */ @Test public void agentFilterDataProcessor() { AbstractDataProcessor abstractDataProcessor = mock(AbstractDataProcessor.class); AgentFilterDataProcessor dataProcessor = new AgentFilterDataProcessor(Collections.singletonList(abstractDataProcessor), Collections.singleton(10L)); DefaultData data1 = mock(DefaultData.class); DefaultData data2 = mock(DefaultData.class); when(data1.getPlatformIdent()).thenReturn(10L); when(data2.getPlatformIdent()).thenReturn(20L); dataProcessor.process(data1); dataProcessor.process(data2); assertThat(dataProcessor.canBeProcessed(data1), is(true)); assertThat(dataProcessor.canBeProcessed(data2), is(true)); verify(abstractDataProcessor, times(1)).process(data1); verify(abstractDataProcessor, times(0)).process(data2); }
/** * Tests that stop recording will correctly flush the data processor and record the system * information data for all recorded platforms. */ @Test public void stopRecording() throws BusinessException { cmrStorageRecorder = spy(cmrStorageRecorder); when(recordingProperties.getRecordingDataProcessors()).thenReturn(Collections.singleton(dataProcessor)); cmrStorageRecorder.startOrScheduleRecording(storageWriter, recordingProperties); long platformId = 10L; DefaultData defaultData = mock(DefaultData.class); when(defaultData.getPlatformIdent()).thenReturn(platformId); cmrStorageRecorder.record(defaultData); SystemInformationData systemInformationData = mock(SystemInformationData.class); when(storageDataDao.getSystemInformationData(Collections.singleton(platformId))).thenReturn(Collections.singletonList(systemInformationData)); cmrStorageRecorder.stopRecording(); verify(dataProcessor, times(1)).flush(); verify(cmrStorageRecorder, times(1)).record(systemInformationData); assertThat(cmrStorageRecorder.isRecordingOn(), is(false)); }
/** * Testing that the {@link PlatformIdentIndexer} returns different keys based on the platform * ident. */ @Test public void platformIdentIndexer() { // different keys if platform idents differ DefaultData data = mock(DefaultData.class); PlatformIdentIndexer<DefaultData> indexer = new PlatformIdentIndexer<>(); when(data.getPlatformIdent()).thenReturn(10L); Object key1 = indexer.getKey(data); when(data.getPlatformIdent()).thenReturn(20L); Object key2 = indexer.getKey(data); assertThat(key1, is(not(key2))); IIndexQuery query = mock(IIndexQuery.class); when(query.getPlatformIdent()).thenReturn(0L); assertThat(indexer.getKeys(query), is(emptyArray())); when(query.getPlatformIdent()).thenReturn(10L); key1 = indexer.getKeys(query); when(query.getPlatformIdent()).thenReturn(20L); key2 = indexer.getKeys(query); assertThat(key1, is(not(key2))); }
/** * {@inheritDoc} */ @Override public List<DefaultData> getDataObjectsSinceId(DefaultData template) { StorageIndexQuery query = storageIndexQueryProvider.createNewStorageIndexQuery(); query.setMinId(template.getId()); ArrayList<Class<?>> searchClasses = new ArrayList<>(); searchClasses.add(template.getClass()); query.setObjectClasses(searchClasses); query.setPlatformIdent(template.getPlatformIdent()); query.setSensorTypeIdent(template.getSensorTypeIdent()); if (template instanceof MethodSensorData) { query.setMethodIdent(((MethodSensorData) template).getMethodIdent()); if (template instanceof InvocationSequenceData) { query.setOnlyInvocationsWithoutChildren(true); } } return super.executeQuery(query); }
when(defaultData1.getPlatformIdent()).thenReturn(10L); when(defaultData1.isQueryComplied(indexQuery)).thenReturn(true); rootBranch.put(defaultData1); when(defaultData2.getPlatformIdent()).thenReturn(20L); when(defaultData2.isQueryComplied(indexQuery)).thenReturn(true); rootBranch.put(defaultData2); assertThat(results.size(), is(equalTo(1))); for (DefaultData result : results) { assertThat(result.getPlatformIdent(), is(equalTo(10L))); assertThat(resultsForkJoin.size(), is(equalTo(1))); for (DefaultData result : resultsForkJoin) { assertThat(result.getPlatformIdent(), is(equalTo(10L)));
/** * Sets data for the {@link BreadcrumbTitleComposite}. */ private void setDataForBreadcrumbTitleComposite() { // repository breadcrumbTitleComposite.setRepositoryDefinition(repositoryDefinition); // agent PlatformIdent platformIdent = repositoryDefinition.getCachedDataService().getPlatformIdentForId(defaultData.getPlatformIdent()); if (null != platformIdent) { breadcrumbTitleComposite.setAgent(TextFormatter.getAgentDescription(platformIdent), InspectIT.getDefault().getImage(InspectITImages.IMG_AGENT)); } else { breadcrumbTitleComposite.setAgent("All Agents", InspectIT.getDefault().getImage(InspectITImages.IMG_AGENT)); } // sensor info if (0 != defaultData.getSensorTypeIdent()) { SensorTypeIdent sensorTypeIdent = repositoryDefinition.getCachedDataService().getSensorTypeIdentForId(defaultData.getSensorTypeIdent()); String fqn = sensorTypeIdent.getFullyQualifiedClassName(); SensorTypeEnum sensorTypeEnum = SensorTypeEnum.get(fqn); if (null != sensorTypeEnum) { breadcrumbTitleComposite.setGroup(sensorTypeEnum.getDisplayName(), sensorTypeEnum.getImage()); } } else if (defaultData instanceof Span) { // must be set explicitly as no sensor id is set with user spans breadcrumbTitleComposite.setGroup("Tracing SDK", null); } breadcrumbTitleComposite.setView("Details", null); }