Skip to content

Commit ca2a15a

Browse files
Add ArtifactStore implementation for MongoDB
Co-authored-by: Chetan Mehrotra <[email protected]> Co-authored-by: jiangpengcheng <[email protected]>
1 parent d847d0f commit ca2a15a

34 files changed

+2528
-1
lines changed

ansible/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ db_host=
102102
db_port=
103103
```
104104

105+
or
106+
```bash
107+
[db_creds]
108+
db_username=
109+
db_password=
110+
db_host=
111+
db_port=
112+
mongodb_database=
113+
```
114+
if you want to use MongoDB.
115+
105116
This file is generated automatically if you are using an ephermeral CouchDB instance. Otherwise, you must create it explicitly.
106117
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.
107118

@@ -125,8 +136,12 @@ export OW_DB_PASSWORD=<your cloudant password>
125136
export OW_DB_PROTOCOL=https
126137
export OW_DB_HOST=<your cloudant user>.cloudant.com
127138
export OW_DB_PORT=443
139+
# below variables are for mongodb
140+
export OW_MONGODB_DATABASE=<your mongodb database name>
128141
129142
ansible-playbook -i environments/<environment> couchdb.yml --tags ini
143+
# or below for mongodb
144+
ansible-playbook -i environments/<environment> mongodb.yml --tags ini
130145
```
131146

132147
#### Install Prerequisites
@@ -191,6 +206,24 @@ data that include actions and activations are lost.
191206

192207
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.
193208

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

ansible/environments/distributed/group_vars/all

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ db_password: couch_password
1313
db_host: "{{ groups['db'] | first }}"
1414
db_prefix: whisk_distributed_
1515

16+
mongodb_database: whisks
17+
1618
config_root_dir: /tmp/wskconf
1719
whisk_logs_dir: /tmp/wsklogs
1820
registry_storage_dir: "/"

ansible/group_vars/all

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ db:
226226
protocol: "{{ db_protocol | default(lookup('ini', 'db_protocol section=db_creds file={{ playbook_dir }}/db_local.ini')) }}"
227227
port: "{{ db_port | default(lookup('ini', 'db_port section=db_creds file={{ playbook_dir }}/db_local.ini')) }}"
228228
host: "{{ db_host | default(lookup('ini', 'db_host section=db_creds file={{ playbook_dir }}/db_local.ini')) }}"
229+
backend: "{{ database_backend | default('CouchDB') }}"
230+
confdir: "{{ config_root_dir }}/database"
229231
instances: "{{ groups['db'] | length }}"
230232
authkeys:
231233
- guest
@@ -244,6 +246,9 @@ db:
244246
invoker:
245247
user: "{{ db_invoker_user | default(lookup('ini', 'db_username section=invoker file={{ playbook_dir }}/db_local.ini')) }}"
246248
pass: "{{ db_invoker_pass | default(lookup('ini', 'db_password section=invoker file={{ playbook_dir }}/db_local.ini')) }}"
249+
mongodb:
250+
database: "{{ mongodb_database | default(lookup('ini', 'mongodb_database section=db_creds file={{ playbook_dir }}/db_local.ini')) }}"
251+
data_volume: "{{ mongodb_data_volume | default('mongo-data') }}"
247252

248253
apigateway:
249254
port:
@@ -262,6 +267,23 @@ linux:
262267
couchdb:
263268
version: 2.1
264269

270+
mongodb:
271+
version: 3.6.6
272+
commonEnv:
273+
CONFIG_whisk_mongodb_host: "{{ db.host }}"
274+
CONFIG_whisk_mongodb_port: "{{ db.port }}"
275+
CONFIG_whisk_mongodb_database: "{{ db.mongodb.database }}"
276+
CONFIG_whisk_mongodb_collections_WhiskAuth: "{{ db.whisk.auth }}"
277+
CONFIG_whisk_mongodb_collections_WhiskEntity: "{{ db.whisk.actions }}"
278+
CONFIG_whisk_mongodb_collections_WhiskActivation: "{{ db.whisk.activations }}"
279+
CONFIG_whisk_spi_ArtifactStoreProvider: "whisk.core.database.mongodb.MongoDBArtifactStoreProvider"
280+
envForController:
281+
CONFIG_whisk_mongodb_username: "{{ db.credentials.controller.user }}"
282+
CONFIG_whisk_mongodb_password: "{{ db.credentials.controller.pass }}"
283+
envForInvoker:
284+
CONFIG_whisk_mongodb_username: "{{ db.credentials.invoker.user }}"
285+
CONFIG_whisk_mongodb_password: "{{ db.credentials.invoker.pass }}"
286+
265287
docker:
266288
# The user to install docker for. Defaults to the ansible user if not set. This will be the user who is able to run
267289
# docker commands on a machine setup with prereq_build.yml

ansible/initMongoDB.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 will initialize the immortal DBs in the database account.
5+
# This step is usually done only once per deployment.
6+
7+
- hosts: ansible
8+
tasks:
9+
- name: "create user in {{ db.mongodb.database }}"
10+
mongodb:
11+
database: "{{ db.mongodb.database }}"
12+
login_user: "{{ db.credentials.admin.user }}"
13+
login_password: "{{ db.credentials.admin.pass }}"
14+
login_host: "{{ db.host }}"
15+
login_port: "{{ db.port }}"
16+
login_database: "{{ db.mongodb.database }}"
17+
user: "{{ item.user }}"
18+
password: "{{ item.pass }}"
19+
mode: "user"
20+
roles: "readWrite"
21+
force_update: True
22+
with_items:
23+
- "{{ db.credentials.controller }}"
24+
- "{{ db.credentials.invoker }}"
25+
26+
- name: create necessary auth keys
27+
mongodb:
28+
database: "{{ db.mongodb.database }}"
29+
login_user: "{{ db.credentials.admin.user }}"
30+
login_password: "{{ db.credentials.admin.pass }}"
31+
login_host: "{{ db.host }}"
32+
login_port: "{{ db.port }}"
33+
login_database: "{{ db.mongodb.database }}"
34+
collection: "{{ db.whisk.auth }}"
35+
doc:
36+
_id: "{{ item }}"
37+
subject: "{{ item }}"
38+
namespaces:
39+
- name: "{{ item }}"
40+
uuid: "{{ key.split(':')[0] }}"
41+
key: "{{ key.split(':')[1] }}"
42+
mode: "doc"
43+
force_update: True
44+
vars:
45+
key: "{{ lookup('file', 'files/auth.{{ item }}') }}"
46+
with_items: "{{ db.authkeys }}"
47+
48+
- name: create necessary indexes on {{ db.whisk.auth }}
49+
mongodb:
50+
database: "{{ db.mongodb.database }}"
51+
login_user: "{{ db.credentials.admin.user }}"
52+
login_password: "{{ db.credentials.admin.pass }}"
53+
login_host: "{{ db.host }}"
54+
login_port: "{{ db.port }}"
55+
login_database: "{{ db.mongodb.database }}"
56+
collection: "{{ db.whisk.auth }}"
57+
indexes:
58+
- index:
59+
- field: "namespaces.name"
60+
direction: -1
61+
- index:
62+
- field: "namespaces.uuid"
63+
direction: -1
64+
- field: "namespaces.key"
65+
direction: -1
66+
mode: "index"

0 commit comments

Comments
 (0)