File: plugin.sh

package info (click to toggle)
sahara 1%3A16.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,452 kB
  • sloc: python: 39,677; xml: 3,418; sh: 874; makefile: 80
file content (373 lines) | stat: -rwxr-xr-x 11,456 bytes parent folder | download
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#!/bin/bash
#
# lib/sahara

# Dependencies:
# ``functions`` file
# ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined

# ``stack.sh`` calls the entry points in this order:
#
# install_sahara
# install_python_saharaclient
# configure_sahara
# start_sahara
# stop_sahara
# cleanup_sahara

# Save trace setting
XTRACE=$(set +o | grep xtrace)
set -o xtrace


# Functions
# ---------

# create_sahara_accounts() - Set up common required sahara accounts
#
# Tenant      User       Roles
# ------------------------------
# service     sahara    admin
function create_sahara_accounts {

    create_service_user "sahara"

    get_or_create_service "sahara" "data-processing" "Sahara Data Processing"
    get_or_create_endpoint "data-processing" \
        "$REGION_NAME" \
        "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT" \
        "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT" \
        "$SAHARA_SERVICE_PROTOCOL://$SAHARA_SERVICE_HOST:$SAHARA_SERVICE_PORT"
}

# cleanup_sahara() - Remove residual data files, anything left over from
# previous runs that would need to clean up.
function cleanup_sahara {

    # Cleanup auth cache dir
    if [ "$SAHARA_USE_MOD_WSGI" == "True" ]; then
        sudo rm -f $(apache_site_config_for sahara-api)
    fi
}

function configure_sahara_apache_wsgi {

    local sahara_apache_conf=$(apache_site_config_for sahara-api)
    local sahara_ssl=""
    local sahara_certfile=""
    local sahara_keyfile=""
    local venv_path=""

    if is_ssl_enabled_service sahara; then
        sahara_ssl="SSLEngine On"
        sahara_certfile="SSLCertificateFile $SAHARA_SSL_CERT"
        sahara_keyfile="SSLCertificateKeyFile $SAHARA_SSL_KEY"
    fi

    sudo cp $SAHARA_DIR/devstack/files/apache-sahara-api.template $sahara_apache_conf
    sudo sed -e "
        s|%PUBLICPORT%|$SAHARA_SERVICE_PORT|g;
        s|%APACHE_NAME%|$APACHE_NAME|g;
        s|%SAHARA_BIN_DIR%|$SAHARA_BIN_DIR|g;
        s|%SSLENGINE%|$sahara_ssl|g;
        s|%SSLCERTFILE%|$sahara_certfile|g;
        s|%SSLKEYFILE%|$sahara_keyfile|g;
        s|%USER%|$STACK_USER|g;
        s|%VIRTUALENV%|$venv_path|g
    " -i $sahara_apache_conf

}

# configure_sahara() - Set config files, create data dirs, etc
function configure_sahara {
    sudo install -d -o $STACK_USER $SAHARA_CONF_DIR

    cp -p $SAHARA_DIR/etc/sahara/api-paste.ini $SAHARA_CONF_DIR

    configure_keystone_authtoken_middleware $SAHARA_CONF_FILE sahara

    # Set admin user parameters needed for trusts creation
    iniset $SAHARA_CONF_FILE \
        trustee project_name $SERVICE_TENANT_NAME
    iniset $SAHARA_CONF_FILE trustee username sahara
    iniset $SAHARA_CONF_FILE \
        trustee password $SERVICE_PASSWORD
    iniset $SAHARA_CONF_FILE \
        trustee user_domain_name "$SERVICE_DOMAIN_NAME"
    iniset $SAHARA_CONF_FILE \
        trustee project_domain_name "$SERVICE_DOMAIN_NAME"
    iniset $SAHARA_CONF_FILE \
        trustee auth_url "$KEYSTONE_SERVICE_URI/v3"

    iniset_rpc_backend sahara $SAHARA_CONF_FILE DEFAULT

    # Set configuration to send notifications

    if is_service_enabled ceilometer; then
        iniset $SAHARA_CONF_FILE oslo_messaging_notifications driver "messaging"
    fi

    iniset $SAHARA_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL

    iniset $SAHARA_CONF_FILE DEFAULT plugins $SAHARA_ENABLED_PLUGINS

    iniset $SAHARA_CONF_FILE \
        database connection `database_connection_url sahara`

    if is_service_enabled neutron; then
        iniset $SAHARA_CONF_FILE neutron endpoint_type $SAHARA_ENDPOINT_TYPE
        if is_ssl_enabled_service "neutron" \
            || is_service_enabled tls-proxy; then
            iniset $SAHARA_CONF_FILE neutron ca_file $SSL_BUNDLE_FILE
        fi
    fi

    if is_ssl_enabled_service "heat" || is_service_enabled tls-proxy; then
        iniset $SAHARA_CONF_FILE heat ca_file $SSL_BUNDLE_FILE
    fi
    iniset $SAHARA_CONF_FILE heat endpoint_type $SAHARA_ENDPOINT_TYPE

    if is_ssl_enabled_service "cinder" || is_service_enabled tls-proxy; then
        iniset $SAHARA_CONF_FILE cinder ca_file $SSL_BUNDLE_FILE
    fi
    iniset $SAHARA_CONF_FILE cinder endpoint_type $SAHARA_ENDPOINT_TYPE

    if is_ssl_enabled_service "nova" || is_service_enabled tls-proxy; then
        iniset $SAHARA_CONF_FILE nova ca_file $SSL_BUNDLE_FILE
    fi
    iniset $SAHARA_CONF_FILE nova endpoint_type $SAHARA_ENDPOINT_TYPE

    if is_ssl_enabled_service "swift" || is_service_enabled tls-proxy; then
        iniset $SAHARA_CONF_FILE swift ca_file $SSL_BUNDLE_FILE
    fi
    iniset $SAHARA_CONF_FILE swift endpoint_type $SAHARA_ENDPOINT_TYPE

    if is_ssl_enabled_service "key" || is_service_enabled tls-proxy; then
        iniset $SAHARA_CONF_FILE keystone ca_file $SSL_BUNDLE_FILE
    fi
    iniset $SAHARA_CONF_FILE keystone endpoint_type $SAHARA_ENDPOINT_TYPE

    if is_ssl_enabled_service "glance" || is_service_enabled tls-proxy; then
        iniset $SAHARA_CONF_FILE glance ca_file $SSL_BUNDLE_FILE
    fi
    iniset $SAHARA_CONF_FILE glance endpoint_type $SAHARA_ENDPOINT_TYPE

    # Register SSL certificates if provided
    if is_ssl_enabled_service sahara; then
        ensure_certificates SAHARA

        iniset $SAHARA_CONF_FILE ssl cert_file "$SAHARA_SSL_CERT"
        iniset $SAHARA_CONF_FILE ssl key_file "$SAHARA_SSL_KEY"
    fi

    iniset $SAHARA_CONF_FILE DEFAULT use_syslog $SYSLOG

    # Format logging
    if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
        if [ "$SAHARA_USE_MOD_WSGI" == "False" ]; then
            setup_colorized_logging $SAHARA_CONF_FILE DEFAULT
        fi
    fi

    if is_service_enabled tls-proxy; then
        # Set the service port for a proxy to take the original
        iniset $SAHARA_CONF_FILE DEFAULT port $SAHARA_SERVICE_PORT_INT
    fi

    if [ "$SAHARA_ENABLE_DISTRIBUTED_PERIODICS" == "True" ]; then
        # Enable distributed periodic tasks
        iniset $SAHARA_CONF_FILE DEFAULT periodic_coordinator_backend_url\
            $SAHARA_PERIODIC_COORDINATOR_URL
        pip_install tooz[memcached]

        restart_service memcached
    fi

    recreate_database sahara
    $SAHARA_BIN_DIR/sahara-db-manage \
        --config-file $SAHARA_CONF_FILE upgrade head

    if [ "$SAHARA_USE_MOD_WSGI" == "True" ]; then
        configure_sahara_apache_wsgi
    fi
}

# install_sahara() - Collect source and prepare
function install_sahara {
    setup_develop $SAHARA_DIR
    if [ "$SAHARA_USE_MOD_WSGI" == "True" ]; then
        install_apache_wsgi
    fi
}

# install_ambari() - Collect source and prepare
function install_ambari {
    git_clone $AMBARI_PLUGIN_REPO $AMBARI_PLUGIN_DIR $AMBARI_PLUGIN_BRANCH
    setup_develop $AMBARI_PLUGIN_DIR
}

# install_cdh() - Collect source and prepare
function install_cdh {
    git_clone $CDH_PLUGIN_REPO $CDH_PLUGIN_DIR $CDH_PLUGIN_BRANCH
    setup_develop $CDH_PLUGIN_DIR
}

# install_mapr() - Collect source and prepare
function install_mapr {
    git_clone $MAPR_PLUGIN_REPO $MAPR_PLUGIN_DIR $MAPR_PLUGIN_BRANCH
    setup_develop $MAPR_PLUGIN_DIR
}

# install_spark() - Collect source and prepare
function install_spark {
    git_clone $SPARK_PLUGIN_REPO $SPARK_PLUGIN_DIR $SPARK_PLUGIN_BRANCH
    setup_develop $SPARK_PLUGIN_DIR
}

# install_storm() - Collect source and prepare
function install_storm {
    git_clone $STORM_PLUGIN_REPO $STORM_PLUGIN_DIR $STORM_PLUGIN_BRANCH
    setup_develop $STORM_PLUGIN_DIR
}

# install_vanilla() - Collect source and prepare
function install_vanilla {
    git_clone $VANILLA_PLUGIN_REPO $VANILLA_PLUGIN_DIR $VANILLA_PLUGIN_BRANCH
    setup_develop $VANILLA_PLUGIN_DIR
}

# install_python_saharaclient() - Collect source and prepare
function install_python_saharaclient {
    if use_library_from_git "python-saharaclient"; then
        git_clone $SAHARACLIENT_REPO $SAHARACLIENT_DIR $SAHARACLIENT_BRANCH
        setup_develop $SAHARACLIENT_DIR
    fi
}

# start_sahara() - Start running processes, including screen
function start_sahara {
    local service_port=$SAHARA_SERVICE_PORT
    local service_protocol=$SAHARA_SERVICE_PROTOCOL
    if is_service_enabled tls-proxy; then
        service_port=$SAHARA_SERVICE_PORT_INT
        service_protocol="http"
    fi

    if [ "$SAHARA_USE_MOD_WSGI" == "True" ] ; then
        enable_apache_site sahara-api
        restart_apache_server
    else
        run_process sahara-api "$SAHARA_BIN_DIR/sahara-api \
            --config-file $SAHARA_CONF_FILE"
    fi

    run_process sahara-eng "$SAHARA_BIN_DIR/sahara-engine \
        --config-file $SAHARA_CONF_FILE"

    echo "Waiting for Sahara to start..."
    if ! wait_for_service $SERVICE_TIMEOUT \
                $service_protocol://$SAHARA_SERVICE_HOST:$service_port; then
        die $LINENO "Sahara did not start"
    fi

    # Start proxies if enabled
    if is_service_enabled tls-proxy; then
        start_tls_proxy '*' $SAHARA_SERVICE_PORT \
                            $SAHARA_SERVICE_HOST \
                            $SAHARA_SERVICE_PORT_INT &
    fi
}

# configure_tempest_for_sahara() - Tune Tempest configuration for Sahara
function configure_tempest_for_sahara {
    if is_service_enabled tempest; then
        iniset $TEMPEST_CONFIG service_available sahara True
        iniset $TEMPEST_CONFIG data-processing-feature-enabled plugins $SAHARA_INSTALLED_PLUGINS
    fi
}

# stop_sahara() - Stop running processes
function stop_sahara {
    # Kill the Sahara screen windows
    if [ "$SAHARA_USE_MOD_WSGI" == "True" ]; then
        disable_apache_site sahara-api
        restart_apache_server
    else
        stop_process sahara-all
        stop_process sahara-api
        stop_process sahara-eng
    fi
}

# is_sahara_enabled. This allows is_service_enabled sahara work
# correctly throughout devstack.
function is_sahara_enabled {
    if is_service_enabled sahara-api || \
        is_service_enabled sahara-eng; then
        return 0
    else
        return 1
    fi
}

function is_plugin_required {
    if [ "${SAHARA_INSTALLED_PLUGINS/$1}" = "$SAHARA_INSTALLED_PLUGINS" ] ; then
        return 1
    else
        return 0
    fi
}

# Dispatcher for Sahara plugin
if is_service_enabled sahara; then
    if [[ "$1" == "stack" && "$2" == "install" ]]; then
        echo_summary "Installing sahara"
        install_sahara
        if is_plugin_required ambari; then
            install_ambari
        fi
        if is_plugin_required cdh; then
            install_cdh
        fi
        if is_plugin_required mapr; then
            install_mapr
        fi
        if is_plugin_required spark; then
            install_spark
        fi
        if is_plugin_required storm; then
            install_storm
        fi
        if is_plugin_required vanilla; then
            install_vanilla
        fi
        install_python_saharaclient
        cleanup_sahara
    elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
        echo_summary "Configuring sahara"
        configure_sahara
        create_sahara_accounts
    elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
        echo_summary "Initializing sahara"
        start_sahara
    elif [[ "$1" == "stack" && "$2" == "test-config" ]]; then
        echo_summary "Configuring tempest"
        configure_tempest_for_sahara
    fi

    if [[ "$1" == "unstack" ]]; then
        stop_sahara
    fi

    if [[ "$1" == "clean" ]]; then
        cleanup_sahara
    fi
fi


# Restore xtrace
$XTRACE

# Local variables:
# mode: shell-script
# End: