Sonar Fixes (#2243)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -151,32 +151,7 @@ public class Statistics {
|
||||
|
||||
final Matcher matcher = PATTERN.matcher(k);
|
||||
if (matcher.matches()) {
|
||||
final String type = matcher.group("type");
|
||||
final StringTokenizer stringTokenizer = new StringTokenizer(matcher.group("key"), ":");
|
||||
final String name = METER_PREFIX + stringTokenizer.nextToken();
|
||||
if (type.equals("Counter")) {
|
||||
final double quantity = v instanceof Double d ? d : Double.parseDouble(v.toString());
|
||||
final Counter counter;
|
||||
if (stringTokenizer.hasMoreTokens()) {
|
||||
counter = meterRegistry.counter(name, "entity", stringTokenizer.nextToken());
|
||||
} else {
|
||||
counter = meterRegistry.counter(name);
|
||||
}
|
||||
counter.increment(quantity - counter.count());
|
||||
} else { // Timer
|
||||
final long quantity = v instanceof Long l ? l : (long) Double.parseDouble(v.toString());
|
||||
final Timer timer;
|
||||
if (stringTokenizer.hasMoreTokens()) {
|
||||
final String entity = stringTokenizer.nextToken();
|
||||
stringTokenizer.nextToken(); // skip, what is this?
|
||||
final String subOp = stringTokenizer.hasMoreTokens() ? stringTokenizer.nextToken() : "n/a";
|
||||
timer = meterRegistry.timer(name, "entity", entity, "subOp", subOp);
|
||||
} else {
|
||||
timer = meterRegistry.timer(name);
|
||||
}
|
||||
timer.record(quantity - REPORTED_TIMER_VALUES.getOrDefault(name, 0L), TimeUnit.NANOSECONDS);
|
||||
REPORTED_TIMER_VALUES.put(name, quantity);
|
||||
}
|
||||
recordMetric(v, matcher);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -188,6 +163,35 @@ public class Statistics {
|
||||
}
|
||||
}
|
||||
|
||||
private void recordMetric(final Object v, final Matcher matcher) {
|
||||
final String type = matcher.group("type");
|
||||
final StringTokenizer stringTokenizer = new StringTokenizer(matcher.group("key"), ":");
|
||||
final String name = METER_PREFIX + stringTokenizer.nextToken();
|
||||
if (type.equals("Counter")) {
|
||||
final double quantity = v instanceof Double d ? d : Double.parseDouble(v.toString());
|
||||
final Counter counter;
|
||||
if (stringTokenizer.hasMoreTokens()) {
|
||||
counter = meterRegistry.counter(name, "entity", stringTokenizer.nextToken());
|
||||
} else {
|
||||
counter = meterRegistry.counter(name);
|
||||
}
|
||||
counter.increment(quantity - counter.count());
|
||||
} else { // Timer
|
||||
final long quantity = v instanceof Long l ? l : (long) Double.parseDouble(v.toString());
|
||||
final Timer timer;
|
||||
if (stringTokenizer.hasMoreTokens()) {
|
||||
final String entity = stringTokenizer.nextToken();
|
||||
stringTokenizer.nextToken(); // skip, what is this?
|
||||
final String subOp = stringTokenizer.hasMoreTokens() ? stringTokenizer.nextToken() : "n/a";
|
||||
timer = meterRegistry.timer(name, "entity", entity, "subOp", subOp);
|
||||
} else {
|
||||
timer = meterRegistry.timer(name);
|
||||
}
|
||||
timer.record(quantity - REPORTED_TIMER_VALUES.getOrDefault(name, 0L), TimeUnit.NANOSECONDS);
|
||||
REPORTED_TIMER_VALUES.put(name, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
private static PerformanceMonitor getPerformanceMonitor(final EntityManagerFactory entityManagerFactory) {
|
||||
return (PerformanceMonitor) entityManagerFactory.unwrap(Session.class).getProfiler();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.Optional;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -101,7 +101,6 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
@@ -79,7 +79,6 @@ import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
|
||||
import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -668,7 +667,8 @@ public class JpaRolloutManagement implements RolloutManagement {
|
||||
// prepare the groups
|
||||
final List<RolloutGroup> srcGroups = groupList.stream()
|
||||
.map(group -> prepareRolloutGroupWithDefaultConditions(group, conditions))
|
||||
.collect(Collectors.toList());
|
||||
.map(RolloutGroup.class::cast)
|
||||
.toList();
|
||||
srcGroups.forEach(RolloutHelper::verifyRolloutGroupHasConditions);
|
||||
|
||||
RolloutHelper.verifyRemainingTargets(calculateRemainingTargets(
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.eclipse.hawkbit.repository.jpa.repository.LocalArtifactRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
|
||||
import org.eclipse.hawkbit.repository.report.model.TenantUsage;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@@ -105,7 +105,8 @@ public abstract class AbstractRSQLVisitor<A extends Enum<A> & RsqlQueryField> {
|
||||
}
|
||||
|
||||
private List<String> getExpectedFieldList() {
|
||||
final List<String> expectedFieldList = Arrays.stream(rsqlQueryFieldType.getEnumConstants())
|
||||
return Stream.concat(
|
||||
Arrays.stream(rsqlQueryFieldType.getEnumConstants())
|
||||
.filter(enumField -> enumField.getSubEntityAttributes().isEmpty()).map(enumField -> {
|
||||
final String enumFieldName = enumField.name().toLowerCase();
|
||||
if (enumField.isMap()) {
|
||||
@@ -113,9 +114,8 @@ public abstract class AbstractRSQLVisitor<A extends Enum<A> & RsqlQueryField> {
|
||||
} else {
|
||||
return enumFieldName;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
final List<String> expectedSubFieldList = Arrays.stream(rsqlQueryFieldType.getEnumConstants())
|
||||
}),
|
||||
Arrays.stream(rsqlQueryFieldType.getEnumConstants())
|
||||
.filter(enumField -> !enumField.getSubEntityAttributes().isEmpty()).flatMap(enumField -> {
|
||||
final List<String> subEntity = enumField
|
||||
.getSubEntityAttributes().stream().map(fieldName -> enumField.name().toLowerCase()
|
||||
@@ -123,9 +123,8 @@ public abstract class AbstractRSQLVisitor<A extends Enum<A> & RsqlQueryField> {
|
||||
.toList();
|
||||
|
||||
return subEntity.stream();
|
||||
}).toList();
|
||||
expectedFieldList.addAll(expectedSubFieldList);
|
||||
return expectedFieldList;
|
||||
}))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Value
|
||||
|
||||
Reference in New Issue
Block a user