Uploaded image for project: 'Dev - Nexus Repo'
  1. Dev - Nexus Repo
  2. NEXUS-12719

add component and asset counts per repository

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: New
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.3.0
    • Fix Version/s: None
    • Component/s: Repository, UI
    • Labels:
      None
    • Notability:
      4

      Description

      Display some place in the UI component and asset counts per repository.

      Workaround

      Here is a script that can be run inside an Execute Script scheduled task that will print this information to the application log.

      import org.sonatype.nexus.repository.Repository
      import org.sonatype.nexus.repository.storage.Query
      import org.sonatype.nexus.repository.storage.StorageFacet
      
      import groovy.json.JsonOutput
      
      def result = [:]
      
      def totalComponents = 0
      def totalAssets = 0
      
      repository.repositoryManager.browse().each { Repository repo ->
        def tx = repo.facet(StorageFacet).txSupplier().get()
        def components = 0
        def assets = 0
        try {
          tx.begin()
          components = tx.countComponents(Query.builder().where('1').eq(1).build(), [repo])
          assets = tx.countAssets(Query.builder().where('1').eq(1).build(), [repo])
          tx.commit()
        } catch (Exception e) {
          log.warn("Transaction failed {}", e.toString())
          tx.rollback()
        } finally {
          tx.close()
        }
        totalComponents += components
        totalAssets += assets
        result[repo.name] = [components: components, assets: assets]
      }
      
      result["_totals"] = [components : totalComponents, assets : totalAssets]
      
      def json = JsonOutput.toJson(result)
      log.info json
      return json
      

      IMPORTANT NOTE

      Previous variations of this script which did not properly close database transactions have been deleted from the ticket comments. Only the script in the description has been verified to not leak db transactions.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            plynch Peter Lynch
            Last Updated By:
            Joe Tom
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Dates

              Created:
              Updated:
              Date of First Response:

                tigCommentSecurity.panel-title