This documentation supports the 9.1 to 9.1 Service Pack 3 version and its patches of BMC Atrium Core. The documentation for version 9.1.04 and its patches is available here.

To view the latest version, select the version from the Product version menu.

Example- Finding all CIs related to an instance of computer system using the graph walk query functions

This example shows how to use the graph walk query functions in a common scenario: searching for all CIs related to a specific computer system in your organization.

At the fictional Calbro Services company, Allen Allbrook wants to view all the CIs related to the CS000000 instance of the BMC_ComputerSystem class. Allen needs to determine the impact of an outage of the CS000000 CI. Allen does not know the exact data model path to follow in the query. Therefore, he uses the graph walk functions in his program.

In the following sample program, Allen first creates the CMDBGraphWalkQueryStruct, CMDBGraphWalkStateStruct, and CMDBGraphWalkResultStruct variables, and the CMDBGraphWalkSelectorAndFilterList data structure in his program. He then initializes these variables with specific values and passes them to the CMDBQueryByPath function as parameters.

/*declare variables*/
  int returnCode;
  CMDBClassNameId startClassNameId;
  ARNameType startInstanceId;
  CMDBGraphWalkQueryStruct graphWalkQueryStruct;
  CMDBGraphWalkStateStruct graphWalkStateStruct;
  CMDBGraphWalkResultStruct graphWalkResult;
  CMDBGraphWalkSelectorAndFilterList objSelAndFilterList;
  CMDBGraphWalkRelation walkLink;
  CMDBGraphWalkRelationList walkList;
  CMDBGraphWalkRelationList walkList;

/*Reset the memory space allocated for the query variables*/
  memset(&graphWalkStateStruct,0, sizeof(CMDBGraphWalkStateStruct));
  memset(&graphWalkResult,0, sizeof(CMDBGraphWalkResultStruct));
  memset(&objSelAndFilterList, 0, sizeof(CMDBGraphWalkSelectorAndFilterList));
  memset(&walkLink, 0, sizeof(CMDBGraphWalkRelation));
  memset(&walkLink, 0, sizeof(CMDBGraphWalkRelation));

/*Set values to graph walk flags*/

/*Set values to the CMDBGraphWalkRelation and CMDBGraphWalkRelationList structure members*/
  strcpy(walkLink.classNameId.namespaceName, "BMC.CORE");
  strcpy(walkLink.classNameId.className, "BMC_BaseRelationship");
  walkLink.qualification = NULL;
  walkList.numItems = 1;
  walkList.walkRelationList = &walkLink;
  strcpy(startClassNameId.namespaceName, "BMC.CORE");
  strcpy(startClassNameId.className, "BMC_ComputerSystem");
  strcpy(startInstanceId, "CS000000");
  strcpy(startInstanceId, "CS000000");

/*Set values to the CMDBGraphWalkQueryStruct structure members*/
  memset(&graphWalkQueryStruct, 0, sizeof(CMDBGraphWalkQueryStruct));
  strcpy(graphWalkQueryStruct.datasetId, "BMC.ASSET");
  graphWalkQueryStruct.datasetMask = 0;
  graphWalkQueryStruct.maxRetrieve = 10000;
  graphWalkQueryStruct.numLevels = 1;
  graphWalkQueryStruct.queryMode = CMDB_GRAPH_WALK_WALK_COMPLETE_GRAPH;
  graphWalkQueryStruct.objSelectorAndFilterList = objSelAndFilterList;
  graphWalkQueryStruct.walkRelationList = walkList;
  graphWalkQueryStruct.walkRelationList = walkList;

/*Call the CMDBGraphWalkBegin function
  int returnCode = CMDBGraphWalkBegin(
    control, &startClassNameId, startInstanceId, &graphWalkQueryStruct, &graphWalkStateStruct, &status );
    control, &startClassNameId, startInstanceId, &graphWalkQueryStruct, &graphWalkStateStruct, &status );
  if( returnCode >= AR_RETURN_ERROR) {return returnCode;}

/* Loop until the next chunk of rows are available for retrieving*/
  while(graphWalkStateStruct.hasNextChunk == TRUE)

/*call the CMDBGraphWalkNext to retrieve the next chunk of rows*/
  returnCode = CMDBGraphWalkNext(control, &graphWalkStateStruct, &graphWalkResult, &status );
  if( returnCode >= AR_RETURN_ERROR)
    return returnCode;

/* Process the results here */
  FreeCMDBGraphWalkResultStruct(&graphWalkResult, FALSE);

/*End the graph walk*/
  returnCode = CMDBGraphWalkEnd(control, &graphWalkStateStruct, &status);
  FreeCMDBGraphWalkStateStruct(&graphWalkStateStruct, FALSE);
  Return returnCode;

In the program, Allen sets the namespaceName member of the CMDBGraphWalkRelation structure to BMC.CORE and the className of the type of relationships to walk to BMC_BaseRelationship. Allen wants to retrieve only the destination relationships for the CS000000 instance. Therefore, he sets the qualification for the relationship walk to NULL and the walk direction to CMDB_RELATIONSHIP_DIRECTION_OUT (destination).

Allen sets the namespaceName and className members of the startClassNameId variable to BMC.CORE and BMC_ComputerSystem, respectively. He sets the startInstanceId to CS000000.

Because Allen wants to retrieve instances from the production dataset, he sets the datasetId member of the graphWalkQueryStruct variable to BMC.ASSET and the datasetMask member to 0. He sets the maxRetrieve member to 10000 and the numLevels to 1 to indicate that he wants to enable chunking.

Allen passes the startClassNameId, startInstanceId, graphWalkQueryStruct, and graphWalkStateStruct parameters as inputs to the CMDBGraphWalkBegin function. The hasNextChunk member of the graphWalkStateStruct parameter now contains a value of TRUE to indicate that the next chunk of rows is available to be retrieved.

Allen calls the CMDBGraphWalkNext function in a While loop with the hasNextChunk member as the condition. The next chunk of rows will be retrieved until hasNextChunk is equal to TRUE. He then calls the CMDBGraphWalkEnd function to end the graph walk query.

The query that Allen constructed in this example returns all the relationships of the CS000000 instance in the BMC.ASSET dataset where the CS000000 instance is the source.

Was this page helpful? Yes No Submitting... Thank you