Author Topic: To Retrieve applications on the Hosts  (Read 2832 times)

Offline genesyslearner

  • Jr. Member
  • **
  • Posts: 58
  • Karma: 0
To Retrieve applications on the Hosts
« on: February 08, 2018, 05:08:59 PM »
Hi All,

My goal is to retrieve the hosts in my environment using SDK and then print the applications on these hosts.
I was able to successfully get the hosts using the below code:-

Collection<CfgHost> hos= confservice.retrieveMultipleObjects(CfgHost.class,
    new CfgHostQuery());
    System.out.println(hos.size());
      for (CfgHost hs : hos)
      {
      System.out.println(hs.getName());
              }
I need reference on the code to fetch applications on these particular hosts. Any reference will help me alot.

Thanks

Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: To Retrieve applications on the Hosts
« Reply #1 on: February 14, 2018, 10:59:26 AM »
Hi,

I don't think there is a specific search you can do to obtain all applications by host.

Probably the best way would be to retrieve all applications and then iterate through each application and find which host it is on.

Hope this helps,

Pete.

Offline genesyslearner

  • Jr. Member
  • **
  • Posts: 58
  • Karma: 0
Re: To Retrieve applications on the Hosts
« Reply #2 on: February 15, 2018, 08:51:57 AM »
Hi Pete,

Thanks for your response!

I found a way to get application by host and it is more or less the way you are suggesting.
Happy to share the code with you/all :-


Collection<CfgHost> hos= confservice.retrieveMultipleObjects(CfgHost.class,
    new CfgHostQuery());
   
      for (CfgHost hs : hos)
      {
   
      Integer dbid = hs.getDBID();
     
     
      CfgApplicationQuery query = new CfgApplicationQuery();
      query.setHostDbid(dbid);
     
      Collection<CfgApplication> app = confservice.retrieveMultipleObjects(CfgApplication.class, query);
      for (CfgApplication ap : app)
      {
         
         
      System.out.println("AppName" + " " + ap.getName());
     
   
      } 
         
      }