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 -> serviceInfo.getServiceTypesList().contains(ServiceType.EDQS.name()))
|
||||||
.filter(ServiceInfo::getReady)
|
.filter(ServiceInfo::getReady)
|
||||||
.toList();
|
.toList();
|
||||||
boolean changed = state.setEdqsReady(!readyEdqsServers.isEmpty());
|
boolean changed = state.updateEdqsReady(!readyEdqsServers.isEmpty());
|
||||||
if (changed) {
|
if (changed) {
|
||||||
broadcastEdqsReady(state.getEdqsReady());
|
broadcastEdqsReady(state.getEdqsReady());
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ public class DefaultEdqsService implements EdqsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onEdqsReady(boolean ready) {
|
private void onEdqsReady(boolean ready) {
|
||||||
state.setEdqsReady(ready);
|
state.updateEdqsReady(ready);
|
||||||
checkState();
|
checkState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,8 +77,9 @@ public class EdqsEntityQueryControllerTest extends EntityQueryControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEdqsState() {
|
public void testEdqsState() throws Exception {
|
||||||
assertThat(edqsService.getState().getApiMode()).isEqualTo(EdqsApiMode.AUTO_ENABLED);
|
loginSysAdmin();
|
||||||
|
assertThat(getEdqsState().getApiMode()).isEqualTo(EdqsApiMode.AUTO_ENABLED);
|
||||||
|
|
||||||
// notifying EDQS is not ready: API should be auto-disabled
|
// notifying EDQS is not ready: API should be auto-disabled
|
||||||
discoveryService.setReady(false);
|
discoveryService.setReady(false);
|
||||||
@ -129,8 +130,12 @@ public class EdqsEntityQueryControllerTest extends EntityQueryControllerTest {
|
|||||||
|
|
||||||
private void verifyState(ThrowingConsumer<EdqsState> assertion) {
|
private void verifyState(ThrowingConsumer<EdqsState> assertion) {
|
||||||
await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> {
|
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;
|
package org.thingsboard.server.common.data.edqs;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -32,16 +33,18 @@ public class EdqsState {
|
|||||||
@Setter
|
@Setter
|
||||||
private EdqsApiMode apiMode;
|
private EdqsApiMode apiMode;
|
||||||
|
|
||||||
public boolean setEdqsReady(boolean ready) {
|
public boolean updateEdqsReady(boolean ready) {
|
||||||
boolean changed = BooleanUtils.toBooleanDefaultIfNull(this.edqsReady, false) != ready;
|
boolean changed = BooleanUtils.toBooleanDefaultIfNull(this.edqsReady, false) != ready;
|
||||||
this.edqsReady = ready;
|
this.edqsReady = ready;
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
public boolean isApiReady() {
|
public boolean isApiReady() {
|
||||||
return edqsReady && syncStatus == EdqsSyncStatus.FINISHED;
|
return edqsReady && syncStatus == EdqsSyncStatus.FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
public boolean isApiEnabled() {
|
public boolean isApiEnabled() {
|
||||||
return apiMode != null && (apiMode == EdqsApiMode.ENABLED || apiMode == EdqsApiMode.AUTO_ENABLED);
|
return apiMode != null && (apiMode == EdqsApiMode.ENABLED || apiMode == EdqsApiMode.AUTO_ENABLED);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user