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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Idempotency Under Concurrency: Why Your Application Check Isn't the Last Line of Defense
  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine
  • Your Application Has an Unindexed Attack Surface. Do You Know What’s in It?
  • Retrieval Augmented Generation With Spring AI 2.0, Claude, and PGvector

Trending

  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty
  • GenAI Security Gateway: An End-to-End Architecture
  • Spring AI on Local LLMs
  • Microsoft Fabric Throttling: Diagnose Before You Scale

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

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
·
Feb. 26, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
5.9K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Idempotency Under Concurrency: Why Your Application Check Isn't the Last Line of Defense
  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine
  • Your Application Has an Unindexed Attack Surface. Do You Know What’s in It?
  • Retrieval Augmented Generation With Spring AI 2.0, Claude, and PGvector

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook