GithubHelp home page GithubHelp logo

automated-api-promotion's Introduction

Documentation

Use this script to easily promote your APIs and applications from one environment to the other. The script execution is fully configurable, so it can support all the environments and promote APIs and applications in any direction.

The tool also solves the problem stated below:

How to make application aware of the new API Version for auto-discovery purposes without the need to update application itself and build a new package.

Supported scenarios are:

Scenarios

  • Promote API together with application (fresh deployment).
  • Promote API Instance (the original one won't be used anymore - will be switched to Inactive state) and patch existing application on target server.
  • Patch existing application on the target servers - no updates in API Instance / new application version will register with the same API Instance as the old version.

Project also contains prebuild Jenkins pipeline for "one click" deployment to provide some idea on how this tool could be used in terms of CICD.

Prerequisite

  • Installed Node.js
  • Set environment variables:
    • ANYPOINT_USER - user with permission to promote APIs (deployment user)
    • ANYPOINT_PASSWORD - user password

Supported versions

Configuration

Sample Config File

Config:
  Organisation: "IRMulesoftCrowd"		//your organisation / business group
  SourceEnvName: "TEST"				//name of environment configure on ARM
  SourceServerName: "ContainerizedCluster"	//source runtime name - could be server or cluster
  SourceServerType: "CLUSTER"			//supported types are SERVER or CLUSTER
  TargetEnvName: "PROD"				//name of environment configured on ARM
  TargetServerName: "joker"			//target runtime name - could be server or cluster
  TargetServerType: "SERVER"			//supported types are SERVER or CLUSTER
  Applications:					//all the applications running on source runtime that should be promoted to target runtime
    - 
      appName: "ir-s-customer"			//application name as displayed on the source server
      apiInstanceId: 9546857			//API Instance ID application is registered with

How to run

  1. Update configuration file as per your requirements
config/promotion_config.yml
  1. Use npm to install project dependencies
npm install
  1. Run script app.js to:
    1. Pormote API Instances and applications
    node src/app.js
    
    1. Promote Applications only - patch applications without any updates in registration with API Manager
    node src/app.js app-only
    

APIs and Applications promotion and auto-discovery

Chapter describes how to enable auto-discovery for APIs and applications that have been promoted.

Auto-discovery requires API Version to be configured within the application <api-platform-gw:api apiName="${api.name}" version="${api.build.version}:${api.instance}" flowRef="api-main" create="true" apikitRef="api-config" doc:name="API Autodiscovery" />. See documentation for more details here. The API Version is generated as part of the API promotion process (once API Instance is created on specific environment), however application must be aware of the API Version in API Manager to register with API Manager.

The problem statement the solution solves is: How to make application aware of the new API Version for auto-discovery purposes without the need to update application itself and build a new package. - so an application can be easily promoted instead of doing standard deployment / redeployment.

Restrictions

The tool has been tested for Mule runtime 3.9.0. Please note, that there are some deviations from Mule runtime 4 auto-discovery configuration. More details could be found here.

The tool doesn't support application promotion only, if it is a fresh deployment (target server is not running the application yet) without API promotion and registration.

Capturing API Version

How to capture API Version and make it available for application.

After running the command node src/app.js API Instances are promoted and API Instance IDs captured, so each application can be registered with proper API Instance as part of the next step: promotion of applications. The script creates a pairs of origin API Instance ID and newly generated API Instance ID (ID of promoted API Instance on the target environment), so it can easily identify what application needs to use what API Instance ID.

Captured API Instance ID is then used and added to properties in application's settings, as displayed on picture below: Settings

Project configuration

How to configure the project / application to use a new API Instance ID generated by promoting the instance from lower environment.

1. Step: Configure auto-discovery

Sample
<api-platform-gw:api apiName="${api.name}" version="${api.build.version}:${api.instance}" flowRef="api-main" create="true" apikitRef="api-config" doc:name="API Autodiscovery" />

2. Step: Configure Maven to enable filtering of application directory. Add the following to your pom.xml for plugin mule-app-maven-plugin: <filterAppDirectory>true</filterAppDirectory>.

Sample - Maven plugin
<plugin>
  <groupId>org.mule.tools.maven</groupId>
  <artifactId>mule-app-maven-plugin</artifactId>
  <version>${mule.tools.version}</version>
  <extensions>true</extensions>
  <configuration>
    <copyToAppsDirectory>true</copyToAppsDirectory>
    <filterAppDirectory>true</filterAppDirectory>
  </configuration>
</plugin> 

Also, add a new Maven property <api.build.version>v1</api.build.version>. The value must match the API Specification version in RAML (and in Exchange / API Manager).

Sample - Maven property
  <properties>
    <api.build.version>v1</api.build.version>
    
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <mule.version>3.9.0</mule.version>
    <mule.tools.version>1.2</mule.tools.version>
    <maven.assembly.plugin.version>3.0.0</maven.assembly.plugin.version>
    <maven.release.plugin.version>2.5.3</maven.release.plugin.version>
    <munit.version>1.3.7</munit.version>
    <mule.munit.support.version>3.9.1</mule.munit.support.version>
  </properties>

How does the configuration described above work?

Maven uses property <api.build.version>v1</api.build.version> to filter application folder, which replaces variables in configuration of auto-discovery: version="${api.build.version}:${api.instance}". For this specific example we would get: version="v1:${api.instance}". Property from settings api.instance is then used during the application deployment / start up to replace variable ${api.instance}, so finally we are getting version="v1:9547246" and auto-discovery is enabled (for Mule 4 the API Instance ID is used instead of full api version, however it is NOT currently supported by the script).

Continues Deployment

Project also contains Jenkinsfile with simple pipeline definition for easy integration with Jenkins. Pipeline implements "one click" deployment and is configured to be triggered manually. The same environment variables as mentioned in Prerequisite section must be configured on Jenkins server.

Pipeline consists of the following stages:

1. Stage: Promote APIs and Applications (exectues when build parameter APP_ONLY == false): runs command node src/app.js

2. Stage: Promote Applications only (executes when build parameter APP_ONLY == true): runs command node src/app.js app-only

Roadmap

  • API Manager: Promoting an API - IMPLEMENTED
  • Promote to more than one target in parallel
  • Cloudhub support
  • Mule 4 support

Not Supported Functionality

Deployment of external properties file is not supported. Properties file must be copied to server before this script runs.

Every API Instance promotion would create a new API Instance on target environment. Patching of API Instance is not supported.

Notes

  • Custom policies are supported. The tool will promote API Instance with all the configured policies, custom policies included.

  • New API Instance creation means that your client applications must request access for this new version (e.g. if Client ID enforcement policy has been applied).

  • Impact on Analytics yet to be clarified.

  • Difference between API Instance ID and API Version can be seen in API Manager as highlighted on the picture below: API Instance ID vs API Version

automated-api-promotion's People

Contributors

igor-repka avatar

Stargazers

Juan Martin Porcel avatar José da Gama avatar Paul Gardner avatar Chandra (tckb) avatar  avatar Soo Kang Wei avatar Marc Escalona avatar Smita Lawande avatar Jonathan Ben-Hamou avatar  avatar  avatar Adam Pridmore avatar

Watchers

James Cloos avatar Smita Lawande avatar  avatar Daniel Moellenbeck avatar Mike Hamilton avatar Ettore Giallaurito avatar  avatar

automated-api-promotion's Issues

API Promotion to cluster MuleESB nodes

Hi Team,

Query-
Could you please advise if this promotion tool will promote both API/API Instances to both the nodes in the Cluster configuration having two nodes in the same network?

Nodes:targetserver1 & targetserver2 (two nodes)
Hope the targetserver type will be cluster?

For that shall I enter the below in promotion_config.yml

Organisation: "IRMulesoftCrowd"
SourceEnvName: "TEST"
SourceServerName: "ContainerizedCluster"
SourceServerType: "sourceserver"
TargetEnvName: "Pre-Prod"
TargetServerName: "targetserver1,targetserver2"
TargetServerType: "CLUSTER"
Applications:

appName: "ir-s-customer"
apiInstanceId: 9546857

Thanks,
Siddharth

Auto discovery not registered during promotion from server to cluster Environment

Hi Igor,

When I promote to Pre-Prod clustered Env from SIT server Environmnet, API’s are not getting registered. Seeing below error in Mule Logs

ERROR 2019-01-02 16:10:23,851 [agw-policy-polling.01] com.mulesoft.module.client.APIPlatformPoliciesRunnable: There was an error retrieving policies (API {name='groupId:108638e7-996b-405a-aa11-0e9b584839ce.general-insurance:assetId:exp-web-gi-ui-sq-qab-mgmt', version='v1:${api.instance}'}). Reason: Missing API information from API Platform

Whatever you had advised I’ve done that in –

<api-platform-gw:api apiName="${api.name}" version="${api.build.version}:${api.instance}" flowRef="sys-policy-mgmt-main" create="true" apikitRef="sys-policy-mgmt-config" doc:name="API Autodiscovery"/>

Should we remove the api.instance from the global autodiscovery configuration element? Not sure how that worked for CIT to SIT.
https://github.com/mulesoft-consulting/automated-api-promotion

Api.instance is defined only in CIT.prop as source and not in SIT & PPTE properties file.

Flow is CIT (deploy) ->SIT(promote) ->PPTE (promote)

Green ones promotion works fine.

Thanks,
Siddharth

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.