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())) { if (twoFactorAuthService.isTwoFaEnabled(securityUser.getTenantId(), securityUser.getId())) {
return new MfaAuthenticationToken(securityUser); return new MfaAuthenticationToken(securityUser);
} else { } else {
systemSecurityService.logLoginAction(securityUser, authentication.getDetails(), ActionType.LOGIN, null); systemSecurityService.logLoginAction(securityUser, authentication.getDetails(), ActionType.LOGIN, null);
} }
} else { } 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)) { if (serviceInfoProvider.isService(ServiceType.TB_RULE_ENGINE)) {
publishPartitionChangeEvent(ServiceType.TB_RULE_ENGINE, queueKeys.stream() 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; myPartitions = newPartitions;
Map<QueueKey, Set<TopicPartitionInfo>> changedPartitionsMap = new HashMap<>(); Map<QueueKey, Set<TopicPartitionInfo>> changedPartitionsMap = new HashMap<>();
Map<QueueKey, Set<TopicPartitionInfo>> oldPartitionsMap = new HashMap<>();
Set<QueueKey> removed = new HashSet<>(); Set<QueueKey> removed = new HashSet<>();
oldPartitions.forEach((queueKey, partitions) -> { oldPartitions.forEach((queueKey, partitions) -> {
@ -429,16 +428,16 @@ public class HashPartitionService implements PartitionService {
myPartitions.forEach((queueKey, partitions) -> { myPartitions.forEach((queueKey, partitions) -> {
if (!partitions.equals(oldPartitions.get(queueKey))) { if (!partitions.equals(oldPartitions.get(queueKey))) {
changedPartitionsMap.put(queueKey, toTpiList(queueKey, partitions)); Set<TopicPartitionInfo> tpiList = partitions.stream()
oldPartitionsMap.put(queueKey, toTpiList(queueKey, oldPartitions.get(queueKey))); .map(partition -> buildTopicPartitionInfo(queueKey, partition))
.collect(Collectors.toSet());
changedPartitionsMap.put(queueKey, tpiList);
} }
}); });
if (!changedPartitionsMap.isEmpty()) { if (!changedPartitionsMap.isEmpty()) {
changedPartitionsMap.entrySet().stream() changedPartitionsMap.entrySet().stream()
.collect(Collectors.groupingBy(entry -> entry.getKey().getType(), Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) .collect(Collectors.groupingBy(entry -> entry.getKey().getType(), Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
.forEach((serviceType, partitionsMap) -> { .forEach(this::publishPartitionChangeEvent);
publishPartitionChangeEvent(serviceType, partitionsMap, oldPartitionsMap);
});
} }
if (currentOtherServices == null) { if (currentOtherServices == null) {
@ -470,15 +469,13 @@ public class HashPartitionService implements PartitionService {
applicationEventPublisher.publishEvent(new ServiceListChangedEvent(otherServices, currentService)); applicationEventPublisher.publishEvent(new ServiceListChangedEvent(otherServices, currentService));
} }
private void publishPartitionChangeEvent(ServiceType serviceType, private void publishPartitionChangeEvent(ServiceType serviceType, Map<QueueKey, Set<TopicPartitionInfo>> partitionsMap) {
Map<QueueKey, Set<TopicPartitionInfo>> newPartitions, log.info("Partitions changed: {}", System.lineSeparator() + partitionsMap.entrySet().stream()
Map<QueueKey, Set<TopicPartitionInfo>> oldPartitions) {
log.info("Partitions changed: {}", System.lineSeparator() + newPartitions.entrySet().stream()
.map(entry -> "[" + entry.getKey() + "] - [" + entry.getValue().stream() .map(entry -> "[" + entry.getKey() + "] - [" + entry.getValue().stream()
.map(tpi -> tpi.getPartition().orElse(-1).toString()).sorted() .map(tpi -> tpi.getPartition().orElse(-1).toString()).sorted()
.collect(Collectors.joining(", ")) + "]") .collect(Collectors.joining(", ")) + "]")
.collect(Collectors.joining(System.lineSeparator()))); .collect(Collectors.joining(System.lineSeparator())));
PartitionChangeEvent event = new PartitionChangeEvent(this, serviceType, newPartitions); PartitionChangeEvent event = new PartitionChangeEvent(this, serviceType, partitionsMap);
try { try {
applicationEventPublisher.publishEvent(event); applicationEventPublisher.publishEvent(event);
} catch (Exception e) { } 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 @Override
public Set<String> getAllServiceIds(ServiceType serviceType) { public Set<String> getAllServiceIds(ServiceType serviceType) {
return getAllServices(serviceType).stream().map(ServiceInfo::getServiceId).collect(Collectors.toSet()); 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; private final byte[] data;
public KafkaTbQueueMsg(ConsumerRecord<String, byte[]> record) { public KafkaTbQueueMsg(ConsumerRecord<String, byte[]> record) {
if (record.key().length() == UUID_LENGTH) { if (record.key().length() <= UUID_LENGTH) {
this.key = UUID.fromString(record.key()); this.key = UUID.fromString(record.key());
} else { } else {
this.key = UUID.randomUUID(); 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 * Copyright © 2016-2024 The Thingsboard Authors
* <p> *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Loading…
Cancel
Save