Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an ElasticSearchActivationStore #4724

Merged
merged 20 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ansible/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
# This playbook deploys a ElasticSearch cluster

- hosts: elasticsearch
vars:
#
# host_group - usually "{{ groups['...'] }}" where '...' is what was used
# for 'hosts' above. The hostname of each host will be looked up in this
# group to assign a zero-based index. That index will be used in concert
# with 'name_prefix' below to assign a host/container name.
host_group: "{{ groups['elasticsearch'] }}"
#
# name_prefix - a unique prefix for this set of elasticsearches. The prefix
# will be used in combination with an index (determined using
# 'host_group' above) to name host/elasticsearcher.
name_prefix: "elasticsearch"
roles:
- elasticsearch
3 changes: 3 additions & 0 deletions ansible/environments/docker-machine/hosts.j2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ invoker1 ansible_host={{ docker_machine_ip }}
[apigateway]
{{ docker_machine_ip }} ansible_host={{ docker_machine_ip }}

[elasticsearch:children]
db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the meaning of db here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means elasticsearch nodes will be deployed on the same hosts specified in the db section.


; define variables
[all:vars]
ansible_connection=ssh
Expand Down
3 changes: 3 additions & 0 deletions ansible/environments/local/hosts.j2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ invoker1 ansible_host=172.17.0.1 ansible_connection=local
[db]
172.17.0.1 ansible_host=172.17.0.1 ansible_connection=local

[elasticsearch:children]
db

[redis]
172.17.0.1 ansible_host=172.17.0.1 ansible_connection=local

Expand Down
3 changes: 3 additions & 0 deletions ansible/environments/vagrant/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ invoker0 ansible_host=172.17.0.1 ansible_connection=local

[apigateway]
172.17.0.1 ansible_host=172.17.0.1 ansible_connection=local

[elasticsearch:children]
db
jiangpengcheng marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 30 additions & 0 deletions ansible/group_vars/all
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,27 @@ db:
invoker:
user: "{{ db_invoker_user | default(lookup('ini', 'db_username section=invoker file={{ playbook_dir }}/db_local.ini')) }}"
pass: "{{ db_invoker_pass | default(lookup('ini', 'db_password section=invoker file={{ playbook_dir }}/db_local.ini')) }}"
activation_store:
backend: "{{ db_activation_backend | default('CouchDB') }}"
elasticsearch:
protocol: "{{ elastic_protocol | default('http') }}"
port: 9200
index_pattern: "{{ elastic_index_pattern | default('openwhisk-%s') }}"
base_transport_port: 9300
confdir: "{{ config_root_dir }}/elasticsearch"
dir:
become: "{{ elastic_dir_become | default(false) }}"
base_volume: "{{ elastic_base_volume | default('esdata') }}"
cluster_name: "{{ elastic_cluster_name | default('openwhisk') }}"
java_opts: "{{ elastic_java_opts | default('-Xms1g -Xmx1g') }}"
loglevel: "{{ elastic_loglevel | default('INFO') }}"
# the user id of elasticsearch process, default is 1000, if you have enabled user namespace
# for docker daemon, this need to be changed correspondingly
uid: "{{ elastic_uid | default(1000) }}"
auth:
admin:
username: "{{ elastic_username | default('admin') }}"
password: "{{ elastic_password | default('admin') }}"

apigateway:
port:
Expand All @@ -290,6 +311,15 @@ linux:
couchdb:
version: 2.3

elasticsearch:
version: 6.4.2

elasticsearch_connect_string: "{% set ret = [] %}\
{% for host in groups['elasticsearch'] %}\
{{ ret.append( hostvars[host].ansible_host + ':' + ((db.elasticsearch.port+loop.index-1)|string) ) }}\
{% endfor %}\
{{ ret | join(',') }}"

docker:
# The user to install docker for. Defaults to the ansible user if not set. This will be the user who is able to run
# docker commands on a machine setup with prereq_build.yml
Expand Down
16 changes: 16 additions & 0 deletions ansible/roles/controller/tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@
set_fact:
env: "{{ env | combine(controller.extraEnv) }}"

- name: setup elasticsearch activation store env
set_fact:
elastic_env:
"CONFIG_whisk_activationStore_elasticsearch_protocol": "{{ db.elasticsearch.protocol}}"
"CONFIG_whisk_activationStore_elasticsearch_hosts": "{{ elasticsearch_connect_string }}"
"CONFIG_whisk_activationStore_elasticsearch_indexPattern": "{{ db.elasticsearch.index_pattern }}"
"CONFIG_whisk_activationStore_elasticsearch_username": "{{ db.elasticsearch.auth.admin.username }}"
"CONFIG_whisk_activationStore_elasticsearch_password": "{{ db.elasticsearch.auth.admin.password }}"
"CONFIG_whisk_spi_ActivationStoreProvider": "org.apache.openwhisk.core.database.elasticsearch.ElasticSearchActivationStoreProvider"
when: db.activation_store.backend == "ElasticSearch"

- name: merge elasticsearch activation store env
set_fact:
env: "{{ env | combine(elastic_env) }}"
when: db.activation_store.backend == "ElasticSearch"

- name: populate volumes for controller
set_fact:
controller_volumes:
Expand Down
39 changes: 39 additions & 0 deletions ansible/roles/elasticsearch/tasks/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
# Remove ElasticSearch server

- name: set elasticsearch container name and volume
set_fact:
elasticsearch_name: "{{ name_prefix ~ host_group.index(inventory_hostname) }}"
volume_name: "{{ db.elasticsearch.base_volume ~ host_group.index(inventory_hostname) }}"

- name: remove ElasticSearch
vars:
elasticsearch_image: "{{ elasticsearch.docker_image | default('docker.elastic.co/elasticsearch/elasticsearch:' ~ elasticsearch.version ) }}"
docker_container:
name: "{{ elasticsearch_name }}"
image: "{{ elasticsearch_image }}"
keep_volumes: False
state: absent
ignore_errors: True

- name: remove ElasticSearch conf dir
file:
path: "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}"
state: absent
become: "{{ db.elasticsearch.dir.become }}"
96 changes: 96 additions & 0 deletions ansible/roles/elasticsearch/tasks/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
# This role will run a ElasticSearch server on the db group

- name: set the vm.max_map_count to 262144
sysctl:
name: vm.max_map_count
value: '262144'
become: true

- name: set elasticsearch container name, volume and port
set_fact:
elasticsearch_name: "{{ name_prefix ~ host_group.index(inventory_hostname) }}"
volume_name: "{{ db.elasticsearch.base_volume ~ host_group.index(inventory_hostname) }}"
http_port: "{{ (db.elasticsearch.port|int) + host_group.index(inventory_hostname) }}"
transport_port: "{{ (db.elasticsearch.base_transport_port|int) + host_group.index(inventory_hostname) }}"

- name: ensure elasticserach config directory is created with permissions
file:
path: "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}"
state: directory
mode: 0755
become: "{{ db.elasticsearch.dir.become }}"

# create volume direcotry if it's a directory path(not a named volume)
- name: ensure elasticserach volume directory is created with permissions
file:
path: "{{ volume_name }}"
state: directory
mode: 0700
owner: "{{ db.elasticsearch.uid }}"
become: true
when: volume_name is search("/")

- name: copy elasticsearch config file
template:
src: "elasticsearch.yml.j2"
dest: "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/elasticsearch.yml"
mode: 0644
become: "{{ db.elasticsearch.dir.become }}"

- name: copy elasticsearch log config file
template:
src: "log4j2.properties.j2"
dest: "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/log4j2.properties"
mode: 0644
become: "{{ db.elasticsearch.dir.become }}"

- name: "(re)start ElasticSearch from '{{ elasticsearch_image }} ' "
vars:
elasticsearch_image: "{{ elasticsearch.docker_image | default('docker.elastic.co/elasticsearch/elasticsearch:' ~ elasticsearch.version ) }}"
docker_container:
name: "{{ elasticsearch_name }}"
image: "{{ elasticsearch_image }}"
state: started
recreate: true
restart_policy: "{{ docker.restart.policy }}"
ports:
- "{{ http_port }}:9200"
- "{{ transport_port }}:{{ transport_port }}"
volumes:
- "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
- "{{ db.elasticsearch.confdir }}/{{ elasticsearch_name }}/log4j2.properties:/usr/share/elasticsearch/config/log4j2.properties"
- "{{ volume_name }}:/usr/share/elasticsearch/data"
pull: "{{ docker.pull_elasticsearch | default(true) }}"
ulimits:
- "nofile:262144:262144"
- "memlock:-1:-1"
env:
TZ: "{{ docker.timezone }}"
ES_JAVA_OPTS: "{{ db.elasticsearch.java_opts }}"

- name: wait until ElasticSearch in this host is up and running
uri:
url: "{{ db.elasticsearch.protocol }}:https://{{ ansible_host }}:{{ http_port }}"
status_code: 200
return_content: yes
register: result
until: result.json is defined
retries: 12
delay: 5
26 changes: 26 additions & 0 deletions ansible/roles/elasticsearch/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
---
# This role will deploy a database server. Use the role if you want to use ElasticSearch locally.
# In deploy mode it will start the ElasticSearch container.
# In clean mode it will remove the ElasticSearch container.

- import_tasks: deploy.yml
when: mode == "deploy"

- import_tasks: clean.yml
when: mode == "clean"
23 changes: 23 additions & 0 deletions ansible/roles/elasticsearch/templates/elasticsearch.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cluster.name: "{{ db.elasticsearch.cluster_name }}"
node.name: "{{ elasticsearch_name }}"
network.host: 0.0.0.0
network.publish_host: {{ ansible_default_ipv4.address }}

http.port: 9200
transport.tcp.port: {{ transport_port }}

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17282
discovery.zen.ping.unicast.hosts:
{% for es in groups['elasticsearch'] %}
- {{ hostvars[es].ansible_host }}:{{ db.elasticsearch.base_transport_port + host_group.index(es)|int }}
{% endfor %}
discovery.zen.minimum_master_nodes: {{ (host_group|length / 2 + 1) | int}}

gateway.recover_after_nodes: {{ (host_group|length / 2 + 1) | int }}
gateway.expected_nodes: {{ host_group|length }}
gateway.recover_after_time: 5m

xpack.security.enabled: false
bootstrap.memory_lock: true
10 changes: 10 additions & 0 deletions ansible/roles/elasticsearch/templates/log4j2.properties.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
status = error

appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n

rootLogger.appenderRef.console.ref = console

rootLogger.level = {{ db.elasticsearch.loglevel }}
16 changes: 16 additions & 0 deletions ansible/roles/invoker/tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@
set_fact:
env: "{{ env | combine(invoker.extraEnv) }}"

- name: setup elasticsearch activation store env
set_fact:
elastic_env:
"CONFIG_whisk_activationStore_elasticsearch_protocol": "{{ db.elasticsearch.protocol}}"
jiangpengcheng marked this conversation as resolved.
Show resolved Hide resolved
"CONFIG_whisk_activationStore_elasticsearch_hosts": "{{ elasticsearch_connect_string }}"
"CONFIG_whisk_activationStore_elasticsearch_indexPattern": "{{ db.elasticsearch.index_pattern }}"
"CONFIG_whisk_activationStore_elasticsearch_username": "{{ db.elasticsearch.auth.admin.username }}"
"CONFIG_whisk_activationStore_elasticsearch_password": "{{ db.elasticsearch.auth.admin.password }}"
"CONFIG_whisk_spi_ActivationStoreProvider": "org.apache.openwhisk.core.database.elasticsearch.ElasticSearchActivationStoreProvider"
when: db.activation_store.backend == "ElasticSearch"

- name: merge elasticsearch activation store env
set_fact:
env: "{{ env | combine(elastic_env) }}"
when: db.activation_store.backend == "ElasticSearch"

- name: include plugins
include_tasks: "{{ inv_item }}.yml"
with_items: "{{ invoker_plugins | default([]) }}"
Expand Down
2 changes: 2 additions & 0 deletions common/scala/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ dependencies {
compile 'io.reactivex:rxjava-reactive-streams:1.2.1'
compile ('com.microsoft.azure:azure-cosmosdb:2.6.2')

compile 'com.sksamuel.elastic4s:elastic4s-http_2.12:6.4.0'
jiangpengcheng marked this conversation as resolved.
Show resolved Hide resolved

compile ('com.lightbend.akka:akka-stream-alpakka-s3_2.12:1.0.1') {
exclude group: 'org.apache.httpcomponents' //Not used as alpakka uses akka-http
exclude group: 'com.fasterxml.jackson.core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ object ConfigKeys {
val controllerActivation = s"$controller.activation"

val activationStore = "whisk.activation-store"
val elasticSearchActivationStore = s"$activationStore.elasticsearch"
val activationStoreWithFileStorage = s"$activationStore.with-file-storage"

val metrics = "whisk.metrics"
Expand Down
Loading