Re: Help need to batch delete runs from 2+ years ago (989 Views)
Reply
Occasional Contributor
Posts: 11
Registered: ‎03-31-2011
Message 1 of 10 (1,668 Views)
Accepted Solution

Help need to batch delete runs from 2+ years ago

Am trying to programatically purge RUNs from 2+ years ago.   I keep running into walls and the closest I've gotten is show below however it gives me the error "Can not delete run from global RunFactory":

 

Anybody have a working sample as the API docs are less than helpful :-(

 

                Set oRunFactory = oConn.RunFactory
                Set oRuns = oRunFactory.NewList("")
                
                iRuns = oRuns.Count
                For x = 1 To iRuns
                        Set oRun = oRuns.Item(x)
                        If oRun.Field("RN_EXECUTION_DATE") <= #9/10/2009# Then
                           '' Set oTSTests = oTSTestFactory.NewList(oRun.TestInstanceID)
                           '' If oTSTests.Count = 1 Then
                           ''     Set oTSTest = oTSTests.Item(1)
                           ''         Debug.Print oTSTest.Name
                           ''    Set oTSTest = Nothing
                           '' End If
                            iKey = oRun.id
                            If iKey = 2309 Then
                                oRunFactory.RemoveItem iKey        '' gets the error above....
                            End If
                        End If
                       
 

Esteemed Contributor
Posts: 342
Registered: ‎04-02-2008
Message 2 of 10 (1,664 Views)

Re: Help need to batch delete runs from 2+ years ago

Why don't you just use the Purge Runs function in the TestLab module? You can select all test sets and a date range of "Runs older than 2 years".
Occasional Contributor
Posts: 11
Registered: ‎03-31-2011
Message 3 of 10 (1,659 Views)

Re: Help need to batch delete runs from 2+ years ago

Our group supports over 100+ projects within our organization.  With that many we  need to be able to do a number of housekeeping tasks via a batch projcess.....

Esteemed Contributor
Posts: 342
Registered: ‎04-02-2008
Message 4 of 10 (1,657 Views)

Re: Help need to batch delete runs from 2+ years ago

Look at the API ref for the PurgeRuns method of the TD connection object. It has a filter for date. You would then just need to iterate through all of your projects' TDConnections and call that method.
Occasional Contributor
Posts: 11
Registered: ‎03-31-2011
Message 5 of 10 (1,649 Views)

Re: Help need to batch delete runs from 2+ years ago

[ Edited ]

William - THANKS for the lead as I didn't even think about it being at the Connection level... (kinda counterintuitive)...

 

Here is a sample of the code to delete runs (excluding the last) from the prior 2 years....

 

 

                iKeep = 1                   ' keep last run ONLY
                iUnit = 4                   ' year
                iUnitCount = 2              ' 2 years
               
                dCutoff = DateAdd("yyyy", (-1 * iUnitCount), Date)
               
                Set oTSTestFactory = oConn.TSTestFactory
                Set oRunFactory = oConn.RunFactory
                Set oRuns = oRunFactory.NewList("")
                iRuns = oRuns.Count
                For x = 1 To iRuns
                        Set oRun = oRuns.Item(x)
                        If oRun.Field("RN_EXECUTION_DATE") <= dCutoff Then

                            '' if you wish to write the list of runs to a file insert the code here 

                            ''Debug.Print oRun.Name, oRun.id, oRun.TestInstanceID, oRun.TestInstance

                            ''Debug.print  oRun.Field("RN_EXECUTION_DATE")
                            iRetire = iRetire + 1
                        End If
                        Set oRun = Nothing
                Next
                Set oTSTestFactory = Nothing
                If iRetire > 0 Then
                  Debug.Print "Purging " & CStr(iRetire) & " runs before " & CStr(dCutoff) & " from " & oConn.DomainName & ":" & oConn.ProjectName
                    oConn.PurgeRuns "", iKeep, iUnit, iUnitCount, False
                Else
                    Debug.Print "No runs to purge since " & CStr(dCutoff)
                End If

                Set oRuns = Nothing
                Set oRunFactory = Nothing
            Else
                Debug.Print "Cannot connect to " & sDomain & " : " & sProject
            End If
            oConn.DisconnectProject
            oConn.ReleaseConnection

Esteemed Contributor
Posts: 342
Registered: ‎04-02-2008
Message 6 of 10 (1,587 Views)

Re: Help need to batch delete runs from 2+ years ago

I am also in need of a method to purge old test runs.  I tried both the built-in Purge function and this code.  Both methods remove the entries from the RUN table, but as far as I can tell, they do not delete the corresponding files from the repository.  Purging old runs is kind of worthless if you leave a bunch of files that use up storage space.

 

Can anyone confirm that this is true?  Do I need to add code to do the file deletion after I purge the run?

Highlighted
Honored Contributor
Posts: 4,370
Registered: ‎09-09-2010
Message 7 of 10 (989 Views)

Re: Help need to batch delete runs from 2+ years ago

@William

If you are using v11.0 or newer keep in mind that Repository files may not be immediately deleted. Take a look at the Administrator Guide and read the section on "The ALM Optimized Project Repository" > "Project Repository Cleanup". There can be a delay between when you execute the Delete (or Purge) function and when the files actually get deleted.
[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Senior Member
Posts: 3
Registered: ‎06-13-2012
Message 8 of 10 (254 Views)

Re: Help need to batch delete runs from 2+ years ago

Hi,

 

The space on our ALM server is almost full and we tried doing purge run and also promote repository cleanup but however there seems to be any increase in the free space availability.

 

Please can somebody help to resolve this issue.

 

Regards,

Ashok

Honored Contributor
Posts: 4,370
Registered: ‎09-09-2010
Message 9 of 10 (238 Views)

Re: Help need to batch delete runs from 2+ years ago

There is going to be a delay between the time you purge data and when associated files in the repository are actually removed.

 

Take a look at this:

http://h30499.www3.hp.com/t5/Quality-Center-Support-Customer/lt-QC-ALM-Support-Tip-gt-ALM-Smart-Repo...

 

Here is how Repository Cleanup works (basically).

 

The process runs periodically for each project. By default this is every 7 days. HP has never been able to tell me exactly how to figure out when it will run for a given project.

 

When it runs, it looks at database tables for the project that track the files in the associated repository. The tables keep track of, among other things, when the last instance of a reference to the file was deleted.

 

There is a parameter that says how old that last-reference-deleted date has to be in order for the cleanup process to actually remove the file. By default, that is also 7 days.

 

So, if you purge data such that the last-reference-deleted date is today, the earliest that file could actually be removed from the system is 7 days from now, regardless of when the Cleanup process runs.

 

You can override these settings with Site Configuration parameters, as described in the referenced post.

 

 

[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Senior Member
Posts: 3
Registered: ‎06-13-2012
Message 10 of 10 (205 Views)

Re: Help need to batch delete runs from 2+ years ago

[ Edited ]

Hi Trudy,

 

Thanks for the response , however i have 3 questions on the repository cleanup.

 

1. Once we add the new site admin parameters REPOSITORY_GC_PROJECT_CLEANUP_INTERVAL and REPOSITORY_GC_DELAY_CANDIDATE_TIME values to zero (0) do i need to restart ALM service

 

2. Also as per the link you shared since I am setting REPOSITORY_GC_PROJECT_CLEANUP_INTERVAL to 0 do i need to manaually trigger the promote repository option from ALM site admin.

 

3. Does repository clean up run in the backgroud i mean do we have to be logged in to site admin when the repository clean up actually triggers or is it a background silent automatic process.

 

Also since we have already purged all our old run information from ALM client after we set site admin parameteres is it still required for us trigger the promote repository option explicitly.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.