|
|
|
@ -179,10 +179,15 @@ public class HashPartitionService implements PartitionService { |
|
|
|
public void removeQueue(TransportProtos.QueueDeleteMsg queueDeleteMsg) { |
|
|
|
TenantId tenantId = new TenantId(new UUID(queueDeleteMsg.getTenantIdMSB(), queueDeleteMsg.getTenantIdLSB())); |
|
|
|
QueueKey queueKey = new QueueKey(ServiceType.TB_RULE_ENGINE, queueDeleteMsg.getQueueName(), tenantId); |
|
|
|
myPartitions.remove(queueKey); |
|
|
|
partitionTopicsMap.remove(queueKey); |
|
|
|
partitionSizesMap.remove(queueKey); |
|
|
|
//TODO: remove after merging tb entity services
|
|
|
|
removeTenant(tenantId); |
|
|
|
|
|
|
|
if (serviceInfoProvider.isService(ServiceType.TB_RULE_ENGINE)) { |
|
|
|
publishPartitionChangeEvent(ServiceType.TB_RULE_ENGINE, Map.of(queueKey, Collections.emptySet())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -271,6 +276,8 @@ public class HashPartitionService implements PartitionService { |
|
|
|
final ConcurrentMap<QueueKey, List<Integer>> oldPartitions = myPartitions; |
|
|
|
myPartitions = newPartitions; |
|
|
|
|
|
|
|
Map<QueueKey, Set<TopicPartitionInfo>> changedPartitionsMap = new HashMap<>(); |
|
|
|
|
|
|
|
Set<QueueKey> removed = new HashSet<>(); |
|
|
|
oldPartitions.forEach((queueKey, partitions) -> { |
|
|
|
if (!newPartitions.containsKey(queueKey)) { |
|
|
|
@ -286,7 +293,7 @@ public class HashPartitionService implements PartitionService { |
|
|
|
} |
|
|
|
removed.forEach(queueKey -> { |
|
|
|
log.info("[{}] NO MORE PARTITIONS FOR CURRENT KEY", queueKey); |
|
|
|
applicationEventPublisher.publishEvent(new PartitionChangeEvent(this, queueKey, Collections.emptySet())); |
|
|
|
changedPartitionsMap.put(queueKey, Collections.emptySet()); |
|
|
|
}); |
|
|
|
|
|
|
|
myPartitions.forEach((queueKey, partitions) -> { |
|
|
|
@ -295,9 +302,17 @@ public class HashPartitionService implements PartitionService { |
|
|
|
Set<TopicPartitionInfo> tpiList = partitions.stream() |
|
|
|
.map(partition -> buildTopicPartitionInfo(queueKey, partition)) |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
applicationEventPublisher.publishEvent(new PartitionChangeEvent(this, queueKey, tpiList)); |
|
|
|
changedPartitionsMap.put(queueKey, tpiList); |
|
|
|
} |
|
|
|
}); |
|
|
|
if (!changedPartitionsMap.isEmpty()) { |
|
|
|
Map<ServiceType, Map<QueueKey, Set<TopicPartitionInfo>>> partitionsByServiceType = new HashMap<>(); |
|
|
|
changedPartitionsMap.forEach((queueKey, partitions) -> { |
|
|
|
partitionsByServiceType.computeIfAbsent(queueKey.getType(), serviceType -> new HashMap<>()) |
|
|
|
.put(queueKey, partitions); |
|
|
|
}); |
|
|
|
partitionsByServiceType.forEach(this::publishPartitionChangeEvent); |
|
|
|
} |
|
|
|
|
|
|
|
if (currentOtherServices == null) { |
|
|
|
currentOtherServices = new ArrayList<>(otherServices); |
|
|
|
@ -328,6 +343,18 @@ public class HashPartitionService implements PartitionService { |
|
|
|
applicationEventPublisher.publishEvent(new ServiceListChangedEvent(otherServices, currentService)); |
|
|
|
} |
|
|
|
|
|
|
|
private void publishPartitionChangeEvent(ServiceType serviceType, Map<QueueKey, Set<TopicPartitionInfo>> partitionsMap) { |
|
|
|
if (log.isDebugEnabled()) { |
|
|
|
log.debug("Publishing partition change event for service type " + serviceType + ":" + System.lineSeparator() + |
|
|
|
partitionsMap.entrySet().stream() |
|
|
|
.map(entry -> entry.getKey() + " - " + entry.getValue().stream() |
|
|
|
.map(TopicPartitionInfo::getFullTopicName).sorted() |
|
|
|
.collect(Collectors.toList())) |
|
|
|
.collect(Collectors.joining(System.lineSeparator()))); |
|
|
|
} |
|
|
|
applicationEventPublisher.publishEvent(new PartitionChangeEvent(this, serviceType, partitionsMap)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Set<String> getAllServiceIds(ServiceType serviceType) { |
|
|
|
return getAllServices(serviceType).stream().map(ServiceInfo::getServiceId).collect(Collectors.toSet()); |
|
|
|
@ -493,6 +520,9 @@ public class HashPartitionService implements PartitionService { |
|
|
|
} |
|
|
|
responsibleServices.put(profileId, responsible); |
|
|
|
} |
|
|
|
if (responsible.isEmpty()) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
servers = responsible; |
|
|
|
} |
|
|
|
|
|
|
|
|