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 Long id;
|
||||||
public final ConnectionStatus status;
|
public final ConnectionStatus status;
|
||||||
public final Map<Long, String> indicatorVals;
|
public final Map<Long, String> indicatorVals;
|
||||||
|
public final Integer notificationFlag;
|
||||||
|
|
||||||
public final boolean missingPing;
|
public final boolean missingPing;
|
||||||
public final Boolean grantDenied;
|
public final boolean grantChecked;
|
||||||
|
public final boolean grantDenied;
|
||||||
public final boolean pendingNotification;
|
public final boolean pendingNotification;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
|
@ -33,16 +36,16 @@ public class ClientMonitoringData implements ClientMonitoringDataView {
|
||||||
@JsonProperty(Domain.CLIENT_CONNECTION.ATTR_ID) final Long id,
|
@JsonProperty(Domain.CLIENT_CONNECTION.ATTR_ID) final Long id,
|
||||||
@JsonProperty(ATTR_STATUS) final ConnectionStatus status,
|
@JsonProperty(ATTR_STATUS) final ConnectionStatus status,
|
||||||
@JsonProperty(ATTR_INDICATOR_VALUES) final Map<Long, String> indicatorVals,
|
@JsonProperty(ATTR_INDICATOR_VALUES) final Map<Long, String> indicatorVals,
|
||||||
@JsonProperty(ATTR_MISSING_PING) final boolean missingPing,
|
@JsonProperty(ATTR_NOTIFICATION_FLAG) final Integer notificationFlag) {
|
||||||
@JsonProperty(ATTR_GRANT_DENIED) final Boolean grantDenied,
|
|
||||||
@JsonProperty(ATTR_PENDING_NOTIFICATION) final boolean pendingNotification) {
|
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.indicatorVals = indicatorVals;
|
this.indicatorVals = indicatorVals;
|
||||||
this.missingPing = missingPing;
|
this.notificationFlag = notificationFlag;
|
||||||
this.grantDenied = grantDenied;
|
this.missingPing = notificationFlag != null && (notificationFlag & FLAG_MISSING_PING) > 0;
|
||||||
this.pendingNotification = pendingNotification;
|
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
|
@Override
|
||||||
|
@ -61,24 +64,13 @@ public class ClientMonitoringData implements ClientMonitoringDataView {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMissingPing() {
|
public Integer notificationFlag() {
|
||||||
return this.missingPing;
|
return this.notificationFlag;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean isGrantDenied() {
|
|
||||||
return this.grantDenied;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPendingNotification() {
|
|
||||||
return this.pendingNotification;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasChanged(final ClientMonitoringData other) {
|
public boolean hasChanged(final ClientMonitoringData other) {
|
||||||
return this.status != other.status ||
|
return this.status != other.status ||
|
||||||
this.missingPing != other.missingPing ||
|
!Objects.equals(this.notificationFlag, other.notificationFlag);
|
||||||
!Objects.equals(this.grantDenied, other.grantDenied);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean indicatorValuesEquals(final ClientMonitoringData other) {
|
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_INFO = "in";
|
||||||
public static final String ATTR_INDICATOR_VALUES = "iv";
|
public static final String ATTR_INDICATOR_VALUES = "iv";
|
||||||
public static final String ATTR_CLIENT_GROUPS = "cg";
|
public static final String ATTR_CLIENT_GROUPS = "cg";
|
||||||
public static final String ATTR_MISSING_PING = "mp";
|
public static final String ATTR_NOTIFICATION_FLAG = "nf";
|
||||||
public static final String ATTR_GRANT_DENIED = "gd";
|
|
||||||
public static final String ATTR_PENDING_NOTIFICATION = "pn";
|
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)
|
@JsonProperty(Domain.CLIENT_CONNECTION.ATTR_ID)
|
||||||
Long getId();
|
Long getId();
|
||||||
|
@ -39,14 +43,28 @@ public interface ClientMonitoringDataView {
|
||||||
@JsonProperty(ATTR_INDICATOR_VALUES)
|
@JsonProperty(ATTR_INDICATOR_VALUES)
|
||||||
Map<Long, String> getIndicatorValues();
|
Map<Long, String> getIndicatorValues();
|
||||||
|
|
||||||
@JsonProperty(ATTR_MISSING_PING)
|
@JsonProperty(ATTR_NOTIFICATION_FLAG)
|
||||||
boolean isMissingPing();
|
Integer notificationFlag();
|
||||||
|
|
||||||
@JsonProperty(ATTR_GRANT_DENIED)
|
default boolean isMissingPing() {
|
||||||
Boolean isGrantDenied();
|
final Integer notificationFlag = notificationFlag();
|
||||||
|
return notificationFlag != null && (notificationFlag & FLAG_MISSING_PING) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
@JsonProperty(ATTR_PENDING_NOTIFICATION)
|
default boolean isGrantChecked() {
|
||||||
boolean isPendingNotification();
|
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) {
|
public static Predicate<ClientMonitoringDataView> getStatusPredicate(final ConnectionStatus... status) {
|
||||||
final EnumSet<ConnectionStatus> states = EnumSet.noneOf(ConnectionStatus.class);
|
final EnumSet<ConnectionStatus> states = EnumSet.noneOf(ConnectionStatus.class);
|
||||||
|
|
|
@ -648,15 +648,14 @@ public class ResourceService {
|
||||||
if (monitoringEntry.hasMissingPing()) {
|
if (monitoringEntry.hasMissingPing()) {
|
||||||
return missingPing;
|
return missingPing;
|
||||||
}
|
}
|
||||||
final Boolean grantDenied = monitoringEntry.grantDenied();
|
if (!monitoringEntry.grantChecked()) {
|
||||||
if (grantDenied != null) {
|
if (monitoringEntry.showNoGrantCheckApplied()) {
|
||||||
if (grantDenied) {
|
|
||||||
return grantDeniedText;
|
|
||||||
}
|
|
||||||
} else if (monitoringEntry.showNoGrantCheckApplied()) {
|
|
||||||
return localizedNames.get(status) + grantMissingText;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return localizedNames.get(status) + grantMissingText;
|
||||||
|
}
|
||||||
|
} else if (monitoringEntry.grantDenied()) {
|
||||||
|
return grantDeniedText;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return localizedNames.get(status);
|
return localizedNames.get(status);
|
||||||
|
|
|
@ -77,7 +77,8 @@ public class ClientConnectionDetails implements MonitoringEntry {
|
||||||
public final boolean checkSecurityGrant;
|
public final boolean checkSecurityGrant;
|
||||||
|
|
||||||
private ClientConnectionData connectionData = null;
|
private ClientConnectionData connectionData = null;
|
||||||
public Boolean grantDenied = null;
|
public boolean grantChecked = false;
|
||||||
|
public boolean grantDenied = false;
|
||||||
private boolean statusChanged = true;
|
private boolean statusChanged = true;
|
||||||
private boolean missingChanged = true;
|
private boolean missingChanged = true;
|
||||||
private long startTime = -1;
|
private long startTime = -1;
|
||||||
|
@ -169,7 +170,12 @@ public class ClientConnectionDetails implements MonitoringEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean grantDenied() {
|
public boolean grantChecked() {
|
||||||
|
return this.grantChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean grantDenied() {
|
||||||
return this.grantDenied;
|
return this.grantDenied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,8 +207,10 @@ public class ClientConnectionDetails implements MonitoringEntry {
|
||||||
}
|
}
|
||||||
this.connectionData = connectionData;
|
this.connectionData = connectionData;
|
||||||
if (this.connectionData == null || this.connectionData.clientConnection.securityCheckGranted == null) {
|
if (this.connectionData == null || this.connectionData.clientConnection.securityCheckGranted == null) {
|
||||||
this.grantDenied = null;
|
this.grantChecked = false;
|
||||||
|
this.grantDenied = false;
|
||||||
} else {
|
} else {
|
||||||
|
this.grantChecked = true;
|
||||||
this.grantDenied = !this.connectionData.clientConnection.securityCheckGranted;
|
this.grantDenied = !this.connectionData.clientConnection.securityCheckGranted;
|
||||||
}
|
}
|
||||||
if (this.startTime < 0) {
|
if (this.startTime < 0) {
|
||||||
|
|
|
@ -479,7 +479,12 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean grantDenied() {
|
public boolean grantChecked() {
|
||||||
|
return this.monitoringData.grantChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean grantDenied() {
|
||||||
return this.monitoringData.grantDenied;
|
return this.monitoringData.grantDenied;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,9 @@ public class ColorData {
|
||||||
return this.defaultColor;
|
return this.defaultColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Boolean grantDenied = entry.grantDenied();
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case ACTIVE:
|
case ACTIVE:
|
||||||
return (grantDenied != null && grantDenied)
|
return (entry.grantChecked() && entry.grantDenied())
|
||||||
? this.color3 : (entry.hasMissingPing())
|
? this.color3 : (entry.hasMissingPing())
|
||||||
? this.color2 : this.color1;
|
? this.color2 : this.color1;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -16,13 +16,9 @@ public interface MonitoringEntry {
|
||||||
|
|
||||||
boolean hasMissingPing();
|
boolean hasMissingPing();
|
||||||
|
|
||||||
/** Indicates the security key grant check state
|
boolean grantChecked();
|
||||||
* true = grant denied
|
|
||||||
* false = granted
|
boolean grantDenied();
|
||||||
* null = not checked yet
|
|
||||||
*
|
|
||||||
* @return the security key grant check state */
|
|
||||||
Boolean grantDenied();
|
|
||||||
|
|
||||||
boolean showNoGrantCheckApplied();
|
boolean showNoGrantCheckApplied();
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class ClientConnectionDataInternal extends ClientConnectionData {
|
||||||
|
|
||||||
private final Boolean grantDenied;
|
private final Boolean grantDenied;
|
||||||
|
|
||||||
protected ClientConnectionDataInternal(
|
public ClientConnectionDataInternal(
|
||||||
final ClientConnection clientConnection,
|
final ClientConnection clientConnection,
|
||||||
final PendingNotificationIndication pendingNotificationIndication,
|
final PendingNotificationIndication pendingNotificationIndication,
|
||||||
final List<ClientIndicator> clientIndicators,
|
final List<ClientIndicator> clientIndicators,
|
||||||
|
@ -141,18 +141,38 @@ public class ClientConnectionDataInternal extends ClientConnectionData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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() {
|
public boolean isMissingPing() {
|
||||||
return BooleanUtils.isTrue(getMissingPing());
|
return BooleanUtils.isTrue(getMissingPing());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
public boolean isPendingNotification() {
|
public boolean isPendingNotification() {
|
||||||
return BooleanUtils.isTrue(pendingNotification());
|
return BooleanUtils.isTrue(pendingNotification());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean isGrantDenied() {
|
@JsonIgnore
|
||||||
return ClientConnectionDataInternal.this.grantDenied;
|
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;
|
package ch.ethz.seb.sebserver.gbl.model;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
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.UserMod;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
|
import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
|
||||||
import ch.ethz.seb.sebserver.gbl.monitoring.SimpleIndicatorValue;
|
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 {
|
public class ModelObjectJSONGenerator {
|
||||||
|
|
||||||
|
@ -282,8 +288,30 @@ public class ModelObjectJSONGenerator {
|
||||||
System.out.println(domainObject.getClass().getSimpleName() + ":");
|
System.out.println(domainObject.getClass().getSimpleName() + ":");
|
||||||
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
|
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(domainObject.getClass().getSimpleName() + ":");
|
||||||
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
|
System.out.println(
|
||||||
|
writerWithDefaultPrettyPrinter.writeValueAsString(clientConnectionDataInternal.monitoringDataView));
|
||||||
|
|
||||||
domainObject = new ClientEvent(1L, 1L, EventType.WARN_LOG,
|
domainObject = new ClientEvent(1L, 1L, EventType.WARN_LOG,
|
||||||
System.currentTimeMillis(), System.currentTimeMillis(), 123.0, "text");
|
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