SEBSERV-329 refactoring of monitoring flags, now baked into integer
This commit is contained in:
parent
7e22375260
commit
a078d1d421
9 changed files with 191 additions and 55 deletions
|
@ -24,8 +24,11 @@ public class ClientMonitoringData implements ClientMonitoringDataView {
|
|||
public final Long id;
|
||||
public final ConnectionStatus status;
|
||||
public final Map<Long, String> indicatorVals;
|
||||
public final Integer notificationFlag;
|
||||
|
||||
public final boolean missingPing;
|
||||
public final Boolean grantDenied;
|
||||
public final boolean grantChecked;
|
||||
public final boolean grantDenied;
|
||||
public final boolean pendingNotification;
|
||||
|
||||
@JsonCreator
|
||||
|
@ -33,16 +36,16 @@ public class ClientMonitoringData implements ClientMonitoringDataView {
|
|||
@JsonProperty(Domain.CLIENT_CONNECTION.ATTR_ID) final Long id,
|
||||
@JsonProperty(ATTR_STATUS) final ConnectionStatus status,
|
||||
@JsonProperty(ATTR_INDICATOR_VALUES) final Map<Long, String> indicatorVals,
|
||||
@JsonProperty(ATTR_MISSING_PING) final boolean missingPing,
|
||||
@JsonProperty(ATTR_GRANT_DENIED) final Boolean grantDenied,
|
||||
@JsonProperty(ATTR_PENDING_NOTIFICATION) final boolean pendingNotification) {
|
||||
@JsonProperty(ATTR_NOTIFICATION_FLAG) final Integer notificationFlag) {
|
||||
|
||||
this.id = id;
|
||||
this.status = status;
|
||||
this.indicatorVals = indicatorVals;
|
||||
this.missingPing = missingPing;
|
||||
this.grantDenied = grantDenied;
|
||||
this.pendingNotification = pendingNotification;
|
||||
this.notificationFlag = notificationFlag;
|
||||
this.missingPing = notificationFlag != null && (notificationFlag & FLAG_MISSING_PING) > 0;
|
||||
this.grantChecked = notificationFlag == null || (notificationFlag & FLAG_GRANT_NOT_CHECKED) == 0;
|
||||
this.grantDenied = notificationFlag != null && (notificationFlag & FLAG_GRANT_DENIED) > 0;
|
||||
this.pendingNotification = notificationFlag != null && (notificationFlag & FLAG_PENDING_NOTIFICATION) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,24 +64,13 @@ public class ClientMonitoringData implements ClientMonitoringDataView {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isMissingPing() {
|
||||
return this.missingPing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isGrantDenied() {
|
||||
return this.grantDenied;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPendingNotification() {
|
||||
return this.pendingNotification;
|
||||
public Integer notificationFlag() {
|
||||
return this.notificationFlag;
|
||||
}
|
||||
|
||||
public boolean hasChanged(final ClientMonitoringData other) {
|
||||
return this.status != other.status ||
|
||||
this.missingPing != other.missingPing ||
|
||||
!Objects.equals(this.grantDenied, other.grantDenied);
|
||||
!Objects.equals(this.notificationFlag, other.notificationFlag);
|
||||
}
|
||||
|
||||
public boolean indicatorValuesEquals(final ClientMonitoringData other) {
|
||||
|
|
|
@ -26,9 +26,13 @@ public interface ClientMonitoringDataView {
|
|||
public static final String ATTR_INFO = "in";
|
||||
public static final String ATTR_INDICATOR_VALUES = "iv";
|
||||
public static final String ATTR_CLIENT_GROUPS = "cg";
|
||||
public static final String ATTR_MISSING_PING = "mp";
|
||||
public static final String ATTR_GRANT_DENIED = "gd";
|
||||
public static final String ATTR_PENDING_NOTIFICATION = "pn";
|
||||
public static final String ATTR_NOTIFICATION_FLAG = "nf";
|
||||
|
||||
public static final int FLAG_MISSING_PING = 1;
|
||||
public static final int FLAG_PENDING_NOTIFICATION = 2;
|
||||
public static final int FLAG_GRANT_NOT_CHECKED = 4;
|
||||
public static final int FLAG_GRANT_DENIED = 8;
|
||||
public static final int FLAG_INVALID_SEB_VERSION = 16;
|
||||
|
||||
@JsonProperty(Domain.CLIENT_CONNECTION.ATTR_ID)
|
||||
Long getId();
|
||||
|
@ -39,14 +43,28 @@ public interface ClientMonitoringDataView {
|
|||
@JsonProperty(ATTR_INDICATOR_VALUES)
|
||||
Map<Long, String> getIndicatorValues();
|
||||
|
||||
@JsonProperty(ATTR_MISSING_PING)
|
||||
boolean isMissingPing();
|
||||
@JsonProperty(ATTR_NOTIFICATION_FLAG)
|
||||
Integer notificationFlag();
|
||||
|
||||
@JsonProperty(ATTR_GRANT_DENIED)
|
||||
Boolean isGrantDenied();
|
||||
default boolean isMissingPing() {
|
||||
final Integer notificationFlag = notificationFlag();
|
||||
return notificationFlag != null && (notificationFlag & FLAG_MISSING_PING) > 0;
|
||||
}
|
||||
|
||||
@JsonProperty(ATTR_PENDING_NOTIFICATION)
|
||||
boolean isPendingNotification();
|
||||
default boolean isGrantChecked() {
|
||||
final Integer notificationFlag = notificationFlag();
|
||||
return notificationFlag != null && (notificationFlag & FLAG_GRANT_NOT_CHECKED) == 0;
|
||||
}
|
||||
|
||||
default boolean isGrantDenied() {
|
||||
final Integer notificationFlag = notificationFlag();
|
||||
return notificationFlag != null && (notificationFlag & FLAG_GRANT_DENIED) > 0;
|
||||
}
|
||||
|
||||
default boolean isPendingNotification() {
|
||||
final Integer notificationFlag = notificationFlag();
|
||||
return notificationFlag != null && (notificationFlag & FLAG_PENDING_NOTIFICATION) > 0;
|
||||
}
|
||||
|
||||
public static Predicate<ClientMonitoringDataView> getStatusPredicate(final ConnectionStatus... status) {
|
||||
final EnumSet<ConnectionStatus> states = EnumSet.noneOf(ConnectionStatus.class);
|
||||
|
|
|
@ -648,15 +648,14 @@ public class ResourceService {
|
|||
if (monitoringEntry.hasMissingPing()) {
|
||||
return missingPing;
|
||||
}
|
||||
final Boolean grantDenied = monitoringEntry.grantDenied();
|
||||
if (grantDenied != null) {
|
||||
if (grantDenied) {
|
||||
return grantDeniedText;
|
||||
}
|
||||
} else if (monitoringEntry.showNoGrantCheckApplied()) {
|
||||
return localizedNames.get(status) + grantMissingText;
|
||||
}
|
||||
if (!monitoringEntry.grantChecked()) {
|
||||
if (monitoringEntry.showNoGrantCheckApplied()) {
|
||||
|
||||
return localizedNames.get(status) + grantMissingText;
|
||||
}
|
||||
} else if (monitoringEntry.grantDenied()) {
|
||||
return grantDeniedText;
|
||||
}
|
||||
}
|
||||
|
||||
return localizedNames.get(status);
|
||||
|
|
|
@ -77,7 +77,8 @@ public class ClientConnectionDetails implements MonitoringEntry {
|
|||
public final boolean checkSecurityGrant;
|
||||
|
||||
private ClientConnectionData connectionData = null;
|
||||
public Boolean grantDenied = null;
|
||||
public boolean grantChecked = false;
|
||||
public boolean grantDenied = false;
|
||||
private boolean statusChanged = true;
|
||||
private boolean missingChanged = true;
|
||||
private long startTime = -1;
|
||||
|
@ -169,7 +170,12 @@ public class ClientConnectionDetails implements MonitoringEntry {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean grantDenied() {
|
||||
public boolean grantChecked() {
|
||||
return this.grantChecked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grantDenied() {
|
||||
return this.grantDenied;
|
||||
}
|
||||
|
||||
|
@ -201,8 +207,10 @@ public class ClientConnectionDetails implements MonitoringEntry {
|
|||
}
|
||||
this.connectionData = connectionData;
|
||||
if (this.connectionData == null || this.connectionData.clientConnection.securityCheckGranted == null) {
|
||||
this.grantDenied = null;
|
||||
this.grantChecked = false;
|
||||
this.grantDenied = false;
|
||||
} else {
|
||||
this.grantChecked = true;
|
||||
this.grantDenied = !this.connectionData.clientConnection.securityCheckGranted;
|
||||
}
|
||||
if (this.startTime < 0) {
|
||||
|
|
|
@ -479,7 +479,12 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean grantDenied() {
|
||||
public boolean grantChecked() {
|
||||
return this.monitoringData.grantChecked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grantDenied() {
|
||||
return this.monitoringData.grantDenied;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,9 @@ public class ColorData {
|
|||
return this.defaultColor;
|
||||
}
|
||||
|
||||
final Boolean grantDenied = entry.grantDenied();
|
||||
switch (status) {
|
||||
case ACTIVE:
|
||||
return (grantDenied != null && grantDenied)
|
||||
return (entry.grantChecked() && entry.grantDenied())
|
||||
? this.color3 : (entry.hasMissingPing())
|
||||
? this.color2 : this.color1;
|
||||
default:
|
||||
|
|
|
@ -16,13 +16,9 @@ public interface MonitoringEntry {
|
|||
|
||||
boolean hasMissingPing();
|
||||
|
||||
/** Indicates the security key grant check state
|
||||
* true = grant denied
|
||||
* false = granted
|
||||
* null = not checked yet
|
||||
*
|
||||
* @return the security key grant check state */
|
||||
Boolean grantDenied();
|
||||
boolean grantChecked();
|
||||
|
||||
boolean grantDenied();
|
||||
|
||||
boolean showNoGrantCheckApplied();
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ClientConnectionDataInternal extends ClientConnectionData {
|
|||
|
||||
private final Boolean grantDenied;
|
||||
|
||||
protected ClientConnectionDataInternal(
|
||||
public ClientConnectionDataInternal(
|
||||
final ClientConnection clientConnection,
|
||||
final PendingNotificationIndication pendingNotificationIndication,
|
||||
final List<ClientIndicator> clientIndicators,
|
||||
|
@ -141,18 +141,38 @@ public class ClientConnectionDataInternal extends ClientConnectionData {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Integer notificationFlag() {
|
||||
final int flag = 0
|
||||
| (isMissingPing() ? ClientMonitoringDataView.FLAG_MISSING_PING : 0)
|
||||
| (isPendingNotification() ? ClientMonitoringDataView.FLAG_PENDING_NOTIFICATION : 0)
|
||||
| (!isGrantChecked() ? ClientMonitoringDataView.FLAG_GRANT_NOT_CHECKED : 0)
|
||||
| (isGrantDenied() ? ClientMonitoringDataView.FLAG_GRANT_DENIED : 0);
|
||||
|
||||
return (flag > 0) ? flag : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public boolean isMissingPing() {
|
||||
return BooleanUtils.isTrue(getMissingPing());
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public boolean isPendingNotification() {
|
||||
return BooleanUtils.isTrue(pendingNotification());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isGrantDenied() {
|
||||
return ClientConnectionDataInternal.this.grantDenied;
|
||||
@JsonIgnore
|
||||
public boolean isGrantChecked() {
|
||||
return ClientConnectionDataInternal.this.grantDenied != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public boolean isGrantDenied() {
|
||||
return BooleanUtils.isTrue(ClientConnectionDataInternal.this.grantDenied);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
package ch.ethz.seb.sebserver.gbl.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -70,6 +72,10 @@ import ch.ethz.seb.sebserver.gbl.model.user.UserLogActivityType;
|
|||
import ch.ethz.seb.sebserver.gbl.model.user.UserMod;
|
||||
import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
|
||||
import ch.ethz.seb.sebserver.gbl.monitoring.SimpleIndicatorValue;
|
||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientEventRecord;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ClientIndicator;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.session.PendingNotificationIndication;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.ClientConnectionDataInternal;
|
||||
|
||||
public class ModelObjectJSONGenerator {
|
||||
|
||||
|
@ -282,8 +288,30 @@ public class ModelObjectJSONGenerator {
|
|||
System.out.println(domainObject.getClass().getSimpleName() + ":");
|
||||
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
|
||||
|
||||
final ClientConnectionDataInternal clientConnectionDataInternal = new ClientConnectionDataInternal(
|
||||
new ClientConnection(
|
||||
1L, 1L, 1L, ConnectionStatus.ACTIVE, UUID.randomUUID().toString(),
|
||||
"user-account-1", "86.119.30.213",
|
||||
"seb_os_name", "seb_machine_name", "seb_version",
|
||||
"vdiID", true, "", currentTimeMillis, currentTimeMillis,
|
||||
123L,
|
||||
true,
|
||||
false, null),
|
||||
new PendingNotificationIndication() {
|
||||
@Override
|
||||
public boolean notifictionPending() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
Arrays.asList(
|
||||
new ClientIndicatorTestImpl(1L, 1.0),
|
||||
new ClientIndicatorTestImpl(2L, 2.0),
|
||||
new ClientIndicatorTestImpl(3L, 3.0)),
|
||||
new HashSet<>(Arrays.asList(1L, 2L)));
|
||||
|
||||
System.out.println(domainObject.getClass().getSimpleName() + ":");
|
||||
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
|
||||
System.out.println(
|
||||
writerWithDefaultPrettyPrinter.writeValueAsString(clientConnectionDataInternal.monitoringDataView));
|
||||
|
||||
domainObject = new ClientEvent(1L, 1L, EventType.WARN_LOG,
|
||||
System.currentTimeMillis(), System.currentTimeMillis(), 123.0, "text");
|
||||
|
@ -326,4 +354,75 @@ public class ModelObjectJSONGenerator {
|
|||
|
||||
}
|
||||
|
||||
private static class ClientIndicatorTestImpl implements ClientIndicator {
|
||||
|
||||
public final Long indicatorId;
|
||||
public final double value;
|
||||
|
||||
public ClientIndicatorTestImpl(final Long indicatorId, final double value) {
|
||||
this.value = value;
|
||||
this.indicatorId = indicatorId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getIndicatorId() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.indicatorId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final Indicator indicatorDefinition, final Long connectionId, final boolean active,
|
||||
final boolean cachingEnabled) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndicatorType getType() {
|
||||
return IndicatorType.ERROR_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long examId() {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long connectionId() {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double computeValueAt(final long timestamp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<EventType> observedEvents() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyValueChange(final ClientEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyValueChange(final ClientEventRecord clientEventRecord) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasIncident() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue