Search in sources :

Example 1 with ConjecturalNode

use of org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode in project incubator-skywalking by apache.

the class TopologyBuilder method build.

Topology build(List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents, List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings, List<IApplicationMetricUIDAO.ApplicationMetric> applicationMetrics, List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric, List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric, Step step, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) {
    Map<Integer, String> components = changeNodeComp2Map(applicationComponents);
    Map<Integer, Integer> mappings = changeMapping2Map(applicationMappings);
    filterZeroSourceOrTargetReference(callerReferenceMetric);
    filterZeroSourceOrTargetReference(calleeReferenceMetric);
    calleeReferenceMetric = calleeReferenceMetricFilter(calleeReferenceMetric);
    List<Node> nodes = new LinkedList<>();
    applicationMetrics.forEach(applicationMetric -> {
        int applicationId = applicationMetric.getId();
        Application application = applicationCacheService.getApplicationById(applicationId);
        ApplicationNode applicationNode = new ApplicationNode();
        applicationNode.setId(applicationId);
        applicationNode.setName(application.getApplicationCode());
        applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN));
        applicationNode.setSla(SLACalculator.INSTANCE.calculate(applicationMetric.getErrorCalls(), applicationMetric.getCalls()));
        try {
            applicationNode.setCallsPerSec(applicationMetric.getCalls() / secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket));
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        applicationNode.setAvgResponseTime(applicationMetric.getDurations() / applicationMetric.getCalls());
        applicationNode.setApdex(ApdexCalculator.INSTANCE.calculate(applicationMetric.getSatisfiedCount(), applicationMetric.getToleratingCount(), applicationMetric.getFrustratedCount()));
        applicationNode.setAlarm(false);
        try {
            Alarm alarm = alarmService.loadApplicationAlarmList(Const.EMPTY_STRING, step, startTimeBucket, endTimeBucket, 1, 0);
            if (alarm.getItems().size() > 0) {
                applicationNode.setAlarm(true);
            }
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        applicationNode.setNumOfServer(serverService.getAllServer(applicationId, startSecondTimeBucket, endSecondTimeBucket).size());
        try {
            Alarm alarm = alarmService.loadInstanceAlarmList(Const.EMPTY_STRING, step, startTimeBucket, endTimeBucket, 1000, 0);
            applicationNode.setNumOfServerAlarm(alarm.getItems().size());
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        try {
            Alarm alarm = alarmService.loadServiceAlarmList(Const.EMPTY_STRING, step, startTimeBucket, endTimeBucket, 1000, 0);
            applicationNode.setNumOfServiceAlarm(alarm.getItems().size());
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        nodes.add(applicationNode);
    });
    List<Call> calls = new LinkedList<>();
    Set<Integer> nodeIds = new HashSet<>();
    callerReferenceMetric.forEach(referenceMetric -> {
        Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
        Application target = applicationCacheService.getApplicationById(referenceMetric.getTarget());
        if (BooleanUtils.valueToBoolean(target.getIsAddress()) && !mappings.containsKey(target.getApplicationId())) {
            if (!nodeIds.contains(target.getApplicationId())) {
                ConjecturalNode conjecturalNode = new ConjecturalNode();
                conjecturalNode.setId(target.getApplicationId());
                conjecturalNode.setName(target.getApplicationCode());
                conjecturalNode.setType(components.getOrDefault(target.getApplicationId(), Const.UNKNOWN));
                nodes.add(conjecturalNode);
                nodeIds.add(target.getApplicationId());
            }
        }
        Set<Integer> applicationNodeIds = buildNodeIds(nodes);
        if (!applicationNodeIds.contains(source.getApplicationId())) {
            ApplicationNode applicationNode = new ApplicationNode();
            applicationNode.setId(source.getApplicationId());
            applicationNode.setName(source.getApplicationCode());
            applicationNode.setType(components.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
            applicationNode.setApdex(100);
            applicationNode.setSla(100);
            nodes.add(applicationNode);
        }
        Call call = new Call();
        call.setSource(source.getApplicationId());
        call.setSourceName(source.getApplicationCode());
        int actualTargetId = mappings.getOrDefault(target.getApplicationId(), target.getApplicationId());
        call.setTarget(actualTargetId);
        call.setTargetName(applicationCacheService.getApplicationById(actualTargetId).getApplicationCode());
        call.setAlert(false);
        call.setCallType(components.get(referenceMetric.getTarget()));
        try {
            call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(source.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        call.setAvgResponseTime(referenceMetric.getDurations() / referenceMetric.getCalls());
        calls.add(call);
    });
    calleeReferenceMetric.forEach(referenceMetric -> {
        Application source = applicationCacheService.getApplicationById(referenceMetric.getSource());
        Application target = applicationCacheService.getApplicationById(referenceMetric.getTarget());
        if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
            if (!nodeIds.contains(source.getApplicationId())) {
                VisualUserNode visualUserNode = new VisualUserNode();
                visualUserNode.setId(source.getApplicationId());
                visualUserNode.setName(Const.USER_CODE);
                visualUserNode.setType(Const.USER_CODE.toUpperCase());
                nodes.add(visualUserNode);
                nodeIds.add(source.getApplicationId());
            }
        }
        if (BooleanUtils.valueToBoolean(source.getIsAddress())) {
            if (!nodeIds.contains(source.getApplicationId())) {
                ConjecturalNode conjecturalNode = new ConjecturalNode();
                conjecturalNode.setId(source.getApplicationId());
                conjecturalNode.setName(source.getApplicationCode());
                conjecturalNode.setType(components.getOrDefault(source.getApplicationId(), Const.UNKNOWN));
                nodeIds.add(source.getApplicationId());
                nodes.add(conjecturalNode);
            }
        }
        Call call = new Call();
        call.setSource(source.getApplicationId());
        call.setSourceName(source.getApplicationCode());
        call.setTarget(target.getApplicationId());
        call.setTargetName(target.getApplicationCode());
        call.setAlert(false);
        if (source.getApplicationId() == Const.NONE_APPLICATION_ID) {
            call.setCallType(Const.EMPTY_STRING);
        } else {
            call.setCallType(components.get(referenceMetric.getTarget()));
        }
        try {
            call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(target.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket));
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
        }
        call.setAvgResponseTime(referenceMetric.getDurations() / referenceMetric.getCalls());
        calls.add(call);
    });
    Topology topology = new Topology();
    topology.setCalls(calls);
    topology.setNodes(nodes);
    return topology;
}
Also used : Call(org.apache.skywalking.apm.collector.storage.ui.common.Call) Node(org.apache.skywalking.apm.collector.storage.ui.common.Node) ConjecturalNode(org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode) VisualUserNode(org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode) ApplicationNode(org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode) ApplicationNode(org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode) Topology(org.apache.skywalking.apm.collector.storage.ui.common.Topology) LinkedList(java.util.LinkedList) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm) VisualUserNode(org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode) ParseException(java.text.ParseException) ConjecturalNode(org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode) Application(org.apache.skywalking.apm.collector.storage.table.register.Application) HashSet(java.util.HashSet)

Aggregations

ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 Alarm (org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm)1 ApplicationNode (org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode)1 ConjecturalNode (org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode)1 Call (org.apache.skywalking.apm.collector.storage.ui.common.Call)1 Node (org.apache.skywalking.apm.collector.storage.ui.common.Node)1 Topology (org.apache.skywalking.apm.collector.storage.ui.common.Topology)1 VisualUserNode (org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode)1