Exemplo n.º 1
0
 /**
  * Opens respective mediator logs in case of a continuation call.
  *
  * @param messageId message uuid which corresponds to the continuation flow.
  * @param componentId component name
  */
 public void openLogForContinuation(String messageId, String componentId) {
   if (continuationStateMap.containsKey(messageId)) {
     ContinuationStateHolder continuationStateHolder = continuationStateMap.get(messageId);
     int continuationIndex = continuationStateHolder.getCallbackPoint();
     Integer componentIndex = null;
     while (continuationIndex > continuationStateHolder.getContinuationStackPosition()) {
       StatisticsLog statisticsLog = messageFlowLogs.get(continuationIndex);
       if (statisticsLog.getComponentId().equals(componentId)) {
         componentIndex = continuationIndex;
       }
       continuationIndex = statisticsLog.getParentLevel();
     }
     if (componentIndex != null) {
       openLogs.addFirst(componentIndex);
       messageFlowLogs.get(componentIndex).setIsOpenedByContinuation(true);
       continuationStateHolder.setContinuationStackPosition(componentIndex);
     } else {
       if (log.isDebugEnabled()) {
         log.error("No log found to match the continuation component Id:" + componentId);
       }
     }
   } else {
     if (log.isDebugEnabled()) {
       log.debug("No continuation information found in statistic trace for this message Id.");
     }
   }
 }
Exemplo n.º 2
0
 /**
  * After receiving a fault increment fault count of the statistics logs from its parent to the
  * root log to maintain correct fault hierarchy.
  *
  * @param parentIndexOfFault parent Index of the fault log
  */
 private void addFaultsToParents(int parentIndexOfFault) {
   while (parentIndexOfFault > PARENT_LEVEL_OF_ROOT) {
     StatisticsLog updatingLog = messageFlowLogs.get(parentIndexOfFault);
     updatingLog.incrementNoOfFaults();
     parentIndexOfFault = updatingLog.getParentLevel();
   }
 }
Exemplo n.º 3
0
  private boolean isCloneFlow(int msgId) {
    for (int i = messageFlowLogs.size() - 1; i >= 0; i--) {
      StatisticsLog statisticsLog = messageFlowLogs.get(i);

      if (statisticsLog.getMsgId() == msgId) {
        return false;
      }
    }
    return true;
  }
Exemplo n.º 4
0
  private Integer getParentFromMessageLogs(int msgId, int limit) {
    Integer immediateIndex = null;
    for (int i = messageFlowLogs.size() - 1; i >= 0; i--) {
      StatisticsLog statisticsLog = messageFlowLogs.get(i);

      if (statisticsLog.getMsgId() == msgId) {
        immediateIndex = i;
        break;
      }
    }
    return immediateIndex;
  }
Exemplo n.º 5
0
  private Integer getParentFromOpenLogs(int msgId) {
    Integer immediateIndex = null;
    for (Integer index : openLogs) {
      StatisticsLog statisticsLog = messageFlowLogs.get(index);

      if (statisticsLog.getMsgId() == msgId) {
        immediateIndex = index;
        break;
      }
    }
    return immediateIndex;
  }
Exemplo n.º 6
0
 private Integer getParentForClosedMsgFlow(int msgId) {
   Integer sameMsgIdLastLog = getParentFromMessageLogs(msgId);
   StatisticsLog lastLog = messageFlowLogs.get(sameMsgIdLastLog);
   while (lastLog.getParentMsgId() > DEFAULT_MSG_ID) {
     Integer parentIndex = getParentFromOpenLogs(lastLog.getParentMsgId());
     if (parentIndex != null) {
       return parentIndex;
     }
     lastLog = messageFlowLogs.get(lastLog.getParentLevel());
   }
   return getParentFromOpenLogs(DEFAULT_MSG_ID);
 }
Exemplo n.º 7
0
  private Integer getImmediateAggregateIndex() {
    Integer immediateIndex = null;
    for (int i = messageFlowLogs.size() - 1; i >= 0; i--) {
      StatisticsLog statisticsLog = messageFlowLogs.get(i);

      if (statisticsLog.isAggregateLog()) {
        immediateIndex = i;
        break;
      }
    }
    return immediateIndex;
  }
Exemplo n.º 8
0
 /**
  * Closes opened statistics log specified by the componentLevel.
  *
  * @param componentLevel index of the closing statistic log in messageFlowLogs
  * @param endTime endTime of the closing statistics log
  */
 private void closeStatisticLog(int componentLevel, Long endTime) {
   StatisticsLog currentLog = messageFlowLogs.get(componentLevel);
   if (log.isDebugEnabled()) {
     log.debug(
         "Closed statistic log of [ElementId"
             + currentLog.getComponentId()
             + "][MsgId"
             + currentLog.getParentMsgId());
   }
   currentLog.setEndTime(endTime);
   updateParentLogs(currentLog.getParentLevel(), endTime);
 }
Exemplo n.º 9
0
 /**
  * This overloaded constructor will create the root statistic log og the Statistic Entry according
  * to given parameters. Statistic Event for creating statistic entry can be either PROXY, API or
  * SEQUENCE.
  *
  * @param statisticDataUnit statistic data unit with raw data
  */
 public StatisticsEntry(StatisticDataUnit statisticDataUnit) {
   StatisticsLog statisticsLog =
       new StatisticsLog(statisticDataUnit, DEFAULT_MSG_ID, PARENT_LEVEL_OF_ROOT);
   statisticsLog.setTimeStamp(statisticDataUnit.getTimeStamp());
   statisticsLog.setMessageFlowId(statisticDataUnit.getStatisticId());
   messageFlowLogs.add(statisticsLog);
   openLogs.addFirst(messageFlowLogs.size() - 1);
   if (log.isDebugEnabled()) {
     log.debug(
         "Created statistic Entry [Start|RootElement]|[ElementId|"
             + statisticDataUnit.getComponentId()
             + "]|[MsgId|"
             + statisticDataUnit.getCloneId()
             + "].");
   }
 }
Exemplo n.º 10
0
 /**
  * Updates parent logs from the specified element after an notification is received. It updates
  * all the ended parent logs from specified index.
  *
  * @param closedIndex child index in the messageFlowLogs Array List
  * @param endTime end time of the child
  */
 private void updateParentLogs(int closedIndex, Long endTime) {
   if (closedIndex > -1) {
     StatisticsLog updatingLog = messageFlowLogs.get(closedIndex);
     // if log is closed end time will be different than -1
     while (!(updatingLog.getEndTime() == -1)) {
       updatingLog.setEndTime(endTime);
       if (updatingLog.getParentLevel() == PARENT_LEVEL_OF_ROOT) {
         break;
       }
       updatingLog = messageFlowLogs.get(updatingLog.getParentLevel());
     }
     if (log.isDebugEnabled()) {
       log.debug("Log updating finished.");
     }
   }
 }
Exemplo n.º 11
0
 private void createNewCloneLog(StatisticDataUnit statisticDataUnit, int parentIndex) {
   StatisticsLog parentLog = messageFlowLogs.get(parentIndex);
   StatisticsLog statisticsLog =
       new StatisticsLog(statisticDataUnit, parentLog.getMsgId(), parentIndex);
   messageFlowLogs.add(statisticsLog);
   parentLog.setChildren(messageFlowLogs.size() - 1);
   openLogs.addFirst(messageFlowLogs.size() - 1);
   if (log.isDebugEnabled()) {
     log.debug(
         "Created statistic log for [ElementId|"
             + statisticDataUnit.getComponentId()
             + "]|[MsgId|"
             + statisticDataUnit.getCloneId()
             + "]");
   }
 }
Exemplo n.º 12
0
  /**
   * Create a new statistics log for the reported statistic event for given parameters.
   *
   * @param statisticDataUnit statistic data unit with raw data
   * @param parentIndex parentIndex of the statistic log
   */
  private void createNewLog(StatisticDataUnit statisticDataUnit, int parentIndex) {
    StatisticsLog parentLog = messageFlowLogs.get(parentIndex);

    StatisticsLog statisticsLog =
        new StatisticsLog(statisticDataUnit, parentLog.getMsgId(), parentIndex);

    Integer immediateParentFromMessageLogs =
        getImmediateParentFromMessageLogs(statisticsLog.getMsgId());

    if (immediateParentFromMessageLogs == null) {
      immediateParentFromMessageLogs = parentIndex;
    }

    StatisticsLog possibleParent = messageFlowLogs.get(immediateParentFromMessageLogs);
    Integer lastAggregateIndex = getImmediateAggregateIndex();
    StatisticsLog lastAggregateLog = null;
    if (lastAggregateIndex != null) {
      lastAggregateLog = messageFlowLogs.get(getImmediateAggregateIndex());
    }

    if (possibleParent.getImmediateChild() == null) {
      if (possibleParent.getChildren().size() == 0) {
        possibleParent.setImmediateChild(messageFlowLogs.size());
      } else {
        if (lastAggregateLog != null && lastAggregateLog.getImmediateChild() == null) {
          lastAggregateLog.setImmediateChild(messageFlowLogs.size());
          lastAggregateLog.setMsgId(statisticsLog.getMsgId());
        } else {
          log.error(
              "Trying to set branching tree for non clone ComponentId:"
                  + statisticDataUnit.getComponentId());
          possibleParent.setChildren(messageFlowLogs.size());
        }
      }
    } else {
      if (lastAggregateLog != null && lastAggregateLog.getImmediateChild() == null) {
        lastAggregateLog.setImmediateChild(messageFlowLogs.size());
        lastAggregateLog.setMsgId(statisticsLog.getMsgId());
      } else {
        if (possibleParent.getChildren().size() == 0) {
          possibleParent.setChildren(possibleParent.getImmediateChild());
          possibleParent.setImmediateChild(null);
          possibleParent.setChildren(messageFlowLogs.size());
          log.error(
              "Setting immediate child of the component:"
                  + possibleParent.getComponentId()
                  + " as branching child");
        } else {
          log.error("Unexpected unrecoverable error happened during statistics collection");
        }
      }
    }

    messageFlowLogs.add(statisticsLog);
    openLogs.addFirst(messageFlowLogs.size() - 1);
    if (log.isDebugEnabled()) {
      log.debug(
          "Created statistic log for [ElementId|"
              + statisticDataUnit.getComponentId()
              + "]|[MsgId|"
              + statisticDataUnit.getCloneId()
              + "]");
    }
  }
  public static PublishingFlow createPublishingFlow(List<StatisticsLog> messageFlowLogs) {

    // Data structure using to serialize thr statistic data while publishing.
    PublishingFlow publishingFlow = new PublishingFlow();

    // Payload map which contains all the payloads of the message flow.
    Map<String, PublishingPayload> payloadMap = new HashMap<>();

    // Constants
    final String REFER = "#REFER:";
    final String BEFORE = "before-";
    final String AFTER = "after-";
    final Integer BEFORE_PAYLOAD = 8; // 8th attribute setting @PublishingEvent
    final Integer AFTER_PAYLOAD = 9; // 9th attribute setting @PublishingEvent

    String entryPoint = messageFlowLogs.get(0).getComponentName();
    String flowId = messageFlowLogs.get(0).getMessageFlowId();
    Integer entrypointHashcode = messageFlowLogs.get(0).getHashCode();

    boolean isTracingEnabledForFlow = messageFlowLogs.get(0).isTracingEnabled();

    for (int index = 0; index < messageFlowLogs.size(); index++) {
      StatisticsLog currentStatLog = messageFlowLogs.get(index);
      if (currentStatLog == null) {
        continue;
      }

      // Add each event to Publishing Flow
      publishingFlow.addEvent(
          new PublishingEvent(flowId, index, currentStatLog, entryPoint, entrypointHashcode));

      // Skip the rest of things, if message tracing is disabled
      if (!RuntimeStatisticCollector.isCollectingPayloads()) {
        continue;
      }

      // Skip flow is tracing is not enabled for the flow (from UI)
      if (!isTracingEnabledForFlow) {
        continue;
      }

      // Update children's immediateParent index
      List<Integer> childrenOfCurrent = currentStatLog.getChildren();
      for (Integer child : childrenOfCurrent) {
        messageFlowLogs.get(child).setImmediateParent(currentStatLog.getCurrentIndex());
      }

      if (currentStatLog.getBeforePayload() != null && currentStatLog.getAfterPayload() == null) {
        currentStatLog.setAfterPayload(currentStatLog.getBeforePayload());
      }

      if (currentStatLog.getBeforePayload() == null) {
        int parentIndex = currentStatLog.getImmediateParent();
        StatisticsLog parentStatLog = messageFlowLogs.get(parentIndex);

        if (parentStatLog.getAfterPayload().startsWith(REFER)) {
          // Parent also referring to after-payload
          currentStatLog.setBeforePayload(parentStatLog.getAfterPayload());
          currentStatLog.setAfterPayload(parentStatLog.getAfterPayload());

          String referringIndex = parentStatLog.getAfterPayload().split(":")[1];

          payloadMap
              .get(AFTER + referringIndex)
              .addEvent(new PublishingPayloadEvent(index, BEFORE_PAYLOAD));
          payloadMap
              .get(AFTER + referringIndex)
              .addEvent(new PublishingPayloadEvent(index, AFTER_PAYLOAD));

        } else {
          // Create a new after-payload reference
          currentStatLog.setBeforePayload(REFER + parentIndex);
          currentStatLog.setAfterPayload(REFER + parentIndex);

          payloadMap
              .get(AFTER + parentIndex)
              .addEvent(new PublishingPayloadEvent(index, BEFORE_PAYLOAD));
          payloadMap
              .get(AFTER + parentIndex)
              .addEvent(new PublishingPayloadEvent(index, AFTER_PAYLOAD));
        }

      } else {

        // For content altering components
        PublishingPayload publishingPayloadBefore = new PublishingPayload();
        publishingPayloadBefore.setPayload(currentStatLog.getBeforePayload());
        publishingPayloadBefore.addEvent(new PublishingPayloadEvent(index, BEFORE_PAYLOAD));
        payloadMap.put(BEFORE + index, publishingPayloadBefore);

        PublishingPayload publishingPayloadAfter = new PublishingPayload();
        publishingPayloadAfter.setPayload(currentStatLog.getAfterPayload());
        publishingPayloadAfter.addEvent(new PublishingPayloadEvent(index, AFTER_PAYLOAD));
        payloadMap.put(AFTER + index, publishingPayloadAfter);
      }
    }

    publishingFlow.setMessageFlowId(flowId);
    // Move all payloads to publishingFlow object
    publishingFlow.setPayloads(payloadMap.values());

    return publishingFlow;
  }