Merge pull request #8277 from YevhenBondarenko/fix/system-info-updates

[3.5]fixed system info updates
This commit is contained in:
Yevhen Bondarenko 2023-03-29 12:42:07 +02:00 committed by GitHub
commit 7204d1bf95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 12 deletions

View File

@ -112,13 +112,11 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
public SystemInfo getSystemInfo() {
SystemInfo systemInfo = new SystemInfo();
ServiceInfo serviceInfo = serviceInfoProvider.getServiceInfoWithCurrentSystemInfo();
if (discoveryService.isMonolith()) {
systemInfo.setMonolith(true);
systemInfo.setSystemData(Collections.singletonList(createSystemInfoData(serviceInfo)));
systemInfo.setSystemData(Collections.singletonList(createSystemInfoData(serviceInfoProvider.generateNewServiceInfoWithCurrentSystemInfo())));
} else {
systemInfo.setSystemData(getSystemData(serviceInfo));
systemInfo.setSystemData(getSystemData(serviceInfoProvider.getServiceInfo()));
}
return systemInfo;
@ -156,7 +154,7 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
private void saveCurrentClusterSystemInfo() {
long ts = System.currentTimeMillis();
List<SystemInfoData> clusterSystemData = getSystemData(serviceInfoProvider.getServiceInfoWithCurrentSystemInfo());
List<SystemInfoData> clusterSystemData = getSystemData(serviceInfoProvider.getServiceInfo());
BasicTsKvEntry clusterDataKv = new BasicTsKvEntry(ts, new JsonDataEntry("clusterSystemData", JacksonUtil.toString(clusterSystemData)));
doSave(Collections.singletonList(clusterDataKv));
}
@ -164,7 +162,6 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
private void saveCurrentMonolithSystemInfo() {
long ts = System.currentTimeMillis();
List<TsKvEntry> tsList = new ArrayList<>();
getMemoryUsage().ifPresent(v -> tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("memoryUsage", v))));
getTotalMemory().ifPresent(v -> tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("totalMemory", v))));
getFreeMemory().ifPresent(v -> tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("freeMemory", v))));

View File

@ -79,7 +79,7 @@ public class DefaultTbServiceInfoProvider implements TbServiceInfoProvider {
serviceTypes = Collections.singletonList(ServiceType.of(serviceType));
}
serviceInfo = getServiceInfoWithCurrentSystemInfo();
generateNewServiceInfoWithCurrentSystemInfo();
}
@AfterContextReady
@ -106,13 +106,13 @@ public class DefaultTbServiceInfoProvider implements TbServiceInfoProvider {
}
@Override
public ServiceInfo getServiceInfoWithCurrentSystemInfo() {
public ServiceInfo generateNewServiceInfoWithCurrentSystemInfo() {
ServiceInfo.Builder builder = ServiceInfo.newBuilder()
.setServiceId(serviceId)
.addAllServiceTypes(serviceTypes.stream().map(ServiceType::name).collect(Collectors.toList()))
.setSystemInfo(getCurrentSystemInfoProto());
return builder.build();
return serviceInfo = builder.build();
}
private TransportProtos.SystemInfoProto getCurrentSystemInfoProto() {

View File

@ -16,7 +16,6 @@
package org.thingsboard.server.queue.discovery;
import org.thingsboard.server.common.msg.queue.ServiceType;
import org.thingsboard.server.gen.transport.TransportProtos;
import org.thingsboard.server.gen.transport.TransportProtos.ServiceInfo;
public interface TbServiceInfoProvider {
@ -29,6 +28,6 @@ public interface TbServiceInfoProvider {
boolean isService(ServiceType serviceType);
ServiceInfo getServiceInfoWithCurrentSystemInfo();
ServiceInfo generateNewServiceInfoWithCurrentSystemInfo();
}

View File

@ -143,7 +143,7 @@ public class ZkDiscoveryService implements DiscoveryService, PathChildrenCacheLi
TransportProtos.ServiceInfo self = serviceInfoProvider.getServiceInfo();
if (currentServerExists()) {
log.trace("[{}] Updating ZK node for current instance: {}", self.getServiceId(), nodePath);
client.setData().forPath(nodePath, serviceInfoProvider.getServiceInfoWithCurrentSystemInfo().toByteArray());
client.setData().forPath(nodePath, serviceInfoProvider.generateNewServiceInfoWithCurrentSystemInfo().toByteArray());
} else {
try {
log.info("[{}] Creating ZK node for current instance", self.getServiceId());