Name: liberty-outage-reporter
Owner: International Business Machines
Description: Get started with Liberty on Bluemix with this basic outage reporting app.
Created: 2017-07-17 20:49:22.0
Updated: 2017-07-27 02:55:04.0
Pushed: 2017-07-28 17:58:00.0
Size: 32
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
By following this guide, you'll set up a development environment, deploy an app locally and on Bluemix, and integrate a Bluemix database service in your app.
Git, Bluemix CLI, Maven, and a Bluemix account.
Now you're ready to start working with the app. Clone the repo and change the directory to where the sample app is located.
t clone https://github.com/IBM/liberty-outage-reporter
liberty-outage-reporter
Use Maven to install dependencies and build the .war file.
n clean install
Run the app locally on Liberty.
n install liberty:run-server
View your app at: http://localhost:9080/LibertyOutageReporter
To deploy to Bluemix using command line, it can be helpful to set up a manifest.yml file. The manifest.yml includes basic information about your app, such as the name, the location of your app, how much memory to allocate for each instance, and how many instances to create on startup. This is also where you'll choose your URL. Learn more…
The manifest.yml is provided in the sample.
plications:
path: target/LibertyOutageReporter.war
memory: 512M
instances: 1
name: your-appname-here
host: your-appname-here
Change both the name and host to a single unique name of your choice. Note that the host value will be used in your public url, for example, http://your-appname-here.mybluemix.net. If you already created an app from the Bluemix UI but haven't pushed your code to it, you can use the same name value. Make sure the path points to the built application, for this example the location is target/LibertyOutageReporter.war
.
Choose your API endpoint
luemix api <API-endpoint>
Replace the API-endpoint in the command with an API endpoint from the following list.
Login to your Bluemix account
uemix login
Push your application to Bluemix.
uemix app push
This can take around two minutes. If there is an error in the deployment process you can use the command cf logs <Your-App-Name> --recent
to troubleshoot.
Next, we'll add a NoSQL database to this application and set up the application so that it can run locally and on Bluemix.
Connect new
under Connections
.Cloudant NoSQL DB
and Create the service.Restage
when prompted. Bluemix will restart your application and provide the database credentials to your application using the VCAP_SERVICES
environment variable. This environment variable is only available to the application when it is running on Bluemix.We're now going to update your local code to point to this database. We'll store the credentials for the services in a properties file. This file will get used ONLY when the application is running locally. When running in Bluemix, the credentials will be read from the VCAP_SERVICES environment variable.
In Eclipse, open the file src/main/resources/cloudant.properties:
dant_url=
In your browser open the Bluemix UI, select your App -> Connections -> Cloudant -> View Credentials (Note you may have create a set of credentials)
Copy and paste just the url
from the credentials to the url
field of the cloudant.properties
file.
Your Liberty server in Eclipse should automatically pick up the changes and restart the application.
View your app at: http://localhost:9080/LibertyOutageReporter/. Any names you enter into the app will now get added to the database.
Make any changes you want and re-deploy to Bluemix!
IBM® Eclipse Tools for Bluemix provides plug-ins that can be installed into an existing Eclipse environment to assist in integrating the developer's integrated development environment (IDE) with Bluemix.
Download and install IBM Eclipse Tools for Bluemix.
Import this sample into Eclipse using File
-> Import
-> Maven
-> Existing Maven Projects
option.
Create a Liberty server definition:
Servers
view right-click -> New
-> Server
IBM
-> WebSphere Application Server Liberty
Install from an archive or a repository
WAS Liberty with Java EE 7 Web Profile
Run your application locally on Liberty:
LibertyOutageReporter
sample and select Run As
-> Run on Server
optionFinish
Create a Bluemix server definition:
Servers
view, right-click -> New
-> Server
IBM
-> IBM Bluemix
and follow the steps in the wizard.\Next
org
and space
and click Finish
Run your application on Bluemix:
LibertyOutageReporter
sample and select Run As
-> Run on Server
optionIBM Bluemix
and press Finish
Name
for your applicationNow you have your code running locally and on the cloud!
The IBM Eclipse Tools for Bluemix
provides many powerful features such as incremental updates, remote debugging, pushing packaged servers, etc. Learn more
One deployment option is to deploy this application to kubernetes. For this option, we will provision a lite kubernetes cluster via the IBM Bluemix Container Service and deploy the service using the manifests/deployment.yml file. We will be using the IBM Container Registry to store the Docker image for our application.
lugin install container-service -r Bluemix
lugin list # To verify the plugin has been installed
s init # Initialize the container service plugin
lugin install container-registry -r Bluemix
r login
r namespace-add [your namespace]
r namespace-list
1) Log into the Bluemix console and create a lite Kubernetes cluster named mycluster
. This will take several minutes to provision.
kubectl
to point to your Kubernetes cluster hosted on the IBM Bluemix Container Service.mycluster
. If you don't, make sure you have waited enough time for the cluster to be provisioned.s clusters
kubectl
to point to your Kubernetes cluster.
First print the configuration for your cluster.s cluster-config mycluster
This should give you an export KUBE_CONFIG
line. Copy and paste this to configure your kubectl
to point to your Kubernetes cluster.
For example:rt KUBECONFIG=/Users/johnzaccone/.bluemix/plugins/container-service/clusters/mycluster/kube-config-par01-mycluster.yml
kubectl
is configured. The following should show: mycluster
.ctl config get-clusters
You can now send commands to your Kubernetes cluster!We will use the Bluemix CLI to create a binding between our Cloudant instance and our Kubernetes cluster.
List the Cloudant service that you created eariler in this lab. If you haven't created one, refer back to the Add a Database section.
ervice list | grep cloudant
Use the name of your Cloudant service in the command below to bind the service.
s cluster-service-bind mycluster default [Cloudant service Name]
The command above loads a Kubernetes secret into your cluster that contains information to connect to your Cloudant instance. By managing your Cloudant credentials via secrets, you avoid saving them in plain text inside your source code repository.
List the secrets of the Kubernetes cluster. There might be a few, but you should see the one that was just created for your Cloudant database. We are going to reference the name of this secret in our deployment in the next step.
ctl get secrets
You need to configure your application to read the Kubernetes secret you just created. This will require two changes.
src/main/resources/cloudant.properties
file. And uncomment the line that specifies the Kubernetes secret file. Also, comment out the line that explicitly sets the Cloudant URL. Your resulting properties file should look something like this:ese properties are meant for local development only and will not be read when application is running in Bluemix.
en running in Bluemix, the credentials of bound services are available in the VCAP_SERVICES environment variable.
oudant_url=
bx cs cluster-service-bind
command.kubernetes_secrets_file=/etc/cloudant-secrets/binding
location for the secret is: `/etc/cloudant-secrets/binding`. This is configured for you already in the `manifests/deployment.yml` file. There is no need to change this path at this time.
pen the `manifests/deployment.yml` file. Replace `my-secret` in the container spec with the name of your secret. You can get a list of secrets loaded into your cluster with `kubectl get secrets`. Note that the `etc/cloudant-secrets/binding` path has already been configured for you. Close and save the file.
Build and Push your Docker image
uild your application
mvn clean install
uild and push the Docker image you the IBM Container Registry. Use the namespace you created earlier in the following command. You can list the namespace you created using `bx cr namespace-list`.
export CR_NAMESPACE=[your namespace] docker build -t registry.ng.bluemix.net/$CR_NAMESPACE/liberty-outage-reporter . docker push registry.ng.bluemix.net/$CR_NAMESPACE/liberty-outage-reporter
dit the `manifests/deployment.yml` to reference the name of the image that you just pushed. Search for the line
ge: registry.ng.bluemix.net/mynamespace/liberty-outage-reporter`
replace `mynamespace` with your namespace. For example, if you used namespace `dev` the line would be:
ge: registry.ng.bluemix.net/dev/liberty-outage-reporter`
Deploy the Application
se `kubectl to deploy the application:
kubectl apply -f manifests
hould take a few minutes for the application to deploy. You can check the status by using `kubectl get deploy`.
heck that your application has been started by printing the logs.
kubectl get pods NAME READY STATUS RESTARTS AGE liberty-outage-reporter-495303238-65dfm 1/1 Running 0 2m
kubectl logs -f liberty-outage-reporter-495303238-65dfm
Test the Application
deployment uses NodePort to expose the application on all nodes in the cluster. To access the application, first get the IP of the worker node in the cluster.
kubectl get nodes NAME STATUS AGE VERSION 184.172.247.191 Ready 8d v1.5.6-4+abe34653415733
lists the services to get the port for your application.
kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
liberty-outage-reporter-service 10.10.10.177
his example, the application is running at: `http://184.172.247.191:30052/LibertyOutageReporter`.