use of org.apache.skywalking.apm.collector.storage.table.register.Application in project incubator-skywalking by apache.
the class ApplicationRegisterSerialWorker method onWork.
@Override
protected void onWork(Application application) throws WorkerException {
logger.debug("register application, application code: {}", application.getApplicationCode());
int applicationId;
if (BooleanUtils.valueToBoolean(application.getIsAddress())) {
applicationId = applicationCacheService.getApplicationIdByAddressId(application.getAddressId());
} else {
applicationId = applicationCacheService.getApplicationIdByCode(application.getApplicationCode());
}
if (applicationId == 0) {
Application newApplication;
int min = applicationRegisterDAO.getMinApplicationId();
if (min == 0) {
Application userApplication = new Application();
userApplication.setId(String.valueOf(Const.NONE_APPLICATION_ID));
userApplication.setApplicationCode(Const.USER_CODE);
userApplication.setApplicationId(Const.NONE_APPLICATION_ID);
userApplication.setAddressId(Const.NONE);
userApplication.setIsAddress(BooleanUtils.FALSE);
applicationRegisterDAO.save(userApplication);
newApplication = new Application();
newApplication.setId("-1");
newApplication.setApplicationId(-1);
newApplication.setApplicationCode(application.getApplicationCode());
newApplication.setAddressId(application.getAddressId());
newApplication.setIsAddress(application.getIsAddress());
} else {
int max = applicationRegisterDAO.getMaxApplicationId();
applicationId = IdAutoIncrement.INSTANCE.increment(min, max);
newApplication = new Application();
newApplication.setId(String.valueOf(applicationId));
newApplication.setApplicationId(applicationId);
newApplication.setApplicationCode(application.getApplicationCode());
newApplication.setAddressId(application.getAddressId());
newApplication.setIsAddress(application.getIsAddress());
}
applicationRegisterDAO.save(newApplication);
}
}
use of org.apache.skywalking.apm.collector.storage.table.register.Application in project incubator-skywalking by apache.
the class ApplicationEsCacheDAO method getApplication.
@Override
public Application getApplication(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
ElasticSearchClient client = getClient();
GetRequestBuilder getRequestBuilder = client.prepareGet(ApplicationTable.TABLE, String.valueOf(applicationId));
GetResponse getResponse = getRequestBuilder.get();
if (getResponse.isExists()) {
Application application = new Application();
application.setApplicationId(applicationId);
application.setApplicationCode((String) getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE));
application.setIsAddress(((Number) getResponse.getSource().get(ApplicationTable.COLUMN_IS_ADDRESS)).intValue());
return application;
}
return null;
}
use of org.apache.skywalking.apm.collector.storage.table.register.Application in project incubator-skywalking by apache.
the class ApplicationH2CacheDAO method getApplication.
@Override
public Application getApplication(int applicationId) {
logger.debug("get application code, applicationId: {}", applicationId);
H2Client client = getClient();
String sql = SqlBuilder.buildSql(GET_APPLICATION_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.COLUMN_IS_ADDRESS, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID);
Object[] params = new Object[] { applicationId };
try (ResultSet rs = client.executeQuery(sql, params)) {
if (rs.next()) {
Application application = new Application();
application.setApplicationId(applicationId);
application.setApplicationCode(rs.getString(1));
application.setIsAddress(rs.getInt(2));
return application;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
return null;
}
use of org.apache.skywalking.apm.collector.storage.table.register.Application in project incubator-skywalking by apache.
the class ApplicationReferenceMetricAlarmAssertWorker method generateAlarmContent.
@Override
protected void generateAlarmContent(ApplicationReferenceAlarm alarm, double threshold) {
Application application = applicationCacheService.getApplicationById(alarm.getBehindApplicationId());
String clientOrServer = "server";
if (MetricSource.Caller.getValue() == alarm.getSourceValue()) {
clientOrServer = "client";
}
if (AlarmType.ERROR_RATE.getValue() == alarm.getAlarmType()) {
alarm.setAlarmContent("The success rate of " + application.getApplicationCode() + ", detected from " + clientOrServer + " side, is lower than " + threshold + " rate.");
} else if (AlarmType.SLOW_RTT.getValue() == alarm.getAlarmType()) {
alarm.setAlarmContent("Response time of " + application.getApplicationCode() + ", detected from " + clientOrServer + " side, is slower than " + threshold + " ms.");
}
}
use of org.apache.skywalking.apm.collector.storage.table.register.Application 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;
}
Aggregations