2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.logging.ref.slf4j.analysis;
24 import java.util.ArrayList;
25 import java.util.List;
27 import org.apache.commons.lang3.StringUtils;
30 * Crude analyzer for log messages, to build a simple
31 * representation of the call graph.
33 public class CallGraphAnalyzer {
35 /** Messages of interest. */
36 private List<LogEntry> mEntries = new ArrayList<>();
39 * Capture entry if it's interesting.
40 * @param entry candidate.
43 public CallGraphAnalyzer add(final LogEntry entry) {
45 if (entry.getLogger().contains("ONAPLogAdapterTest")) {
49 if (StringUtils.isNotBlank(entry.getMarkers())) {
50 this.mEntries.add(entry);
57 * Get all captured entries, for diagnostics only.
60 public List<LogEntry> getEntries() {
65 * Find the entry point into the call graph through the various components.
66 * @return entry point or (failure) null.
68 public LogEntry findEntryPoint() {
69 for (final LogEntry e : this.mEntries) {
70 if (e.getLogger().endsWith("ComponentAlpha")) {
71 if ("ENTRY".equals(e.getMarkers())) {
72 if (StringUtils.isBlank(e.getPartnerName())) {
82 * Find entries for where a component invokes others.
83 * @param parent parent ENTRY (not actually the entry where it's doing the invoking).
84 * @return components invoked by this one.
86 public List<LogEntry> findInvokes(final LogEntry parent) {
87 final List<LogEntry> invokes = new ArrayList<>();
88 for (final LogEntry e : this.mEntries) {
89 if (StringUtils.equals(parent.getInvocationID(), e.getInvocationID())) {
90 final String invokingID = e.getInvokingID();
91 if (StringUtils.isNotBlank(invokingID)) {
100 * Find a specific invocation.
101 * @param invoke invocation record.
102 * @return invocation ENTRY, or (failure) null if not found.
104 public LogEntry findInvocation(final LogEntry invoke) {
105 for (final LogEntry e : this.mEntries) {
106 if ("ENTRY".equals(e.getMarkers())) {
107 if (StringUtils.equals(invoke.getInvokingID(), e.getInvocationID())) {