The Java API defines a set of client-side base classes for developing client applications that interact with Domain Managers.

This chapter provides guidelines for building a basic application that uses the Java API to interact with Domain Managers. These guidelines include setting up a development environment to build solutions with the Java API and the SMARTS.

The EDA API is distributed as part of the SMARTS. Installing the SMARTS will provide the development environment described in this section.

The Java language implementation of the Remote API is distributed as the skclient.jar file, which is located in:

BASEDIR\smarts\classes
File skclient.jar includes the Java classes that directly implement the API, along with supporting classes. The four packages are:
  • com.smarts.decs, which includes classes supporting the event correlation interface

  • com.smarts.remote, which includes the main interface classes for accessing Domain Manager functionality

  • com.smarts.repos, which includes supporting classes for working with repository objects

  • com.smarts.sos, which includes supporting classes related to the operating system.

Sample Programs

The SMARTS includes the following sample Java programs that you can build and run:
  • CloneClass
  • getInstance

CloneClass

The CloneClass program provides clones an instance of a class which are passed as parameters in the CloneClass Method and renames it with the name passed again as the parameter to the method.
package SmartsEDAATestingIP.com.org.edaa;

import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.when;

import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;

import Utilities.SmartsGeneric;

public class Clone {
       
       private String hostname;
       private String username;
       private String password;
       private String broker;  //holds broker:port value
       private String serverName;
       
       public Clone(String hostname,String username,String password,String broker,String serverName) {
              
              this.hostname = hostname;
              this.username = username;
              this.password = password;
              this.broker = broker;
              this.serverName = serverName;
              
       }
       
       
       public int  CloneClass(String className, String newinstancename , String instancename) {
              
              Response resp =given().
                           body(" { arguments : {\"clone_name\" : \""+newinstancename+"\" } }").
                           when().
                           contentType(ContentType.JSON).
                           post("http://"+hostname+":8080/smarts-edaa/msa/"+serverName+"/instances/"+className+"::"+instancename+"/action/clone?alt=json&pretty=true");
                                         
              return resp.getStatusCode(); 
              
       }
       
       public static void main (String args[]){
              Clone sg ; 
              sg = new Clone("itops-dev-210", "admin" , "changeme" , "itops-dev-210:426",  "INCHARGE-AM-PM-EDAA") ;
              int i  = sg.CloneClass("InCharge_NAS_Host_Feature","abcd", "Feature-NAS-Host") ; 
              
              System.out.print(" Response code is "+ i);
       }
       
       

}

Output: Response code is 200OK.

getInstance

The getInstance program gets the cloned instance from the last execution.
package SmartsEDAATestingIP.com.org.edaa;

import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.RestAssured.when;

import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Response;

import Utilities.SmartsGeneric;

public class GetClass {
       
       private String hostname;
       private String username;
       private String password;
       private String broker;  //holds broker:port value
       private String serverName;
       
       public GetClass(String hostname,String username,String password,String broker,String serverName) {
              
              this.hostname = hostname;
              this.username = username;
              this.password = password;
              this.broker = broker;
              this.serverName = serverName;
              
       }
       
       
       public int getInstance (String className, String clonedinstancename)
       {
              Response resp = when().
                           get("http://"+hostname+":8080/smarts-edaa/msa/"+serverName+"/instances/"+className+"::"+clonedinstancename+"?alt=json&pretty=true");
              
              
              return resp.getStatusCode(); 
       }
       
       public static void main (String args[]){
              GetClass sg ; 
              sg = new GetClass("itops-dev-210", "admin" , "changeme" , "itops-dev-210:426",  "INCHARGE-AM-PM-EDAA") ;
              int i  = sg.getInstance("InCharge_NAS_Host_Feature","abcd") ; 
              
              System.out.print(" Response code is "+ i);
       }
       
       

}

Output: Response code is 200OK.

Post Request

The Post request has two parts, the URL to which you send the data and the arguments which form the payload of the post request.

The EDAA gives you the flexibility to perform all the operation which is done on an instance of a class through dmctl using a web call. For example, the URL to which the post request is sent is:

localhost:8080/smarts-edaa/msa/servername/instances/className::instanceName/action/action_name

For example, if you want to perform clone action on Feature-NAS-Host instance of InCharge_NAS_HOST_Feature class, which is hosted on a domain with name INCHARGE-AM-PM on the host <ip address>. The URL which is used to post the request using the above mentioned format must be:

http://<host ip address>:8080/smarts-edaa/msa/INCHARGE-AM-PM-EDAA/instances/InCharge_NAS_Host_Feature::Feature-NAS-Host/action/clone?alt=json&pretty=true

In the payload of this post request you must pass all the parameters needed for that particular action to execute. In this case the clone action expects clone_name as the parameter. So, the payload must be:
{
arguments : {
		“clone_name” : “new_name”
      } 
}