Skip to content

Commit

Permalink
Add preliminary support for simulations in tasks
Browse files Browse the repository at this point in the history
Now it is possible to specify:

1. Whether the activity should use production or development
configuration (if "preview" execution mode is set).
2. If the simulation result should be created for the activity.

Work in progress. Early prototype.
  • Loading branch information
mederly committed Dec 9, 2022
1 parent 0dc08ac commit f94fcb6
Show file tree
Hide file tree
Showing 67 changed files with 649 additions and 410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

package com.evolveum.midpoint.schema;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ExecutionModeType;

import org.jetbrains.annotations.NotNull;

import java.io.Serializable;

/**
Expand Down Expand Up @@ -42,19 +38,6 @@ private TaskExecutionMode(String name, boolean persistent, boolean productionCon
this.productionConfiguration = productionConfiguration;
}

// Preliminary implementation
public static @NotNull TaskExecutionMode fromActivityExecutionMode(@NotNull ExecutionModeType activityExecutionMode) {
switch (activityExecutionMode) {
case PREVIEW:
return TaskExecutionMode.SIMULATED_PRODUCTION;
case DEVELOPMENT_PREVIEW:
return TaskExecutionMode.SIMULATED_DEVELOPMENT;
default:
// dry run, none, bucket analysis - these are treated in a special way (for now)
return PRODUCTION;
}
}

/** Should the effects of this task be persistent or not? The latter means "simulation", "preview", etc. */
public boolean isPersistent() {
return persistent;
Expand All @@ -66,7 +49,7 @@ public boolean isPersistent() {
* - Production usually means `active` and `deprecated` lifecycle states.
* - Development usually means `active` and `proposed` states.
*
* However, in the future we may provide more customization options here (e.g. explicit enumeration of livecycle states
* However, in the future we may provide more customization options here (e.g. explicit enumeration of lifecycle states
* to use, or even a set of specific deltas to apply).
*
* If {@link #persistent} is `true` then {@link #productionConfiguration} should be `true` as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ public enum ObjectTypes {
DASHBOARD(DashboardType.COMPLEX_TYPE, SchemaConstantsGenerated.C_DASHBOARD, DashboardType.class, ObjectManager.MODEL,
"dashboards"),

MESSAGE_TEMPLATE(MessageTemplateType.COMPLEX_TYPE, SchemaConstantsGenerated.C_MESSAGE_TEMPLATE, MessageTemplateType.class, ObjectManager.MODEL,
"messageTemplates"),
MESSAGE_TEMPLATE(
MessageTemplateType.COMPLEX_TYPE, SchemaConstantsGenerated.C_MESSAGE_TEMPLATE, MessageTemplateType.class,
ObjectManager.MODEL, "messageTemplates"),

SIMULATION_RESULT(
SimulationResultType.COMPLEX_TYPE, SchemaConstantsGenerated.C_SIMULATION_RESULT, SimulationResultType.class,
ObjectManager.MODEL, "simulationResults"),

// this should be at end, because otherwise it presents itself as entry for all subtypes of ObjectType
OBJECT(SchemaConstants.C_OBJECT_TYPE, SchemaConstants.C_OBJECT, ObjectType.class, ObjectManager.MODEL, "objects");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->
-->
<!--suppress XmlUnusedNamespaceDeclaration, HttpUrlsUsage -->
<xsd:schema targetNamespace="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:tns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
Expand Down Expand Up @@ -82,7 +83,7 @@
<xsd:annotation>
<xsd:documentation>
<p>
Task (lightweight) identifier. This is an unique identification of any task,
Task (lightweight) identifier. This is a unique identification of any task,
regardless whether it is persistent or transient (cf. OID). Therefore this can be used
to identify all tasks, e.g. for the purposes of auditing and logging.
</p>
Expand Down Expand Up @@ -1748,6 +1749,7 @@
<xsd:annotation>
<xsd:documentation>
Execution mode for this activity: full, preview, dryRun, none, bucketAnalysis.
TODO move this into "execution" item.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand All @@ -1774,6 +1776,17 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="execution" type="tns:ActivityExecutionDefinitionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Detailed definition of the execution.
TODO better name
</xsd:documentation>
<xsd:appinfo>
<a:since>4.7</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="tailoring" type="tns:ActivitiesTailoringType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -2530,20 +2543,6 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="developmentPreview">
<xsd:annotation>
<xsd:documentation>
<p>
As "preview" but development-mode configuration is taken into accounts.

TODO reconsider the name
</p>
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="DEVELOPMENT_PREVIEW"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="dryRun">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -2655,6 +2654,44 @@
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="ActivityExecutionDefinitionType">
<xsd:annotation>
<xsd:documentation>
Detailed definition of the execution.
</xsd:documentation>
<xsd:appinfo>
<a:since>4.7</a:since>
<a:container>true</a:container>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<!-- TODO "mode" will be here. -->
<xsd:element name="productionConfiguration" type="xsd:boolean" minOccurs="0" default="true">
<xsd:annotation>
<xsd:documentation>
What configuration should the actions take into account? Production or "development" one?

- Production usually means `active` and `deprecated` lifecycle states.
- Development will probably `active` and `proposed` states. (Currently: `active`, `proposed` and `deprecated`.)

TEMPORARY. May change in near future.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- TODO parameters for the simulation -->
<xsd:element name="createSimulationResult" type="xsd:boolean" minOccurs="0" default="false">
<xsd:annotation>
<xsd:documentation>
Should we create a simulation result for this activity?

TEMPORARY. May change in near future.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long"/>
</xsd:complexType>

<xsd:complexType name="SchedulerInformationType">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -2845,6 +2882,17 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="simulation" type="tns:ActivitySimulationStateType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
State related to the "simulated" execution of this activity (and its children).
Contains e.g. the OID of the simulation result object after it is created.
</xsd:documentation>
<xsd:appinfo>
<a:since>4.7</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="reports" type="tns:ActivityReportsType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -8764,4 +8812,29 @@
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:complexType name="ActivitySimulationStateType">
<xsd:annotation>
<xsd:documentation>
State related to the "simulated" execution of this activity (and its children).
</xsd:documentation>
<xsd:appinfo>
<a:container>true</a:container>
<a:since>4.7</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="resultRef" type="tns:ObjectReferenceType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Reference to the object into which the results of the simulation should be stored.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:SimulationResultType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long"/>
</xsd:complexType>
</xsd:schema>
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.model.api.simulation;

import java.util.Collection;

import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.AggregatedObjectProcessingListener;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SimulationResultType;

import org.jetbrains.annotations.NotNull;

import java.util.Collection;

public interface SimulationResultContext {

AggregatedObjectProcessingListener aggregatedObjectProcessingListener();
@NotNull AggregatedObjectProcessingListener aggregatedObjectProcessingListener();

/** OID of the {@link SimulationResultType} object that can be used to retrieve the data. */
/** OID of the {@link SimulationResultType} object. */
@NotNull String getResultOid();

/** Reference to the {@link SimulationResultType} object. */
default ObjectReferenceType getResultRef() {
return ObjectTypeUtil.createObjectRef(getResultOid(), ObjectTypes.SIMULATION_RESULT);
}

/** TEMPORARY. Retrieves stored deltas. May be replaced by something more general in the future. */
@NotNull Collection<ObjectDelta<?>> getStoredDeltas(OperationResult result) throws SchemaException;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.model.api.simulation;

import org.jetbrains.annotations.NotNull;
Expand All @@ -8,8 +15,11 @@

public interface SimulationResultManager {

SimulationResultContext newSimulationResult(@Nullable SimulationResultType configuration,
@NotNull OperationResult parentResult);
SimulationResultContext newSimulationResult(
@Nullable SimulationResultType configuration, @NotNull OperationResult parentResult);

/** TODO better name */
SimulationResultContext newSimulationContext(@NotNull String resultOid);

SimulationResultType newConfiguration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public class CleanupWorkDefinition extends AbstractWorkDefinition {

@Override
protected void debugDumpContent(StringBuilder sb, int indent) {
DebugUtil.debugDumpWithLabelLn(sb, "cleanupPolicies", cleanupPolicies, indent + 1);
DebugUtil.debugDumpWithLabel(sb, "cleanupPolicies", cleanupPolicies, indent + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ObjectSetType getObjectSetSpecification() {

@Override
protected void debugDumpContent(StringBuilder sb, int indent) {
DebugUtil.debugDumpWithLabelLn(sb, "objects", objects, indent + 1);
DebugUtil.debugDumpWithLabel(sb, "objects", objects, indent + 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
import java.util.Map;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.repo.common.activity.run.SearchBasedActivityRun;

import com.google.common.base.MoreObjects;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.model.api.ModelPublicConstants;
import com.evolveum.midpoint.model.impl.tasks.simple.SimpleActivityHandler;
import com.evolveum.midpoint.repo.common.activity.run.ActivityRunException;
import com.evolveum.midpoint.repo.common.activity.definition.AbstractWorkDefinition;
import com.evolveum.midpoint.repo.common.activity.definition.ObjectSetSpecificationProvider;
import com.evolveum.midpoint.repo.common.activity.definition.WorkDefinitionFactory;
import com.evolveum.midpoint.repo.common.activity.run.ActivityRunInstantiationContext;
import com.evolveum.midpoint.repo.common.activity.run.ActivityReportingCharacteristics;
import com.evolveum.midpoint.repo.common.activity.run.ActivityRunInstantiationContext;
import com.evolveum.midpoint.repo.common.activity.run.SearchBasedActivityRun;
import com.evolveum.midpoint.repo.common.activity.run.processing.ItemProcessingRequest;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
Expand All @@ -30,7 +28,6 @@
import com.evolveum.midpoint.schema.util.task.work.WorkDefinitionWrapper;
import com.evolveum.midpoint.task.api.RunningTask;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.CommonException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -118,8 +115,7 @@ static final class MyRun extends

@Override
public Collection<SelectorOptions<GetOperationOptions>> customizeSearchOptions(
Collection<SelectorOptions<GetOperationOptions>> configuredOptions, OperationResult result)
throws CommonException {
Collection<SelectorOptions<GetOperationOptions>> configuredOptions, OperationResult result) {
return SelectorOptions.updateRootOptions(configuredOptions, opt -> opt.setAttachDiagData(true), GetOperationOptions::new);
}

Expand All @@ -134,16 +130,15 @@ public void beforeRun(OperationResult result) {
}

@Override
public void afterRun(OperationResult result) throws ActivityRunException, CommonException {
public void afterRun(OperationResult result) {
getActivityHandler().dumpStatistics(
objectStatistics,
getWorkDefinition().histogramColumns);
}

@Override
public boolean processItem(@NotNull ObjectType object,
@NotNull ItemProcessingRequest<ObjectType> request, RunningTask workerTask, OperationResult parentResult)
throws CommonException, ActivityRunException {
@NotNull ItemProcessingRequest<ObjectType> request, RunningTask workerTask, OperationResult parentResult) {
OperationResult result = parentResult.createMinorSubresult(OP_PROCESS_ITEM);
try {
objectStatistics.record(object);
Expand Down Expand Up @@ -196,14 +191,10 @@ public ObjectSetType getObjectSetSpecification() {
return objects;
}

public int getHistogramColumns() {
return histogramColumns;
}

@Override
protected void debugDumpContent(StringBuilder sb, int indent) {
DebugUtil.debugDumpWithLabelLn(sb, "objects", objects, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "histogramColumns", histogramColumns, indent + 1);
DebugUtil.debugDumpWithLabel(sb, "histogramColumns", histogramColumns, indent + 1);
}
}
}

0 comments on commit f94fcb6

Please sign in to comment.