Skip to content

Commit 2c25716

Browse files
add ArtifactStore implementation for MongoDB
Co-authored-by: Chetan Mehrotra <[email protected]> Co-authored-by: jiangpengcheng <[email protected]>
1 parent fbd34be commit 2c25716

File tree

36 files changed

+2095
-8
lines changed

36 files changed

+2095
-8
lines changed

ansible/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ db_host=
9898
db_port=
9999
```
100100

101+
or
102+
```bash
103+
db_username=
104+
db_password=
105+
mongodb_replicaSet=
106+
mongodb_database=
107+
```
108+
if you want to use MongoDB.
109+
101110
This file is generated automatically if you are using an ephermeral CouchDB instance. Otherwise, you must create it explicitly.
102111
For convenience, you can use shell environment variables that are read by the playbook to generate the required `db_local.ini` file as shown below.
103112

@@ -121,8 +130,13 @@ export OW_DB_PASSWORD=<your cloudant password>
121130
export OW_DB_PROTOCOL=https
122131
export OW_DB_HOST=<your cloudant user>.cloudant.com
123132
export OW_DB_PORT=443
133+
# below variables are for mongodb
134+
export OW_MONGODB_REPLICASER=<your mongodb replicaset name>
135+
export OW_MONGODB_DATABASE=<your mongodb database name>
124136
125137
ansible-playbook -i environments/<environment> couchdb.yml --tags ini
138+
# or below for mongodb
139+
ansible-playbook -i environments/<environment> mongodb.yml --tags ini
126140
```
127141

128142
#### Install Prerequisites
@@ -187,6 +201,24 @@ data that include actions and activations are lost.
187201

188202
Use `ansible-playbook -i environments/<environment> openwhisk.yml` to avoid wiping the data store. This is useful to start OpenWhisk after restarting your Operating System.
189203

204+
### Deploying Using MongoDB
205+
- Make sure your `db_local.ini` file is [setup for](#setup) MongoDB then execute:
206+
207+
```
208+
cd <openwhisk_home>
209+
./gradlew distDocker
210+
cd ansible
211+
ansible-playbook -i environments/<environment> mongodb.yml
212+
ansible-playbook -i environments/<environment> initdb.yml -e database_backend=MongoDB
213+
ansible-playbook -i environments/<environment> wipe.yml -e database_backend=MongoDB
214+
ansible-playbook -i environments/<environment> apigateway.yml
215+
ansible-playbook -i environments/<environment> openwhisk.yml
216+
ansible-playbook -i environments/<environment> postdeploy.yml
217+
```
218+
You need to run `initdb.yml` **every time** you do a fresh deploy MongoDB to initialize the subjects database.
219+
The playbooks `wipe.yml` and `postdeploy.yml` should be run on a fresh deployment only, otherwise all transient
220+
data that include actions and activations are lost.
221+
190222
### Configuring the installation of `wsk` CLI
191223
There are two installation modes to install `wsk` CLI: remote and local.
192224

ansible/environments/distributed/group_vars/all

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ db_password: couch_password
1010
db_host: "{{ groups['db'] | first }}"
1111
db_prefix: whisk_distributed_
1212

13+
mongodb_database: whisks
14+
mongodb_replicaSet: whisk_replica_set
15+
1316
whisk_version_name: distributed
1417
config_root_dir: /tmp/wskconf
1518
whisk_logs_dir: /tmp/wsklogs

ansible/environments/docker-machine/group_vars/all

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ db_password: "{{ lookup('ini', 'db_password section=db_creds file={{ playbook_di
2525
db_protocol: "{{ lookup('ini', 'db_protocol section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
2626
db_host: "{{ lookup('ini', 'db_host section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
2727
db_port: "{{ lookup('ini', 'db_port section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
28+
mongodb_database: "{{ lookup('ini', 'mongodb_database section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
29+
mongodb_replicaSet: "{{ lookup('ini', 'mongodb_replicaSet section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
2830

2931
# API GW connection configuration
3032
apigw_auth_user: ""

ansible/environments/local/group_vars/all

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ db_password: "{{ lookup('ini', 'db_password section=db_creds file={{ playbook_di
1919
db_protocol: "{{ lookup('ini', 'db_protocol section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
2020
db_host: "{{ lookup('ini', 'db_host section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
2121
db_port: "{{ lookup('ini', 'db_port section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
22+
mongodb_database: "{{ lookup('ini', 'mongodb_database section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
23+
mongodb_replicaSet: "{{ lookup('ini', 'mongodb_replicaSet section=db_creds file={{ playbook_dir }}/db_local.ini') }}"
2224

2325
# API GW connection configuration
2426
apigw_auth_user: ""

ansible/group_vars/all

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ nginx:
205205
# The key db.whisk.auth is the name of the authentication database where all keys of all users are stored.
206206
# The db_prefix is defined for each environment on its own. The CouchDb credentials are also defined for each environment on its own.
207207
db:
208+
backend: "{{ database_backend | default('CouchDB') }}"
209+
confdir: "{{ config_root_dir }}/database"
208210
instances: "{{ groups['db'] | length }}"
209211
authkeys:
210212
- guest
@@ -213,6 +215,17 @@ db:
213215
actions: "{{ db_prefix }}whisks"
214216
activations: "{{ db_prefix }}activations"
215217
auth: "{{ db_prefix }}subjects"
218+
mongodb:
219+
port: "{{ mongodb_port | default('27017') }}"
220+
version: 3.6.3
221+
data_volume: "{{ mongodb_data_volume | default('mongo-data') }}"
222+
223+
database_spi: "{% if db.backend == 'MongoDB' %}whisk.core.database.mongodb.MongoDbStoreProvider{% else %}whisk.core.database.CouchDbStoreProvider{% endif %}"
224+
mongodb_connect_string: "{% set ret = [] %}\
225+
{% for host in groups['db'] %}\
226+
{{ ret.append( hostvars[host].ansible_host + ':' + db.mongodb.port) }}\
227+
{% endfor %}\
228+
{{ ret | join(',') }}"
216229

217230
apigateway:
218231
port:

ansible/initdb.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
- hosts: ansible
88
tasks:
99
- include_tasks: tasks/initdb.yml
10+
run_once: True

ansible/mongodb.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements; and to You under the Apache License, Version 2.0.
3+
---
4+
# This playbook deploys a MongoDB for Openwhisk.
5+
6+
- hosts: localhost
7+
tasks:
8+
- name: check if db_local.ini exists?
9+
tags: ini
10+
stat: path="{{ playbook_dir }}/db_local.ini"
11+
register: db
12+
13+
- name: prepare db_local.ini
14+
tags: ini
15+
local_action: template src="db_local.ini.j2" dest="{{ playbook_dir }}/db_local.ini"
16+
when: not db.stat.exists
17+
18+
- hosts: db
19+
roles:
20+
- mongodb
21+
22+
post_tasks:
23+
- import_tasks: tasks/initMongoDBReplicaSet.yml
24+
when: mode == "deploy"

ansible/roles/controller/tasks/deploy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@
170170
"CONFIG_whisk_couchdb_databases_WhiskEntity": "{{ db.whisk.actions }}"
171171
"CONFIG_whisk_couchdb_databases_WhiskActivation":
172172
"{{ db.whisk.activations }}"
173+
"CONFIG_whisk_mongodb_hosts": "{{ mongodb_connect_string }}"
174+
"CONFIG_whisk_mongodb_username": "{{ db_username }}"
175+
"CONFIG_whisk_mongodb_password": "{{ db_password }}"
176+
"CONFIG_whisk_mongodb_replicaSet": "{{ mongodb_replicaSet}}"
177+
"CONFIG_whisk_mongodb_database": "{{ mongodb_database }}"
178+
"CONFIG_whisk_mongodb_collections_WhiskAuth": "{{ db.whisk.auth }}"
179+
"CONFIG_whisk_mongodb_collections_WhiskEntity": "{{ db.whisk.actions }}"
180+
"CONFIG_whisk_mongodb_collections_WhiskActivation": "{{ db.whisk.activations }}"
173181
"CONFIG_whisk_db_actionsDdoc": "{{ db_whisk_actions_ddoc | default() }}"
174182
"CONFIG_whisk_db_activationsDdoc": "{{ db_whisk_activations_ddoc | default() }}"
175183
"CONFIG_whisk_db_activationsFilterDdoc": "{{ db_whisk_activations_filter_ddoc | default() }}"
@@ -232,6 +240,7 @@
232240
"CONFIG_whisk_spi_LogStoreProvider": "{{ userLogs.spi }}"
233241
"CONFIG_whisk_spi_LoadBalancerProvider":
234242
"{{ controller.loadbalancer.spi }}"
243+
"CONFIG_whisk_spi_ArtifactStoreProvider": "{{ database_spi }}"
235244
"CONFIG_logback_log_level": "{{ controller.loglevel }}"
236245

237246
"CONFIG_whisk_transactions_header": "{{ transactions.header }}"

ansible/roles/invoker/tasks/deploy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@
170170
"CONFIG_whisk_couchdb_databases_WhiskAuth": "{{ db.whisk.auth }}"
171171
"CONFIG_whisk_couchdb_databases_WhiskEntity": "{{ db.whisk.actions }}"
172172
"CONFIG_whisk_couchdb_databases_WhiskActivation": "{{ db.whisk.activations }}"
173+
"CONFIG_whisk_mongodb_hosts": "{{ mongodb_connect_string }}"
174+
"CONFIG_whisk_mongodb_username": "{{ db_username }}"
175+
"CONFIG_whisk_mongodb_password": "{{ db_password }}"
176+
"CONFIG_whisk_mongodb_replicaSet": "{{ mongodb_replicaSet}}"
177+
"CONFIG_whisk_mongodb_database": "{{ mongodb_database }}"
178+
"CONFIG_whisk_mongodb_collections_WhiskAuth": "{{ db.whisk.auth }}"
179+
"CONFIG_whisk_mongodb_collections_WhiskEntity": "{{ db.whisk.actions }}"
180+
"CONFIG_whisk_mongodb_collections_WhiskActivation": "{{ db.whisk.activations }}"
173181
"DB_WHISK_ACTIONS": "{{ db.whisk.actions }}"
174182
"DB_WHISK_ACTIVATIONS": "{{ db.whisk.activations }}"
175183
"DB_WHISK_AUTHS": "{{ db.whisk.auth }}"
@@ -200,6 +208,7 @@
200208
"CONFIG_kamon_statsd_hostname": "{{ metrics.kamon.host }}"
201209
"CONFIG_kamon_statsd_port": "{{ metrics.kamon.port }}"
202210
"CONFIG_whisk_spi_LogStoreProvider": "{{ userLogs.spi }}"
211+
"CONFIG_whisk_spi_ArtifactStoreProvider": "{{ database_spi }}"
203212
"CONFIG_logback_log_level": "{{ invoker.loglevel }}"
204213
"CONFIG_whisk_memory_min": "{{ limit_action_memory_min | default() }}"
205214
"CONFIG_whisk_memory_max": "{{ limit_action_memory_max | default() }}"

ansible/roles/mongodb/tasks/clean.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements; and to You under the Apache License, Version 2.0.
3+
---
4+
# Remove MongoDB server
5+
6+
- name: remove MongoDB
7+
docker_container:
8+
name: mongodb
9+
state: absent
10+
keep_volumes: False
11+
12+
- name: remove MongoDB data volume
13+
docker_volume:
14+
name: "{{ db.mongodb.data_volume }}"
15+
state: absent
16+
17+
- name: remove MongoDB log directory
18+
file:
19+
path: "{{ whisk_logs_dir }}/mongodb"
20+
state: absent
21+
become: "{{ logs.dir.become }}"
22+
23+
- name: remove MongoDB conf directory
24+
file:
25+
path: "{{ db.confdir }}"
26+
state: absent

0 commit comments

Comments
 (0)