Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vrotsc, vrotsc-annotations] (#339) Add Workflow canvas Default Error Handler item #346

Merged
merged 7 commits into from
Jul 22, 2024

Conversation

akantchev
Copy link
Contributor

@akantchev akantchev commented Jul 18, 2024

*New DefaultErrorHandler decorator for Workflows

This decorator is used to specify a default error handler. It can be bound either to a workflow item component or workflow end.

Supported Parameters

  • target - target item to be attached to the default error handler, could be one of workflow item or workflow end.
  • exceptionVariable - Exception variable that will hold the exception data when triggered.

In order to bind inputs and outputs, you do it with the @In and @Out decorators. This is the same way we do it for other items.

Example:

import { Workflow, RootItem, In, Out, Item, DefaultErrorHandler, WorkflowEndItem } from "vrotsc-annotations";

@Workflow({
	name: "Default Error Handler Custom Item",
	path: "VMware/PSCoE",
	description: "Default error handler workflow with error handler redirecting to a workflow item",
	attributes: {
		errorMessage: {
			type: "string"
		}
	}
})
export class HandleDefaultError {

	@RootItem()
	public initiateWorkflow() {
		System.log("Initiating workflow execution");
	}

	@Item({
		target: "workflowEnd"
	})
	public processError(@In errorMessage: string) {
		System.log(`Processing error using custom task with message '${errorMessage}'`);
	}

	@DefaultErrorHandler({
		exceptionVariable: "errorMessage",
		target: "processError"
	})
	public defaultErrorHandler(@Out errorMessage: string) {
		// NOOP
	}

	@WorkflowEndItem({
		endMode: 0,
		exceptionVariable: "errorMessage",
	})
	public workflowEnd(@Out errorMessage: string) {
		System.log(`Terminating workflow with error ${errorMessage}`);
	}
}

vrotsc_error_handler_component

Checklist

  • I have added relevant error handling and logging messages to help troubleshooting
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation, relevant usage information (if applicable)
  • I have updated the PR title with affected component, related issue number and a short summary of the changes introduced
  • I have added labels for implementation kind (kind/) and version type (version/)
  • I have tested against live environment, if applicable
  • I have my changes rebased and squashed to the minimal number of relevant commits. Notice: don't squash all commits
  • I have added a descriptive commit message with a short title, including a Fixed #XXX - or Closed #XXX - prefix to auto-close the issue

Testing

Added e2e tests to the PR and also tested on an actual environment. Testing process on live environment:

  1. Create project of archetype typescript-project-all.
  2. Add a typescript representation of a workflow as shown in the example above.
  3. Push project to a live environment with vRO.

Test Screenshot

vrotsc_error_handler_component

Release Notes

*New DefaultErrorHandler decorator for Workflows

This decorator is used to specify a default error handler. Note that the default error handler will be generated
with its own end workflow item as it is required by the component.

Supported Parameters
  • target - Not implemented yet
  • exception - if set the variable will be bound to the error handler and its own end workflow component.
    If set the end workflow component bound to the error handler will have exit code 1, otherwise the exit code will be 0.

Related issues and PRs

Implementation of #339

@akantchev akantchev added area/documentation Relates to improvements or additions to documentation area/vrotsc Relates to `vrotsc` module version/minor Introduces a non-breaking feature or change kind/feature New Feature to the project labels Jul 18, 2024
@akantchev akantchev self-assigned this Jul 18, 2024
@akantchev akantchev requested a review from a team as a code owner July 18, 2024 08:45
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Signed-off-by: Alexander Kantchev <[email protected]>
@akantchev akantchev changed the title [vrotsc] (#340) Added a new canvas item for Default Error Handler [vrotsc] (#339) Added a new canvas item for Default Error Handler Jul 18, 2024
@vmware vmware deleted a comment from vmwclabot Jul 18, 2024
@vmware vmware deleted a comment from vmwclabot Jul 18, 2024
@vmware vmware deleted a comment from vmwclabot Jul 18, 2024
@akantchev akantchev removed the area/documentation Relates to improvements or additions to documentation label Jul 18, 2024
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Signed-off-by: Alexander Kantchev <[email protected]>
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Copy link
Collaborator

@Michaelpalacce Michaelpalacce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non relevant

// NOOP
}

@DefaultErrorHandler({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't modify old tests like this, rather add new ones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this one serves as an integration test for all currently supported workflow items, hence it should be here, Furthermore there are other tests for this specific functionality as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't 😄 the example was just too big perhaps, but it was meant mainly for Workflow

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, comment not applicable anymore.

<?xml version="1.0" encoding="utf-8" ?><workflow xmlns="http://vmware.com/vco/workflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://vmware.com/vco/workflow http://vmware.com/vco/workflow/Workflow-v4.xsd" root-name="item1" object-name="workflow:name=generic" id="983d90ae-55f4-3618-b049-264e66324e74" version="1.0.0" api-version="6.0.0" restartMode="1" resumeFromFailedMode="0"><display-name><![CDATA[Waiting Timer Edge]]></display-name><description><![CDATA[Waiting timer will point to end with target]]></description><position x="105" y="45.90909090909091" /><attrib name="waitingTimer" type="Date" read-only="false" /><attrib name="counter" type="number" read-only="false" /><workflow-item name="item0" type="end" end-mode="0"><position x="585.0" y="45.40909090909091" /></workflow-item><workflow-item name="item1" out-name="item0" type="waiting-timer"><display-name><![CDATA[waitForEvent]]></display-name><in-binding><bind name="timer.date" type="Date" export-name="waitingTimer" /></in-binding><position x="225.0" y="55.40909090909091" /></workflow-item><workflow-item name="item2" out-name="item0" type="task"><script encoded="false"><![CDATA[]]></script><display-name><![CDATA[shouldNotGoHere]]></display-name><position x="385.0" y="55.40909090909091" /></workflow-item><presentation><p-param name="waitingTimer"><desc><![CDATA[waitingTimer]]></desc></p-param></presentation></workflow>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there changes here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to changes in the typescript representations of the workflows.

typescript/vrotsc/src/compiler/decorators.ts Show resolved Hide resolved
@@ -58,6 +58,7 @@ export interface WorkflowItemDescriptor<T = any> {
canvasItemPolymorphicBag: T;
polyglot?: PolyglotDescriptor;
parent: WorkflowDescriptor;
type?: WorkflowItemType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should get this from the assigned strategy. You can do descriptor.strategy.getDecoratorType()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Property removed.

import { buildItemParameterBindings, InputOutputBindings } from "./helpers/presentation";

// UI positioning constants in the output XML file.
const xBasePosition = 180;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a task for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent

const exceptionVariable = itemInfo?.canvasItemPolymorphicBag?.exception;
const hasException = (exceptionVariable !== null && exceptionVariable !== undefined && exceptionVariable);

stringBuilder.append(`<error-handler name="item${pos}" `);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more readable, maybe sth like:

		stringBuilder.append(`<error-handler`
			+ ` name="item${pos}" `
			+ ` ${hasException ? `throw-bind-name="${exceptionVariable}" ` : ""}`
			+ `>`).appendLine();

as we do with others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually your proposal is less readable.

stringBuilder.append("</error-handler>").appendLine();

// attach a default end item to the error handler, note that the name of the end item and the error handler should be the same
const defaultEndItem = this.buildDefaultEndItem(itemInfo, pos, exceptionVariable);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really make sense, the whole idea is that they can attach to an end item or another task to handle the error in some way

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, this can easily point to the default end item that was created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it does, it should have a default end item, attached to the error handler.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't answer the first question. users can point to a task or sth else, how do we handle that?

Where is the requirement to have a default end item?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, comment not applicable anymore.

@@ -127,6 +127,8 @@ type CompositeType = {

type AttributeValue = CompositeType | SupportedValues | SupportedValues[];

type WorkflowEndMode = 0 | 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

@@ -253,7 +266,11 @@ interface VroPolyglotDecorator {
new(obj?: VroPolyglotConfiguration): VroPolyglotConfiguration;
}

interface VroPolyglotConfiguration { package: string, method: string; }
interface VroPolyglotConfiguration {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, reverting is not needed.


interface VroWorkflowDefaultErrorHandlerDecorator {
(obj?: VroItemConfiguration): VroWorkflowDefaultErrorHandlerMethodDecorator;
new(obj?: VroItemConfiguration): VroItemConfiguration;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each item should have their own definition so they are easy to change and don't bring confusion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not make sense to have own definition in this case, as it does not bring new properties.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So each other type have their own Config Type, but specifically the DefaultErrorhanlder will point to the Item one? Isn't it more clear for the user if it has it's own?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline, decided that the whole interface will be reworked using inheritance once all needed workflow components are implemented (will be done in a separate PR).

itemInfo.target = propValue;
break;
}
case "exception": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception will mean sth else in other items... can we rename this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotation variable name changed.

@akantchev akantchev changed the title [vrotsc] (#339) Added a new canvas item for Default Error Handler [vrotsc, vrotsc-annotations] (#339) Added a new canvas item for Default Error Handler Jul 22, 2024
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Signed-off-by: Alexander Kantchev <[email protected]>
Signed-off-by: Alexander Kantchev <[email protected]>
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link
Member

@akantchev, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@akantchev akantchev merged commit 2c96994 into main Jul 22, 2024
14 checks passed
@VenelinBakalov VenelinBakalov deleted the feature/340-canvas-item-default-error-handler branch July 29, 2024 09:16
@VenelinBakalov VenelinBakalov changed the title [vrotsc, vrotsc-annotations] (#339) Added a new canvas item for Default Error Handler [vrotsc, vrotsc-annotations] (#339) Add Workflow canvas Default Error Handler item Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/vrotsc Relates to `vrotsc` module kind/feature New Feature to the project version/minor Introduces a non-breaking feature or change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants