Skip to content

Commit

Permalink
Add distinction between short and long activity descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-weber committed Jan 9, 2025
1 parent 4045ac5 commit 7c0f4f1
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.NotImplementedException;
import org.polypheny.db.PolyphenyDb;
import org.polypheny.db.adapter.java.AdapterTemplate;
Expand Down Expand Up @@ -58,6 +59,7 @@
import org.polypheny.db.workflow.session.SessionManager;
import org.polypheny.db.workflow.session.WorkflowWebSocket;

@Slf4j
public class WorkflowManager {

private final SessionManager sessionManager;
Expand Down Expand Up @@ -171,6 +173,9 @@ private void addSampleWorkflows() {
fileName = fileName.substring( 0, fileName.length() - ".json".length() );
try {
WorkflowModel workflow = mapper.readValue( file, WorkflowModel.class );
if ( repo.doesNameExist( fileName ) ) {
continue;
}
UUID wId = repo.createWorkflow( fileName );
repo.writeVersion( wId, "Created Sample Workflow", workflow );
} catch ( IOException e ) {
Expand All @@ -181,7 +186,7 @@ private void addSampleWorkflows() {


private void registerAdapter() {
if ( PolyphenyDb.mode == RunMode.TEST || Catalog.getInstance().getAdapters().values().stream().anyMatch( a -> a.adapterName.equals( DEFAULT_CHECKPOINT_ADAPTER ) ) ) {
if ( PolyphenyDb.mode == RunMode.TEST || Catalog.getInstance().getAdapters().values().stream().anyMatch( a -> a.uniqueName.equals( DEFAULT_CHECKPOINT_ADAPTER ) ) ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ public interface Workflow {
ActivityWrapper updateActivity( UUID activityId, @Nullable Map<String, JsonNode> settings, @Nullable ActivityConfigModel config, @Nullable RenderModel rendering, StorageManager sm );

/**
* Returns the number of milliseconds until the execution of the subtree containing the given activities times out.
* Returns the number of seconds until the execution of the subtree containing the given activities times out.
* If there is more than one activitiy in the set, the sum of all timeout durations is returned.
*
* @param activities the activities of the subtree to be executed
* @return the timout duration in millis, or 0 if no timeout is desired.
* @return the timout duration in seconds, or 0 if no timeout is desired.
*/
int getTimeoutMillis( Set<UUID> activities );
int getTimeoutSeconds( Set<UUID> activities );

AttributedDirectedGraph<UUID, ExecutionEdge> toDag();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,11 @@ public ActivityWrapper updateActivity( UUID activityId, @Nullable Map<String, Js


@Override
public int getTimeoutMillis( Set<UUID> activities ) {
int baseTimeout = Math.max( 0, config.getTimeoutMillis() );
public int getTimeoutSeconds( Set<UUID> activities ) {
int baseTimeout = Math.max( 0, config.getTimeoutSeconds() );
int timeout = 0;
for ( UUID activityId : activities ) {
int activityTimeout = Math.max( 0, getActivity( activityId ).getConfig().getTimeoutMillis() );
int activityTimeout = Math.max( 0, getActivity( activityId ).getConfig().getTimeoutSeconds() );
if ( activityTimeout > 0 ) { // override base timeout
timeout += activityTimeout;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package org.polypheny.db.workflow.dag.activities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Value;
import org.polypheny.db.workflow.dag.activities.Activity.ActivityCategory;
import org.polypheny.db.workflow.dag.activities.Activity.PortType;
Expand All @@ -42,7 +45,8 @@ public class ActivityDef {
Class<? extends Activity> activityClass;
String type;
String displayName;
String description;
String shortDescription;
String longDescription;
ActivityCategory[] categories;
InPortDef[] inPorts;
OutPortDef[] outPorts;
Expand All @@ -62,7 +66,8 @@ public static ActivityDef fromAnnotations( Class<? extends Activity> activityCla
activityClass,
def.type(),
def.displayName(),
def.description(),
def.shortDescription(),
def.longDescription().isEmpty() ? def.shortDescription() : def.longDescription(),
def.categories(),
InPortDef.fromAnnotations( def.inPorts() ),
OutPortDef.fromAnnotations( def.outPorts() ),
Expand Down Expand Up @@ -115,6 +120,8 @@ public static class InPortDef {

PortType type;
String description;

@Getter(AccessLevel.NONE)
boolean isOptional;


Expand All @@ -125,6 +132,12 @@ private InPortDef( InPort inPort ) {
}


@JsonProperty("isOptional")
public boolean isOptional() {
return isOptional;
}


public static InPortDef[] fromAnnotations( InPort[] inPorts ) {
return Arrays.stream( inPorts ).map( InPortDef::new ).toArray( InPortDef[]::new );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,39 @@
import org.polypheny.db.workflow.engine.storage.reader.RelReader;

@ActivityDefinition(type = "identity", displayName = "Identity", categories = { ActivityCategory.TRANSFORM, ActivityCategory.RELATIONAL },
inPorts = { @InPort(type = PortType.REL) },
outPorts = { @OutPort(type = PortType.REL) }
)

@IntSetting(key = "I1", displayName = "FIRST", defaultValue = 2)
@StringSetting(key = "S1", displayName = "SECOND")
inPorts = { @InPort(type = PortType.REL, description = "Input table") },
outPorts = { @OutPort(type = PortType.REL, description = "Output table, equal to the input table.") },
shortDescription = "The identity activity outputs the input table unchanged.",
longDescription = """
This is the long description of the identity activity. It is possible to use *markdown*!
# Title
## Subtitle
### Subsubtitle
Now a list:
- first
- second
- third
code: `inline code`
or block:
```python
def my_function():
print('test')
```
> This is a blockquote
""")

@IntSetting(key = "I1", displayName = "FIRST", defaultValue = 2, shortDescription = "This setting doesn't do anything.")
@StringSetting(key = "S1", displayName = "SECOND", shortDescription = "This setting doesn't do anything.")

@Group(key = "groupA", displayName = "Group A",
subgroups = { @Subgroup(key = "a", displayName = "Sub1") }
)
@IntSetting(key = "I2", displayName = "THIRD", defaultValue = 0, isList = true, group = "groupA")
@StringSetting(key = "S2", displayName = "FOURTH", defaultValue = "test", isList = true, group = "groupA", subGroup = "a")
@IntSetting(key = "I2", displayName = "THIRD", defaultValue = 0, isList = true, group = "groupA", shortDescription = "This setting doesn't do anything.")
@StringSetting(key = "S2", displayName = "FOURTH", defaultValue = "test", isList = true, group = "groupA", subGroup = "a", shortDescription = "This setting doesn't do anything.")

@SuppressWarnings("unused")
public class IdentityActivity implements Activity, Fusable, Pipeable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@

String displayName(); // Display name used by the UI

String description() default "";
/**
* A short description of this activity shown as raw text.
*/
String shortDescription() default "";

/**
* A long description of this activity using markdown.
* Image paths are resolved by the UI to "assets/img/plugin/workflows" (subject to change).
* If no longDescription is given, the shortDescription is used instead.
*/
String longDescription() default ""; // given as markdown

ActivityCategory[] categories();

Expand All @@ -45,6 +55,9 @@

PortType type();

/**
* A description given in raw text.
*/
String description() default "";

boolean isOptional() default false; // TODO: isOptional currently has no effect
Expand All @@ -56,6 +69,9 @@

PortType type();

/**
* A description given in raw text.
*/
String description() default "";

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@

String displayName();

String description() default "";
/**
* A short description given in raw text.
*/
String shortDescription() default "";

/**
* A description given in markdown.
*/
String longDescription() default "";

String group() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@

String displayName();

String description() default "";
/**
* A short description given in raw text.
*/
String shortDescription() default "";

/**
* A description given in markdown.
*/
String longDescription() default "";

String group() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@

String displayName();

String description() default "";
/**
* A short description given in raw text.
*/
String shortDescription() default "";

/**
* A description given in markdown.
*/
String longDescription() default "";

String group() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@

String displayName();

String description() default "";
/**
* A short description given in raw text.
*/
String shortDescription() default "";

/**
* A description given in markdown.
*/
String longDescription() default "";

String group() default "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@

String displayName();

String description() default "";
/**
* A short description given in raw text.
*/
String shortDescription() default "";

/**
* A description given in markdown.
*/
String longDescription() default "";

String group() default ""; // the group this setting belongs to. Default is {@code GroupDef.DEFAULT_GROUP}, advanced is {@code GroupDef.ADVANCED_GROUP}. Others must be created manually

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BoolSettingDef extends SettingDef {


public BoolSettingDef( BoolSetting a ) {
super( SettingType.BOOLEAN, a.key(), a.displayName(), a.description(), getDefaultValue( a.defaultValue() ), a.group(), a.subGroup(), a.position(), a.subOf() );
super( SettingType.BOOLEAN, a.key(), a.displayName(), a.shortDescription(), a.longDescription(), getDefaultValue( a.defaultValue() ), a.group(), a.subGroup(), a.position(), a.subOf() );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DoubleSettingDef extends SettingDef {


public DoubleSettingDef( DoubleSetting a ) {
super( SettingType.DOUBLE, a.key(), a.displayName(), a.description(), getDefaultValue( a.defaultValue() ), a.group(), a.subGroup(), a.position(), a.subOf() );
super( SettingType.DOUBLE, a.key(), a.displayName(), a.shortDescription(), a.longDescription(), getDefaultValue( a.defaultValue() ), a.group(), a.subGroup(), a.position(), a.subOf() );
minValue = a.min();
maxValue = a.max();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class EntitySettingDef extends SettingDef {


public EntitySettingDef( EntitySetting a ) {
super( SettingType.ENTITY, a.key(), a.displayName(), a.description(), getDefaultValue( a.defaultNamespace(), a.defaultName() ), a.group(), a.subGroup(), a.position(), a.subOf() );
super( SettingType.ENTITY, a.key(), a.displayName(), a.shortDescription(), a.longDescription(), getDefaultValue( a.defaultNamespace(), a.defaultName() ), a.group(), a.subGroup(), a.position(), a.subOf() );
this.dataModel = a.dataModel();
this.mustExist = a.mustExist();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class IntSettingDef extends SettingDef {


public IntSettingDef( IntSetting a ) {
super( SettingType.INT, a.key(), a.displayName(), a.description(), getDefaultValue( a.defaultValue(), a.isList() ), a.group(), a.subGroup(), a.position(), a.subOf() );
super( SettingType.INT, a.key(), a.displayName(), a.shortDescription(), a.longDescription(), getDefaultValue( a.defaultValue(), a.isList() ), a.group(), a.subGroup(), a.position(), a.subOf() );
this.isList = a.isList();
this.minValue = a.min();
this.maxValue = a.max();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public abstract class SettingDef {
private final SettingType type;
private final String key;
private final String displayName;
private final String description;
private final String shortDescription;
private final String longDescription;

@JsonIgnore // the UI does not handle defaultValues. This is instead done by the backend, at the moment the activity is created.
private final SettingValue defaultValue;
Expand All @@ -59,12 +60,13 @@ public abstract class SettingDef {
private final String subOf;


public SettingDef( SettingType type, String key, String displayName, String description, SettingValue defaultValue, String group, String subgroup, int position, String subOf ) {
public SettingDef( SettingType type, String key, String displayName, String shortDescription, String longDescription, SettingValue defaultValue, String group, String subgroup, int position, String subOf ) {
assert !key.contains( SettingDef.SUB_SEP ) : "Setting key must not contain separator symbol '" + SUB_SEP + "': " + key;
this.type = type;
this.key = key;
this.displayName = displayName;
this.description = description;
this.shortDescription = shortDescription;
this.longDescription = longDescription.isEmpty() ? shortDescription : longDescription;
this.defaultValue = defaultValue;
this.group = group;
this.subgroup = subgroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class StringSettingDef extends SettingDef {


public StringSettingDef( StringSetting a ) {
super( SettingType.STRING, a.key(), a.displayName(), a.description(), getDefaultValue( a.defaultValue(), a.isList() ), a.group(), a.subGroup(), a.position(), a.subOf() );
super( SettingType.STRING, a.key(), a.displayName(), a.shortDescription(), a.longDescription(), getDefaultValue( a.defaultValue(), a.isList() ), a.group(), a.subGroup(), a.position(), a.subOf() );
this.isList = a.isList();
this.minLength = a.minLength();
this.maxLength = a.maxLength();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ExecutionSubmission {
UUID rootId;
CommonType commonType;
UUID sessionId;
int timeoutMillis; // 0 for no timeout
int timeoutSeconds; // 0 for no timeout
ExecutionInfo info;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ private void submit( List<ExecutionSubmission> submissions ) {

activeSubmissions.computeIfAbsent( sessionId, k -> ConcurrentHashMap.newKeySet() ).add( submission );

int timeoutMillis = submission.getTimeoutMillis();
if ( timeoutMillis > 0 ) {
int timeoutSeconds = submission.getTimeoutSeconds();
if ( timeoutSeconds > 0 ) {
timeoutService.schedule( () -> {
if ( submission.getInfo().getState() == ExecutionState.EXECUTING ) {
submission.getExecutor().interrupt();
}
}, Math.max( 50, timeoutMillis ), TimeUnit.MILLISECONDS ); // minimum timeout to ensure executor was actually called
}, timeoutSeconds, TimeUnit.SECONDS );
}

ExecutionResult result;
Expand Down
Loading

0 comments on commit 7c0f4f1

Please sign in to comment.