vmware / build-tools-for-vmware-aria

Build Tools for VMware Aria provides development and release management tools for implementing automation solutions based on the VMware Aria Suite and VMware Cloud Director. The solution enables Virtual Infrastructure Administrators and Automation Developers to use standard DevOps practices for managing and deploying content.
Other
45 stars 21 forks source link

Policy definition error #385

Closed unbreakabl3 closed 2 weeks ago

unbreakabl3 commented 1 month ago

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

Server

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

Michaelpalacce commented 1 month ago

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

80aa1d67 is the last working one.

Here is the diff:

image

Good find @unbreakabl3!

Michaelpalacce commented 1 month ago
                    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 commented 1 month ago

@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 commented 3 weeks ago

Notes:

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

https://github.com/vmware/build-tools-for-vmware-aria/pull/245/commits/e169cdf06f4413f208ba072bdb1a9b9fd10ced90#diff-2758ec22240769ca24b53db71e3dc4dc4a7990dabed3bc38bf2ec4456d19f3a1 -> removed v2 policy features ('templateVersion', 'variables', 'elements' from policyTemplate.ts, info from Release.md).

VenelinBakalov commented 3 weeks ago

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

bcpmihail commented 3 weeks ago

@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 commented 3 weeks ago

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

bcpmihail commented 2 weeks ago

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