Class VManagerSessionsClient

java.lang.Object
org.jenkinsci.plugins.vmanager.charts.util.VManagerSessionsClient

public final class VManagerSessionsClient extends Object
Thin client around the vManager /rest/sessions/list endpoint used to obtain run-state counts for a list of session names.

The endpoint expects a POST with JSON body of the form:

{
   "filter":     { "@c":".InFilter", "attName":"session_name", "operand":"IN", "values":[...] },
   "grouping":   ["region_identifier"],
   "projection": { "type":"SELECTION_ONLY",
                   "selection":[ "region_identifier","failed_runs","passed_runs",
                                 "running","waiting","other_runs","number_of_entities" ] }
 }

The response is a JSON array of objects, one per region group, with the fields above. fetchAggregated(java.lang.String, java.util.Collection<java.lang.String>, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials) sums the run-state counts across all returned rows.

For internal vManager servers with self-signed certs we trust all certificates and hostnames (consistent with the rest of the plugin).

  • Method Details

    • fetchSessionNamesByIds

      public static List<String> fetchSessionNamesByIds(String baseUrl, Collection<String> ids, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds, TaskListener listener) throws IOException
      Translates a list of session ids (e.g. lines of a .session_launch.output file produced by the vManager Jenkins Plugin in launch mode) into a list of session names by POSTing to /rest/sessions/list with an .InFilter over id and a SELECTION_ONLY projection of name.

      Trace lines mirror the rest of the plugin: the outbound URL / headers / payload and the response summary go to the build console when BuildLog.isVerbose() is on, and the same information is mirrored to Jenkins' system log at Level.FINE.

      Returns:
      the session names returned by the server (empty if the input is empty, the base URL is blank, or the response shape is unexpected). Never null.
      Throws:
      IOException
    • fetchAggregated

      public static VManagerSessionsClient.SessionAggregates fetchAggregated(String baseUrl, Collection<String> sessionNames, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds) throws IOException
      Posts the sessions list query and returns the summed counts across all region groups returned by the server.
      Parameters:
      baseUrl - vManager server base URL (e.g. https://host:port/vmgr/vapi)
      sessionNames - one or more session names; null/empty returns zeros.
      creds - credentials for HTTP Basic auth; may be null (no auth header).
      Throws:
      IOException
    • fetchAggregated

      public static VManagerSessionsClient.SessionAggregates fetchAggregated(String baseUrl, Collection<String> sessionNames, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds, TaskListener listener) throws IOException
      Same as fetchAggregated(String, Collection, StandardUsernamePasswordCredentials) but logs the URL, headers and payload to listener (if non-null).
      Throws:
      IOException
    • fetchSessionAttributeSums

      public static Map<String,Double> fetchSessionAttributeSums(String baseUrl, Collection<String> sessionNames, Collection<String> attributeIds, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds) throws IOException
      Posts a sessions-list query selecting an arbitrary set of attribute ids and returns the summed numeric value for each attribute across all returned rows.
      Parameters:
      baseUrl - vManager server base URL.
      sessionNames - one or more session names; null/empty returns an empty map.
      attributeIds - attribute ids to project (e.g. "passed_runs", "MyCustomAtt"); null/empty returns an empty map.
      creds - credentials for HTTP Basic auth; may be null.
      Returns:
      map of attribute id → summed value (only numeric fields are summed; non-numeric attributes are skipped). Never null.
      Throws:
      IOException
    • fetchSessionAttributeSums

      public static Map<String,Double> fetchSessionAttributeSums(String baseUrl, Collection<String> sessionNames, Collection<String> attributeIds, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds, TaskListener listener) throws IOException
      Same as fetchSessionAttributeSums(String, Collection, Collection, StandardUsernamePasswordCredentials) but logs the URL, headers and payload to listener (if non-null).
      Throws:
      IOException
    • fetchSessionTatWarnings

      public static Map<String,String> fetchSessionTatWarnings(String baseUrl, Collection<String> sessionNames, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds, TaskListener listener) throws IOException
      Posts a sessions-list query for the given session names and inspects three vManager attributes per session — total_runs_in_session, real_max_runs_in_parallel_vmgr and max_runs_in_parallel — to detect sessions whose configured parallelism could not be met at runtime. Returns a map of sessionName → warning text for every such session; sessions that do not match the condition are absent from the returned map.

      The condition for adding a warning is:

         total_runs_in_session   > real_max_runs_in_parallel_vmgr
         AND
         max_runs_in_parallel    > 1.25 * real_max_runs_in_parallel_vmgr
       
      Throws:
      IOException
    • fetchRunAnomalies

      public static VManagerSessionsClient.RunAnomalies fetchRunAnomalies(String baseUrl, Collection<String> sessionNames, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials creds, TaskListener listener) throws IOException
      Two-step fetch for the build-level Run Anomalies chart:
      1. POST /rest/sessions/list with .InFilter on session_name and projection [name, id, total_runs_in_session] to translate session names → ids and sum total_runs_in_session across them.
      2. POST /rest/data-mining/get-sessions-exceptions-aggregated-counts with the resulting array of ids as the raw JSON body; the response is a single object with the *_critical_ex_count_vmgr_latest and *_unknown_ex_count_vmgr_latest fields for each of the four metrics.
      Returns null if there are no sessions or no ids could be resolved (caller should skip storing the build action in that case).
      Throws:
      IOException