UCMDB API CIs to Record Set


I am trying to pull the information from UCMDB using the api(Version 8). This extract needs to be stored in a database. I am able to connect to the server and then iterate thru each of the topology. But all topology CI's have 0 properties.

Please let me know how to read the Topology to convert it to a recorset. I wanted somthing like the way we export it to CSV, so we can store it as a database base.



P.S. This thread has been moevd from Application Perf Mgmt (BAC / BSM) Support and News Forum to CMS and Discovery Support and News Forum. - Hp Forum Moderator

  • Hi,

    I guess you meant you want to get the properties values for the returned CIs

    See the example in the doc (Topology Query Example) and also in the QueryDefinition and QueryElement interfaces doc.

    In this post you can find where the java doc is located : http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1441023

  • Hi Amit,

    As you said I am looking for the properties of the CI's.

    I am able to loop thru the CI's but when I print the properties its all null within the CI's, the document you mentioned I went thru seems like that works for the 7.5 version.

    But for the 8.02 version, its not compiling with the API jar given.

    Pls let me know if I am missing anything,
  • Hi,

    Between 7.5 and 8.02 the new Java API was introtuced, see the Solutions and integrations help on 8.02.

    Which API you are try to use , the Java or the Web API ? Try to attach the code/errors you have.

  • I went thru the TQL Samples given, The sample seems to reffer to the 7.5 version I guess., as when I tried that didn't comple with the api-jar given.

    I am working on the Java api.

    I have attached the sample code., I dont see any error, but its not printing the value as I see in the TQL result set when I export it to CSV. I wanted to execute the query and store the result set in a different database.

    The no of lines after the export excluding the headers and the count of collections are same. but when I print the properties on each of the collection I dont see any value its null.

    Thanks for helping me., Pls suggest your ideas, or if you have any sample code.
  • Hi,

    The examples (you should use the one from page 406 on the pdf) are for 8.0 and up, and shuold complie and run with no issues with the correct jar.

    make sure you follow this step:

    Retrieve the API Jar File
    Get the ucmdb-api.jar from a BAC or UCMDB server installation. Extract the
    jar file from ucmdb-api.war, found in the AppServer\webapps directory on
    the server. Inside the war archive, ucmdb-api.jar is located in
    theWEB-INF\lib directory.
    Compile and run your application with ucmdb-api.jar in the classpath.

  • Hi Amit,

    As you suggested I saw the examples,and was able to see the ClassDefinition.

    The problem I am facing is the executeNamedQuery returns Collection of type Topology, the type displays as "software" or "nt" or "unix" for different topology.

    how do I read the attributes on these??

    I downloaded some PDF and and trying it on my own. I donnot have UCMDB installed on my mac, its from a different team, so I am not able to get the files from the server as requested.
  • Hi

    Use getCIsByName and getPropertyValue methods, as seen below:

    TopologyQueryService queryService =
    TopologyQueryFactory queryFactory =
    QueryDefinition queryDefinition =
    ("Get hosts with more than one network interface");
    String hostNodeName = "Host";
    QueryNode hostNode =
    QueryNode ipNode =
    Topology topology = queryService.executeQuery(queryDefinition);
    Collection hosts = topology.getCIsByName(hostNodeName);
    for (TopologyCI host : hosts) {
    System.out.println("Host " host.getPropertyValue("display_label"));
    for (TopologyRelation relation : host.getOutgoingRelations()) {
    (" has IP " relation.getEnd2CI().getPropertyValue("ip_address"));

    this is from Topology javadoc:

    Result of a topology query execution.
    You can retrieve CIs and relations from this by query node name or as a flat collection. If each CI matches exactly one node, the two techniques give the same result. If a CI matches more than one node, the topology structure holds n 1 instances of the CI where n is the number of nodes that contain the CI. When a CI is retrieved from the collection returned by getCIsByName(java.lang.String), its properties and relations are defined by the node with the specified name. When a CI is retrieved from the collection returned by getAllCIs(), the CI has all of the of the queried properties and connected relations of all instances of that CI.

    Similarly, when a Relations relation is matched by more than one query link node, the relation appears in this structure more than once.

    When traversing the resulting graph with TopologyCI.getOutgoingRelations() and TopologyCI.getIncomingRelations(), the relations are consistent with the connected CIs. If the CI is taken from a node, the relation will be the one connected to that node. When the CI is taken from the collection of all CIs, it is associated with all the relations to which the CI is connected from all nodes.


    List all hosts in uCMDB:

    QueryDefinition queryDefinition = factory.createQueryDefinition("Get all hosts");
    Topology topology = topologyQueryService.executeQuery(queryDefinition);
    for (TopologyCI host : topology.getAllCIs()) {
    System.out.println("Host key:" host.getPropertyValue("host_dnsname");
    List all hosts with their contained resources
    QueryDefinition queryDefinition = factory.createQueryDefinition("Get hosts' resources");
    String hostsNodeName = "Hosts";
    QueryNode hostsNode = queryDefinition.addNode(cisNodeName).ofType("host");
    QueryNode resourcesNode = queryDefinition.addNode("Resources").ofType("hostresource").queryKeyProperties();
    Topology topology = topologyQueryService.executeQuery(queryDefinition);
    for (TopologyCI host : topology.getCIsByName(hostsNodeName)) {
    for (Relation relation : host.getOutgoingRelations()) {
    printElement(relation.getEnd2CI(), "\t");
  • Thanks for the excellent reply!!!

    I did work on this example and these examples work great., and prints the result as expected.

    For my request, the UCMDB team had created a TQL query, which I am able to access from the UCMDB Reports(front-end).

    I wanted to execute that perticular query and retrive the result. I am able to execute the query and iterate thru the loop, but I am not able to print the different columns what I see in the report via front-end.

    Topology returned prints only 2 values, UCMDBID and the type, rest all other methos either returns a null or blank string("").

    In your reply you mentioned about the Flat collection, not sure if this is what is happening to my queries. Please let me know if you have any suggestions for reading the flat collections.

  • Hi,

    Make sure you specified the properties go get with the query definition, for example:

    Interface QueryDefinition


    public interface QueryDefinitionDefinition of a uCMDB TQL query.

    Examples of simple queries:

    Query CIs by list of IDs
    QueryDefinition queryDefinition = topologyQueryFactory.createQueryDefinition("Get Hosts by IDs");
    QueryNode queryNode = queryDefinition.addNode("Hosts").ofType("host").withIds(ids);
    queryNode.queryPropertiesWithQualifier("COMPARABLE").queryProperties("host_key", "host_iscomplete");
    Query CIs by their properties
    QueryDefinition queryDefinition = factory.createQueryDefinition("Get Hosts");
    QueryNode queryNode = queryDefinition.addNode("Hosts").ofType("host");
    Query CIs' neighbors
    QueryDefinition queryDefinition = factory.createQueryDefinition("Get hosts' neighbors");
    QueryNode cisNode = queryDefinition.addNode("CIs").ofType("host").withIdsOf(hosts);
    QueryNode neighborsNode = queryDefinition.addNode("Neighbors").ofAnyType();

    Once you got the Topology, you need to get TopologyCI collection from it, and use getPropertyValue method on the TopologyCI

  • Was wonderful, but I am not suppose to define the query in java, our team has to just pull data from already created TQLs from the respective team.

    uCMDB team will create many such TQLs and we will just have to read the info, we are not suppose to change or create our own queries.

    All I need is to do an export of the result set to a different table.,

    Hope you undersatnd my limitation.