Skip to Content

/wp-content/uploads/2016/06/aston_martin_869646_1280_969876.jpg

At the recent Sapphire one of the big news for the developers was the beta release of Cloud Foundry(CF) based services for SAP HANA Cloud Platform. Rui Nogueira provided a lot of details in his blog. As explained in Rui’s blog we get a lot of new capabilities with these services like additional runtimes and backing services, additional ways for apps to be scalable etc.  Developers are known to be magpies  i.e. interested in new and shiny things. So how does the existing rich set of HANA Cloud Platform capabilities fit with the new and shiny things provides by these CF services. In this blog I would show how to mash the new and existing services to develop a Fiori Application that is backed by an Odata service running inside cloud foundry services.

Prerequisites

To successfully run this scenario you would need the following

  • A SAP HANA Cloud Platform(HCP) trial/facotry account ( For new register here )
  • Registered for the Cloud Foundry based services on HCP. ( For new follow instructions here OR Step 1 of this blog)
  • Working Cloud Foundry CLI from the step above.
  • Working JDK/Maven/GIT
  • Some knowledge of WebIDE

Part 1: Olingo based OData Backend

Step 1: Developing the OData based Cars service locally

I will be a little lazy over here and take a short cut to do this. Apache OData is a java library that is used to enable OData services for your project. It comes with a Maven artifact that we will use to generate sample code which would be sufficient for our purposes.  Launch a command line CMD on Windows and Terminal on Mac. If you have a working maven launch the following command ( if you don’t have maven clone this git repo), please note this is a really long command line so make sure to copy paste all of it


mvn archetype:generate -DinteractiveMode=false -Dversion=1.0.0-SNAPSHOT -DgroupId=com.acme -DartifactId=cf-cars-svc -DarchetypeGroupId=org.apache.olingo -DarchetypeArtifactId=olingo-odata2-sample-cars-annotation-archetype -DarchetypeVersion=RELEASE






You should see something like this

2016-06-07 11_11_16-_new  4 - Notepad++ [Administrator].png

This will create a cf-cars-svc directory in your current folder. That’s it, we have all the Java code needed for our purpose 🙂 Change directory to the newly created cf-cars-svc folder. You can check the code if you want to by firing up your favorite IDE. Proceed further to package it using Maven


mvn package






Maven would try to download the internet 😉 once it has everything it needs it will package it nicely as a war file in the target folder.

Step 2: Prepping for Cloud Foundry – manifest.yml

Cloud Foundry requires a manifest file that acts as metadata for your application. This manifest.yml file instructs CF on how much memory to use, what to name the app any backing services to use etc. Please create a manifest.yml file in the cf-cars-svc folder


---
applications:
- name: cars
  memory: 512M
  host: carsxxx
  path: target/cf-cars-svc.war






As you can see we will call our application cars, it will use 512MB of memory (you a 1GB of quota as part of beta) and the host will be called carsxxx. Please note the host needs to be unique across all the applications even by different users. So if you use just cars it may already be taken. If that happens during the next step. Just come back and change it to something unique. Another thing to remember is that yml files are quite finicky about the syntax so if you get syntax error, you may want to use this one from github. We have everything we need locally to push these bits to SAP HCP Cloud Foundry.

Step 3: Push it push it

Remember you would need Cloud Foundry CLI for this step. If you haven’t downloaded that yet, now would be good time to do it from here as other wise you are going to hit a wall. Open a command prompt and specify CF API point for HCP CF


 cf api https://api.cf.us10.hana.ondemand.com






You should see something like this

2016-06-07 14_43_45-C__WINDOWS_system32_cmd.exe.png

Your CF CLI is now pointing to HCP CF and knows all commands you give from now should be in the context of HCP CF. As the good doctor CLI says in the screenshot you have to login. You can do that by doing cf login and giving the credentials as shown below

2016-06-07 14_49_35-C__WINDOWS_system32_cmd.exe.png

All that is left now is to do the cf push command to push the code. Please make sure you are in the cf-cars-svc folder and there is a target folder containing the war file in it. Also check that manifest file manifest.yml is in the cf-cars-svc folder. After cf push you should see this

2016-06-07 14_55_52-C__WINDOWS_system32_cmd.exe - cf  push.png

Followed at the end of successful push you would see the following, notice the URL in the logs. This would be the URL to access our application. You can also get the same URL from HCP CF Cockpit.

2016-06-07 14_58_39-C__WINDOWS_system32_cmd.exe.png

You can also login to web based HCP CF cockpit to check the application https://hcp-cockpit.cfapps.us10.hana.ondemand.com/cockpit you would need to login with your credentials. After login you would see a list of all the apps deployed in your account. Click on the your application name hyperlink and youshould see the following with the URL to your application as well

2016-06-07 15_47_57-bootone _ dev _ cars _ Overview - SAP HANA Cloud Platform, Starter Edition for C.png

Notice the URL for your app https://xxx.cfapps.us10.hana.ondemand.com/ where xxx is the host name you chose in your manifest file. Go to this URL and you would see a the following webpage with link to various OData Endpoints. There is a button to generate the data as well. Click on the button only once. There is also link for service document. This URL (https://xxx.cfapps.us10.hana.ondemand.com/MyFormula.svc/ ) will be used in creating the Fiori app.


2016-06-07 15_36_41-Apache Olingo - OData2 Library.png

Also click on the links with Cars or Drivers in the link and you should see some data. Congrats you are done with the first part and you have a Odata based service running on HCP CF.


Part 2: Developing Fiori Front End


Step 1: Create HCP Destination

Login to HCP Cockpit and click on destinations in the left navigation bar. Create a destination with the name Car-O-Data. In the URL field use the Service document URL we had noted down in Part 1 (https://xxxx.cfapps.us10.hana.ondemand.com/MyFormula.svc/) Replace xxxx with the host name you used in manifest file. Rest of the details for the destination are shown below

2016-06-07 16_19_55-Europe (Trial) _ Pankaj's HCP Trial _ Destinations - SAP HANA Cloud Platform Coc.png

Step 2: Developing the Fiori App front End

Browse to WebIDE and choose new project from Template. Choose the Fiori – Master Detail template. Supply a good project name. Most important part happens in the Data Connection tab as shown below. Click on Service URL from the left hand Sources table and choose the Car-O-Data system. Specify the URL again https://xxxx.cfapps.us10.hana.ondemand.com/MyFormula.svc. Make sure you see the entities from Odata service when you click on the button in the URL field

2016-06-07 16_54_03-SAP Web IDE.png

In the template customization specify the name, namespace etc. For the Master section i.e. Object choose Manufactures as shown below

2016-06-07 17_05_17-SAP Web IDE.png

For the line item choose cars as shown below.

2016-06-07 17_05_48-SAP Web IDE.png

We are ready with the Fiori Application. Click Finish and now you can run your Fiori App to see it pulling data from Odata service you deployed in part one. There you have it OData backend running in Cloud Foundry services of HCP while Fiori app running in WebIDE.

2016-06-07 17_16_11-Cars.png

I would be very interested to know how you found this hands on. Looking forward to your work with HCP Cloud Foundry services.



To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

    1. Pankaj Kumar Post author

      That is strange. If you are able to see the odata service document from the browser then there is no reason for the service unavailable dialog. Is it possible for you to upload the screenshot for your settings.

      – Pankaj

      (0) 

Leave a Reply