Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
naeem_maqsud
Advisor
Advisor
1,552
Update August 1, 2022: As of SP24, wildcards are supported when using the LaMa provider implementation definition of "HTTP post service"

This blog shows how you can use LaMa to stop/start PI channels. You can indicate a specific channel or use wildcards. The concepts used have already been covered in a previous blog which you can reference.

Before continuing please ensure that your channels are configured to allow controlling externally as explained in the PI configuration guide

I will cover two methods namely using the LaMa provider implementation definitions of "HTTP post service" and "SAP host agent registered scripts".

Disclaimer

This blog is published “AS IS”. Any software coding and/or code lines / strings (“Code”) included are only examples and are not intended to be used in any productive system environment. The Code is only intended to better explain and visualize the features of the SAP Landscape Management Automation Studio. No effort has been made to make the code production quality (e.g. security, error handling, robustness, etc). If you use any of the code shown, you are doing it at your own risk.

Information in this blog could include technical inaccuracies or typographical errors. Changes may be periodically made.

1.0 SAP host agent registered scripts


1.1 Create Script:


Decide on the central host from where to execute the script. You only need a single host to manage channels on multiple systems. I selected the host "a4h-vm1" which happens to be the central instance host of one of my SAP systems.


Decide on where to save your script. I used the location /usr/sap/scripts on the above single host



#!/bin/bash
HOST=$1
PORT=$2
PASS=$3
PARTY=$4
SERVICE=$5
COMMAND="curl -u \"pidemo:$PASS\" \"http://$HOST:$PORT//AdapterFramework/ChannelAdminServlet?party=$PARTY&service=$SERVICE&channel=*&action=STOP\""
eval $COMMAND

Note the use of channel=* which means we will stop all channels for chosen party and service.


 

1.2 Create Conf File:


On the same host as above, create the file pi_channel_stop_all.conf



# cd /usr/sap/hostctrl/exe/operations.d

# vim pi_channel_stop_all.conf

Username: root
Name: pi_channel_stop_all
Description: Stop all channels
Command: /usr/sap/scripts/pi_channel_stop_all.sh $[PARAM-HOST:#required] $[PARAM-PORT:#required] $[PARAM-PASS:#required] $[PARAM-PARTY:#required] $[
PARAM-SERVICE:#required]
ResultConverter: flat
Platform: Unix

 


1.3 Create Provider Definition


We are going to create a custom process that does a mass channel stop using wildcards.

  1. Go to Automation Studio -> Provider Definitions -> Create

  2. Specify Provider Type as "Script Registered with Host Agent"

  3. Add host (your chosen host - e.g. a4h-vm1) from the drop down and click “Retrieve Scripts”. The host agent fills the drop list.

  4. Choose the script (the configuration file) “pi_channel_stop_all.conf” and give Name of “pi_channel_stop_all”. Check mark “Execute on Central Host Only” and fill in the host information. Click on Create Provider.



4. Click on the newly created provider definition.



5. Go to Parameters tab and click on “Add Parameter”. Add the below 5 parameters of Type string for all except PORT which is integer. Select Mandatory for all. Also mark the parameter PASS as secure.



 

1.4 Create Custom Operation



  1. Go to Automation Studio -> Custom Operations -> Create



2. Click on the newly created custom operation



3. Click on constraints. This is an optional step. We want to restrict the operation to be selectable from a single host. This does not mean the operation occurs on this host. The host in the URL is the one that determines where it will be executed.


4. Click Add Constraint and then fill out the constraint details




 

1.5 Test Custom Operation


First let's check that channel are running. Go to a browser and add the URL with action STATUS



http://<host or IP>:<PORT>//AdapterFramework/ChannelAdminServlet?party=Party_VAN&service=VAN_Provider&channel=*&action=STATUS


Now lets stop all the channels from LaMa:






    1. Go to Operations -> Hosts

    2. Find the host that you put the constraint on. In my case I put it on a4h-vm1. Now click Operations -> PI Channel -> PI_CHANNEL_STOP_ALL





3. On the next screen fill in the parameters as needed. Example below:



4. Click Execute on the next screen


The channels should have stopped. Let's verify via the browser:
http://<host or IP>:<PORT>//AdapterFramework/ChannelAdminServlet?party=Party_VAN&service=VAN_Provider&channel=*&action=STATUS


You can also do the reverse and start the channel by creating another custom operation.


2.0 HTTP Post Service


2.1 Create Provider Definition



  1. Go to Automation Studio -> Provider Definitions -> Create


Enter the following to stop a specific channel



Provider Type: HTTP POST

Name: pi_channel_stop_party_van

URL: http://<host>:<port>//AdapterFramework/ChannelAdminServlet?party=Party_VAN&service=VAN_Provider&chan...

Username: <username>

Password: <your password>

Operation Uses: Host

 


Save Provider



2.2 Create Custom Operation


1. Go to Automation Studio -> Custom Operations -> Create



2. Click on the newly created custom operation



3. Click on constraints. This is an optional step. We want to restrict the operation to be selectable from a single host. This does not mean the operation occurs on this host. The host in the URL is the one that determines where it will be executed.


4. Click Add Constraint and then fill out the constraint details





2.3 HTTP Post Service Test


First let's check that the channel is running. Go to a browser and add the URL with action STATUS



http://<host or IP>:<PORT>//AdapterFramework/ChannelAdminServlet?party=Party_VAN&service=VAN_Provider&channel=1_ReceiveBulkOrdersFromVAN_AS2_Sender&action=STATUS

OUTPUT:

<ChannelAdminResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xx:xx/AdapterFramework/channelAdmin/ChannelAdmin.xsd">
<Channels>
<Channel>
<Party>Party_VAN</Party>
<Service>VAN_Provider</Service>
<ChannelName>1_ReceiveBulkOrdersFromVAN_AS2_Sender</ChannelName>
<ChannelID>4b51da227b253e08865cc70b6554066a</ChannelID>
<AdapterType>AS2</AdapterType>
<Direction>INBOUND</Direction>
<ActivationState>STARTED</ActivationState>
<ChannelState>OK</ChannelState>
<Control>WEBSERVICE</Control>
</Channel>
</Channels>
</ChannelAdminResult>

Now lets stop the channel from LaMa:






    1. Go to Operations -> Hosts

    2. Find the host that you put the constraint on. In my case I put it on a4h-vm1. Now click Operations -> PI Channel -> PI_CHANNEL_STOP_PARTY_VAN





3. Click Execute on the next screen


The channel should have stopped. Let's verify via the browser:
http://<host or IP>:<PORT>//AdapterFramework/ChannelAdminServlet?party=Party_VAN&service=VAN_Provider&channel=1_ReceiveBulkOrdersFromVAN_AS2_Sender&action=STATUS


 

You can also do the reverse and start the channel by creating another custom operation.

References

For more information on Automation Studio please refer to:

  1. https://blogs.sap.com/2020/02/28/sap-landscape-management-lama-automation-studio/

  2. SAP Landscape Management Enterprise 3.0 User Guide

  3. https://blogs.sap.com/2020/06/08/outgoing-api-calls-from-sap-landscape-management-lama-with-automati...