App Connect

App Connect

Join this online user group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  REST Admin API Sample Code

    Posted Tue April 21, 2020 11:10 AM
    I am looking for any sample code where a Java application uses the Rest Administration API to interact with the Integration Nodes without the assistance of the Integration API if that is possible.  Since the IntegrationAPI has been deprecated or at least does not have all the features that were provided in IB 10, I want to direct my developers to use techniques that will be available in the future.  Specifically, the developers need to access a configurable service (or Policy in ACE) to extract values as well as being able to start and stop applications and message flows running on the Integration Servers.  I an see the samples supplied on the installation of the toolkit but they all use the Integration API which if that is recommended I can use the samples to figure out the features I need to use.  Does anyone have any sample code that would demonstrate the REST Administration API?

    ------------------------------
    Tom Lowry
    ------------------------------


  • 2.  RE: REST Admin API Sample Code

    Posted Tue April 21, 2020 04:02 PM
    Here is some JCN code that gets a policy type/name and interates through the properties and adds them to the Environment tree. Not the REST API but shows how to do it is Java using IntegrationAPI. Note this changed between IIB and ACE.

    You can pass in the policy type/name to get the properties for via the LocalEnvironment or UDPs...

    HTH

    Regards

    public class GetPolicyProperties extends
      MbJavaComputeNode {
     private final static String POLICY_TYPE = "policyType";
     private final static String POLICY_NAME = "policyName";
     public void evaluate(MbMessageAssembly assembly) throws MbException {
      
      String policyType, policyName;
      boolean processUDCS = true;
      MbOutputTerminal out = getOutputTerminal("out");
      //Get the environment
      MbMessage env = assembly.getGlobalEnvironment();
      //Get the local environment
      MbMessage le = assembly.getLocalEnvironment();
      
      MbElement typeElement = le.getRootElement().getFirstElementByPath("Variables/Input/policyType");
      
      if (typeElement == null) {
      
       //get the policy type and name from UDPs defined in flow
       policyType = (String)getUserDefinedAttribute(POLICY_TYPE);
     
       if (policyType == null)  {
        MbService.logWarning(this,
          "UDP_Error",
          ErrorMessages.MESSAGE_SOURCE,
          ErrorMessages.POLICY_TYPE_ERROR,
          "",
          null);
        processUDCS = false;
       }
      
      }
      else {
       policyType = typeElement.getValueAsString();
      }
      MbElement nameElement = le.getRootElement().getFirstElementByPath("Variables/Input/policyName");
      
      if (nameElement == null) {
       
       policyName = (String)getUserDefinedAttribute(POLICY_NAME);
     
       if (policyName == null)  {
        MbService.logWarning(this,
          "UDP_Error",
          ErrorMessages.MESSAGE_SOURCE,
          ErrorMessages.POLICY_NAME_ERROR,
          "",
          null);
        processUDCS = false;
       }
      }
      
      else {
       policyName = nameElement.getValueAsString();
      }
      
      
      if (processUDCS) {
       
      
       try {
        
        MbElement geRoot = env.getRootElement();
        
        MbElement var = geRoot.createElementAsLastChild(MbElement.TYPE_NAME,"Variables",null);
        MbElement pol = var.createElementAsLastChild(MbElement.TYPE_NAME,"Policy",null);
        
        MbPolicy policy =  getPolicy(policyType, policyName);
        
        //String polType = policy.getType().toString();
        
        Collection<MbProperty> policyProperties = policy.getProperties();
         
        Iterator<MbProperty> iterator = policyProperties.iterator();
        
              // while loop
              while (iterator.hasNext()) {
               MbProperty policyProperty = iterator.next();
               
         String name = policyProperty.name().toString();
         String value = policyProperty.value().toString(); //keys.nextElement().toString();
     
         MbElement ele = pol.createElementAsFirstChild(MbElement.TYPE_NAME,"Property",null);
         
         ele.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Value", value);
         ele.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Key", name);
              }
      
        pol.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE,"Type",policyType);
        pol.createElementAsFirstChild(MbXMLNSC.ATTRIBUTE, "Name", policyName);
                
       }
       catch (Exception e) {
     
       }
      }
      
      // The following should only be changed
      // if not propagating message to the 'out' terminal
      out.propagate(assembly);
     }
     
     public static class ErrorMessages extends ListResourceBundle
     {
      public static final String MESSAGE_SOURCE = ErrorMessages.class.getName();
      public final static String POLICY_TYPE_ERROR = "Error with policyType UDP";
      public final static String POLICY_NAME_ERROR = "Error with policyName UDP";
      
      private Object[][] messages =
      {
        {POLICY_TYPE_ERROR,
        "Check definition for: " + POLICY_TYPE
        },
        {POLICY_NAME_ERROR,
        "Check definition for: " + POLICY_NAME
        }
      };
      public Object[][] getContents()
      {
       return messages;
      }
     }



  • 3.  RE: REST Admin API Sample Code

    Posted Wed April 22, 2020 09:31 AM
    Thanks Marc, that does help.  Have you ever tried to access some of the integration server properties like what the status of a specfic Resource Statistics were turned on?  In IB10, I was able to use something like this: 

    if (thisExecutionGroup.getResourceStatisticsEnabled("CICS")) { if (thisExecutionGroup.getResourceStatisticsEnabled("CICS")) {         log("Resetting CICS Resource Statistics to On: " + executionGroupName + " " + brokerName );              thisExecutionGroup.setResourceStatisticsEnabled("CICS", false);        }

    In ACE, it appears that those methods are no longer around and I am looking to migrating some of my administration type processes to ACE and am exploring all possibilities.  If you are not aware of this capability, that is fine, just thought I would ask. 

    Thanks for your help.

    ------------------------------
    Tom Lowry
    ------------------------------



  • 4.  RE: REST Admin API Sample Code

    Posted Wed April 22, 2020 09:34 AM
    Hi Tom,

    You can use the HttpClient and HttpResponse classes in the Integration API in ACE v11 to get send requests to the the server using the REST Admin API.
    My article has an example to show how to use it:  https://developer.ibm.com/integration/blog/2019/07/11/using-the-integration-api-with-ace-v11/

    Thanks

    Sanjay


  • 5.  RE: REST Admin API Sample Code

    Posted Wed April 22, 2020 09:35 AM

    Hello,

    Are you referring to AppConnect Enterprise?

    If so, did you looked at 
    https://www.ibm.com/support/knowledgecenter/SSTTDS_11.0.0/com.ibm.etools.mft.doc/bn28430_.html



    ------------------------------
    Pierre Richelle
    IBM Hybrid Cloud Integration Specialist
    IBM
    brussels
    ------------------------------