Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ pipeline {
}

stages {
stage('Find and Run Ruff') {
steps {
script {
sh 'pip3 install --user ruff'
echo "Contents of /home/jenkins/.local/bin:"
sh 'ls -l /home/jenkins/.local/bin || echo "Directory not found"'
}
}
}

stage('Ruff Check') {
steps {
withEnv(["PATH+LOCALBIN=/home/jenkins/.local/bin:${env.PATH}"]) {
sh 'ruff --version'
sh 'mvn exec:exec@ruff-check -Pruff-check -pl :ambari -DskipTests -Dmaven.install.skip=true'
}
}
}
stage('Pre-Build Deps') {
parallel{
stage('JIRA Integration') {
Expand Down
83 changes: 58 additions & 25 deletions ambari-agent/conf/unix/agent-multiplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Host:
"""
Abstraction of the elements unique to each Ambari Agent running on this VM.
"""

def __init__(self, host_name, ping_port, home_dir):
self.host_name = host_name
self.ping_port = ping_port
Expand All @@ -46,12 +47,19 @@ class Multiplier:
-v --verbose : Increase logging

"""

CONFIG_FILE = "/etc/ambari-agent/conf/agent-multiplier.conf"

def __init__(self, args):
parser = OptionParser()
parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False,
help="Verbose logging")
parser.add_option(
"-v",
"--verbose",
dest="verbose",
action="store_true",
default=False,
help="Verbose logging",
)
(options, args) = parser.parse_args(args)
self.verbose = options.verbose

Expand All @@ -77,8 +85,10 @@ def __init__(self, args):
self.parse_configs()

if len(args) != 2:
print("Sample Usage: python agent_multiplier.py [action]\n" \
"actions: start|stop|restart|status")
print(
"Sample Usage: python agent_multiplier.py [action]\n"
"actions: start|stop|restart|status"
)
self.command = args[1]

# Validate configs
Expand Down Expand Up @@ -114,7 +124,7 @@ def parse_configs(self):
index = line.index("=") if "=" in line else None
if index is not None:
config = line[0:index].strip()
value = line[index+1:].strip()
value = line[index + 1 :].strip()
params[config] = value

# Convert some configs to ints
Expand All @@ -139,9 +149,11 @@ def validate(self):
errors.append("Number of agents on this host must be a positive integer")
if self.prefix is None or self.prefix.strip() == "":
errors.append("Prefix is a required field")

if not os.path.isfile(self.source_config_file):
errors.append(f"Ambari Agent config file does not exist at {self.source_config_file}")
errors.append(
f"Ambari Agent config file does not exist at {self.source_config_file}"
)

valid_commands = set(["start", "stop", "restart", "status"])
if self.command is None or self.command not in valid_commands:
Expand Down Expand Up @@ -169,7 +181,14 @@ def bootstrap(self):
if self.verbose:
print("Analyzing host %s with port %d" % (host_name, host.ping_port))

for dir in [host_home_dir, host_log_dir, host_config_dir, host_pid_dir, host_prefix, host_cache_dir]:
for dir in [
host_home_dir,
host_log_dir,
host_config_dir,
host_pid_dir,
host_prefix,
host_cache_dir,
]:
if not os.path.isdir(dir):
print(f"Creating dir {dir}")
os.makedirs(dir)
Expand All @@ -196,13 +215,15 @@ def bootstrap(self):
self.create_host_name_script(host_name, host_name_script)

# Overwrite the port and hostname
config_dict = {"ping_port": host.ping_port,
"hostname_script": host_name_script,
"public_hostname_script": host_name_script,
"logdir": host_log_dir,
"piddir": host_pid_dir,
"prefix": host_prefix,
"cache_dir": host_cache_dir}
config_dict = {
"ping_port": host.ping_port,
"hostname_script": host_name_script,
"public_hostname_script": host_name_script,
"logdir": host_log_dir,
"piddir": host_pid_dir,
"prefix": host_prefix,
"cache_dir": host_cache_dir,
}
self.change_config(host_config_file, config_dict)

# Change /etc/hosts file by appending each hostname.
Expand All @@ -223,8 +244,7 @@ def create_host_name_script(self, host_name, host_name_script):
:param host_name: Host name to echo
:param host_name_script: Location to save the scrip to
"""
template = "#!/bin/sh\n" \
"echo HOSTNAME"
template = "#!/bin/sh\n" "echo HOSTNAME"
with open(str(host_name_script), "w+") as f:
f.writelines(template.replace("HOSTNAME", host_name))
subprocess.call(f"chmod +x {host_name_script}", shell=True)
Expand Down Expand Up @@ -265,7 +285,9 @@ def change_config(self, config_file, config_dict):
# TODO, if can append configs, then this is not needed.
if len(configs_found) < len(config_dict.keys()):
missing_configs = set(config_dict.keys()) - configs_found
print(f"ERROR: Did not find all required configs. Missing: {', '.join(missing_configs)}")
print(
f"ERROR: Did not find all required configs. Missing: {', '.join(missing_configs)}"
)
sys.exit(-1)

if len(configs_changed) > 0:
Expand All @@ -288,12 +310,16 @@ def modify_etc_hosts_file(self):
lines = f.readlines()

# Value to search for when using Vagrant VMs
localhost_line_start = "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 "
localhost_line_start = (
"127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 "
)
new_lines = []
line_changed = False
for line in lines:
if line.startswith("127.0.0.1"):
new_change = localhost_line_start + " ".join([x.host_name for x in self.hosts]) + "\n"
new_change = (
localhost_line_start + " ".join([x.host_name for x in self.hosts]) + "\n"
)
if line != new_change:
line = new_change
line_changed = True
Expand Down Expand Up @@ -321,21 +347,27 @@ def cmd_start(self):
print(f"Starting {len(self.hosts)} host(s)")
for host in self.hosts:
cmd = f"ambari-agent start --home {host.home_dir}"
os.environ['AMBARI_AGENT_CONF_DIR'] = os.path.join(host.home_dir, "etc/ambari-agent/conf")
os.environ["AMBARI_AGENT_CONF_DIR"] = os.path.join(
host.home_dir, "etc/ambari-agent/conf"
)
subprocess.call(cmd, shell=True, env=os.environ)

def cmd_stop(self):
print(f"Stopping {len(self.hosts)} host(s)")
for host in self.hosts:
cmd = f"ambari-agent stop --home {host.home_dir}"
os.environ['AMBARI_AGENT_CONF_DIR'] = os.path.join(host.home_dir, "etc/ambari-agent/conf")
os.environ["AMBARI_AGENT_CONF_DIR"] = os.path.join(
host.home_dir, "etc/ambari-agent/conf"
)
subprocess.call(cmd, shell=True, env=os.environ)

def cmd_restart(self):
print(f"Restarting {len(self.hosts)} host(s)")
for host in self.hosts:
cmd = f"ambari-agent restart --home {host.home_dir}"
os.environ['AMBARI_AGENT_CONF_DIR'] = os.path.join(host.home_dir, "etc/ambari-agent/conf")
os.environ["AMBARI_AGENT_CONF_DIR"] = os.path.join(
host.home_dir, "etc/ambari-agent/conf"
)
subprocess.call(cmd, shell=True, env=os.environ)

def cmd_status(self):
Expand Down Expand Up @@ -390,14 +422,15 @@ def aggregate_status(self):

@classmethod
def check_pid(cls, pid):
""" Check For the existence of a unix pid. """
"""Check For the existence of a unix pid."""
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True


if __name__ == "__main__":
m = Multiplier(sys.argv)
m.run()
m.run()
30 changes: 15 additions & 15 deletions ambari-agent/conf/unix/upgrade_agent_configs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env ambari-python-wrap
'''
"""
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
Expand All @@ -15,26 +15,23 @@
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.
'''
"""

import os
import configparser

PROPERTIES_TO_REWRITE = [
('heartbeat', 'dirs'),
('heartbeat', 'state_interval')
]
SECTIONS_TO_REMOVE = [
'stack', 'puppet', 'command', 'python'
]
PROPERTIES_TO_REWRITE = [("heartbeat", "dirs"), ("heartbeat", "state_interval")]
SECTIONS_TO_REMOVE = ["stack", "puppet", "command", "python"]

CONFIG_FILE_BACKUP = '/etc/ambari-agent/conf/ambari-agent.ini.old'
CONFIG_FILE = '/etc/ambari-agent/conf/ambari-agent.ini'
CONFIG_FILE_BACKUP = "/etc/ambari-agent/conf/ambari-agent.ini.old"
CONFIG_FILE = "/etc/ambari-agent/conf/ambari-agent.ini"

if os.path.isfile(CONFIG_FILE_BACKUP):
if os.path.isfile(CONFIG_FILE):
print(f"Upgrading configs in {CONFIG_FILE}")
print(f"Values will be updated from {CONFIG_FILE_BACKUP} except the following list: {PROPERTIES_TO_REWRITE}, {SECTIONS_TO_REMOVE}")
print(
f"Values will be updated from {CONFIG_FILE_BACKUP} except the following list: {PROPERTIES_TO_REWRITE}, {SECTIONS_TO_REMOVE}"
)

agent_config_backup = configparser.ConfigParser()
agent_config_backup.read(CONFIG_FILE_BACKUP)
Expand All @@ -43,15 +40,18 @@
agent_config.read(CONFIG_FILE)

for section in agent_config_backup.sections():
for (property_name, property_val) in agent_config_backup.items(section):
if section not in SECTIONS_TO_REMOVE and (section, property_name) not in PROPERTIES_TO_REWRITE:
for property_name, property_val in agent_config_backup.items(section):
if (
section not in SECTIONS_TO_REMOVE
and (section, property_name) not in PROPERTIES_TO_REWRITE
):
try:
agent_config.set(section, property_name, property_val)
except configparser.NoSectionError:
agent_config.add_section(section)
agent_config.set(section, property_name, property_val)

with (open(CONFIG_FILE, "w")) as new_agent_config:
with open(CONFIG_FILE, "w") as new_agent_config:
agent_config.write(new_agent_config)
else:
print(f"Values are not updated, configs {CONFIG_FILE} is not found")
Expand Down
Loading