It's all about the answers!

Ask a question

API call to get RTC engine build activity


SUNIL KUURAM (6431923) | asked Mar 26 '13, 9:38 a.m.
edited Mar 27 '13, 1:35 p.m. by Spencer Murata (2.3k115971)
Hello,

I was trying to get the number of builds in progress on RTC engine. The API call IBuildEngineActivityHandle.size() returns 69 for all engines. Please let me know if you saw this problem before. Here's my code snippet.

            teamRepository = TeamPlatform.getTeamRepositoryService()
                    .getTeamRepository(REPOSITORY_ADDRESS);
            teamRepository.registerLoginHandler(new LoginHandler(userId,
                    password));
            teamRepository.login(monitor);
           
            ITeamBuildClient buildClient = (ITeamBuildClient) teamRepository.getClientLibrary(ITeamBuildClient.class);
            IItemManager itemManager = teamRepository.itemManager();



IBuildEngine buildEngine=buildClient.getBuildEngine("RationalBuildforgeConnector", monitor);
       IBuildEngineActivityHandle ib=buildEngine.getBuildEngineActivity();
        System.out.println(ib.size());



Thanks
Sunil

5 answers



permanent link
Spencer Murata (2.3k115971) | answered Mar 27 '13, 1:37 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
 The build activities are all activities in all builds running on the engine.  So if you want builds running you want to gather the BuildResult and only those whose state is IN_PROGRESS.

~Spencer

permanent link
SUNIL KUURAM (6431923) | answered Mar 27 '13, 3:00 p.m.
Hi Spencer,

Sorry, If I not being clear. I am looking to list active builds on the engine (right click engine - select Show Build Activity) via API call. Could you give some pointers?

Thanks
Sunil

permanent link
Nick Edgar (6.5k711) | answered Apr 13 '13, 2:01 p.m.
JAZZ DEVELOPER
An IBuildEngineActivity item maintain the last contact time for an engine.  As with any other item, it's referenced by an item handle, in this case an IBuildEngineActivityItemHandle.  IItemHandle defines size(), but that's misleading -- it gives an estimate of the number of bytes taken by the handle's representation.

To get the list of active (i.e. in-progress) builds for a given build engine, you'd need to run an item query.
There's an internal query service method for builds that the Eclipse UI uses.  For example,
com.ibm.team.build.internal.ui.query.BuildQueryByEngine.getBuildQueryCriteria(IProgressMonitor)
returns:

  IBuildResultSearchCriteria.BUILDER.forEngine(fBuildEngineHandle)

where fBuildEngineHandle is an IBuildEngineHandle.
The criteria object is then passed to the query service method in:
  com.ibm.team.build.internal.ui.query.BuildQuery.doIterativeQuery(boolean, IProgressMonitor)
which does:

getRecordClient().getBuildResultRecords(buildQueryCriteria, buildResultProperties, monitor)

where getRecordClient() is:

fTeamRepository.getClientLibrary(ITeamBuildRecordClient.class);


The criteria object also lets you filter by build state:

com.ibm.team.build.internal.common.model.dto.IBuildResultSearchCriteria.inState(BuildState...)


Another option is to call:
  com.ibm.team.build.internal.client.ITeamBuildRecordClient.getBuildEngineStatusRecord(IBuildEngineHandle, IProgressMonitor)
where the resulting record lists the in-progress builds:
  com.ibm.team.build.internal.common.model.dto.IBuildEngineStatusRecord.getInProgressBuilds()
but this is also internal.

It's also possible to construct your own item query.  Although IBuildResultQueryModel lets you query for builds in a given state, the query model that's exposed as API does not let you filter by handling build engine (which is on the build's IBuildRequest item, not the IBuildResult).  Unfortunately, I don't see any way to do this with our current API.  Please feel free to open an enhancement request for this.




permanent link
Alan Jamison (1) | answered May 16 '14, 6:29 p.m.
Hi,

   Your suggestion above works very well to get IInProgressBuilds[] on a build engine.  With each IInProgressBuild record I can get the status.name(), the label(), and currentBuildActivityLabel().

    How do I get the StartTime and Duration of the build-in-progress (as also shows in Eclipse)?  Which objects do I need to traverse?  Do I somehow use the buildResult and then the fullState iItem?

    Thanks you for any tips.  I have looked very hard, but can not find a definitive answer to this.

    Al...

Comments
sam detweiler commented May 16 '14, 8:24 p.m.

everything is in the build result

long getBuildStartTime()
Get the time the build was started.
long getBuildTimeTaken()
Get the time taken by the build.


permanent link
Alan Jamison (1) | answered May 17 '14, 11:09 p.m.
Excellent, thank you very much. 
I knew I was close, but I needed to correctly fetch the IBuildResult object.  This link helped bridge that gap: Fetch the data from the IBuildResultHandle

    public IBuildResult getBuildResult(IBuildResultHandle iBRH) throws TeamRepositoryException
    {
        IItemManager itemManager = teamRepository.itemManager();
        IBuildResult buildResultData = null;
     
        try{
            buildResultData = (IBuildResult)itemManager.fetchCompleteItem(iBRH, IItemManager.REFRESH, myPM);
        } catch(ItemNotFoundException infx) {
            logger.warn("RtcRepository.getBuildResult(), ItemNotFoundException, "+infx.getMessage());
        }
        return buildResultData;
    }

   And once done, your tip was perfect.  Since I am reading the running RTC build queue, the active jobs go away from the time I query the queue and the time I go to fetch the build data - so I catch the missing Item case.  And because I am looking at the active running builds, I guess I can't expect to have a BuildTimeTaken value.  I get zero for that call, and presumably would until the build completes?

   Thanks very much for your patience and information!

    Al...

Comments
sam detweiler commented May 18 '14, 6:35 a.m.

yes, if you have the handle to an object, you have to load the rest of the data. you can load everything ( .fetchCompleteItem) or only selected fields (.fetchItem)

time spent is not complete til the build ends,.. yes, but you can calculate it.
now- getBuildStartTime() .

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.