Skip to content

Commit

Permalink
Updating policy rule threshold schema (MID-5049,MID-5050)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Feb 1, 2019
1 parent 5a10588 commit 99b004f
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 14 deletions.
113 changes: 103 additions & 10 deletions infra/schema/src/main/resources/xml/ns/public/common/common-policy-3.xsd
Expand Up @@ -1256,27 +1256,44 @@
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="count" type="xsd:int" minOccurs="0">
<xsd:element name="lowWaterMark" type="tns:WaterMarkType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Lower bound of the threshold.
Lowest value for which the policy rule is activated. The policy rule
will be triggered for all values starting from this value up until the
high water mark (closed interval). If no low water mark is specified then
the policy rule will be activated for all values up to the high water mark.
Policy rule with a threshold that does not have any water marks will
never be activated.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>PolicyThresholdType.lowWaterMark</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="highWaterMark" type="tns:WaterMarkType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expected inner constraint state before the operation.
True means the constraint must evaluate to true. False means the constraint must evaluate to false.
Unspecified means the constraint is not checked before the operation.
Upper bound of the threshold.
Highest value for which the policy rule is activated. The policy rule
will be triggered for all values starting from low water mark up until
this value (closed interval). If no high water mark is specified then
the policy rule will be activated for all values that are greater than
or equal to high water mark.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>TransitionPolicyConstraintType.stateBefore</a:displayName>
<a:displayName>PolicyThresholdType.highWaterMark</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="countRefresh" type="xsd:duration" minOccurs="0">
<xsd:element name="timeInterval" type="tns:TimeIntervalType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expected inner constraint state after the operation.
True means the constraint must evaluate to true. False means the constraint must evaluate to false.
Unspecified means the constraint is not checked after the operation.
TODO: time interval!
</xsd:documentation>
<xsd:appinfo>
<a:displayName>TransitionPolicyConstraintType.stateAfter</a:displayName>
<a:displayName>PolicyThresholdType.timeInterval</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand All @@ -1285,6 +1302,82 @@
</xsd:complexType>
<xsd:element name="policyThreshold" type="tns:PolicyThresholdType"/>

<xsd:complexType name="WaterMarkType">
<xsd:annotation>
<xsd:documentation>
Water mark (bound). Lowest or highest value defining an interval.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
<a:since>4.0</a:since>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="count" type="xsd:int" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Absolute count of objects that triggers the watermark.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>WaterMarkType.count</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="percentage" type="xsd:float" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Relative proportion (percentage) of objects that triggers
the watermark. Value in percents (0-100). The value is relative
to the "domain". This only works if a domain is specified.
E.g. it will work for object collections with a domain or
for processes where we know total count of all processed
objects. Percentage watermarks cannot be used if domain
is not specified.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>WaterMarkType.percentage</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="TimeIntervalType">
<xsd:annotation>
<xsd:documentation>
Water mark (bound). Lowest or highest value defining an interval.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
<a:since>4.0</a:since>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="interval" type="xsd:duration" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Time interval. Interpretation of this time interval depends on the context
in which it is used. E.g. for synchronization thresholds the interval of 1 hour
usually means "number of changes in one hour interval". For dashboards it may
mean "number of errors in last hour" and so on.
If there is a danger that the interval might be misinterpreted then the
precise interpretation may be specified by using additional items in this
data structure.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>TimeIntervalType.interval</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<!-- TODO: specify how to interpret time interval.
Whether it is periodic (every 5min), relative to present time (last 24hours),
relative to other point in time (first 3hours after system start) or absolute
time range. -->
</xsd:sequence>
</xsd:complexType>


<xsd:simpleType name="PolicyConstraintEnforcementType">
<xsd:annotation>
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyActionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyThresholdType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SuspendTaskPolicyActionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.WaterMarkType;

/**
* @author katka
Expand Down Expand Up @@ -100,12 +101,27 @@ private synchronized int checkEvaluatedPolicyRule(Task task, EvaluatedPolicyRule
// SuspendTaskPolicyActionType stopAction = policyRule.getEnabledAction(SuspendTaskPolicyActionType.class);

PolicyThresholdType thresholdSettings = policyRule.getPolicyThreshold();
if (thresholdSettings.getCount() != null && thresholdSettings.getCount().intValue() < counter) {
if (isOverThreshold(thresholdSettings, counter)) {
// taskManager.suspendTask(task, 10, result);
throw new ThresholdPolicyViolationException("Policy rule violation: " + policyRule.getPolicyRule());
}
}

return counter;
}

private boolean isOverThreshold(PolicyThresholdType thresholdSettings, int counter) throws SchemaException {
// TODO: better implementation that takes hight water mark into account
WaterMarkType lowWaterMark = thresholdSettings.getLowWaterMark();
if (lowWaterMark == null) {
return true;
}
Integer lowWaterCount = lowWaterMark.getCount();
if (lowWaterCount == null) {
throw new SchemaException("No count in low water mark in a policy rule");
}
return (counter >= lowWaterCount);
}
}


4 changes: 2 additions & 2 deletions samples/experimental/collection-resources-up.xml
Expand Up @@ -52,10 +52,10 @@
</collectionStats>
</policyConstraints>
<policyThreshold>
<lowerBound> <!-- lowWaterMark? -->
<lowWaterMark> <!-- lowWaterMark? -->
<percentage>90</percentage>
<!-- <count>4</count> -->
</lowerBound>
</lowWaterMark>
<!-- <period>PT1H</period> -->
</policyThreshold>
<policySituation>#resourceHealthDanger</policySituation>
Expand Down

0 comments on commit 99b004f

Please sign in to comment.