On-Demand-Schedulers With MuleSoft CloudHub APIs – DZone – Uplaza

In some tasks, there may be many scheduler-based purposes, and the testing staff from both supply or goal methods does not have entry to the Anypoint platform to run schedulers at any time when required; thus, having to depend on MuleSoft builders to run the schedulers for them. On this article, you’ll discover ways to create a easy internet web page utilizing HTML for fetching the person’s enter and use CloudHub APIs to run the schedulers primarily based on the person’s inputs supplied.

This can save numerous time for the testing staff to check the mixing within the decrease environments. I’d suggest not utilizing this for testing in manufacturing as if somebody misuses it by working the schedulers extra continuously, then integration may break.

Implementation

Step 1

Go to Anypoint platform and create a Linked App in Entry Administration for utilizing CloudHub APIs. Restrict the scope of the Linked App to Runtime Supervisor solely. You may undergo this MuleSoft doc to discover ways to create a Linked App in Entry Administration. 

Copy the Shopper ID and Secret, which might be used for fetching the access_token to authenticate requests for CloudHub APIs.

Step 2

Create a brand new Mule software in Anypoint Studio and create the next HTML information inside src/most important/assets:

  • purposes.html
  • homepage.html
  • invalidCredentials.html
  • notfound.html
  • schedulers.html
  • signin.html
  • thankyou.html

First, create the circulate as proven under. That is the entry level of the applying which can open the Signin internet web page utilizing the Parse Template element. 

signin.html

Within the above HTML, the type tag’s motion attribute ought to name the endpoint of the mule circulate “run-scheduler-environments” (listening to the endpoint /environments) as proven within the Mule picture under. The strategy needs to be POST in order that the credentials don’t get displayed within the URL.

On the internet web page above, you’ll have to enter the username and password for the non-prod/prod setting through which you need to run the scheduler. The credentials for non-prod and prod environments are managed within the properties file. The Mule circulate, as proven under, will validate the credentials and proceed additional to get the setting particulars. If the credentials are invalid, then it will not proceed additional, and you’re going to get an error message.

invalidCredentials.html






Invalid Username or Password !!


Right here, within the above HTML, the shape tag’s motion attribute ought to name the Mule circulate “run-scheduler-onDemandSchedulers,” listening to the endpoint /onDemandSchedulersShould you click on on the Go Again button, it would take you to the sign-in web page once more.

Step 3

To ship a request to CloudHub APIs, you should generate the entry token by utilizing the next curl:

curl --location 'https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token' 
--header 'Content material-type: software/json' 
--data '{
    "client_id": "{{client_id}}",
    "client_secret": "{{client_secret}}",
    "grant_type": "client_credentials"
}

Right here, the client_id and secrets should be handed from Step 1. The response that you’re going to get is proven under. Retailer the access_token within the object retailer and set the Entry TTL property to 3600 (identical because the expires_in property within the response). This can be sure that the important thing expires after 3600 seconds.

Implement the above logic within the Mule circulate as proven under.

Step 4

After credentials are validated on the Signal-in web page, that you must name the endpoint (https://anypoint.mulesoft.com/accounts/api/organizations/{{orgID}}/environments) to get the record of environmentsYou’ll get the response as proven under. You’ll get the group ID within the URL of the Anypoint Platform Dwelling Web page.

Implement the above logic utilizing Mule as proven under.

Step 5

Non-Prod Environments

When the person indicators in with non-prod setting credentials, the non-prod setting names and IDs are filtered out of the payload, and the values are handed to the homepage.html.

homepage.html

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version