Refactor EdqsState serialization
This commit is contained in:
parent
e17004ebb3
commit
eb97bd7db7
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user