From 2f31d2cedcdf01cf9483918468e0a1cee4e1af97 Mon Sep 17 00:00:00 2001 From: Roland Hochmuth Date: Thu, 25 Jun 2015 23:40:50 -0600 Subject: [PATCH] Cleanup and deleted unused message formats --- etc/events_api.conf | 3 -- .../message_formats/cadf/__init__.py | 0 .../messaging/message_formats/cadf/events.py | 17 ---------- .../messaging/message_formats/cadf/metrics.py | 17 ---------- .../message_formats/{reference => }/events.py | 0 .../events_transform_factory.py | 29 ---------------- .../message_formats/identity/__init__.py | 0 .../message_formats/identity/events.py | 17 ---------- .../message_formats/identity/metrics.py | 17 ---------- .../metrics_transform_factory.py | 29 ---------------- .../message_formats/reference/__init__.py | 0 .../message_formats/reference/metrics.py | 33 ------------------- .../{reference => }/transforms.py | 0 monasca_events_api/v2/events.py | 22 +++++-------- monasca_events_api/v2/transforms.py | 11 ++++--- 15 files changed, 15 insertions(+), 180 deletions(-) delete mode 100644 monasca_events_api/common/messaging/message_formats/cadf/__init__.py delete mode 100644 monasca_events_api/common/messaging/message_formats/cadf/events.py delete mode 100644 monasca_events_api/common/messaging/message_formats/cadf/metrics.py rename monasca_events_api/common/messaging/message_formats/{reference => }/events.py (100%) delete mode 100644 monasca_events_api/common/messaging/message_formats/events_transform_factory.py delete mode 100644 monasca_events_api/common/messaging/message_formats/identity/__init__.py delete mode 100644 monasca_events_api/common/messaging/message_formats/identity/events.py delete mode 100644 monasca_events_api/common/messaging/message_formats/identity/metrics.py delete mode 100644 monasca_events_api/common/messaging/message_formats/metrics_transform_factory.py delete mode 100644 monasca_events_api/common/messaging/message_formats/reference/__init__.py delete mode 100644 monasca_events_api/common/messaging/message_formats/reference/metrics.py rename monasca_events_api/common/messaging/message_formats/{reference => }/transforms.py (100%) diff --git a/etc/events_api.conf b/etc/events_api.conf index f056423..66552fc 100755 --- a/etc/events_api.conf +++ b/etc/events_api.conf @@ -29,9 +29,6 @@ delegate_authorized_roles = admin # The message queue driver to use driver = monasca_events_api.common.messaging.kafka_publisher:KafkaPublisher -# The type of events message format to publish to the message queue. -events_message_format = reference - [repositories] # The driver to use for the stream definitions repository streams = monasca_events_api.common.repositories.mysql.streams_repository:StreamsRepository diff --git a/monasca_events_api/common/messaging/message_formats/cadf/__init__.py b/monasca_events_api/common/messaging/message_formats/cadf/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monasca_events_api/common/messaging/message_formats/cadf/events.py b/monasca_events_api/common/messaging/message_formats/cadf/events.py deleted file mode 100644 index 4b625d6..0000000 --- a/monasca_events_api/common/messaging/message_formats/cadf/events.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2014 Hewlett-Packard -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, 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. - - -def transform(events, tenant_id, region): - raise NotImplemented() diff --git a/monasca_events_api/common/messaging/message_formats/cadf/metrics.py b/monasca_events_api/common/messaging/message_formats/cadf/metrics.py deleted file mode 100644 index 2b33518..0000000 --- a/monasca_events_api/common/messaging/message_formats/cadf/metrics.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2014 Hewlett-Packard -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, 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. - - -def transform(metrics, tenant_id, region): - raise NotImplemented() diff --git a/monasca_events_api/common/messaging/message_formats/reference/events.py b/monasca_events_api/common/messaging/message_formats/events.py similarity index 100% rename from monasca_events_api/common/messaging/message_formats/reference/events.py rename to monasca_events_api/common/messaging/message_formats/events.py diff --git a/monasca_events_api/common/messaging/message_formats/events_transform_factory.py b/monasca_events_api/common/messaging/message_formats/events_transform_factory.py deleted file mode 100644 index d1f6c19..0000000 --- a/monasca_events_api/common/messaging/message_formats/events_transform_factory.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2014 Hewlett-Packard -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, 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. - -from oslo_config import cfg - -import monasca_events_api.common.messaging.message_formats.cadf.events as cadf_events -import monasca_events_api.common.messaging.message_formats.identity.events as ident_events -import monasca_events_api.common.messaging.message_formats.reference.events as ref_events - - -def create_events_transform(): - message_format = cfg.CONF.messaging.events_message_format - if message_format == 'reference': - return ref_events.transform - elif message_format == 'cadf': - return cadf_events.transform - else: - return ident_events.transform diff --git a/monasca_events_api/common/messaging/message_formats/identity/__init__.py b/monasca_events_api/common/messaging/message_formats/identity/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monasca_events_api/common/messaging/message_formats/identity/events.py b/monasca_events_api/common/messaging/message_formats/identity/events.py deleted file mode 100644 index 1e51576..0000000 --- a/monasca_events_api/common/messaging/message_formats/identity/events.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2014 Hewlett-Packard -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, 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. - - -def transform(events, tenant_id, region): - return events diff --git a/monasca_events_api/common/messaging/message_formats/identity/metrics.py b/monasca_events_api/common/messaging/message_formats/identity/metrics.py deleted file mode 100644 index f0f71ea..0000000 --- a/monasca_events_api/common/messaging/message_formats/identity/metrics.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2014 Hewlett-Packard -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, 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. - - -def transform(metrics, tenant_id, region): - return metrics diff --git a/monasca_events_api/common/messaging/message_formats/metrics_transform_factory.py b/monasca_events_api/common/messaging/message_formats/metrics_transform_factory.py deleted file mode 100644 index eb2c915..0000000 --- a/monasca_events_api/common/messaging/message_formats/metrics_transform_factory.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2014 Hewlett-Packard -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, 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. - -from oslo_config import cfg - -import monasca_events_api.common.messaging.message_formats.cadf.metrics as cadf_metrics -import monasca_events_api.common.messaging.message_formats.identity.metrics as id_metrics -import monasca_events_api.common.messaging.message_formats.reference.metrics as r_metrics - - -def create_metrics_transform(): - metrics_message_format = cfg.CONF.messaging.metrics_message_format - if metrics_message_format == 'reference': - return r_metrics.transform - elif metrics_message_format == 'cadf': - return cadf_metrics.transform - else: - return id_metrics.transform diff --git a/monasca_events_api/common/messaging/message_formats/reference/__init__.py b/monasca_events_api/common/messaging/message_formats/reference/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/monasca_events_api/common/messaging/message_formats/reference/metrics.py b/monasca_events_api/common/messaging/message_formats/reference/metrics.py deleted file mode 100644 index e3ee110..0000000 --- a/monasca_events_api/common/messaging/message_formats/reference/metrics.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2014 Hewlett-Packard -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, 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 copy - -from oslo_utils import timeutils - - -def transform(metrics, tenant_id, region): - transformed_metric = {'metric': {}, - 'meta': {'tenantId': tenant_id, 'region': region}, - 'creation_time': timeutils.utcnow_ts()} - - if isinstance(metrics, list): - transformed_metrics = [] - for metric in metrics: - transformed_metric['metric'] = metric - transformed_metrics.append(copy.deepcopy(transformed_metric)) - return transformed_metrics - else: - transformed_metric['metric'] = metrics - return transformed_metric diff --git a/monasca_events_api/common/messaging/message_formats/reference/transforms.py b/monasca_events_api/common/messaging/message_formats/transforms.py similarity index 100% rename from monasca_events_api/common/messaging/message_formats/reference/transforms.py rename to monasca_events_api/common/messaging/message_formats/transforms.py diff --git a/monasca_events_api/v2/events.py b/monasca_events_api/v2/events.py index 0ea4dd1..d5962ec 100644 --- a/monasca_events_api/v2/events.py +++ b/monasca_events_api/v2/events.py @@ -22,8 +22,8 @@ import simport from monasca_events_api.api import events_api_v2 from monasca_events_api.common.messaging import exceptions \ as message_queue_exceptions -from monasca_events_api.common.messaging.message_formats \ - import events_transform_factory +from monasca_events_api.common.messaging.message_formats import events \ + as message_format_events from monasca_events_api.v2.common import helpers from monasca_events_api.v2.common import resource from monasca_events_api.v2.common.schemas import ( @@ -46,25 +46,20 @@ class Events(events_api_v2.EventsV2API): self._post_events_authorized_roles = ( cfg.CONF.security.default_authorized_roles + cfg.CONF.security.agent_authorized_roles) - - self._event_transform = ( - events_transform_factory.create_events_transform()) - self._message_queue = ( simport.load(cfg.CONF.messaging.driver)("raw-events")) self._events_repo = ( simport.load(cfg.CONF.repositories.events)()) def on_get(self, req, res, event_id=None): + helpers.validate_authorization(req, self._default_authorized_roles) + tenant_id = helpers.get_tenant_id(req) + if event_id: - helpers.validate_authorization(req, self._default_authorized_roles) - tenant_id = helpers.get_tenant_id(req) result = self._list_event(tenant_id, event_id, req.uri) res.body = helpers.dumpit_utf8(result) res.status = falcon.HTTP_200 else: - helpers.validate_authorization(req, self._default_authorized_roles) - tenant_id = helpers.get_tenant_id(req) offset = helpers.normalize_offset(helpers.get_query_param( req, 'offset')) @@ -75,14 +70,13 @@ class Events(events_api_v2.EventsV2API): res.status = falcon.HTTP_200 def on_post(self, req, res): - helpers.validate_json_content_type(req) helpers.validate_authorization(req, self._post_events_authorized_roles) + helpers.validate_json_content_type(req) event = helpers.read_http_resource(req) - self._validate_event(event) tenant_id = helpers.get_tenant_id(req) - transformed_event = self._event_transform(event, tenant_id, - self._region) + transformed_event = message_format_events.transform(event, tenant_id, + self._region) self._send_event(transformed_event) res.status = falcon.HTTP_204 diff --git a/monasca_events_api/v2/transforms.py b/monasca_events_api/v2/transforms.py index 0731861..5dd9687 100644 --- a/monasca_events_api/v2/transforms.py +++ b/monasca_events_api/v2/transforms.py @@ -27,8 +27,8 @@ import simport from monasca_events_api.api import transforms_api_v2 from monasca_events_api.common.messaging import exceptions as message_queue_exceptions -from monasca_events_api.common.messaging.message_formats.reference.transforms import ( - transform as transform_event) +from monasca_events_api.common.messaging.message_formats import ( + transforms as message_formats_transforms) from monasca_events_api.common.repositories import exceptions as repository_exceptions from monasca_events_api.v2.common import helpers from monasca_events_api.v2.common.schemas import (exceptions as schemas_exceptions) @@ -66,7 +66,8 @@ class Transforms(transforms_api_v2.TransformsV2API): transform_id = uuidutils.generate_uuid() tenant_id = helpers.get_tenant_id(req) self._create_transform(transform_id, tenant_id, transform) - transformed_event = transform_event(transform_id, tenant_id, transform) + transformed_event = message_formats_transforms.transform( + transform_id, tenant_id, transform) self._send_event(transformed_event) res.body = self._create_transform_response(transform_id, transform) res.status = falcon.HTTP_200 @@ -81,7 +82,9 @@ class Transforms(transforms_api_v2.TransformsV2API): helpers.validate_authorization(req, self._default_authorized_roles) tenant_id = helpers.get_tenant_id(req) self._delete_transform(tenant_id, transform_id) - transformed_event = transform_event(transform_id, tenant_id, []) + transformed_event = message_formats_transforms.transform(transform_id, + tenant_id, + []) self._send_event(transformed_event) res.status = falcon.HTTP_204