use of org.apache.skywalking.apm.collector.storage.ui.common.Topology 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;
}
use of org.apache.skywalking.apm.collector.storage.ui.common.Topology in project incubator-skywalking by apache.
the class ApplicationTopologyService method getApplicationTopology.
public Topology getApplicationTopology(Step step, int applicationId, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) throws ParseException {
logger.debug("startTimeBucket: {}, endTimeBucket: {}", startTimeBucket, endTimeBucket);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTimeBucket, endTimeBucket);
List<IApplicationMappingUIDAO.ApplicationMapping> applicationMappings = applicationMappingUIDAO.load(step, startTimeBucket, endTimeBucket);
Set<Integer> applicationIds = new HashSet<>();
applicationIds.add(applicationId);
applicationMappings.forEach(mapping -> {
if (mapping.getApplicationId() == applicationId) {
applicationIds.add(mapping.getMappingApplicationId());
}
});
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
List<IApplicationMetricUIDAO.ApplicationMetric> applicationMetrics = applicationMetricUIDAO.getApplications(step, startTimeBucket, endTimeBucket, MetricSource.Callee);
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> callerReferenceMetric = applicationReferenceMetricUIDAO.getReferences(step, startTimeBucket, endTimeBucket, MetricSource.Caller, applicationIds.toArray(new Integer[0]));
List<IApplicationReferenceMetricUIDAO.ApplicationReferenceMetric> calleeReferenceMetric = applicationReferenceMetricUIDAO.getReferences(step, startTimeBucket, endTimeBucket, MetricSource.Callee, applicationIds.toArray(new Integer[0]));
TopologyBuilder builder = new TopologyBuilder(moduleManager);
Topology topology = builder.build(applicationComponents, applicationMappings, applicationMetrics, callerReferenceMetric, calleeReferenceMetric, step, startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket);
Set<Integer> nodeIds = new HashSet<>();
topology.getCalls().forEach(call -> {
nodeIds.add(call.getSource());
nodeIds.add(call.getTarget());
});
for (int i = topology.getNodes().size() - 1; i >= 0; i--) {
if (!nodeIds.contains(topology.getNodes().get(i).getId())) {
topology.getNodes().remove(i);
}
}
return topology;
}
use of org.apache.skywalking.apm.collector.storage.ui.common.Topology in project incubator-skywalking by apache.
the class ServiceTopologyService method getServiceTopology.
public Topology getServiceTopology(Step step, int serviceId, long startTimeBucket, long endTimeBucket, long startSecondTimeBucket, long endSecondTimeBucket) throws ParseException {
logger.debug("startTimeBucket: {}, endTimeBucket: {}", startTimeBucket, endTimeBucket);
List<IApplicationComponentUIDAO.ApplicationComponent> applicationComponents = applicationComponentUIDAO.load(step, startTimeBucket, endTimeBucket);
Map<Integer, String> components = new HashMap<>();
applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId())));
List<IServiceReferenceMetricUIDAO.ServiceReferenceMetric> referenceMetrics = serviceReferenceMetricUIDAO.getFrontServices(step, startTimeBucket, endTimeBucket, MetricSource.Callee, serviceId);
referenceMetrics.addAll(serviceReferenceMetricUIDAO.getBehindServices(step, startTimeBucket, endTimeBucket, MetricSource.Caller, serviceId));
Set<Integer> nodeIds = new HashSet<>();
List<Call> calls = new LinkedList<>();
referenceMetrics.forEach(referenceMetric -> {
nodeIds.add(referenceMetric.getSource());
nodeIds.add(referenceMetric.getTarget());
Call call = new Call();
call.setSource(referenceMetric.getSource());
call.setTarget(referenceMetric.getTarget());
call.setAvgResponseTime(referenceMetric.getDurations() / referenceMetric.getCalls());
call.setCallType(components.getOrDefault(serviceNameCacheService.get(referenceMetric.getTarget()).getApplicationId(), Const.UNKNOWN));
try {
int applicationId = serviceNameCacheService.get(referenceMetric.getTarget()).getApplicationId();
call.setCallsPerSec(referenceMetric.getCalls() / secondBetweenService.calculate(applicationId, startSecondTimeBucket, endSecondTimeBucket));
} catch (ParseException e) {
logger.error(e.getMessage(), e);
}
call.setAlert(false);
calls.add(call);
});
List<Node> serviceNodes = serviceMetricUIDAO.getServicesMetric(step, startTimeBucket, endTimeBucket, MetricSource.Callee, nodeIds);
Set<Integer> gotNodes = new HashSet<>();
serviceNodes.forEach(serviceNode -> gotNodes.add(serviceNode.getId()));
Set<Integer> callerNodeIds = new HashSet<>();
nodeIds.forEach(nodeId -> {
if (!gotNodes.contains(nodeId)) {
callerNodeIds.add(nodeId);
}
});
serviceNodes.addAll(serviceMetricUIDAO.getServicesMetric(step, startTimeBucket, endTimeBucket, MetricSource.Caller, callerNodeIds));
serviceNodes.forEach(serviceNode -> {
ServiceName serviceName = serviceNameCacheService.get(serviceNode.getId());
serviceNode.setName(serviceName.getServiceName());
});
if (callerNodeIds.contains(Const.NONE_SERVICE_ID)) {
VisualUserNode userNode = new VisualUserNode();
userNode.setId(Const.NONE_SERVICE_ID);
userNode.setName(Const.USER_CODE);
userNode.setType(Const.USER_CODE.toUpperCase());
serviceNodes.add(userNode);
}
Topology topology = new Topology();
topology.setCalls(calls);
topology.setNodes(serviceNodes);
return topology;
}
Aggregations