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

Policy definition error #385

Closed
unbreakabl3 opened this issue Aug 12, 2024 · 8 comments · Fixed by #390
Closed

Policy definition error #385

unbreakabl3 opened this issue Aug 12, 2024 · 8 comments · Fixed by #390
Assignees
Labels
area/vrotsc Relates to `vrotsc` module effort/low kind/bug Something isn't working priority/medium triage/accepted The issue was accepted and will be done version/minor Introduces a non-breaking feature or change

Comments

@unbreakabl3
Copy link
Contributor

Description

After a new vRO TS project is created, the building step is failing ,because of the sample.pl.ts file. If I do remove the variables and elements sections, the build is complete without issues.


Working

import { PolicyTemplate } from "vrotsc-annotations";

@PolicyTemplate({
    name: "Sample Policy",
    path: "MyOrg/MyProject",
})
export class SamplePolicy {
    onMessage(self: AMQPSubscription, event: any) {
        let message = self.retrieveMessage(event);
        System.log(`Received message ${message.bodyAsText}`);
    }
}

If I do add templateVersion: "v1" (which is optional and supposed to work in any case), the error Error: PolicyTemplate attribute 'templateVersion' is not supported. is appears.


Not working

import { PolicyTemplate } from "vrotsc-annotations";

@PolicyTemplate({
    name: "Sample Policy",
    path: "MyOrg/MyProject",
    templateVersion: "v1", // or v1
})
export class SamplePolicy {
    onMessage(self: AMQPSubscription, event: any) {
        let message = self.retrieveMessage(event);
        System.log(`Received message ${message.bodyAsText}`);
    }
}

It is looks like that anything, which is coming after the path causing that error.

Steps to Reproduce

  1. Create a new vRO TS project
  2. Run mvn install

Preconditions: [What are the preconditions to reproduce the issue]

Expected behavior: [What you expect to happen]

The build will complete successfully

Actual behavior: [What actually happens]

The build is failing

Reproduces how often: [What percentage of the time does it reproduce]

All the time
Component/s: [What are the Build Tools for VMware Aria components affected by the issue (e.g. "common/artifact-manager", "maven/plugins/vra-ng", "typescript/vrotest", etc)]

TS Types

Affects Build/s: [Which are the Build Tools for VMware Aria releases / builds affected by the issue]

2.40 and 2.41

Environment

Client

  • Build Tools for VMware Aria Version: 2.41
  • Visual Studio Code Version: 1.92.1
  • OS Version: MacOS

Server

  • vRealize Automation Version: 8.16
  • vRealize Orchestrator Version: 8.16
  • vRealize Operations Version:
  • vRealize Log Insight Version:

Failure Logs

[INFO] --- vro:2.41.0:compile (default-compile) @ policy_management ---
[INFO] Files changed on Git Version. Total files to be compiled: ALL
[INFO] Typescript transpilation started
[ERROR] /Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:207600
[ERROR]                         throw new Error("PolicyTemplate attribute '".concat(propName, "' is not supported."));
[ERROR]                         ^
[ERROR] 
[ERROR] Error: PolicyTemplate attribute 'variables' is not supported.
[ERROR]     at /Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:207600:31
[ERROR]     at Array.forEach (<anonymous>)
[ERROR]     at populatePolicyTemplateInfoFromDecorator (/Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:207559:39)
[ERROR]     at /Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:207469:17
[ERROR]     at Array.forEach (<anonymous>)
[ERROR]     at registerPolicyTemplateClass (/Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:207468:16)
[ERROR]     at /Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:207400:9
[ERROR]     at Array.forEach (<anonymous>)
[ERROR]     at Object.getPolicyTemplateTransformer (/Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:207399:110)
[ERROR]     at /Users/user/Github_Repos/policy_management/node_modules/@vmware-pscoe/vrotsc/lib/vrotsc.js:212201:76
[ERROR] 
[ERROR] Node.js v20.16.0
[INFO] Typescript transpilation finished

Related issues and PRs

Additional Context

@VenelinBakalov VenelinBakalov added triage/accepted The issue was accepted and will be done priority/medium effort/low kind/bug Something isn't working area/vrotsc Relates to `vrotsc` module version/minor Introduces a non-breaking feature or change labels Aug 12, 2024
@Michaelpalacce
Copy link
Collaborator

Michaelpalacce commented Aug 12, 2024

This is definitely a bug, @VenelinBakalov I'd change to effort/high, this is an issue with vrotsc and that's always tricky.

After a git bisect, I found that the breaking commit seems to be: e169cdf0

80aa1d6 is the last working one.

Here is the diff:
image

Good find @unbreakabl3!

@Michaelpalacce
Copy link
Collaborator

Michaelpalacce commented Aug 12, 2024

					case "templateVersion":
						policyTemplateInfo.templateVersion = (<ts.StringLiteral>(property.initializer)).text;
						break;
					case "variables":
						buildPolicyVariables(policyTemplateInfo, <ts.ObjectLiteralExpression>property.initializer);
						break;
					case "elements":
						buildPolicyElements(policyTemplateInfo, <ts.ObjectLiteralExpression>property.initializer);
						break;

needs to be added back, pinging @bcpmihail maybe you can help out here?

@VenelinBakalov
Copy link
Collaborator

@Michaelpalacce oks, I will wait for further feedback before updating the labels to see if it doesn't turn out to be something small

@bcpmihail bcpmihail self-assigned this Aug 16, 2024
@bcpmihail
Copy link
Contributor

Notes:

Full support of Policy (PR: #202 , samples PR: vmware-samples/build-tools-for-vmware-aria-samples#1 ) -> adds variables and samples; agreed to do versioning

e169cdf#diff-2758ec22240769ca24b53db71e3dc4dc4a7990dabed3bc38bf2ec4456d19f3a1 -> removed v2 policy features ('templateVersion', 'variables', 'elements' from policyTemplate.ts, info from Release.md).

@VenelinBakalov
Copy link
Collaborator

@bcpmihail I see that vmware-samples/build-tools-for-vmware-aria-samples#1 is old and approved, should I merge it or it will fail now because of the current bug?

@bcpmihail
Copy link
Contributor

bcpmihail commented Aug 22, 2024

@VenelinBakalov it will fail because of the current bug - support for v2 attributes (elements, variables and templateVersion) needed to be reintroduced in https://github.com/vmware/build-tools-for-vmware-aria/pull/390/files#diff-94ef6e165c573f7516349e7530e4a466f874cee3d034b5075094dbd1d3011ec9:~:text=case%20%22templateVersion%22,elements%22%3A%20%7B (policyTemplate.ts l.275-286)

@VenelinBakalov
Copy link
Collaborator

I see, then I guess we can merge it after we close the current PR and do a release

@bcpmihail
Copy link
Contributor

bcpmihail commented Aug 23, 2024

As discussed with @Michaelpalacce , @VenelinBakalov , @joroaf :

  • 'v1' will remain the default Policy Template version ('templateVersion' attribute), unless specified otherwise.
  • the Policy template attributes will be validated, throwing an error when 'variables' or 'elements' are present for 'v1' (including when set by default) OR when 'type' is present for 'v2'.
  • the samples in BTVA will be updated to 'v2'
  • an issue will be opened for the next Major version milestone to make the 'templateVersion' attribute mandatory and update the sample Policy Template in https://github.com/vmware-samples/build-tools-for-vmware-aria-samples (will require major version release of the samples as well, as it won't be buildable with older BTVA versions like the base-package version 2.31.1 currently used there): Make Policy Template version mandatory #393

bcpmihail added a commit that referenced this issue Aug 28, 2024
[vrotsc] (#385) Fix TS-vRA archetype sample policy definition and re-add v2 policy attributes
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 effort/low kind/bug Something isn't working priority/medium triage/accepted The issue was accepted and will be done version/minor Introduces a non-breaking feature or change
Projects
None yet
4 participants