/** * {@inheritDoc} */ @Override public void objectChecked(Object object, boolean checked) { if (object instanceof InvocationSequenceData) { InvocationSequenceData selected = (InvocationSequenceData) object; if (checked) { for (InvocationSequenceData inData : loadedInvocations) { if (inData.getId() == selected.getId()) { if (!selectedList.contains(inData)) { selectedList.add(inData); } break; } } } else { for (InvocationSequenceData inData : selectedList) { if (inData.getId() == selected.getId()) { selectedList.remove(inData); break; } } } passSelectedList(); } }
builder.append(sequence.getId()); } else if (type == TreeElementType.SPAN) { Span span = (Span) dataElement;
/** * Returns template for {@link InvocationSequenceData}. * * @param invocationSequenceData * Source object. * @param id * Should id be inserted into template. * @param methodIdent * Should methodIdent be inserted into template. * @return Template object. */ protected InvocationSequenceData getTemplate(InvocationSequenceData invocationSequenceData, boolean id, boolean methodIdent) { InvocationSequenceData template = OccurrenceFinderFactory.getEmptyTemplate(invocationSequenceData); if (id && (0 != invocationSequenceData.getId())) { template.setId(invocationSequenceData.getId()); } if (methodIdent && (0 != invocationSequenceData.getMethodIdent())) { template.setMethodIdent(invocationSequenceData.getMethodIdent()); } return template; } }
/** * Calculates a key which is used for the lookup map and identifying * {@link InvocationTreeElement} based on the contained data object. * * @param object * the object to generate a key for * @return the key of the given object */ public static String calculateLookupKey(Object object) { if (object == null) { return null; } if (object instanceof Span) { return "span_" + ((Span) object).getSpanIdent().getId(); } else if (object instanceof InvocationSequenceData) { return "isd_" + ((InvocationSequenceData) object).getId(); } else if (object instanceof SpanIdent) { return "span_" + ((SpanIdent) object).getId(); } return null; }
/** * Create new InvocationIdentifier based on InvocationSequenceData. * * @param invocationSequenceData * the InvocationIdentifier the InvocationIdentifier is created */ public InvocationIdentifier(final InvocationSequenceData invocationSequenceData) { if (null == invocationSequenceData) { throw new IllegalArgumentException("Cannot create InvocationIdentifier when invocationSequenceData is null."); } this.methodIdent = invocationSequenceData.getMethodIdent(); this.invocationId = invocationSequenceData.getId(); TimerData timerData = null; if (InvocationSequenceDataHelper.hasSQLData(invocationSequenceData)) { timerData = invocationSequenceData.getSqlStatementData(); } else if (InvocationSequenceDataHelper.hasTimerData(invocationSequenceData)) { timerData = invocationSequenceData.getTimerData(); } else { throw new IllegalStateException("Timer data unknown."); } this.diagnosisTimerData = new DiagnosisTimerData(timerData); }
/** * Process SQL statement if one exists in the invData object and passes it to the chained * processors. * * @param entityManager * {@link EntityManager} needed for DB persistence. * @param invData * Invocation data to be processed. * @param topInvocationParent * Top invocation object. */ private void processSqlStatementData(EntityManager entityManager, InvocationSequenceData invData, InvocationSequenceData topInvocationParent) { SqlStatementData sqlStatementData = invData.getSqlStatementData(); if (null != sqlStatementData) { topInvocationParent.setNestedSqlStatements(Boolean.TRUE); sqlStatementData.addInvocationParentId(topInvocationParent.getId()); passToChainedProcessors(sqlStatementData, entityManager); } }
/** * {@inheritDoc} */ @Override public InvocationSequenceData getInvocationSequenceDetail(InvocationSequenceData template) { // here we need to create new query since this one does not exist in factory StorageIndexQuery query = invocationDataQueryFactory.getIndexQueryProvider().getIndexQuery(); ArrayList<Class<?>> searchedClasses = new ArrayList<>(); searchedClasses.add(InvocationSequenceData.class); query.setObjectClasses(searchedClasses); query.setPlatformIdent(template.getPlatformIdent()); query.setMethodIdent(template.getMethodIdent()); query.setSensorTypeIdent(template.getSensorTypeIdent()); query.setOnlyInvocationsWithoutChildren(false); ArrayList<Long> includeIds = new ArrayList<>(); includeIds.add(template.getId()); query.setIncludeIds(includeIds); List<InvocationSequenceData> results = super.executeQuery(query); if (results.size() == 1) { return results.get(0); } return null; }
/** * Test that get will work even when branch can not generate key for the element if ID is * correctly set. * * @throws IndexingException */ @Test public void getWithNoKey() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false)); InvocationSequenceData invocation = mock(InvocationSequenceData.class); when(invocation.getId()).thenReturn(1L); when(invocation.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); IStorageDescriptor storageDescriptor = rootBranch.put(invocation); when(invocation.getTimeStamp()).thenReturn(null); // test get assertThat(rootBranch.get(invocation), is(equalTo(storageDescriptor))); // then get and remove assertThat(rootBranch.getAndRemove(invocation), is(equalTo(storageDescriptor))); // confirm it is removed assertThat(rootBranch.get(invocation), is(nullValue())); }
/** * Confirm {@link IndexingException} will be reaised when key can not be generated for element. * * @throws IndexingException */ @Test(expectedExceptions = { IndexingException.class }) public void putWithNoKey() throws IndexingException { IStorageTreeComponent<DefaultData> rootBranch = new StorageBranch<>(new StorageBranchIndexer<>(new TimestampIndexer<>(), false)); InvocationSequenceData invocation = mock(InvocationSequenceData.class); when(invocation.getId()).thenReturn(1L); rootBranch.put(invocation); }
@Test public void happyPath() throws Exception { when(cachedDataService.getPlatformIdentForId(PLATFORM_ID)).thenReturn(platformIdent); when(cachedDataService.getBusinessTransactionForId(APP_ID, BT_ID)).thenReturn(businessTransactionData); when(businessTransactionData.getApplication()).thenReturn(applicationData); double duration = RandomUtils.nextDouble(); long time = RandomUtils.nextLong(); when(data.getPlatformIdent()).thenReturn(PLATFORM_ID); when(data.getApplicationId()).thenReturn(APP_ID); when(data.getBusinessTransactionId()).thenReturn(BT_ID); when(data.getTimeStamp()).thenReturn(new Timestamp(time)); when(data.getDuration()).thenReturn(duration); when(data.getId()).thenReturn(Long.MAX_VALUE); Collection<Builder> pointBuilderCol = builder.createBuilders(data); assertThat(pointBuilderCol.size(), is(1)); Builder pointBuilder = pointBuilderCol.iterator().next(); assertThat(getMeasurement(pointBuilder), is(Series.BusinessTransaction.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.BusinessTransaction.TAG_APPLICATION_NAME, String.valueOf(APP_NAME))); assertThat(getTags(pointBuilder), hasEntry(Series.BusinessTransaction.TAG_BUSINESS_TRANSACTION_NAME, String.valueOf(BT_NAME))); assertThat(getFields(pointBuilder), hasEntry(Series.BusinessTransaction.FIELD_DURATION, (Object) duration)); assertThat(getFields(pointBuilder), hasEntry(Series.BusinessTransaction.FIELD_TRACE_ID, (Object) Long.MAX_VALUE)); }
/** * Process all the exceptions in the invData and passes exceptions to the chained processors. * <br> * <br> * Note also that only exception data with CREATED event are processed, since the PASSED and * HANDLED should be connected as children to the CREATED one. * * @param entityManager * {@link EntityManager} needed for DB persistence. * @param invData * Invocation data to be processed. * @param topInvocationParent * Top invocation object. */ private void processExceptionSensorData(EntityManager entityManager, InvocationSequenceData invData, InvocationSequenceData topInvocationParent) { if (CollectionUtils.isNotEmpty(invData.getExceptionSensorDataObjects())) { for (ExceptionSensorData exceptionData : invData.getExceptionSensorDataObjects()) { if (exceptionData.getExceptionEvent() == ExceptionEvent.CREATED) { // only if created exception is in invocation set to the parent topInvocationParent.setNestedExceptions(Boolean.TRUE); // we need to directly call Exception message processor, cause it can not be // chained exceptionMessageCmrProcessor.process(exceptionData, entityManager); exceptionData.addInvocationParentId(topInvocationParent.getId()); passToChainedProcessors(exceptionData, entityManager); } } } }
/** * {@inheritDoc} */ @Override protected void addFields(InvocationSequenceData data, Builder builder) { builder.addField(Series.BusinessTransaction.FIELD_DURATION, data.getDuration()); builder.addField(Series.BusinessTransaction.FIELD_TRACE_ID, data.getId()); if (InvocationSequenceDataHelper.hasHttpTimerData(data) && HttpTimerDataHelper.hasResponseCode((HttpTimerData) data.getTimerData())) { builder.addField(Series.BusinessTransaction.FIELD_HTTP_RESPONSE_CODE, ((HttpTimerData) data.getTimerData()).getHttpResponseStatus()); } }
/** * Process timer data if one exists in the invData object and passes it to the chained * processors. * * @param entityManager * {@link EntityManager} needed for DB persistence. * @param invData * Invocation data to be processed. * @param topInvocationParent * Top invocation object. * @param exclusiveDurationDelta * Duration to subtract from timer duration to get the exclusive duration. */ private void processTimerData(EntityManager entityManager, InvocationSequenceData invData, InvocationSequenceData topInvocationParent, double exclusiveDurationDelta) { TimerData timerData = invData.getTimerData(); if (null != timerData) { double exclusiveTime = invData.getTimerData().getDuration() - exclusiveDurationDelta; timerData.setExclusiveCount(1L); timerData.setExclusiveDuration(exclusiveTime); timerData.calculateExclusiveMax(exclusiveTime); timerData.calculateExclusiveMin(exclusiveTime); timerData.addInvocationParentId(topInvocationParent.getId()); passToChainedProcessors(invData.getTimerData(), entityManager); } }
InvocationSequenceData invocationSequenceData = (InvocationSequenceData) object; MethodIdent methodIdent = cachedDataService.getMethodIdentForId(invocationSequenceData.getMethodIdent()); if (0 == invocationSequenceData.getId()) { return TextFormatter.getMethodString(methodIdent) + " [All]"; } else {
/** * Clones invocation sequence. This method returns new object exactly same as the original * object, but with out nested sequences set. * * @return Cloned invocation sequence. */ public InvocationSequenceData getClonedInvocationSequence() { InvocationSequenceData clone = new InvocationSequenceData(this.getTimeStamp(), this.getPlatformIdent(), this.getSensorTypeIdent(), this.getMethodIdent()); clone.setId(this.getId()); clone.setSpanIdent(this.getSpanIdent()); clone.setChildCount(this.getChildCount()); clone.setDuration(this.getDuration()); clone.setEnd(this.getEnd()); clone.setNestedSequences(Collections.<InvocationSequenceData> emptyList()); clone.setParameterContentData(this.getParameterContentData()); clone.setParentSequence(this.getParentSequence()); clone.setPosition(this.getPosition()); clone.setSqlStatementData(this.getSqlStatementData()); clone.setTimerData(this.getTimerData()); clone.setExceptionSensorDataObjects(this.getExceptionSensorDataObjects()); clone.setStart(this.getStart()); clone.setNestedSqlStatements(this.isNestedSqlStatements()); clone.setNestedExceptions(this.isNestedExceptions()); clone.setLoggingData(this.getLoggingData()); clone.setApplicationId(this.getApplicationId()); clone.setBusinessTransactionId(this.getBusinessTransactionId()); return clone; }