Browse Source

Minor improvements

pull/12681/head
ViacheslavKlimov 1 year ago
parent
commit
f342bd989e
  1. 1
      application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationProvider.java
  2. 30
      common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java
  3. 2
      common/queue/src/main/java/org/thingsboard/server/queue/kafka/KafkaTbQueueMsg.java
  4. 8
      common/queue/src/main/java/org/thingsboard/server/queue/util/AfterStartUp.java

1
application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationProvider.java

@ -106,7 +106,6 @@ public class RestAuthenticationProvider implements AuthenticationProvider {
if (twoFactorAuthService.isTwoFaEnabled(securityUser.getTenantId(), securityUser.getId())) {
return new MfaAuthenticationToken(securityUser);
} else {
systemSecurityService.logLoginAction(securityUser, authentication.getDetails(), ActionType.LOGIN, null);
}
} else {

30
common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java

@ -228,7 +228,7 @@ public class HashPartitionService implements PartitionService {
});
if (serviceInfoProvider.isService(ServiceType.TB_RULE_ENGINE)) {
publishPartitionChangeEvent(ServiceType.TB_RULE_ENGINE, queueKeys.stream()
.collect(Collectors.toMap(k -> k, k -> Collections.emptySet())), Collections.emptyMap());
.collect(Collectors.toMap(k -> k, k -> Collections.emptySet())));
}
}
@ -408,7 +408,6 @@ public class HashPartitionService implements PartitionService {
myPartitions = newPartitions;
Map<QueueKey, Set<TopicPartitionInfo>> changedPartitionsMap = new HashMap<>();
Map<QueueKey, Set<TopicPartitionInfo>> oldPartitionsMap = new HashMap<>();
Set<QueueKey> removed = new HashSet<>();
oldPartitions.forEach((queueKey, partitions) -> {
@ -429,16 +428,16 @@ public class HashPartitionService implements PartitionService {
myPartitions.forEach((queueKey, partitions) -> {
if (!partitions.equals(oldPartitions.get(queueKey))) {
changedPartitionsMap.put(queueKey, toTpiList(queueKey, partitions));
oldPartitionsMap.put(queueKey, toTpiList(queueKey, oldPartitions.get(queueKey)));
Set<TopicPartitionInfo> tpiList = partitions.stream()
.map(partition -> buildTopicPartitionInfo(queueKey, partition))
.collect(Collectors.toSet());
changedPartitionsMap.put(queueKey, tpiList);
}
});
if (!changedPartitionsMap.isEmpty()) {
changedPartitionsMap.entrySet().stream()
.collect(Collectors.groupingBy(entry -> entry.getKey().getType(), Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
.forEach((serviceType, partitionsMap) -> {
publishPartitionChangeEvent(serviceType, partitionsMap, oldPartitionsMap);
});
.forEach(this::publishPartitionChangeEvent);
}
if (currentOtherServices == null) {
@ -470,15 +469,13 @@ public class HashPartitionService implements PartitionService {
applicationEventPublisher.publishEvent(new ServiceListChangedEvent(otherServices, currentService));
}
private void publishPartitionChangeEvent(ServiceType serviceType,
Map<QueueKey, Set<TopicPartitionInfo>> newPartitions,
Map<QueueKey, Set<TopicPartitionInfo>> oldPartitions) {
log.info("Partitions changed: {}", System.lineSeparator() + newPartitions.entrySet().stream()
private void publishPartitionChangeEvent(ServiceType serviceType, Map<QueueKey, Set<TopicPartitionInfo>> partitionsMap) {
log.info("Partitions changed: {}", System.lineSeparator() + partitionsMap.entrySet().stream()
.map(entry -> "[" + entry.getKey() + "] - [" + entry.getValue().stream()
.map(tpi -> tpi.getPartition().orElse(-1).toString()).sorted()
.collect(Collectors.joining(", ")) + "]")
.collect(Collectors.joining(System.lineSeparator())));
PartitionChangeEvent event = new PartitionChangeEvent(this, serviceType, newPartitions);
PartitionChangeEvent event = new PartitionChangeEvent(this, serviceType, partitionsMap);
try {
applicationEventPublisher.publishEvent(event);
} catch (Exception e) {
@ -486,15 +483,6 @@ public class HashPartitionService implements PartitionService {
}
}
private Set<TopicPartitionInfo> toTpiList(QueueKey queueKey, List<Integer> partitions) {
if (partitions == null) {
return Collections.emptySet();
}
return partitions.stream()
.map(partition -> buildTopicPartitionInfo(queueKey, partition))
.collect(Collectors.toSet());
}
@Override
public Set<String> getAllServiceIds(ServiceType serviceType) {
return getAllServices(serviceType).stream().map(ServiceInfo::getServiceId).collect(Collectors.toSet());

2
common/queue/src/main/java/org/thingsboard/server/queue/kafka/KafkaTbQueueMsg.java

@ -31,7 +31,7 @@ public class KafkaTbQueueMsg implements TbQueueMsg {
private final byte[] data;
public KafkaTbQueueMsg(ConsumerRecord<String, byte[]> record) {
if (record.key().length() == UUID_LENGTH) {
if (record.key().length() <= UUID_LENGTH) {
this.key = UUID.fromString(record.key());
} else {
this.key = UUID.randomUUID();

8
common/queue/src/main/java/org/thingsboard/server/queue/util/AfterStartUp.java

@ -1,12 +1,12 @@
/**
* Copyright © 2016-2024 The Thingsboard Authors
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Loading…
Cancel
Save