Skip to content

Latest commit

 

History

History
271 lines (189 loc) · 14.6 KB

hello-world-on-cloudhub.adoc

File metadata and controls

271 lines (189 loc) · 14.6 KB

Deploy to CloudHub

This tutorial covers how to create an Anypoint Platform organization, how to modify a Mule project to make it CloudHub-ready and then how to deploy it to the cloud via the Anypoint Platform, via Anypoint Studio. It also includes a section on how to do the same via the command line.

Completing this tutorial should take about 20 minutes. You will accomplish the following:

  • Create an account and organization in the Anypoint Platform

  • Optionally modify a simple hello world example mule application so that it runs on CloudHub

  • Upload, deploy, and run a Mule project

Tip
Take a look at Deployment Strategies and CloudHub so that you’re familiar with what CloudHub is vs other alternatives for deploying your Mule applications.

Create an Anypoint Platform Organization

To deploy applications to CloudHub, you first need to create an Anypoint Platform account and organization.

  1. Go to https://anypoint.mulesoft.com to create a new account in a new organization.

    Note
    Otherwise, if you want your account to be part of an existing organization, ask the administrator of that organization to invite you to join it, then create your account via the link she sends to you.
  2. Enter your information, choose a username and password, then click Create account. Your new user account is now created, if you aren’t joining an existing organization, then a new organization is created too and your user is made its administrator.

Note
After you’ve created your account, you can use CloudHub for one month with a single resource unit, or "worker". If you need additional resources or would like to continue using CloudHub, you can sign up for a paid subscription.

Edit the Hello World Tutorial for CloudHub

The application built on the How to Create a Mule App needs some slight adjustments to be able to run on CloudHub, you must modify its HTTP connector so that:

  • Its host is set to 0.0.0.0

  • Its port is set to the property ${http.port}

Tip

Any application that includes HTTP connectors needs to have its host set to 0.0.0.0 and its port to ${http.port}. CloudHub can then dynamically allocate a port at deployment time.

See Developing Applications for CloudHub for more details.

You can either:

To make these changes to the project, you must:

  1. Open the project in Studio. If you’ve created the hello world example yourself by following the tutorial, then you should already have this in an Anypoint Studio project. Otherwise, download the Hello World project and then import it into Anypoint Studio as a general deployable archive.

    Tip
    See Importing into Studio for more detailed instructions.
  2. Find the HTTP Connector in the flow and click it to view its properties editor

    http1

  3. Click the green plus sign next to the Connector Configuration field to open its global element settings.

  4. Edit the Host and Port fields:

    • Set the Host to 0.0.0.0.

    • Set the Port to: ${http.port}

    Field Value

    Name

    HTTP_Listener_Configuration

    Host

    0.0.0.0

    Port

    ${http.port}

  5. Click Ok to close this dialog.

    Note

    Optional step: to Deploy Your App Anywhere

    Because you’ve put a property placeholder in the Port field, your app is now compatible with CloudHub, but not with other Deployment Strategies.

    CloudHub dynamically allocates a value to this property at deploy time, but for other deployment strategies you need to assign it a default concrete value. To do so, you must edit the mule-app.properties file, found in the src/main/app folder of your project.

    1. In your Package Explorer (on the left of the Studio screen), open the node src/main/app.

    2. Double-click the mule-app.properties file to open it.

    3. In this file, type in the line http.port=8081 and save it.

  6. Save your changes to the project.

Deploy Via Studio

If you have your project open in Studio, then the easiest way to deploy it to CloudHub is to do so directly from the editor:

  1. Right-click on the project node, basic_tutorial in the Package Explorer, and then select CloudHub > Deploy to Anypoint Platform > Cloud.

    deploy+to+cloudhub

  2. If this is your first time deploying in this way, a popup menu asks you to provide your login credentials for the Anypoint Platform. Studio stores your credentials and uses them automatically the next time you deploy to CloudHub.

    Tip
    You can manage these credentials through the Studio Preferences menu, in Anypoint Studio > Authentication.
  3. Choose a unique domain under which to deploy the application, for example helloworld.

    The domain name can be up to 42 characters. A green confirmation check mark is displayed.

  4. Select an environment to deploy your application (such as PRODUCTION or QA).

  5. Select the Mule Runtime

    Tip
    To reduce compatibility risks, you should always deploy to the runtime version in which your Mule project is created or the closest alternative. If in doubts, you can check your project’s mule-project.xml file.
  6. Click Deploy Application.

    studio+to+cloudhub2-1

  7. Anypoint Studio packages, uploads, and deploys your application to CloudHub.

Tip
For more details about the different deployment settings, see Deploying to CloudHub.

Deploy Via Anypoint Platform

Note

If you create the project yourself in Studio by following the tutorial, you must then export it as a deployable .zip file. To do so, go to File > Export and then select Anypoint Studio Project to Mule Deployable Archive.

See Exporting from Studio for more detailed instructions.

  1. Log into your Anypoint Platform account. You’ll be directed to the landing page.

    hello world on cloudhub 6df18

  2. Click the Runtime Manager link to reach the Runtime Manager dashboard.

  3. On the Aplications tab (selected by default), Click Deploy application.

    hello world on cloudhub 45c14

  4. Choose a unique domain under which to deploy the application, for example helloworld.

    The domain name can be up to 42 characters. A green confirmation check mark is displayed.

  5. Select an environment to deploy your application (such as PRODUCTION or QA).

  6. Select the Mule Runtime

    Tip
    To reduce compatibility risks, you should always deploy to the runtime version in which your Mule project is created or the closest alternative.
  7. Click Choose File and select the ink:_attachments/basic-tutorial.zip[.zip file that you downloaded] from this tutorial or that you exported from Studio.

  8. Click Deploy Application.

    studio+to+cloudhub2-1

  9. Anypoint Studio packages, uploads, and deploys your application to CloudHub.

Tip
For more details about the different deployment settings, see Deploying to CloudHub.

Running Your App

Once the deployment is complete (which could take a few minutes), browse to the URL of yourdomain.cloudhub.io.

In this example, it should be helloworldtest.cloudhub.io. You should see the text "Hello World!"; recall that the application listens for HTTP calls on the root address, sets the payload to the string "Hello World!" and then returns this string as a response to the requester.

CH_HelloWorld_displayed-1

This proves you have successfully deployed a Mule application to your new Anypoint Platform account!

Tip
Visit https://anypoint.mulesoft.com to manage your application through the Runtime Manager, access its dashboard, view logs and alerts, and more.

Deploying via the Command Line

This section explains how to perform the same deployment actions as shown above, but all via the CloudHub CLI (Command Line Utility).

Before starting, make sure you enable CloudHub access on your Anypoint Platform account.

Tip
You can see a reference to a full list of CLI commands for Anypoint Platform here
  1. Download the modified CloudHub-ready Hello World project, by clicking here.

  2. If you do not already have access to the Anypoint-CLI command line tool, follow the brief Anypoint Platform CLI installation instructions.

  3. Log into your Anypoint Platform account from the command line, providing your username: anypoint-cli --username="user". Next you enter your password.

  4. Use the runtime-mgr application deploy command providing the name of the app and the location of the deployable archive (.zip) file on your file system, for example:

    runtime-mgr application deploy helloworldtest /Users/exported-app-folder/hello-world.zip
  5. If there are no issues with the name, location or any optional parameters provided, you should see a table like this:

    Deploying helloworldtest ...
    ┌──────────────────────────────┬────────────────────────────────────────┐
    │ Domain                       │ helloworldtest.cloudhub.io             │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Status                       │ UNDEPLOYED                             │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Updated                      │ a few seconds ago                      │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Runtime                      │ 3.8.2                                  │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ File name                    │ hello-world.zip                        │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Persistent queues            │ false                                  │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Persistent queues encrypted  │ false                                  │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Static IPs enabled           │ false                                  │
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Monitoring                   │ Enabled. Auto-restart if not responding│
    ├──────────────────────────────┼────────────────────────────────────────┤
    │ Workers                      │ 1 vCore * 1                            │
  6. Congratulations, your app is now deployed on CloudHub!

    Tip
    Applications that are deployed via the CLI can be viewed and managed on Runtime Manager like any other application. See the Running Your App section.
  7. If you then want to stop the app, on the command line type runtime-mgr application stop <app-name>.

  8. To exit the command line tool, hit ctrl + c twice.

Tip
For more information on these or other commands see Anypoint Platform CLI.