Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,436
Community Members
 
Community Events
184
Community Groups

Is there an easy way to get a report on Bamboo Agent's idle time

Is the below script runner based Bamboo core JAVA API call still the best way to get this report?

 

import com.atlassian.bamboo.resultsummary.AgentResultsSummaryManagerimport com.atlassian.bamboo.resultsummary.BuildResultsSummaryimport com.atlassian.bamboo.util.TextProviderUtilsimport com.atlassian.bamboo.utils.DurationUtilsimport com.atlassian.sal.api.component.ComponentLocatorimport com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegateimport groovy.transform.BaseScript import javax.ws.rs.core.MultivaluedMapimport javax.ws.rs.core.Responseimport java.util.concurrent.TimeUnit @BaseScript CustomEndpointDelegate delegate /** * End point to retrieve Bamboo agent build activity details. * * @return Response wrapping build activity details */ getAgentActivityDetails(httpMethod: "GET", groups: ["bamboo-admin"]) {    MultivaluedMap queryParams, String body ->        RequestParams requestParams = RequestParams.from(queryParams);        AgentActivityDetailsDto agentActivityDetialsDto = doGetAgentActivityDetialsDto(requestParams)        return Response.ok(agentActivityDetialsDto).build()} /** * Implementation for retrieving Bamboo agent's activity details. * * @Param params from request. * @return Agent activity details wrapped in an object. * */def doGetAgentActivityDetialsDto(RequestParams params) {    def AgentActivityDetailsDto agentActivityDetialsDto = new AgentActivityDetailsDto();    def AgentResultsSummaryManager agentManager = ComponentLocator.getComponent(AgentResultsSummaryManager)    List<BuildResultsSummary> allBuildsSummary = agentManager.getAllBuildResultsSummariesForAgent(params.agentId)    def long totalQueueDuration = 0L    def long totalDuration = 0L    def long totalProcessingDuration = 0L    def long reportingDaysMills = TimeUnit.DAYS.toMillis(params.reportingDays)    def long idleMillis = reportingDaysMills - totalProcessingDuration      allBuildsSummary.each {        buildSummary ->            long duration = buildSummary.duration            long queueDuration = buildSummary.queueDuration            long processingDuration = buildSummary.processingDuration            totalQueueDuration += queueDuration            totalProcessingDuration += processingDuration            totalDuration += duration    }     agentActivityDetialsDto.setTotalBuildsCount(allBuildsSummary.size())    agentActivityDetialsDto.setIdleTime(formatMillisToTime(idleMillis))    agentActivityDetialsDto.setTotalProcessingDuration(formatMillisToTime(totalProcessingDuration))    agentActivityDetialsDto.setTotalDuration(formatMillisToTime(totalDuration))    agentActivityDetialsDto.setTotalQueueDuration(formatMillisToTime(totalQueueDuration))     return agentActivityDetialsDto} /** * Formats time in milli second to pretty printing in minutes. * * @Param millis * @return pretty time * */def String formatMillisToTime(long millis) {    double processingDuration = (double) millis;    return processingDuration > 0.0D ? DurationUtils.getPrettyPrint((long) processingDuration) : TextProviderUtils            .getText("global.unknown"); } class AgentActivityDetailsDto {    int totalBuildsCount;    String idleTime;    String totalDuration;    String totalQueueDuration;    String totalProcessingDuration} class RequestParams {    int agentId;    int startPage;    int pageSize;    int reportingDays;     static RequestParams from(MultivaluedMap queryParams) {        RequestParams requestParams = new RequestParams();        requestParams.setAgentId(queryParams.get("agentId"))        requestParams.setReportingDays(queryParams.get("reportingDays"))        requestParams.setStartPage(queryParams.get("startPage"))        requestParams.setPageSize(queryParams.get("pageSize"))        return requestParams    }}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events