-
Notifications
You must be signed in to change notification settings - Fork 9
/
spark-cluster-setup.yml
185 lines (165 loc) · 5.48 KB
/
spark-cluster-setup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
---
- name: Create a Spark cluster
hosts: local
connection: local
gather_facts: no
vars:
instance_tag: "{{ spark_tag }}"
instance_count: "{{ spark_worker_per_az_count }}"
instance_function: spark
az_list: "{{ cluster_az_list }}"
instance_type: "{{ spark_instance_type }}"
tasks:
- name: Import configuration properties
include_vars:
dir: vars
- name: "stat {{ feature_key_path }}"
local_action: "stat path={{ feature_key_path }}"
become: no
register: feature_key_meta
- name: "Check feature key {{ feature_key_path }} exists"
fail:
msg: "Specified feature key {{ feature_key_path }} not found - required to use Spark connector"
when: not feature_key_meta.stat.exists
- name: "Setup {{ instance_function }} instance vars"
include_vars: modules/instance-setup-vars.yml
- name: "Setup {{ instance_function }} instances"
import_tasks: modules/instance-setup.yml
- meta: refresh_inventory
- name: Set up Spark
hosts: "{{ spark_tag }}"
gather_facts: false
become: no
remote_user: "{{ os_config['remote_user'] }}"
vars_files:
- vars/cluster-config.yml
- vars/constants.yml
- vars/os-level-config.yml
tasks:
- name: Import configuration properties
include_vars:
dir: vars
- block:
- name: If Ubuntu, update package cache
shell: |
sudo apt update
when: operating_system == ubuntu_os
- name: Install Java
package:
name:
- "{{ os_config['java_package_name'] }}"
state: present
become: yes
- name: Install Scala
shell: |
set -e
if [ -z $(which scala 2>/dev/null ) ]
then
cd /tmp
wget https://downloads.typesafe.com/scala/{{ scala_version }}/scala-{{ scala_version }}.tgz
tar xzf "scala-{{ scala_version }}.tgz"
mkdir "{{ scala_home }}"
rm "/tmp/scala-{{ scala_version }}/bin/"*.bat
mv "/tmp/scala-{{ scala_version }}/bin" "/tmp/scala-{{ scala_version }}/lib" "{{ scala_home }}"
ln -s "{{ scala_home }}/bin/"* "/usr/bin/"
rm "/tmp/scala-{{ scala_version }}.tgz"
rm -rf "/tmp/scala-{{ scala_version }}"
fi
become: yes
- name: Install Spark
shell: |
set -e
mkdir -p /etc/aerospike
if [ ! -d /spark ]
then
cd /tmp
wget https://downloads.apache.org/spark/spark-{{ spark_version }}/spark-{{ spark_version }}-bin-hadoop{{ hadoop_version}}.tgz
tar xvfz spark-{{ spark_version }}-bin-hadoop{{ hadoop_version}}.tgz
mv spark-{{ spark_version }}-bin-hadoop{{ hadoop_version}} /spark
rm spark-{{ spark_version }}-bin-hadoop{{ hadoop_version}}.tgz
fi
become: yes
- name: Install Aerospike Spark Connect
shell: |
set -e
if [ ! -f /spark/jars/ aerospike-spark-{{ aerospike_spark_connect_version }}_spark_{{ spark_version }}_{{ hadoop_version }}_allshaded.jar ]
then
cd /tmp
wget https://www.aerospike.com/enterprise/download/connectors/aerospike-spark/{{ aerospike_spark_connect_version }}/artifact/jar -O aerospike-spark-{{ aerospike_spark_connect_version }}_spark_{{ spark_version }}_{{ hadoop_version }}_allshaded.jar
mv aerospike-spark-{{ aerospike_spark_connect_version }}_spark_{{ spark_version }}_{{ hadoop_version }}_allshaded.jar /spark/jars/
fi
become: yes
- name: Copy feature key
copy:
src: "{{ feature_key_path }}"
dest: /etc/aerospike/features.conf
owner: root
group: root
mode: '0644'
become: yes
- name: Start Master
hosts: "{{ spark_tag }}[0]"
gather_facts: false
become: no
remote_user: "{{ os_config['remote_user'] }}"
vars_files:
- vars/cluster-config.yml
- vars/constants.yml
- vars/os-level-config.yml
tasks:
- name: Start Master
become: yes
shell: |
set -e
/spark/sbin/stop-master.sh
/spark/sbin/start-master.sh
- name: Start Spark worker processes
hosts: "{{ spark_tag }}"
gather_facts: false
become: no
remote_user: "{{ os_config['remote_user'] }}"
vars_files:
- vars/cluster-config.yml
- vars/constants.yml
- vars/os-level-config.yml
tasks:
- name: Import configuration properties
include_vars:
dir: vars
- name: Get Spark master
delegate_to: localhost
ec2_instance_info:
region: "{{ aws_region }}"
filters:
instance-state-name: [ "pending", "running" ]
dns-name: "{{ groups.aerospike_spark[0] }}"
"tag:group": "{{ spark_tag }}"
register: spark_info
- name: Start agents
become: yes
shell: |
set -e
/spark/sbin/stop-slave.sh
/spark/sbin/start-slave.sh spark://{{ spark_info.instances[0].private_ip_address }}:{{ spark_master_port }}
- name: Spark Info
hosts: local
connection: local
gather_facts: no
tasks:
- name: Import configuration properties
include_vars:
dir: vars
- name: Get Spark master
ec2_instance_info:
region: "{{ aws_region }}"
filters:
instance-state-name: [ "pending", "running" ]
dns-name: "{{ groups.aerospike_spark[0] }}"
"tag:group": "{{ spark_tag }}"
register: spark_info
- name: Spark master IP & master internal url
debug:
msg: "Spark master is {{ groups.aerospike_spark[0] }}. Spark master internal url is spark://{{ spark_info.instances[0].private_ip_address }}:{{ spark_master_port }}."
- name: Spark web URL
debug:
msg: "Spark web url is http://{{ groups.aerospike_spark[0] }}:{{ spark_master_web_port }}"