File openstack-monasca-transform.spec of Package openstack-monasca-transform

#
# spec file for package openstack-monasca-transform
#
# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%global sname monasca-transform
%define username            monasca-transform
%define groupname           monasca
Name:           openstack-monasca-transform
Version:        0.18.1~dev6
Release:        0
Summary:        A transformation and aggregation engine for Monasca
License:        Apache-2.0
Group:          Development/Languages/Python
URL:            https://wiki.openstack.org/wiki/Monasca/Transform
Source0:        monasca-transform-master.tar.gz
Source1:        openstack-monasca-transform.service
BuildRequires:  crudini
BuildRequires:  fdupes
BuildRequires:  openstack-macros
BuildRequires:  python3-PyMySQL
BuildRequires:  python3-SQLAlchemy
BuildRequires:  python3-kazoo
BuildRequires:  python3-mock
BuildRequires:  python3-monasca-common
BuildRequires:  python3-nose
BuildRequires:  python3-oslo.config
BuildRequires:  python3-oslo.log
BuildRequires:  python3-oslo.service
BuildRequires:  python3-oslotest
BuildRequires:  python3-pbr
BuildRequires:  python3-psutil
BuildRequires:  python3-setuptools
BuildRequires:  python3-six
BuildRequires:  python3-stestr
BuildRequires:  python3-stevedore
BuildRequires:  python3-tooz
BuildRequires:  zip
#BuildRequires:  spark == 1.6.3
Requires:       python3-%{sname} = %{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
Requires(pre):  pwdutils
%{?systemd_requires}
%else
BuildRequires:  systemd
Requires(post): systemd
Requires(postun):   systemd
Requires(preun):    systemd
%endif

%description
A transformation and aggregation engine for Monasca.  Collects, groups and
aggregates existing individual Monasca metrics according to business
requirements and publishes new transformed (derived) metrics to the Monasca
Kafka queue.
Requires an installation of Apache Spark 1.6.3, either on
this server or another, and configured in %{_sysconfdir}/monasca-transform.conf
as spark_master_list.

%package -n python3-%{sname}
Summary:        Python core module for monasca-transform
Group:          Development/Languages/Python
Requires:       python3-PyMySQL
Requires:       python3-SQLAlchemy
Requires:       python3-kazoo
Requires:       python3-monasca-common
Requires:       python3-oslo.config
Requires:       python3-oslo.log
Requires:       python3-six
Requires:       python3-stevedore
Requires:       python3-tooz
#Requires:       spark == 1.6.3

%description -n python3-%{sname}
A transformation and aggregation engine for Monasca.  Collects, groups and
aggregates existing individual Monasca metrics according to business
requirements and publishes new transformed (derived) metrics to the Monasca
Kafka queue.
Requires an installation of Apache Spark 1.6.3, either on this server or
another, and configured in %{_sysconfdir}/monasca-transform.conf as spark_master_list.

%prep
# Unfortunately again, .tgz has _ in directory name so can't use sname
%autosetup -n monasca_transform-0.18.1.dev6
%py_req_cleanup
# Add entry point for service startup by appending console_scripts after [entry_points].
sed -i '/\[entry_points\]/aconsole_scripts =\n    monasca-transform = monasca_transform.service.transform_service:main_service\n' setup.cfg

%build
export LANG=en_US.UTF-8
%{py3_build}

# copy, compile and create a zip file to be fed to spark
python3 -m compileall monasca_transform
zip -r %{sname}.zip monasca_transform -i '*.pyc'

%install
export LANG=en_US.UTF-8
%{py3_install}

install -d -m 755 %{buildroot}%{_sysconfdir}/monasca
install -d -m 750 %{buildroot}%{_sysconfdir}/monasca_transform
install -d -m 750 %{buildroot}%{_sysconfdir}/monasca_transform/monasca_transform.conf.d
install -D -m 640 etc/monasca-transform.conf %{buildroot}%{_sysconfdir}/monasca-transform.conf

install -d -m 750 %{buildroot}%{_var}/log/monasca
install -d -m 750 %{buildroot}%{_var}/log/monasca/transform

# systemd unit file
install -p -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
%if 0%{?suse_version}
mkdir -p %{buildroot}%{_sbindir}
ln -sr %{buildroot}%{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
%endif

install -d -m 750 %{buildroot}%{_datadir}/%{sname}
install -D -m 644 %{sname}.zip %{buildroot}%{_datadir}/%{sname}/%{sname}.zip

# reconfigure for rpm install
%define mon_trans_conf %{buildroot}%{_sysconfdir}/monasca-transform.conf
crudini --set %{mon_trans_conf} service service_log_path %{_var}/log/monasca/transform/
crudini --del %{mon_trans_conf} service setup_file
crudini --set %{mon_trans_conf} service spark_driver %{python3_sitelib}/monasca_transform/driver/mon_metrics_kafka.py
# disable spark event logging - mon-trans only keeps 10 jobs so history not needed
crudini --set %{mon_trans_conf} service spark_event_logging_enabled false
# NOTE: Special handling for spark_jars_list will need to be done after install
crudini --set %{mon_trans_conf} service spark_home $"$spark_home"
crudini --set %{mon_trans_conf} service work_dir %{_rundir}/monasca/monasca-transform
crudini --set %{mon_trans_conf} service spark_master_list spark://localhost:7078
# for the .zip file created above
crudini --set %{mon_trans_conf} service spark_python_files %{_datadir}/%{sname}/%{sname}.zip

%fdupes %{buildroot}%{python3_sitelib}

%check
# automated tests need to be restricted, as functional tests require running Spark
find . -type f -name *.pyc -delete
python3 -m stestr.cli run

%pre
# create user and groups
%openstack_pre_user_group_create %{username} %{groupname} /sbin/nologin

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun %{name}.service

%files
%license LICENSE
%doc README.rst ChangeLog
%dir %attr(-, root, %{groupname}) %{_sysconfdir}/monasca
%config(noreplace) %attr(0640, root, %{groupname}) %{_sysconfdir}/monasca-transform.conf
%{_unitdir}/%{name}.service
%if 0%{?suse_version}
%{_sbindir}/rc%{name}
%endif
%{_bindir}/monasca-transform
%dir %attr(0750, root, %{groupname}) %{_var}/log/monasca
%dir %attr(0750, %{username}, %{groupname}) %{_var}/log/monasca/transform

%files -n python3-monasca-transform
%license LICENSE
%{python3_sitelib}/monasca_transform
%{python3_sitelib}/*.egg-info
%dir %attr(0750, %{username}, %{groupname}) %{_datadir}/%{sname}
%{_datadir}/%{sname}/%{sname}.zip

%changelog