Problem with decorator in xWork, the page is displayed without tabs and lot of exceptions in the log

I am adding a new tab to Bamboo job configuration, the tab gets displayed correctly but when I am on this tab and I click on the job, the page rendering does not happen correctly (no tabs are visible, just the page content (RobotReport)) and I see a lot of Java exceptions in the log… Moving between the tabs is smooth, no errors. When I am on the existing tabs MetaData, Logs, Artifact, Summary… and I click on the Jobs everything works correclty, only on the newly added tab the functionality is broken.

Below is the content of atlassian-plugin.xml

    <xwork key="KeyXworkViewRobotReport" name="View Robot Report">
        <package name="RobotPlugin" extends="buildResultView" namespace="/build/result">
            <default-interceptor-ref name="defaultStack"/>
            <action name="viewRobotReport" class="isode.robot.RobotReport">
                <result name="success" type="freemarker">/templates/viewRobotReport.ftl</result>
                <result name="error" type="freemarker">/templates/error.ftl</result>
            </action>
        </package>
    </xwork>

    <web-item key="KeyWebItemJobRobotReportTab:${planKey}-${buildNumber}" name="NameWebItemJobRobotReport" section="results.subMenu/results" weight="80">
        <label key="Robot Report"/>
        <link linkId="KeyWebItemJobRobotReportTab:${planKey}-${buildNumber}">/build/result/viewRobotReport.action?planKey=${planKey}&amp;buildNumber=${buildNumber}</link>
        <condition class="isode.robot.RobotReportViewCondition"/>
    </web-item>

===================================================================
content of freemarker template

<html>
<head>
    <title>[@ui.header pageKey='Robot Report and Logs' object='${immutableBuild.name} ${buildResultsSummary.buildNumber}' title=true /]</title>
    <meta name="decorator" content="result"/>
    <meta name="tab" content="NameWebItemJobRobotReport"/>
</head>
<body>
        <iframe src=${HrefRobotLogPath} height="1000" width="1000"></iframe>
</body>
</html>

====================================================================
Note: If I choose the "plan"decorator, I don’t see any Java execptions but the page says
“Apologies, this page could not be properly decorated (data is missing)”

As per the link https://developer.atlassian.com/server/bamboo/xwork-plugin-module/
if the URL maps to /build/result/*.action , “result” decorator should be used so that the necessary decorations (Tabs, Ribbons,…) are provided.
using “result” decorator throws numerous exceptions and using “plan” decorator gives message “Apologies, this page could not be properly decorated (data is missing)”

From the bamboo code it looks like the correct decorator is getting called (result) below is the stack trace.

[INFO] [talledLocalContainer] Java method "com.atlassian.bamboo.ww2.BambooActionSupport.getWebSectionsForLocation(String)" threw an exception when invoked on isode.robot.RobotReport object "isode.robot.RobotReport@3f0a9aac"; see cause exception in the Java stack trace.
[INFO] [talledLocalContainer] 
[INFO] [talledLocalContainer] ----[INFO] [talledLocalContainer] FTL stack trace ("~" means nesting-related):[INFO] [talledLocalContainer]     - Failed at: #list action.getWebSectionsForLocatio...  [in template "lib/menus.ftl" in macro "displayWebItems" at line 563, column 5]
[INFO] [talledLocalContainer]     - Reached through: @menu.displayWebItems plan=immutableP...  [in template "decorators/resultDecorator.ftl" at line 96, column 21]
[INFO] [talledLocalContainer] ----[INFO] [talledLocalContainer] [INFO] [talledLocalContainer] Java stack trace (for programmers):

**File resultDecorator.ftl**
96                 [/#assign] 
97                 [#assign pluginItems]
98                     [@menu.displayWebItems plan=immutablePlan location="jobResult.actions" /]
99                 [/#assign]

**File menus.ftl**
562   [#macro displayWebItems plan location ]
563         [#list action.getWebSectionsForLocation(location) as section ]  **<< This throws exception**
564               [#list action.getWebItemsForSection(location + '/' + section.key) as item]
565                    [#if item.link.id?has_content]

A number of other folks are facing this issue, it was raised sometime back with no resolution, below is the link
Forum Link

Dev Help Ticket
https://ecosystem.atlassian.net/servicedesk/customer/portal/14/DEVHELP-1230

2 Likes

Hi @kshi.korde,

Thanks for posting this in the dev community forum.

Cheers,
Anne Calantog

Hey Anne,

Thanks for involving the Bamboo Dev Team for assisting us on this (seemingly simple) issue.
Looking forward to hear from the team.

Regards,
~Kshi

Hello @kshi.korde,
I tried to reproduce your issue with simplest ftl page

<html>
<head>
    <meta name="decorator" content="result"/>
    <meta name="tab" content="chainNFTResults"/>
</head>
<body>
Hello world
</body>
</html>

It works as expected on any page refresh etc
Looks like problem is with ftl render and it depends on ftl code. If it’s possible please share your ftl. You can create support request if don’t want to share code with community

Hi Alexey,

Thanks for replying, I have shared my ftl code already on this page (above). The only difference that I see is your ftl does not have title tag. I tried removing the title tag from my .ftl file, but I am facing the same problem.

Regards,

Below is the log of the sequence of actions, after clicking on MetaData tab, I click on the Job, things work fine. After clicking on the (Robot Report tab) newly added tab, I get FreeMarker errors and further Java execptions…

[INFO] [talledLocalContainer] 2018-05-15 12:15:25,300 INFO [http-nio-6990-exec-4] [AccessLogFilter] admin GET http://172.20.1.30:6990/bamboo/build/result/viewBuildResultsMetaData.action?buildKey=TPRO1-TPLAN1-JOB1&buildNumber=7 126927kb
[INFO] [talledLocalContainer] Returning True
[INFO] [talledLocalContainer] 2018-05-15 12:15:25,631 INFO [http-nio-6990-exec-3] [AccessLogFilter] admin GET http://172.20.1.30:6990/bamboo/rest/pref/latest/user/?expand=preferences.preference&=1526382925586 77380kb
[INFO] [talledLocalContainer] 2018-05-15 12:15:25,738 INFO [http-nio-6990-exec-8] [AccessLogFilter] admin GET http://172.20.1.30:6990/bamboo/plugins/servlet/dev-toolbar?
=1526382925587 77060kb
[INFO] [talledLocalContainer] 2018-05-15 12:15:25,738 INFO [http-nio-6990-exec-6] [AccessLogFilter] admin GET http://172.20.1.30:6990/bamboo/rest/qr/1.0/batching?=1526382925588 76988kb
[INFO] [talledLocalContainer] 2018-05-15 12:15:25,741 INFO [http-nio-6990-exec-9] [AccessLogFilter] admin GET http://172.20.1.30:6990/bamboo/rest/troubleshooting/1.0/check/admin?
=1526382925590 75622kb
[INFO] [talledLocalContainer] 2018-05-15 12:15:27,092 INFO [17-BAM::Default Agent::Agent:pool-32-thread-1] [BuildAgentControllerImpl] Agent 131073 checking build queue for executables…
[INFO] [talledLocalContainer] 2018-05-15 12:15:29,172 INFO [http-nio-6990-exec-1] [AccessLogFilter] admin GET http://172.20.1.30:6990/bamboo/build/result/viewRobotReport.action?planKey=TPRO1-TPLAN1-JOB1&buildNumber=7&_=1526382925591 73312kb
[INFO] [talledLocalContainer] 2018-05-15 12:15:29,184 WARN [http-nio-6990-exec-1] [TextProviderHelper] The first TextProvider in the ValueStack (isode.robot.RobotReport) could not locate the message resource with key ‘Robot Report and Logs’
[INFO] [talledLocalContainer] 2018-05-15 12:15:29,184 WARN [http-nio-6990-exec-1] [TextProviderHelper] The default value expression ‘Robot Report and Logs’ was evaluated and did not match a property. The literal value ‘Robot Report and Logs’ will be used.
[INFO] [talledLocalContainer] 2018-05-15 12:15:30,505 INFO [http-nio-6990-exec-5] [AccessLogFilter] admin GET http://172.20.1.30:6990/bamboo/build/result/viewRobotReport.action?planKey=TPRO1-TPLAN1-JOB1&buildNumber=7 70585kb
[INFO] [talledLocalContainer] 2018-05-15 12:15:30,532 WARN [http-nio-6990-exec-5] [TextProviderHelper] The first TextProvider in the ValueStack (isode.robot.RobotReport) could not locate the message resource with key ‘Robot Report and Logs’
[INFO] [talledLocalContainer] 2018-05-15 12:15:30,532 WARN [http-nio-6990-exec-5] [TextProviderHelper] The default value expression ‘Robot Report and Logs’ was evaluated and did not match a property. The literal value ‘Robot Report and Logs’ will be used.
[INFO] [talledLocalContainer] 2018-05-15 12:15:30,571 ERROR [http-nio-6990-exec-5] [runtime] Error executing FreeMarker template
[INFO] [talledLocalContainer] FreeMarker template error:
[INFO] [talledLocalContainer] Java method “com.atlassian.bamboo.ww2.BambooActionSupport.hasPlanPermission(String, com.atlassian.bamboo.plan.PlanIdentifier)” threw an exception when invoked on isode.robot.RobotReport object “isode.robot.RobotReport@1d5e0f1”; see cause exception in the Java stack trace.
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer] FTL stack trace ("~" means nesting-related):
[INFO] [talledLocalContainer] - Failed at: #return action.hasPlanPermission(perm… [in template “freemarker-lib/functions.ftl” in function “hasPlanPermission” at line 4, column 5]
[INFO] [talledLocalContainer] - Reached through: @menu.displayPlanSuspendLink immutabl… [in template “decorators/resultDecorator.ftl” at line 71, column 29]
[INFO] [talledLocalContainer] ----
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] Java stack trace (for programmers):

When I click on the job, because of the action tag in xwork (below)
<action name="viewRobotReport" class="isode.robot.RobotReport"> <result name="success" type="freemarker">/templates/viewRobotReport.ftl</result> <result name="error" type="freemarker">/templates/error.ftl</result> </action>
the class isode.robot.RobotReport execution is done and it probably expects the functions “hasPlanPermission” and “getWebItemsForSection” to be executed successfully (which is probably not happening) before rendering the page using the underlying freemarker template.

What version of Bamboo and AMPS do you use for plugin development?

atlas-version

ATLAS Version: 6.3.7
ATLAS Home: /usr/share/atlassian-plugin-sdk-6.3.7
ATLAS Scripts: /usr/share/atlassian-plugin-sdk-6.3.7/bin
ATLAS Maven Home: /usr/share/atlassian-plugin-sdk-6.3.7/apache-maven-3.2.1
AMPS Version: 6.3.14

Bamboo
Atlassian Bamboo version 6.5.0 build 60509 - 20 Apr 18

I suspected that the problem could be with the SDK and uploaded the jar file (atlas-package) on the latest bamboo server (6.5.0) but I could see the exact same problem on the server too.

I don’t see any problems with ftl nor atlassian-plugin.xml, but I would use /build/result/viewRobotReport.action?buildKey=${buildKey} at web-item link declaration.

Something is broken at isode.robot.RobotReport class, because simple class like I’ve shared works without any issues at Bamboo 6.5

I was reading on some atlassian post suggesting the planKey should be used instead of the buildKey. But I will try and see if it works. Could you share the sample code of the class that extends from ViewBuildResults ?
There is no guideline / sample implementation of such a class on the Plugin tutorials. I would be very helpful to have a sample implementation somewhere to have the basic stuff ready.

I think we are missing some initialization in the implementation of RobotReport class that extends ViewBuildresults.
I don’t mind sharing my implementation of the class if you want to take a look at it to find any problem it has just 50 lines. Let me know

I have already taken a look at the below :slight_smile:
https://bitbucket.org/atlassian/bamboo-build-times-plugin/src/031df1939e4d9122d90a40616d5ce664b45effc9/src/main/java/com/atlassian/bamboo/plugin/buildtimes/ViewBuildTimes.java?at=master&fileviewer=file-view-default

public class NFTLogsView extends BuildResultsAction {
    private String HrefRobotLogPath;

    public String getHrefRobotLogPath() {
        return "https://google.com";
    }
}

Please share it. By default you don’t need any special initialisation for this class

It’s PlanResultsAction which shows tab at Plan result level, not job level

Below is my implementation
Some of the bigger function definitions are replaced with (…) here.
I am extending my class from ViewBuildResults as I need functions like getSharedArtifactPath()
for getting the path of the shared artifacts.

@Scanned
public class RobotReport extends ViewBuildResults {

    public RobotReport(@ComponentImport StorageLocationService storageLocationService){
    }   

    public String execute() throws Exception {
        String strBuildList = doExecute();
        return strBuildList;
    }   

    /** The framework would export ${RobotReportSharedArtifactPath} in the FreeMarker Template */
    public String getRobotReportSharedArtifactPath(){
        return getSharedArtifactPath()+"/Robot-Reports/report.html";
    }   

    /** The framework would export ${RobotLogSharedArtifactPath} in the FreeMarker Template */
    public String getRobotLogSharedArtifactPath(){
        return getSharedArtifactPath()+"/Robot-Reports/log.html";
    }   

    /** Returns: TPRO1-TPLAN1-JOB1 */
    public String getRobotPlanKey(){
        ...

    /** Returns: TPRO1-TPLAN1-JOB1-4 */
    public String getRobotPlanResultKey(){
        ...
    }   

    /** Returns: TPRO1-TPLAN1 extracted from TPRO1-TPLAN1-JOB1 */
    public String getPlanId(){
        ...
    }   

    public String getHrefRobotLogPath(){
        ...
    }

    public String getHrefRobotReportPath(){
       ...
    }

}

Hello,
I got the same / a similar issue.

$ atlas-version
ATLAS Version: 6.3.10
ATLAS Home: /usr/share/atlassian-plugin-sdk-6.3.10
ATLAS Scripts: /usr/share/atlassian-plugin-sdk-6.3.10/bin
ATLAS Maven Home: /usr/share/atlassian-plugin-sdk-6.3.10/apache-maven-3.2.1
AMPS Version: 6.3.15

At https://bitbucket.org/MarkusSchulte/devhelp1230, I added a minimal Bamboo-plugin (close to my own one), which has the problem.

Start the project by checking it out, and using “atlas-run”. Create a plan, and run it.

I added tab/panel “A label”, which is added at the plan build result correctly. When I click on the tab, everything is fine. If use the link to the tab http://markus-aspire-vn7-592g:6990/bamboo/build/result/devhelppanel.action?planKey=SOM-SOM&buildNumber=1 directly, the markup is broken.

1 Like

buildKey reports the same problem.

Don’t use doExecute method in RobotReport. As nearest doExecute method implementation is at com.atlassian.bamboo.ww2.BambooActionSupport
Use super.execute() from com.atlassian.bamboo.build.BuildResultsAction as it does some initialisation of buildResults etc

After some debug I can confirm it’s a bug in Bamboo. Some dependencies of Action from plugin are not injected. It works when user clicks tab from UI, but doesn’t work if refresh page.
I’ll create public issue at https://jira.atlassian.com/browse/BAM when gather more details

1 Like

Use workaround while there’s no fix for this issue:
Add these code to any of your class, it might be better to create new one just for this purpose

@ComponentImport
    private BambooPermissionManager bambooPermissionManager;
    @ComponentImport
    private BambooAuthenticationContext bambooAuthenticationContext;
    @ComponentImport
    private JiraApplinksService jiraApplinksService;
    @ComponentImport
    private WebInterfaceManager webInterfaceManager;
    @ComponentImport
    private VcsRepositoryConfigurationService vcsRepositoryConfigurationService;
    @ComponentImport
    private PlanExecutionManager planExecutionManager;
    @ComponentImport
    private TriggerManager triggerManager;
    @ComponentImport
    private PlanManager planManager;

The problem that when Bamboo initialise action from plugin it doesn’t scan for required dependencies so class loader doesn’t see classes which BambooActionSupport class requires to render page menu. Workaround above forces adding of missing dependencies to Spring configuration of plugin.

Workaround works if you use spring-scanner to generate dependencies

2 Likes

Hi @achystoprudov,

Thanks for looking into this and sharing the work around.

Cheers,
Anne Calantog