You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/02/08 15:08:12 UTC

[GitHub] cbickel closed pull request #3206: Refactor controller role to use variables for hostname and host index

cbickel closed pull request #3206: Refactor controller role to use variables for hostname and host index
URL: https://github.com/apache/incubator-openwhisk/pull/3206
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/ansible/group_vars/all b/ansible/group_vars/all
index 92b047ed1e..6978fb97ac 100644
--- a/ansible/group_vars/all
+++ b/ansible/group_vars/all
@@ -43,9 +43,6 @@ limits:
   firesPerMinute: "{{ limit_fires_per_minute | default(60) }}"
   sequenceMaxLength: "{{ limit_sequence_max_length | default(50) }}"
 
-controllerHostnameFromMap: "{{ groups['controllers'] | map('extract', hostvars, 'ansible_host') | list | first }}"
-controllerHostname: "{{ controllerHostnameFromMap | default(inventory_hostname) }}"
-
 # port means outer port
 controller:
   dir:
@@ -68,10 +65,6 @@ controller:
   # We recommend to enable HA for the controllers only, if bookkeeping data are shared too. (localBookkeeping: false)
   ha: "{{ controller_enable_ha | default(True) and groups['controllers'] | length > 1 }}"
   loglevel: "{{ controller_loglevel | default(whisk_loglevel) | default('INFO') }}"
-  jmxremote:
-    jvmArgs:  "{% if inventory_hostname in groups['controllers'] %}
-    {{ jmx.jvmCommonArgs }} -Djava.rmi.server.hostname={{ controllerHostname }} -Dcom.sun.management.jmxremote.rmi.port={{ jmx.rmiBasePortController + groups['controllers'].index(inventory_hostname) }} -Dcom.sun.management.jmxremote.port={{ jmx.basePortController + groups['controllers'].index(inventory_hostname) }}
-    {% endif %}"
 
 jmx:
   basePortController: 15000
diff --git a/ansible/roles/controller/tasks/clean.yml b/ansible/roles/controller/tasks/clean.yml
index 231198a489..c34b8e8756 100644
--- a/ansible/roles/controller/tasks/clean.yml
+++ b/ansible/roles/controller/tasks/clean.yml
@@ -1,21 +1,29 @@
 ---
 # Remove controller containers.
 
+- name: get controller index
+  set_fact:
+    controller_index: "{{ groups['controllers'].index(inventory_hostname) }}"
+
+- name: get controller name
+  set_fact:
+    controller_name: "controller{{ controller_index }}"
+
 - name: remove controller
   docker_container:
-    name: "controller{{ groups['controllers'].index(inventory_hostname) }}"
+    name: "{{ controller_name }}"
     image: "{{ docker_registry }}{{ docker.image.prefix }}/controller:{{ docker.image.tag }}"
     state: absent
   ignore_errors: True
 
 - name: remove controller log directory
   file:
-    path: "{{ whisk_logs_dir }}/controller{{ groups['controllers'].index(inventory_hostname) }}"
+    path: "{{ whisk_logs_dir }}/{{ controller_name }}"
     state: absent
   become: "{{ logs.dir.become }}"
 
 - name: remove controller conf directory
   file:
-    path: "{{ controller.confdir }}/controller{{ groups['controllers'].index(inventory_hostname) }}"
+    path: "{{ controller.confdir }}/{{ controller_name }}"
     state: absent
   become: "{{ controller.dir.become }}"
diff --git a/ansible/roles/controller/tasks/deploy.yml b/ansible/roles/controller/tasks/deploy.yml
index e67343850a..8601a2985d 100644
--- a/ansible/roles/controller/tasks/deploy.yml
+++ b/ansible/roles/controller/tasks/deploy.yml
@@ -3,6 +3,14 @@
 
 - include: docker_login.yml
 
+- name: get controller index
+  set_fact:
+    controller_index: "{{ groups['controllers'].index(inventory_hostname) }}"
+
+- name: get controller name
+  set_fact:
+    controller_name: "controller{{ controller_index }}"
+
 - name: "pull the {{ docker.image.tag }} image of controller"
   shell: "docker pull {{ docker_registry }}{{ docker.image.prefix }}/controller:{{ docker.image.tag }}"
   when: docker_registry != ""
@@ -11,14 +19,14 @@
 
 - name: ensure controller log directory is created with permissions
   file:
-    path: "{{ whisk_logs_dir }}/controller{{ groups['controllers'].index(inventory_hostname) }}"
+    path: "{{ whisk_logs_dir }}/{{ controller_name }}"
     state: directory
     mode: 0777
   become: "{{ logs.dir.become }}"
 
 - name: ensure controller config directory is created with permissions
   file:
-    path: "{{ controller.confdir }}/controller{{ groups['controllers'].index(inventory_hostname) }}"
+    path: "{{ controller.confdir }}/{{ controller_name }}"
     state: directory
     mode: 0777
   become: "{{ controller.dir.become }}"
@@ -27,14 +35,14 @@
   when: jmx.enabled
   template:
     src: "jmxremote.password.j2"
-    dest: "{{ controller.confdir }}/controller{{ groups['controllers'].index(inventory_hostname) }}/jmxremote.password"
+    dest: "{{ controller.confdir }}/{{ controller_name }}/jmxremote.password"
     mode: 0777
 
 - name: copy jmxremote access file
   when: jmx.enabled
   template:
     src: "jmxremote.access.j2"
-    dest: "{{ controller.confdir }}/controller{{ groups['controllers'].index(inventory_hostname) }}/jmxremote.access"
+    dest: "{{ controller.confdir }}/{{ controller_name }}/jmxremote.access"
     mode: 0777
 
 - name: check, that required databases exist
@@ -48,17 +56,17 @@
 
 - name: prepare controller ports
   set_fact:
-    ports_to_expose: ["{{ controller.basePort + groups['controllers'].index(inventory_hostname) }}:8080", "{{ controller.akka.cluster.basePort + groups['controllers'].index(inventory_hostname) }}:{{ controller.akka.cluster.bindPort }}"]
+    ports_to_expose: ["{{ controller.basePort + (controller_index | int) }}:8080", "{{ controller.akka.cluster.basePort + (controller_index | int) }}:{{ controller.akka.cluster.bindPort }}"]
 
 - name: expose additional ports if jmxremote is enabled
   when: jmx.enabled
   set_fact:
-    ports_to_expose: "{{ ports_to_expose }} + [ \"{{ jmx.basePortController + groups['controllers'].index(inventory_hostname) }}:{{ jmx.basePortController + groups['controllers'].index(inventory_hostname) }}\" ] + [ \"{{ jmx.rmiBasePortController + groups['controllers'].index(inventory_hostname) }}:{{ jmx.rmiBasePortController + groups['controllers'].index(inventory_hostname) }}\" ]"
+    ports_to_expose: "{{ ports_to_expose }} + [ \"{{ jmx.basePortController + (controller_index | int) }}:{{ jmx.basePortController + (controller_index | int)}}\" ] + [ \"{{ jmx.rmiBasePortController + (controller_index | int) }}:{{ jmx.rmiBasePortController + (controller_index | int) }}\" ]"
 
 - name: add additional jvm params if jmxremote is enabled
   when: jmx.enabled
   set_fact:
-    controller_args: "{{ controller.arguments }} {{ controller.jmxremote.jvmArgs }}"
+    controller_args: "{{ controller.arguments }} {{ jmx.jvmCommonArgs }} -Djava.rmi.server.hostname={{ inventory_hostname }} -Dcom.sun.management.jmxremote.rmi.port={{ jmx.rmiBasePortController + (controller_index | int) }} -Dcom.sun.management.jmxremote.port={{ jmx.basePortController + (controller_index | int) }}"
 
 - name: create seed nodes list
   set_fact:
@@ -68,19 +76,19 @@
 
 - name: (re)start controller
   docker_container:
-    name: controller{{ groups['controllers'].index(inventory_hostname) }}
+    name: "{{ controller_name }}"
     image: "{{ docker_registry }}{{ docker.image.prefix }}/controller:{{ docker.image.tag }}"
     state: started
     recreate: true
     restart_policy: "{{ docker.restart.policy }}"
-    hostname: "controller{{ groups['controllers'].index(inventory_hostname) }}"
+    hostname: "{{ controller_name }}"
     env:
       "JAVA_OPTS": "-Xmx{{ controller.heap }} -XX:+CrashOnOutOfMemoryError -XX:+UseGCOverheadLimit -XX:ErrorFile=/logs/java_error.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/logs"
       "CONTROLLER_OPTS": "{{ controller_args | default(controller.arguments) }}"
       "CONTROLLER_INSTANCES": "{{ controller.instances }}"
       "JMX_REMOTE": "{{ jmx.enabled }}"
 
-      "COMPONENT_NAME": "controller{{ groups['controllers'].index(inventory_hostname) }}"
+      "COMPONENT_NAME": "{{ controller_name }}"
       "PORT": 8080
 
       "WHISK_VERSION_NAME": "{{ whisk_version_name }}"
@@ -136,8 +144,8 @@
       "CONFIG_whisk_loadbalancer_blackboxFraction": "{{ controller.blackboxFraction }}"
 
       "CONFIG_akka_actor_provider": "{{ controller.akka.provider }}"
-      "CONFIG_akka_remote_netty_tcp_hostname": "{{ controller.akka.cluster.host[groups['controllers'].index(inventory_hostname)] }}"
-      "CONFIG_akka_remote_netty_tcp_port": "{{ controller.akka.cluster.basePort + groups['controllers'].index(inventory_hostname) }}"
+      "CONFIG_akka_remote_netty_tcp_hostname": "{{ controller.akka.cluster.host[(controller_index | int)] }}"
+      "CONFIG_akka_remote_netty_tcp_port": "{{ controller.akka.cluster.basePort + (controller_index | int) }}"
       "CONFIG_akka_remote_netty_tcp_bindPort": "{{ controller.akka.cluster.bindPort }}"
 
       "CONFIG_kamon_statsd_hostname": "{{ metrics.kamon.host }}"
@@ -149,15 +157,15 @@
 
       "CONFIG_whisk_transactions_stride": "{{ transactions.stride | default() }}"
     volumes:
-      - "{{ whisk_logs_dir }}/controller{{ groups['controllers'].index(inventory_hostname) }}:/logs"
-      - "{{ controller.confdir }}/controller{{ groups['controllers'].index(inventory_hostname) }}:/conf"
+      - "{{ whisk_logs_dir }}/{{ controller_name }}:/logs"
+      - "{{ controller.confdir }}/{{ controller_name }}:/conf"
     ports: "{{ ports_to_expose }}"
-    command: /bin/sh -c "exec /init.sh {{ groups['controllers'].index(inventory_hostname) }} >> /logs/controller{{ groups['controllers'].index(inventory_hostname) }}_logs.log 2>&1"
+    command: /bin/sh -c "exec /init.sh {{ controller_index }} >> /logs/{{ controller_name }}_logs.log 2>&1"
 
 - name: wait until the Controller in this host is up and running
   uri:
-    url: "http://{{ ansible_host }}:{{ controller.basePort + groups['controllers'].index(inventory_hostname) }}/ping"
+    url: "http://{{ ansible_host }}:{{ controller.basePort + (controller_index | int) }}/ping"
   register: result
   until: result.status == 200
   retries: 12
-  delay: 5
\ No newline at end of file
+  delay: 5


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services