DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Power BI Embedded Analytics — Part 3: Power BI Embedded Demo
  • DGS GraphQL and Spring Boot
  • Auto-Instrumentation in Azure Application Insights With AKS
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

Trending

  • What’s Got Me Interested in OpenTelemetry—And Pursuing Certification
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • Proactive Security in Distributed Systems: A Developer’s Approach
  • How To Build Resilient Microservices Using Circuit Breakers and Retries: A Developer’s Guide To Surviving

Scheduled Restart on CloudHub

Have you ever been required to restart applications in CloudHub at a specific time of the day on weekdays? Automate it with CloudHub API and make life easier.

By 
Vince Soliza user avatar
Vince Soliza
·
Feb. 26, 16 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
5.4K Views

Join the DZone community and get the full member experience.

Join For Free

Have you ever been required to restart applications in CloudHub at a specific time of the day on weekdays? For example, in a testing environment when the app should be restarted at the beginning of the day before the testers commence their duties. This might sound simple as it's just few clicks to restart an application in CloudHub.

But...

What if you have a different shift and you're unable to do it on time?

What if one day you forgot to do it?

What if there are too many applications to restart?

The solution is to make this thing automated, but how? No problem, we can do it by utilizing CloudHub API and a time-based job scheduler.

What do we need?

  • Access to CloudHub API service: https://anypoint.mulesoft.com/cloudhub/api/applications/{domain}/status

  • X-ANYPNT-ENV-ID: The environment where the application deployed example: 6ebdb30c-b6bf-4d75-b8ba-61cb87b5ed4b

  • Domain - The application domain example: cloudhub-restarter

  • Anypoint Platform for API account with 'Manage Settings' role.

  • A Time-based job scheduler example: CRON, Mulesoft Poll Scheduler

After we got all of the things we need, let's create the application in Mule with a scheduled restart at 6:00 AM every weekdays.

This simple flow used Poll Scheduler to configure a polling schedule using cron expressions. When the given schedule is attained it will invoke the CloudHub REST API to restart the application using the defined values in the properties.

Image title

Put the environment id, username, and password in mule-app.properties. Replace {domain} with the application domain you want to be restarted.

Image title

Here's the Mule configuration XML.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:schedulers="http://www.mulesoft.org/schema/mule/schedulers"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/schedulers http://www.mulesoft.org/schema/mule/schedulers/current/mule-schedulers.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<http:request-config name="HTTP_Request_Configuration"
protocol="HTTPS" host="${cloudhub.restapi.host}" port="${cloudhub.restapi.port}"
basePath="${cloudhub.restapi.base.path}" doc:name="HTTP Request Configuration">
<http:basic-authentication username="${anypoint.platform.account.username}"
password="${anypoint.platform.account.password}" />
</http:request-config>
<flow name="cloudhub-restarterFlow">
<poll doc:name="Poll">
<schedulers:cron-scheduler expression="${cloudhub.restart.schedule}" />
<flow-ref name="invoke-restart-Flow" doc:name="invoke-restart-Flow" />
</poll>
<logger message="The Application has been restarted." level="INFO"
doc:name="Logger" />
</flow>
<flow name="invoke-restart-Flow">
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
"status":"restart"
}]]></dw:set-payload>
</dw:transform-message>
<http:request config-ref="HTTP_Request_Configuration"
path="${cloudhub.restapi.application.status.endpoint}" method="POST"
doc:name="HTTP">
<http:request-builder>
<http:header headerName="X-ANYPNT-ENV-ID"
value="${anypoint.platform.environment.id}" />
</http:request-builder>
</http:request>
</flow>
</mule>

See how simple, fast, and easy CloudHub RESTful API can be used, if we explore more there is more than just restarting that we can do with the help of this API. See the full API reference.

Please leave a comment :)

application

Opinions expressed by DZone contributors are their own.

Related

  • Power BI Embedded Analytics — Part 3: Power BI Embedded Demo
  • DGS GraphQL and Spring Boot
  • Auto-Instrumentation in Azure Application Insights With AKS
  • Deploying a Scala Play Application to Heroku: A Step-by-Step Guide

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!