Skip to content

Commit

Permalink
Improve activity tailoring
Browse files Browse the repository at this point in the history
It is now possible to tailor more child activities at once.
Also a new mode (overwriteSpecified) was introduced.
  • Loading branch information
mederly committed Jul 1, 2021
1 parent 1a9d364 commit 6879679
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 214 deletions.
128 changes: 117 additions & 11 deletions infra/schema/src/main/resources/xml/ns/public/common/common-tasks-3.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -2070,10 +2070,11 @@
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="reference" type="xsd:string" minOccurs="0">
<xsd:element name="reference" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Identifier of existing activity that is to be tailored.
Identifier of existing activity or activities that are to be tailored.
No value means all activities.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand All @@ -2084,26 +2085,112 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="controlFlow" type="tns:ActivityControlFlowSpecificationType" minOccurs="0">
<xsd:element name="controlFlow" type="tns:ActivityControlFlowSpecificationTailoringType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Items like prerequisites, preconditions, error handling strategy, and so on.
TODO partial overriding
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="distribution" type="tns:WorkDistributionType" minOccurs="0">
<xsd:element name="distribution" type="tns:WorkDistributionTailoringType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Distribution of the work executed as part of this activity.
TODO partial overriding
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long"/>
</xsd:complexType>

<xsd:complexType name="ActivityControlFlowSpecificationTailoringType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
<xsd:appinfo>
<a:since>4.4</a:since>
<a:container>true</a:container>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:ActivityControlFlowSpecificationType">
<xsd:sequence>
<xsd:element name="tailoringMode" type="tns:TailoringModeType" minOccurs="0" default="overwrite">
<xsd:annotation>
<xsd:documentation>
How the tailoring is applied.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="WorkDistributionTailoringType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
<xsd:appinfo>
<a:since>4.4</a:since>
<a:container>true</a:container>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:WorkDistributionType">
<xsd:sequence>
<xsd:element name="tailoringMode" type="tns:TailoringModeType" minOccurs="0" default="overwrite">
<xsd:annotation>
<xsd:documentation>
How the tailoring is applied.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:simpleType name="TailoringModeType">
<xsd:annotation>
<xsd:documentation>
How the tailoring is applied.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="overwrite">
<xsd:annotation>
<xsd:documentation>
<p>
Specified container value overwrites everything that was configured for an activity.
This is the default.
</p>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="OVERWRITE"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="overwriteSpecified">
<xsd:annotation>
<xsd:documentation>
<p>
Only specified (first-level) items are overwritten.
</p>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="OVERWRITE_SPECIFIED"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="ActivityCompositionType">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -3157,14 +3244,11 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="subtasks" type="tns:PartsSubtasksRealizationType" minOccurs="0">
<xsd:element name="autoscaling" type="tns:AutoscalingConfigurationType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Parameters describing the realization of this complex part via subtasks.
Whether and how is this activity work distribution auto-scaled.
</xsd:documentation>
<xsd:appinfo>
<a:since>4.4</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
Expand Down Expand Up @@ -6751,4 +6835,26 @@
</xsd:complexType>
<xsd:element name="workersReconciliationResult" type="tns:WorkersReconciliationResultType" />

<xsd:complexType name="AutoscalingConfigurationType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
<xsd:appinfo>
<a:container>true</a:container>
<a:since>4.4</a:since>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="enabled" type="xsd:boolean" minOccurs="0" default="true">
<xsd:annotation>
<xsd:documentation>
Is autoscaling enabled for this activity? The default is "true" if the autoscaling configuration
exists. (Note that this may change in the future.)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,11 @@
</focusValidityScan>
</work>
<tailoring>
<!-- TODO simplify this specification -->
<change>
<reference>objects</reference>
<distribution>
<subtask/>
</distribution>
</change>
<change>
<reference>assignments</reference>
<distribution>
<subtask/>
</distribution>
</change>
</tailoring>
</activity>

</task>
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
</reconciliation>
</work>
<tailoring>
<change>
<reference>operationCompletion</reference>
<distribution>
<subtask/>
</distribution>
</change>
<change>
<reference>resourceObjects</reference>
<distribution>
Expand All @@ -61,13 +55,13 @@
</workersPerNode>
</workers>
<workerThreads>2</workerThreads>
<subtask/>
<tailoringMode>overwriteSpecified</tailoringMode>
</distribution>
</change>
<change>
<reference>remainingShadows</reference>
<distribution>
<subtask/>
<tailoringMode>overwriteSpecified</tailoringMode>
</distribution>
</change>
</tailoring>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
</work>
<tailoring>
<change>
<reference>operationCompletion</reference>
<distribution>
<subtask/>
<tailoringMode>overwriteSpecified</tailoringMode>
</distribution>
</change>
<change>
Expand All @@ -54,13 +54,6 @@
</stringSegmentation>
</buckets>
<workerThreads>2</workerThreads>
<subtask/>
</distribution>
</change>
<change>
<reference>remainingShadows</reference>
<distribution>
<subtask/>
</distribution>
</change>
</tailoring>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</work>
<tailoring>
<change>
<reference>operationCompletion</reference>
<distribution>
<subtask/>
<tailoringMode>overwriteSpecified</tailoringMode>
</distribution>
</change>
<change>
Expand All @@ -53,12 +53,6 @@
<subtask/>
</distribution>
</change>
<change>
<reference>remainingShadows</reference>
<distribution>
<subtask/>
</distribution>
</change>
</tailoring>
</activity>
</task>
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@

<task oid="19418f29-096e-4d15-b3df-e579e33ca405"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:syncext="http://midpoint.evolveum.com/xml/ns/public/model/extension-3"
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">

<name>Reconciliation</name>

<extension>
<syncext:freshnessInterval>1000</syncext:freshnessInterval>
</extension>

<taskIdentifier>10000000-0000-0000-5656-56560000a204</taskIdentifier>
<ownerRef oid="00000000-0000-0000-0000-000000000002"/>
<executionStatus>closed</executionStatus> <!-- run by the test code -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

import com.evolveum.midpoint.repo.common.activity.definition.ActivityTailoring;

import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityTailoringType;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Objects;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

class ActivityTailor {
Expand All @@ -33,18 +33,23 @@ class ActivityTailor {

public void execute() throws SchemaException {
for (ActivityTailoringType change : tailoring.getChanges()) {
Activity<?, ?> child = findChild(change.getReference());
child.applyChangeTailoring(change);
findChildren(change.getReference())
.forEach(child -> child.applyChangeTailoring(change));
}
}

private @NotNull Activity<?, ?> findChild(String reference) throws SchemaException {
Objects.requireNonNull(reference, "An existing child identifier is required when tailoring");
return MiscUtil.extractSingletonRequired(
childrenList.stream()
.filter(ch -> reference.equals(ch.getIdentifier()))
.collect(Collectors.toList()),
() -> new SchemaException("More than one child activity with identifier '" + reference + "' in " + activity),
() -> new SchemaException("No child activity with identifier '" + reference + "' in " + activity));
private @NotNull Collection<Activity<?, ?>> findChildren(List<String> references) throws SchemaException {
if (!references.isEmpty()) {
List<Activity<?, ?>> matching = childrenList.stream()
.filter(ch -> references.contains(ch.getIdentifier()))
.collect(Collectors.toList());
if (matching.isEmpty()) {
throw new SchemaException("No child activity matching " + references + " in " + activity);
} else {
return matching;
}
} else {
return childrenList;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityControlFlowSpecificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityDefinitionType;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivityTailoringType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskErrorHandlingStrategyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -48,7 +44,7 @@ public TaskErrorHandlingStrategyType getErrorHandlingStrategy() {

void applyChangeTailoring(@NotNull ActivityTailoringType tailoring) {
if (tailoring.getControlFlow() != null) {
this.bean = tailoring.getControlFlow();
bean = TailoringUtil.getTailoredBean(bean, tailoring.getControlFlow());
} else {
// null means we do not want it to change.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public int getWorkerThreads() {

void applyChangeTailoring(@NotNull ActivityTailoringType tailoring) {
if (tailoring.getDistribution() != null) {
this.bean = tailoring.getDistribution();
bean = TailoringUtil.getTailoredBean(bean, tailoring.getDistribution());
} else {
// null means we do not want it to change.
}
Expand Down

0 comments on commit 6879679

Please sign in to comment.