openapi: 3.0.3
paths:
  /jvmInventory:
    post:
      tags:
        - JVM Inventory Report
      summary: Schedules generation of the report on JVM runtimes detected by IC
      description: |
        Schedules generation of the report that includes JVM runtimes detected by IC,        
        accepts filters and group conditions provided as parameters of report.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JvmInventoryReportCreateRequest'
      responses:
        '202':
          description: Scheduled report
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '../report/common.yaml#/components/schemas/Report'
                  - properties:
                      params:
                        allOf:
                          - $ref: '#/components/schemas/JvmInventoryReportParameters'
                          - $ref: '../report/common.yaml#/components/schemas/ResolvedFromAndToParameters'
                      state:
                        type: string
                        example: PROCESSING
                  - required:
                      - reportId
                      - state
                      - params
                      - userId
                      - requestTime
        '400':
          description: Information about invalid parameters used to generate a report
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '../report/common.yaml#/components/schemas/Report'
                  - properties:
                      params:
                        allOf:
                          - $ref: '#/components/schemas/JvmInventoryReportParameters'
                          - $ref: '../report/common.yaml#/components/schemas/ResolvedFromAndToParameters'
                      state:
                        type: string
                        example: FAILED
                      stateMessages:
                        description: Information why the report generation failed
                        type: array
                        items:
                          type: string
                  - required:
                      - state
                      - params
                      - stateMessages
    get:
      tags:
        - JVM Inventory Report
      summary: Gets a list of JVM inventory report descriptions
      description:
        Gets a list of JVM inventory report descriptions (without report data)
      parameters:
        - $ref: '../crs_restapi_common.yaml#/components/parameters/afterToken'
        - $ref: '../crs_restapi_common.yaml#/components/parameters/limit'
        - $ref: '../crs_restapi_common.yaml#/components/parameters/userId'
        - $ref: '../crs_restapi_common.yaml#/components/parameters/reportName'
        - $ref: '../report/common.yaml#/components/parameters/reportState'
        - $ref: '../report/common.yaml#/components/parameters/reportRequestTimeFrom'
        - $ref: '../report/common.yaml#/components/parameters/reportRequestTimeTo'
      responses:
        '200':
          description: List of JVM inventory report descriptions
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '../crs_restapi_common.yaml#/components/schemas/DataPage'
                  - properties:
                      data:
                        type: array
                        items:
                          allOf:
                            - $ref: '../report/common.yaml#/components/schemas/Report'
                            - properties:
                                data:
                                  example: null
                                  type: array
                                  items:
                                    type: object
                                stateMessages:
                                  type: array
                                  example: null
                                  items:
                                    type: string
                                params:
                                  allOf:
                                    - $ref: '#/components/schemas/JvmInventoryReportParameters'
                                    - $ref: '../report/common.yaml#/components/schemas/ResolvedFromAndToParameters'
                            - required:
                                - reportId
                                - state
                                - params
                                - requestTime
                                - userId

  /jvmInventory/{reportId}:
    get:
      tags:
        - JVM Inventory Report
      summary: Gets JVM inventory report by ID
      description:
        Gets JVM inventory report by identifier
      parameters:
        - $ref: '../report/common.yaml#/components/parameters/reportId'
        - $ref: '../report/common.yaml#/components/parameters/afterToken'

      responses:
        '200':
          description: Found JVM inventory report by ID
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '../report/common.yaml#/components/schemas/Report'
                  - properties:
                      params:
                        allOf:
                          - $ref: '#/components/schemas/JvmInventoryReportParameters'
                          - $ref: '../report/common.yaml#/components/schemas/ResolvedFromAndToParameters'
                  - required:
                      - reportId
                      - state
                      - params
                      - userId
                      - requestTime
        '404':
          description: Report with such ID does not exist
          content:
            application/json:
              schema:
                type: string
                example: "Unknown report: 1cc40ee6-87a7-4147-b02d-7d26ce0387d0"
    delete:
      tags:
        - JVM Inventory Report
      summary: Deletes JVM inventory report by ID
      description:
        Deletes JVM inventory report by identifier
      security:
        - ApiKey: [ ]
      parameters:
        - $ref: '../report/common.yaml#/components/parameters/reportId'
      responses:
        '204':
          description: Report deleted successfully

components:
  schemas:
    JvmInventoryReportCreateRequest:
      description: Request to create JVM inventory report
      allOf:
        - $ref: '#/components/schemas/JvmInventoryReportParameters'
        - $ref: '../report/common.yaml#/components/schemas/ReportName'

    JvmQueryProperty:
      description: JVM properties supported by JVM inventory report for filtering, sorting and grouping
      oneOf:
        - type: string
          pattern: 'tags\\..+'
        - type: string
          enum:
            - 'vmId'
            - 'state'
            - 'startTime'
            - 'lastHeardTime'
            - 'agentRevision'
            - 'agentVersion'
            - 'inventory.hostName'
            - 'inventory.systemProperties.java.home'
            - 'inventory.systemProperties.java.runtime.version'
            - 'inventory.systemProperties.java.specification.version'
            - 'inventory.systemProperties.java.vendor'
            - 'inventory.systemProperties.java.version'
            - 'inventory.systemProperties.java.vm.name'
            - 'inventory.systemProperties.java.vm.vendor'
            - 'inventory.systemProperties.java.vm.version'
            - 'inventory.systemProperties.os.arch'
            - 'inventory.systemProperties.os.name'
            - 'inventory.systemProperties.os.version'
            - 'inventory.mainMethod'

    JvmInventoryReportParameters:
      description: Parameters used to generate a JVM inventory report
      type: object
      properties:
        filter:
          $ref: '../report/common.yaml#/components/schemas/PropertyFilter'
        groupBy:
          $ref: '../report/common.yaml#/components/schemas/PropertyGroupBy'
        sortBy:
          $ref: '../report/common.yaml#/components/schemas/PropertySortBy'

        from:
          type: string
          title: |
            Start of the time interval to report running VM instances [inclusive].
            It can be absolute or relative
          default: "3m"
          allOf:
            - $ref: '../report/common.yaml#/components/schemas/TimeString'
        to:
          type: string
          title: |
            End of the time interval to report running VM instances [exclusive]
            It can be absolute or relative
          default: "0d"
          allOf:
            - $ref: '../report/common.yaml#/components/schemas/TimeString'

        details:
          description: |
            Whether to include VM details in the report, such as:
            
            - `vmId`
            - `startTime`
            - `lastHeardTime`
            - `state`
            - `agentVersion`
            - `agentRevision`
            - `inventory.hostName`
            - `inventory.systemProperties.java.home`
            - `inventory.systemProperties.java.runtime.version`
            - `inventory.systemProperties.java.specification.version`
            - `inventory.systemProperties.java.vendor`
            - `inventory.systemProperties.java.version`
            - `inventory.systemProperties.java.vm.name`
            - `inventory.systemProperties.java.vm.vendor`
            - `inventory.systemProperties.java.vm.version`
            - `inventory.systemProperties.os.arch`
            - `inventory.systemProperties.os.name`
            - `inventory.systemProperties.os.version`
            - `inventory.mainMethod`
            - `tags`
            
            NOTE: if `details` is "false" and there are no `filter` and `groupBy` parameters, 
            then only the `count` field will be returned as report data, 
            which contains the number of virtual machines that satisfy the requested time period.
          type: boolean
          example: false
          default: false

