Skip to content

Commit

Permalink
Moving to store actuators
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdinando Villa committed Nov 16, 2024
1 parent b1a8fbe commit 73786e0
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 933 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ interface Operation extends Closeable {
*/
Activity getActivity();

/**
* Create a child operation using the same transaction and representing a new activity, which will be
* linked as a subordinate to the current one. Pass anything that can affect the child activity, at
* minimum an Activity.Type and a description.
*
* @param activityData
* @return
*/
Operation createChild(Object... activityData);

/**
* Store the passed asset, return its unique long ID.
*
Expand Down Expand Up @@ -89,76 +99,6 @@ void linkToRootNode(RuntimeAsset destination,
DigitalTwin.Relationship relationship,
Object... additionalProperties);


//
// /**
// * Run the operation as configured and return the ID of the last object created or
// modified, or
// * {@link Observation#UNASSIGNED_ID} if the operation failed or was wrongly defined.
// *
// * @return a valid ID or {@link Observation#UNASSIGNED_ID}
// * @deprecated just run each operation and rollback if unsuccessful
// */
// long run(ContextScope scope);
//
// /**
// * Add the passed runtime asset, which must not be part of the graph already.
// * <p>
// * Sets the current link target to the created object.
// *
// * @param observation
// * @return
// * @deprecated use store
// */
// Operation add(RuntimeAsset observation);
//
// /**
// * Sets an existing asset as the target for future links or updates called on the
// operation. If
// * properties are passed that differ from the existing ones, an update is performed at
// * {@link #run(ContextScope)} and the appropriate provenance records are inserted in the
// graph.
// *
// * @param source
// * @return
// * @deprecated shouldn't be necessary, use update on the main KG
// */
// Operation set(RuntimeAsset source, Object... properties);
//
// /**
// * Link the last asset referenced in the call chain to the passed asset, which must exist
// . Use the
// * additional parameters to specify the link, which should include a link type unless
// that can be
// * inferred unambiguously, and can include PODs for properties as needed. Creates an
// outgoing
// * connection from the current asset to the passed one.
// * <p>
// * When returning, the target is still set as before the link call, so that various link
// calls can be
// * chained.
// *
// * @param assetFrom
// * @param assetTo
// * @param linkData
// * @return
// * @deprecated use link above, remove this
// */
// Operation link(RuntimeAsset assetFrom, RuntimeAsset assetTo, DigitalTwin.Relationship
// relationship,
// Object... linkData);
//
// /**
// * Link the passed asset directly to the root object of reference - provenance, context
// or dataflow.
// *
// * @param asset
// * @param linkData
// * @return
// * @deprecated
// */
// Operation rootLink(RuntimeAsset asset, Object... linkData);

/**
* Call after run() when the activity has finished without errors to ensure that all info in the
* knowledge graph is up to date from a successful run.
Expand All @@ -179,40 +119,6 @@ void linkToRootNode(RuntimeAsset destination,
Operation fail(ContextScope scope, Object... assets);
}

// /**
// * Create a new operation to be run on the graph, resulting in assets being created or modified,
// with
// * recording of provenance information. As a result, even an atomic operation may add several
// assets and
// * relationships. Unless the operation is empty, exactly one Activity node is always created at
// run().
// * <p>
// * If no parameters are passed, the first target must be set manually on the returned operation.
// Otherwise
// * the target will be set according to which parameters are passed and their existence in the
// graph. No
// * change is made to the graph until {@link Operation#run(ContextScope)} is called.
// * <p>
// * Obtaining and running an operation (i.e. creating a new Activity in the knowledge graph) will
// also
// * reset the idle time counter to 0 for those scopes whose expiration is IDLE_TIME. Operations
// may be
// * invoked on the scope by the API user, but also triggered by applications, behaviors etc.
// * <p>
// * When the operation has run, call success() or fail() to update the knowledge graph with any
// IDs and
// * states.
// *
// * @param agent the agent that will own the activity created
// * @param scope the specific scope, whose observer and context will determine the links made
// * @param targets any additional parameters. A string will be interpreted as the description of the
// * activity generated. An activity will be interpreted as the parent for the activity
// * generated.
// * @return a graph modification operation description ready for run()
// * @deprecated
// */
// Operation activity(Agent agent, ContextScope scope, Object... targets);

/**
* Create a new operation with a new activity and a transaction, which can be committed or rolled back
* after using it to define the graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ enum Outcome {
*/
long getCredits();

/**
* The activity, if any, that represent a super-activity of this one
*
* @return
*/
Activity getParent();

/**
* Logs each time that the action was executed (in lieu of having an action per each execution). Empty for
* any action that wasn't called by the scheduler. If not empty the first time could be initialization or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class ActivityImpl extends ProvenanceNodeImpl implements Activity {
private String description;
private long id;
private String taskId;
private Activity parent;
private Outcome outcome;
private String stackTrace;

Expand Down Expand Up @@ -89,15 +88,6 @@ public void setId(long id) {
this.id = id;
}

@Override
public Activity getParent() {
return parent;
}

public void setParent(Activity parent) {
this.parent = parent;
}

/**
* Non-API: the ID path through which the activity hierarchy can be reconstructed. When an activity is
* included in a message, the taskId gets in there.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.integratedmodelling.common.runtime;

import org.integratedmodelling.klab.api.collections.Parameters;
import org.integratedmodelling.klab.api.data.KnowledgeGraph;
import org.integratedmodelling.klab.api.geometry.Geometry;
import org.integratedmodelling.klab.api.knowledge.Artifact;
import org.integratedmodelling.klab.api.knowledge.Observable;
Expand Down Expand Up @@ -28,7 +29,8 @@ public class ActuatorImpl implements Actuator {
private Actuator.Type actuatorType;
private long internalId; // ID within the graph, can't be the same as the observation
private double resolvedCoverage;
private Activity activity;

private transient KnowledgeGraph.Operation operation;

@Override
public long getId() {
Expand Down Expand Up @@ -142,16 +144,18 @@ public void setInternalId(long internalId) {
*
* @return
*/
public Activity getActivity() {
return activity;
public KnowledgeGraph.Operation getOperation() {
return operation;
}

public void setActivity(Activity activity) {
this.activity = activity;
public void setOperation(KnowledgeGraph.Operation operation) {
this.operation = operation;
}

@Override
public String toString() {
return "ActuatorImpl{ " + this.id + "}";
}


}
Loading

0 comments on commit 73786e0

Please sign in to comment.