From 9e49e4d94438cb3932a9a344fd9cc971c1c0e448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Tr=C4=99bski?= Date: Tue, 10 Jan 2017 14:02:06 +0100 Subject: [PATCH] Add template for monasca-api Depends-On: Id07dcc249965d97644da9396b6d288255ffaab43 Change-Id: Idcc181bbb19a68c622eca51dc9822bde9a91f6a9 --- openstack/monasca-api/api-config.conf | 131 ++++++++++++++++ openstack/monasca-api/api-config.ini | 21 +++ openstack/monasca-api/api-logging.conf | 33 ++++ openstack/monasca-api/api-wsgi.conf | 22 +++ openstack/monasca-api/api-wsgi.py | 3 + openstack/monasca-api/monasca-api.spec.j2 | 175 ++++++++++++++++++++++ 6 files changed, 385 insertions(+) create mode 100644 openstack/monasca-api/api-config.conf create mode 100644 openstack/monasca-api/api-config.ini create mode 100644 openstack/monasca-api/api-logging.conf create mode 100644 openstack/monasca-api/api-wsgi.conf create mode 100644 openstack/monasca-api/api-wsgi.py create mode 100644 openstack/monasca-api/monasca-api.spec.j2 diff --git a/openstack/monasca-api/api-config.conf b/openstack/monasca-api/api-config.conf new file mode 100644 index 000000000..d906536a7 --- /dev/null +++ b/openstack/monasca-api/api-config.conf @@ -0,0 +1,131 @@ +[DEFAULT] +log_config_append=/etc/monasca/api-logging.conf + +# Identifies the region that the Monasca API is running in. +region = + +# Dispatchers to be loaded to serve restful APIs +[dispatcher] +versions = monasca_api.v2.reference.versions:Versions +version_2_0 = monasca_api.v2.reference.version_2_0:Version2 +metrics = monasca_api.v2.reference.metrics:Metrics +metrics_measurements = monasca_api.v2.reference.metrics:MetricsMeasurements +metrics_statistics = monasca_api.v2.reference.metrics:MetricsStatistics +metrics_names = monasca_api.v2.reference.metrics:MetricsNames +alarm_definitions = monasca_api.v2.reference.alarm_definitions:AlarmDefinitions +alarms = monasca_api.v2.reference.alarms:Alarms +alarms_count = monasca_api.v2.reference.alarms:AlarmsCount +alarms_state_history = monasca_api.v2.reference.alarms:AlarmsStateHistory +notification_methods = monasca_api.v2.reference.notifications:Notifications +dimension_values = monasca_api.v2.reference.metrics:DimensionValues +dimension_names = monasca_api.v2.reference.metrics:DimensionNames +notification_method_types = monasca_api.v2.reference.notificationstype:NotificationsType + +[security] +# The roles that are allowed full access to the API. +default_authorized_roles = user, domainuser, domainadmin, monasca-user + +# The roles that are allowed to only POST metrics to the API. This role would be used by the Monasca Agent. +agent_authorized_roles = monasca-agent + +# The roles that are allowed to only GET metrics from the API. +read_only_authorized_roles = monasca-read-only-user + +# The roles that are allowed to access the API on behalf of another tenant. +# For example, a service can POST metrics to another tenant if they are a member of the "delegate" role. +delegate_authorized_roles = admin + +[messaging] +# The message queue driver to use +driver = monasca_api.common.messaging.kafka_publisher:KafkaPublisher + +[repositories] +# The driver to use for the metrics repository +# Switches depending on backend database in use. Influxdb or Cassandra. +metrics_driver = monasca_api.common.repositories.influxdb.metrics_repository:MetricsRepository +#metrics_driver = monasca_api.common.repositories.cassandra.metrics_repository:MetricsRepository + +# The driver to use for the alarm definitions repository +alarm_definitions_driver = monasca_api.common.repositories.sqla.alarm_definitions_repository:AlarmDefinitionsRepository + +# The driver to use for the alarms repository +alarms_driver = monasca_api.common.repositories.sqla.alarms_repository:AlarmsRepository + +# The driver to use for the notifications repository +notifications_driver = monasca_api.common.repositories.sqla.notifications_repository:NotificationsRepository + +# The driver to use for the notification method type repository +notification_method_type_driver = monasca_api.common.repositories.sqla.notification_method_type_repository:NotificationMethodTypeRepository + + +[dispatcher] +driver = v2_reference + +[kafka] +# The endpoint to the kafka server +uri = + +# The topic that metrics will be published too +metrics_topic = metrics + +# consumer group name +group = api + +# how many times to try when error occurs +max_retry = 1 + +# wait time between tries when kafka goes down +wait_time = 1 + +# use synchronous or asynchronous connection to kafka +async = False + +# send messages in bulk or send messages one by one. +compact = False + +# How many partitions this connection should listen messages on, this +# parameter is for reading from kafka. If listens on multiple partitions, +# For example, if the client should listen on partitions 1 and 3, then the +# configuration should look like the following: +# partitions = 1 +# partitions = 3 +# default to listen on partition 0. +partitions = 0 + +[influxdb] +# Only needed if Influxdb database is used for backend. +# The IP address of the InfluxDB service. +ip_address = + +# The port number that the InfluxDB service is listening on. +port = 8086 + +# The username to authenticate with. +user = mon_api + +# The password to authenticate with. +password = password + +# The name of the InfluxDB database to use. +database_name = mon + +[cassandra] +# Only needed if Cassandra database is used for backend. +# Comma separated list of Cassandra node IP addresses. No spaces. +cluster_ip_addresses: +keyspace: monasca + +# Below is configuration for database. +[database] +url = "mysql+pymysql://monapi:password@127.0.0.1/mon" + +[keystone_authtoken] +identity_uri = http://127.0.0.1:35357 +auth_uri = http://127.0.0.1:5000 +admin_password = admin +admin_user = admin +admin_tenant_name = admin +cafile = +certfile = +keyfile = +insecure = false diff --git a/openstack/monasca-api/api-config.ini b/openstack/monasca-api/api-config.ini new file mode 100644 index 000000000..a0fc2af05 --- /dev/null +++ b/openstack/monasca-api/api-config.ini @@ -0,0 +1,21 @@ +[DEFAULT] +name = monasca_api + +[pipeline:main] +pipeline = request_id auth api + +[app:api] +paste.app_factory = monasca_api.api.server:launch + +[filter:auth] +paste.filter_factory = keystonemiddleware.auth_token:filter_factory + +[filter:request_id] +paste.filter_factory = oslo_middleware.request_id:RequestId.factory + +[server:main] +use = egg:gunicorn#main +host = 127.0.0.1 +port = 8082 +workers = 1 +proc_name = monasca_api diff --git a/openstack/monasca-api/api-logging.conf b/openstack/monasca-api/api-logging.conf new file mode 100644 index 000000000..b7f420f85 --- /dev/null +++ b/openstack/monasca-api/api-logging.conf @@ -0,0 +1,33 @@ +[loggers] +keys = root, sqlalchemy, kafka + +[handlers] +keys = console + +[formatters] +keys = context + +[logger_root] +level = INFO +handlers = console + +[logger_sqlalchemy] +qualname = sqlalchemy.engine +level = WARN +handlers = console +propagate=0 + +[logger_kafka] +qualname = kafka +level = WARN +handlers = console +propagate = 0 + +[handler_console] +class = logging.StreamHandler +args = (sys.stderr,) +level = WARN +formatter = context + +[formatter_context] +class = oslo_log.formatters.ContextFormatter diff --git a/openstack/monasca-api/api-wsgi.conf b/openstack/monasca-api/api-wsgi.conf new file mode 100644 index 000000000..30efe1a2f --- /dev/null +++ b/openstack/monasca-api/api-wsgi.conf @@ -0,0 +1,22 @@ +Listen 8070 + + + WSGIDaemonProcess monasca-api processes=2 threads=1 socket-timeout=120 user=monasca-api group=monasca display-name=%{GROUP} + WSGIProcessGroup monasca-api + WSGIApplicationGroup %{GLOBAL} + WSGIScriptAlias / /usr/bin/monasca-api-wsgi.py + + WSGIPassAuthorization On + + LogLevel info + ErrorLog /var/log/__APACHE_NAME__/monasca-api.log + CustomLog /var/log/__APACHE_NAME__/monasca-api_access.log combined + + SetEnv no-gzip 1 + AddDefaultCharset utf-8 + + + Require all granted + + + diff --git a/openstack/monasca-api/api-wsgi.py b/openstack/monasca-api/api-wsgi.py new file mode 100644 index 000000000..2fe95d060 --- /dev/null +++ b/openstack/monasca-api/api-wsgi.py @@ -0,0 +1,3 @@ +from monasca_api.api import server + +application = server.get_wsgi_app(config_base_path='/etc/monasca') diff --git a/openstack/monasca-api/monasca-api.spec.j2 b/openstack/monasca-api/monasca-api.spec.j2 new file mode 100644 index 000000000..ebda9e74c --- /dev/null +++ b/openstack/monasca-api/monasca-api.spec.j2 @@ -0,0 +1,175 @@ +%define component monasca-api + +# apache settings +%if 0%{?suse_version} +%define apache_name apache2 +%define apache_site_dir %{_sysconfdir}/%{apache_name}/vhosts.d/ +%else +%define apache_name httpd +%define apache_site_dir %{_sysconfdir}/%{apache_name}/conf.d/ +%endif + +Name: {{ py2name('monasca-api') }} +Version: 1.6.1 +Release: 0 +License: {{ license('Apache-2.0') }} +Summary: Monasca REST API +Group: Development/Languages/Python +Url: https://wiki.openstack.org/wiki/Monasca + +Source0: https://pypi.io/packages/source/m/%{component}/%{component}-%{version}.tar.gz +Source1: api-config.conf +Source2: api-logging.conf +Source3: api-config.ini +Source4: api-wsgi.conf +Source5: api-wsgi.py + +BuildRequires: openstack-macros +BuildRequires: {{ py2pkg('cassandra-driver') }} +BuildRequires: {{ py2pkg('coverage') }} +BuildRequires: {{ py2pkg('eventlet') }} +BuildRequires: {{ py2pkg('falcon') }} +BuildRequires: {{ py2pkg('fixtures') }} +BuildRequires: {{ py2pkg('funcsigs') }} +BuildRequires: {{ py2pkg('httplib2') }} +BuildRequires: {{ py2pkg('influxdb') }} +BuildRequires: {{ py2pkg('keystonemiddleware') }} +BuildRequires: {{ py2pkg('mock') }} +BuildRequires: {{ py2pkg('monasca-common') }} +BuildRequires: {{ py2pkg('mox') }} +BuildRequires: {{ py2pkg('nose') }} +BuildRequires: {{ py2pkg('oslo.config') }} +BuildRequires: {{ py2pkg('oslo.context') }} +BuildRequires: {{ py2pkg('oslo.log') }} +BuildRequires: {{ py2pkg('oslo.middleware') }} +BuildRequires: {{ py2pkg('oslo.serialization') }} +BuildRequires: {{ py2pkg('oslo.utils') }} +BuildRequires: {{ py2pkg('oslotest') }} +BuildRequires: {{ py2pkg('PasteDeploy') }} +BuildRequires: {{ py2pkg('pbr') }} +BuildRequires: {{ py2pkg('pyparsing') }} +BuildRequires: {{ py2pkg('python-keystoneclient') }} +BuildRequires: {{ py2pkg('python-subunit') }} +BuildRequires: {{ py2pkg('simplejson') }} +BuildRequires: {{ py2pkg('six') }} +BuildRequires: {{ py2pkg('SQLAlchemy') }} +BuildRequires: {{ py2pkg('tempest-lib') }} +BuildRequires: {{ py2pkg('testrepository') }} +BuildRequires: {{ py2pkg('testscenarios') }} +BuildRequires: {{ py2pkg('testtools') }} +BuildRequires: {{ py2pkg('voluptuous') }} +BuildRequires: fdupes +%if 0%{?suse_version} +BuildRequires: apache2-mod_wsgi +Requires: apache2-mod_wsgi +%else +BuildRequires: mod_wsgi +Requires: mod_wsgi +%endif +Requires: python-%{component} = %{version}-%{release} +BuildArch: noarch + +%description +The Monasca API provides a RESTful JSON interface for interacting with +and managing monitoring related resources. + +%package -n python-%{component} +Summary: Monasca REST API +Group: Development/Languages/Python + +Requires: {{ py2pkg('eventlet') }} +Requires: {{ py2pkg('falcon') }} +Requires: {{ py2pkg('keystonemiddleware') }} +Requires: {{ py2pkg('monasca-common') }} +Requires: {{ py2pkg('oslo.config') }} +Requires: {{ py2pkg('oslo.context') }} +Requires: {{ py2pkg('oslo.log') }} +Requires: {{ py2pkg('oslo.middleware') }} +Requires: {{ py2pkg('oslo.serialization') }} +Requires: {{ py2pkg('oslo.utils') }} +Requires: {{ py2pkg('PasteDeploy') }} +Requires: {{ py2pkg('pbr') }} +Requires: {{ py2pkg('pyparsing') }} +Requires: {{ py2pkg('python-keystoneclient') }} +Requires: {{ py2pkg('simplejson') }} +Requires: {{ py2pkg('six') }} +Requires: {{ py2pkg('SQLAlchemy') }} +Requires: {{ py2pkg('voluptuous') }} +BuildArch: noarch + +%description -n python-%{component} +The Monasca API provides a RESTful JSON interface for interacting with +and managing monitoring related resources. + +%prep +%autosetup -n %{component}-%{version} +%py_req_cleanup + +%build +%py2_build + +%install +%py2_install + +# create all necessary directories +%{__install} -d -m 755 %{buildroot}%{_sysconfdir}/monasca +%{__install} -d -m 755 %{buildroot}%{_var}/log/%{component} +%{__install} -d -m 755 %{buildroot}%{apache_site_dir} + +# copy embedded configuration files + +## copy configs +%{__install} -D -m 640 %{SOURCE1} %{buildroot}%{_sysconfdir}/monasca/api-config.conf +%{__install} -D -m 640 %{SOURCE2} %{buildroot}%{_sysconfdir}/monasca/api-logging.conf +%{__install} -D -m 640 %{SOURCE3} %{buildroot}%{_sysconfdir}/monasca/api-config.ini + +## install apache configuration +%{__install} -p -D -m 640 %{SOURCE4} %{buildroot}%{apache_site_dir}/%{component}.conf.sample +sed -e " + s|__APACHE_NAME__|%{apache_name}|g; +" -i %{buildroot}%{apache_site_dir}/%{component}.conf.sample + +## install WSGIScriptAlias +%{__install} -D -m 755 %{SOURCE5} %{buildroot}%{_bindir}/monasca-api-wsgi.py + +# remove duplicates +%fdupes $RPM_BUILD_ROOT%{python2_sitelib}/monasca_api +%fdupes $RPM_BUILD_ROOT%{python2_sitelib}/monasca_tempest_tests + +%check +find . -type f -name *.pyc -delete +OS_TEST_PATH=./monasca_api/tests PYTHONPATH=. ostestr + +%pre +%openstack_pre_user_group_create monasca-api monasca /sbin/nologin + +%postun +if [ $1 -eq 0 ] ; then + getent passwd monasca-api > /dev/null + if [ "$?" == "0" ] ; then + userdel monasca-api + fi +fi + +%files +%defattr(-, root, root) +%{_bindir}/monasca-api +%{_bindir}/monasca-api-wsgi.py + +%dir %attr(-, root, monasca) %{_sysconfdir}/monasca +%dir %attr(-, root, monasca) %{_var}/log/%{component} + +%config(noreplace) %attr(0640, root, monasca) %{_sysconfdir}/monasca/api-config.conf +%config(noreplace) %attr(0640, root, monasca) %{_sysconfdir}/monasca/api-logging.conf +%config(noreplace) %attr(0640, root, monasca) %{_sysconfdir}/monasca/api-config.ini +%config(noreplace) %attr(0640, root, monasca) %{apache_site_dir}/%{component}.conf.sample + +%files -n python-%{component} +%defattr(-, root, root,-) +%license LICENSE +%doc README.md ChangeLog +%{python2_sitelib}/monasca_api +%{python2_sitelib}/monasca_tempest_tests +%{python2_sitelib}/*.egg-info + +%changelog