summaryrefslogtreecommitdiffstats
path: root/docs/overview.rst
diff options
context:
space:
mode:
authorDylanB95EST <dylan.byrne@est.tech>2021-10-11 16:29:16 +0100
committerDylanB95EST <dylan.byrne@est.tech>2021-10-11 16:41:53 +0100
commit3fcf869dd53f82349eee503582705b2407240f4f (patch)
treeac312b3211c2b7d209fc424c66b9e01de27e5198 /docs/overview.rst
parent1ab1a5450452352ff00bee718054f10adfc5bea0 (diff)
Cleanup naming conventions for CPS-NCMP
Change naming conventions in CPS-NCMP project Issue-ID: CPS-626 Change-Id: Ie97c53ef50eb3d0947136db0606047150181ec1b Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
Diffstat (limited to 'docs/overview.rst')
-rw-r--r--docs/overview.rst8
1 files changed, 4 insertions, 4 deletions
diff --git a/docs/overview.rst b/docs/overview.rst
index 1333e66fc..4b69dd810 100644
--- a/docs/overview.rst
+++ b/docs/overview.rst
@@ -37,18 +37,18 @@ This is the component of CPS which encompasses the generic storage of Yang modul
**NCMP**
The Network Configuration Management Proxy (NCMP) provides access to network configuration data and is a part of CPS-Core.
-NCMP accesses all network Data-Model-Inventory (DMI) information via NCMP-DMI-Plugins. The ONAP DMI Plugin described in the next section is one such plugin.
+NCMP accesses all network Data-Model-Inventory (DMI) information via NCMP-DMI-Plugins. The ONAP0-DMI-Plugin described in the next section is one such plugin.
**Note:** This documentation will often refer to "CPS-NCMP" which is the component (container image) that contains both CPS-Core and NCMP since NCMP is not a stand-alone component
even though CPS-Core could be deployed without the NCMP extension.
-ONAP NCMP-DMI-Plugin
+NCMP-DMI-Plugin
####################
-The Data-Model-Inventory (DMI) Plugin is a rest interface used to synchronize CM-Handles data between CPS and DMI through the DMI Plugin.
+The Data-Model-Inventory (DMI) Plugin is a rest interface used to synchronize CM-Handles data between CPS and DMI through the DMI-Plugin.
This is built previously from the CPS-NF-Proxy component.
-CPS Temporal
+CPS-Temporal
############
This service is responsible to provide a time oriented perspective for
id='n184' href='#n184'>184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
# ============LICENSE_START=======================================================
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# 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.
# ============LICENSE_END=========================================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.

"""
Functions for DMaaP integration
"""
import six
import logging
from jsonschema import validate, ValidationError
from dcae_cli.util import reraise_with_msg
from dcae_cli.util.logger import get_logger
from dcae_cli.catalog.mock.schema import apply_defaults


logger = get_logger('Dmaap')

_SCHEMA = {
      "$schema": "http://json-schema.org/draft-04/schema#",
      "title": "Schema for dmaap inputs",
      "type": "object",
      "oneOf": [
        { "$ref": "#/definitions/message_router" },
        { "$ref": "#/definitions/data_router_publisher" },
        { "$ref": "#/definitions/data_router_subscriber" }
      ],
      "definitions": {
        "message_router": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["message_router"]
            },
            "aaf_username": {
              "type": "string",
              "default": None
            },
            "aaf_password": {
              "type": "string",
              "default": None
            },
            "dmaap_info": {
              "type": "object",
              "properties": {
                "client_role": {
                  "type": "string",
                  "default": None
                },
                "client_id": {
                  "type": "string",
                  "default": None
                },
                "location": {
                  "type": "string",
                  "default": None
                },
                "topic_url": {
                  "type": "string"
                }
              },
              "required": [
                "topic_url"
              ],
              "additionalProperties": False
            }
          },
          "required": [
            "type",
            "dmaap_info"
          ],
          "additionalProperties": False
        },
        "data_router_publisher": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["data_router"]
            },
            "dmaap_info": {
              "type": "object",
              "properties": {
                "location": {
                  "type": "string",
                  "default": None,
                  "description": "the DCAE location for the publisher, used to set up routing"
                },
                "publish_url": {
                  "type": "string",
                  "description": "the URL to which the publisher makes Data Router publish requests"
                },
                "log_url": {
                  "type": "string",
                  "default": None,
                  "description": "the URL from which log data for the feed can be obtained"
                },
                "username": {
                  "type": "string",
                  "default": None,
                  "description": "the username the publisher uses to authenticate to Data Router"
                },
                "password": {
                  "type": "string",
                  "default": None,
                  "description": "the password the publisher uses to authenticate to Data Router"
                },
                "publisher_id": {
                  "type": "string",
                  "default": ""
                }
              },
              "required": [
                "publish_url"
              ],
              "additionalProperties": False
            }
          },
          "required": [
            "type",
            "dmaap_info"
          ],
          "additionalProperties": False
      },
      "data_router_subscriber": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["data_router"]
            },
            "dmaap_info": {
              "type": "object",
              "properties": {
                "location": {
                  "type": "string",
                  "default": None,
                  "description": "the DCAE location for the publisher, used to set up routing"
                },
                "delivery_url": {
                  "type": "string",
                  "description": "the URL to which the Data Router should deliver files"
                },
                "username": {
                  "type": "string",
                  "default": None,
                  "description": "the username Data Router uses to authenticate to the subscriber when delivering files"
                },
                "password": {
                  "type": "string",
                  "default": None,
                  "description": "the username Data Router uses to authenticate to the subscriber when delivering file"
                },
                "subscriber_id": {
                  "type": "string",
                  "default": ""
                }
              },
              "additionalProperties": False
            }
          },
          "required": [
            "type",
            "dmaap_info"
          ],
          "additionalProperties": False
      }
    }
}


_validation_msg = """
Is your DMaaP client object a valid json?
Does your DMaaP client object follow this format?

Message router:

    {
        "aaf_username": <string, optional>,
        "aaf_password": <string, optional>,
        "type": "message_router",
        "dmaap_info": {
            "client_role": <string, optional>,
            "client_id": <string, optional>,
            "location": <string, optional>,
            "topic_url": <string, required>
        }
    }

Data router (publisher):

    {
        "type": "data_router",
        "dmaap_info": {
            "location": <string, optional>,
            "publish_url": <string, required>,
            "log_url": <string, optional>,
            "username": <string, optional>,
            "password": <string, optional>,
            "publisher_id": <string, optional>
        }
    }

Data router (subscriber):

    {
        "type": "data_router",
        "dmaap_info": {
            "location": <string, optional>,
            "delivery_url": <string, optional>,
            "username": <string, optional>,
            "password": <string, optional>,
            "subscriber_id": <string, optional>
        }
    }

"""

def validate_dmaap_map_schema(dmaap_map):
    """Validate the dmaap map schema"""
    for k, v in six.iteritems(dmaap_map):
        try:
            validate(v, _SCHEMA)
        except ValidationError as e:
            logger.error("DMaaP validation issue with \"{k}\"".format(k=k))
            logger.error(_validation_msg)
            reraise_with_msg(e, as_dcae=True)


class DMaaPValidationError(RuntimeError):
    pass

def _find_matching_definition(instance):
    """Find and return matching definition given an instance"""
    for subsection in ["message_router", "data_router_publisher",
            "data_router_subscriber"]:
        try:
            validate(instance, _SCHEMA["definitions"][subsection])
            return _SCHEMA["definitions"][subsection]
        except ValidationError:
            pass

    # You should never get here but just in case..
    logger.error("No matching definition: {0}".format(instance))
    raise DMaaPValidationError("No matching definition")

def apply_defaults_dmaap_map(dmaap_map):
    """Apply the defaults to the dmaap map"""
    def grab_properties(instance):
        return _find_matching_definition(instance)["properties"]

    return { k: apply_defaults(grab_properties(v), v) for k,v in
            six.iteritems(dmaap_map) }


def validate_dmaap_map_entries(dmaap_map, mr_config_keys, dr_config_keys):
    """Validate dmaap map entries

    Validate dmaap map to make sure all config keys are there and that there's
    no additional config keys beceause this map is used in generating the
    configuration json.

    Returns:
    --------
    True when dmaap_map is ok and False when it is not
    """
    # Catch when there is no dmaap_map when there should be
    if len(mr_config_keys) + len(dr_config_keys) > 0 and len(dmaap_map) == 0:
        logger.error("You have dmaap streams defined in your specification")
        logger.error("You must provide a dmaap json to resolve those dmaap streams.")
        logger.error("Please use the \"--dmaap-file\" option")
        return False

    config_keys = dr_config_keys + mr_config_keys
    # Look for missing keys
    is_missing = lambda config_key: config_key not in dmaap_map
    missing_keys = list(filter(is_missing, config_keys))

    if missing_keys:
        logger.error("Missing config keys in dmaap json: {0}".format(
            ",".join(missing_keys)))
        logger.error("Re-edit your dmaap json")
        return False

    # Look for unexpected keys
    is_unexpected = lambda config_key: config_key not in config_keys
    unexpected_keys = list(filter(is_unexpected, dmaap_map.keys()))

    if unexpected_keys:
        # NOTE: Changed this to a non-error in order to support the feature of
        # developer having a master dmaap map
        logger.warn("Unexpected config keys in dmaap json: {0}".format(
            ",".join(unexpected_keys)))
        return True

    return True


def update_delivery_urls(get_route_func, target_base_url, dmaap_map):
    """Update delivery urls for dmaap map

    This method picks out all the data router connections for subscribers and
    updates the delivery urls with the supplied base target url concatentated
    with the user specified route (or path).

    Args:
    -----
    get_route_func (func): Function that takes a config_key and returns the route
        used for the data router subscriber
    target_base_url (string): "{http|https}://<hostname>:<port>"
    dmaap_map (dict): DMaaP map is map of inputs that is config_key to provisioned
        data router feed or message router topic connection details

    Returns:
    --------
    Returns the updated DMaaP map
    """
    def update_delivery_url(config_key, dm):
        route = get_route_func(config_key)
        dm["dmaap_info"]["delivery_url"] = "{base}{tween}{path}".format(base=target_base_url,
                path=route, tween="" if route[0] == "/" else "/")
        return dm

    def is_dr_subscriber(dm):
        return dm["type"] == "data_router" and "publish_url" not in dm["dmaap_info"]

    updated_map = { config_key: update_delivery_url(config_key, dm)
            for config_key, dm in six.iteritems(dmaap_map) if is_dr_subscriber(dm) }
    dmaap_map.update(updated_map)

    return dmaap_map


def list_delivery_urls(dmaap_map):
    """List delivery urls

    Returns:
    --------
    List of tuples (config_key, deliery_url)
    """
    return [(config_key, dm["dmaap_info"]["delivery_url"]) \
            for config_key, dm in six.iteritems(dmaap_map) if "delivery_url" in dm["dmaap_info"]]