dda-devops-build/src/main/python/ddadevops/dda_tenant_mixin.py

75 lines
3 KiB
Python
Raw Normal View History

2020-03-03 15:34:12 +00:00
from string import Template
2020-03-04 08:27:46 +00:00
from subprocess import run
2020-03-03 15:34:12 +00:00
from .python_util import *
from .devops_build import DevopsBuild
def add_dda_tenant_mixin_config(config, tenant, application, domain_file_name):
config.update({'DdaTenantMixin':
2020-03-03 16:33:00 +00:00
{'tenant': tenant,
'application': application,
'domain_file_name': domain_file_name,
'target_edn_name': 'target.edn',
'jar_file': 'target/meissa-tenant-server.jar',
'target_template':
"""
2020-03-03 15:34:12 +00:00
{:existing [{:node-name "$node_name"
:node-ip "$ipv4"}]
:provisioning-user {:login "root"}}
""", }})
2020-03-03 16:33:00 +00:00
return config
2020-03-03 15:34:12 +00:00
class DdaTenantMixin(DevopsBuild):
2020-03-03 15:34:12 +00:00
def __init__(self, project, config):
2020-03-03 16:36:56 +00:00
super().__init__(project, config)
dda_pallet_mixin_config = config['DdaTenantMixin']
2020-03-03 15:34:12 +00:00
self.tenant = dda_pallet_mixin_config['tenant']
self.application = dda_pallet_mixin_config['application']
self.domain_file_name = dda_pallet_mixin_config['domain_file_name']
self.target_edn_name = dda_pallet_mixin_config['target_edn_name']
self.jar_file = dda_pallet_mixin_config['jar_file']
self.target_template = Template(
dda_pallet_mixin_config['target_template'])
2020-03-03 17:30:17 +00:00
def initialize_build_dir(self):
super().initialize_build_dir()
run('cp *.edn ' + self.build_path(), shell=True)
2020-03-03 15:34:12 +00:00
def dda_write_target(self, node_name, ipv4):
2020-04-17 17:08:18 +00:00
with open(self.build_path() + '/' + self.target_edn_name, "w") as output_file:
2020-03-03 15:34:12 +00:00
output_file.write(
self.target_template.substitute({'ipv4': ipv4, 'node_name': node_name}))
2020-03-10 07:28:06 +00:00
def dda_write_domain(self, substitues):
2020-04-17 17:08:18 +00:00
with open(self.build_path() + '/' + self.domain_file_name, "r") as input_file:
2020-03-10 07:28:06 +00:00
domain_input=input_file.read()
domain_template=Template(domain_input)
2020-04-17 17:08:18 +00:00
with open(self.build_path() + '/out_' + self.domain_file_name, "w") as output_file:
2020-03-03 15:34:12 +00:00
output_file.write(domain_template.substitute(substitues))
2020-03-10 07:28:06 +00:00
def dda_uberjar(self, configure_switch = None):
2020-03-03 15:34:12 +00:00
if configure_switch:
2020-04-17 17:08:18 +00:00
cmd=['java', '-jar', self.project_root_path + '/' + self.jar_file,
'--targets', self.build_path() + '/' + self.target_edn_name,
2020-03-03 15:34:12 +00:00
'--tenant', self.tenant, '--application', self.application,
'--configure',
2020-04-17 17:08:18 +00:00
self.build_path() + '/out_' + self.domain_file_name]
2020-03-03 15:34:12 +00:00
else:
2020-04-17 17:08:18 +00:00
cmd = ['java', '-jar', self.project_root_path + '/' + self.jar_file,
'--targets', self.build_path() + '/' + self.target_edn_name,
2020-03-03 15:34:12 +00:00
'--tenant', self.tenant, '--application', self.application,
2020-04-17 17:08:18 +00:00
self.build_path() + '/out_' + self.domain_file_name]
2020-03-03 15:34:12 +00:00
prn_cmd = list(cmd)
print(" ".join(prn_cmd))
output = execute(cmd)
print(output)
return output
def dda_install(self):
return self.dda_uberjar()
def dda_configure(self):
return self.dda_uberjar(True)