Cleanup and deleted unused message formats

This commit is contained in:
Roland Hochmuth 2015-06-25 23:40:50 -06:00
parent c896672c61
commit 2896511aa0
17 changed files with 15 additions and 234 deletions

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,24 +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 monasca_events_api.common.messaging import publisher
class RabbitmqPublisher(publisher.Publisher):
def __init__(self, topic):
pass
def send_message(self, message):
raise NotImplemented()

View File

@ -1,30 +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
from oslo_log import log
import peewee
LOG = log.getLogger(__name__)
db = peewee.MySQLDatabase(cfg.CONF.mysql.database_name,
host=cfg.CONF.mysql.hostname,
user=cfg.CONF.mysql.username,
passwd=cfg.CONF.mysql.password)
class Model(peewee.Model):
class Meta(object):
database = db

View File

@ -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

View File

@ -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