In some initiatives, there is perhaps many scheduler-based functions, and the testing group from both supply or goal techniques would 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 learn 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 offered.
It will save a whole lot of time for the testing group to check the mixing within the decrease environments. I’d advocate not utilizing this for testing in manufacturing as if somebody misuses it by operating the schedulers extra ceaselessly, then integration would possibly 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’ll be able to undergo this MuleSoft doc to learn to create a Linked App in Entry Administration.
Copy the Consumer 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 utility in Anypoint Studio and create the next HTML recordsdata inside src/primary/assets:
- functions.html
- homepage.html
- invalidCredentials.html
- notfound.html
- schedulers.html
- signin.html
- thankyou.html
First, create the circulate as proven beneath. That is the entry level of the appliance which is able to 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 beneath. The strategy must 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 during 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 beneath, 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 /onDemandSchedulers
. When you click on on the Go Again button, it’ll take you to the sign-in web page once more.
Step 3
To ship a request to CloudHub APIs, you have to generate the entry token by utilizing the next curl
:
curl --location 'https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token'
--header 'Content material-type: utility/json'
--data '{
"client_id": "{{client_id}}",
"client_secret": "{{client_secret}}",
"grant_type": "client_credentials"
}
Right here, the client_id
and secret
s should be handed from Step 1. The response that you’re going to get is proven beneath. 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). It will be sure that the important thing expires after 3600 seconds.
Implement the above logic within the Mule circulate as proven beneath.
Step 4
After credentials are validated on the Signal-in web page, you want to name the endpoint (https://anypoint.mulesoft.com/accounts/api/organizations/{{orgID}}/environments)
to get the record of environments. You’ll get the response as proven beneath. You’ll get the group ID within the URL of the Anypoint Platform House Web page.
Implement the above logic utilizing Mule as proven beneath.
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
.