Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit 1cba8d9

Browse files
AnthonyAmanseanimeshsingh
authored andcommitted
Notification Service (#3)
* Added slack notification * Added Slack notification with OpenWhisk * Update README * Update README * Update README * Update README * Added email openwhisk action * Added email openwhisk action * Fixed TriggerEmail for OpenWhisk * Added email action in README * Fix Spacing on Yaml file * Update Readme * Update README
1 parent 9d1fa57 commit 1cba8d9

30 files changed

+277
-35
lines changed

README.md

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Build Status](https://travis-ci.org/IBM/office-space.svg?branch=master)](https://travis-ci.org/IBM/office-space)
22
# OfficeSpace: Polyglot Microservices application leveraging Java Spring Boot on Kubernetes
33

4-
Spring Boot is one of the popular Java microservices framework. Spring Cloud has a rich set of well integrated Java libraries to address runtime concerns as part of the Java application stack, and Kubernetes provides a rich featureset to run polyglot microservices. Together these technologies complement each other and make a great platform for Spring Boot applications.
4+
Spring Boot is one of the popular Java microservices framework. Spring Cloud has a rich set of well integrated Java libraries to address runtime concerns as part of the Java application stack, and Kubernetes provides a rich featureset to run polyglot microservices. Together these technologies complement each other and make a great platform for Spring Boot applications.
55

66
In this code we demonstrate how a simple Spring Boot application can be deployed on top of Kuberneets. This application, Office Space, mimicks the fictitious app idea from Michael Bolton in the movie [Office Space](http://www.imdb.com/title/tt0151804/). The app takes advantage of a financial program that computes interest for transactions by diverting fractions of a cent that are usually rounded off into a seperate bank account.
77

@@ -31,10 +31,13 @@ Please follow the [Toolchain instructions](https://github.com/IBM/container-jour
3131
4. [Create the Transaction Generator service](#4-create-the-transaction-generator-service)
3232
5. [Access Your Application](#5-access-your-application)
3333

34+
#### [Using OpenWhisk](#using-openwhisk-action-with-slack-notification)
35+
#### [Troubleshooting](#troubleshooting-1)
36+
3437
# 1. Create the Database service
3538
The backend consists of the MySQL database and the Spring Boot app. You will also be creating a deployment controller for each to provision their Pods.
3639

37-
* There are two ways to create the MySQL database backend: **Use MySQL in a container in your cluster** *OR* **Use Bluemix MySQL**
40+
* There are two ways to create the MySQL database backend: **Use MySQL in a container in your cluster** *OR* **Use Bluemix MySQL**
3841

3942
## 1.1 Use MySQL in container
4043
**NOTE:** Leave the environment variables blank in the `compute-interest-api.yaml` and `account-summary.yaml`
@@ -72,7 +75,11 @@ deployment "account-database" created
7275
You will need to have [Maven installed on your environment](https://maven.apache.org/index.html).
7376
If you want to modify the Spring Boot apps, you will need to do it before building the Java project and the docker image.
7477

75-
The Spring Boot Microservices are the **Compute-Interest-API** and the **Email-Service**.
78+
The Spring Boot Microservices are the **Compute-Interest-API** and the **Send-Notification**.
79+
80+
The **Send-Notification** can be configured to send notification through gmail and/or Slack.
81+
82+
You will need to use an [OpenWhisk](#using-openwhisk-action-with-slack-notification) action for the slack notification. You may also choose to use an OpenWhisk action for the email notification. If you want to use OpenWhisk, go to [Using OpenWhisk](#using-openwhisk-action-with-slack-notification) section before building and deploying the images. Otherwise, you can proceed if you choose to only have an email notification setup.
7683

7784
* 1. Build the images
7885

@@ -84,7 +91,7 @@ The Spring Boot Microservices are the **Compute-Interest-API** and the **Email-S
8491
8592
Go to containers/email-office-space
8693
$ mvn package
87-
$ docker build -t registry.ng.bluemix.net/<namespace>/email-service .
94+
$ docker build -t registry.ng.bluemix.net/<namespace>/send-notification .
8895
```
8996
*We will be using Bluemix container registry to push images (hence the image naming), but the images [can be pushed in Docker hub](https://docs.docker.com/datacenter/dtr/2.2/guides/user/manage-images/pull-and-push-images) as well.*
9097
* 2. Push the images:
@@ -96,23 +103,23 @@ The Spring Boot Microservices are the **Compute-Interest-API** and the **Email-S
96103

97104
```bash
98105
$ docker push registry.ng.bluemix.net/<namespace>/compute-interest-api
99-
$ docker push registry.ng.bluemix.net/<namespace>/email-service
106+
$ docker push registry.ng.bluemix.net/<namespace>/send-notification
100107
```
101-
* 3. Modify `compute-interest-api.yaml` and `email-service.yaml` to use your image
108+
* 3. Modify `compute-interest-api.yaml` and `send-notification.yaml` to use your image
102109
```yaml
103110
// compute-interest-api.yaml
104111
spec:
105112
containers:
106113
- image: registry.ng.bluemix.net/<namespace>/compute-interest-api # replace with your image name
107-
// email-service.yaml
114+
// send-notification.yaml
108115
spec:
109116
containers:
110-
- image: registry.ng.bluemix.net/<namespace>/email-service # replace with your image name
117+
- image: registry.ng.bluemix.net/<namespace>/send-notification # replace with your image name
111118
```
112-
You will also need to modify the **environment variables** in the `email-service.yaml`:
119+
You will also need to modify the **environment variables** in the `send-notification.yaml`:
113120
```yaml
114121
env:
115-
- name: GMAIL_SENDER_USER
122+
- name: GMAIL_SENDER_USER
116123
value: 'username@gmail.com' # change this to the gmail that will send the email
117124
- name: GMAIL_SENDER_PASSWORD
118125
value: 'password' # change this to the the password of the gmail above
@@ -126,9 +133,9 @@ The Spring Boot Microservices are the **Compute-Interest-API** and the **Email-S
126133
deployment "compute-interest-api" created
127134
```
128135
```bash
129-
$ kubectl create -f email-service.yaml
130-
service "email-service" created
131-
deployment "email-service" created
136+
$ kubectl create -f send-notification.yaml
137+
service "send-notification" created
138+
deployment "send-notification" created
132139
```
133140
> Note: The compute-interest-api multiplies the fraction of the pennies to x100,000 for simulation purposes. You can edit/remove the line `remainingInterest *= 100000` in `src/main/java/officespace/controller/MainController.java` then build the image again.
134141

@@ -178,6 +185,59 @@ account-summary 10.10.10.74 <nodes> 80:30080/TCP
178185
* On your browser, go to `http://<your-cluster-IP>:30080`
179186
![Account-balance](images/balance.png)
180187

188+
# Using OpenWhisk Action with Slack Notification
189+
190+
Requirements for this sections:
191+
* [Slack Incoming Webhook](https://api.slack.com/incoming-webhooks) in your Slack team.
192+
* **Bluemix Account** to use [OpenWhisk](https://console.ng.bluemix.net/openwhisk/).
193+
194+
195+
1. Create an OpenWhisk Action
196+
* Click on [Developer in your Browser](https://console.ng.bluemix.net/openwhisk/) and click on **Create an Action**
197+
![Create-Action](images/developBrowser.png)
198+
199+
* Then click on
200+
![Create-Action](images/createAction.png)
201+
202+
![Create-Action](images/action.png)
203+
* Copy the [sendSlack.js](/sendSlack.js) for sending a Slack Notification then save it
204+
![Copy-Script](images/copyScript.png)
205+
* Set your [Slack Webhook URL](https://api.slack.com/incoming-webhooks) as default parameter for the action then save it
206+
Click on View Action Details
207+
![Set-Default](images/viewAction.png)
208+
Then set `url` to `https://< Your Slack Team's incoming webhook url>`
209+
![Set-Default](images/defaultParameters.png)
210+
* Create another action for [sendEmail.js](/sendEmail.js) for sending an email through Gmail.
211+
212+
2. Create Managed API
213+
* From the API tab, Create Managed API
214+
![Managed-API](images/createManaged.png)
215+
216+
* Then set an API name
217+
![Managed-API](images/api.png)
218+
* Create an operation. Make it a **POST request** and **select the Slack Action** you just created. **Do the same fore the Email Action**.
219+
![Create-Operation](images/createOperation.png)
220+
221+
![Create-Operation](images/operation.png)
222+
* Go to the API Explorer section on your managed API and take note of the URL for both **Slack** and **Email** operations.
223+
![API-Url](images/apiUrl.png)
224+
3. Modify `send-notification.yaml`
225+
* Fill in the necessary values on the environment variables
226+
```yaml
227+
- name: OPENWHISK_API_URL_SLACK
228+
value: 'openwhisk api url for slack action' # enter the url of the API you just created
229+
- name: SLACK_MESSAGE
230+
value: 'Your balance is over $50,000.00' # set the slack message
231+
- name: OPENWHISK_API_URL_EMAIL
232+
value: 'openwhisk api url for email action'
233+
```
234+
4. Redeploy your Application
235+
236+
237+
## Troubleshooting
238+
* To start over, delete everything: `kubectl delete svc,deploy -l app=office-space`
239+
240+
181241
## References
182242
* [John Zaccone](https://github.com/jzaccone) - The original author of the [office space app deployed via Docker](https://github.com/jzaccone/office-space-dockercon2017).
183243
* The Office Space app is based on the 1999 film that used that concept.

compute-interest-api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ spec:
2929
tier: compute
3030
spec:
3131
containers:
32-
- image: anthonyamanse/compute-interest-api-with-email
32+
- image: anthonyamanse/compute-interest-api:4.0
3333
imagePullPolicy: Always
3434
name: compute-interest-api
3535
env:

containers/.DS_Store

0 Bytes
Binary file not shown.

containers/compute-interest-api/src/main/java/officespace/controllers/MainController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String computeInterest(@RequestBody(required = true) Transaction transact
6060
if (updatedBalance > 50000 && emailSent == false ) {
6161
RestTemplate rest = new RestTemplate();
6262
HttpHeaders headers = new HttpHeaders();
63-
String server = "http://email-service:8080/email";
63+
String server = "http://send-notification:8080/email";
6464
headers.add("Content-Type", "application/json");
6565
headers.add("Accept", "*/*");
6666
String json = "{}";
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)