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] (#325) Add Workflow canvas Workflow item #334

Merged
merged 17 commits into from
Jul 16, 2024

Conversation

Michaelpalacce
Copy link
Collaborator

Description

New WorkflowItem decorator for Workflows

The new Decorator gives you the ability to specify a canvas item that calls a Workflow.

  • @WorkflowItem({target: "", linkedItem: "" })
    • target - The name of the next in line item.
    • linkedItem - The ID of the workflow to call

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, Out, In, Item, RootItem, DecisionItem, WaitingTimerItem, WorkflowItem } from "vrotsc-annotations";

@Workflow({
	name: "Example Waiting Timer",
	path: "VMware/PSCoE",
	attributes: {
		waitingTimer: {
			type: "Date"
		},
		counter: {
			type: "number"
		},
		first: {
			type: "number"
		},
		second: {
			type: "number"
		},
		result: {
			type: "number"
		}
	}
})
export class HandleNetworkConfigurationBackup {
	@DecisionItem({ target: "waitForEvent", else: "prepareItems" })
	public decisionElement(waitingTimer: Date) {
		return waitingTimer !== null;
	}

	@Item({ target: "callOtherWf" })
	public prepareItems(@In @Out first: number, @In @Out second: number) {
		first = 1;
		second = 2;
	}

	@WorkflowItem({
		target: "print",
		linkedItem: "9e4503db-cbaa-435a-9fad-144409c08df0"
	})
	public callOtherWf(@In first: number, @In second: number, @Out result: number) {
	}

	@Item({ target: "end" })
	public print(@In result: number) {
		System.log("Result: " + result);
	}

	@Item({ target: "decisionElement", exception: "" })
	public execute(@Out @In waitingTimer: Date, @Out @In counter: number): void {
		if (!counter) {
			counter = 0;
		}

		counter++;

		if (counter < 2) {
			const tt = Date.now() + 5 * 1000;
			waitingTimer = new Date(tt);
		} else {
			waitingTimer = null;
		}

		System.log("Counter: " + counter);
		System.log("Waiting Timer: " + waitingTimer);
	}

	@Item({ target: "execute", exception: "" })
	@RootItem()
	public start() {
		System.log("Starting workflow");
	}

	@WaitingTimerItem({ target: "execute" })
	public waitForEvent(@In waitingTimer: Date) {
	}
}
image

You can see in the screenshot that the result is 3 :)

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 synced any structure and/or content vRA-NG improvements with vra-ng and ts-vra-ng archetypes (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

Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
The strategy pattern is not correctly implemented. It holds state and it
should not. I think when I was writing it I got side tracked with the
implementation because of the amount of changes and refactoring that was
required.

Will fix this in another commit

Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
@Michaelpalacce Michaelpalacce requested a review from a team as a code owner July 16, 2024 08:41
@Michaelpalacce Michaelpalacce linked an issue Jul 16, 2024 that may be closed by this pull request
@github-actions github-actions bot added the kind/feature New Feature to the project label Jul 16, 2024
@Michaelpalacce Michaelpalacce 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 labels Jul 16, 2024
@Michaelpalacce Michaelpalacce self-assigned this Jul 16, 2024
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
getDecoratorProps(decoratorNode).forEach((propTuple) => {
const [propName, propValue] = propTuple;
switch (propName) {
case "target":
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a good practice to wrap the cases with braces {}, i.e.

case "target": {
    itemInfo.target = propValue;
    break;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Really? Because I removed it because I thought it wasn't a good practice... I think It was also part of our convention that we don't do this

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not aware of such convention, however I think using braces would improve readability of the code.

@@ -48,7 +45,7 @@ export function buildItemParameterBindings(
parameters.forEach(paramName => {
const param = itemInfo.parent.parameters.find(p => p.name === paramName);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can change the above line to

const param = itemInfo.parent.parameters.find((p: WorkflowParameter) => p.name === paramName);

getScriptProgram: () =>
scriptProgram
|| (
scriptProgram = context.sourceFiles.length
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be a good idea to change the above line to:

 scriptProgram = context.sourceFiles?.length

const itemStrategy = getItemStrategy(decoratorNode, itemInfo);
itemStrategy.registerItemArguments(decoratorNode);
const itemStrategy = getItemStrategy(decoratorNode);
if (itemStrategy.getDecoratorType() !== WorkflowItemType.RootItem) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a side note: I think it would be good to introduce a new WorkflowItemType called EndItem and this end item to be able to be linked for example to a decision item (as an alternative exit).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a todo for later for sure

@bcpmihail bcpmihail self-requested a review July 16, 2024 10:43
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Also some small type improvements
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
@Michaelpalacce Michaelpalacce merged commit aad231c into main Jul 16, 2024
14 checks passed
@VenelinBakalov VenelinBakalov deleted the feature/325-canvas-item-workflow-element branch July 29, 2024 07:17
@VenelinBakalov VenelinBakalov changed the title [vrotsc] (#325) Added a new canvas item for Workflow Items [vrotsc] (#325) Add Workflow canvas Workflow item Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Relates to improvements or additions to documentation 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.

Canvas Item decorator for Workflow Items
3 participants