How it works: CMCI GraphQL API

The CICS® management client interface (CMCI) provides a GraphQL application programming interface (API) for system management clients such as IBM® CICS Explorer®. The CMCI GraphQL API is supported through HTTP. With the GraphQL API, a client can query many types of CICS resources across CICSplexes or regions in a single request. In the single query request, the client can specify exactly what data it needs about multiple CICS resources, with inherent relationships between the CICS resources explicitly expressed. For more information about GraphQL, see Introduction to GraphQL.

Notes:
  • The aggregation function in CICS Explorer is also supported by the CMCI GraphQL API in CICS TS. For more information, see Configuring for CICS Explorer.
  • The CMCI GraphQL API is supported in a CICSPlex® SM environment as of CICS TS 5.5, and in a single CICS region (SMSS) environment as of CICS TS 5.6 with APAR PH35122.
  • To set up the CMCI GraphQL API in CICS, you need to configure a CMCI JVM server within the WUI region of a CICSplex or a single CICS region. For instructions, see Setting up CMCI.

What is a GraphQL query?

A simple GraphQL query request looks like this:
Figure 1. Simple query requesting CICSplex names
{
  cicsplexes {
    name
  }
}

At the root of the query is the cicsplexes field, which finds all the CICSplexes that the WUI server is connected to. The name field nested in the cicsplexes field requests the name of each CICSplex.

Query responses are returned as JSON objects, with the requested data enclosed in the value of the data field. The structure of the response follows that in the query.
Figure 2. Response to simple query about CICSplex names
{
  "data": {
    "cicsplexes": [
      {
        "name": "CICSPLX01"
      },
      {
        "name": "CICSPLX02"
      }
    ]
  }
}
In an SMSS region, the structure of a GraphQL query is different and looks like this:
Figure 3. Simple query requesting SMSS region name
{
  smssRegion {
    name  
  }
}

The structure of the response is similar to the CICSplex, and looks like this:

Figure 4. Response to simple query about SMSS region name
{
  "data": {
    "smssRegion": {
      "name": "IYCWENSS"
    }
  }
}
In CICS TS, the GraphQL API has support for:
  • Basic system topology (CICSplexes, Regions, System Groups)
  • Querying regions for the resources installed in them
  • Querying BAS repositories and CSD repositories for definitions
  • Aggregating and grouping resources
  • Navigating links between resources

To retrieve more information, add more fields to the query, including nested ones. See Sample queries.

How to make GraphQL API requests

The GraphQL API endpoint is at:
https://host:port/graphql
where host and port are the host name and the port number of your CMCI JVM server.
The GraphQL API accepts GET and POST requests.
For GET requests:

A Content-Type: application/json header must be sent. The query is supplied by the query query parameter. The operation is supplied by the optional operationName query parameter.

For example, the simple query in Figure 1 can be sent by using the following URL:
https://host:port/graphql?query={cicsplexes{name}}
Likewise, for the simple query in Figure 3, a GET request is similar, and can be sent by using the following URL:
https://host:port/graphql?query={smssRegion{name}}
For POST requests:
A Content-Type: application/json header must be sent. The body of the request must be a JSON-encoded object.
{
    "query": "query_body",
    "operationName": "operation_name"
}
where only the query field is mandatory.

Alternatively, a Content-Type: application/graphql header can be sent on POST requests. In this case, the body of the request must be the GraphQL query itself, and no operation name can be specified.

See Sample queries for sample code of GraphQL queries.

Example: the CICSplex Explorer view of CICS Explorer

The GraphQL API can provide a more responsive experience in user interfaces such as CICS Explorer. Take the CICSplex Explorer view of CICS Explorer as an example, consider what information is needed in CICS Explorer to build the CICSplex Explorer view:
CICSplex Explorer view

At its most basic, you need to know what CICSplexes are in the environment, and which CICS regions are in those CICSplexes. With a REST API, you have to make multiple requests:

  1. Ask for a list of CICSplexes in the environment.
  2. For each CICSplex, ask for a list of the regions in that CICSplex.

Even this simple example demonstrates that the number of requests you have to make grows with the complexity of the information you ask for. When you consider adding region groups into the mix, and members of those region groups, even more information needs to be requested.

Here’s how to ask for the information you need to populate the CICSplex Explorer view in the GraphQL API:
{
  cicsplexes {
    name
    regions {
      name
    }
  }
}
And here’s the response:
{
  "data": {
    "cicsplexes": [
      {
        "name": "DUMMY907",
        "regions": []
      },
      {
        "name": "CICSEXCD",
        "regions": [
          {
            "name": "IYCWEZW2"
          },
          {
            "name": "IYCWEZG1"
          },
          {
            "name": "IYCWEZW1"
          },
          {
            "name": "IYCWEZH1"
          },
          {
            "name": "IYCWEZI1"
          },
          {
            "name": "IYCWEZJ1"
          },
          {
            "name": "IYCWEZZ1"
          }
        ]
      }
    ]
  }
}

The GraphQL supplies all the data you require in a single request with explicitly shown relationships between CICS resources. When enabled for the CMCI connection, it can drastically reduce the time you need to retrieve information through CICS Explorer. It also powers the aggregation function in CICS Explorer for Aqua 3.2 to provide aggregation and grouping of CICS resources.

Sample queries

You can use GraphiQL, an online GraphQL visualization editor, to test your GraphQL queries or the samples. The URL to GraphiQL is:
https://host:port/graphiql
where host and port are the host name and the port number of your CMCI JVM server.
GraphiQL tips:
  • GraphiQL provides auto-completion and a built-in documentation explorer for GraphQL schema reference. You can display available field names by pressing Ctrl+Space.
  • To easily differentiate queries in GraphiQL history, you can specify a unique query name by prefixing the query with query QueryName.
The following example queries the count of local files of all regions in all the connected CICSplexes, and the name of each CICSplex and region. It also has a query name LocalFilesInRegionsInCICSplexes.
query LocalFilesInRegionsInCICSplexes {
  cicsplexes {
    name
    regions {
      name
      cicsResources {
        locfile {
          count
        }
      }
    }
  }
}
You can add more attributes to be queried. This example queries all CICSplexes and all the regions in each CICSplex. Within each region, it retrieves the name, useCount, and status fields of all the local transactions.
{
  cicsplexes {
    name
    regions {
      name
      cicsResources {
        loctran {
          records {
            name
            useCount
            status
          }
        }
      }
    }
  }
}
You can specify which CICSplex or CICS region to be queried. This example queries Region AORRGN in CICSplex PLEX1, retrieving the name, useCount, and status fields of all the local transactions in the region.
{
  cicsplex(name: "PLEX1") {
    name
    region(name: "AORRGN") {
      name
      cicsResources {
        loctran {
          records {
            name
            useCount
            status
          }
        }
      }
    }
  }
}
Removing the CICSplex and region specifications, this example queries all connected CICSplexes and the name, useCount, and status fields of all the local transactions in those CICSplexes.
{
  cicsplexes {
    name
    cicsResources {
      loctran {
        records {
          name
          useCount
          status
        }
      }
    }
  }
}
This example is similar to the previous one, except that it uses a filter to retrieve only transactions starting with CED.
{
  cicsplexes {
    name
    cicsResources {
      loctran(filter: {name: {value: "CED*"}}) {
        records {
          name
          useCount
          status
        }
      }
    }
  }
}
You can also query CICS definitions. This request queries the name and update attributes for all file definitions in the CICSplex data repository.
{
  cicsplex(name: "PLEX1") {
    drep {
      cicsDefinitions {
        filedef {
          records {
            name
            update
          }
        }
      }
    }
  }
}
Similarly, this request queries the name for all pipeline definitions in the CSD for Region AORRGN in CICSplex PLEX1.
{
  cicsplex(name: "PLEX1") {
    region(name: "AORRGN") {
      csd {
        cicsDefinitions {
          pipedef {
            records {
              name
            }
          }
        }
      }
    }
  }
}
This query performs aggregation of all local files in each CICSplex, grouping them by common values of the name attribute and retrieving the count of aggregated records within each aggregation group, the name of each group, and the average, minimum, and maximum readCount within each group.
{
  cicsplexes {
    name
    cicsResources {
      locfile {
        groupBy(attribute: "name") {
          count
          aggregateRecord {
            name {
              value
            }
            readCount {
              average
              min
              max
            }
          }
        }
      }
    }
  }
}
The following example queries the current local transactions connected to the SMSS region. It retrieves records and displaying name, priority, status, tracing, purgeability, and deadlock timeout under each SMSS region name.
{
  smssRegion {
    name
    cicsResources{
      loctran{        
       records{
          name
          priority
          profile
          status
          tracing
          purgeability
          deadlockTimeout
        }
      }
    }
  }
}