Refactor EdqsState serialization

This commit is contained in:
ViacheslavKlimov 2025-05-28 17:08:09 +03:00
parent e17004ebb3
commit eb97bd7db7
3 changed files with 14 additions and 6 deletions

View File

@ -140,7 +140,7 @@ public class DefaultEdqsService implements EdqsService {
.filter(serviceInfo -> serviceInfo.getServiceTypesList().contains(ServiceType.EDQS.name()))
.filter(ServiceInfo::getReady)
.toList();
boolean changed = state.setEdqsReady(!readyEdqsServers.isEmpty());
boolean changed = state.updateEdqsReady(!readyEdqsServers.isEmpty());
if (changed) {
broadcastEdqsReady(state.getEdqsReady());
}
@ -236,7 +236,7 @@ public class DefaultEdqsService implements EdqsService {
}
private void onEdqsReady(boolean ready) {
state.setEdqsReady(ready);
state.updateEdqsReady(ready);
checkState();
}

View File

@ -77,8 +77,9 @@ public class EdqsEntityQueryControllerTest extends EntityQueryControllerTest {
}
@Test
public void testEdqsState() {
assertThat(edqsService.getState().getApiMode()).isEqualTo(EdqsApiMode.AUTO_ENABLED);
public void testEdqsState() throws Exception {
loginSysAdmin();
assertThat(getEdqsState().getApiMode()).isEqualTo(EdqsApiMode.AUTO_ENABLED);
// notifying EDQS is not ready: API should be auto-disabled
discoveryService.setReady(false);
@ -129,8 +130,12 @@ public class EdqsEntityQueryControllerTest extends EntityQueryControllerTest {
private void verifyState(ThrowingConsumer<EdqsState> assertion) {
await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> {
assertThat(edqsService.getState()).satisfies(assertion);
assertThat(getEdqsState()).satisfies(assertion);
});
}
private EdqsState getEdqsState() throws Exception {
return doGet("/api/edqs/state", EdqsState.class);
}
}

View File

@ -15,6 +15,7 @@
*/
package org.thingsboard.server.common.data.edqs;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -32,16 +33,18 @@ public class EdqsState {
@Setter
private EdqsApiMode apiMode;
public boolean setEdqsReady(boolean ready) {
public boolean updateEdqsReady(boolean ready) {
boolean changed = BooleanUtils.toBooleanDefaultIfNull(this.edqsReady, false) != ready;
this.edqsReady = ready;
return changed;
}
@JsonIgnore
public boolean isApiReady() {
return edqsReady && syncStatus == EdqsSyncStatus.FINISHED;
}
@JsonIgnore
public boolean isApiEnabled() {
return apiMode != null && (apiMode == EdqsApiMode.ENABLED || apiMode == EdqsApiMode.AUTO_ENABLED);
}