Wednesday, 10 February 2016

Invoking the Billing API for Bluemix Public Organizations

The ability to view usage data from a billing perspective on IBM Bluemix Public is available as a REST based API. To use it follow the steps below.

In order to use the API you have to have the Billing Manager Role or be the Account Owner of the organization as shown below.



Steps

1. Log into the PUBLIC Bluemix region as shown below

pasapicella@Pas-MacBook-Pro:~$ cf login -u pasapi@au1.ibm.com -p ***** -o pasapi@au1.ibm.com -s dev
API endpoint: https://api.ng.bluemix.net
Authenticating...
OK

Targeted org pasapi@au1.ibm.com

Targeted space dev

API endpoint:   https://api.ng.bluemix.net (API version: 2.40.0)
User:           pasapi@au1.ibm.com
Org:            pasapi@au1.ibm.com
Space:          dev


2. List all your Organizations as shown below

pasapicella@Pas-MacBook-Pro:~$ cf orgs
Getting orgs as pasapi@au1.ibm.com...

name
iwinoto@au1.ibm.com
vralh@au1.ibm.com
MobileQualityAssurance
arthur.proestakis@au1.ibm.com
abentley@au1.ibm.com
shawmale@au1.ibm.com
ANZ-Innovation-Lab
pasapi@au1.ibm.com
NAB Experimentation
Telstra-CustomerA


3. Determine the GUID of the Org you wnat to get metering usage from

pasapicella@Pas-MacBook-Pro:~$ cf org pasapi@au1.ibm.com --guid
e270a605-978e-45fc-9507-00a50dec2469


4. Determine the region name for the PUBLIC instance your connected to as follows

pasapicella@Pas-MacBook-Pro:~$ curl http://mccp.ng.bluemix.net/info
{
  "name": "Bluemix",
  "build": "221004",
  "support": "http://ibm.com",
  "version": 2,
  "description": "IBM Bluemix",
  "authorization_endpoint": "https://mccp.ng.bluemix.net/login",
  "token_endpoint": "https://mccp.ng.bluemix.net/uaa",
  "min_cli_version": null,
  "min_recommended_cli_version": null,
  "api_version": "2.40.0",
  "app_ssh_endpoint": "ssh.ng.bluemix.net:2222",
  "app_ssh_host_key_fingerprint": null,
  "app_ssh_oauth_client": "ssh-proxy",
  "routing_endpoint": "https://api.ng.bluemix.net/routing",
  "logging_endpoint": "wss://loggregator.ng.bluemix.net:443",
  "doppler_logging_endpoint": "wss://doppler.ng.bluemix.net:4443",
  "console_endpoint": "https://mccp.ng.bluemix.net/console",
  "region": "us-south"
}


5. Determine the OAUTH token for your connected session as follows

pasapicella@Pas-MacBook-Pro:~$ cf oauth-token
Getting OAuth token...
OK

bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0ODAzOWM1My0yODZhLTQ5Y2YtYWIzYi0yNGVhZTY

4ZmFmYzIiLCJzdWIiOiJiNmMwMjBiNC1lMTFhLTQ2MzAtYTZhMi0zZjIwZmNlYzdmOTAiL
CJzY29wZSI6WyJjbG91ZF9jb250cm9sbGVyLnJlYWQiLCJwYXNzd29yZC53cml0ZSIsImNsb3
VkX2NvbnRyb2xsZXIud3JpdGUiLCJvcGVuaWQiXSwiY2xpZW50X2lkIjoiY2YiLCJjaWQiOiJj
ZiIsImF6cCI6ImNmIiwiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIiwidXNlcl9pZCI6ImI2YzAyMGI0L
WUxMWEtNDYzMC1hNmEyLTNmMjBmY2VjN2Y5MCIsIm9yaWdpbiI6InVhYSIsInVzZXJf
bmFtZSI6InBhc2FwaUBhdTEuaWJtLmNvbSIsImVtYWlsIjoicGFzYXBpQGF1MS5pYm0uY29t
IiwicmV2X3NpZyI6IjVjOGMyODQ4IiwiaWF0IjoxNDU1MDU3NzQxLCJleHAiOjE0NTUxMD
A5NDEsImlzcyI6Imh0dHBzOi8vdWFhLm5nLmJsdWVtaXgubmV0L29hdXRoL3Rva2VuIiwiem
lkIjoidWFhIiwiYXVkIjpbImNsb3VkX2NvbnRyb2xsZXIiLCJwYXNzd29yZCIsImNmIiwib3Blbm
lkIl19.EUEIXZ-XgxQbvTQnSgrToODHbNmKvhx0PtAp9CaiPTk

At this point we are ready to invoke the Billing/Metering API. The format is as follows

Bluemix Endpoint:

https://rated-usage.ng.bluemix.net/v2/metering/organizations/us-south:ORG_ID/YYYY-MM

  1. ORG_ID : Account GUID
  2. YYYY-MM: Year and month for which usage is required
Format as follows:

curl -v -X GET -H "Authorization: bearer {oauth-token}" "https://rated-usage.ng.bluemix.net/v2/metering/organizations/us-south:e270a605-978e-45fc-9507-00a50dec2469/usage/2016-02" | python -m json.tool
 
6. To invoke using curl we should do it as follows

Output:

pasapicella@Pas-MacBook-Pro:~$ curl -v -X GET -H "Authorization: bearer {oauth-token}" "https://rated-usage.ng.bluemix.net/v2/metering/organizations/us-south:e270a605-978e-45fc-9507-00a50dec2469/usage/2016-02" | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 75.126.70.44...
* Connected to rated-usage.ng.bluemix.net (75.126.70.44) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.ng.bluemix.net
* Server certificate: DigiCert SHA2 Secure Server CA
* Server certificate: DigiCert Global Root CA
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0> GET /v2/metering/organizations/us-south:e270a605-978e-45fc-9507-00a50dec2469/usage/2016-02 HTTP/1.1
> Host: rated-usage.ng.bluemix.net
> User-Agent: curl/7.43.0
> Accept: */*
> Authorization: bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0ODAzOWM1My0yODZhLTQ5Y2YtYWIzYi0yNGVhZTY4ZmFmYzIiLCJzdWIiOiJiNmMwMjBiNC1lMTFhLTQ2MzAtYTZhMi0zZjIwZmNlYzdmOTAiLCJzY29wZSI6WyJjbG91ZF9jb250cm9sbGVyLnJlYWQiLCJwYXNzd29yZC53cml0ZSIsImNsb3VkX2NvbnRyb2xsZXIud3JpdGUiLCJvcGVuaWQiXSwiY2xpZW50X2lkIjoiY2YiLCJjaWQiOiJjZiIsImF6cCI6ImNmIiwiZ3JhbnRfdHlwZSI6InBhc3N3b3JkIiwidXNlcl9pZCI6ImI2YzAyMGI0LWUxMWEtNDYzMC1hNmEyLTNmMjBmY2VjN2Y5MCIsIm9yaWdpbiI6InVhYSIsInVzZXJfbmFtZSI6InBhc2FwaUBhdTEuaWJtLmNvbSIsImVtYWlsIjoicGFzYXBpQGF1MS5pYm0uY29tIiwicmV2X3NpZyI6IjVjOGMyODQ4IiwiaWF0IjoxNDU1MDU3NzQxLCJleHAiOjE0NTUxMDA5NDEsImlzcyI6Imh0dHBzOi8vdWFhLm5nLmJsdWVtaXgubmV0L29hdXRoL3Rva2VuIiwiemlkIjoidWFhIiwiYXVkIjpbImNsb3VkX2NvbnRyb2xsZXIiLCJwYXNzd29yZCIsImNmIiwib3BlbmlkIl19.EUEIXZ-XgxQbvTQnSgrToODHbNmKvhx0PtAp9CaiPTk
>
  0     0    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0< HTTP/1.1 200 OK
< X-Backside-Transport: OK OK
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< Content-Type: application/json; charset=utf-8
< Date: Tue, 09 Feb 2016 22:54:44 GMT
< Etag: W/"3bcc-JgmFioUYI4v46tUXnGY1SQ"
< Vary: Accept-Encoding
< X-Cf-Requestid: 7b5cea8c-1a24-4114-44b2-a45e5d6e6f40
< X-Heap-Used: 136304240
< X-Instance-Id: 657c5e04638a49788a1053e7bb4e22ff
< X-Instance-Index: 5
< X-Node-Version: v0.10.41
< X-Powered-By: Express
< X-Process-Id: 93
< X-Response-Time: 3374.537ms
< X-Uptime: 16055
< X-Client-IP: 124.180.37.173
< X-Global-Transaction-ID: 750960253
<
{ [4055 bytes data]
100 15308    0 15308    0     0   3019      0 --:--:--  0:00:05 --:--:--  3967
* Connection #0 to host rated-usage.ng.bluemix.net left intact
{
    "organizations": [
        {
            "billable_usage": {
                "spaces": []
            },
            "currency_code": "AUD",
            "id": "e270a605-978e-45fc-9507-00a50dec2469",
            "name": "pasapi@au1.ibm.com",
            "non_billable_usage": {
                "spaces": [
                    {
                        "applications": [
                            {
                                "id": "121ccef0-2417-49c4-9f8f-47958b6d819d",
                                "name": "pas-bmspringboot-demo",
                                "usage": [
                                    {
                                        "buildpack": "0154f971-ae72-4882-9695-bda6e31310b7",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "0154f971-ae72-4882-9695-bda6e31310b7",
                                            "name": "liberty-for-java_v2_1-20151006-0912"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "2d7dfb5f-0900-4c4a-a936-edaf3b7febb8",
                                "name": "pas-tonynode",
                                "usage": [
                                    {
                                        "buildpack": "f0bff590-8b49-4c7d-bc4a-3ff24adcd411",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "f0bff590-8b49-4c7d-bc4a-3ff24adcd411",
                                            "name": "sdk-for-nodejs_v2_8-20151209-1403"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "3a962319-e7c4-456f-a2a4-b1f356a5d142",
                                "name": "pas-dotnet-helloworld",
                                "usage": [
                                    {
                                        "buildpack": "0a566654-d250-463e-b413-67782482e903",
                                        "cost": 4.265998000402778,
                                        "quantity": 53.72793451388889,
                                        "runtime": {
                                            "id": "0a566654-d250-463e-b413-67782482e903",
                                            "name": "aspnet5-experimental"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "54629864-0e43-488f-bfca-3f9c9d806de6",
                                "name": "pas-mysql-local",
                                "usage": [
                                    {
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 7.498824610083008,
                                        "quantity": 94.44363488769531,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "59f15702-1c42-444b-a1fb-94fbaf6cb27a",
                                "name": "pas-mobile-web",
                                "usage": [
                                    {
                                        "buildpack": "0154f971-ae72-4882-9695-bda6e31310b7",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "0154f971-ae72-4882-9695-bda6e31310b7",
                                            "name": "liberty-for-java_v2_1-20151006-0912"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "926900dd-ccd7-4442-8f58-413df2bc0237",
                                "name": "pas-mongodb-local",
                                "usage": [
                                    {
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 7.498824610083008,
                                        "quantity": 94.44363488769531,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "ab5a3278-a1c1-44f6-9113-713a4d800131",
                                "name": "bluemix-apples-springboot",
                                "usage": [
                                    {
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "b448fd3a-5350-47d2-820d-7f739a057f22",
                                "name": "pas-SpringBootJARDemo",
                                "usage": [
                                    {
                                        "buildpack": "eb0b11e9-8982-4b93-adcb-7350d0bf2ae4",
                                        "cost": 8.531996000805556,
                                        "quantity": 107.45586902777778,
                                        "runtime": {
                                            "id": "eb0b11e9-8982-4b93-adcb-7350d0bf2ae4",
                                            "name": "liberty-for-java_v2_3-20151208-1311"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },
                            {
                                "id": "b7d3d442-5546-41b4-b5c0-4ef737734e7b",
                                "name": "pas-sb-elastic",
                                "usage": [
                                    {
                                        "buildpack": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                        "cost": 7.498824610083008,
                                        "quantity": 94.44363488769531,
                                        "runtime": {
                                            "id": "dac36860-94be-495a-96f5-d81d79c2ef3f",
                                            "name": "java_buildpack"
                                        },
                                        "unit": "GB-HOURS",
                                        "unitId": "GB_HOURS_PER_MONTH"
                                    }
                                ]
                            },



Wednesday, 27 January 2016

Adding community based Plugins to the CF CLI Tool

I needed a community based plugin recently and this is how you would add it to your CF CLI interface.

1. Add Community based REPO as shown below

$ cf add-plugin-repo community http://plugins.cfapps.io/

2. Check available plugins from REPO added above


pasapicella@Pas-MacBook-Pro:~/ibm$ cf repo-plugins community
Getting plugins from all repositories ...

Repository: CF-Community
name                      version   description
Download Droplet          1.0.0     Download droplets to your local machine
Firehose Plugin           0.8.0     This plugin allows you to connect to the firehose (CF admins only)
doctor                    1.0.1     doctor scans your deployed applications, routes and services for anomalies and reports any issues found. (CLI v6.7.0+)
manifest-generator        1.0.0     Help you to generate a manifest from 0 (CLI v6.7.0+)
Diego-Enabler             1.0.1     Enable/Disable Diego support for an app (CLI v6.13.0+)

3. Install plugin as shown below

pasapicella@Pas-MacBook-Pro:~/ibm/$ cf install-plugin "Live Stats" -r community

**Attention: Plugins are binaries written by potentially untrusted authors. Install and use plugins at your own risk.**

Do you want to install the plugin Live Stats? (y or n)> y
Looking up 'Live Stats' from repository 'community'
7874156 bytes downloaded...
Installing plugin /var/folders/rj/5r89y5nd6pd4c9hwkbvdp_1w0000gn/T/cf-plugin-stats...
OK
Plugin Live Stats v0.0.0 successfully installed.


4. View plugin commands

pasapicella@Pas-MacBook-Pro:~/ibm/$ cf plugins
Listing Installed Plugins...
OK

Plugin Name       Version   Command Name                                           Command Help
IBM-Containers    0.8.788   ic                                                     IBM Containers plug-in

Live Stats        N/A       live-stats                                             Show browser based stats
active-deploy     0.1.22    active-deploy-service-info                             Reports version information about the CLI and Active Deploy service. It also reports the cloud back ends enabled by the Active Deploy service instance.

Monday, 25 January 2016

ServletContextAware Controller class with Spring

I rarely need to save state within the Servlet Context via an application scope, but recently I did and here is what your controller class would look like to get access to the ServletConext with Spring. I was using Spring Boot 1.3.2.RELEASE.

In short you implement the "org.springframework.web.context.ServletContextAware" interface as shown below. In this example we retrieve an application scope attribute.

  
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.json.JsonParser;
import org.springframework.boot.json.JsonParserFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class CommentatorController implements ServletContextAware
{
    private static final Logger log = LoggerFactory.getLogger(CommentatorController.class);
    private static final JsonParser parser = JsonParserFactory.getJsonParser();

    private ServletContext context;

    public void setServletContext(ServletContext servletContext)
    {
        this.context = servletContext;
    }

    @RequestMapping(value="/", method = RequestMethod.GET)
    public String listTeams (Model model)
    {
        String jsonString = (String) context.getAttribute("riderData");
        List<Rider> riders = new ArrayList<>();

        if (jsonString != null)
        {
            if (jsonString.trim().length() != 0)
            {
                Map<String, Object> jsonMap = parser.parseMap(jsonString);
                List<Object> riderList = (List<Object>) jsonMap.get("Riders");

                for (Object rider: riderList)
                {
                    Map m = (Map) rider;
                    riders.add(
                            new Rider((String)m.get("RiderId"),
                                    (String)m.get("Cadence"),
                                    (String)m.get("Speed"),
                                    (String)m.get("HeartRate")));
                }

                //log.info("Riders = " + riders.size());
                model.addAttribute("ridercount", riders.size());
            }
        }
        else
        {
            model.addAttribute("ridercount", 0);
        }

        model.addAttribute("riders", riders);

        return "commentator";

    }
} 

Thursday, 3 December 2015

IBM Containers running Spring Boot Applications with IBM Bluemix

There is now a new command line plugin for IBM containers on Bluemix so you can push and run docker images using CF CLI itself. The steps below show you how to set this up and I use a basic spring boot application as a docker image to test this out.

Steps

Take a note of the docker local host IP. In this example it was as follows, as I test my docker image on my laptop prior to pushing it to Bluemix.

-> docker is configured to use the default machine with IP 192.168.99.100

1. Install the latest CF command line, I used the following version.

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ cf --version
cf version 6.14.0+2654a47-2015-11-18


https://github.com/cloudfoundry/cli

2. Install IBM Containers Cloud Foundry plug-in

pasapicella@pas-macbook-pro:~$ cf install-plugin https://static-ice.ng.bluemix.net/ibm-containers-mac

**Attention: Plugins are binaries written by potentially untrusted authors. Install and use plugins at your own risk.**

Do you want to install the plugin https://static-ice.ng.bluemix.net/ibm-containers-mac? (y or n)> y

Attempting to download binary file from internet address...
9314192 bytes downloaded...
Installing plugin /var/folders/rj/5r89y5nd6pd4c9hwkbvdp_1w0000gn/T/ibm-containers-mac...
OK
Plugin IBM-Containers v0.8.788 successfully installed.


Note: Default plugin directory as follows

$HOME/.cf/plugins


3. Login to IBM Containers

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS$ cf ic login
Client certificates are being retrieved from IBM Containers...
Client certificates are being stored in /Users/pasapicella/.ice/certs/...
Client certificates are being stored in /Users/pasapicella/.ice/certs/containers-api.ng.bluemix.net/0bcbcada-bd11-4372-b416-955dff3078a1...
OK
Client certificates were retrieved.

Deleting old configuration file...
Checking local Docker configuration...
OK

Authenticating with registry at host name registry.ng.bluemix.net
OK
Your container was authenticated with the IBM Containers registry.
Your private Bluemix repository is URL: registry.ng.bluemix.net/apples

You can choose from two ways to use the Docker CLI with IBM Containers:

Option 1: This option allows you to use "cf ic" for managing containers on IBM Containers while still using the Docker CLI directly to manage your local Docker host.
    Use this Cloud Foundry IBM Containers plug-in without affecting the local Docker environment:

    Example Usage:
    cf ic ps
    cf ic images

Option 2: Use the Docker CLI directly. In this shell, override the local Docker environment to connect to IBM Containers by setting these variables. Copy and paste the following commands:
    Note: Only Docker commands followed by (Docker) are supported with this option.

     export DOCKER_HOST=tcp://containers-api.ng.bluemix.net:8443
     export DOCKER_CERT_PATH=/Users/pasapicella/.ice/certs/containers-api.ng.bluemix.net/0bcbcada-bd11-4372-b416-955dff3078a1
     export DOCKER_TLS_VERIFY=1

    Example Usage:
    docker ps
    docker images
4. View docker images

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS$ cf ic images
REPOSITORY                                        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
registry.ng.bluemix.net/ibm-mobilefirst-starter   latest              5996bb6e51a1        6 weeks ago         770.4 MB
registry.ng.bluemix.net/ibm-node-strong-pm        latest              ef21e9d1656c        8 weeks ago         528.7 MB
registry.ng.bluemix.net/ibmliberty                latest              2209a9732f35        8 weeks ago         492.8 MB
registry.ng.bluemix.net/ibmnode                   latest              8f962f6afc9a        8 weeks ago         429 MB
registry.ng.bluemix.net/apples/etherpad_bluemix   latest              131fd7a39dff        11 weeks ago        570 MB


5. Clone application to run as docker image

$ git clone https://github.com/spring-guides/gs-rest-service.git

6. Create a file called Dockerfile as follows in the "complete" directory

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ cat Dockerfile
FROM java:8
VOLUME /tmp
ADD target/gs-rest-service-0.1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]


7. Package the demo

$ mvn package

8. Build docker image

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ docker build -t gs-rest-service .
Sending build context to Docker daemon 13.44 MB
Step 1 : FROM java:8
8: Pulling from library/java
1565e86129b8: Pull complete
a604b236bcde: Pull complete
5822f840e16b: Pull complete
276ac25b516c: Pull complete
5d32526c1c0e: Pull complete
0d61f7a71c59: Pull complete
16952eac0a64: Pull complete
2fb3388c8597: Pull complete
ca603b247c8e: Pull complete
1785f2bc7c99: Pull complete
40e61a6ae215: Pull complete
32f541968fe6: Pull complete
Digest: sha256:52a1b487ed34f5a76f88a336a740cdd3e7b4486e264a3e69ece7b96e76d9f1dd
Status: Downloaded newer image for java:8
 ---> 32f541968fe6
Step 2 : VOLUME /tmp
 ---> Running in 030f739777ac
 ---> 22bf0f9356a1
Removing intermediate container 030f739777ac
Step 3 : ADD target/gs-rest-service-0.1.0.jar app.jar
 ---> ac590c46b73b
Removing intermediate container 9790c39eb1f7
Step 4 : RUN bash -c 'touch /app.jar'
 ---> Running in e9350ddebb75
 ---> 697d245c6afb
Removing intermediate container e9350ddebb75
Step 5 : ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
 ---> Running in 42fc22473930
 ---> df853abfea57
Removing intermediate container 42fc22473930
Successfully built df853abfea57


9. Run locally

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ docker run --name gs-rest-service -p 80:8080 -d -t gs-rest-service
a392aa15da81fb4ca6c16a6307e0bd1c6b22f9a046228f1fc477d3fe12e15f16


10. Test as follows

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers$ curl http://192.168.99.100/greeting
{"id":1,"content":"Hello, World!"}


11. PUSH TO BLUEMIX AS follows

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ docker tag gs-rest-service registry.ng.bluemix.net/apples/gs-rest-service
pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ docker push registry.ng.bluemix.net/apples/gs-rest-service
The push refers to a repository [registry.ng.bluemix.net/apples/gs-rest-service] (len: 1)
Sending image list
Pushing repository registry.ng.bluemix.net/apples/gs-rest-service (1 tags)
Image 5822f840e16b already pushed, skipping
Image 276ac25b516c already pushed, skipping
Image 5d32526c1c0e already pushed, skipping
Image a604b236bcde already pushed, skipping
Image 1565e86129b8 already pushed, skipping
Image 0d61f7a71c59 already pushed, skipping
Image 2fb3388c8597 already pushed, skipping
Image 16952eac0a64 already pushed, skipping
Image ca603b247c8e already pushed, skipping
Image 1785f2bc7c99 already pushed, skipping
Image 40e61a6ae215 already pushed, skipping
Image 32f541968fe6 already pushed, skipping
22bf0f9356a1: Image successfully pushed
ac590c46b73b: Image successfully pushed
697d245c6afb: Image successfully pushed
df853abfea57: Image successfully pushed
Pushing tag for rev [df853abfea57] on {https://registry.ng.bluemix.net/v1/repositories/apples/gs-rest-service/tags/latest}


12. List all allocated IP

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ cf ic ip list
Number of allocated public IP addresses:  2

IpAddress        ContainerId
134.168.13.83
134.168.15.105


13. Create a container from the uploaded image

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ cf ic run -p 8080 --memory 512 --name pas-sb-container registry.ng.bluemix.net/apples/gs-rest-service:latest
b1fe3159-0c19-4d54-b0f5-cdd938618deb


14. Assign IP to container

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ cf ic ip bind 134.168.13.83 pas-sb-container
OK
The IP address was bound successfully.


15. Verify it's running

pasapicella@pas-macbook-pro:~/bluemix_apps/CONTAINERS/ibm-containers/gs-rest-service/complete$ cf ic ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                  PORTS                          NAMES
3794802b-b0c                  ""                  4 minutes ago       Running 3 minutes ago   134.168.13.83:8080->8080/tcp   pas-sb-container

16. Invoke as follows

$ curl http://134.168.13.83:8080/greeting


More Information

Plugin Reference ->

https://www.eu-gb.bluemix.net/docs/containers/container_cli_reference_cfic.html

Installing cf ci plugin ->

https://www.eu-gb.bluemix.net/docs/containers/doc/container_cli_cfic.html

Friday, 20 November 2015

IBM Bluemix Secure Gateway Service with Oracle

I previously blogged about using the IBM Bluemix Secure Gateway Service as follows

http://theblasfrompas.blogspot.com.au/2015/11/ibm-bluemix-secure-gateway-service-step.html

I decided I would extend on this and Connect a Spring Boot Application to Oracle and consume Oracle data using the Secure Gateway Service.

The full demo is as follows

https://dl.dropboxusercontent.com/u/15829935/bluemix-docs/secure-gateway-oracle/index.html


Wednesday, 18 November 2015

IBM Bluemix Secure Gateway Service Step by Step Demo

I created this simple step by step guide on how to use the IBM Secure Gateway Service. Very simple demo which shows how easy it is to set this up and open a world of possibilities from on premise resources directly exposed via Bluemix whether it's PUBLIC or Dedicated/LOcal Instances

https://dl.dropboxusercontent.com/u/15829935/bluemix-docs/secure-gateway/index.html



Tuesday, 10 November 2015

IBM Bluemix Admin Console Command Line (CLI) Installation

The IBM Bluemix Dedicated/Local Administration Console also includes support for CLI to enable common management tasks to be performed using the Cloud Foundry Command Line by adding a plugin to enable support for it's commands.

Note: The Bluemix Admin CLI plugin requires version 6.11.2 or later.

Admin Console UI


Admin Console - Installing Command Line

The CLI to the admin console is installed as follows. The reference to this is found in your own Dedicated/Local install via a link as follows with "cli" appended to the Admin Console URL

https://opsconsole.mylocalinstance.bluemix.net/cli


pasapicella@pas-macbook
pro:~$ cf add-plugin-repo BluemixAdmin https://opsconsole.mylocalinstance.bluemix.net/cli

OK
https://opsconsole.mylocalinstance.bluemix.net/cli/list added as 'BluemixAdmin'

pasapicella@pas-macbook-pro:~$ cf install-plugin bluemix-admin-cli -r BluemixAdmin
Looking up 'bluemix-admin-cli' from repository 'BluemixAdmin'
8889440 bytes downloaded...
Installing plugin /var/folders/rj/5r89y5nd6pd4c9hwkbvdp_1w0000gn/T/bluemix-admin...
OK
Plugin BluemixAdminCLI v0.0.1 successfully installed.
pasapicella@pas-macbook-pro:~$ cf plugins
Listing Installed Plugins...
OK

…...

Finally target admin API endpoint:

pasapicella@pas-macbook-pro:~$ cf baa https://opsconsole.mylocalinstance.bluemix.net
The API endpoint has been updated to 'https://opsconsole.mylocalinstance.bluemix.net'

At this point you can now run Admin Console commands as follows. To get help issue "cf {command} --help"
 
The current supported commands are as follows:
 
bluemix-admin-api, baa                              
bluemix-admin-add-user, baau                        
bluemix-admin-remove-user, baru                     
bluemix-admin-set-organization, baso                
bluemix-admin-unset-organization, bauo              
bluemix-admin-set-quota, basq                       
bluemix-admin-add-report, baar                      
bluemix-admin-delete-report, badr                   
bluemix-admin-retrieve-report, barr                 
bluemix-admin-enable-service-plan, baesp            
bluemix-admin-disable-service-plan, badsp           
bluemix-admin-add-service-plan-visibility, baaspv   
bluemix-admin-remove-service-plan-visibility, barspv
bluemix-admin-edit-service-plan-visibilites, baespv 
bluemix-admin-set-region-access, basra              
bluemix-admin-create-organization, baco             
bluemix-admin-delete-organization, bado 
 
 

Monday, 9 November 2015

Spring Security Demo with a Bootstrap Look and Feel

I decided to take the Spring Security demo at the following link , and add Bootstrap to it. In the end it's basically the same code and the Form Based Login will accept one user "pas/welcome1".

http://spring.io/guides/gs/securing-web/

Here is the updated demo with Bootstrap added to the UI pages. You can deploy this to Bluemix using the "Deploy to Bluemix" directly from GitHub and it will as you to Sing into IBM devOps prior to deploying it directly into your Bluemix Environment.

https://github.com/papicella/SpringBootSecurityBootstrap

Saturday, 10 October 2015

IBM Bluemix - Spring Boot Elasticsearch Repositories demo

I decided to take the Elasticsearch repositories as part of the Spring Data project for a test drive. The Spring boot Elasticsearch repositories are described in the link below.

http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.repositories

In this example I create a basic Spring Boot application using Elasticsearch, Web, Rest Repositories along with Thymeleaf / Bootstrap as the view pages. The code for this is on GitHub which also provides the "Deploy to Bluemix" button to deploy to your own instance of this application into your own Bluemix accout.

https://github.com/papicella/SpringBootElasticSearch



Like all Spring Data Repositories you can create an interface and be given basic CRUD operations to the Elastisearch DOCUMENT as shown below.

EmployeeRepository.java
 
package pas.au.ibm.bluemix.elastic;

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

public interface EmployeeRepository extends ElasticsearchRepository<Employee, String>
{
    public List<Employee> findByFirstNameContaining(String firstName);
} 

Employee.java
  
package pas.au.ibm.bluemix.elastic;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

@Document(indexName = "employee", type = "employee", shards = 1, replicas = 0, refreshInterval = "-1")
public class Employee
{
    @Id
    private String id;
    private String firstName;
    private String lastName;
    private String job;
    private int deptNo;

    public Employee()
    {
    }

....

If you don't have a IBM DevOps Jazzhub account the manifest.yml can be used if you clone the project, and compile it using maven with "mvn package". Be sure to alter the application name / host to be a unique name within Bluemix.

applications:
 - name: pas-sb-elastic
   memory: 450M
   path: ./target/SpringBootElasticSearch-0.0.1-SNAPSHOT.jar
   instances: 1
   host: pas-sb-elastic
   buildpack: java_buildpack
   domain: mybluemix.net


Example Deployment

pasapicella@pas-macbook-pro:~/ibm/DemoProjects/spring-starter/jazzhub/SpringBootElasticSearch$ cf push
Using manifest file /Users/pasapicella/ibm/DemoProjects/spring-starter/jazzhub/SpringBootElasticSearch/manifest.yml

Creating app pas-sb-elastic in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

Using route pas-sb-elastic.mybluemix.net
Binding pas-sb-elastic.mybluemix.net to pas-sb-elastic...
OK

Uploading pas-sb-elastic...
Uploading app files from: /Users/pasapicella/ibm/DemoProjects/spring-starter/jazzhub/SpringBootElasticSearch/target/SpringBootElasticSearch-0.0.1-SNAPSHOT.jar
Uploading 1M, 133 files
Done uploading
OK

Starting app pas-sb-elastic in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
-----> Downloaded app package (35M)
-----> Java Buildpack Version: v3.0 | https://github.com/cloudfoundry/java-buildpack.git#3bd15e1
-----> Downloading Open Jdk JRE 1.8.0_60 from https://download.run.pivotal.io/openjdk/trusty/x86_64/openjdk-1.8.0_60.tar.gz (2.7s)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.7s)
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (0.9s)

-----> Uploading droplet (79M)

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started


OK

App pas-sb-elastic was started using this command `SERVER_PORT=$PORT $PWD/.java-buildpack/open_jdk_jre/bin/java -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar -Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh -Xmx329386K -Xms329386K -XX:MaxMetaspaceSize=64M -XX:MetaspaceSize=64M -Xss975K org.springframework.boot.loader.JarLauncher`

Showing health and status for app pas-sb-elastic in org pasapi@au1.ibm.com / space dev as pasapi@au1.ibm.com...
OK

requested state: started
instances: 1/1
usage: 450M x 1 instances
urls: pas-sb-elastic.mybluemix.net
last uploaded: Sat Oct 10 10:20:52 UTC 2015
stack: cflinuxfs2
buildpack: java_buildpack

     state     since                    cpu    memory           disk           details
#0   running   2015-10-10 09:22:42 PM   0.3%   425.1M of 450M   158.1M of 1G


The application is currently deployed and is accessible at the URL below.

http://pas-sb-elastic.mybluemix.net/





More Information

http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#elasticsearch.repositories

https://www.elastic.co/

Tuesday, 6 October 2015

IBM Bluemix - Specify only Liberty buildpack features you require

I am more often then not using spring boot applications on IBM Bluemix and most of what I need is packaged with the application from JPA or JDBC, drivers, Rest etc. Of course with IBM Bluemix we can specify which build pack we wish to use but by default for java applications LIberty is used.

When a stand-alone application is deployed, a default Liberty configuration is provided for the application. The default configuration enables the following Liberty features:

  • beanValidation-1.1
  • cdi-1.2
  • ejbLite-3.2
  • el-3.0
  • jaxrs-2.0
  • jdbc-4.1
  • jndi-1.0
  • jpa-2.1
  • jsf-2.2
  • jsonp-1.0
  • jsp-2.3
  • managedBeans-1.0
  • servlet-3.1
  • websocket-1.1
  • icap:managementConnector-1.0
  • appstate-1.0
Here is how I strip out some of what isn't required in my Liberty runtime container to a bare minimal of what I need.

manifest.yml

applications:
 - name: pas-speedtest
   memory: 512M
   instances: 1
   path: ./demo-0.0.1-SNAPSHOT.jar
   host: pas-speedtest
   domain: mybluemix.net
   env:
     JBP_CONFIG_LIBERTY: "app_archive: {features: [jsp-2.3, websocket-1.1, servlet-3.1]}"


 More Information

https://www.ng.bluemix.net/docs/starters/liberty/index.html#optionsforpushinglibertyapplications