|
18 | 18 | import logging
|
19 | 19 | import os
|
20 | 20 | from StringIO import StringIO
|
| 21 | +from contextlib import closing |
21 | 22 | from fabric.contrib import files
|
22 | 23 | from fabric.decorators import task, serial
|
23 | 24 | from fabric.operations import get
|
| 25 | +from fabric.operations import put |
24 | 26 | from fabric.state import env
|
25 | 27 | from fabric.utils import abort, warn
|
26 | 28 | import prestoadmin.deploy
|
27 | 29 | from prestoadmin.topology import requires_topology
|
28 | 30 | from prestoadmin.util import constants
|
| 31 | +from prestoadmin.util.filesystem import ensure_parent_directories_exist |
29 | 32 |
|
30 | 33 |
|
31 | 34 | CONFIG_PROPERTIES = "config.properties"
|
32 | 35 | LOG_PROPERTIES = "log.properties"
|
33 | 36 | JVM_CONFIG = "jvm.config"
|
34 | 37 | NODE_PROPERTIES = "node.properties"
|
35 | 38 |
|
| 39 | +ALL_CONFIG = [CONFIG_PROPERTIES, LOG_PROPERTIES, JVM_CONFIG, NODE_PROPERTIES] |
| 40 | + |
36 | 41 | _LOGGER = logging.getLogger(__name__)
|
37 | 42 |
|
38 | 43 | __all__ = ['deploy', 'show']
|
@@ -69,15 +74,51 @@ def deploy(rolename=None):
|
69 | 74 | abort("Invalid Argument. Possible values: coordinator, workers")
|
70 | 75 |
|
71 | 76 |
|
72 |
| -def configuration_show(file_name, should_warn=True): |
73 |
| - file_path = os.path.join(constants.REMOTE_CONF_DIR, file_name) |
74 |
| - if not files.exists(file_path): |
| 77 | +def gather_directory(target_directory, allow_overwrite=False): |
| 78 | + fetch_all(target_directory, allow_overwrite=allow_overwrite) |
| 79 | + |
| 80 | + |
| 81 | +def deploy_all(source_directory, should_warn=True): |
| 82 | + host_config_dir = os.path.join(source_directory, env.host) |
| 83 | + for file_name in ALL_CONFIG: |
| 84 | + local_config_file = os.path.join(host_config_dir, file_name) |
| 85 | + if not os.path.exists(local_config_file): |
| 86 | + if should_warn: |
| 87 | + warn("No configuration file found for %s at %s" |
| 88 | + % (env.host, local_config_file)) |
| 89 | + continue |
| 90 | + remote_config_file = os.path.join(constants.REMOTE_CONF_DIR, file_name) |
| 91 | + put(local_config_file, remote_config_file) |
| 92 | + |
| 93 | + |
| 94 | +def fetch_all(target_directory, allow_overwrite=False): |
| 95 | + host_config_dir = os.path.join(target_directory, env.host) |
| 96 | + for file_name in ALL_CONFIG: |
| 97 | + local_config_file = os.path.join(host_config_dir, file_name) |
| 98 | + ensure_parent_directories_exist(local_config_file) |
| 99 | + if not allow_overwrite and os.path.exists(local_config_file): |
| 100 | + abort("Refusing to overwrite %s" % (local_config_file)) |
| 101 | + configuration_fetch(file_name, local_config_file) |
| 102 | + |
| 103 | + |
| 104 | +def configuration_fetch(file_name, config_destination, should_warn=True): |
| 105 | + remote_file_path = os.path.join(constants.REMOTE_CONF_DIR, file_name) |
| 106 | + if not files.exists(remote_file_path): |
75 | 107 | if should_warn:
|
76 | 108 | warn("No configuration file found for %s at %s"
|
77 |
| - % (env.host, file_path)) |
| 109 | + % (env.host, remote_file_path)) |
| 110 | + return None |
78 | 111 | else:
|
79 |
| - file_content_buffer = StringIO() |
80 |
| - get(file_path, file_content_buffer) |
| 112 | + get(remote_file_path, config_destination) |
| 113 | + return remote_file_path |
| 114 | + |
| 115 | + |
| 116 | +def configuration_show(file_name, should_warn=True): |
| 117 | + with closing(StringIO()) as file_content_buffer: |
| 118 | + file_path = configuration_fetch(file_name, file_content_buffer, |
| 119 | + should_warn) |
| 120 | + if file_path is None: |
| 121 | + return |
81 | 122 | config_values = file_content_buffer.getvalue()
|
82 | 123 | file_content_buffer.close()
|
83 | 124 | print ("\n%s: Configuration file at %s:" % (env.host, file_path))
|
|
0 commit comments