Skip to Content
Technical Articles
Author's profile photo vinay mittal

Deploy / Un-Deploy All Integration artifacts on SAP CI Cloud foundry – A Self Conscious iFlow

Introduction: 

I recently had a requirement to automate the deployment / Un-Deployment of iFLOW’s in SAP CI and as what anyone would do I tried to search if someone has already achieved this and better shared it for everyone to use.

I have come across two recent blogs on deploying and Un-Deploying all iFLOW’s in SAP CI.

This one for Neo

https://blogs.sap.com/2020/02/07/bulk-deploy-undeploy-cpi-artifacts/

This solution is great but requires manual intervention like selecting all iflows or keeping track of what you undeployed in past and then the onus of deploying only what you undeployed lies on you. Suppose you undeployed 200 iFlows its on you to remember what you undeployed at the time of bringing down the tenant.

Moreover the API’s used in this solution some of them are deprecated in CF and work only on neo.

 

and

This one for Cloud Foundry (I assume)

https://blogs.sap.com/2023/06/15/sap-cloud-integration-system-downtime-handling-by-automatic-deployment-and-undeployment-of-the-iflows/

This solution works only for a single iflow at a time which renders it impractical to use given you will have to configure your iflow 100 times and deploy it 100 times just to bring everything down or deploy everything.

Also It doesnt remember which iFlows/artifacts it had undeployed previously.

Solution:

Download Link:

Download Link

I have created this iFLOW which requires minimal intervention and takes care of the entire deployment and un-deployment process seamlessly. The iFLOW can be downloaded from the link above.

 

Configuration: 

This iFlow when deployed with parameter BRING_TENANT_DOWN brings down all SAP CPI iFlow’s, Script Collections, Value Mappings, Message Mappings and ODATA_Services , Rest API’s and SOAP API’s And logs the list of iFlows along with artifact type as a MPL attachment for referencing it later. This iFlow also creates a data store entry of all the artifacts it undeployed for future use.

 

When deployed with BRING_TENANT_UP it deploys the Artifacts it undeployed by referencing the data store entry of the list of all the iFlows.

There are artifacts like SOAP API’s , REST API’s , ODATA Services which cannot be Deployed via an API (SAP is working on exposing deploy/Un-Deploy functionality via ODATA API’s). This iFlow creates a separate MPL attachment for such artifacts that need manual deployment.

 

How It Works:

This iFLOW deploys and Un-Deploys everything other then itself – Do not change the iFLOW ID.

 

iFLOW Overview

 

Step1: Create a instance of type Process Integration , Plan api in BTP Cockpit and then create a service key of type client_credentials and use the url in the service key to configure the iFLOW

 

Step 2: Create OAUTH credentials in Security Material

 

Step 3: If you want to bring the tenant down configure parameter as BRING_TENANT_DOWN and deploy the iFlow.

 

iFlow will execute and will get the whole list of deployed artifacts, it will then un-deploy each and every artifact including script Collections, Message mappings, Value mappings, REST , SOAP API’s ODATA Services and iFlows (except itself).

The iFLOW will create a MPL attachment with the list of artifacts it undeployed for auditing purpose

This is how the MPL attachment looks

 

The iFlow also creates a Data store entry for tracking what it undeployed so that when you re deploy the iflow with BRING_TENANT_UP Later it can refer this entry and bring up exactly what you brought down.

 

Step 4: You now want to bring your tenant up. You now configure the parameter as BRING_TENANT_UP and re deploy the iFlow. the iFlow runs only once.

 

The iFLOW then runs and refers the data store entry and brings back up each and every artifact EXCEPT ODATA Services , REST API’s , SOAP API’s. It creates two MPL attachments.

a) Artifacts that need manual deployment (Odata, SOAP, REST API’s)

b) List of artifacts it deployed

 

 

 

 

Key features:

The way SAP CI ODATA API’s work in CF is that every different artifact type has a separate ODATA API for deployment but they all have a common Un-Deploy API.

The iFLOW allows you to add the deployment api’s whenever SAP makes these available in future , you just need to update the below groovy script in the iFlow

/* Refer the link below to learn more about the use cases of script.
https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/148851bf8192412cba1f9d2c17f4bd25.html

If you want to know more about the SCRIPT APIs, refer the link below
https://help.sap.com/doc/a56f52e1a58e4e2bac7f7adbf45b2e26/Cloud/en-US/index.html */
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
    //Body
    
    //Properties
    def properties = message.getProperties();
    def artifactID = properties.get("artifact_id");
    def artifactType = properties.get("artifact_type");
    
    def resource = '';
    def query = '';
    
    //   /api/v1/DeployIntegrationDesigntimeArtifact?Version='active'&Id=''

    
    switch (artifactType) 
    {
      case 'INTEGRATION_FLOW':
          resource = '/api/v1/DeployIntegrationDesigntimeArtifact';
          query = 'Version=\'active\'&Id=\''+artifactID+'\'';
        break;  


      case 'ODATA_SERVICE':
          resource = '';
          query='';
        break;
        
      case 'VALUE_MAPPING':
          resource = '/api/v1/DeployValueMappingDesigntimeArtifact';
          query = 'Version=\'active\'&Id=\''+artifactID+'\'';
        break;  
        
      case 'MESSAGE_MAPPING':
          resource = '/api/v1/DeployMessageMappingDesigntimeArtifact';
          query = 'Version=\'active\'&Id=\''+artifactID+'\'';
        break;  
        
      case 'SCRIPT_COLLECTION':
          resource = '/api/v1/DeployScriptCollectionDesigntimeArtifact';
          query = 'Version=\'active\'&Id=\''+artifactID+'\'';
        break;
        
      case 'SOAP_API_PROVIDER':
           resource = '';
          query='';
        break;
      case 'REST_API_PROVIDER':
           resource = '';
          query='';
        break;
      case 'JDBC_DRIVER':
           resource = '';
          query='';
        break;
      default:
         resource = '';
          query='';
        break;
      
      
      
        
    }
    
    message.setProperty("resource", resource);
    message.setProperty("query", query);
    
    return message;
}

 

Advantages over other solutions: 

This requires minimal intervention and you can schedule the timer after configuring it with a parameter to either bring the tenant up or down at a time and date of your choosing

Works not just for iFLOWS but for all other artifacts while other solutions work just for iFlows. It also has provision for future enhancements when SAP delivers the ODATA API’s for deploying ODATA Services, REST API’s and SOAP API’s right now these are missing.

This iFLOW wont undeploy JDBC Drivers or Integration adapters.

While some may argue what is the need of undeploying Script collection etc yes there is no need but I wanted the solution to be complete and future proof.

This iFLOW remembers exactly what it undeploys , logs every event for any mishaps and refers the data store entries to bring back only those artifacts that we undeployed.

This iFLOW deletes the data store entry once the tenant is brought back up. Any attempt to bring the tenant up if the data store entry is deleted OR if you try to bring the tenant up without actually bringing the tenant down first will fail.

follow the order – BRING_TENANT_DOWN , Deploy and then BRING_TENANT_UP, deploy.

Happy coding.

 

Version 2: Updated iFlow on  download link on suggestions from Daniel Graversen To Deploy Script collections, Value mappings, Message mappings first.

Assigned Tags

      18 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Morten Ingebridsen
      Morten Ingebridsen

      Hello Vinay,

       

      This is indeed a brilliant solution I went through the entire flow and set it up in my landscape and it worked in the very first run, I must say setup is very simple and it works with minimum manual effort. Keep blogging and thanks for this nice utility.

      I like the way it remembers what it un deployed as we have more than 300 iflows and during cutovers bringing all iflows down via the other solutions you mentioned was tough and time consuming (trust me we tried them). Thanks for this.

      cheers.

      Morten

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      Thank you Morten , Happy to know it helped you.

      Author's profile photo Chiranjeevi A
      Chiranjeevi A

      Nice blog, vinay mittal
      Thanks for sharing !!

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      Thank you Chiranjeevi

      Author's profile photo Priyanka Badase
      Priyanka Badase

      Hello Vinay,

       

      I have tried your solution, but I am facing issue in Oauth client credential.

      Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: Jwt token with allowed audiences

      I am getting this http response headers.

      Please suggest.

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      Hello Priyanka

       

      What is the token service url that you have maintained in security material?

       

      Regards

      vinay

      Author's profile photo Priyanka Badase
      Priyanka Badase

      I am using below URL and deployed credential as OAuth2 Client Credentials

      https://xxxxxx.authentication.ap11.hana.ondemand.com/oauth/token

       

      I have tried with below URL as well but getting unsupported grant type

      https://xxxxxxxx.authentication.ap11.hana.ondemand.com/oauth/token?grant_type=client_credentials

      Generated this from configuring service-key.

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      This is the right format i think you already tried it

      https://xxxxxx.authentication.eu20.hana.ondemand.com/oauth/token

       

      try to get the access token via postman and see if you get the access token

       

      Author's profile photo Priyanka Badase
      Priyanka Badase

      Yes, I am getting access token

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      can you share screenshot of configuration of your http adapter ? all the tabs

      Author's profile photo Priyanka Badase
      Priyanka Badase

      Please check error and http adapter screenshot

      Author's profile photo Sufiyan Sayed
      Sufiyan Sayed

      I had the same error because of wrong credentials, After the error I copied all the required credentials from cloud foundry -> Process integration runtime instance (Type: api) instead of (Type: integration flow) and it worked fine for me.

      Author's profile photo Priyanka Badase
      Priyanka Badase

      Thanks Sufiyan. Now , it is working for me 🙂

       

      vinay mittal Thanks for making such a wonderful blog. It is really helpful.

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      I am glad it helped Priyanka and Sufiyan Sayed great work mate.

      Author's profile photo Sufiyan Sayed
      Sufiyan Sayed

      Hi Vinay,

       

      I've followed your instructions but getting error while invoking the tenant in HTTPS adapter,

      Below I've provided the screenshot of the error. Please let me know.

       

      Regards,

      Sufiyan.

       

       

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      Hello Sufiyan,

       

      How did you get this url ? you have to create a service key of type "api" for instance of type "process integration runtime" and credential type should be "client_credentials". You should try to see if this url https://xxxxx.cfapps.us10-001.xxxxx/api/v1 works in postman for you. I suspect it wont as the url has issues.

       

      Regards

      Vinay

      Author's profile photo Sufiyan Sayed
      Sufiyan Sayed

      Hi Vinay,

       

      Actually I was trying to give Client Id and secret from integration flow's instance instead of api. Now I've tried with the api instance and it worked perfectly fine. Thankyou so much for the answer and keep making such wonderful blogs.

       

      Thanks & regards,

      Sufiyan.

      Author's profile photo vinay mittal
      vinay mittal
      Blog Post Author

      I am glad it worked Sufiyan.